fixes, hopefully

This commit is contained in:
tyuXX 2026-10-10 20:48:03 +00:00
parent 7495e34ade
commit cbc24e7672
13 changed files with 449 additions and 78 deletions

View file

@ -138,14 +138,21 @@ public class ChatWebSocketManager
}
}
private static readonly JsonSerializerOptions s_envelopeJsonOptions = new()
{
PropertyNameCaseInsensitive = true
};
private async Task ProcessClientMessageAsync(ConnectedClient client, string json, CancellationToken ct)
{
try
{
var envelope = JsonSerializer.Deserialize<NetworkEnvelope>(json);
if (envelope == null) return;
var envelope = JsonSerializer.Deserialize<NetworkEnvelope>(json, s_envelopeJsonOptions);
if (envelope == null || string.IsNullOrWhiteSpace(envelope.Type)) return;
switch (envelope.Type)
string msgType = envelope.Type.Trim().ToUpperInvariant();
switch (msgType)
{
case MessageTypes.SendMessage:
var sendMsg = envelope.Unpack<SendMessagePacket>();
@ -271,7 +278,7 @@ public class ChatWebSocketManager
private async Task HandleCreateChannelAsync(ConnectedClient client, CreateChannelPacket packet, CancellationToken ct)
{
if (client.User.Role != UserRoles.Owner && client.User.Role != UserRoles.Admin)
if (!_options.AllowMemberChannelCreation && client.User.Role != UserRoles.Owner && client.User.Role != UserRoles.Admin)
{
await client.SendMessageAsync(MessageTypes.Error, new ErrorPacket { Message = "Only Admins can create channels." }, ct);
return;
@ -326,7 +333,7 @@ public class ChatWebSocketManager
private async Task HandleCommandAsync(ConnectedClient client, ExecuteCommandPacket packet, CancellationToken ct)
{
string cmd = packet.Command.TrimStart('/').ToLowerInvariant();
string cmd = (packet.Command ?? string.Empty).TrimStart('/').ToLowerInvariant();
// Check mod command interceptor first
if (CommandInterceptor != null)
@ -343,10 +350,11 @@ public class ChatWebSocketManager
switch (cmd)
{
case "help":
string createDesc = _options.AllowMemberChannelCreation ? "Create a new channel" : "Create a new channel (Admin)";
string helpText = "Available commands:\n" +
" /help - Show this help\n" +
" /join <channel> - Switch active channel\n" +
" /create <name> [topic]- Create a new channel (Admin)\n" +
$" /create <name> [topic]- {createDesc}\n" +
" /delete <name> - Delete a channel (Admin)\n" +
" /users - List all registered users\n" +
" /motd - Display message of the day";