Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pg9182 committed Sep 14, 2023
1 parent a27368d commit 8a26221
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
8 changes: 6 additions & 2 deletions NorthstarDLL/masterserver/masterserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,11 @@ void MasterServerManager::ProcessConnectionlessPacketSigreq1(std::string data)
if (obj.HasMember("username") && obj["username"].IsString())
username = obj["username"].GetString();


std::string reject;
if (!g_pBanSystem->IsUIDAllowed(uid))
if (g_pServerPresence->IsDraining())
reject = "Server is shutting down.";
else if (!g_pBanSystem->IsUIDAllowed(uid))
reject = "Banned from this server.";

std::string pdata;
Expand Down Expand Up @@ -1356,7 +1359,7 @@ void MasterServerPresenceReporter::InternalUpdateServer(const ServerPresence* pS
fmt::format(
"{}/server/"
"update_values?id={}&port={}&authPort=udp&name={}&description={}&map={}&playlist={}&playerCount={}&"
"maxPlayers={}&password={}",
"maxPlayers={}&isDraining={}&password={}",
hostname.c_str(),
serverId.c_str(),
threadedPresence.m_iPort,
Expand All @@ -1366,6 +1369,7 @@ void MasterServerPresenceReporter::InternalUpdateServer(const ServerPresence* pS
playlistEscaped,
threadedPresence.m_iPlayerCount,
threadedPresence.m_iMaxPlayers,
threadedPresence.m_bIsDraining,
passwordEscaped)
.c_str());

Expand Down
4 changes: 3 additions & 1 deletion NorthstarDLL/server/auth/serverauthentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ bool,, (R2::CBaseClient* self, char* pName, void* pNetChannel, char bFakePlayer,

if (!bFakePlayer)
{
if (!g_pServerAuthentication->VerifyPlayerName(pNextPlayerToken, pName, pVerifiedName))
if (g_pServerPresence->IsDraining())
pAuthenticationFailure = "Server is shutting down.";
else if (!g_pServerAuthentication->VerifyPlayerName(pNextPlayerToken, pName, pVerifiedName))
pAuthenticationFailure = "Invalid Name.";
else if (!g_pBanSystem->IsUIDAllowed(iNextPlayerUid))
pAuthenticationFailure = "Banned From server.";
Expand Down
20 changes: 20 additions & 0 deletions NorthstarDLL/server/serverpresence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,28 @@ void ServerPresenceManager::SetPlayerCount(const int iPlayerCount)
m_ServerPresence.m_iPlayerCount = iPlayerCount;
}

void ServerPresenceManager::SetIsDraining(bool bIsDraining)
{
m_ServerPresence.m_bIsDraining = bIsDraining;
}

bool ServerPresenceManager::IsDraining() const
{
// TODO: is there a better place for this?
return m_ServerPresence.m_bIsDraining;
}

ON_DLL_LOAD_RELIESON("engine.dll", ServerPresence, ConVar, (CModule module))
{
g_pServerPresence->CreateConVars();
Cvar_hostname = module.Offset(0x1315BAE8).Deref().RCast<ConVar*>();
}

ADD_SQFUNC("void", NSDrainServer, "bool drain, int timeout", "", ScriptContext::SERVER) {
bool drain = g_pSquirrel<ScriptContext::SERVER>->getbool(sqvm, 1);
int timeout = g_pSquirrel<ScriptContext::SERVER>->getinteger(sqvm, 2);
g_pServerPresence->SetIsDraining(drain);
// TODO: notify the connected clients when this is set?
// TODO: auto exit after a timeout or match end or player count reaches zero (use the quit command for a graceful exit)
return SQRESULT_NULL;
}
8 changes: 8 additions & 0 deletions NorthstarDLL/server/serverpresence.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ struct ServerPresence
int m_iPlayerCount;
int m_iMaxPlayers;

bool m_bIsDraining;

ServerPresence()
{
memset(this, 0, sizeof(this));
Expand All @@ -39,6 +41,8 @@ struct ServerPresence

m_iPlayerCount = obj->m_iPlayerCount;
m_iMaxPlayers = obj->m_iMaxPlayers;

m_bIsDraining = obj->m_bIsDraining;
}
};

Expand Down Expand Up @@ -72,6 +76,7 @@ class ServerPresenceManager
ConVar* Cvar_ns_report_sp_server_to_masterserver;

public:

void AddPresenceReporter(ServerPresenceReporter* reporter);

void CreateConVars();
Expand All @@ -89,6 +94,9 @@ class ServerPresenceManager
void SetMap(const char* pMapName, bool isInitialising = false);
void SetPlaylist(const char* pPlaylistName);
void SetPlayerCount(const int iPlayerCount);

void SetIsDraining(bool bIsDraining);
bool IsDraining() const;
};

extern ServerPresenceManager* g_pServerPresence;

0 comments on commit 8a26221

Please sign in to comment.