sharp-chat/SharpChat/Commands/ChannelJoinCommand.cs

24 lines
838 B
C#
Raw Normal View History

using SharpChat.PacketsS2C;
using System.Linq;
namespace SharpChat.Commands {
public class ChannelJoinCommand : ISockChatClientCommand {
public bool IsMatch(SockChatClientCommandContext ctx) {
return ctx.NameEquals("join");
}
public void Dispatch(SockChatClientCommandContext ctx) {
2024-05-14 22:17:25 +00:00
string joinChanStr = ctx.Args.FirstOrDefault() ?? string.Empty;
2024-05-19 21:02:17 +00:00
ChannelInfo? joinChan = ctx.Chat.Channels.Get(joinChanStr, SockChatUtility.SanitiseChannelName);
if(joinChan == null) {
ctx.Chat.SendTo(ctx.User, new ChannelNotFoundErrorS2CPacket(joinChanStr));
ctx.Chat.ForceChannel(ctx.User);
return;
}
ctx.Chat.SwitchChannel(ctx.User, joinChan, string.Join(' ', ctx.Args.Skip(1)));
}
}
}