mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Fix Pylon backend not working on dedicated server
Also fix dual thread for backend, and main thread pausing when request is slow
This commit is contained in:
parent
4e9ae9c350
commit
4cbb4746bd
@ -94,7 +94,6 @@ FORCEINLINE void CHostState::FrameUpdate(void* rcx, void* rdx, float time)
|
||||
}
|
||||
case HostStates_t::HS_RUN:
|
||||
{
|
||||
g_pHostState->Think();
|
||||
State_RunFn(&g_pHostState->m_iCurrentState, nullptr, time);
|
||||
break;
|
||||
}
|
||||
@ -153,6 +152,9 @@ FORCEINLINE void CHostState::Setup(void) const
|
||||
g_pRConClient->Init();
|
||||
#endif // DEDICATED
|
||||
|
||||
std::thread t1(&CHostState::Think, this);
|
||||
t1.detach();
|
||||
|
||||
*reinterpret_cast<bool*>(m_bRestrictServerCommands) = true; // Restrict commands.
|
||||
ConCommandBase* disconnect = g_pCVar->FindCommandBase("disconnect");
|
||||
disconnect->AddFlags(FCVAR_SERVER_CAN_EXECUTE); // Make sure server is not restricted to this.
|
||||
@ -182,12 +184,15 @@ FORCEINLINE void CHostState::Think(void) const
|
||||
static CFastTimer statsTimer;
|
||||
static ConVar* hostname = g_pCVar->FindVar("hostname");
|
||||
|
||||
for (;;) // Loop running at 20-tps.
|
||||
{
|
||||
if (!bInitialized) // Initialize clocks.
|
||||
{
|
||||
banListTimer.Start();
|
||||
#ifdef DEDICATED
|
||||
pylonTimer.Start();
|
||||
#endif // DEDICATED
|
||||
statsTimer.Start();
|
||||
|
||||
bInitialized = true;
|
||||
}
|
||||
|
||||
@ -196,11 +201,13 @@ FORCEINLINE void CHostState::Think(void) const
|
||||
g_pBanSystem->BanListCheck();
|
||||
banListTimer.Start();
|
||||
}
|
||||
#ifdef DEDICATED
|
||||
if (pylonTimer.GetDurationInProgress().GetSeconds() > 5.0)
|
||||
{
|
||||
KeepAliveToPylon();
|
||||
pylonTimer.Start();
|
||||
}
|
||||
#endif // DEDICATED
|
||||
if (statsTimer.GetDurationInProgress().GetSeconds() > 1.0)
|
||||
{
|
||||
std::string svCurrentPlaylist = KeyValues_GetCurrentPlaylist();
|
||||
@ -210,6 +217,8 @@ FORCEINLINE void CHostState::Think(void) const
|
||||
hostname->GetString(), nPlayerCount, g_ServerGlobalVariables->m_nMaxClients, svCurrentPlaylist.c_str(), m_levelName).c_str());
|
||||
statsTimer.Start();
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -640,16 +640,18 @@ void IBrowser::UpdateHostingStatus(void)
|
||||
void IBrowser::SendHostingPostRequest(void)
|
||||
{
|
||||
#ifndef GAMECLIENTONLY
|
||||
static ConVar* hostport = g_pCVar->FindVar("hostport");
|
||||
static ConVar* mp_gamemode = g_pCVar->FindVar("mp_gamemode");
|
||||
|
||||
m_szHostToken = std::string();
|
||||
DevMsg(eDLL_T::CLIENT, "Sending PostServerHost request\n");
|
||||
bool result = g_pR5net->PostServerHost(m_szHostRequestMessage, m_szHostToken,
|
||||
ServerListing
|
||||
{
|
||||
m_Server.svServerName,
|
||||
m_Server.svServerName.c_str(),
|
||||
std::string(g_pHostState->m_levelName),
|
||||
"",
|
||||
g_pCVar->FindVar("hostport")->GetString(),
|
||||
g_pCVar->FindVar("mp_gamemode")->GetString(),
|
||||
hostport->GetString(),
|
||||
mp_gamemode->GetString(),
|
||||
m_Server.bHidden,
|
||||
std::to_string(*g_nClientRemoteChecksum),
|
||||
|
||||
|
@ -29,7 +29,6 @@ void KeepAliveToPylon()
|
||||
std::string m_szHostToken = std::string();
|
||||
std::string m_szHostRequestMessage = std::string();
|
||||
|
||||
DevMsg(eDLL_T::SERVER, "Sending PostServerHost request\n");
|
||||
bool result = g_pR5net->PostServerHost(m_szHostRequestMessage, m_szHostToken,
|
||||
ServerListing{
|
||||
hostname->GetString(),
|
||||
|
@ -21,17 +21,18 @@ std::vector<ServerListing> R5Net::Client::GetServersList(std::string& svOutMessa
|
||||
{
|
||||
std::vector<ServerListing> vslList{};
|
||||
|
||||
nlohmann::json jsReqBody = nlohmann::json::object();
|
||||
jsReqBody["version"] = GetSDKVersion();
|
||||
nlohmann::json jsRequestBody = nlohmann::json::object();
|
||||
jsRequestBody["version"] = GetSDKVersion();
|
||||
|
||||
std::string reqBodyStr = jsReqBody.dump();
|
||||
std::string svRequestBody = jsRequestBody.dump(4);
|
||||
|
||||
if (r5net_show_debug->GetBool())
|
||||
{
|
||||
DevMsg(eDLL_T::ENGINE, "Sending GetServerList post.\n");
|
||||
DevMsg(eDLL_T::ENGINE, "%s - Sending server list request to comp-server:\n%s\n", __FUNCTION__, svRequestBody.c_str());
|
||||
}
|
||||
|
||||
httplib::Result htResults = m_HttpClient.Post("/servers", jsReqBody.dump().c_str(), jsReqBody.dump().length(), "application/json");
|
||||
httplib::Result htResults = m_HttpClient.Post("/servers", jsRequestBody.dump().c_str(), jsRequestBody.dump().length(), "application/json");
|
||||
|
||||
if (htResults && r5net_show_debug->GetBool())
|
||||
{
|
||||
@ -122,18 +123,18 @@ bool R5Net::Client::PostServerHost(std::string& svOutMessage, std::string& svOut
|
||||
jsRequestBody["encKey"] = slServerListing.svEncryptionKey;
|
||||
jsRequestBody["hidden"] = slServerListing.bHidden;
|
||||
|
||||
std::string svRequestBody = jsRequestBody.dump();
|
||||
std::string svRequestBody = jsRequestBody.dump(4);
|
||||
|
||||
if (r5net_show_debug->GetBool())
|
||||
{
|
||||
DevMsg(eDLL_T::ENGINE, "Sending PostServerHost post '%s'.\n", svRequestBody.c_str());
|
||||
DevMsg(eDLL_T::ENGINE, "%s - Sending post host request to comp-server:\n%s\n", __FUNCTION__, svRequestBody.c_str());
|
||||
}
|
||||
|
||||
httplib::Result htResults = m_HttpClient.Post("/servers/add", svRequestBody.c_str(), svRequestBody.length(), "application/json");
|
||||
|
||||
if (htResults && r5net_show_debug->GetBool())
|
||||
{
|
||||
DevMsg(eDLL_T::ENGINE, "PostServerHost replied with '%d'.\n", htResults->status);
|
||||
DevMsg(eDLL_T::ENGINE, "%s - Comp-server replied with '%d'\n", __FUNCTION__, htResults->status);
|
||||
}
|
||||
|
||||
if (htResults && htResults->status == 200) // STATUS_OK
|
||||
@ -209,19 +210,20 @@ bool R5Net::Client::PostServerHost(std::string& svOutMessage, std::string& svOut
|
||||
bool R5Net::Client::GetServerByToken(ServerListing& slOutServer, std::string& svOutMessage, const std::string svToken)
|
||||
{
|
||||
nlohmann::json jsRequestBody = nlohmann::json::object();
|
||||
|
||||
jsRequestBody["token"] = svToken;
|
||||
|
||||
std::string svRequestBody = jsRequestBody.dump(4);
|
||||
|
||||
if (r5net_show_debug->GetBool())
|
||||
{
|
||||
DevMsg(eDLL_T::ENGINE, "Sending GetServerByToken post.\n");
|
||||
DevMsg(eDLL_T::ENGINE, "%s - Sending token connect request to comp-server:\n%s\n", __FUNCTION__, svRequestBody.c_str());
|
||||
}
|
||||
|
||||
httplib::Result htResults = m_HttpClient.Post("/server/byToken", jsRequestBody.dump().c_str(), jsRequestBody.dump().length(), "application/json");
|
||||
|
||||
if (r5net_show_debug->GetBool())
|
||||
{
|
||||
DevMsg(eDLL_T::ENGINE, "GetServerByToken replied with '%d'\n", htResults->status);
|
||||
DevMsg(eDLL_T::ENGINE, "%s - Comp-server replied with '%d'\n", __FUNCTION__, htResults->status);
|
||||
}
|
||||
|
||||
if (htResults && htResults->status == 200) // STATUS_OK
|
||||
|
@ -140,7 +140,7 @@ void ConVar::Init(void) const
|
||||
r5net_show_debug = new ConVar("r5net_show_debug" , "1" , FCVAR_DEVELOPMENTONLY, "Shows debug output for R5Net.", false, 0.f, false, 0.f, nullptr, nullptr);
|
||||
//-------------------------------------------------------------------------
|
||||
// RTECH API |
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// RUI |
|
||||
#ifndef DEDICATED
|
||||
rui_drawEnable = new ConVar("rui_drawEnable", "1", FCVAR_RELEASE, "Draws the RUI, 1 = Draw, 0 = No Draw.", false, 0.f, false, 0.f, nullptr, nullptr);
|
||||
@ -505,7 +505,7 @@ void ConVar::ChangeStringValue(const char* pszTempVal, float flOldValue)
|
||||
m_Value.m_pszString = NULL;
|
||||
}
|
||||
|
||||
pszOldValue = 0;
|
||||
pszOldValue = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -97,7 +97,7 @@ ConVar* r5net_matchmaking_hostname = nullptr;
|
||||
ConVar* r5net_show_debug = nullptr;
|
||||
//-----------------------------------------------------------------------------
|
||||
// RTECH API |
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RUI |
|
||||
#ifndef DEDICATED
|
||||
ConVar* rui_drawEnable = nullptr;
|
||||
|
@ -107,7 +107,7 @@ extern ConVar* r5net_matchmaking_hostname;
|
||||
extern ConVar* r5net_show_debug;
|
||||
//-----------------------------------------------------------------------------
|
||||
// RTECH API |
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RUI |
|
||||
#ifndef DEDICATED
|
||||
extern ConVar* rui_drawEnable;
|
||||
|
Loading…
x
Reference in New Issue
Block a user