From a64e75f513d36924da087b8d68d725918b2639f8 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 26 Oct 2020 01:28:09 +0300 Subject: [PATCH] net: add some more gulag tools --- src/game/g_console.pas | 8 ++- src/game/g_game.pas | 123 ++++++++++++++++++++++++++++++++++++++++- src/game/g_net.pas | 3 + src/game/g_netmsg.pas | 78 ++++++++++++++------------ src/game/g_player.pas | 2 + 5 files changed, 177 insertions(+), 37 deletions(-) diff --git a/src/game/g_console.pas b/src/game/g_console.pas index d305954..c779409 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -1049,10 +1049,14 @@ begin AddCommand('ready', GameCommands); AddCommand('kick', GameCommands); AddCommand('kick_id', GameCommands); + AddCommand('kick_pid', GameCommands); AddCommand('ban', GameCommands); - AddCommand('permban', GameCommands); AddCommand('ban_id', GameCommands); + AddCommand('ban_pid', GameCommands); + AddCommand('permban', GameCommands); AddCommand('permban_id', GameCommands); + AddCommand('permban_pid', GameCommands); + AddCommand('permban_ip', GameCommands); AddCommand('unban', GameCommands); AddCommand('connect', GameCommands); AddCommand('disconnect', GameCommands); @@ -1105,7 +1109,9 @@ begin WhitelistCommand('endmap'); WhitelistCommand('restart'); WhitelistCommand('kick'); + WhitelistCommand('kick_pid'); WhitelistCommand('ban'); + WhitelistCommand('ban_pid'); WhitelistCommand('centerprint'); WhitelistCommand('addbot'); diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 82d2981..8e3f808 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -267,6 +267,7 @@ var gShowFPS: Boolean = False; gShowGoals: Boolean = True; gShowStat: Boolean = True; + gShowPIDs: Boolean = False; gShowKillMsg: Boolean = True; gShowLives: Boolean = True; gShowPing: Boolean = False; @@ -1162,6 +1163,7 @@ var stat: TPlayerStatArray; wad, map: string; mapstr: string; + namestr: string; begin s1 := ''; s2 := ''; @@ -1303,8 +1305,12 @@ begin gg := g; bb := b; end; + if gShowPIDs then + namestr := Format('[%5d] %s', [UID, Name]) + else + namestr := Name; // Èìÿ - e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1); + e_TextureFontPrintEx(x+16, _y, namestr, gStdFont, rr, gg, bb, 1); // Ïèíã/ïîòåðè e_TextureFontPrintEx(x+w1+16, _y, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, rr, gg, bb, 1); // Ôðàãè @@ -1339,11 +1345,15 @@ begin r := 255; g := 127; end; + if gShowPIDs then + namestr := Format('[%5d] %s', [UID, Name]) + else + namestr := Name; // Öâåò èãðîêà e_DrawFillQuad(x+16, _y+4, x+32-1, _y+16+4-1, Color.R, Color.G, Color.B, 0); e_DrawQuad(x+16, _y+4, x+32-1, _y+16+4-1, 192, 192, 192); // Èìÿ - e_TextureFontPrintEx(x+16+16+8, _y+4, Name, gStdFont, r, g, 0, 1); + e_TextureFontPrintEx(x+16+16+8, _y+4, namestr, gStdFont, r, g, 0, 1); // Ïèíã/ïîòåðè e_TextureFontPrintEx(x+w1+16, _y+4, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, r, g, 0, 1); // Ôðàãè @@ -6285,6 +6295,34 @@ begin end else g_Console_Add(_lc[I_MSG_SERVERONLY]); end + else if cmd = 'kick_pid' then + begin + if g_Game_IsServer and g_Game_IsNet then + begin + if Length(P) < 2 then + begin + g_Console_Add('kick_pid '); + Exit; + end; + if P[1] = '' then + begin + g_Console_Add('kick_pid '); + Exit; + end; + + a := StrToIntDef(P[1], 0); + pl := g_Net_Client_ByPlayer(a); + if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then + begin + s := g_Net_ClientName_ByID(pl^.ID); + enet_peer_disconnect(pl^.Peer, NET_DISC_KICK); + g_Console_Add(Format(_lc[I_PLAYER_KICK], [s])); + MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s); + g_Net_Slist_ServerPlayerLeaves(); + end; + end else + g_Console_Add(_lc[I_MSG_SERVERONLY]); + end else if cmd = 'ban' then begin if g_Game_IsServer and g_Game_IsNet then @@ -6343,6 +6381,35 @@ begin end else g_Console_Add(_lc[I_MSG_SERVERONLY]); end + else if cmd = 'ban_pid' then + begin + if g_Game_IsServer and g_Game_IsNet then + begin + if Length(P) < 2 then + begin + g_Console_Add('ban_pid '); + Exit; + end; + if P[1] = '' then + begin + g_Console_Add('ban_pid '); + Exit; + end; + + a := StrToIntDef(P[1], 0); + pl := g_Net_Client_ByPlayer(a); + if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then + begin + s := g_Net_ClientName_ByID(pl^.ID); + g_Net_BanHost(pl^.Peer^.address.host, False); + enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN); + g_Console_Add(Format(_lc[I_PLAYER_BAN], [s])); + MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s); + g_Net_Slist_ServerPlayerLeaves(); + end; + end else + g_Console_Add(_lc[I_MSG_SERVERONLY]); + end else if cmd = 'permban' then begin if g_Game_IsServer and g_Game_IsNet then @@ -6403,6 +6470,57 @@ begin end else g_Console_Add(_lc[I_MSG_SERVERONLY]); end + else if cmd = 'permban_pid' then + begin + if g_Game_IsServer and g_Game_IsNet then + begin + if Length(P) < 2 then + begin + g_Console_Add('permban_pid '); + Exit; + end; + if P[1] = '' then + begin + g_Console_Add('permban_pid '); + Exit; + end; + + a := StrToIntDef(P[1], 0); + pl := g_Net_Client_ByPlayer(a); + if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then + begin + s := g_Net_ClientName_ByID(pl^.ID); + g_Net_BanHost(pl^.Peer^.address.host); + enet_peer_disconnect(pl^.Peer, NET_DISC_BAN); + g_Net_SaveBanList(); + g_Console_Add(Format(_lc[I_PLAYER_BAN], [s])); + MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s); + g_Net_Slist_ServerPlayerLeaves(); + end; + end else + g_Console_Add(_lc[I_MSG_SERVERONLY]); + end + else if cmd = 'permban_ip' then + begin + if g_Game_IsServer and g_Game_IsNet then + begin + if Length(P) < 2 then + begin + g_Console_Add('permban_ip '); + Exit; + end; + if P[1] = '' then + begin + g_Console_Add('permban_ip '); + Exit; + end; + + g_Net_BanHost(P[1]); + g_Net_SaveBanList(); + g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]])); + end else + g_Console_Add(_lc[I_MSG_SERVERONLY]); + end else if cmd = 'unban' then begin if g_Game_IsServer and g_Game_IsNet then @@ -8131,4 +8249,5 @@ begin conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives'); conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud'); conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats'); + conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs'); end. diff --git a/src/game/g_net.pas b/src/game/g_net.pas index 7dad24c..7c5de2a 100644 --- a/src/game/g_net.pas +++ b/src/game/g_net.pas @@ -172,6 +172,8 @@ var NetGotEverything: Boolean = False; NetGotKeys: Boolean = False; + NetDeafLevel: Integer = 0; + {$IFDEF USE_MINIUPNPC} NetPortForwarded: Word = 0; NetPongForwarded: Boolean = False; @@ -2439,6 +2441,7 @@ initialization conRegVar('cl_interp', @NetInterpLevel, '', 'net player interpolation steps'); conRegVar('cl_last_ip', @NetClientIP, '', 'address of the last you have connected to'); conRegVar('cl_last_port', @NetClientPort, '', 'port of the last server you have connected to'); + conRegVar('cl_deafen', @NetDeafLevel, '', 'filter server messages (0-3)'); conRegVar('sv_forwardports', @NetForwardPorts, '', 'forward server port using miniupnpc (requires server restart)'); conRegVar('sv_rcon', @NetAllowRCON, '', 'enable remote console'); diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index 17942e2..0f57f84 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -1516,22 +1516,25 @@ begin if Mode <> NET_CHAT_SYSTEM then begin - if Mode = NET_CHAT_PLAYER then - begin - g_Console_Add(Txt, True); - e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify); - g_Game_ChatSound(b_Text_Unformat(Txt)); - end else - if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then + if NetDeafLevel = 0 then begin - if gPlayer1.Team = TEAM_RED then - g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True); - if gPlayer1.Team = TEAM_BLUE then - g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True); - e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify); - g_Game_ChatSound(b_Text_Unformat(Txt)); + if Mode = NET_CHAT_PLAYER then + begin + g_Console_Add(Txt, True); + e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify); + g_Game_ChatSound(b_Text_Unformat(Txt)); + end else + if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then + begin + if gPlayer1.Team = TEAM_RED then + g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True); + if gPlayer1.Team = TEAM_BLUE then + g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True); + e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify); + g_Game_ChatSound(b_Text_Unformat(Txt)); + end; end; - end else + end else if (NetDeafLevel < 2) then g_Console_Add(Txt, True); end; @@ -1842,10 +1845,13 @@ begin NET_EV_CHANGE_TEAM: begin - if EvNum = TEAM_RED then - g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True); - if EvNum = TEAM_BLUE then - g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True); + if NetDeafLevel < 2 then + begin + if EvNum = TEAM_RED then + g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True); + if EvNum = TEAM_BLUE then + g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True); + end; end; NET_EV_PLAYER_KICK: @@ -1878,7 +1884,7 @@ begin g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True); NET_EV_BIGTEXT: - g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum)); + if NetDeafLevel < 2 then g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum)); NET_EV_SCORE: begin @@ -2222,7 +2228,8 @@ begin end; end; - g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True); + if NetDeafLevel < 3 then + g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True); e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify); Result := PID; end; @@ -2455,7 +2462,8 @@ begin Result := 0; if Pl = nil then Exit; - g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True); + if NetDeafLevel < 3 then + g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True); e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify); g_Player_Remove(PID); @@ -2520,7 +2528,8 @@ begin if Pl.Name <> TmpName then begin - g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True); + if NetDeafLevel < 3 then + g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True); Pl.Name := TmpName; end; @@ -2914,18 +2923,19 @@ begin Str1 := M.ReadString(); Str2 := M.ReadString(); - case EvID of - NET_VE_STARTED: - g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True); - NET_VE_PASSED: - g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True); - NET_VE_FAILED: - g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True); - NET_VE_VOTE: - g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True); - NET_VE_INPROGRESS: - g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True); - end; + if NetDeafLevel < 2 then + case EvID of + NET_VE_STARTED: + g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True); + NET_VE_PASSED: + g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True); + NET_VE_FAILED: + g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True); + NET_VE_VOTE: + g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True); + NET_VE_INPROGRESS: + g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True); + end; end; // CLIENT SEND diff --git a/src/game/g_player.pas b/src/game/g_player.pas index 64e6166..28032e9 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -114,6 +114,7 @@ type Kills: Word; Color: TRGB; Spectator: Boolean; + UID: Word; end; TPlayerStatArray = Array of TPlayerStat; @@ -1521,6 +1522,7 @@ begin Color := gPlayers[a].FModel.Color; Lives := gPlayers[a].FLives; Spectator := gPlayers[a].FSpectator; + UID := gPlayers[a].FUID; end; end; end; -- 2.29.2