From: Ketmar Dark Date: Fri, 11 Oct 2019 21:09:23 +0000 (+0300) Subject: net: try to abort map downloading when client received "map change" event X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=b171ccb122f9084809e739b19baf68bba80a9dab;p=d2df-sdl.git net: try to abort map downloading when client received "map change" event we could restart downloading with the new map hash instead, but meh... anyway, aborting is better than trying to download some obsolete crap. --- diff --git a/src/game/g_game.pas b/src/game/g_game.pas index babcb8e..46251bb 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -4629,9 +4629,18 @@ begin begin if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then begin + if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then + begin + // ignore all download packets, they're processed by separate code + enet_packet_destroy(NetEvent.packet); + continue; + end; Ptr := NetEvent.packet^.data; if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then + begin + enet_packet_destroy(NetEvent.packet); continue; + end; InMsg.ReadLongWord(); // skip size MID := InMsg.ReadByte(); diff --git a/src/game/g_net.pas b/src/game/g_net.pas index 60d91c1..82f4632 100644 --- a/src/game/g_net.pas +++ b/src/game/g_net.pas @@ -181,6 +181,9 @@ var NetDumpFile: TStream; + g_Res_received_map_start: Boolean = false; // set if we received "map change" event + + function g_Net_Init(): Boolean; procedure g_Net_Cleanup(); procedure g_Net_Free(); @@ -1210,6 +1213,7 @@ begin case NetEvent.kind of ENET_EVENT_TYPE_RECEIVE: begin + if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then continue; // ignore all download packets, they're processed by separate code if NetDump then g_Net_DumpRecvBuffer(NetEvent.packet^.data, NetEvent.packet^.dataLength); g_Net_Client_HandlePacket(NetEvent.packet, g_Net_ClientMsgHandler); end; @@ -1232,6 +1236,7 @@ begin case NetEvent.kind of ENET_EVENT_TYPE_RECEIVE: begin + if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then continue; // ignore all download packets, they're processed by separate code if NetDump then g_Net_DumpRecvBuffer(NetEvent.packet^.data, NetEvent.packet^.dataLength); g_Net_Client_HandlePacket(NetEvent.packet, g_Net_ClientLightMsgHandler); end; @@ -1611,6 +1616,9 @@ begin if (ev.channelID <> NET_CHAN_DOWNLOAD_EX) then begin //e_LogWritefln('g_Net_Wait_MapInfo: skip message from non-transfer channel', []); + freePacket := false; + g_Net_Client_HandlePacket(ev.packet, g_Net_ClientLightMsgHandler); + if (g_Res_received_map_start) then begin result := -666; exit; end; end else begin @@ -1789,6 +1797,9 @@ begin if (ev.channelID <> NET_CHAN_DOWNLOAD_EX) then begin //e_LogWriteln('g_Net_Wait_Event: skip message from non-transfer channel'); + freePacket := false; + g_Net_Client_HandlePacket(ev.packet, g_Net_ClientLightMsgHandler); + if (g_Res_received_map_start) then begin result := -666; exit; end; end else begin @@ -1967,6 +1978,9 @@ begin if (ev.channelID <> NET_CHAN_DOWNLOAD_EX) then begin //e_LogWritefln('g_Net_Wait_Event: skip message from non-transfer channel', []); + freePacket := false; + g_Net_Client_HandlePacket(ev.packet, g_Net_ClientLightMsgHandler); + if (g_Res_received_map_start) then begin result := -666; exit; end; end else begin diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index 2541dfd..0483bea 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -1709,6 +1709,7 @@ begin case EvType of NET_EV_MAPSTART: begin + g_Res_received_map_start := true; gGameOn := False; g_Game_ClearLoading(); g_Game_StopAllSounds(True); @@ -1731,6 +1732,7 @@ begin NET_EV_MAPEND: begin + g_Res_received_map_start := true; gMissionFailed := EvNum <> 0; gExit := EXIT_ENDLEVELCUSTOM; end; diff --git a/src/game/g_res_downloader.pas b/src/game/g_res_downloader.pas index a092437..ed1ea3b 100644 --- a/src/game/g_res_downloader.pas +++ b/src/game/g_res_downloader.pas @@ -286,6 +286,7 @@ begin //result := g_Res_SearchResWad(true{asMap}, mapHash); result := ''; g_Res_ClearReplacementWads(); + g_Res_received_map_start := false; try CreateDir(GameDir+'/maps/downloads');