log all disconnects

This commit is contained in:
Elijah R 2024-01-03 19:47:02 -05:00
parent 8d809c66ba
commit d62c8ca564
2 changed files with 11 additions and 0 deletions

View file

@ -91,6 +91,7 @@ public class User
{
if (msgArr.Length < 1)
{
Utilities.Log(LogLevel.INFO, $"Kicking {_username ?? _ip.ToString()} for sending an empty message");
await Close();
return;
}
@ -209,6 +210,7 @@ public class User
if (msgArr.Length != 4 || this.vm == null || (!HasTurn() && _rank != Rank.Admin)) return;
if (KitLimiter != null && !KitLimiter.Limit())
{
Utilities.Log(LogLevel.INFO, $"Kicking {_username ?? _ip.ToString()} for kitting the VM");
await Close();
return;
}
@ -224,6 +226,7 @@ public class User
if (this.vm == null || msgArr.Length != 3 || (!HasTurn() && _rank != Rank.Admin)) return;
if (KitLimiter != null && !KitLimiter.Limit())
{
Utilities.Log(LogLevel.INFO, $"Kicking {_username ?? _ip.ToString()} for kitting the VM");
await Close();
return;
}
@ -349,6 +352,7 @@ public class User
if (_rank != Rank.Admin && (_rank != Rank.Moderator || !Program.Config.ModPermissions.Ban) || msgArr.Length < 3 || vm == null) return;
var user = vm.Users.First(u => u.Username == msgArr[2]);
if (user == null) return;
Utilities.Log(LogLevel.INFO, $"{_username ?? _ip.ToString()} banned {user.Username!}");
await user.Ban(msgArr.Length == 4 ? msgArr[3] : null);
}
break;
@ -383,6 +387,7 @@ public class User
if (_rank != Rank.Admin && (_rank != Rank.Moderator || !Program.Config.ModPermissions.Kick) || msgArr.Length != 3 || vm == null) return;
var user = vm.Users.First(u => u.Username == msgArr[2]);
if (user == null) return;
Utilities.Log(LogLevel.INFO, $"Kicked {user.Username!} by {_username}");
await user.Close();
}
break;
@ -488,6 +493,7 @@ public class User
}
else
{
Utilities.Log(LogLevel.INFO, $"Kicking {_username ?? _ip.ToString()} for not responding to NOP");
await Close();
}
}
@ -507,6 +513,7 @@ public class User
}
catch (WebSocketException ex)
{
Utilities.Log(LogLevel.INFO, $"Kicking {_username ?? _ip.ToString()} due to websocket exception: {ex.Message}");
await Close(false);
return;
}
@ -518,6 +525,7 @@ public class User
if (result.MessageType == WebSocketMessageType.Binary)
{
Utilities.Log(LogLevel.INFO, $"Kicking {_username ?? _ip.ToString()} for sending a binary message");
await Close();
}
@ -530,6 +538,7 @@ public class User
} catch (Exception ex)
{
Utilities.Log(LogLevel.DEBUG, "Failed to decode websocket message");
Utilities.Log(LogLevel.INFO, $"Kicking {_username ?? _ip.ToString()} for sending an invalid message");
await Close();
return;
}
@ -540,6 +549,7 @@ public class User
} catch (Exception ex)
{
Utilities.Log(LogLevel.DEBUG, "Failed to decode guacamole message " + msg);
Utilities.Log(LogLevel.INFO, $"Kicking {_username ?? _ip.ToString()} for sending an invalid guacamole string");
await Close();
return;
}

View file

@ -129,6 +129,7 @@ public class VM
};
user.Disconnected += async (_, _) =>
{
Utilities.Log(LogLevel.INFO, $"User {user.Username!} disconnected");
this.Users.Remove(user);
this.TurnQueue.RemoveUser(user);
user.IPData.Reset();