DEADSOFTWARE

net: try to abort map downloading when client received "map change" event
authorKetmar Dark <ketmar@ketmar.no-ip.org>
Fri, 11 Oct 2019 21:09:23 +0000 (00:09 +0300)
committerKetmar Dark <ketmar@ketmar.no-ip.org>
Sat, 12 Oct 2019 15:54:12 +0000 (18:54 +0300)
  we could restart downloading with the new map hash instead, but meh...
  anyway, aborting is better than trying to download some obsolete crap.

src/game/g_game.pas
src/game/g_net.pas
src/game/g_netmsg.pas
src/game/g_res_downloader.pas

index babcb8e2cd3e7f2a19b28a00218cc5d3ea107416..46251bb7d3e2684ec69a340f2ad415de97f6f821 100644 (file)
@@ -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();
index 60d91c110a118bfe840059d4ffd01035a84ee95c..82f4632a28c22fefd344cdca1e406d3f547534e0 100644 (file)
@@ -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
index 2541dfd37de2abcb9969a41fb9dace000ab37f71..0483bea1651608dc407895e67f6125f568f932f1 100644 (file)
@@ -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;
index a092437993d1601f774deb9235ff1ac037916e7d..ed1ea3bdf3feb7c77de12529d99b0b146c67d94b 100644 (file)
@@ -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');