DEADSOFTWARE

cleanup: remove g_main.pas
[d2df-sdl.git] / src / game / g_net.pas
index 07d9713477ed7da1251d54bfffac53b3cfd5d9b7..2316d1c7e5e77f354434d250c393a516c38660e4 100644 (file)
@@ -172,6 +172,8 @@ var
   NetGotEverything: Boolean = False;
   NetGotKeys:       Boolean = False;
 
+  NetDeafLevel: Integer = 0;
+
 {$IFDEF USE_MINIUPNPC}
   NetPortForwarded: Word = 0;
   NetPongForwarded: Boolean = False;
@@ -252,9 +254,9 @@ implementation
 
 uses
   SysUtils,
-  e_input, e_res,
+  e_input, e_res, g_options,
   g_nethandler, g_netmsg, g_netmaster, g_player, g_window, g_console,
-  g_main, g_game, g_language, g_weapons, ctypes, g_system, g_map;
+  g_game, g_language, g_weapons, ctypes, g_system, g_map;
 
 const
   FILE_CHUNK_SIZE = 8192;
@@ -271,7 +273,10 @@ begin
 end;
 
 procedure g_Net_InitLowLevel ();
+  var v: ENetVersion;
 begin
+  v := enet_linked_version();
+  e_LogWritefln('ENet Version: %s.%s.%s', [ENET_VERSION_GET_MAJOR(v), ENET_VERSION_GET_MINOR(v), ENET_VERSION_GET_PATCH(v)]);
   if enet_init_success then raise Exception.Create('wuta?!');
   enet_init_success := (enet_initialize() = 0);
 end;
@@ -1492,8 +1497,6 @@ begin
   NetAddr.host := IPAddr;
   NetAddr.port := Port;
 
-  if NetForwardPorts then NetPortThread := BeginThread(ForwardThread);
-
   NetHost := enet_host_create(@NetAddr, NET_MAXCLIENTS, NET_CHANS, 0, 0);
 
   if (NetHost = nil) then
@@ -1504,6 +1507,8 @@ begin
     Exit;
   end;
 
+  if NetForwardPorts then NetPortThread := BeginThread(ForwardThread);
+
   NetPongSock := enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM);
   if NetPongSock <> ENET_SOCKET_NULL then
   begin
@@ -1606,7 +1611,7 @@ var
   Ping: array [0..9] of Byte;
   NPl: Byte;
 begin
-  if NetPongSock = ENET_SOCKET_NULL then Exit;
+  if (NetPongSock = ENET_SOCKET_NULL) or (NetHost = nil) then Exit;
 
   Buf.data := Addr(Ping[0]);
   Buf.dataLength := 2+8;
@@ -2238,6 +2243,9 @@ var
 begin
   Result := False;
 
+  if NetHost = nil then
+    exit;
+
   if NetPortForwarded = NetHost.address.port then
   begin
     Result := True;
@@ -2436,6 +2444,7 @@ initialization
   conRegVar('cl_interp', @NetInterpLevel, '', 'net player interpolation steps');
   conRegVar('cl_last_ip', @NetClientIP, '', 'address of the last you have connected to');
   conRegVar('cl_last_port', @NetClientPort, '', 'port of the last server you have connected to');
+  conRegVar('cl_deafen', @NetDeafLevel, '', 'filter server messages (0-3)');
 
   conRegVar('sv_forwardports', @NetForwardPorts, '', 'forward server port using miniupnpc (requires server restart)');
   conRegVar('sv_rcon', @NetAllowRCON, '', 'enable remote console');