Name adjustments and moved some things to the common lib.
This commit is contained in:
parent
b8ec381f3b
commit
0cc5d46ea9
50 changed files with 323 additions and 323 deletions
SharpChat/ClientCommands
62
SharpChat/ClientCommands/WhoClientCommand.cs
Normal file
62
SharpChat/ClientCommands/WhoClientCommand.cs
Normal file
|
@ -0,0 +1,62 @@
|
|||
using SharpChat.S2CPackets;
|
||||
using System.Text;
|
||||
|
||||
namespace SharpChat.ClientCommands {
|
||||
public class WhoClientCommand : ClientCommand {
|
||||
public bool IsMatch(ClientCommandContext ctx) {
|
||||
return ctx.NameEquals("who");
|
||||
}
|
||||
|
||||
public void Dispatch(ClientCommandContext ctx) {
|
||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||
StringBuilder whoChanSB = new();
|
||||
string? whoChanStr = ctx.Args.FirstOrDefault();
|
||||
|
||||
if(string.IsNullOrEmpty(whoChanStr)) {
|
||||
foreach(User whoUser in ctx.Chat.Users) {
|
||||
whoChanSB.Append(@"<a href=""javascript:void(0);"" onclick=""UI.InsertChatText(this.innerHTML);""");
|
||||
|
||||
if(whoUser == ctx.User)
|
||||
whoChanSB.Append(@" style=""font-weight: bold;""");
|
||||
|
||||
whoChanSB.Append('>');
|
||||
whoChanSB.Append(whoUser.LegacyName);
|
||||
whoChanSB.Append("</a>, ");
|
||||
}
|
||||
|
||||
if(whoChanSB.Length > 2)
|
||||
whoChanSB.Length -= 2;
|
||||
|
||||
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USERS_LISTING_SERVER, false, whoChanSB));
|
||||
} else {
|
||||
Channel? whoChan = ctx.Chat.Channels.FirstOrDefault(c => c.NameEquals(whoChanStr));
|
||||
|
||||
if(whoChan is null) {
|
||||
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.CHANNEL_NOT_FOUND, true, whoChanStr));
|
||||
return;
|
||||
}
|
||||
|
||||
if(whoChan.Rank > ctx.User.Rank || (whoChan.HasPassword && !ctx.User.Can(UserPermissions.JoinAnyChannel))) {
|
||||
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USERS_LISTING_ERROR, true, whoChanStr));
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(User whoUser in ctx.Chat.GetChannelUsers(whoChan)) {
|
||||
whoChanSB.Append(@"<a href=""javascript:void(0);"" onclick=""UI.InsertChatText(this.innerHTML);""");
|
||||
|
||||
if(whoUser == ctx.User)
|
||||
whoChanSB.Append(@" style=""font-weight: bold;""");
|
||||
|
||||
whoChanSB.Append('>');
|
||||
whoChanSB.Append(whoUser.LegacyName);
|
||||
whoChanSB.Append("</a>, ");
|
||||
}
|
||||
|
||||
if(whoChanSB.Length > 2)
|
||||
whoChanSB.Length -= 2;
|
||||
|
||||
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USERS_LISTING_CHANNEL, false, whoChan.Name, whoChanSB));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue