summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f5e6473)
raw | patch | inline | side by side (parent: f5e6473)
author | fgsfds <derp.primus@gmail.com> | |
Sat, 22 Jul 2023 14:08:54 +0000 (16:08 +0200) | ||
committer | fgsfds <derp.primus@gmail.com> | |
Sat, 22 Jul 2023 14:08:54 +0000 (16:08 +0200) |
src/game/g_game.pas | patch | blob | history | |
src/game/g_language.pas | patch | blob | history | |
src/game/g_net.pas | patch | blob | history | |
src/game/g_netmsg.pas | patch | blob | history |
diff --git a/src/game/g_game.pas b/src/game/g_game.pas
index 71eb6095d6ee5ef232245707315b9c1e2e347798..2c158c4e2335c16dfa78df2323cd49f44b5677a6 100644 (file)
--- a/src/game/g_game.pas
+++ b/src/game/g_game.pas
end;
end;
- g_Net_UnbanNonPermHosts();
+ g_Net_UnbanNonPerm();
end;
if gLastMap then
pl := g_Net_Client_ByName(P[1]);
if (pl <> nil) then
- begin
- s := g_Net_ClientName_ByID(pl^.ID);
- g_Net_BanHost(pl^.Peer^.address.host, False);
- g_Net_Host_Kick(pl^.ID, 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 else
+ g_Net_Host_Ban(pl, False)
+ else
g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
end else
g_Console_Add(_lc[I_MSG_SERVERONLY]);
a := StrToIntDef(P[1], 0);
if (NetClients <> nil) and (a <= High(NetClients)) then
if NetClients[a].Used and (NetClients[a].Peer <> nil) then
- begin
- s := g_Net_ClientName_ByID(NetClients[a].ID);
- g_Net_BanHost(NetClients[a].Peer^.address.host, False);
- g_Net_Host_Kick(NetClients[a].ID, 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;
+ g_Net_Host_Ban(pl, False);
end else
g_Console_Add(_lc[I_MSG_SERVERONLY]);
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);
- g_Net_Host_Kick(pl^.ID, 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;
+ g_Net_Host_Ban(pl, False);
end else
g_Console_Add(_lc[I_MSG_SERVERONLY]);
end
pl := g_Net_Client_ByName(P[1]);
if (pl <> nil) then
- begin
- s := g_Net_ClientName_ByID(pl^.ID);
- g_Net_BanHost(pl^.Peer^.address.host);
- g_Net_Host_Kick(pl^.ID, 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 else
+ g_Net_Host_Ban(pl, True)
+ else
g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
end else
g_Console_Add(_lc[I_MSG_SERVERONLY]);
a := StrToIntDef(P[1], 0);
if (NetClients <> nil) and (a <= High(NetClients)) then
if NetClients[a].Used and (NetClients[a].Peer <> nil) then
- begin
- s := g_Net_ClientName_ByID(NetClients[a].ID);
- g_Net_BanHost(NetClients[a].Peer^.address.host);
- g_Net_Host_Kick(NetClients[a].ID, 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;
+ g_Net_Host_Ban(@NetClients[a], True);
end else
g_Console_Add(_lc[I_MSG_SERVERONLY]);
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);
- g_Net_Host_Kick(pl^.ID, NET_DISC_TEMPBAN);
- 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;
+ g_Net_Host_Ban(pl, True);
end else
g_Console_Add(_lc[I_MSG_SERVERONLY]);
end
Exit;
end;
- g_Net_BanHost(P[1]);
+ g_Net_BanAddress(P[1]);
g_Net_SaveBanList();
g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
end else
Exit;
end;
- if g_Net_UnbanHost(P[1]) then
+ if g_Net_UnbanAddress(P[1]) then
begin
g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
g_Net_SaveBanList();
index a75db11bba78186bbde0367068d7540606c4fc8e..e7e3a42a0913b9607f8f99b4677e818e6426cafe 100644 (file)
--- a/src/game/g_language.pas
+++ b/src/game/g_language.pas
I_NET_DISC_PASSWORD,
I_NET_DISC_TEMPBAN,
I_NET_DISC_BAN,
+ I_NET_DISC_BADMSG,
I_NET_SLIST,
I_NET_SLIST_NOSERVERS,
'Âû çàáàíåíû äî êîíöà ðàóíäà.'),
('NET DISC BAN', 'You are banned. Contact the server administrator.',
'Âû çàáàíåíû. Ñâÿæèòåñü ñ àäìèíèñòðàòîðîì ñåðâåðà.'),
+ ('NET DISC BADMSG' 'Malformed net message.',
+ 'Íåâåðíûé ôîðìàò ïàêåòà.'),
('NET SLIST', 'Server list',
'Ñïèñîê ñåðâåðîâ'),
diff --git a/src/game/g_net.pas b/src/game/g_net.pas
index d97d4bd07675033281e6a61b888d390eb52a40ab..292f919b9e9c5beb4981f9f073313e52ed679595 100644 (file)
--- a/src/game/g_net.pas
+++ b/src/game/g_net.pas
procedure g_Net_Host_Send(ID: Integer; Reliable: Boolean);
procedure g_Net_Host_Update();
procedure g_Net_Host_Kick(ID: Integer; Reason: enet_uint32);
+procedure g_Net_Host_Ban(ID: Integer; Perm: Boolean);
+procedure g_Net_Host_Ban(C: pTNetClient; Perm: Boolean);
function g_Net_Connect(IP: string; Port: enet_uint16): Boolean;
procedure g_Net_Disconnect(Forced: Boolean = False);
function IpToStr(IP: LongWord): string;
function StrToIp(IPstr: string; var IP: LongWord): Boolean;
-function g_Net_IsHostBanned(IP: LongWord; Perm: Boolean = False): Boolean;
-procedure g_Net_BanHost(IP: LongWord; Perm: Boolean = True); overload;
-procedure g_Net_BanHost(IP: string; Perm: Boolean = True); overload;
-function g_Net_UnbanHost(IP: string): Boolean; overload;
-function g_Net_UnbanHost(IP: LongWord): Boolean; overload;
-procedure g_Net_UnbanNonPermHosts();
+function g_Net_IsAddressBanned(IP: LongWord; Perm: Boolean = False): Boolean;
+procedure g_Net_BanAddress(IP: LongWord; Perm: Boolean = True); overload;
+procedure g_Net_BanAddress(IP: string; Perm: Boolean = True); overload;
+function g_Net_UnbanAddress(IP: string): Boolean; overload;
+function g_Net_UnbanAddress(IP: LongWord): Boolean; overload;
+procedure g_Net_UnbanNonPerm();
procedure g_Net_SaveBanList();
procedure g_Net_Penalize(C: pTNetClient; Reason: string);
begin
Readln(F, IPstr);
if StrToIp(IPstr, IP) then
- g_Net_BanHost(IP);
+ g_Net_BanAddress(IP);
end;
CloseFile(F);
g_Net_SaveBanList();
Exit;
end;
- if g_Net_IsHostBanned(NetEvent.Peer^.address.host) then
+ if g_Net_IsAddressBanned(NetEvent.Peer^.address.host) then
begin
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
_lc[I_NET_DISC_BAN]);
pl := g_Player_Get(NetClients[a].Player);
if pl = nil then Exit;
Result := pl.Name;
+ Exit;
end;
-end;
+ Result := 'Client #' + IntToStr(ID);
+ end;
-function g_Net_IsHostBanned(IP: LongWord; Perm: Boolean = False): Boolean;
+function g_Net_IsAddressBanned(IP: LongWord; Perm: Boolean = False): Boolean;
var
I: Integer;
begin
end;
end;
-procedure g_Net_BanHost(IP: LongWord; Perm: Boolean = True); overload;
+procedure g_Net_BanAddress(IP: LongWord; Perm: Boolean = True); overload;
var
I, P: Integer;
begin
if IP = 0 then
Exit;
- if g_Net_IsHostBanned(IP, Perm) then
+ if g_Net_IsAddressBanned(IP, Perm) then
Exit;
P := -1;
NetBannedHosts[P].Perm := Perm;
end;
-procedure g_Net_BanHost(IP: string; Perm: Boolean = True); overload;
+procedure g_Net_BanAddress(IP: string; Perm: Boolean = True); overload;
var
a: LongWord;
b: Boolean;
begin
b := StrToIp(IP, a);
if b then
- g_Net_BanHost(a, Perm);
+ g_Net_BanAddress(a, Perm);
end;
-procedure g_Net_UnbanNonPermHosts();
+procedure g_Net_UnbanNonPerm();
var
I: Integer;
begin
end;
end;
-function g_Net_UnbanHost(IP: string): Boolean; overload;
+function g_Net_UnbanAddress(IP: string): Boolean; overload;
var
a: LongWord;
begin
Result := StrToIp(IP, a);
if Result then
- Result := g_Net_UnbanHost(a);
+ Result := g_Net_UnbanAddress(a);
end;
-function g_Net_UnbanHost(IP: LongWord): Boolean; overload;
+function g_Net_UnbanAddress(IP: LongWord): Boolean; overload;
var
I: Integer;
begin
end
end;
+procedure g_Net_Host_Ban(C: pTNetClient; Perm: Boolean);
+var
+ KickReason: enet_uint32;
+ Name: string;
+begin
+ if (not C^.Used) then
+ exit;
+
+ if Perm then
+ KickReason := NET_DISC_BAN
+ else
+ KickReason := NET_DISC_TEMPBAN;
+
+ Name := g_Net_ClientName_ByID(C^.ID);
+
+ g_Net_BanAddress(C^.Peer^.address.host, Perm);
+ g_Net_Host_Kick(C^.ID, KickReason);
+ g_Console_Add(Format(_lc[I_PLAYER_BAN], [Name]));
+ MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, Name);
+ g_Net_Slist_ServerPlayerLeaves();
+ g_Net_SaveBanList();
+end;
+
+procedure g_Net_Host_Ban(ID: Integer; Perm: Boolean);
+begin
+ if (ID < 0) or (ID > High(NetClients)) then
+ exit;
+ g_Net_Host_Ban(@NetClients[ID], Perm);
+end;
+
procedure g_Net_Penalize(C: pTNetClient; Reason: string);
var
s: string;
if (C^.Crimes >= NetAutoBanLimit) then
begin
- s := '#' + IntToStr(C^.ID); // can't be arsed
- g_Net_BanHost(C^.Peer^.address.host, NetAutoBanPerm);
- g_Net_Host_Kick(C^.ID, NET_DISC_BAN);
- g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
- MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
- g_Net_Slist_ServerPlayerLeaves();
+
end;
end;
diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas
index 1eb3683759c40e6a12ab9b30ba1855a50b4c0f18..b090aa30e08bdb690b645389cd73d22cfd6a9549 100644 (file)
--- a/src/game/g_netmsg.pas
+++ b/src/game/g_netmsg.pas
procedure MH_MalformedPacket(C: pTNetClient);
begin
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
- _lc[I_NET_DISC_PROTOCOL]);
- g_Net_Host_Kick(C^.ID, NET_DISC_PROTOCOL);
+ _lc[I_NET_DISC_BADMSG]);
+ g_Net_Host_Ban(C, True);
end;
procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
Exit;
end;
- if g_Net_IsHostBanned(C^.Peer^.address.host) then
+ if g_Net_IsAddressBanned(C^.Peer^.address.host) then
begin
- if g_Net_IsHostBanned(C^.Peer^.address.host, True) then
+ if g_Net_IsAddressBanned(C^.Peer^.address.host, True) then
begin
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
_lc[I_NET_DISC_BAN]);