Skip to content

Commit

Permalink
add ns_send_clients_back_to_lobby_after_match
Browse files Browse the repository at this point in the history
  • Loading branch information
DBmaoha committed Aug 20, 2023
1 parent 9819a90 commit b6a9a4e
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Northstar.Custom/mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
],

Expand Down
26 changes: 26 additions & 0 deletions Northstar.Custom/mod/scripts/vscripts/sh_northstar_matchmaker.gnut
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions Northstar.CustomServers/mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
{
"Name": "ns_allow_kill_commands",
"DefaultValue": "0"
},
{
"Name": "ns_send_clients_back_to_lobby_after_match",
"DefaultValue": "0"
}
],
"Scripts": [
Expand Down
1 change: 1 addition & 0 deletions Northstar.CustomServers/mod/cfg/autoexec_ns_server.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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处理延迟阈值
Expand Down
24 changes: 24 additions & 0 deletions Northstar.CustomServers/mod/scripts/vscripts/mp/_changemap.nut
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
}

0 comments on commit b6a9a4e

Please sign in to comment.