summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0e1b2d3)
raw | patch | inline | side by side (parent: 0e1b2d3)
author | fgsfds <pvt.fgsfds@gmail.com> | |
Mon, 5 Jun 2023 23:21:34 +0000 (23:21 +0000) | ||
committer | Dmitry D. Chernov <blackdoomer@yandex.ru> | |
Tue, 6 Jun 2023 02:59:11 +0000 (12:59 +1000) |
src/game/g_game.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 200a57a76ca77dee66710288ef1fd2b147eac7fa..7510eca123454caf27ae768b3ac2c9336e7d226d 100644 (file)
--- a/src/game/g_game.pas
+++ b/src/game/g_game.pas
if (pl <> nil) then
begin
s := g_Net_ClientName_ByID(pl^.ID);
- enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
+ g_Net_Host_Kick(pl^.ID, 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();
if NetClients[a].Used and (NetClients[a].Peer <> nil) then
begin
s := g_Net_ClientName_ByID(NetClients[a].ID);
- enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
+ g_Net_Host_Kick(NetClients[a].ID, 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();
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_Net_Host_Kick(pl^.ID, 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();
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_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();
begin
s := g_Net_ClientName_ByID(NetClients[a].ID);
g_Net_BanHost(NetClients[a].Peer^.address.host, False);
- enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
+ 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();
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_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();
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_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);
begin
s := g_Net_ClientName_ByID(NetClients[a].ID);
g_Net_BanHost(NetClients[a].Peer^.address.host);
- enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
+ 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);
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_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);
diff --git a/src/game/g_net.pas b/src/game/g_net.pas
index 6a17f7e52be79bf63cea6a249a27b940f5c5b822..44485eb48aa1363a77c17e1a896ab2ef1cc253d4 100644 (file)
--- a/src/game/g_net.pas
+++ b/src/game/g_net.pas
procedure g_Net_Host_Die();
procedure g_Net_Host_Send(ID: Integer; Reliable: Boolean; Chan: Byte = NET_CHAN_GAME);
procedure g_Net_Host_Update();
+procedure g_Net_Host_Kick(ID: Integer; Reason: enet_uint32);
function g_Net_Connect(IP: string; Port: enet_uint16): Boolean;
procedure g_Net_Disconnect(Forced: Boolean = False);
procedure killClientByFT (var nc: TNetClient);
begin
e_LogWritefln('disconnected client #%d due to file transfer error', [nc.ID], TMsgType.Warning);
- enet_peer_disconnect(nc.Peer, NET_DISC_FILE_TIMEOUT);
+ g_Net_Host_Kick(nc.ID, NET_DISC_FILE_TIMEOUT);
clearNetClientTransfers(nc);
g_Net_Slist_ServerPlayerLeaves();
end;
if NetUseMaster then g_Net_Slist_ServerPlayerLeaves();
end;
+procedure g_Net_Host_Kick(ID: Integer; Reason: enet_uint32);
+var
+ Peer: pENetPeer;
+ TC: pTNetClient;
+begin
+ TC := @NetClients[ID];
+ if (TC <> nil) and TC^.Used and (TC^.Peer <> nil) then
+ begin
+ Peer := TC^.Peer;
+ g_Net_Host_Disconnect_Client(ID);
+ enet_peer_disconnect(Peer, Reason);
+ end;
+end;
+
procedure g_Net_Host_CheckPings();
var
ClAddr: ENetAddress;
_lc[I_NET_DISC_PROTOCOL]);
e_WriteLog('NET: Connection request from ' + IP + ' rejected: version mismatch',
TMsgType.Notify);
- NetEvent.peer^.data := GetMemory(SizeOf(Byte));
- Byte(NetEvent.peer^.data^) := 255;
enet_peer_disconnect(NetEvent.peer, NET_DISC_PROTOCOL);
- enet_host_flush(NetHost);
Exit;
end;
_lc[I_NET_DISC_BAN]);
e_WriteLog('NET: Connection request from ' + IP + ' rejected: banned',
TMsgType.Notify);
- NetEvent.peer^.data := GetMemory(SizeOf(Byte));
- Byte(NetEvent.peer^.data^) := 255;
enet_peer_disconnect(NetEvent.Peer, NET_DISC_BAN);
- enet_host_flush(NetHost);
Exit;
end;
_lc[I_NET_DISC_FULL]);
e_WriteLog('NET: Connection request from ' + IP + ' rejected: server full',
TMsgType.Notify);
- NetEvent.Peer^.data := GetMemory(SizeOf(Byte));
- Byte(NetEvent.peer^.data^) := 255;
enet_peer_disconnect(NetEvent.peer, NET_DISC_FULL);
- enet_host_flush(NetHost);
Exit;
end;
end
else
begin
+ if NetEvent.peer^.data = nil then Exit;
+
ID := Byte(NetEvent.peer^.data^);
if ID > High(NetClients) then Exit;
TC := @NetClients[ID];
ENET_EVENT_TYPE_DISCONNECT:
begin
- ID := Byte(NetEvent.peer^.data^);
- if ID > High(NetClients) then Exit;
- g_Net_Host_Disconnect_Client(ID);
+ if NetEvent.peer^.data <> nil then
+ begin
+ ID := Byte(NetEvent.peer^.data^);
+ if ID > High(NetClients) then Exit;
+ g_Net_Host_Disconnect_Client(ID);
+ end;
end;
end;
end;
begin
s := '#' + IntToStr(C^.ID); // can't be arsed
g_Net_BanHost(C^.Peer^.address.host, NetAutoBanPerm);
- enet_peer_disconnect(C^.Peer, NET_DISC_BAN);
+ 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();
if b > NetMaxClients then
begin
s := g_Player_Get(NetClients[a].Player).Name;
- enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL);
+ g_Net_Host_Kick(NetClients[a].ID, NET_DISC_FULL);
g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
end;
diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas
index e41eafed8acafacaad3e23967d10eaf806db723d..73c65e358b9427b7486f9425cb1c0569d39f67c3 100644 (file)
--- a/src/game/g_netmsg.pas
+++ b/src/game/g_netmsg.pas
begin
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
_lc[I_NET_DISC_PROTOCOL]);
- enet_peer_disconnect(C^.Peer, NET_DISC_PROTOCOL);
+ g_Net_Host_Kick(C^.ID, NET_DISC_PROTOCOL);
end;
procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
begin
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
_lc[I_NET_DISC_VERSION]);
- enet_peer_disconnect(C^.Peer, NET_DISC_VERSION);
+ g_Net_Host_Kick(C^.ID, NET_DISC_VERSION);
Exit;
end;
begin
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
_lc[I_NET_DISC_BAN]);
- enet_peer_disconnect(C^.Peer, NET_DISC_BAN);
+ g_Net_Host_Kick(C^.ID, NET_DISC_BAN);
end
else
begin
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
_lc[I_NET_DISC_BAN]);
- enet_peer_disconnect(C^.Peer, NET_DISC_TEMPBAN);
+ g_Net_Host_Kick(C^.ID, NET_DISC_TEMPBAN);
end;
Exit;
end;
begin
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
_lc[I_NET_DISC_PASSWORD]);
- enet_peer_disconnect(C^.Peer, NET_DISC_PASSWORD);
+ g_Net_Host_Kick(C^.ID, NET_DISC_PASSWORD);
Exit;
end;