Added C2S and S2C markings to class names.
This commit is contained in:
parent
e17aed7c25
commit
a8f5c00e37
45 changed files with 181 additions and 181 deletions
SharpChat
C2SPacketHandler.cs
C2SPacketHandlers
ChatConnection.csChatContext.csCommands
BanListCommand.csBroadcastCommand.csCreateChannelCommand.csDeleteChannelCommand.csDeleteMessageCommand.csJoinChannelCommand.csKickBanCommand.csNickCommand.csPardonAddressCommand.csPardonUserCommand.csPasswordChannelCommand.csRankChannelCommand.csRemoteAddressCommand.csShutdownRestartCommand.csWhisperCommand.csWhoCommand.cs
S2CPacket.csS2CPackets
AuthFailS2CPacket.csAuthSuccessS2CPacket.csBanListS2CPacket.csChannelCreateS2CPacket.csChannelDeleteS2CPacket.csChannelUpdateS2CPacket.csChatMessageAddS2CPacket.csChatMessageDeleteS2CPacket.csCommandResponseS2CPacket.csContextChannelsS2CPacket.csContextClearS2CPacket.csContextMessageS2CPacket.csContextUsersS2CPacket.csForceDisconnectS2CPacket.csPongS2CPacket.csUserChannelForceJoinS2CPacket.csUserChannelJoinS2CPacket.csUserChannelLeaveS2CPacket.csUserConnectS2CPacket.csUserDisconnectS2CPacket.csUserUpdateS2CPacket.cs
SockChatServer.cs
|
@ -1,5 +1,5 @@
|
||||||
namespace SharpChat {
|
namespace SharpChat {
|
||||||
public interface IChatPacketHandler {
|
public interface C2SPacketHandler {
|
||||||
bool IsMatch(ChatPacketHandlerContext ctx);
|
bool IsMatch(ChatPacketHandlerContext ctx);
|
||||||
void Handle(ChatPacketHandlerContext ctx);
|
void Handle(ChatPacketHandlerContext ctx);
|
||||||
}
|
}
|
|
@ -1,14 +1,14 @@
|
||||||
using SharpChat.Config;
|
using SharpChat.Config;
|
||||||
using SharpChat.Misuzu;
|
using SharpChat.Misuzu;
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.PacketHandlers {
|
namespace SharpChat.C2SPacketHandlers {
|
||||||
public class AuthHandler(
|
public class AuthC2SPacketHandler(
|
||||||
MisuzuClient msz,
|
MisuzuClient msz,
|
||||||
ChatChannel defaultChannel,
|
ChatChannel defaultChannel,
|
||||||
CachedValue<int> maxMsgLength,
|
CachedValue<int> maxMsgLength,
|
||||||
CachedValue<int> maxConns
|
CachedValue<int> maxConns
|
||||||
) : IChatPacketHandler {
|
) : C2SPacketHandler {
|
||||||
private readonly MisuzuClient Misuzu = msz ?? throw new ArgumentNullException(nameof(msz));
|
private readonly MisuzuClient Misuzu = msz ?? throw new ArgumentNullException(nameof(msz));
|
||||||
private readonly ChatChannel DefaultChannel = defaultChannel ?? throw new ArgumentNullException(nameof(defaultChannel));
|
private readonly ChatChannel DefaultChannel = defaultChannel ?? throw new ArgumentNullException(nameof(defaultChannel));
|
||||||
private readonly CachedValue<int> MaxMessageLength = maxMsgLength ?? throw new ArgumentNullException(nameof(maxMsgLength));
|
private readonly CachedValue<int> MaxMessageLength = maxMsgLength ?? throw new ArgumentNullException(nameof(maxMsgLength));
|
||||||
|
@ -23,14 +23,14 @@ namespace SharpChat.PacketHandlers {
|
||||||
|
|
||||||
string? authMethod = args.ElementAtOrDefault(1);
|
string? authMethod = args.ElementAtOrDefault(1);
|
||||||
if(string.IsNullOrWhiteSpace(authMethod)) {
|
if(string.IsNullOrWhiteSpace(authMethod)) {
|
||||||
ctx.Connection.Send(new AuthFailPacket(AuthFailReason.AuthInvalid));
|
ctx.Connection.Send(new AuthFailS2CPacket(AuthFailReason.AuthInvalid));
|
||||||
ctx.Connection.Dispose();
|
ctx.Connection.Dispose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string? authToken = args.ElementAtOrDefault(2);
|
string? authToken = args.ElementAtOrDefault(2);
|
||||||
if(string.IsNullOrWhiteSpace(authToken)) {
|
if(string.IsNullOrWhiteSpace(authToken)) {
|
||||||
ctx.Connection.Send(new AuthFailPacket(AuthFailReason.AuthInvalid));
|
ctx.Connection.Send(new AuthFailS2CPacket(AuthFailReason.AuthInvalid));
|
||||||
ctx.Connection.Dispose();
|
ctx.Connection.Dispose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ namespace SharpChat.PacketHandlers {
|
||||||
fai = await Misuzu.AuthVerifyAsync(authMethod, authToken, ipAddr);
|
fai = await Misuzu.AuthVerifyAsync(authMethod, authToken, ipAddr);
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
Logger.Write($"<{ctx.Connection.Id}> Failed to authenticate: {ex}");
|
Logger.Write($"<{ctx.Connection.Id}> Failed to authenticate: {ex}");
|
||||||
ctx.Connection.Send(new AuthFailPacket(AuthFailReason.AuthInvalid));
|
ctx.Connection.Send(new AuthFailS2CPacket(AuthFailReason.AuthInvalid));
|
||||||
ctx.Connection.Dispose();
|
ctx.Connection.Dispose();
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
throw;
|
throw;
|
||||||
|
@ -60,7 +60,7 @@ namespace SharpChat.PacketHandlers {
|
||||||
|
|
||||||
if(fai?.Success != true) {
|
if(fai?.Success != true) {
|
||||||
Logger.Debug($"<{ctx.Connection.Id}> Auth fail: {fai?.Reason ?? "unknown"}");
|
Logger.Debug($"<{ctx.Connection.Id}> Auth fail: {fai?.Reason ?? "unknown"}");
|
||||||
ctx.Connection.Send(new AuthFailPacket(AuthFailReason.AuthInvalid));
|
ctx.Connection.Send(new AuthFailS2CPacket(AuthFailReason.AuthInvalid));
|
||||||
ctx.Connection.Dispose();
|
ctx.Connection.Dispose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ namespace SharpChat.PacketHandlers {
|
||||||
fbi = await Misuzu.CheckBanAsync(fai.UserId.ToString(), ipAddr);
|
fbi = await Misuzu.CheckBanAsync(fai.UserId.ToString(), ipAddr);
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
Logger.Write($"<{ctx.Connection.Id}> Failed auth ban check: {ex}");
|
Logger.Write($"<{ctx.Connection.Id}> Failed auth ban check: {ex}");
|
||||||
ctx.Connection.Send(new AuthFailPacket(AuthFailReason.AuthInvalid));
|
ctx.Connection.Send(new AuthFailS2CPacket(AuthFailReason.AuthInvalid));
|
||||||
ctx.Connection.Dispose();
|
ctx.Connection.Dispose();
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
throw;
|
throw;
|
||||||
|
@ -81,7 +81,7 @@ namespace SharpChat.PacketHandlers {
|
||||||
|
|
||||||
if(fbi?.IsBanned == true && !fbi.HasExpired) {
|
if(fbi?.IsBanned == true && !fbi.HasExpired) {
|
||||||
Logger.Write($"<{ctx.Connection.Id}> User is banned.");
|
Logger.Write($"<{ctx.Connection.Id}> User is banned.");
|
||||||
ctx.Connection.Send(new AuthFailPacket(AuthFailReason.Banned, fbi));
|
ctx.Connection.Send(new AuthFailS2CPacket(AuthFailReason.Banned, fbi));
|
||||||
ctx.Connection.Dispose();
|
ctx.Connection.Dispose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -109,21 +109,21 @@ namespace SharpChat.PacketHandlers {
|
||||||
|
|
||||||
// Enforce a maximum amount of connections per user
|
// Enforce a maximum amount of connections per user
|
||||||
if(ctx.Chat.Connections.Count(conn => conn.User == user) >= MaxConnections) {
|
if(ctx.Chat.Connections.Count(conn => conn.User == user) >= MaxConnections) {
|
||||||
ctx.Connection.Send(new AuthFailPacket(AuthFailReason.MaxSessions));
|
ctx.Connection.Send(new AuthFailS2CPacket(AuthFailReason.MaxSessions));
|
||||||
ctx.Connection.Dispose();
|
ctx.Connection.Dispose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Connection.BumpPing();
|
ctx.Connection.BumpPing();
|
||||||
ctx.Connection.User = user;
|
ctx.Connection.User = user;
|
||||||
ctx.Connection.Send(new LegacyCommandResponse(0, LCR.WELCOME, false, $"Welcome to Flashii Chat, {user.UserName}!"));
|
ctx.Connection.Send(new CommandResponseS2CPacket(0, LCR.WELCOME, false, $"Welcome to Flashii Chat, {user.UserName}!"));
|
||||||
|
|
||||||
if(File.Exists("welcome.txt")) {
|
if(File.Exists("welcome.txt")) {
|
||||||
IEnumerable<string> lines = File.ReadAllLines("welcome.txt").Where(x => !string.IsNullOrWhiteSpace(x));
|
IEnumerable<string> lines = File.ReadAllLines("welcome.txt").Where(x => !string.IsNullOrWhiteSpace(x));
|
||||||
string? line = lines.ElementAtOrDefault(RNG.Next(lines.Count()));
|
string? line = lines.ElementAtOrDefault(RNG.Next(lines.Count()));
|
||||||
|
|
||||||
if(!string.IsNullOrWhiteSpace(line))
|
if(!string.IsNullOrWhiteSpace(line))
|
||||||
ctx.Connection.Send(new LegacyCommandResponse(0, LCR.WELCOME, false, line));
|
ctx.Connection.Send(new CommandResponseS2CPacket(0, LCR.WELCOME, false, line));
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Chat.HandleJoin(user, DefaultChannel, ctx.Connection, MaxMessageLength);
|
ctx.Chat.HandleJoin(user, DefaultChannel, ctx.Connection, MaxMessageLength);
|
|
@ -1,8 +1,8 @@
|
||||||
using SharpChat.Misuzu;
|
using SharpChat.Misuzu;
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.PacketHandlers {
|
namespace SharpChat.C2SPacketHandlers {
|
||||||
public class PingHandler(MisuzuClient msz) : IChatPacketHandler {
|
public class PingC2SPacketHandler(MisuzuClient msz) : C2SPacketHandler {
|
||||||
private readonly MisuzuClient Misuzu = msz ?? throw new ArgumentNullException(nameof(msz));
|
private readonly MisuzuClient Misuzu = msz ?? throw new ArgumentNullException(nameof(msz));
|
||||||
|
|
||||||
private readonly TimeSpan BumpInterval = TimeSpan.FromMinutes(1);
|
private readonly TimeSpan BumpInterval = TimeSpan.FromMinutes(1);
|
||||||
|
@ -19,7 +19,7 @@ namespace SharpChat.PacketHandlers {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ctx.Connection.BumpPing();
|
ctx.Connection.BumpPing();
|
||||||
ctx.Connection.Send(new PongPacket());
|
ctx.Connection.Send(new PongS2CPacket());
|
||||||
|
|
||||||
ctx.Chat.ContextAccess.Wait();
|
ctx.Chat.ContextAccess.Wait();
|
||||||
try {
|
try {
|
|
@ -4,11 +4,11 @@ using SharpChat.Snowflake;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.PacketHandlers {
|
namespace SharpChat.C2SPacketHandlers {
|
||||||
public class SendMessageHandler(
|
public class SendMessageC2SPacketHandler(
|
||||||
RandomSnowflake randomSnowflake,
|
RandomSnowflake randomSnowflake,
|
||||||
CachedValue<int> maxMsgLength
|
CachedValue<int> maxMsgLength
|
||||||
) : IChatPacketHandler {
|
) : C2SPacketHandler {
|
||||||
private readonly CachedValue<int> MaxMessageLength = maxMsgLength ?? throw new ArgumentNullException(nameof(maxMsgLength));
|
private readonly CachedValue<int> MaxMessageLength = maxMsgLength ?? throw new ArgumentNullException(nameof(maxMsgLength));
|
||||||
|
|
||||||
private List<IChatCommand> Commands { get; } = [];
|
private List<IChatCommand> Commands { get; } = [];
|
|
@ -41,7 +41,7 @@ namespace SharpChat {
|
||||||
RemotePort = (ushort)sock.ConnectionInfo.ClientPort;
|
RemotePort = (ushort)sock.ConnectionInfo.ClientPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Send(IServerPacket packet) {
|
public void Send(S2CPacket packet) {
|
||||||
if(!Socket.IsAvailable)
|
if(!Socket.IsAvailable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using SharpChat.Events;
|
using SharpChat.Events;
|
||||||
using SharpChat.EventStorage;
|
using SharpChat.EventStorage;
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
using SharpChat.Snowflake;
|
using SharpChat.Snowflake;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ namespace SharpChat {
|
||||||
public void DispatchEvent(IChatEvent eventInfo) {
|
public void DispatchEvent(IChatEvent eventInfo) {
|
||||||
if(eventInfo is MessageCreateEvent mce) {
|
if(eventInfo is MessageCreateEvent mce) {
|
||||||
if(mce.IsBroadcast) {
|
if(mce.IsBroadcast) {
|
||||||
Send(new LegacyCommandResponse(RandomSnowflake.Next(), LCR.BROADCAST, false, mce.MessageText));
|
Send(new CommandResponseS2CPacket(RandomSnowflake.Next(), LCR.BROADCAST, false, mce.MessageText));
|
||||||
} else if(mce.IsPrivate) {
|
} else if(mce.IsPrivate) {
|
||||||
// The channel name returned by GetDMChannelName should not be exposed to the user, instead @<Target User> should be displayed
|
// The channel name returned by GetDMChannelName should not be exposed to the user, instead @<Target User> should be displayed
|
||||||
// e.g. nook sees @Arysil and Arysil sees @nook
|
// e.g. nook sees @Arysil and Arysil sees @nook
|
||||||
|
@ -48,7 +48,7 @@ namespace SharpChat {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach(ChatUser user in users)
|
foreach(ChatUser user in users)
|
||||||
SendTo(user, new ChatMessageAddPacket(
|
SendTo(user, new ChatMessageAddS2CPacket(
|
||||||
mce.MessageId,
|
mce.MessageId,
|
||||||
DateTimeOffset.Now,
|
DateTimeOffset.Now,
|
||||||
mce.SenderId,
|
mce.SenderId,
|
||||||
|
@ -59,7 +59,7 @@ namespace SharpChat {
|
||||||
} else {
|
} else {
|
||||||
ChatChannel? channel = Channels.FirstOrDefault(c => c.NameEquals(mce.ChannelName));
|
ChatChannel? channel = Channels.FirstOrDefault(c => c.NameEquals(mce.ChannelName));
|
||||||
if(channel is not null)
|
if(channel is not null)
|
||||||
SendTo(channel, new ChatMessageAddPacket(
|
SendTo(channel, new ChatMessageAddS2CPacket(
|
||||||
mce.MessageId,
|
mce.MessageId,
|
||||||
DateTimeOffset.Now,
|
DateTimeOffset.Now,
|
||||||
mce.SenderId,
|
mce.SenderId,
|
||||||
|
@ -190,15 +190,15 @@ namespace SharpChat {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasChanged)
|
if(hasChanged)
|
||||||
SendToUserChannels(user, new UserUpdatePacket(RandomSnowflake.Next(), user, previousName));
|
SendToUserChannels(user, new UserUpdateS2CPacket(RandomSnowflake.Next(), user, previousName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BanUser(ChatUser user, TimeSpan duration, UserDisconnectReason reason = UserDisconnectReason.Kicked) {
|
public void BanUser(ChatUser user, TimeSpan duration, UserDisconnectReason reason = UserDisconnectReason.Kicked) {
|
||||||
if(duration > TimeSpan.Zero) {
|
if(duration > TimeSpan.Zero) {
|
||||||
DateTimeOffset expires = duration >= TimeSpan.MaxValue ? DateTimeOffset.MaxValue : DateTimeOffset.Now + duration;
|
DateTimeOffset expires = duration >= TimeSpan.MaxValue ? DateTimeOffset.MaxValue : DateTimeOffset.Now + duration;
|
||||||
SendTo(user, new ForceDisconnectPacket(ForceDisconnectReason.Banned, expires));
|
SendTo(user, new ForceDisconnectS2CPacket(ForceDisconnectReason.Banned, expires));
|
||||||
} else
|
} else
|
||||||
SendTo(user, new ForceDisconnectPacket(ForceDisconnectReason.Kicked));
|
SendTo(user, new ForceDisconnectS2CPacket(ForceDisconnectReason.Kicked));
|
||||||
|
|
||||||
foreach(ChatConnection conn in Connections)
|
foreach(ChatConnection conn in Connections)
|
||||||
if(conn.User == user)
|
if(conn.User == user)
|
||||||
|
@ -211,17 +211,17 @@ namespace SharpChat {
|
||||||
public void HandleJoin(ChatUser user, ChatChannel chan, ChatConnection conn, int maxMsgLength) {
|
public void HandleJoin(ChatUser user, ChatChannel chan, ChatConnection conn, int maxMsgLength) {
|
||||||
if(!IsInChannel(user, chan)) {
|
if(!IsInChannel(user, chan)) {
|
||||||
long msgId = RandomSnowflake.Next();
|
long msgId = RandomSnowflake.Next();
|
||||||
SendTo(chan, new UserConnectPacket(msgId, DateTimeOffset.Now, user));
|
SendTo(chan, new UserConnectS2CPacket(msgId, DateTimeOffset.Now, user));
|
||||||
Events.AddEvent(msgId, "user:connect", chan.Name, user.UserId, user.UserName, user.Colour, user.Rank, user.NickName, user.Permissions, null, StoredEventFlags.Log);
|
Events.AddEvent(msgId, "user:connect", chan.Name, user.UserId, user.UserName, user.Colour, user.Rank, user.NickName, user.Permissions, null, StoredEventFlags.Log);
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.Send(new AuthSuccessPacket(user, chan, maxMsgLength));
|
conn.Send(new AuthSuccessS2CPacket(user, chan, maxMsgLength));
|
||||||
conn.Send(new ContextUsersPacket(GetChannelUsers(chan).Except([user]).OrderByDescending(u => u.Rank)));
|
conn.Send(new ContextUsersS2CPacket(GetChannelUsers(chan).Except([user]).OrderByDescending(u => u.Rank)));
|
||||||
|
|
||||||
foreach(StoredEventInfo msg in Events.GetChannelEventLog(chan.Name))
|
foreach(StoredEventInfo msg in Events.GetChannelEventLog(chan.Name))
|
||||||
conn.Send(new ContextMessagePacket(msg));
|
conn.Send(new ContextMessageS2CPacket(msg));
|
||||||
|
|
||||||
conn.Send(new ContextChannelsPacket(Channels.Where(c => c.Rank <= user.Rank)));
|
conn.Send(new ContextChannelsS2CPacket(Channels.Where(c => c.Rank <= user.Rank)));
|
||||||
|
|
||||||
Users.Add(user);
|
Users.Add(user);
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ namespace SharpChat {
|
||||||
ChannelUsers.Remove(new ChannelUserAssoc(user.UserId, chan.Name));
|
ChannelUsers.Remove(new ChannelUserAssoc(user.UserId, chan.Name));
|
||||||
|
|
||||||
long msgId = RandomSnowflake.Next();
|
long msgId = RandomSnowflake.Next();
|
||||||
SendTo(chan, new UserDisconnectPacket(msgId, DateTimeOffset.Now, user, reason));
|
SendTo(chan, new UserDisconnectS2CPacket(msgId, DateTimeOffset.Now, user, reason));
|
||||||
Events.AddEvent(msgId, "user:disconnect", chan.Name, user.UserId, user.UserName, user.Colour, user.Rank, user.NickName, user.Permissions, new { reason = (int)reason }, StoredEventFlags.Log);
|
Events.AddEvent(msgId, "user:disconnect", chan.Name, user.UserId, user.UserName, user.Colour, user.Rank, user.NickName, user.Permissions, new { reason = (int)reason }, StoredEventFlags.Log);
|
||||||
|
|
||||||
if(chan.IsTemporary && chan.IsOwner(user))
|
if(chan.IsTemporary && chan.IsOwner(user))
|
||||||
|
@ -256,13 +256,13 @@ namespace SharpChat {
|
||||||
|
|
||||||
if(!user.Can(ChatUserPermissions.JoinAnyChannel) && chan.IsOwner(user)) {
|
if(!user.Can(ChatUserPermissions.JoinAnyChannel) && chan.IsOwner(user)) {
|
||||||
if(chan.Rank > user.Rank) {
|
if(chan.Rank > user.Rank) {
|
||||||
SendTo(user, new LegacyCommandResponse(RandomSnowflake.Next(), LCR.CHANNEL_INSUFFICIENT_HIERARCHY, true, chan.Name));
|
SendTo(user, new CommandResponseS2CPacket(RandomSnowflake.Next(), LCR.CHANNEL_INSUFFICIENT_HIERARCHY, true, chan.Name));
|
||||||
ForceChannel(user);
|
ForceChannel(user);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!string.IsNullOrEmpty(chan.Password) && chan.Password != password) {
|
if(!string.IsNullOrEmpty(chan.Password) && chan.Password != password) {
|
||||||
SendTo(user, new LegacyCommandResponse(RandomSnowflake.Next(), LCR.CHANNEL_INVALID_PASSWORD, true, chan.Name));
|
SendTo(user, new CommandResponseS2CPacket(RandomSnowflake.Next(), LCR.CHANNEL_INVALID_PASSWORD, true, chan.Name));
|
||||||
ForceChannel(user);
|
ForceChannel(user);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -278,18 +278,18 @@ namespace SharpChat {
|
||||||
ChatChannel oldChan = UserLastChannel[user.UserId];
|
ChatChannel oldChan = UserLastChannel[user.UserId];
|
||||||
|
|
||||||
long leaveId = RandomSnowflake.Next();
|
long leaveId = RandomSnowflake.Next();
|
||||||
SendTo(oldChan, new UserChannelLeavePacket(leaveId, user));
|
SendTo(oldChan, new UserChannelLeaveS2CPacket(leaveId, user));
|
||||||
Events.AddEvent(leaveId, "chan:leave", oldChan.Name, user.UserId, user.UserName, user.Colour, user.Rank, user.NickName, user.Permissions, null, StoredEventFlags.Log);
|
Events.AddEvent(leaveId, "chan:leave", oldChan.Name, user.UserId, user.UserName, user.Colour, user.Rank, user.NickName, user.Permissions, null, StoredEventFlags.Log);
|
||||||
|
|
||||||
long joinId = RandomSnowflake.Next();
|
long joinId = RandomSnowflake.Next();
|
||||||
SendTo(chan, new UserChannelJoinPacket(joinId, user));
|
SendTo(chan, new UserChannelJoinS2CPacket(joinId, user));
|
||||||
Events.AddEvent(joinId, "chan:join", chan.Name, user.UserId, user.UserName, user.Colour, user.Rank, user.NickName, user.Permissions, null, StoredEventFlags.Log);
|
Events.AddEvent(joinId, "chan:join", chan.Name, user.UserId, user.UserName, user.Colour, user.Rank, user.NickName, user.Permissions, null, StoredEventFlags.Log);
|
||||||
|
|
||||||
SendTo(user, new ContextClearPacket(ContextClearMode.MessagesUsers));
|
SendTo(user, new ContextClearS2CPacket(ContextClearMode.MessagesUsers));
|
||||||
SendTo(user, new ContextUsersPacket(GetChannelUsers(chan).Except([user]).OrderByDescending(u => u.Rank)));
|
SendTo(user, new ContextUsersS2CPacket(GetChannelUsers(chan).Except([user]).OrderByDescending(u => u.Rank)));
|
||||||
|
|
||||||
foreach(StoredEventInfo msg in Events.GetChannelEventLog(chan.Name))
|
foreach(StoredEventInfo msg in Events.GetChannelEventLog(chan.Name))
|
||||||
SendTo(user, new ContextMessagePacket(msg));
|
SendTo(user, new ContextMessageS2CPacket(msg));
|
||||||
|
|
||||||
ForceChannel(user, chan);
|
ForceChannel(user, chan);
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ namespace SharpChat {
|
||||||
RemoveChannel(oldChan);
|
RemoveChannel(oldChan);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Send(IServerPacket packet) {
|
public void Send(S2CPacket packet) {
|
||||||
ArgumentNullException.ThrowIfNull(packet);
|
ArgumentNullException.ThrowIfNull(packet);
|
||||||
|
|
||||||
foreach(ChatConnection conn in Connections)
|
foreach(ChatConnection conn in Connections)
|
||||||
|
@ -309,7 +309,7 @@ namespace SharpChat {
|
||||||
conn.Send(packet);
|
conn.Send(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendTo(ChatUser user, IServerPacket packet) {
|
public void SendTo(ChatUser user, S2CPacket packet) {
|
||||||
ArgumentNullException.ThrowIfNull(user);
|
ArgumentNullException.ThrowIfNull(user);
|
||||||
ArgumentNullException.ThrowIfNull(packet);
|
ArgumentNullException.ThrowIfNull(packet);
|
||||||
|
|
||||||
|
@ -318,7 +318,7 @@ namespace SharpChat {
|
||||||
conn.Send(packet);
|
conn.Send(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendTo(ChatChannel channel, IServerPacket packet) {
|
public void SendTo(ChatChannel channel, S2CPacket packet) {
|
||||||
ArgumentNullException.ThrowIfNull(channel);
|
ArgumentNullException.ThrowIfNull(channel);
|
||||||
ArgumentNullException.ThrowIfNull(packet);
|
ArgumentNullException.ThrowIfNull(packet);
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ namespace SharpChat {
|
||||||
conn.Send(packet);
|
conn.Send(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendToUserChannels(ChatUser user, IServerPacket packet) {
|
public void SendToUserChannels(ChatUser user, S2CPacket packet) {
|
||||||
ArgumentNullException.ThrowIfNull(user);
|
ArgumentNullException.ThrowIfNull(user);
|
||||||
ArgumentNullException.ThrowIfNull(packet);
|
ArgumentNullException.ThrowIfNull(packet);
|
||||||
|
|
||||||
|
@ -348,7 +348,7 @@ namespace SharpChat {
|
||||||
if(chan == null && !UserLastChannel.TryGetValue(user.UserId, out chan))
|
if(chan == null && !UserLastChannel.TryGetValue(user.UserId, out chan))
|
||||||
throw new ArgumentException("no channel???");
|
throw new ArgumentException("no channel???");
|
||||||
|
|
||||||
SendTo(user, new UserChannelForceJoinPacket(chan));
|
SendTo(user, new UserChannelForceJoinS2CPacket(chan));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateChannel(ChatChannel channel, bool? temporary = null, int? hierarchy = null, string? password = null) {
|
public void UpdateChannel(ChatChannel channel, bool? temporary = null, int? hierarchy = null, string? password = null) {
|
||||||
|
@ -367,7 +367,7 @@ namespace SharpChat {
|
||||||
|
|
||||||
// TODO: Users that no longer have access to the channel/gained access to the channel by the hierarchy change should receive delete and create packets respectively
|
// TODO: Users that no longer have access to the channel/gained access to the channel by the hierarchy change should receive delete and create packets respectively
|
||||||
foreach(ChatUser user in Users.Where(u => u.Rank >= channel.Rank)) {
|
foreach(ChatUser user in Users.Where(u => u.Rank >= channel.Rank)) {
|
||||||
SendTo(user, new ChannelUpdatePacket(channel.Name, channel));
|
SendTo(user, new ChannelUpdateS2CPacket(channel.Name, channel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ namespace SharpChat {
|
||||||
|
|
||||||
// Broadcast deletion of channel
|
// Broadcast deletion of channel
|
||||||
foreach(ChatUser user in Users.Where(u => u.Rank >= channel.Rank))
|
foreach(ChatUser user in Users.Where(u => u.Rank >= channel.Rank))
|
||||||
SendTo(user, new ChannelDeletePacket(channel));
|
SendTo(user, new ChannelDeleteS2CPacket(channel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using SharpChat.Misuzu;
|
using SharpChat.Misuzu;
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
public class BanListCommand(MisuzuClient msz) : IChatCommand {
|
public class BanListCommand(MisuzuClient msz) : IChatCommand {
|
||||||
|
@ -14,7 +14,7 @@ namespace SharpChat.Commands {
|
||||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||||
|
|
||||||
if(!ctx.User.Can(ChatUserPermissions.BanUser | ChatUserPermissions.KickUser)) {
|
if(!ctx.User.Can(ChatUserPermissions.BanUser | ChatUserPermissions.KickUser)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ namespace SharpChat.Commands {
|
||||||
MisuzuBanInfo[]? mbi = await Misuzu.GetBanListAsync();
|
MisuzuBanInfo[]? mbi = await Misuzu.GetBanListAsync();
|
||||||
|
|
||||||
if(mbi is null)
|
if(mbi is null)
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.GENERIC_ERROR, true));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.GENERIC_ERROR, true));
|
||||||
else
|
else
|
||||||
ctx.Chat.SendTo(ctx.User, new BanListPacket(msgId, mbi));
|
ctx.Chat.SendTo(ctx.User, new BanListS2CPacket(msgId, mbi));
|
||||||
}).Wait();
|
}).Wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using SharpChat.Events;
|
using SharpChat.Events;
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
public class BroadcastCommand : IChatCommand {
|
public class BroadcastCommand : IChatCommand {
|
||||||
|
@ -12,7 +12,7 @@ namespace SharpChat.Commands {
|
||||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||||
|
|
||||||
if(!ctx.User.Can(ChatUserPermissions.Broadcast)) {
|
if(!ctx.User.Can(ChatUserPermissions.Broadcast)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
public class CreateChannelCommand : IChatCommand {
|
public class CreateChannelCommand : IChatCommand {
|
||||||
|
@ -10,7 +10,7 @@ namespace SharpChat.Commands {
|
||||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||||
|
|
||||||
if(!ctx.User.Can(ChatUserPermissions.CreateChannel)) {
|
if(!ctx.User.Can(ChatUserPermissions.CreateChannel)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ namespace SharpChat.Commands {
|
||||||
|
|
||||||
bool createChanHasHierarchy;
|
bool createChanHasHierarchy;
|
||||||
if(ctx.Args.Length < 1 || (createChanHasHierarchy = firstArg.All(char.IsDigit) && ctx.Args.Length < 2)) {
|
if(ctx.Args.Length < 1 || (createChanHasHierarchy = firstArg.All(char.IsDigit) && ctx.Args.Length < 2)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_FORMAT_ERROR));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_FORMAT_ERROR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,19 +28,19 @@ namespace SharpChat.Commands {
|
||||||
createChanHierarchy = 0;
|
createChanHierarchy = 0;
|
||||||
|
|
||||||
if(createChanHierarchy > ctx.User.Rank) {
|
if(createChanHierarchy > ctx.User.Rank) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.INSUFFICIENT_HIERARCHY));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.INSUFFICIENT_HIERARCHY));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string createChanName = string.Join('_', ctx.Args.Skip(createChanHasHierarchy ? 1 : 0));
|
string createChanName = string.Join('_', ctx.Args.Skip(createChanHasHierarchy ? 1 : 0));
|
||||||
|
|
||||||
if(!ChatChannel.CheckName(createChanName)) {
|
if(!ChatChannel.CheckName(createChanName)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.CHANNEL_NAME_INVALID));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.CHANNEL_NAME_INVALID));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ctx.Chat.Channels.Any(c => c.NameEquals(createChanName))) {
|
if(ctx.Chat.Channels.Any(c => c.NameEquals(createChanName))) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.CHANNEL_ALREADY_EXISTS, true, createChanName));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.CHANNEL_ALREADY_EXISTS, true, createChanName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,10 +53,10 @@ namespace SharpChat.Commands {
|
||||||
|
|
||||||
ctx.Chat.Channels.Add(createChan);
|
ctx.Chat.Channels.Add(createChan);
|
||||||
foreach(ChatUser ccu in ctx.Chat.Users.Where(u => u.Rank >= ctx.Channel.Rank))
|
foreach(ChatUser ccu in ctx.Chat.Users.Where(u => u.Rank >= ctx.Channel.Rank))
|
||||||
ctx.Chat.SendTo(ccu, new ChannelCreatePacket(ctx.Channel));
|
ctx.Chat.SendTo(ccu, new ChannelCreateS2CPacket(ctx.Channel));
|
||||||
|
|
||||||
ctx.Chat.SwitchChannel(ctx.User, createChan, createChan.Password);
|
ctx.Chat.SwitchChannel(ctx.User, createChan, createChan.Password);
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.CHANNEL_CREATED, false, createChan.Name));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.CHANNEL_CREATED, false, createChan.Name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
public class DeleteChannelCommand : IChatCommand {
|
public class DeleteChannelCommand : IChatCommand {
|
||||||
|
@ -13,7 +13,7 @@ namespace SharpChat.Commands {
|
||||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||||
|
|
||||||
if(ctx.Args.Length < 1 || string.IsNullOrWhiteSpace(ctx.Args.FirstOrDefault())) {
|
if(ctx.Args.Length < 1 || string.IsNullOrWhiteSpace(ctx.Args.FirstOrDefault())) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_FORMAT_ERROR));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_FORMAT_ERROR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,17 +21,17 @@ namespace SharpChat.Commands {
|
||||||
ChatChannel? delChan = ctx.Chat.Channels.FirstOrDefault(c => c.NameEquals(delChanName));
|
ChatChannel? delChan = ctx.Chat.Channels.FirstOrDefault(c => c.NameEquals(delChanName));
|
||||||
|
|
||||||
if(delChan == null) {
|
if(delChan == null) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.CHANNEL_NOT_FOUND, true, delChanName));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.CHANNEL_NOT_FOUND, true, delChanName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ctx.User.Can(ChatUserPermissions.DeleteChannel) && delChan.IsOwner(ctx.User)) {
|
if(!ctx.User.Can(ChatUserPermissions.DeleteChannel) && delChan.IsOwner(ctx.User)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.CHANNEL_DELETE_FAILED, true, delChan.Name));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.CHANNEL_DELETE_FAILED, true, delChan.Name));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Chat.RemoveChannel(delChan);
|
ctx.Chat.RemoveChannel(delChan);
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.CHANNEL_DELETED, false, delChan.Name));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.CHANNEL_DELETED, false, delChan.Name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using SharpChat.EventStorage;
|
using SharpChat.EventStorage;
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.Commands
|
namespace SharpChat.Commands
|
||||||
{
|
{
|
||||||
|
@ -16,26 +16,26 @@ namespace SharpChat.Commands
|
||||||
bool deleteAnyMessage = ctx.User.Can(ChatUserPermissions.DeleteAnyMessage);
|
bool deleteAnyMessage = ctx.User.Can(ChatUserPermissions.DeleteAnyMessage);
|
||||||
|
|
||||||
if(!deleteAnyMessage && !ctx.User.Can(ChatUserPermissions.DeleteOwnMessage)) {
|
if(!deleteAnyMessage && !ctx.User.Can(ChatUserPermissions.DeleteOwnMessage)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string? firstArg = ctx.Args.FirstOrDefault();
|
string? firstArg = ctx.Args.FirstOrDefault();
|
||||||
|
|
||||||
if(string.IsNullOrWhiteSpace(firstArg) || !firstArg.All(char.IsDigit) || !long.TryParse(firstArg, out long delSeqId)) {
|
if(string.IsNullOrWhiteSpace(firstArg) || !firstArg.All(char.IsDigit) || !long.TryParse(firstArg, out long delSeqId)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_FORMAT_ERROR));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_FORMAT_ERROR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StoredEventInfo? delMsg = ctx.Chat.Events.GetEvent(delSeqId);
|
StoredEventInfo? delMsg = ctx.Chat.Events.GetEvent(delSeqId);
|
||||||
|
|
||||||
if(delMsg?.Sender is null || delMsg.Sender.Rank > ctx.User.Rank || (!deleteAnyMessage && delMsg.Sender.UserId != ctx.User.UserId)) {
|
if(delMsg?.Sender is null || delMsg.Sender.Rank > ctx.User.Rank || (!deleteAnyMessage && delMsg.Sender.UserId != ctx.User.UserId)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.MESSAGE_DELETE_ERROR));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.MESSAGE_DELETE_ERROR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Chat.Events.RemoveEvent(delMsg);
|
ctx.Chat.Events.RemoveEvent(delMsg);
|
||||||
ctx.Chat.Send(new ChatMessageDeletePacket(delMsg.Id));
|
ctx.Chat.Send(new ChatMessageDeleteS2CPacket(delMsg.Id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
public class JoinChannelCommand : IChatCommand {
|
public class JoinChannelCommand : IChatCommand {
|
||||||
|
@ -12,7 +12,7 @@ namespace SharpChat.Commands {
|
||||||
ChatChannel? joinChan = ctx.Chat.Channels.FirstOrDefault(c => c.NameEquals(joinChanStr));
|
ChatChannel? joinChan = ctx.Chat.Channels.FirstOrDefault(c => c.NameEquals(joinChanStr));
|
||||||
|
|
||||||
if(joinChan is null) {
|
if(joinChan is null) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.CHANNEL_NOT_FOUND, true, joinChanStr));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.CHANNEL_NOT_FOUND, true, joinChanStr));
|
||||||
ctx.Chat.ForceChannel(ctx.User);
|
ctx.Chat.ForceChannel(ctx.User);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using SharpChat.Misuzu;
|
using SharpChat.Misuzu;
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
public class KickBanCommand(MisuzuClient msz) : IChatCommand {
|
public class KickBanCommand(MisuzuClient msz) : IChatCommand {
|
||||||
|
@ -15,7 +15,7 @@ namespace SharpChat.Commands {
|
||||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||||
|
|
||||||
if(!ctx.User.Can(isBanning ? ChatUserPermissions.BanUser : ChatUserPermissions.KickUser)) {
|
if(!ctx.User.Can(isBanning ? ChatUserPermissions.BanUser : ChatUserPermissions.KickUser)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,19 +25,19 @@ namespace SharpChat.Commands {
|
||||||
ChatUser? banUser = null;
|
ChatUser? banUser = null;
|
||||||
|
|
||||||
if(banUserTarget == null || (banUser = ctx.Chat.Users.FirstOrDefault(u => u.NameEquals(banUserTarget))) == null) {
|
if(banUserTarget == null || (banUser = ctx.Chat.Users.FirstOrDefault(u => u.NameEquals(banUserTarget))) == null) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.USER_NOT_FOUND, true, banUserTarget ?? "User"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_NOT_FOUND, true, banUserTarget ?? "User"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ctx.User.IsSuper && banUser.Rank >= ctx.User.Rank && banUser != ctx.User) {
|
if(!ctx.User.IsSuper && banUser.Rank >= ctx.User.Rank && banUser != ctx.User) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.KICK_NOT_ALLOWED, true, banUser.LegacyName));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.KICK_NOT_ALLOWED, true, banUser.LegacyName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeSpan duration = isBanning ? TimeSpan.MaxValue : TimeSpan.Zero;
|
TimeSpan duration = isBanning ? TimeSpan.MaxValue : TimeSpan.Zero;
|
||||||
if(!string.IsNullOrWhiteSpace(banDurationStr) && double.TryParse(banDurationStr, out double durationSeconds)) {
|
if(!string.IsNullOrWhiteSpace(banDurationStr) && double.TryParse(banDurationStr, out double durationSeconds)) {
|
||||||
if(durationSeconds < 0) {
|
if(durationSeconds < 0) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_FORMAT_ERROR));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_FORMAT_ERROR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,12 +59,12 @@ namespace SharpChat.Commands {
|
||||||
// obviously it makes no sense to only check for one ip address but that's current misuzu limitations
|
// obviously it makes no sense to only check for one ip address but that's current misuzu limitations
|
||||||
MisuzuBanInfo? fbi = await Misuzu.CheckBanAsync(userId, userIp);
|
MisuzuBanInfo? fbi = await Misuzu.CheckBanAsync(userId, userIp);
|
||||||
if(fbi is null) {
|
if(fbi is null) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.GENERIC_ERROR, true));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.GENERIC_ERROR, true));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fbi.IsBanned && !fbi.HasExpired) {
|
if(fbi.IsBanned && !fbi.HasExpired) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.KICK_NOT_ALLOWED, true, banUser.LegacyName));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.KICK_NOT_ALLOWED, true, banUser.LegacyName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ namespace SharpChat.Commands {
|
||||||
bool setOthersNick = ctx.User.Can(ChatUserPermissions.SetOthersNickname);
|
bool setOthersNick = ctx.User.Can(ChatUserPermissions.SetOthersNickname);
|
||||||
|
|
||||||
if(!setOthersNick && !ctx.User.Can(ChatUserPermissions.SetOwnNickname)) {
|
if(!setOthersNick && !ctx.User.Can(ChatUserPermissions.SetOwnNickname)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ namespace SharpChat.Commands {
|
||||||
targetUser ??= ctx.User;
|
targetUser ??= ctx.User;
|
||||||
|
|
||||||
if(ctx.Args.Length < offset) {
|
if(ctx.Args.Length < offset) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_FORMAT_ERROR));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_FORMAT_ERROR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ namespace SharpChat.Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!string.IsNullOrWhiteSpace(nickStr) && ctx.Chat.Users.Any(u => u.NameEquals(nickStr))) {
|
if(!string.IsNullOrWhiteSpace(nickStr) && ctx.Chat.Users.Any(u => u.NameEquals(nickStr))) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.NAME_IN_USE, true, nickStr));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.NAME_IN_USE, true, nickStr));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using SharpChat.Misuzu;
|
using SharpChat.Misuzu;
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
|
@ -15,13 +15,13 @@ namespace SharpChat.Commands {
|
||||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||||
|
|
||||||
if(!ctx.User.Can(ChatUserPermissions.BanUser | ChatUserPermissions.KickUser)) {
|
if(!ctx.User.Can(ChatUserPermissions.BanUser | ChatUserPermissions.KickUser)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string? unbanAddrTarget = ctx.Args.FirstOrDefault();
|
string? unbanAddrTarget = ctx.Args.FirstOrDefault();
|
||||||
if(string.IsNullOrWhiteSpace(unbanAddrTarget) || !IPAddress.TryParse(unbanAddrTarget, out IPAddress? unbanAddr)) {
|
if(string.IsNullOrWhiteSpace(unbanAddrTarget) || !IPAddress.TryParse(unbanAddrTarget, out IPAddress? unbanAddr)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_FORMAT_ERROR));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_FORMAT_ERROR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,20 +30,20 @@ namespace SharpChat.Commands {
|
||||||
Task.Run(async () => {
|
Task.Run(async () => {
|
||||||
MisuzuBanInfo? banInfo = await Misuzu.CheckBanAsync(ipAddr: unbanAddrTarget);
|
MisuzuBanInfo? banInfo = await Misuzu.CheckBanAsync(ipAddr: unbanAddrTarget);
|
||||||
if(banInfo is null) {
|
if(banInfo is null) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.GENERIC_ERROR, true));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.GENERIC_ERROR, true));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!banInfo.IsBanned || banInfo.HasExpired) {
|
if(!banInfo.IsBanned || banInfo.HasExpired) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.USER_NOT_BANNED, true, unbanAddrTarget));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_NOT_BANNED, true, unbanAddrTarget));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wasBanned = await Misuzu.RevokeBanAsync(banInfo, MisuzuClient.BanRevokeKind.RemoteAddress);
|
bool wasBanned = await Misuzu.RevokeBanAsync(banInfo, MisuzuClient.BanRevokeKind.RemoteAddress);
|
||||||
if(wasBanned)
|
if(wasBanned)
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.USER_UNBANNED, false, unbanAddrTarget));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_UNBANNED, false, unbanAddrTarget));
|
||||||
else
|
else
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.USER_NOT_BANNED, true, unbanAddrTarget));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_NOT_BANNED, true, unbanAddrTarget));
|
||||||
}).Wait();
|
}).Wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using SharpChat.Misuzu;
|
using SharpChat.Misuzu;
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
public class PardonUserCommand(MisuzuClient msz) : IChatCommand {
|
public class PardonUserCommand(MisuzuClient msz) : IChatCommand {
|
||||||
|
@ -14,14 +14,14 @@ namespace SharpChat.Commands {
|
||||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||||
|
|
||||||
if(!ctx.User.Can(ChatUserPermissions.BanUser | ChatUserPermissions.KickUser)) {
|
if(!ctx.User.Can(ChatUserPermissions.BanUser | ChatUserPermissions.KickUser)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool unbanUserTargetIsName = true;
|
bool unbanUserTargetIsName = true;
|
||||||
string? unbanUserTarget = ctx.Args.FirstOrDefault();
|
string? unbanUserTarget = ctx.Args.FirstOrDefault();
|
||||||
if(string.IsNullOrWhiteSpace(unbanUserTarget)) {
|
if(string.IsNullOrWhiteSpace(unbanUserTarget)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_FORMAT_ERROR));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_FORMAT_ERROR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,20 +37,20 @@ namespace SharpChat.Commands {
|
||||||
Task.Run(async () => {
|
Task.Run(async () => {
|
||||||
MisuzuBanInfo? banInfo = await Misuzu.CheckBanAsync(unbanUserTarget, userIdIsName: unbanUserTargetIsName);
|
MisuzuBanInfo? banInfo = await Misuzu.CheckBanAsync(unbanUserTarget, userIdIsName: unbanUserTargetIsName);
|
||||||
if(banInfo is null) {
|
if(banInfo is null) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.GENERIC_ERROR, true));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.GENERIC_ERROR, true));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!banInfo.IsBanned || banInfo.HasExpired) {
|
if(!banInfo.IsBanned || banInfo.HasExpired) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.USER_NOT_BANNED, true, unbanUserTarget));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_NOT_BANNED, true, unbanUserTarget));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wasBanned = await Misuzu.RevokeBanAsync(banInfo, MisuzuClient.BanRevokeKind.UserId);
|
bool wasBanned = await Misuzu.RevokeBanAsync(banInfo, MisuzuClient.BanRevokeKind.UserId);
|
||||||
if(wasBanned)
|
if(wasBanned)
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.USER_UNBANNED, false, unbanUserTarget));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_UNBANNED, false, unbanUserTarget));
|
||||||
else
|
else
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.USER_NOT_BANNED, true, unbanUserTarget));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_NOT_BANNED, true, unbanUserTarget));
|
||||||
}).Wait();
|
}).Wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
public class PasswordChannelCommand : IChatCommand {
|
public class PasswordChannelCommand : IChatCommand {
|
||||||
|
@ -11,7 +11,7 @@ namespace SharpChat.Commands {
|
||||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||||
|
|
||||||
if(!ctx.User.Can(ChatUserPermissions.SetChannelPassword) || ctx.Channel.IsOwner(ctx.User)) {
|
if(!ctx.User.Can(ChatUserPermissions.SetChannelPassword) || ctx.Channel.IsOwner(ctx.User)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ namespace SharpChat.Commands {
|
||||||
chanPass = string.Empty;
|
chanPass = string.Empty;
|
||||||
|
|
||||||
ctx.Chat.UpdateChannel(ctx.Channel, password: chanPass);
|
ctx.Chat.UpdateChannel(ctx.Channel, password: chanPass);
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.CHANNEL_PASSWORD_CHANGED, false));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.CHANNEL_PASSWORD_CHANGED, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
public class RankChannelCommand : IChatCommand {
|
public class RankChannelCommand : IChatCommand {
|
||||||
|
@ -12,17 +12,17 @@ namespace SharpChat.Commands {
|
||||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||||
|
|
||||||
if(!ctx.User.Can(ChatUserPermissions.SetChannelHierarchy) || ctx.Channel.IsOwner(ctx.User)) {
|
if(!ctx.User.Can(ChatUserPermissions.SetChannelHierarchy) || ctx.Channel.IsOwner(ctx.User)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ctx.Args.Length < 1 || !int.TryParse(ctx.Args.First(), out int chanHierarchy) || chanHierarchy > ctx.User.Rank) {
|
if(ctx.Args.Length < 1 || !int.TryParse(ctx.Args.First(), out int chanHierarchy) || chanHierarchy > ctx.User.Rank) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.INSUFFICIENT_HIERARCHY));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.INSUFFICIENT_HIERARCHY));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Chat.UpdateChannel(ctx.Channel, hierarchy: chanHierarchy);
|
ctx.Chat.UpdateChannel(ctx.Channel, hierarchy: chanHierarchy);
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.CHANNEL_HIERARCHY_CHANGED, false));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.CHANNEL_HIERARCHY_CHANGED, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
|
@ -12,7 +12,7 @@ namespace SharpChat.Commands {
|
||||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||||
|
|
||||||
if(!ctx.User.Can(ChatUserPermissions.SeeIPAddress)) {
|
if(!ctx.User.Can(ChatUserPermissions.SeeIPAddress)) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_NOT_ALLOWED, true, "/ip"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, "/ip"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,12 +20,12 @@ namespace SharpChat.Commands {
|
||||||
ChatUser? ipUser = null;
|
ChatUser? ipUser = null;
|
||||||
|
|
||||||
if(string.IsNullOrWhiteSpace(ipUserStr) || (ipUser = ctx.Chat.Users.FirstOrDefault(u => u.NameEquals(ipUserStr))) == null) {
|
if(string.IsNullOrWhiteSpace(ipUserStr) || (ipUser = ctx.Chat.Users.FirstOrDefault(u => u.NameEquals(ipUserStr))) == null) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.USER_NOT_FOUND, true, ipUserStr ?? "User"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_NOT_FOUND, true, ipUserStr ?? "User"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(IPAddress ip in ctx.Chat.GetRemoteAddresses(ipUser))
|
foreach(IPAddress ip in ctx.Chat.GetRemoteAddresses(ipUser))
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.IP_ADDRESS, false, ipUser.UserName, ip));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.IP_ADDRESS, false, ipUser.UserName, ip));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
public class ShutdownRestartCommand(ManualResetEvent waitHandle, Func<bool> shutdownCheck) : IChatCommand {
|
public class ShutdownRestartCommand(ManualResetEvent waitHandle, Func<bool> shutdownCheck) : IChatCommand {
|
||||||
|
@ -13,7 +13,7 @@ namespace SharpChat.Commands {
|
||||||
public void Dispatch(ChatCommandContext ctx) {
|
public void Dispatch(ChatCommandContext ctx) {
|
||||||
if(ctx.User.UserId != 1) {
|
if(ctx.User.UserId != 1) {
|
||||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using SharpChat.Events;
|
using SharpChat.Events;
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
public class WhisperCommand : IChatCommand {
|
public class WhisperCommand : IChatCommand {
|
||||||
|
@ -12,7 +12,7 @@ namespace SharpChat.Commands {
|
||||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||||
|
|
||||||
if(ctx.Args.Length < 2) {
|
if(ctx.Args.Length < 2) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.COMMAND_FORMAT_ERROR));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_FORMAT_ERROR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ namespace SharpChat.Commands {
|
||||||
ChatUser? whisperUser = ctx.Chat.Users.FirstOrDefault(u => u.NameEquals(whisperUserStr));
|
ChatUser? whisperUser = ctx.Chat.Users.FirstOrDefault(u => u.NameEquals(whisperUserStr));
|
||||||
|
|
||||||
if(whisperUser == null) {
|
if(whisperUser == null) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.USER_NOT_FOUND, true, whisperUserStr));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_NOT_FOUND, true, whisperUserStr));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Commands {
|
namespace SharpChat.Commands {
|
||||||
|
@ -27,17 +27,17 @@ namespace SharpChat.Commands {
|
||||||
if(whoChanSB.Length > 2)
|
if(whoChanSB.Length > 2)
|
||||||
whoChanSB.Length -= 2;
|
whoChanSB.Length -= 2;
|
||||||
|
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.USERS_LISTING_SERVER, false, whoChanSB));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USERS_LISTING_SERVER, false, whoChanSB));
|
||||||
} else {
|
} else {
|
||||||
ChatChannel? whoChan = ctx.Chat.Channels.FirstOrDefault(c => c.NameEquals(whoChanStr));
|
ChatChannel? whoChan = ctx.Chat.Channels.FirstOrDefault(c => c.NameEquals(whoChanStr));
|
||||||
|
|
||||||
if(whoChan is null) {
|
if(whoChan is null) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.CHANNEL_NOT_FOUND, true, whoChanStr));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.CHANNEL_NOT_FOUND, true, whoChanStr));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(whoChan.Rank > ctx.User.Rank || (whoChan.HasPassword && !ctx.User.Can(ChatUserPermissions.JoinAnyChannel))) {
|
if(whoChan.Rank > ctx.User.Rank || (whoChan.HasPassword && !ctx.User.Can(ChatUserPermissions.JoinAnyChannel))) {
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.USERS_LISTING_ERROR, true, whoChanStr));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USERS_LISTING_ERROR, true, whoChanStr));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ namespace SharpChat.Commands {
|
||||||
if(whoChanSB.Length > 2)
|
if(whoChanSB.Length > 2)
|
||||||
whoChanSB.Length -= 2;
|
whoChanSB.Length -= 2;
|
||||||
|
|
||||||
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.USERS_LISTING_CHANNEL, false, whoChan.Name, whoChanSB));
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USERS_LISTING_CHANNEL, false, whoChan.Name, whoChanSB));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
namespace SharpChat {
|
namespace SharpChat {
|
||||||
public interface IServerPacket {
|
public interface S2CPacket {
|
||||||
IEnumerable<string> Pack();
|
IEnumerable<string> Pack();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,18 +1,18 @@
|
||||||
using SharpChat.Misuzu;
|
using SharpChat.Misuzu;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public enum AuthFailReason {
|
public enum AuthFailReason {
|
||||||
AuthInvalid,
|
AuthInvalid,
|
||||||
MaxSessions,
|
MaxSessions,
|
||||||
Banned,
|
Banned,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AuthFailPacket : IServerPacket {
|
public class AuthFailS2CPacket : S2CPacket {
|
||||||
public AuthFailReason Reason { get; private set; }
|
public AuthFailReason Reason { get; private set; }
|
||||||
public MisuzuBanInfo? BanInfo { get; private set; }
|
public MisuzuBanInfo? BanInfo { get; private set; }
|
||||||
|
|
||||||
public AuthFailPacket(AuthFailReason reason, MisuzuBanInfo? fbi = null) {
|
public AuthFailS2CPacket(AuthFailReason reason, MisuzuBanInfo? fbi = null) {
|
||||||
Reason = reason;
|
Reason = reason;
|
||||||
|
|
||||||
if(reason == AuthFailReason.Banned)
|
if(reason == AuthFailReason.Banned)
|
|
@ -1,11 +1,11 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class AuthSuccessPacket(
|
public class AuthSuccessS2CPacket(
|
||||||
ChatUser user,
|
ChatUser user,
|
||||||
ChatChannel channel,
|
ChatChannel channel,
|
||||||
int maxMsgLength
|
int maxMsgLength
|
||||||
) : IServerPacket {
|
) : S2CPacket {
|
||||||
public ChatUser User { get; private set; } = user ?? throw new ArgumentNullException(nameof(user));
|
public ChatUser User { get; private set; } = user ?? throw new ArgumentNullException(nameof(user));
|
||||||
public ChatChannel Channel { get; private set; } = channel ?? throw new ArgumentNullException(nameof(channel));
|
public ChatChannel Channel { get; private set; } = channel ?? throw new ArgumentNullException(nameof(channel));
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
using SharpChat.Misuzu;
|
using SharpChat.Misuzu;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class BanListPacket(
|
public class BanListS2CPacket(
|
||||||
long msgId,
|
long msgId,
|
||||||
IEnumerable<MisuzuBanInfo> bans
|
IEnumerable<MisuzuBanInfo> bans
|
||||||
) : IServerPacket {
|
) : S2CPacket {
|
||||||
public IEnumerable<MisuzuBanInfo> Bans { get; private set; } = bans ?? throw new ArgumentNullException(nameof(bans));
|
public IEnumerable<MisuzuBanInfo> Bans { get; private set; } = bans ?? throw new ArgumentNullException(nameof(bans));
|
||||||
|
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class ChannelCreatePacket(ChatChannel channel) : IServerPacket {
|
public class ChannelCreateS2CPacket(ChatChannel channel) : S2CPacket {
|
||||||
public ChatChannel Channel { get; private set; } = channel ?? throw new ArgumentNullException(nameof(channel));
|
public ChatChannel Channel { get; private set; } = channel ?? throw new ArgumentNullException(nameof(channel));
|
||||||
|
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class ChannelDeletePacket(ChatChannel channel) : IServerPacket {
|
public class ChannelDeleteS2CPacket(ChatChannel channel) : S2CPacket {
|
||||||
public ChatChannel Channel { get; private set; } = channel ?? throw new ArgumentNullException(nameof(channel));
|
public ChatChannel Channel { get; private set; } = channel ?? throw new ArgumentNullException(nameof(channel));
|
||||||
|
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class ChannelUpdatePacket(string previousName, ChatChannel channel) : IServerPacket {
|
public class ChannelUpdateS2CPacket(string previousName, ChatChannel channel) : S2CPacket {
|
||||||
public string PreviousName { get; private set; } = previousName ?? throw new ArgumentNullException(nameof(previousName));
|
public string PreviousName { get; private set; } = previousName ?? throw new ArgumentNullException(nameof(previousName));
|
||||||
public ChatChannel Channel { get; private set; } = channel ?? throw new ArgumentNullException(nameof(channel));
|
public ChatChannel Channel { get; private set; } = channel ?? throw new ArgumentNullException(nameof(channel));
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class ChatMessageAddPacket(
|
public class ChatMessageAddS2CPacket(
|
||||||
long msgId,
|
long msgId,
|
||||||
DateTimeOffset created,
|
DateTimeOffset created,
|
||||||
long userId,
|
long userId,
|
||||||
string text,
|
string text,
|
||||||
bool isAction,
|
bool isAction,
|
||||||
bool isPrivate
|
bool isPrivate
|
||||||
) : IServerPacket {
|
) : S2CPacket {
|
||||||
public string Text { get; } = text ?? throw new ArgumentNullException(nameof(text));
|
public string Text { get; } = text ?? throw new ArgumentNullException(nameof(text));
|
||||||
|
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class ChatMessageDeletePacket(long eventId) : IServerPacket {
|
public class ChatMessageDeleteS2CPacket(long eventId) : S2CPacket {
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
||||||
StringBuilder sb = new();
|
StringBuilder sb = new();
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class LegacyCommandResponse(
|
public class CommandResponseS2CPacket(
|
||||||
long msgId,
|
long msgId,
|
||||||
string stringId,
|
string stringId,
|
||||||
bool isError = true,
|
bool isError = true,
|
||||||
params object[] args
|
params object[] args
|
||||||
) : IServerPacket {
|
) : S2CPacket {
|
||||||
public string StringId { get; private set; } = stringId ?? throw new ArgumentNullException(nameof(stringId));
|
public string StringId { get; private set; } = stringId ?? throw new ArgumentNullException(nameof(stringId));
|
||||||
|
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class ContextChannelsPacket(IEnumerable<ChatChannel> channels) : IServerPacket {
|
public class ContextChannelsS2CPacket(IEnumerable<ChatChannel> channels) : S2CPacket {
|
||||||
public IEnumerable<ChatChannel> Channels { get; private set; } = channels?.Where(c => c != null) ?? throw new ArgumentNullException(nameof(channels));
|
public IEnumerable<ChatChannel> Channels { get; private set; } = channels?.Where(c => c != null) ?? throw new ArgumentNullException(nameof(channels));
|
||||||
|
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public enum ContextClearMode {
|
public enum ContextClearMode {
|
||||||
Messages = 0,
|
Messages = 0,
|
||||||
Users = 1,
|
Users = 1,
|
||||||
|
@ -9,7 +9,7 @@ namespace SharpChat.Packet {
|
||||||
MessagesUsersChannels = 4,
|
MessagesUsersChannels = 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ContextClearPacket(ContextClearMode mode) : IServerPacket {
|
public class ContextClearS2CPacket(ContextClearMode mode) : S2CPacket {
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
||||||
StringBuilder sb = new();
|
StringBuilder sb = new();
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
using SharpChat.EventStorage;
|
using SharpChat.EventStorage;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet
|
namespace SharpChat.S2CPackets
|
||||||
{
|
{
|
||||||
public class ContextMessagePacket(StoredEventInfo evt, bool notify = false) : IServerPacket {
|
public class ContextMessageS2CPacket(StoredEventInfo evt, bool notify = false) : S2CPacket {
|
||||||
public StoredEventInfo Event { get; private set; } = evt ?? throw new ArgumentNullException(nameof(evt));
|
public StoredEventInfo Event { get; private set; } = evt ?? throw new ArgumentNullException(nameof(evt));
|
||||||
|
|
||||||
private const string V1_CHATBOT = "-1\tChatBot\tinherit\t\t";
|
private const string V1_CHATBOT = "-1\tChatBot\tinherit\t\t";
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class ContextUsersPacket(IEnumerable<ChatUser> users) : IServerPacket {
|
public class ContextUsersS2CPacket(IEnumerable<ChatUser> users) : S2CPacket {
|
||||||
public IEnumerable<ChatUser> Users { get; private set; } = users?.Where(u => u != null) ?? throw new ArgumentNullException(nameof(users));
|
public IEnumerable<ChatUser> Users { get; private set; } = users?.Where(u => u != null) ?? throw new ArgumentNullException(nameof(users));
|
||||||
|
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
|
@ -1,16 +1,16 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public enum ForceDisconnectReason {
|
public enum ForceDisconnectReason {
|
||||||
Kicked = 0,
|
Kicked = 0,
|
||||||
Banned = 1,
|
Banned = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ForceDisconnectPacket : IServerPacket {
|
public class ForceDisconnectS2CPacket : S2CPacket {
|
||||||
public ForceDisconnectReason Reason { get; private set; }
|
public ForceDisconnectReason Reason { get; private set; }
|
||||||
public DateTimeOffset Expires { get; private set; }
|
public DateTimeOffset Expires { get; private set; }
|
||||||
|
|
||||||
public ForceDisconnectPacket(ForceDisconnectReason reason, DateTimeOffset? expires = null) {
|
public ForceDisconnectS2CPacket(ForceDisconnectReason reason, DateTimeOffset? expires = null) {
|
||||||
Reason = reason;
|
Reason = reason;
|
||||||
|
|
||||||
if(reason == ForceDisconnectReason.Banned) {
|
if(reason == ForceDisconnectReason.Banned) {
|
|
@ -1,5 +1,5 @@
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class PongPacket : IServerPacket {
|
public class PongS2CPacket : S2CPacket {
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
||||||
yield return "0\tpong";
|
yield return "0\tpong";
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class UserChannelForceJoinPacket(ChatChannel channel) : IServerPacket {
|
public class UserChannelForceJoinS2CPacket(ChatChannel channel) : S2CPacket {
|
||||||
public ChatChannel Channel { get; private set; } = channel ?? throw new ArgumentNullException(nameof(channel));
|
public ChatChannel Channel { get; private set; } = channel ?? throw new ArgumentNullException(nameof(channel));
|
||||||
|
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class UserChannelJoinPacket(long msgId, ChatUser user) : IServerPacket {
|
public class UserChannelJoinS2CPacket(long msgId, ChatUser user) : S2CPacket {
|
||||||
public ChatUser User { get; private set; } = user ?? throw new ArgumentNullException(nameof(user));
|
public ChatUser User { get; private set; } = user ?? throw new ArgumentNullException(nameof(user));
|
||||||
|
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class UserChannelLeavePacket(long msgId, ChatUser user) : IServerPacket {
|
public class UserChannelLeaveS2CPacket(long msgId, ChatUser user) : S2CPacket {
|
||||||
public ChatUser User { get; private set; } = user ?? throw new ArgumentNullException(nameof(user));
|
public ChatUser User { get; private set; } = user ?? throw new ArgumentNullException(nameof(user));
|
||||||
|
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class UserConnectPacket(long msgId, DateTimeOffset joined, ChatUser user) : IServerPacket {
|
public class UserConnectS2CPacket(long msgId, DateTimeOffset joined, ChatUser user) : S2CPacket {
|
||||||
public ChatUser User { get; private set; } = user ?? throw new ArgumentNullException(nameof(user));
|
public ChatUser User { get; private set; } = user ?? throw new ArgumentNullException(nameof(user));
|
||||||
|
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public enum UserDisconnectReason {
|
public enum UserDisconnectReason {
|
||||||
Leave,
|
Leave,
|
||||||
TimeOut,
|
TimeOut,
|
||||||
|
@ -8,12 +8,12 @@ namespace SharpChat.Packet {
|
||||||
Flood,
|
Flood,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UserDisconnectPacket(
|
public class UserDisconnectS2CPacket(
|
||||||
long msgId,
|
long msgId,
|
||||||
DateTimeOffset disconnected,
|
DateTimeOffset disconnected,
|
||||||
ChatUser user,
|
ChatUser user,
|
||||||
UserDisconnectReason reason
|
UserDisconnectReason reason
|
||||||
) : IServerPacket {
|
) : S2CPacket {
|
||||||
public ChatUser User { get; private set; } = user ?? throw new ArgumentNullException(nameof(user));
|
public ChatUser User { get; private set; } = user ?? throw new ArgumentNullException(nameof(user));
|
||||||
|
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SharpChat.Packet {
|
namespace SharpChat.S2CPackets {
|
||||||
public class UserUpdatePacket(long msgId, ChatUser user, string previousName = "") : IServerPacket {
|
public class UserUpdateS2CPacket(long msgId, ChatUser user, string previousName = "") : S2CPacket {
|
||||||
public ChatUser User { get; private set; } = user ?? throw new ArgumentNullException(nameof(user));
|
public ChatUser User { get; private set; } = user ?? throw new ArgumentNullException(nameof(user));
|
||||||
|
|
||||||
public IEnumerable<string> Pack() {
|
public IEnumerable<string> Pack() {
|
|
@ -3,8 +3,8 @@ using SharpChat.Commands;
|
||||||
using SharpChat.Config;
|
using SharpChat.Config;
|
||||||
using SharpChat.EventStorage;
|
using SharpChat.EventStorage;
|
||||||
using SharpChat.Misuzu;
|
using SharpChat.Misuzu;
|
||||||
using SharpChat.Packet;
|
using SharpChat.S2CPackets;
|
||||||
using SharpChat.PacketHandlers;
|
using SharpChat.C2SPacketHandlers;
|
||||||
|
|
||||||
namespace SharpChat {
|
namespace SharpChat {
|
||||||
public class SockChatServer : IDisposable {
|
public class SockChatServer : IDisposable {
|
||||||
|
@ -25,9 +25,9 @@ namespace SharpChat {
|
||||||
private readonly CachedValue<int> FloodKickLength;
|
private readonly CachedValue<int> FloodKickLength;
|
||||||
private readonly CachedValue<int> FloodKickExemptRank;
|
private readonly CachedValue<int> FloodKickExemptRank;
|
||||||
|
|
||||||
private readonly List<IChatPacketHandler> GuestHandlers = [];
|
private readonly List<C2SPacketHandler> GuestHandlers = [];
|
||||||
private readonly List<IChatPacketHandler> AuthedHandlers = [];
|
private readonly List<C2SPacketHandler> AuthedHandlers = [];
|
||||||
private readonly SendMessageHandler SendMessageHandler;
|
private readonly SendMessageC2SPacketHandler SendMessageHandler;
|
||||||
|
|
||||||
private bool IsShuttingDown = false;
|
private bool IsShuttingDown = false;
|
||||||
|
|
||||||
|
@ -70,11 +70,11 @@ namespace SharpChat {
|
||||||
if(DefaultChannel is null)
|
if(DefaultChannel is null)
|
||||||
throw new Exception("The default channel could not be determined.");
|
throw new Exception("The default channel could not be determined.");
|
||||||
|
|
||||||
GuestHandlers.Add(new AuthHandler(Misuzu, DefaultChannel, MaxMessageLength, MaxConnections));
|
GuestHandlers.Add(new AuthC2SPacketHandler(Misuzu, DefaultChannel, MaxMessageLength, MaxConnections));
|
||||||
|
|
||||||
AuthedHandlers.AddRange([
|
AuthedHandlers.AddRange([
|
||||||
new PingHandler(Misuzu),
|
new PingC2SPacketHandler(Misuzu),
|
||||||
SendMessageHandler = new SendMessageHandler(Context.RandomSnowflake, MaxMessageLength),
|
SendMessageHandler = new SendMessageC2SPacketHandler(Context.RandomSnowflake, MaxMessageLength),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
SendMessageHandler.AddCommands([
|
SendMessageHandler.AddCommands([
|
||||||
|
@ -179,7 +179,7 @@ namespace SharpChat {
|
||||||
|
|
||||||
if(banUser is not null) {
|
if(banUser is not null) {
|
||||||
if(banDuration == TimeSpan.MinValue) {
|
if(banDuration == TimeSpan.MinValue) {
|
||||||
Context.SendTo(conn.User, new LegacyCommandResponse(Context.RandomSnowflake.Next(), LCR.FLOOD_WARN, false));
|
Context.SendTo(conn.User, new CommandResponseS2CPacket(Context.RandomSnowflake.Next(), LCR.FLOOD_WARN, false));
|
||||||
} else {
|
} else {
|
||||||
Context.BanUser(conn.User, banDuration, UserDisconnectReason.Flood);
|
Context.BanUser(conn.User, banDuration, UserDisconnectReason.Flood);
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ namespace SharpChat {
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatPacketHandlerContext context = new(msg, Context, conn);
|
ChatPacketHandlerContext context = new(msg, Context, conn);
|
||||||
IChatPacketHandler? handler = conn.User is null
|
C2SPacketHandler? handler = conn.User is null
|
||||||
? GuestHandlers.FirstOrDefault(h => h.IsMatch(context))
|
? GuestHandlers.FirstOrDefault(h => h.IsMatch(context))
|
||||||
: AuthedHandlers.FirstOrDefault(h => h.IsMatch(context));
|
: AuthedHandlers.FirstOrDefault(h => h.IsMatch(context));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue