From: TerminalHash Date: Sat, 11 Mar 2023 09:26:24 +0000 (+0300) Subject: net: anti full state spam (by fgsfds) X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=0e32b76121dd532a73259cbdbf15c43ffdedd5c9;p=d2df-sdl.git net: anti full state spam (by fgsfds) --- diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 4725120..261d5e9 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -5163,6 +5163,11 @@ begin if NetMode = NET_SERVER then begin + // reset full state flags + if NetClients <> nil then + for I := 0 to High(NetClients) do + NetClients[I].FullUpdateSent := False; + MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map); // Ìàñòåðñåðâåð diff --git a/src/game/g_net.pas b/src/game/g_net.pas index a743fa1..3a233da 100644 --- a/src/game/g_net.pas +++ b/src/game/g_net.pas @@ -103,6 +103,7 @@ type Player: Word; RequestedFullUpdate: Boolean; WaitForFirstSpawn: Boolean; // set to `true` in server, used to spawn a player on first full state request + FullUpdateSent: Boolean; RCONAuth: Boolean; Voted: Boolean; Crimes: Integer; @@ -1662,6 +1663,7 @@ begin TC^.AuthTime := 0; TC^.MsgTime := 0; TC^.RequestedFullUpdate := False; + TC^.FullUpdateSent := False; TC^.WaitForFirstSpawn := False; TC^.NetOut[NET_UNRELIABLE].Free(); TC^.NetOut[NET_RELIABLE].Free(); diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index 01708c2..4c67d12 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -555,6 +555,14 @@ end; procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg); begin //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]); + + if C^.FullUpdateSent then + begin + // FullStateRequest spam? + g_Net_Penalize(C, 'duplicate full state request'); + exit; + end; + if gGameOn then begin MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID) @@ -894,11 +902,14 @@ procedure MH_SEND_Everything(CreatePlayers: Boolean {= False}; ID: Integer {= NE var I: Integer; begin - if (ID >= 0) and (ID < length(NetClients)) then - begin - e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID, NetClients[ID].Player]); - MH_ProcessFirstSpawn(@NetClients[ID]); - end; + if (ID < 0) or (ID >= Length(NetClients)) then + exit; // bogus client, this shouldn't happen + + NetClients[ID].FullUpdateSent := True; + + e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID, NetClients[ID].Player]); + + MH_ProcessFirstSpawn(@NetClients[ID]); if gPlayers <> nil then begin