DEADSOFTWARE

buffer network messages (broke a lot of shit)
[d2df-sdl.git] / src / game / g_netmaster.pas
index 194a1eda69d89aaaa2212206c09b3f4cc2293086..bc7d4ae30aaa7e19d9d8671d5e32106ab5166b1f 100644 (file)
@@ -1,3 +1,19 @@
+(* Copyright (C)  DooM 2D:Forever Developers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *)
+{$INCLUDE g_amodes.inc}
 unit g_netmaster;
 
 interface
@@ -23,7 +39,7 @@ type
     Port: Word;
     Map: string;
     Players, MaxPlayers, LocalPl, Bots: Byte;
-    Ping: Integer;
+    Ping: Int64;
     GameMode: Byte;
     Password: Boolean;
     PingAddr: ENetAddress;
@@ -57,8 +73,7 @@ implementation
 
 uses
   SysUtils, e_fixedbuffer, e_input, e_graphics, e_log, g_window, g_net, g_console,
-  g_map, g_game, g_sound, g_textures, g_gui, g_menu, g_options, g_language, WADEDITOR,
-  ENetPlatform;
+  g_map, g_game, g_sound, g_textures, g_gui, g_menu, g_options, g_language, wadreader;
 
 var
   NetMEvent:      ENetEvent;
@@ -66,25 +81,25 @@ var
   slFetched:      Boolean = False;
   slDirPressed:   Boolean = False;
 
-function GetTimerMS(): Integer;
+function GetTimerMS(): Int64;
 begin
-  Result := GetTimer() div 1000;
+  Result := GetTimer() {div 1000};
 end;
 
 procedure PingServer(var S: TNetServer; Sock: ENetSocket);
 var
   Buf: ENetBuffer;
-  Ping: array [0..5] of Byte;
-  ClTime: Integer;
+  Ping: array [0..9] of Byte;
+  ClTime: Int64;
 begin
   ClTime := GetTimerMS();
 
   Buf.data := Addr(Ping[0]);
-  Buf.dataLength := 6;
+  Buf.dataLength := 2+8;
 
   Ping[0] := Ord('D');
   Ping[1] := Ord('F');
-  LongInt(Addr(Ping[2])^) := ClTime;
+  Int64(Addr(Ping[2])^) := ClTime;
 
   enet_socket_send(Sock, Addr(S.PingAddr), @Buf, 1);
 end;
@@ -94,7 +109,8 @@ var
   Cnt: Byte;
   P: pENetPacket;
   MID: Byte;
-  I, T, RX: Integer;
+  I, RX: Integer;
+  T: Int64;
   Sock: ENetSocket;
   Buf: ENetBuffer;
   SvAddr: ENetAddress;
@@ -114,7 +130,7 @@ begin
   e_Buffer_Clear(@NetOut);
   e_Buffer_Write(@NetOut, Byte(NET_MMSG_GET));
 
-  P := enet_packet_create(Addr(NetOut.Data), NetOut.Len, Cardinal(ENET_PACKET_FLAG_RELIABLE));
+  P := enet_packet_create(Addr(NetOut.Data), NetOut.WritePos, Cardinal(ENET_PACKET_FLAG_RELIABLE));
   enet_peer_send(NetMPeer, NET_MCHAN_MAIN, P);
   enet_host_flush(NetMHost);
 
@@ -130,6 +146,7 @@ begin
       Cnt := e_Raw_Read_Byte(NetMEvent.packet^.data);
       e_WriteLog('Retrieved ' + IntToStr(Cnt) + ' server(s).', MSG_NOTIFY);
       g_Console_Add(_lc[I_NET_MSG] + Format(_lc[I_NET_SLIST_RETRIEVED], [Cnt]), True);
+      //writeln('BOO!');
 
       if Cnt > 0 then
       begin
@@ -184,7 +201,7 @@ begin
 
     RX := enet_socket_receive(Sock, @SvAddr, @Buf, 1);
     if RX <= 0 then continue;
-    NetIn.Len := RX + 1;
+    NetIn.Cap := RX + 1;
     NetIn.ReadPos := 0;
 
     if e_Buffer_Read_Char(@NetIn) <> 'D' then continue;
@@ -196,7 +213,7 @@ begin
       begin
         with SL[I] do
         begin
-          Ping := e_Buffer_Read_LongInt(@NetIn);
+          Ping := e_Buffer_Read_Int64(@NetIn);
           Ping := GetTimerMS() - Ping;
           Name := e_Buffer_Read_String(@NetIn);
           Map := e_Buffer_Read_String(@NetIn);
@@ -221,8 +238,8 @@ var
   Wad, Map: string;
   Cli: Byte;
 begin
-  g_ProcessResourceStr(gMapInfo.Map, @Wad, nil, @Map);
-  Wad := ExtractFileName(Wad);
+  Wad := g_ExtractWadNameNoPath(gMapInfo.Map);
+  Map := g_ExtractFileName(gMapInfo.Map);
 
   e_Buffer_Write(@NetOut, NetServerName);
 
@@ -252,7 +269,7 @@ begin
 
   g_Net_Slist_WriteInfo();
 
-  P := enet_packet_create(Addr(NetOut.Data), NetOut.Len, Cardinal(ENET_PACKET_FLAG_RELIABLE));
+  P := enet_packet_create(Addr(NetOut.Data), NetOut.WritePos, Cardinal(ENET_PACKET_FLAG_RELIABLE));
   enet_peer_send(NetMPeer, NET_MCHAN_UPD, P);
 
   enet_host_flush(NetMHost);
@@ -268,7 +285,7 @@ begin
   e_Buffer_Write(@NetOut, Byte(NET_MMSG_DEL));
   e_Buffer_Write(@NetOut, NetAddr.port);
 
-  P := enet_packet_create(Addr(NetOut.Data), NetOut.Len, Cardinal(ENET_PACKET_FLAG_RELIABLE));
+  P := enet_packet_create(Addr(NetOut.Data), NetOut.WritePos, Cardinal(ENET_PACKET_FLAG_RELIABLE));
   enet_peer_send(NetMPeer, NET_MCHAN_MAIN, P);
 
   enet_host_flush(NetMHost);
@@ -526,7 +543,7 @@ begin
 
   if SL = nil then Exit;
 
-  if e_KeyPressed(IK_RETURN) then
+  if e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) then
   begin
     if not slReturnPressed then
     begin
@@ -550,7 +567,7 @@ begin
   else
     slReturnPressed := False;
 
-  if e_KeyPressed(IK_DOWN) then
+  if e_KeyPressed(IK_DOWN) or e_KeyPressed(IK_KPDOWN) then
   begin
     if not slDirPressed then
     begin
@@ -560,7 +577,7 @@ begin
     end;
   end;
 
-  if e_KeyPressed(IK_UP) then
+  if e_KeyPressed(IK_UP) or e_KeyPressed(IK_KPUP) then
   begin
     if not slDirPressed then
     begin
@@ -571,7 +588,7 @@ begin
     end;
   end;
 
-  if (not e_KeyPressed(IK_DOWN)) and (not e_KeyPressed(IK_UP)) then
+  if (not e_KeyPressed(IK_DOWN)) and (not e_KeyPressed(IK_UP)) and (not e_KeyPressed(IK_KPDOWN)) and (not e_KeyPressed(IK_KPUP)) then
     slDirPressed := False;
 end;