DEADSOFTWARE

attempt to unfuck serverlist
[d2df-sdl.git] / src / game / g_netmaster.pas
index 67747595d085f70169932a4cc1c984982c3fbbb3..391d7729cf405f7e38ba25324f95318487e76af2 100644 (file)
@@ -133,7 +133,7 @@ var
   NMASTER_FORCE_UPDATE_TIMEOUT: Integer = 0; // fuck you, fpc, and your idiotic "diagnostics"
 
 
-procedure g_Net_Slist_Set (IP: AnsiString; Port: Word; list: AnsiString='');
+procedure g_Net_Slist_Set (list: AnsiString);
 function g_Net_Slist_Fetch (var SL: TNetServerList): Boolean;
 
 // make this server private
@@ -1053,7 +1053,7 @@ end;
 //  g_Net_Slist_Set
 //
 //==========================================================================
-procedure g_Net_Slist_Set (IP: AnsiString; Port: Word; list: AnsiString='');
+procedure g_Net_Slist_Set (list: AnsiString);
 var
   f, dest: Integer;
   sa: AnsiString;
@@ -1064,13 +1064,6 @@ begin
 
   for f := 0 to High(mlist) do mlist[f].justAdded := false;
 
-  IP := Trim(IP);
-  if (length(IP) > 0) and (Port > 0) then
-  begin
-    sa := IP+':'+IntToStr(Port);
-    if parseAddressPort(ea, sa) then addMasterRecord(ea, sa);
-  end;
-
   list := Trim(list);
   //writeln('list=[', list, ']');
   while (length(list) > 0) do
@@ -1373,6 +1366,7 @@ var
   aliveCount: Integer;
   hasUnanswered: Boolean;
   stt, ct: Int64;
+  tmpsv: TNetServer;
 begin
   result := false;
   SL := nil;
@@ -1559,32 +1553,43 @@ begin
       if InMsg.ReadChar() <> 'D' then continue;
       if InMsg.ReadChar() <> 'F' then continue;
 
+      with tmpsv do
+      begin
+        Port := InMsg.ReadWord();
+        Ping := InMsg.ReadInt64();
+        Ping := GetTimerMS() - Ping;
+        Name := InMsg.ReadString();
+        Map := InMsg.ReadString();
+        GameMode := InMsg.ReadByte();
+        Players := InMsg.ReadByte();
+        MaxPlayers := InMsg.ReadByte();
+        Protocol := InMsg.ReadByte();
+        Password := InMsg.ReadByte() = 1;
+        LocalPl := InMsg.ReadByte();
+        Bots := InMsg.ReadWord();
+        PingAddr := SvAddr;
+      end;
+
       FromSL := False;
       for I := Low(SL) to High(SL) do
         if (SL[I].PingAddr.host = SvAddr.host) and
-           (SL[I].PingAddr.port = SvAddr.port) then
+           (SL[I].PingAddr.port = SvAddr.port) and
+           (SL[I].Port = tmpsv.Port) then
         begin
-          with SL[I] do
-          begin
-            Port := InMsg.ReadWord();
-            Ping := InMsg.ReadInt64();
-            Ping := GetTimerMS() - Ping;
-            Name := InMsg.ReadString();
-            Map := InMsg.ReadString();
-            GameMode := InMsg.ReadByte();
-            Players := InMsg.ReadByte();
-            MaxPlayers := InMsg.ReadByte();
-            Protocol := InMsg.ReadByte();
-            Password := InMsg.ReadByte() = 1;
-            LocalPl := InMsg.ReadByte();
-            Bots := InMsg.ReadWord();
-          end;
+          tmpsv.IP := SL[I].IP;
+          SL[I] := tmpsv;
           FromSL := True;
           Inc(Cnt);
           break;
         end;
+
       if not FromSL then
-        ProcessLocal();
+      begin
+        I := Length(SL);
+        SetLength(SL, I + 1);
+        tmpsv.IP := DecodeIPV4(SvAddr.host);
+        SL[I] := tmpsv;
+      end;
     end;
 
     InMsg.Free();
@@ -1785,7 +1790,7 @@ procedure g_Serverlist_GenerateTable (SL: TNetServerList; var ST: TNetServerTabl
 var
   i, j: Integer;
 
-  function FindServerInTable(Name: AnsiString): Integer;
+  function FindServerInTable(Name: AnsiString; Port: Word): Integer;
   var
     i: Integer;
   begin
@@ -1796,7 +1801,7 @@ var
     begin
       if Length(ST[i].Indices) = 0 then
         continue;
-      if SL[ST[i].Indices[0]].Name = Name then
+      if (SL[ST[i].Indices[0]].Name = Name) and (SL[ST[i].Indices[0]].Port = Port) then
       begin
         Result := i;
         Exit;
@@ -1845,9 +1850,10 @@ begin
   ST := nil;
   if SL = nil then
     Exit;
+
   for i := Low(SL) to High(SL) do
   begin
-    j := FindServerInTable(SL[i].Name);
+    j := FindServerInTable(SL[i].Name, SL[i].Port);
     if j = -1 then
     begin
       j := Length(ST);