Cleaned up Connection class a little more.
This commit is contained in:
parent
98d13ebbbb
commit
e0050a51bd
5 changed files with 7 additions and 10 deletions
SharpChat
|
@ -41,12 +41,12 @@ public class AuthC2SPacketHandler(
|
|||
|
||||
try {
|
||||
AuthResult authResult = await authClient.AuthVerify(
|
||||
ctx.Connection.RemoteAddress,
|
||||
ctx.Connection.RemoteEndPoint.Address,
|
||||
authMethod,
|
||||
authToken
|
||||
);
|
||||
|
||||
BanInfo? banInfo = await bansClient.BanGet(authResult.UserId, ctx.Connection.RemoteAddress);
|
||||
BanInfo? banInfo = await bansClient.BanGet(authResult.UserId, ctx.Connection.RemoteEndPoint.Address);
|
||||
if(banInfo is not null) {
|
||||
ctx.Connection.Logger.ZLogInformation($"User {authResult.UserId} is banned.");
|
||||
await ctx.Connection.Send(new AuthFailS2CPacket(AuthFailS2CPacket.Reason.Banned, banInfo.IsPermanent ? DateTimeOffset.MaxValue : banInfo.ExpiresAt));
|
||||
|
|
|
@ -64,7 +64,7 @@ public class KickBanClientCommand(BansClient bansClient) : ClientCommand {
|
|||
ctx.Chat.GetRemoteAddresses(banUser).FirstOrDefault() ?? IPAddress.None,
|
||||
banUser.UserId,
|
||||
banReason,
|
||||
ctx.Connection.RemoteAddress,
|
||||
ctx.Connection.RemoteEndPoint.Address,
|
||||
ctx.User.UserId
|
||||
);
|
||||
|
||||
|
|
|
@ -18,9 +18,6 @@ public class Connection(ILogger logger, IWebSocketConnection sock, IPEndPoint re
|
|||
|
||||
private int CloseCode { get; set; } = 1000;
|
||||
|
||||
public IPAddress RemoteAddress => RemoteEndPoint.Address;
|
||||
public ushort RemotePort => (ushort)RemoteEndPoint.Port;
|
||||
|
||||
public bool IsAlive => !IsDisposed && !HasTimedOut;
|
||||
|
||||
public async Task Send(S2CPacket packet) {
|
||||
|
|
|
@ -314,7 +314,7 @@ public class Context {
|
|||
}
|
||||
|
||||
public IPAddress[] GetRemoteAddresses(User user) {
|
||||
return [.. Connections.Where(c => c.IsAlive && c.User == user).Select(c => c.RemoteAddress).Distinct()];
|
||||
return [.. Connections.Where(c => c.IsAlive && c.User == user).Select(c => c.RemoteEndPoint.Address).Distinct()];
|
||||
}
|
||||
|
||||
public async Task ForceChannel(User user, Channel? chan = null) {
|
||||
|
|
|
@ -209,11 +209,11 @@ public class SockChatServer {
|
|||
if(rateLimiter.IsExceeded) {
|
||||
banDuration = TimeSpan.FromSeconds(FloodKickLength);
|
||||
banUser = conn.User;
|
||||
banAddr = conn.RemoteAddress.ToString();
|
||||
banAddr = conn.RemoteEndPoint.Address.ToString();
|
||||
conn.Logger.ZLogWarning($"Exceeded flood limit! Issuing ban with duration {banDuration} on {banAddr}/{banUser.UserId}...");
|
||||
} else if(rateLimiter.IsRisky) {
|
||||
banUser = conn.User;
|
||||
banAddr = conn.RemoteAddress.ToString();
|
||||
banAddr = conn.RemoteEndPoint.Address.ToString();
|
||||
conn.Logger.ZLogWarning($"About to exceed flood limit! Issueing warning to {banAddr}/{banUser.UserId}...");
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ public class SockChatServer {
|
|||
await BansClient.BanCreate(
|
||||
BanKind.User,
|
||||
banDuration,
|
||||
conn.RemoteAddress,
|
||||
conn.RemoteEndPoint.Address,
|
||||
conn.User.UserId,
|
||||
"Kicked from chat for flood protection.",
|
||||
IPAddress.IPv6Loopback
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue