Ban before disconnecting client

This commit is contained in:
juanjp600
2016-09-02 22:49:40 -03:00
parent 03948d5f58
commit 4b10ca21c4
2 changed files with 21 additions and 21 deletions
+20 -20
View File
@@ -554,14 +554,14 @@ namespace Barotrauma.Networking
case ClientNetObject.SYNC_IDS: case ClientNetObject.SYNC_IDS:
//TODO: might want to use a clever class for this //TODO: might want to use a clever class for this
UInt32 lastLobbyUpdID = inc.ReadUInt32(); UInt32 lastLobbyUpdID = inc.ReadUInt32();
if (lastLobbyUpdID > c.lastRecvLobbyUpdate) if (lastLobbyUpdID > c.lastRecvLobbyUpdate)
{ {
c.lastRecvLobbyUpdate = lastLobbyUpdID; c.lastRecvLobbyUpdate = lastLobbyUpdID;
} }
UInt32 lastChatID = inc.ReadUInt32(); UInt32 lastChatID = inc.ReadUInt32();
if (lastChatID > c.lastRecvChatMsgID) if (lastChatID > c.lastRecvChatMsgID)
{ {
c.lastRecvChatMsgID = lastChatID; c.lastRecvChatMsgID = lastChatID;
} }
break; break;
case ClientNetObject.CHAT_MESSAGE: case ClientNetObject.CHAT_MESSAGE:
@@ -604,36 +604,36 @@ namespace Barotrauma.Networking
private void ClientWriteLobby(Client c) private void ClientWriteLobby(Client c)
{ {
NetOutgoingMessage outmsg = server.CreateMessage(); NetOutgoingMessage outmsg = server.CreateMessage();
outmsg.Write((byte)ServerPacketHeader.UPDATE_LOBBY); outmsg.Write((byte)ServerPacketHeader.UPDATE_LOBBY);
outmsg.Write((byte)ServerNetObject.SYNC_IDS); outmsg.Write((byte)ServerNetObject.SYNC_IDS);
if (c.lastRecvLobbyUpdate<GameMain.NetLobbyScreen.LastUpdateID) if (c.lastRecvLobbyUpdate<GameMain.NetLobbyScreen.LastUpdateID)
{ {
outmsg.Write(true); outmsg.Write(true);
outmsg.WritePadBits(); outmsg.WritePadBits();
outmsg.Write(GameMain.NetLobbyScreen.LastUpdateID); outmsg.Write(GameMain.NetLobbyScreen.LastUpdateID);
outmsg.Write(GameMain.NetLobbyScreen.GetServerName()); outmsg.Write(GameMain.NetLobbyScreen.GetServerName());
outmsg.Write(GameMain.NetLobbyScreen.ServerMessage); outmsg.Write(GameMain.NetLobbyScreen.ServerMessage);
if (c.lastRecvLobbyUpdate < 1) if (c.lastRecvLobbyUpdate < 1)
{ {
var subList = GameMain.NetLobbyScreen.GetSubList(); var subList = GameMain.NetLobbyScreen.GetSubList();
outmsg.Write((UInt16)subList.Count); outmsg.Write((UInt16)subList.Count);
for (int i = 0; i < subList.Count; i++) for (int i = 0; i < subList.Count; i++)
{ {
outmsg.Write(subList[i].Name); outmsg.Write(subList[i].Name);
outmsg.Write(subList[i].MD5Hash.ToString()); outmsg.Write(subList[i].MD5Hash.ToString());
} }
} }
else else
{ {
outmsg.Write((UInt16)0); outmsg.Write((UInt16)0);
} }
} }
else else
{ {
outmsg.Write(false); outmsg.Write(false);
outmsg.WritePadBits(); outmsg.WritePadBits();
} }
outmsg.Write(c.lastSentChatMsgID); //send this to client so they know which chat messages weren't received by the server outmsg.Write(c.lastSentChatMsgID); //send this to client so they know which chat messages weren't received by the server
@@ -102,9 +102,9 @@ namespace Barotrauma.Networking
if (unauthClient.failedAttempts > 3) if (unauthClient.failedAttempts > 3)
{ {
//disconnect and ban after too many failed attempts //disconnect and ban after too many failed attempts
banList.BanPlayer("Unnamed", unauthClient.Connection.RemoteEndPoint.Address.ToString());
unauthClient.Connection.Disconnect("Too many failed login attempts. You have been automatically banned from the server."); unauthClient.Connection.Disconnect("Too many failed login attempts. You have been automatically banned from the server.");
unauthenticatedClients.Remove(unauthClient); unauthenticatedClients.Remove(unauthClient);
banList.BanPlayer("Unnamed", unauthClient.Connection.RemoteEndPoint.Address.ToString());
unauthClient = null; unauthClient = null;
return; return;
} }