2024-05-20 23:40:34 +00:00
|
|
|
|
using SharpChat.SockChat.PacketsS2C;
|
2023-02-16 20:34:59 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2024-05-20 23:40:34 +00:00
|
|
|
|
namespace SharpChat.SockChat.Commands {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public class WhoCommand : ISockChatClientCommand {
|
|
|
|
|
public bool IsMatch(SockChatClientCommandContext ctx) {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return ctx.NameEquals("who");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public void Dispatch(SockChatClientCommandContext ctx) {
|
2024-05-14 22:17:25 +00:00
|
|
|
|
string? channelName = ctx.Args.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if(string.IsNullOrEmpty(channelName)) {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new WhoServerResponseS2CPacket(
|
2024-05-19 21:02:17 +00:00
|
|
|
|
ctx.Chat.Users.All.Select(u => SockChatUtility.GetUserNameWithStatus(u)).ToArray(),
|
|
|
|
|
SockChatUtility.GetUserName(ctx.User)
|
2024-05-14 22:17:25 +00:00
|
|
|
|
));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
2024-05-19 21:02:17 +00:00
|
|
|
|
ChannelInfo? channel = ctx.Chat.Channels.Get(channelName, SockChatUtility.SanitiseChannelName);
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
2024-05-14 22:17:25 +00:00
|
|
|
|
if(channel == null) {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new ChannelNotFoundErrorS2CPacket(channelName));
|
2024-05-14 22:17:25 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
2024-05-19 02:17:51 +00:00
|
|
|
|
if(channel.Rank > ctx.User.Rank || (channel.HasPassword && !ctx.User.Permissions.HasFlag(UserPermissions.JoinAnyChannel))) {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new WhoChannelNotFoundErrorS2CPacket(channelName));
|
2024-05-14 22:17:25 +00:00
|
|
|
|
return;
|
2023-02-16 20:34:59 +00:00
|
|
|
|
}
|
2024-05-14 22:17:25 +00:00
|
|
|
|
|
2024-05-20 23:00:47 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new WhoChannelResponseS2CPacket(
|
2024-05-14 22:17:25 +00:00
|
|
|
|
channel.Name,
|
2024-05-19 21:02:17 +00:00
|
|
|
|
ctx.Chat.GetChannelUsers(channel).Select(user => SockChatUtility.GetUserNameWithStatus(user)).ToArray(),
|
|
|
|
|
SockChatUtility.GetUserNameWithStatus(ctx.User)
|
2024-05-14 22:17:25 +00:00
|
|
|
|
));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|