diff --git a/Northstar.Custom/mod.json b/Northstar.Custom/mod.json index 4fa3ca5c7..cf531fc8e 100644 --- a/Northstar.Custom/mod.json +++ b/Northstar.Custom/mod.json @@ -443,6 +443,16 @@ { "Path": "sh_northstar_http_requests.gnut", "RunOn": "CLIENT || SERVER || UI" + }, + { + "Path": "sh_northstar_matchmaker.gnut", + "RunOn": "CLIENT || SERVER", + "ClientCallback": { + "Before": "Sh_Northstar_MatchMaker_Init" + }, + "ServerCallback": { + "Before": "Sh_Northstar_MatchMaker_Init" + } } ], diff --git a/Northstar.Custom/mod/scripts/vscripts/sh_northstar_matchmaker.gnut b/Northstar.Custom/mod/scripts/vscripts/sh_northstar_matchmaker.gnut new file mode 100644 index 000000000..bd42146db --- /dev/null +++ b/Northstar.Custom/mod/scripts/vscripts/sh_northstar_matchmaker.gnut @@ -0,0 +1,26 @@ +global function Sh_Northstar_MatchMaker_Init + +#if CLIENT +global function ServerCallback_ClientBackToLobby +#endif + +void function Sh_Northstar_MatchMaker_Init() +{ + AddCallback_OnRegisteringCustomNetworkVars( RegisterNorthstarMatchMakerNetworkFunctions ) +} + +void function RegisterNorthstarMatchMakerNetworkFunctions() +{ + Remote_RegisterFunction( "ServerCallback_ClientBackToLobby" ) +} + +#if CLIENT +void function ServerCallback_ClientBackToLobby() +{ + entity player = GetLocalClientPlayer() + if ( IsValid( player ) ) + { + player.ClientCommand( "ns_start_reauth_and_leave_to_lobby" ) + } +} +#endif \ No newline at end of file diff --git a/Northstar.CustomServers/mod.json b/Northstar.CustomServers/mod.json index 874c4abe1..8b7e21dc9 100644 --- a/Northstar.CustomServers/mod.json +++ b/Northstar.CustomServers/mod.json @@ -53,6 +53,10 @@ { "Name": "ns_allow_kill_commands", "DefaultValue": "0" + }, + { + "Name": "ns_send_clients_back_to_lobby_after_match", + "DefaultValue": "0" } ], "Scripts": [ diff --git a/Northstar.CustomServers/mod/cfg/autoexec_ns_server.cfg b/Northstar.CustomServers/mod/cfg/autoexec_ns_server.cfg index db735be9c..eb8ac290a 100644 --- a/Northstar.CustomServers/mod/cfg/autoexec_ns_server.cfg +++ b/Northstar.CustomServers/mod/cfg/autoexec_ns_server.cfg @@ -13,6 +13,7 @@ everything_unlocked 1 // 全解锁 // gameserver settings ns_should_return_to_lobby 1 // 游戏结束后是否返回到大厅 +ns_send_clients_back_to_lobby_after_match 0 // 游戏结束后是否将非主机玩家送回本地大厅 net_chan_limit_mode 2 // 踢出客户端netchan处理延迟过高的玩家 net_chan_limit_msec_per_sec 100 // 客户端netchan处理延迟阈值 diff --git a/Northstar.CustomServers/mod/scripts/vscripts/mp/_changemap.nut b/Northstar.CustomServers/mod/scripts/vscripts/mp/_changemap.nut index 16a3ce922..9d663404c 100644 --- a/Northstar.CustomServers/mod/scripts/vscripts/mp/_changemap.nut +++ b/Northstar.CustomServers/mod/scripts/vscripts/mp/_changemap.nut @@ -12,6 +12,30 @@ void function CodeCallback_MatchIsOver() PopulatePostgameData() #endif + // nscn specific + float serverMapChangeDelay = 0.0 // default is no delay + + if ( ShouldSendClientsBackToLobby() ) + { + foreach ( entity player in GetPlayerArray() ) + { + if ( !NSIsPlayerLocalPlayer( player ) ) + Remote_CallFunction_NonReplay( player, "ServerCallback_ClientBackToLobby" ) + } + + serverMapChangeDelay = 5.0 // add 500ms grace period for clients to disconnect + } + + thread ChangeServerMapAfterDelay( serverMapChangeDelay ) + // +} + + +void function ChangeServerMapAfterDelay( float delay = 0.0 ) +{ + if ( delay > 0 ) + wait delay + if ( ShouldReturnToLobby() ) { SetCurrentPlaylist( "private_match" ) // needed for private lobby to load diff --git a/Northstar.CustomServers/mod/scripts/vscripts/sh_northstar_utils.gnut b/Northstar.CustomServers/mod/scripts/vscripts/sh_northstar_utils.gnut index b26e48ca0..72a8e57df 100644 --- a/Northstar.CustomServers/mod/scripts/vscripts/sh_northstar_utils.gnut +++ b/Northstar.CustomServers/mod/scripts/vscripts/sh_northstar_utils.gnut @@ -10,4 +10,11 @@ bool function IsNorthstarServer() bool function ShouldReturnToLobby() { return GetConVarBool( "ns_should_return_to_lobby" ) +} + +// whether the game should send other clients back to lobby on GameRules_EndMatch() +// requires loading "sh_northstar_matchmaker.gnut" +bool function ShouldSendClientsBackToLobby() +{ + return GetConVarBool( "ns_send_clients_back_to_lobby_after_match" ) } \ No newline at end of file