Improved logging system.

This commit is contained in:
flash 2025-04-28 12:29:11 +00:00
commit 98d13ebbbb
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E
24 changed files with 202 additions and 142 deletions
SharpChat/C2SPacketHandlers

View file

@ -5,6 +5,7 @@ using SharpChat.Configuration;
using SharpChat.Messages;
using SharpChat.Snowflake;
using SharpChat.SockChat.S2CPackets;
using ZLogger;
namespace SharpChat.C2SPacketHandlers;
@ -47,7 +48,7 @@ public class AuthC2SPacketHandler(
BanInfo? banInfo = await bansClient.BanGet(authResult.UserId, ctx.Connection.RemoteAddress);
if(banInfo is not null) {
Logger.Write($"<{ctx.Connection.Id}> User is banned.");
ctx.Connection.Logger.ZLogInformation($"User {authResult.UserId} is banned.");
await ctx.Connection.Send(new AuthFailS2CPacket(AuthFailS2CPacket.Reason.Banned, banInfo.IsPermanent ? DateTimeOffset.MaxValue : banInfo.ExpiresAt));
ctx.Connection.Dispose();
return;
@ -139,12 +140,12 @@ public class AuthC2SPacketHandler(
ctx.Chat.ContextAccess.Release();
}
} catch(AuthFailedException ex) {
Logger.Write($"<{ctx.Connection.Id}> Failed to authenticate: {ex}");
ctx.Connection.Logger.ZLogWarning($"Failed to authenticate (expected): {ex}");
await ctx.Connection.Send(new AuthFailS2CPacket(AuthFailS2CPacket.Reason.AuthInvalid));
ctx.Connection.Dispose();
throw;
} catch(Exception ex) {
Logger.Write($"<{ctx.Connection.Id}> Failed to authenticate: {ex}");
ctx.Connection.Logger.ZLogError($"Failed to authenticate (unexpected): {ex}");
await ctx.Connection.Send(new AuthFailS2CPacket(AuthFailS2CPacket.Reason.Exception));
ctx.Connection.Dispose();
throw;