X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=blobdiff_plain;f=src%2Fgame%2Fg_net.pas;h=c15df2bae9406b2cc043fce515bdc11b113b21da;hp=95f8f459b862c6a0253d699b0c89715040bcb1a6;hb=ef4db75afec0dcd71f0bbe75b5f0b20537c8eac1;hpb=08ddabc37acc6f5655533fddefbe8a9b8ed95e76 diff --git a/src/game/g_net.pas b/src/game/g_net.pas index 95f8f45..c15df2b 100644 --- a/src/game/g_net.pas +++ b/src/game/g_net.pas @@ -22,7 +22,7 @@ uses e_log, e_msg, ENet, Classes, MAPDEF{$IFDEF USE_MINIUPNPC}, miniupnpc;{$ELSE};{$ENDIF} const - NET_PROTOCOL_VER = 173; + NET_PROTOCOL_VER = 174; NET_MAXCLIENTS = 24; NET_CHANS = 11; @@ -44,6 +44,7 @@ const NET_CLIENT = 2; NET_BUFSIZE = $FFFF; + NET_PING_PORT = $DF2D; NET_EVERYONE = -1; @@ -65,6 +66,12 @@ const BANLIST_FILENAME = 'banlist.txt'; NETDUMP_FILENAME = 'netdump'; + {$IFDEF FREEBSD} + NilThreadId = nil; + {$ELSE} + NilThreadId = 0; + {$ENDIF} + type TNetClient = record ID: Byte; @@ -146,9 +153,10 @@ var NetPongForwarded: Boolean = False; NetIGDControl: AnsiString; NetIGDService: TURLStr; - NetPortThread: TThreadID = 0; {$ENDIF} + NetPortThread: TThreadID = NilThreadId; + NetDumpFile: TStream; function g_Net_Init(): Boolean; @@ -171,7 +179,7 @@ function g_Net_Client_ByName(Name: string): pTNetClient; function g_Net_Client_ByPlayer(PID: Word): pTNetClient; function g_Net_ClientName_ByID(ID: Integer): string; -procedure g_Net_SendData(Data:AByte; peer: pENetPeer; Reliable: Boolean; Chan: Byte = NET_CHAN_DOWNLOAD); +procedure g_Net_SendData(Data: AByte; peer: pENetPeer; Reliable: Boolean; Chan: Byte = NET_CHAN_DOWNLOAD); function g_Net_Wait_Event(msgId: Word): TMemoryStream; function IpToStr(IP: LongWord): string; @@ -317,10 +325,10 @@ begin NetMode := NET_NONE; - if NetPortThread <> 0 then + if NetPortThread <> NilThreadId then WaitForThreadTerminate(NetPortThread, 66666); - NetPortThread := 0; + NetPortThread := NilThreadId; g_Net_UnforwardPorts(); if NetDump then @@ -388,7 +396,7 @@ begin if NetPongSock <> ENET_SOCKET_NULL then begin NetPongAddr.host := IPAddr; - NetPongAddr.port := Port + 1; + NetPongAddr.port := NET_PING_PORT; if enet_socket_bind(NetPongSock, @NetPongAddr) < 0 then begin enet_socket_destroy(NetPongSock); @@ -503,6 +511,7 @@ begin NetOut.Clear(); NetOut.Write(Byte(Ord('D'))); NetOut.Write(Byte(Ord('F'))); + NetOut.Write(NetPort); NetOut.Write(ClTime); g_Net_Slist_WriteInfo(); NPl := 0; @@ -531,10 +540,8 @@ begin Result := 0; if NetUseMaster then - begin g_Net_Slist_Check; - g_Net_Host_CheckPings; - end; + g_Net_Host_CheckPings; while (enet_host_service(NetHost, @NetEvent, 0) > 0) do begin @@ -815,7 +822,7 @@ begin ProcessLoading(true); - if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then + if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_ESCAPE) then OuterLoop := False; end; @@ -900,7 +907,7 @@ begin end; end; -procedure g_Net_SendData(Data:AByte; peer: pENetPeer; Reliable: Boolean; Chan: Byte = NET_CHAN_DOWNLOAD); +procedure g_Net_SendData(Data: AByte; peer: pENetPeer; Reliable: Boolean; Chan: Byte = NET_CHAN_DOWNLOAD); var P: pENetPacket; F: enet_uint32; @@ -978,7 +985,7 @@ begin ProcessLoading(true); - if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then + if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_ESCAPE) then break; end; Result := msgStream; @@ -1144,7 +1151,7 @@ begin NetPongForwarded := False; NetPortForwarded := 0; - DevList := upnpDiscover(1000, nil, nil, 0, 0, Addr(Err)); + DevList := upnpDiscover(1000, nil, nil, 0, 0, 2, Addr(Err)); if DevList = nil then begin conwritefln('port forwarding failed: upnpDiscover() failed: %d', [Err]); @@ -1178,7 +1185,7 @@ begin if ForwardPongPort then begin - StrPort := IntToStr(NetPort + 1); + StrPort := IntToStr(NET_PING_PORT); I := UPNP_AddPortMapping( Urls.controlURL, Addr(data.first.servicetype[1]), PChar(StrPort), PChar(StrPort), Addr(LanAddr[0]), PChar('D2DF'),