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/C2SPacketHandlers
|
@ -11,27 +11,27 @@ namespace SharpChat.C2SPacketHandlers {
|
|||
) : C2SPacketHandler {
|
||||
private readonly CachedValue<int> MaxMessageLength = maxMsgLength ?? throw new ArgumentNullException(nameof(maxMsgLength));
|
||||
|
||||
private List<ChatCommand> Commands { get; } = [];
|
||||
private List<ClientCommand> Commands { get; } = [];
|
||||
|
||||
public void AddCommand(ChatCommand command) {
|
||||
public void AddCommand(ClientCommand command) {
|
||||
Commands.Add(command ?? throw new ArgumentNullException(nameof(command)));
|
||||
}
|
||||
|
||||
public void AddCommands(IEnumerable<ChatCommand> commands) {
|
||||
public void AddCommands(IEnumerable<ClientCommand> commands) {
|
||||
Commands.AddRange(commands ?? throw new ArgumentNullException(nameof(commands)));
|
||||
}
|
||||
|
||||
public bool IsMatch(ChatPacketHandlerContext ctx) {
|
||||
public bool IsMatch(C2SPacketHandlerContext ctx) {
|
||||
return ctx.CheckPacketId("2");
|
||||
}
|
||||
|
||||
public void Handle(ChatPacketHandlerContext ctx) {
|
||||
public void Handle(C2SPacketHandlerContext ctx) {
|
||||
string[] args = ctx.SplitText(3);
|
||||
|
||||
ChatUser? user = ctx.Connection.User;
|
||||
User? user = ctx.Connection.User;
|
||||
string? messageText = args.ElementAtOrDefault(2);
|
||||
|
||||
if(user == null || !user.Can(ChatUserPermissions.SendMessage) || string.IsNullOrWhiteSpace(messageText))
|
||||
if(user == null || !user.Can(UserPermissions.SendMessage) || string.IsNullOrWhiteSpace(messageText))
|
||||
return;
|
||||
|
||||
// Extra validation step, not necessary at all but enforces proper formatting in SCv1.
|
||||
|
@ -40,12 +40,12 @@ namespace SharpChat.C2SPacketHandlers {
|
|||
|
||||
ctx.Chat.ContextAccess.Wait();
|
||||
try {
|
||||
if(!ctx.Chat.UserLastChannel.TryGetValue(user.UserId, out ChatChannel? channel)
|
||||
if(!ctx.Chat.UserLastChannel.TryGetValue(user.UserId, out Channel? channel)
|
||||
&& (channel is null || !ctx.Chat.IsInChannel(user, channel)))
|
||||
return;
|
||||
|
||||
if(user.Status != ChatUserStatus.Online)
|
||||
ctx.Chat.UpdateUser(user, status: ChatUserStatus.Online);
|
||||
if(user.Status != UserStatus.Online)
|
||||
ctx.Chat.UpdateUser(user, status: UserStatus.Online);
|
||||
|
||||
int maxMsgLength = MaxMessageLength;
|
||||
StringInfo messageTextInfo = new(messageText);
|
||||
|
@ -60,8 +60,8 @@ namespace SharpChat.C2SPacketHandlers {
|
|||
#endif
|
||||
|
||||
if(messageText.StartsWith('/')) {
|
||||
ChatCommandContext context = new(messageText, ctx.Chat, user, ctx.Connection, channel);
|
||||
foreach(ChatCommand cmd in Commands)
|
||||
ClientCommandContext context = new(messageText, ctx.Chat, user, ctx.Connection, channel);
|
||||
foreach(ClientCommand cmd in Commands)
|
||||
if(cmd.IsMatch(context)) {
|
||||
cmd.Dispatch(context);
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue