summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8d318ac)
raw | patch | inline | side by side (parent: 8d318ac)
author | fgsfds <pvt.fgsfds@gmail.com> | |
Sun, 13 Aug 2017 16:54:07 +0000 (19:54 +0300) | ||
committer | fgsfds <pvt.fgsfds@gmail.com> | |
Sun, 13 Aug 2017 16:54:07 +0000 (19:54 +0300) |
src/game/g_game.pas | patch | blob | history | |
src/game/g_net.pas | patch | blob | history |
diff --git a/src/game/g_game.pas b/src/game/g_game.pas
index 811148cf456bfb8fb4a54703ca79ebf0ad567361..963f8aec27dfa4e0f4586e9ecfbbecd6c69f203c 100644 (file)
--- a/src/game/g_game.pas
+++ b/src/game/g_game.pas
// Debug mode:
s := Find_Param_Value(pars, '--debug');
if (s <> '') then
+ begin
g_Game_SetDebugMode();
+ s := Find_Param_Value(pars, '--netdump');
+ if (s <> '') then
+ NetDump := True;
+ end;
// Connect when game loads
ip := Find_Param_Value(pars, '-connect');
diff --git a/src/game/g_net.pas b/src/game/g_net.pas
index c9e40400fea7511762dee5f673a05b820b13d776..944ce6f6727eb3746ff56c901238e6ccecbaa035 100644 (file)
--- a/src/game/g_net.pas
+++ b/src/game/g_net.pas
NET_STATE_GAME = 2;
BANLIST_FILENAME = 'banlist.txt';
+ NETDUMP_FILENAME = 'netdump';
type
TNetClient = record
var
NetInitDone: Boolean = False;
NetMode: Byte = NET_NONE;
+ NetDump: Boolean = False;
NetServerName: string = 'Unnamed Server';
NetPassword: string = '';
NetGotEverything: Boolean = False;
+ NetDumpFile: TStream;
+
function g_Net_Init(): Boolean;
procedure g_Net_Cleanup();
procedure g_Net_Free();
procedure g_Net_UnbanNonPermHosts();
procedure g_Net_SaveBanList();
+procedure g_Net_DumpStart();
+procedure g_Net_DumpSendBuffer();
+procedure g_Net_DumpRecvBuffer(Buf: penet_uint8; Len: LongWord);
+procedure g_Net_DumpEnd();
+
implementation
uses
SysUtils,
e_input, g_nethandler, g_netmsg, g_netmaster, g_player, g_window, g_console,
- g_main, g_game, g_language, g_weapons;
+ g_main, g_game, g_language, g_weapons, utils;
{ /// SERVICE FUNCTIONS /// }
NetTimeToReliable := 0;
NetMode := NET_NONE;
+
+ if NetDump then
+ g_Net_DumpEnd();
end;
procedure g_Net_Free();
NetMode := NET_SERVER;
e_Buffer_Clear(@NetOut);
+
+ if NetDump then
+ g_Net_DumpStart();
end;
procedure g_Net_Host_Die();
enet_host_broadcast(NetHost, Chan, P);
end;
+ if NetDump then g_Net_DumpSendBuffer();
g_Net_Flush();
e_Buffer_Clear(@NetOut);
end;
if ID > High(NetClients) then Exit;
TC := @NetClients[ID];
+ if NetDump then g_Net_DumpRecvBuffer(NetEvent.packet^.data, NetEvent.packet^.dataLength);
g_Net_HostMsgHandler(TC, NetEvent.packet);
end;
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);
end;
begin
case NetEvent.kind of
ENET_EVENT_TYPE_RECEIVE:
+ begin
+ if NetDump then g_Net_DumpRecvBuffer(NetEvent.packet^.data, NetEvent.packet^.dataLength);
g_Net_ClientMsgHandler(NetEvent.packet);
+ end;
ENET_EVENT_TYPE_DISCONNECT:
begin
begin
case NetEvent.kind of
ENET_EVENT_TYPE_RECEIVE:
+ begin
+ if NetDump then g_Net_DumpRecvBuffer(NetEvent.packet^.data, NetEvent.packet^.dataLength);
g_Net_ClientLightMsgHandler(NetEvent.packet);
+ end;
ENET_EVENT_TYPE_DISCONNECT:
begin
enet_peer_timeout(NetPeer, ENET_PEER_TIMEOUT_LIMIT * 2, ENET_PEER_TIMEOUT_MINIMUM * 2, ENET_PEER_TIMEOUT_MAXIMUM * 2);
NetClientIP := IP;
NetClientPort := Port;
+ if NetDump then
+ g_Net_DumpStart();
Exit;
end;
end;
CloseFile(F);
end;
+procedure g_Net_DumpStart();
+begin
+ if NetMode = NET_SERVER then
+ NetDumpFile := createDiskFile(NETDUMP_FILENAME + '_server')
+ else
+ NetDumpFile := createDiskFile(NETDUMP_FILENAME + '_client');
+end;
+
+procedure g_Net_DumpSendBuffer();
+begin
+ writeInt(NetDumpFile, gTime);
+ writeInt(NetDumpFile, LongWord(NetOut.Len));
+ writeInt(NetDumpFile, Byte(1));
+ NetDumpFile.WriteBuffer(NetOut.Data[0], NetOut.Len);
+end;
+
+procedure g_Net_DumpRecvBuffer(Buf: penet_uint8; Len: LongWord);
+begin
+ if (Buf = nil) or (Len = 0) then Exit;
+ writeInt(NetDumpFile, gTime);
+ writeInt(NetDumpFile, Len);
+ writeInt(NetDumpFile, Byte(0));
+ NetDumpFile.WriteBuffer(Buf^, Len);
+end;
+
+procedure g_Net_DumpEnd();
+begin
+ NetDumpFile.Free();
+ NetDumpFile := nil;
+end;
+
end.