diff --git a/src/game/g_net.pas b/src/game/g_net.pas
index 944ce6f6727eb3746ff56c901238e6ccecbaa035..cbf5120782839a5703caa116a5d0041465411410 100644 (file)
--- a/src/game/g_net.pas
+++ b/src/game/g_net.pas
-(* Copyright (C) DooM 2D:Forever Developers
+(* Copyright (C) Doom 2D: Forever Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
-{$MODE DELPHI}
+{$INCLUDE ../shared/a_modes.inc}
unit g_net;
interface
uses
unit g_net;
interface
uses
- e_log, e_fixedbuffer, ENet, Classes;
+ e_log, e_msg, ENet, Classes, MAPDEF;
const
const
- NET_PROTOCOL_VER = 171;
+ NET_PROTOCOL_VER = 173;
NET_MAXCLIENTS = 24;
NET_CHANS = 11;
NET_MAXCLIENTS = 24;
NET_CHANS = 11;
NET_SERVER = 1;
NET_CLIENT = 2;
NET_SERVER = 1;
NET_CLIENT = 2;
- NET_BUFSIZE = 65536;
+ NET_BUFSIZE = $FFFF;
NET_EVERYONE = -1;
NET_EVERYONE = -1;
NetClientIP: string = '127.0.0.1';
NetClientPort: Word = 25666;
NetClientIP: string = '127.0.0.1';
NetClientPort: Word = 25666;
- NetIn, NetOut: TBuffer;
+ NetIn, NetOut: TMsg;
NetClients: array of TNetClient;
NetClientCount: Byte = 0;
NetClients: array of TNetClient;
NetClientCount: Byte = 0;
IPstr: string;
IP: LongWord;
begin
IPstr: string;
IP: LongWord;
begin
- e_Buffer_Clear(@NetIn);
- e_Buffer_Clear(@NetOut);
+ NetIn.Clear();
+ NetOut.Clear();
SetLength(NetClients, 0);
NetPeer := nil;
NetHost := nil;
SetLength(NetClients, 0);
NetPeer := nil;
NetHost := nil;
procedure g_Net_Cleanup();
begin
procedure g_Net_Cleanup();
begin
- e_Buffer_Clear(@NetIn);
- e_Buffer_Clear(@NetOut);
+ NetIn.Clear();
+ NetOut.Clear();
SetLength(NetClients, 0);
NetClientCount := 0;
SetLength(NetClients, 0);
NetClientCount := 0;
end;
NetMode := NET_SERVER;
end;
NetMode := NET_SERVER;
- e_Buffer_Clear(@NetOut);
+ NetOut.Clear();
if NetDump then
g_Net_DumpStart();
if NetDump then
g_Net_DumpStart();
NetMode := NET_NONE;
g_Net_Cleanup;
NetMode := NET_NONE;
g_Net_Cleanup;
- e_WriteLog('NET: Server stopped', MSG_NOTIFY);
+ e_WriteLog('NET: Server stopped', TMsgType.Notify);
end;
end;
if ID > High(NetClients) then Exit;
if NetClients[ID].Peer = nil then Exit;
if ID > High(NetClients) then Exit;
if NetClients[ID].Peer = nil then Exit;
- P := enet_packet_create(Addr(NetOut.Data), NetOut.Len, F);
+ P := enet_packet_create(NetOut.Data, NetOut.CurSize, F);
if not Assigned(P) then Exit;
enet_peer_send(NetClients[ID].Peer, Chan, P);
end
else
begin
if not Assigned(P) then Exit;
enet_peer_send(NetClients[ID].Peer, Chan, P);
end
else
begin
- P := enet_packet_create(Addr(NetOut.Data), NetOut.Len, F);
+ P := enet_packet_create(NetOut.Data, NetOut.CurSize, F);
if not Assigned(P) then Exit;
enet_host_broadcast(NetHost, Chan, P);
if not Assigned(P) then Exit;
enet_host_broadcast(NetHost, Chan, P);
if NetDump then g_Net_DumpSendBuffer();
g_Net_Flush();
if NetDump then g_Net_DumpSendBuffer();
g_Net_Flush();
- e_Buffer_Clear(@NetOut);
+ NetOut.Clear();
end;
procedure g_Net_Host_CheckPings();
end;
procedure g_Net_Host_CheckPings();
begin
ClTime := Int64(Addr(Ping[2])^);
begin
ClTime := Int64(Addr(Ping[2])^);
- e_Buffer_Clear(@NetOut);
- e_Buffer_Write(@NetOut, Byte(Ord('D')));
- e_Buffer_Write(@NetOut, Byte(Ord('F')));
- e_Buffer_Write(@NetOut, ClTime);
+ NetOut.Clear();
+ NetOut.Write(Byte(Ord('D')));
+ NetOut.Write(Byte(Ord('F')));
+ NetOut.Write(ClTime);
g_Net_Slist_WriteInfo();
NPl := 0;
if gPlayer1 <> nil then Inc(NPl);
if gPlayer2 <> nil then Inc(NPl);
g_Net_Slist_WriteInfo();
NPl := 0;
if gPlayer1 <> nil then Inc(NPl);
if gPlayer2 <> nil then Inc(NPl);
- e_Buffer_Write(@NetOut, NPl);
- e_Buffer_Write(@NetOut, gNumBots);
+ NetOut.Write(NPl);
+ NetOut.Write(gNumBots);
- Buf.data := Addr(NetOut.Data[0]);
- Buf.dataLength := NetOut.WritePos;
+ Buf.data := NetOut.Data;
+ Buf.dataLength := NetOut.CurSize;
enet_socket_send(NetPongSock, @ClAddr, @Buf, 1);
enet_socket_send(NetPongSock, @ClAddr, @Buf, 1);
- e_Buffer_Clear(@NetOut);
+ NetOut.Clear();
end;
end;
end;
end;
TP.Lives := 0;
TP.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [TP.Name]), True);
TP.Lives := 0;
TP.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [TP.Name]), True);
- e_WriteLog('NET: Client ' + TP.Name + ' [' + IntToStr(ID) + '] disconnected.', MSG_NOTIFY);
+ e_WriteLog('NET: Client ' + TP.Name + ' [' + IntToStr(ID) + '] disconnected.', TMsgType.Notify);
g_Player_Remove(TP.UID);
end;
g_Player_Remove(TP.UID);
end;
end
else
begin
end
else
begin
- e_WriteLog('NET: Kicked from server: ' + IntToStr(NetEvent.data), MSG_NOTIFY);
+ e_WriteLog('NET: Kicked from server: ' + IntToStr(NetEvent.data), TMsgType.Notify);
if (NetEvent.data <= NET_DISC_MAX) then
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_KICK] +
_lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
if (NetEvent.data <= NET_DISC_MAX) then
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_KICK] +
_lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_CLIENT_DISC]);
g_Net_Cleanup;
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_CLIENT_DISC]);
g_Net_Cleanup;
- e_WriteLog('NET: Disconnected', MSG_NOTIFY);
+ e_WriteLog('NET: Disconnected', TMsgType.Notify);
end;
procedure g_Net_Client_Send(Reliable: Boolean; Chan: Byte = NET_CHAN_GAME);
end;
procedure g_Net_Client_Send(Reliable: Boolean; Chan: Byte = NET_CHAN_GAME);
else
F := 0;
else
F := 0;
- P := enet_packet_create(Addr(NetOut.Data), NetOut.Len, F);
+ P := enet_packet_create(NetOut.Data, NetOut.CurSize, F);
if not Assigned(P) then Exit;
enet_peer_send(NetPeer, Chan, P);
if NetDump then g_Net_DumpSendBuffer();
g_Net_Flush();
if not Assigned(P) then Exit;
enet_peer_send(NetPeer, Chan, P);
if NetDump then g_Net_DumpSendBuffer();
g_Net_Flush();
- e_Buffer_Clear(@NetOut);
+ NetOut.Clear();
end;
function g_Net_Client_Update(): enet_size_t;
end;
function g_Net_Client_Update(): enet_size_t;
begin
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_CLIENT_DONE]);
NetMode := NET_CLIENT;
begin
g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_CLIENT_DONE]);
NetMode := NET_CLIENT;
- e_Buffer_Clear(@NetOut);
+ NetOut.Clear();
enet_peer_timeout(NetPeer, ENET_PEER_TIMEOUT_LIMIT * 2, ENET_PEER_TIMEOUT_MINIMUM * 2, ENET_PEER_TIMEOUT_MAXIMUM * 2);
NetClientIP := IP;
NetClientPort := Port;
enet_peer_timeout(NetPeer, ENET_PEER_TIMEOUT_LIMIT * 2, ENET_PEER_TIMEOUT_MINIMUM * 2, ENET_PEER_TIMEOUT_MAXIMUM * 2);
NetClientIP := IP;
NetClientPort := Port;
end;
end;
end;
end;
- ProcessLoading();
-
- e_PollInput();
+ ProcessLoading(true);
if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then
OuterLoop := False;
if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then
OuterLoop := False;
var
Ptr: Pointer;
begin
var
Ptr: Pointer;
begin
- Result := '';
Ptr := Addr(IP);
Ptr := Addr(IP);
-
- e_Raw_Seek(0);
- Result := Result + IntToStr(e_Raw_Read_Byte(Ptr)) + '.';
- Result := Result + IntToStr(e_Raw_Read_Byte(Ptr)) + '.';
- Result := Result + IntToStr(e_Raw_Read_Byte(Ptr)) + '.';
- Result := Result + IntToStr(e_Raw_Read_Byte(Ptr));
- e_Raw_Seek(0);
+ Result := IntToStr(PByte(Ptr + 0)^) + '.';
+ Result := Result + IntToStr(PByte(Ptr + 1)^) + '.';
+ Result := Result + IntToStr(PByte(Ptr + 2)^) + '.';
+ Result := Result + IntToStr(PByte(Ptr + 3)^);
end;
function StrToIp(IPstr: string; var IP: LongWord): Boolean;
end;
function StrToIp(IPstr: string; var IP: LongWord): Boolean;
end;
end;
end;
end;
- ProcessLoading();
-
- e_PollInput();
+ ProcessLoading(true);
if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then
break;
if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then
break;
procedure g_Net_DumpSendBuffer();
begin
writeInt(NetDumpFile, gTime);
procedure g_Net_DumpSendBuffer();
begin
writeInt(NetDumpFile, gTime);
- writeInt(NetDumpFile, LongWord(NetOut.Len));
+ writeInt(NetDumpFile, LongWord(NetOut.CurSize));
writeInt(NetDumpFile, Byte(1));
writeInt(NetDumpFile, Byte(1));
- NetDumpFile.WriteBuffer(NetOut.Data[0], NetOut.Len);
+ NetDumpFile.WriteBuffer(NetOut.Data^, NetOut.CurSize);
end;
procedure g_Net_DumpRecvBuffer(Buf: penet_uint8; Len: LongWord);
end;
procedure g_Net_DumpRecvBuffer(Buf: penet_uint8; Len: LongWord);
NetDumpFile := nil;
end;
NetDumpFile := nil;
end;
+initialization
+
+ NetIn.Alloc(NET_BUFSIZE);
+ NetOut.Alloc(NET_BUFSIZE);
+
+finalization
+
+ NetIn.Free();
+ NetOut.Free();
+
end.
end.