X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_net.pas;h=95686fe911a14e226c33f234963369657a6954b1;hb=ee582ed196b2c56776d407e22bdaaffc5b1ac6ff;hp=11acd5f079370213b7f3db2e0c7799149a4670d2;hpb=2304c541d7bdbf7de389437482ecdff37fc7fbd5;p=d2df-sdl.git diff --git a/src/game/g_net.pas b/src/game/g_net.pas index 11acd5f..95686fe 100644 --- a/src/game/g_net.pas +++ b/src/game/g_net.pas @@ -18,10 +18,10 @@ unit g_net; interface uses - e_log, e_msg, ENet, Classes, md5, MAPDEF{$IFDEF USE_MINIUPNPC}, miniupnpc;{$ELSE};{$ENDIF} + e_log, e_msg, utils, ENet, Classes, md5, MAPDEF{$IFDEF USE_MINIUPNPC}, miniupnpc;{$ELSE};{$ENDIF} const - NET_PROTOCOL_VER = 182; + NET_PROTOCOL_VER = 187; NET_MAXCLIENTS = 24; NET_CHANS = 12; @@ -72,12 +72,6 @@ const BANLIST_FILENAME = 'banlist.txt'; NETDUMP_FILENAME = 'netdump'; - {$IF DEFINED(FREEBSD) OR DEFINED(DARWIN)} - NilThreadId = nil; - {$ELSE} - NilThreadId = 0; - {$ENDIF} - type TNetMapResourceInfo = record wadName: AnsiString; // wad file name, without a path @@ -111,6 +105,9 @@ type WaitForFirstSpawn: Boolean; // set to `true` in server, used to spawn a player on first full state request RCONAuth: Boolean; Voted: Boolean; + Crimes: Integer; + AuthTime: LongWord; + MsgTime: LongWord; Transfer: TNetFileTransfer; // only one transfer may be active NetOut: array [0..1] of TMsg; end; @@ -147,9 +144,7 @@ var NetPongSock: ENetSocket = ENET_SOCKET_NULL; NetUseMaster: Boolean = True; - NetSlistAddr: ENetAddress; - NetSlistIP: string = 'mpms.doom2d.org'; - NetSlistPort: Word = 25665; + NetMasterList: string = 'mpms.doom2d.org:25665, deadsoftware.ru:25665'; NetClientIP: string = '127.0.0.1'; NetClientPort: Word = 25666; @@ -162,6 +157,13 @@ var NetMaxClients: Byte = 255; NetBannedHosts: array of TBanRecord; + NetAutoBanLimit: Integer = 5; + NetAutoBanPerm: Boolean = True; + NetAutoBanWarn: Boolean = False; + + NetAuthTimeout: Integer = 36 * 15; + NetPacketTimeout: Integer = 36 * 30; + NetState: Integer = NET_STATE_NONE; NetMyID: Integer = -1; @@ -180,6 +182,8 @@ var NetGotEverything: Boolean = False; NetGotKeys: Boolean = False; + NetDeafLevel: Integer = 0; + {$IFDEF USE_MINIUPNPC} NetPortForwarded: Word = 0; NetPongForwarded: Boolean = False; @@ -229,6 +233,8 @@ function g_Net_UnbanHost(IP: LongWord): Boolean; overload; procedure g_Net_UnbanNonPermHosts(); procedure g_Net_SaveBanList(); +procedure g_Net_Penalize(C: pTNetClient; Reason: string); + procedure g_Net_DumpStart(); procedure g_Net_DumpSendBuffer(); procedure g_Net_DumpRecvBuffer(Buf: penet_uint8; Len: LongWord); @@ -244,23 +250,59 @@ function g_Net_RequestResFileInfo (resIndex: LongInt; out tf: TNetFileTransfer): function g_Net_AbortResTransfer (var tf: TNetFileTransfer): Boolean; function g_Net_ReceiveResourceFile (resIndex: LongInt; var tf: TNetFileTransfer; strm: TStream): Integer; +function g_Net_IsNetworkAvailable (): Boolean; +procedure g_Net_InitLowLevel (); +procedure g_Net_DeinitLowLevel (); + +procedure NetServerCVars(P: SSArray); + implementation +// *enet_host_service()* +// fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html +// tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure. +// thank you, enet. let's ignore failures altogether then. + uses SysUtils, - e_input, g_nethandler, g_netmsg, g_netmaster, g_player, g_window, g_console, - g_main, g_game, g_language, g_weapons, utils, ctypes, g_system, - g_map; + e_input, e_res, + 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; const FILE_CHUNK_SIZE = 8192; var + enet_init_success: Boolean = false; g_Net_DownloadTimeout: Single; trans_omsg: TMsg; +function g_Net_IsNetworkAvailable (): Boolean; +begin + result := enet_init_success; +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; + +procedure g_Net_DeinitLowLevel (); +begin + if enet_init_success then + begin + enet_deinitialize(); + enet_init_success := false; + end; +end; + + //************************************************************************** // // SERVICE FUNCTIONS @@ -332,6 +374,7 @@ begin e_LogWritefln('disconnected client #%d due to file transfer error', [nc.ID], TMsgType.Warning); enet_peer_disconnect(nc.Peer, NET_DISC_FILE_TIMEOUT); clearNetClientTransfers(nc); + g_Net_Slist_ServerPlayerLeaves(); end; @@ -467,6 +510,12 @@ begin exit; end; + // don't time out clients during a file transfer + if (NetAuthTimeout > 0) then + nc^.AuthTime := gTime + NetAuthTimeout; + if (NetPacketTimeout > 0) then + nc^.MsgTime := gTime + NetPacketTimeout; + tf := @NetClients[nid].Transfer; tf.lastAckTime := GetTimerMS(); @@ -499,7 +548,7 @@ begin killClientByFT(nc^); exit; end; - if (ridx < 0) then fname := MapsDir+gGameSettings.WAD else fname := {GameDir+'/wads/'+}gExternalResources[ridx].diskName; + if (ridx < 0) then fname := gGameSettings.WAD else fname := gExternalResources[ridx].diskName; if (length(fname) = 0) then begin e_WriteLog('Invalid filename: '+fname, TMsgType.Warning); @@ -507,7 +556,6 @@ begin exit; end; tf.diskName := findDiskWad(fname); - //if (length(tf.diskName) = 0) then tf.diskName := findDiskWad(GameDir+'/wads/'+fname); if (length(tf.diskName) = 0) then begin e_LogWritefln('NETWORK: file "%s" not found!', [fname], TMsgType.Fatal); @@ -629,7 +677,7 @@ begin begin e_LogWritefln('client #%d requested map info', [nc.ID]); trans_omsg.Clear(); - dfn := findDiskWad(MapsDir+gGameSettings.WAD); + dfn := findDiskWad(gGameSettings.WAD); if (dfn = '') then dfn := '!wad_not_found!.wad'; //FIXME //md5 := MD5File(dfn); md5 := gWADHash; @@ -649,7 +697,7 @@ begin // packet type trans_omsg.Write(Byte(NTF_SERVER_MAP_INFO)); // map wad name - trans_omsg.Write(gGameSettings.WAD); + trans_omsg.Write(ExtractFileName(gGameSettings.WAD)); // map wad md5 trans_omsg.Write(md5); // map wad size @@ -740,13 +788,15 @@ begin ett := getNewTimeoutEnd(); repeat status := enet_host_service(NetHost, @ev, 300); + { if (status < 0) then begin g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' network error', True); Result := -1; exit; end; - if (status = 0) then + } + if (status <= 0) then begin // check for timeout ct := GetTimerMS(); @@ -919,13 +969,15 @@ begin ett := getNewTimeoutEnd(); repeat status := enet_host_service(NetHost, @ev, 300); + { if (status < 0) then begin g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' network error', True); Result := -1; exit; end; - if (status = 0) then + } + if (status <= 0) then begin // check for timeout ct := GetTimerMS(); @@ -1101,13 +1153,15 @@ begin repeat //stx := -GetTimerMS(); status := enet_host_service(NetHost, @ev, 300); + { if (status < 0) then begin g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' network error', True); Result := -1; exit; end; - if (status = 0) then + } + if (status <= 0) then begin // check for timeout ct := GetTimerMS(); @@ -1285,11 +1339,13 @@ begin Result := N; end; + function g_Net_Init(): Boolean; var F: TextFile; IPstr: string; IP: LongWord; + path: AnsiString; begin NetIn.Clear(); NetOut.Clear(); @@ -1304,9 +1360,10 @@ begin NetPlrUID2 := -1; NetAddr.port := 25666; SetLength(NetBannedHosts, 0); - if FileExists(DataDir + BANLIST_FILENAME) then + path := BANLIST_FILENAME; + if e_FindResource(DataDirs, path) = true then begin - Assign(F, DataDir + BANLIST_FILENAME); + Assign(F, path); Reset(F); while not EOF(F) do begin @@ -1318,7 +1375,8 @@ begin g_Net_SaveBanList(); end; - Result := (enet_initialize() = 0); + //Result := (enet_initialize() = 0); + Result := enet_init_success; end; procedure g_Net_Flush(); @@ -1385,8 +1443,7 @@ begin NetPeer := nil; NetHost := nil; - g_Net_Slist_NetworkStopped(); - //g_Net_Slist_Disconnect(false); // do not spam console + g_Net_Slist_ServerClosed(); NetMyID := -1; NetPlrUID1 := -1; NetPlrUID2 := -1; @@ -1414,7 +1471,7 @@ procedure g_Net_Free(); begin g_Net_Cleanup(); - enet_deinitialize(); + //enet_deinitialize(); NetInitDone := False; end; @@ -1458,8 +1515,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 @@ -1470,6 +1525,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 @@ -1516,13 +1573,16 @@ begin enet_peer_reset(NetClients[I].Peer); NetClients[I].Peer := nil; NetClients[I].Used := False; + NetClients[I].Player := 0; + NetClients[I].Crimes := 0; + NetClients[I].AuthTime := 0; + NetClients[I].MsgTime := 0; NetClients[I].NetOut[NET_UNRELIABLE].Free(); NetClients[I].NetOut[NET_RELIABLE].Free(); end; clearNetClients(false); // don't clear array - //if (g_Net_Slist_IsConnectionActive) then g_Net_Slist_Disconnect; - g_Net_Slist_NetworkStopped(); + g_Net_Slist_ServerClosed(); if NetPongSock <> ENET_SOCKET_NULL then enet_socket_destroy(NetPongSock); @@ -1573,7 +1633,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; @@ -1590,9 +1650,8 @@ begin NetOut.Clear(); NetOut.Write(Byte(Ord('D'))); NetOut.Write(Byte(Ord('F'))); - NetOut.Write(NetPort); + NetOut.Write(NetHost.address.port); NetOut.Write(ClTime); - //g_Net_Slist_WriteInfo(); TMasterHost.writeInfo(NetOut); NPl := 0; if gPlayer1 <> nil then Inc(NPl); @@ -1608,6 +1667,32 @@ begin end; end; +procedure g_Net_Host_CheckTimeouts(); +var + ID: Integer; +begin + // auth timeout + for ID := Low(NetClients) to High(NetClients) do + begin + with NetClients[ID] do + begin + if (Peer = nil) or (State = NET_STATE_NONE) then continue; + if (State = NET_STATE_AUTH) and (AuthTime > 0) and (AuthTime <= gTime) then + begin + g_Net_Penalize(@NetClients[ID], 'auth taking too long'); + AuthTime := gTime + 18; // do it twice a second to give them a chance + end + else if (State = NET_STATE_GAME) and (MsgTime > 0) and (MsgTime <= gTime) then + begin + g_Net_Penalize(@NetClients[ID], 'message timeout'); + AuthTime := gTime + 18; // do it twice a second to give them a chance + end; + end; + end; + + +end; + function g_Net_Host_Update(): enet_size_t; var @@ -1620,12 +1705,9 @@ begin IP := ''; Result := 0; - if NetUseMaster then - begin - //g_Net_Slist_Check; - g_Net_Slist_Pulse(); - end; - g_Net_Host_CheckPings; + if NetUseMaster then g_Net_Slist_Pulse(); + g_Net_Host_CheckPings(); + g_Net_Host_CheckTimeouts(); while (enet_host_service(NetHost, @NetEvent, 0) > 0) do begin @@ -1636,11 +1718,14 @@ begin Port := NetEvent.Peer^.address.port; g_Console_Add(_lc[I_NET_MSG] + Format(_lc[I_NET_MSG_HOST_CONN], [IP, Port])); + e_WriteLog('NET: Connection request from ' + IP + '.', TMsgType.Notify); if (NetEvent.data <> NET_PROTOCOL_VER) then begin g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] + _lc[I_NET_DISC_PROTOCOL]); + e_WriteLog('NET: Connection request from ' + IP + ' rejected: version mismatch', + TMsgType.Notify); NetEvent.peer^.data := GetMemory(SizeOf(Byte)); Byte(NetEvent.peer^.data^) := 255; enet_peer_disconnect(NetEvent.peer, NET_DISC_PROTOCOL); @@ -1648,12 +1733,27 @@ begin Exit; end; + if g_Net_IsHostBanned(NetEvent.Peer^.address.host) then + begin + g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] + + _lc[I_NET_DISC_BAN]); + e_WriteLog('NET: Connection request from ' + IP + ' rejected: banned', + TMsgType.Notify); + NetEvent.peer^.data := GetMemory(SizeOf(Byte)); + Byte(NetEvent.peer^.data^) := 255; + enet_peer_disconnect(NetEvent.Peer, NET_DISC_BAN); + enet_host_flush(NetHost); + Exit; + end; + ID := g_Net_FindSlot(); if ID < 0 then begin g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] + _lc[I_NET_DISC_FULL]); + e_WriteLog('NET: Connection request from ' + IP + ' rejected: server full', + TMsgType.Notify); NetEvent.Peer^.data := GetMemory(SizeOf(Byte)); Byte(NetEvent.peer^.data^) := 255; enet_peer_disconnect(NetEvent.peer, NET_DISC_FULL); @@ -1665,9 +1765,19 @@ begin NetClients[ID].Peer^.data := GetMemory(SizeOf(Byte)); Byte(NetClients[ID].Peer^.data^) := ID; NetClients[ID].State := NET_STATE_AUTH; + NetClients[ID].Player := 0; + NetClients[ID].Crimes := 0; NetClients[ID].RCONAuth := False; NetClients[ID].NetOut[NET_UNRELIABLE].Alloc(NET_BUFSIZE*2); NetClients[ID].NetOut[NET_RELIABLE].Alloc(NET_BUFSIZE*2); + if (NetAuthTimeout > 0) then + NetClients[ID].AuthTime := gTime + NetAuthTimeout + else + NetClients[ID].AuthTime := 0; + if (NetPacketTimeout > 0) then + NetClients[ID].MsgTime := gTime + NetPacketTimeout + else + NetClients[ID].MsgTime := 0; clearNetClientTransfers(NetClients[ID]); // just in case enet_peer_timeout(NetEvent.peer, ENET_PEER_TIMEOUT_LIMIT * 2, ENET_PEER_TIMEOUT_MINIMUM * 2, ENET_PEER_TIMEOUT_MAXIMUM * 2); @@ -1689,6 +1799,9 @@ begin if ID > High(NetClients) then Exit; TC := @NetClients[ID]; + if (NetPacketTimeout > 0) then + TC^.MsgTime := gTime + NetPacketTimeout; + if NetDump then g_Net_DumpRecvBuffer(NetEvent.packet^.data, NetEvent.packet^.dataLength); g_Net_Host_HandlePacket(TC, NetEvent.packet, g_Net_HostMsgHandler); end; @@ -1719,6 +1832,9 @@ begin TC^.State := NET_STATE_NONE; TC^.Peer := nil; TC^.Player := 0; + TC^.Crimes := 0; + TC^.AuthTime := 0; + TC^.MsgTime := 0; TC^.RequestedFullUpdate := False; TC^.WaitForFirstSpawn := False; TC^.NetOut[NET_UNRELIABLE].Free(); @@ -1729,11 +1845,7 @@ begin g_Console_Add(_lc[I_NET_MSG] + Format(_lc[I_NET_MSG_HOST_DISC], [ID])); Dec(NetClientCount); - if NetUseMaster then - begin - //g_Net_Slist_Update; - g_Net_Slist_Pulse(); - end; + if NetUseMaster then g_Net_Slist_ServerPlayerLeaves(); end; end; end; @@ -1813,7 +1925,7 @@ end; function g_Net_Client_Update(): enet_size_t; begin Result := 0; - while (enet_host_service(NetHost, @NetEvent, 0) > 0) do + while (NetHost <> nil) and (enet_host_service(NetHost, @NetEvent, 0) > 0) do begin case NetEvent.kind of ENET_EVENT_TYPE_RECEIVE: @@ -2155,22 +2267,53 @@ procedure g_Net_SaveBanList(); var F: TextFile; I: Integer; + path: AnsiString; +begin + path := e_GetWriteableDir(DataDirs); + if path <> '' then + begin + path := e_CatPath(path, BANLIST_FILENAME); + Assign(F, path); + Rewrite(F); + if NetBannedHosts <> nil then + for I := 0 to High(NetBannedHosts) do + if NetBannedHosts[I].Perm and (NetBannedHosts[I].IP > 0) then + Writeln(F, IpToStr(NetBannedHosts[I].IP)); + CloseFile(F) + end +end; + +procedure g_Net_Penalize(C: pTNetClient; Reason: string); +var + s: string; begin - Assign(F, DataDir + BANLIST_FILENAME); - Rewrite(F); - if NetBannedHosts <> nil then - for I := 0 to High(NetBannedHosts) do - if NetBannedHosts[I].Perm and (NetBannedHosts[I].IP > 0) then - Writeln(F, IpToStr(NetBannedHosts[I].IP)); - CloseFile(F); + e_LogWritefln('NET: client #%u (cid #%u) triggered a penalty (%d/%d): %s', + [C^.ID, C^.Player, C^.Crimes, NetAutoBanLimit, Reason]); + + if (NetAutoBanLimit <= 0) then Exit; + + Inc(C^.Crimes); + + if (NetAutoBanWarn) then + MH_SEND_Chat('You have been warned by the server: ' + Reason, NET_CHAT_SYSTEM, C^.ID); + + if (C^.Crimes >= NetAutoBanLimit) then + begin + s := '#' + IntToStr(C^.ID); // can't be arsed + g_Net_BanHost(C^.Peer^.address.host, NetAutoBanPerm); + enet_peer_disconnect(C^.Peer, NET_DISC_BAN); + g_Console_Add(Format(_lc[I_PLAYER_BAN], [s])); + MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s); + g_Net_Slist_ServerPlayerLeaves(); + end; end; procedure g_Net_DumpStart(); begin if NetMode = NET_SERVER then - NetDumpFile := createDiskFile(NETDUMP_FILENAME + '_server') + NetDumpFile := e_CreateResource(LogDirs, NETDUMP_FILENAME + '_server') else - NetDumpFile := createDiskFile(NETDUMP_FILENAME + '_client'); + NetDumpFile := e_CreateResource(LogDirs, NETDUMP_FILENAME + '_client'); end; procedure g_Net_DumpSendBuffer(); @@ -2208,7 +2351,10 @@ var begin Result := False; - if NetPortForwarded = NetPort then + if NetHost = nil then + exit; + + if NetPortForwarded = NetHost.address.port then begin Result := True; exit; @@ -2234,7 +2380,7 @@ begin exit; end; - StrPort := IntToStr(NetPort); + StrPort := IntToStr(NetHost.address.port); I := UPNP_AddPortMapping( Urls.controlURL, Addr(data.first.servicetype[1]), PChar(StrPort), PChar(StrPort), Addr(LanAddr[0]), PChar('D2DF'), @@ -2243,7 +2389,7 @@ begin if I <> 0 then begin - conwritefln('forwarding port %d failed: error %d', [NetPort, I]); + conwritefln('forwarding port %d failed: error %d', [NetHost.address.port, I]); FreeUPNPDevList(DevList); FreeUPNPUrls(@Urls); exit; @@ -2260,20 +2406,20 @@ begin if I <> 0 then begin - conwritefln('forwarding port %d failed: error %d', [NetPort + 1, I]); + conwritefln('forwarding port %d failed: error %d', [NET_PING_PORT, I]); NetPongForwarded := False; end else begin - conwritefln('forwarded port %d successfully', [NetPort + 1]); + conwritefln('forwarded port %d successfully', [NET_PING_PORT]); NetPongForwarded := True; end; end; - conwritefln('forwarded port %d successfully', [NetPort]); + conwritefln('forwarded port %d successfully', [NetHost.address.port]); NetIGDControl := AnsiString(Urls.controlURL); NetIGDService := data.first.servicetype; - NetPortForwarded := NetPort; + NetPortForwarded := NetHost.address.port; FreeUPNPDevList(DevList); FreeUPNPUrls(@Urls); @@ -2305,12 +2451,12 @@ begin if NetPongForwarded then begin NetPongForwarded := False; - StrPort := IntToStr(NetPortForwarded + 1); + StrPort := IntToStr(NET_PING_PORT); I := UPNP_DeletePortMapping( PChar(NetIGDControl), Addr(NetIGDService[1]), PChar(StrPort), PChar('UDP'), nil ); - conwritefln(' port %d: %d', [NetPortForwarded + 1, I]); + conwritefln(' port %d: %d', [NET_PING_PORT, I]); end; NetPortForwarded := 0; @@ -2320,9 +2466,110 @@ begin end; {$ENDIF} +procedure NetServerCVars(P: SSArray); +var + cmd, s: string; + a, b: Integer; +begin + cmd := LowerCase(P[0]); + case cmd of + 'sv_name': + begin + if (Length(P) > 1) and (Length(P[1]) > 0) then + begin + NetServerName := P[1]; + if Length(NetServerName) > 64 then + SetLength(NetServerName, 64); + g_Net_Slist_ServerRenamed(); + end; + g_Console_Add(cmd + ' "' + NetServerName + '"'); + end; + 'sv_passwd': + begin + if (Length(P) > 1) and (Length(P[1]) > 0) then + begin + NetPassword := P[1]; + if Length(NetPassword) > 24 then + SetLength(NetPassword, 24); + g_Net_Slist_ServerRenamed(); + end; + g_Console_Add(cmd + ' "' + AnsiLowerCase(NetPassword) + '"'); + end; + 'sv_maxplrs': + begin + if (Length(P) > 1) then + begin + NetMaxClients := nclamp(StrToIntDef(P[1], NetMaxClients), 1, NET_MAXCLIENTS); + if g_Game_IsServer and g_Game_IsNet then + begin + b := 0; + for a := 0 to High(NetClients) do + begin + if NetClients[a].Used then + begin + Inc(b); + if b > NetMaxClients then + begin + s := g_Player_Get(NetClients[a].Player).Name; + enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL); + g_Console_Add(Format(_lc[I_PLAYER_KICK], [s])); + MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s); + end; + end; + end; + g_Net_Slist_ServerRenamed(); + end; + end; + g_Console_Add(cmd + ' ' + IntToStr(NetMaxClients)); + end; + 'sv_public': + begin + if (Length(P) > 1) then + begin + NetUseMaster := StrToIntDef(P[1], Byte(NetUseMaster)) <> 0; + if NetUseMaster then g_Net_Slist_Public() else g_Net_Slist_Private(); + end; + g_Console_Add(cmd + ' ' + IntToStr(Byte(NetUseMaster))); + end; + 'sv_port': + begin + if (Length(P) > 1) then + begin + if not g_Game_IsNet then + NetPort := nclamp(StrToIntDef(P[1], NetPort), 0, $FFFF) + else + g_Console_Add(_lc[I_MSG_NOT_NETGAME]); + end; + g_Console_Add(cmd + ' ' + IntToStr(Ord(NetUseMaster))); + end; + end; +end; initialization conRegVar('cl_downloadtimeout', @g_Net_DownloadTimeout, 0.0, 1000000.0, '', 'timeout in seconds, 0 to disable it'); + conRegVar('cl_predictself', @NetPredictSelf, '', 'predict local player'); + conRegVar('cl_forceplayerupdate', @NetForcePlayerUpdate, '', 'update net players on NET_MSG_PLRPOS'); + 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'); + conRegVar('sv_rcon_password', @NetRCONPassword, '', 'remote console password'); + conRegVar('sv_update_interval', @NetUpdateRate, '', 'unreliable update interval'); + conRegVar('sv_reliable_interval', @NetRelupdRate, '', 'reliable update interval'); + conRegVar('sv_master_interval', @NetMasterRate, '', 'master server update interval'); + + conRegVar('sv_autoban_threshold', @NetAutoBanLimit, '', 'max crimes before autoban (0 = no autoban)'); + conRegVar('sv_autoban_permanent', @NetAutoBanPerm, '', 'whether autobans are permanent'); + conRegVar('sv_autoban_warn', @NetAutoBanWarn, '', 'send warnings to the client when he triggers penalties'); + + conRegVar('sv_auth_timeout', @NetAuthTimeout, '', 'number of frames in which connecting clients must complete auth (0 = unlimited)'); + conRegVar('sv_packet_timeout', @NetPacketTimeout, '', 'number of frames the client must idle to be kicked (0 = unlimited)'); + + conRegVar('net_master_list', @NetMasterList, '', 'list of master servers'); + SetLength(NetClients, 0); g_Net_DownloadTimeout := 60; NetIn.Alloc(NET_BUFSIZE);