Added more Server Host Utils.

This commit is contained in:
IcePixelx 2021-07-31 16:51:06 +02:00
parent ea2e07a0f1
commit 8004ee4db3
5 changed files with 36 additions and 11 deletions

View File

@ -331,3 +331,15 @@ enum ClientFrameStage_t
FRAME_NET_FULL_FRAME_UPDATE_ON_REMOVE
};
enum HostStates_t
{
HS_NEW_GAME = 0x0,
HS_LOAD_GAME = 0x1,
HS_CHANGE_LEVEL_SP = 0x2,
HS_CHANGE_LEVEL_MP = 0x3,
HS_RUN = 0x4,
HS_GAME_SHUTDOWN = 0x5,
HS_SHUTDOWN = 0x6,
HS_RESTART = 0x7,
};

View File

@ -236,7 +236,7 @@ class CHostState
{
public:
__int32 m_iCurrentState; //0x0000
__int32 n_iNextState; //0x0004
__int32 m_iNextState; //0x0004
Vector3 m_vecLocation; //0x0008
QAngle m_angLocation; //0x0014
char m_levelName[64]; //0x0020

View File

@ -267,7 +267,6 @@ public:
}
void RefreshServerList();
void UpdateMyServerInfo();
void SendHostingPostRequest();
const nlohmann::json SendGetServerByTokenRequest(const std::string &token, const std::string &password);
void CompMenu();

View File

@ -177,6 +177,9 @@
<ClCompile Include="src\opcptc.cpp">
<Filter>r5-sdk\src</Filter>
</ClCompile>
<ClCompile Include="..\external\imgui\src\imgui_stdlib.cpp">
<Filter>shared\libraries\imgui</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\external\imgui\include\imgui_impl_win32.h">
@ -539,6 +542,9 @@
<ClInclude Include="include\input.h">
<Filter>core\include</Filter>
</ClInclude>
<ClInclude Include="include\imgui_stdlib.h">
<Filter>shared\libraries\imgui\include</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="r5dev.def">

View File

@ -353,11 +353,6 @@ CCompanion::CCompanion()
HostingServerRequestThread.detach();
}
void CCompanion::UpdateMyServerInfo()
{
MyServer.map = GameGlobals::HostState->m_levelName;
}
void CCompanion::UpdateHostingStatus()
{
if (!GameGlobals::HostState || !GameGlobals::Cvar) // Is HostState and Cvar valid?
@ -378,7 +373,6 @@ void CCompanion::UpdateHostingStatus()
if (!BroadCastServer) // Do we wanna broadcast server to the browser?
break;
UpdateMyServerInfo();
SendHostingPostRequest();
break;
}
@ -429,7 +423,7 @@ void CCompanion::SendHostingPostRequest()
// send a post request to "/servers/add" with a json body
nlohmann::json body = nlohmann::json::object();
body["name"] = MyServer.name;
body["map"] = MyServer.map;
body["map"] = std::string(GameGlobals::HostState->m_levelName);
static ConVar* hostport = GameGlobals::Cvar->FindVar("hostport"); // static since it won't move memory locations.
body["port"] = hostport->m_pzsCurrentValue; //body["port"] = MyServer.port;
body["password"] = MyServer.password;
@ -771,6 +765,12 @@ void CCompanion::HostServerSection()
}
}
if (ImGui::Button("Force Start##ServerHost_ForceStart", ImVec2(ImGui::GetWindowSize().x, 32)))
{
strncpy_s(GameGlobals::HostState->m_levelName, MyServer.map.c_str(), 64); // Copy new map into hoststate levelname. 64 is size of m_levelname.
GameGlobals::HostState->m_iNextState = HostStates_t::HS_NEW_GAME; // Force CHostState::FrameUpdate to start a server.
}
ImGui::TextColored(ImVec4(1.00f, 0.00f, 0.00f, 1.00f), ServerNameErr.c_str());
ImGui::TextColored(HostRequestMessageColor, HostRequestMessage.c_str());
if (!HostToken.empty())
@ -778,16 +778,24 @@ void CCompanion::HostServerSection()
ImGui::InputText("##ServerHost_HostToken", &HostToken, ImGuiInputTextFlags_ReadOnly);
}
if (StartAsDedi)
if (GameGlobals::HostState->m_bActiveGame)
{
if (ImGui::Button("Reload Scripts##ServerHost_ReloadServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
{
ProcessCommand("reparse_weapons");
ProcessCommand("reload");
}
if (ImGui::Button("Stop The Server##ServerHost_StopServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
{
ProcessCommand("disconnect");
ProcessCommand("LeaveMatch"); // Use script callback instead.
GameGlobals::HostState->m_iNextState = HostStates_t::HS_GAME_SHUTDOWN; // Force CHostState::FrameUpdate to shutdown the server for dedicated.
}
if (ImGui::Button("Change Level##ServerHost_ChangeLevel", ImVec2(ImGui::GetWindowSize().x, 32)))
{
strncpy_s(GameGlobals::HostState->m_levelName, MyServer.map.c_str(), 64); // Copy new map into hoststate levelname. 64 is size of m_levelname.
GameGlobals::HostState->m_iNextState = HostStates_t::HS_CHANGE_LEVEL_MP; // Force CHostState::FrameUpdate to change the level.
}
}
}