summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1cae0b1)
raw | patch | inline | side by side (parent: 1cae0b1)
author | fgsfds <pvt.fgsfds@gmail.com> | |
Mon, 5 Feb 2018 18:54:46 +0000 (21:54 +0300) | ||
committer | fgsfds <pvt.fgsfds@gmail.com> | |
Mon, 5 Feb 2018 18:54:46 +0000 (21:54 +0300) |
src/game/g_net.pas | patch | blob | history |
diff --git a/src/game/g_net.pas b/src/game/g_net.pas
index 6d6be993ebc751a06046fae9e04a6bbffe618207..95f8f459b862c6a0253d699b0c89715040bcb1a6 100644 (file)
--- a/src/game/g_net.pas
+++ b/src/game/g_net.pas
NetPongForwarded: Boolean = False;
NetIGDControl: AnsiString;
NetIGDService: TURLStr;
+ NetPortThread: TThreadID = 0;
{$ENDIF}
NetDumpFile: TStream;
NetMode := NET_NONE;
+ if NetPortThread <> 0 then
+ WaitForThreadTerminate(NetPortThread, 66666);
+
+ NetPortThread := 0;
g_Net_UnforwardPorts();
if NetDump then
{ /// SERVER FUNCTIONS /// }
+function ForwardThread(Param: Pointer): PtrInt;
+begin
+ Result := 0;
+ if not g_Net_ForwardPorts() then Result := -1;
+end;
+
function g_Net_Host(IPAddr: LongWord; Port: enet_uint16; MaxClients: Cardinal = 16): Boolean;
begin
if NetMode <> NET_NONE then
NetAddr.host := IPAddr;
NetAddr.port := Port;
- if NetForwardPorts then g_Net_ForwardPorts();
+ if NetForwardPorts then NetPortThread := BeginThread(ForwardThread);
NetHost := enet_host_create(@NetAddr, NET_MAXCLIENTS, NET_CHANS, 0, 0);
Urls: TUPNPUrls;
Data: TIGDDatas;
LanAddr: array [0..255] of Char;
- ExtAddr: array [0..40] of Char;
StrPort: AnsiString;
Err, I: Integer;
begin
exit;
end;
- conwriteln('trying to forward server ports...');
-
NetPongForwarded := False;
NetPortForwarded := 0;
DevList := upnpDiscover(1000, nil, nil, 0, 0, Addr(Err));
if DevList = nil then
begin
- conwritefln(' upnpDiscover() failed: %d', [Err]);
+ conwritefln('port forwarding failed: upnpDiscover() failed: %d', [Err]);
exit;
end;
if I = 0 then
begin
- conwriteln(' could not find an IGD device on this LAN, aborting');
+ conwriteln('port forwarding failed: could not find an IGD device on this LAN');
FreeUPNPDevList(DevList);
FreeUPNPUrls(@Urls);
exit;
- end
- else if I = 1 then
- conwritefln(' found IGD @ %s', [Urls.controlURL])
- else
- conwritefln(' found some kind of UPNP device @ %s, maybe it''ll work', [Urls.controlURL]);
-
- UPNP_GetExternalIPAddress(Urls.controlURL, Addr(data.first.servicetype[1]), Addr(ExtAddr[0]));
- if ExtAddr[0] <> #0 then
- conwritefln(' external IP address: %s', [Addr(ExtAddr[0])]);
+ end;
StrPort := IntToStr(NetPort);
I := UPNP_AddPortMapping(
if I <> 0 then
begin
- conwritefln(' forwarding port %d failed: error %d', [NetPort, I]);
+ conwritefln('forwarding port %d failed: error %d', [NetPort, I]);
FreeUPNPDevList(DevList);
FreeUPNPUrls(@Urls);
exit;
if I <> 0 then
begin
- conwritefln(' forwarding port %d failed: error %d', [NetPort + 1, I]);
+ conwritefln('forwarding port %d failed: error %d', [NetPort + 1, I]);
NetPongForwarded := False;
end
else
begin
- conwritefln(' forwarded port %d successfully', [NetPort + 1]);
+ conwritefln('forwarded port %d successfully', [NetPort + 1]);
NetPongForwarded := True;
end;
end;
- conwritefln(' forwarded port %d successfully', [NetPort]);
+ conwritefln('forwarded port %d successfully', [NetPort]);
NetIGDControl := AnsiString(Urls.controlURL);
NetIGDService := data.first.servicetype;
NetPortForwarded := NetPort;