From: Stas'M Date: Sat, 14 Mar 2020 19:50:40 +0000 (+0300) Subject: Net: Add sanity checks. Forward ports only after host is created. X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=bb118168f4465ea81396ae6bbf2c11baaba6539e;p=d2df-sdl.git Net: Add sanity checks. Forward ports only after host is created. Addendum to 10f31fd. --- diff --git a/src/game/g_net.pas b/src/game/g_net.pas index 07d9713..7dad24c 100644 --- a/src/game/g_net.pas +++ b/src/game/g_net.pas @@ -1492,8 +1492,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 +1502,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 +1606,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 +2238,9 @@ var begin Result := False; + if NetHost = nil then + exit; + if NetPortForwarded = NetHost.address.port then begin Result := True;