From 907f02bbf5d1e65c2ce052d883d522e30e7c7a8f Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 16 Aug 2017 23:54:05 +0300 Subject: [PATCH] more buffer fixes (?) --- src/engine/e_fixedbuffer.pas | 2 ++ src/game/g_game.pas | 7 +++++-- src/game/g_net.pas | 30 ++++++++++++++++++++++++------ src/game/g_nethandler.pas | 6 ++++++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/engine/e_fixedbuffer.pas b/src/engine/e_fixedbuffer.pas index 3b6dbf8..bc355b1 100644 --- a/src/engine/e_fixedbuffer.pas +++ b/src/engine/e_fixedbuffer.pas @@ -201,6 +201,8 @@ var begin if V = nil then Exit; N := V^.WritePos; + Assert(N <> 0, 'don''t write empty buffers you fuck'); + if N = 0 then Exit; e_Buffer_Write(B, Word(N)); diff --git a/src/game/g_game.pas b/src/game/g_game.pas index c46f6e4..718cfc2 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -3692,8 +3692,11 @@ begin while (State = 0) and (RawPos < NetEvent.packet^.dataLength) do begin Len := e_Raw_Read_Word(Ptr); + if Len = 0 then break; + MID := e_Raw_Read_Byte(Ptr); - e_WriteLog(Format('conn recv %U %U', [Len, MID]), MSG_NOTIFY); + if NetDump then + g_Net_DumpRecvBuffer(NetEvent.packet^.data, NetEvent.packet^.dataLength); if (MID = NET_MSG_INFO) and (State = 0) then begin @@ -3717,7 +3720,7 @@ begin if newResPath = '' then begin g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False); - newResPath := g_Res_DownloadWAD(WadName); + newResPath := ''; //g_Res_DownloadWAD(WadName); if newResPath = '' then begin g_FatalError(_lc[I_NET_ERR_HASH]); diff --git a/src/game/g_net.pas b/src/game/g_net.pas index aad2fb1..38c0597 100644 --- a/src/game/g_net.pas +++ b/src/game/g_net.pas @@ -187,7 +187,7 @@ procedure g_Net_UnbanNonPermHosts(); procedure g_Net_SaveBanList(); procedure g_Net_DumpStart(); -procedure g_Net_DumpSendBuffer(); +procedure g_Net_DumpSendBuffer(Buf: pTBuffer); procedure g_Net_DumpRecvBuffer(Buf: penet_uint8; Len: LongWord); procedure g_Net_DumpEnd(); @@ -219,6 +219,7 @@ begin else enet_peer_send(Peer, Ch, P); end; + if NetDump then g_Net_DumpSendBuffer(B); e_Buffer_Clear(B); end; end; @@ -617,6 +618,8 @@ begin ID := Byte(NetEvent.peer^.data^); 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; @@ -733,6 +736,8 @@ 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; @@ -754,6 +759,8 @@ 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; @@ -965,6 +972,7 @@ var OuterLoop: Boolean; MID: Byte; Ptr: Pointer; + Len: LongWord; msgStream: TMemoryStream; begin FillChar(downloadEvent, SizeOf(downloadEvent), 0); @@ -976,6 +984,8 @@ begin begin if (downloadEvent.kind = ENET_EVENT_TYPE_RECEIVE) and (downloadEvent.packet^.dataLength > 2) then begin + Len := PWord(downloadEvent.packet^.data)^; + if Len = 0 then break; Ptr := downloadEvent.packet^.data + 2; // skip length MID := Byte(Ptr^); @@ -1131,20 +1141,28 @@ begin NetDumpFile := createDiskFile(NETDUMP_FILENAME + '_client'); end; -procedure g_Net_DumpSendBuffer(); +procedure g_Net_DumpSendBuffer(Buf: pTBuffer); begin + writeInt(NetDumpFile, Byte($BA)); + writeInt(NetDumpFile, Byte($BE)); + writeInt(NetDumpFile, Byte($FF)); writeInt(NetDumpFile, gTime); - writeInt(NetDumpFile, LongWord(NetOut.WritePos)); - writeInt(NetDumpFile, Byte(1)); - NetDumpFile.WriteBuffer(NetOut.Data[0], NetOut.WritePos); + writeInt(NetDumpFile, Byte($FF)); + writeInt(NetDumpFile, LongWord(Buf^.WritePos)); + writeInt(NetDumpFile, Byte($FF)); + NetDumpFile.WriteBuffer(Buf^.Data[0], Buf^.WritePos); end; procedure g_Net_DumpRecvBuffer(Buf: penet_uint8; Len: LongWord); begin if (Buf = nil) or (Len = 0) then Exit; + writeInt(NetDumpFile, Byte($B0)); + writeInt(NetDumpFile, Byte($0B)); + writeInt(NetDumpFile, Byte($FF)); writeInt(NetDumpFile, gTime); + writeInt(NetDumpFile, Byte($FF)); writeInt(NetDumpFile, Len); - writeInt(NetDumpFile, Byte(0)); + writeInt(NetDumpFile, Byte($FF)); NetDumpFile.WriteBuffer(Buf^, Len); end; diff --git a/src/game/g_nethandler.pas b/src/game/g_nethandler.pas index b8d7c80..67b50dd 100644 --- a/src/game/g_nethandler.pas +++ b/src/game/g_nethandler.pas @@ -42,6 +42,8 @@ begin while RawPos < P^.dataLength do begin Len := e_Raw_Read_Word(B); + if Len = 0 then break; + MID := e_Raw_Read_Byte(B); case MID of NET_MSG_CHAT: MC_RECV_Chat(B); @@ -103,6 +105,8 @@ begin while RawPos < P^.dataLength do begin Len := e_Raw_Read_Word(B); + if Len = 0 then break; + MID := e_Raw_Read_Byte(B); case MID of NET_MSG_GEVENT: MC_RECV_GameEvent(B); @@ -136,6 +140,8 @@ begin while RawPos < P^.dataLength do begin Len := e_Raw_Read_Word(B); + if Len = 0 then break; + MID := e_Raw_Read_Byte(B); case MID of NET_MSG_INFO: MH_RECV_Info(S, B); -- 2.29.2