Squashed commit of the following:

commit 4b6351200b9f7e7bb75b780c46042afbed3359f3
Merge: a3946bb 47dc117
Author: Alex <18037145+salcodes1@users.noreply.github.com>
Date:   Tue Dec 28 22:09:36 2021 +0200

    Merge branch 'Mauler125:pylon' into pylon

commit a3946bb5ce4655665a763aeb3c2b016215bfa805
Author: Alex <18037145+salcodes1@users.noreply.github.com>
Date:   Tue Dec 28 22:07:02 2021 +0200

    Pylon C++ implementation actually working now

commit 00cd76f7b21476e054d3ead4a4c8d507f391c963
Author: Alex <18037145+salcodes1@users.noreply.github.com>
Date:   Tue Dec 28 03:45:41 2021 +0200

    Fixed post requests not using provided route

commit 2f2d01713fd38861f0e674641bf14b6afd25ecc6
Author: Alex <18037145+salcodes1@users.noreply.github.com>
Date:   Tue Dec 28 03:44:20 2021 +0200

    added get private game server info route

commit b53b89d31a7201ac594abf16dd7c00134bb5a132
Merge: 433f14c c8ec95b
Author: Alex <18037145+salcodes1@users.noreply.github.com>
Date:   Tue Dec 28 03:32:14 2021 +0200

    Merge branch 'pylon' into indev

commit 433f14c352a0ae366cff2cbe03753b2198a77848
Author: Alex <18037145+salcodes1@users.noreply.github.com>
Date:   Tue Dec 28 03:31:33 2021 +0200

    partial commit

commit c8ec95bd37ed0c3e16090ed0a15808bda6a2ee99
Author: Alex <18037145+salcodes1@users.noreply.github.com>
Date:   Tue Dec 28 03:26:44 2021 +0200

    Added backbone and some of the routes for r5net-ms (now Pylon) interactions
This commit is contained in:
IcePixelx 2022-01-03 15:03:20 +01:00
parent 212eeb87af
commit fb325db19f
16 changed files with 374 additions and 1258 deletions

73
r5dev/IDevPalette.h Normal file
View File

@ -0,0 +1,73 @@
#pragma once
#include "core/stdafx.h"
#include <windows/id3dx.h>
#include <networksystem/r5net.h>
#include <gameui/IConsole.h>
#ifndef DEDICATED
class CDevPalette
{
public:
void Draw(bool* bDraw)
{
ImGui::SetNextWindowSize(ImVec2(1000, 600), ImGuiCond_FirstUseEver);
ImGui::SetWindowPos(ImVec2(-1000, 50), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("Dev Palette", bDraw))
{
ImGui::End();
return;
}
if (ImGui::Button("Get Stats"))
{
auto response = g_pR5net->GetGlobalStats();
switch (response.status)
{
case R5Net::EResponseStatus::SUCCESS:
{
g_GameConsole->AddLog("SUCCESS: %d players, %d servers", response.noPlayers, response.noServers);
break;
}
default:
{
g_GameConsole->AddLog("ERROR: %s", response.error.c_str());
}
}
}
if (ImGui::Button("Send Fake Server Request"))
{
R5Net::UpdateGameServerMSRequest request{};
request.gameServer.name = "TestNameServer";
request.gameServer.playlist = "yoopp";
request.gameServer.gamePort = 8089;
auto response = g_pR5net->UpdateMyGameServer(request);
switch (response.status)
{
case R5Net::EResponseStatus::SUCCESS:
{
g_GameConsole->AddLog("SUCCESS: %s", response.gameServer.name.c_str());
break;
}
default:
{
g_GameConsole->AddLog("ERROR: %s", response.error.c_str());
}
}
}
if (*bDraw == NULL)
{
g_bShowBrowser = false;
}
ImGui::End();
}
};
void DrawDevPalette(bool* bDraw);
extern CDevPalette* g_DevPalette;
#endif

26
r5dev/IDevPallete.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "core/stdafx.h"
#ifndef DEDICATED
#include "IDevPalette.h"
//#############################################################################
// ENTRYPOINT
//#############################################################################
CDevPalette* g_DevPalette = nullptr;
void DrawDevPalette(bool* bDraw)
{
static CDevPalette devPalette;
static bool AssignPtr = []()
{
g_DevPalette = &devPalette;
return true;
} ();
if (*bDraw) devPalette.Draw(bDraw);
}
///////////////////////////////////////////////////////////////////////////
#endif

View File

@ -45,6 +45,8 @@
#include "public/include/httplib.h"
#include "public/include/json.hpp"
#include "networksystem/net_structs.h"
#ifndef SDKLAUNCHER
namespace
{

View File

@ -7,3 +7,4 @@
#define IM_FMTARGS(FMT) __attribute__((format(printf, FMT, FMT+1)))
#define IM_FMTARGS(FMT) __attribute__((format(gnu_printf, FMT, FMT+1)))
#define IM_FMTARGS(FMT)
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, __VA_ARGS__) friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }

View File

@ -1,715 +0,0 @@
#include "core/stdafx.h"
#include "core/init.h"
#include "core/resource.h"
#include "tier0/IConVar.h"
#include "tier0/cvar.h"
#include "tier0/completion.h"
#include "windows/id3dx.h"
#include "windows/console.h"
#include "engine/net_chan.h"
#include "engine/sys_utils.h"
#include "engine/host_state.h"
#include "server/server.h"
#include "client/IVEngineClient.h"
#include "networksystem/serverlisting.h"
#include "networksystem/r5net.h"
#include "vpc/keyvalues.h"
#include "squirrel/sqinit.h"
#include "gameui/IBrowser.h"
/******************************************************************************
-------------------------------------------------------------------------------
File : IBrowser.cpp
Date : 09:06:2021
Author : Sal
Purpose: Implements the in-game server browser frontend
-------------------------------------------------------------------------------
History:
- 09:06:2021 21:07 : Created by Sal
- 25:07:2021 14:26 : Implement private servers connect dialog and password field
******************************************************************************/
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
IBrowser::IBrowser()
{
memset(m_chServerConnStringBuffer, 0, sizeof(m_chServerConnStringBuffer));
std::string path = "stbsp";
for (const auto& entry : std::filesystem::directory_iterator(path))
{
std::string filename = entry.path().string();
int slashPos = filename.rfind("\\", std::string::npos);
filename = filename.substr(static_cast<std::basic_string<char, std::char_traits<char>, std::allocator<char>>::size_type>(slashPos) + 1, std::string::npos);
filename = filename.substr(0, filename.size() - 6);
auto it = mapArray.find(filename); // Find MapName in mapArray.
if (it != mapArray.end())
{
m_vszMapsList.push_back(it->second);
}
else
{
m_vszMapsList.push_back(filename);
}
}
m_szMatchmakingHostName = r5net_matchmaking_hostname->m_pzsCurrentValue;
static std::thread hostingServerRequestThread([this]()
{
while (true)
{
UpdateHostingStatus();
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
}
});
hostingServerRequestThread.detach();
/* Obtain handle to module */
static HGLOBAL rcData = NULL;
HMODULE handle;
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR)"unnamed", &handle);
HRSRC rc = FindResource(handle, MAKEINTRESOURCE(IDB_PNG1), MAKEINTRESOURCE(PNG));
/* Obtain assets from 'rsrc' */
if (rc != NULL)
{ rcData = LoadResource(handle, rc); }
else { assert(rc == NULL); }
if (rcData != NULL) { m_vucLockedIconBlob = (std::vector<unsigned char>*)LockResource(rcData); }
else { assert(rcData == NULL); }
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
IBrowser::~IBrowser()
{
//delete r5net;
}
//-----------------------------------------------------------------------------
// Purpose: updates the hoster's status
//-----------------------------------------------------------------------------
void IBrowser::UpdateHostingStatus()
{
if (!g_pHostState || !g_pCvar)
{
return;
}
eHostingStatus = g_pHostState->m_bActiveGame ? EHostStatus::HOSTING : EHostStatus::NOT_HOSTING; // Are we hosting a server?
switch (eHostingStatus)
{
case EHostStatus::NOT_HOSTING:
{
m_szHostRequestMessage.clear();
m_iv4HostRequestMessageColor = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
break;
}
case EHostStatus::HOSTING:
{
if (eServerVisibility == EServerVisibility::OFFLINE)
{
break;
}
if (*g_nRemoteFunctionCallsChecksum == NULL) // Check if script checksum is valid yet.
{
break;
}
switch (eServerVisibility)
{
case EServerVisibility::HIDDEN:
m_Server.bHidden = true;
break;
case EServerVisibility::PUBLIC:
m_Server.bHidden = false;
break;
default:
break;
}
SendHostingPostRequest();
break;
}
default:
break;
}
}
//-----------------------------------------------------------------------------
// Purpose: refreshes the server browser list with available servers
//-----------------------------------------------------------------------------
void IBrowser::RefreshServerList()
{
static bool bThreadLocked = false;
m_vServerList.clear();
m_szServerListMessage.clear();
if (!bThreadLocked)
{
std::thread t([this]()
{
DevMsg(eDLL_T::CLIENT, "Refreshing server list with string '%s'\n", r5net_matchmaking_hostname->m_pzsCurrentValue);
bThreadLocked = true;
m_vServerList = g_pR5net->GetServersList(m_szServerListMessage);
bThreadLocked = false;
});
t.detach();
}
}
//-----------------------------------------------------------------------------
// Purpose: sends the hosting POST request to the comp server
//-----------------------------------------------------------------------------
void IBrowser::SendHostingPostRequest()
{
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,
std::string(g_pHostState->m_levelName),
"",
g_pCvar->FindVar("hostport")->m_pzsCurrentValue,
g_pCvar->FindVar("mp_gamemode")->m_pzsCurrentValue,
m_Server.bHidden,
std::to_string(*g_nRemoteFunctionCallsChecksum),
std::string(),
g_szNetKey.c_str()
}
);
if (result)
{
m_iv4HostRequestMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f);
std::stringstream msg;
msg << "Broadcasting! ";
if (!m_szHostToken.empty())
{
msg << "Share the following token for clients to connect: ";
}
m_szHostRequestMessage = msg.str().c_str();
}
else
{
m_iv4HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
}
}
//-----------------------------------------------------------------------------
// Purpose: draws the compmenu
//-----------------------------------------------------------------------------
void IBrowser::CompMenu()
{
ImGui::BeginTabBar("CompMenu");
if (ImGui::TabItemButton("Server Browser"))
{
SetSection(ESection::SERVER_BROWSER);
}
if (ImGui::TabItemButton("Host Server"))
{
SetSection(ESection::HOST_SERVER);
}
if (ImGui::TabItemButton("Settings"))
{
SetSection(ESection::SETTINGS);
}
ImGui::EndTabBar();
}
//-----------------------------------------------------------------------------
// Purpose: draws the server browser section
//-----------------------------------------------------------------------------
void IBrowser::ServerBrowserSection()
{
ImGui::BeginGroup();
m_imServerBrowserFilter.Draw();
ImGui::SameLine();
if (ImGui::Button("Refresh List"))
{
RefreshServerList();
}
ImGui::EndGroup();
ImGui::TextColored(ImVec4(1.00f, 0.00f, 0.00f, 1.00f), m_szServerListMessage.c_str());
ImGui::Separator();
const float FooterHeight = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
ImGui::BeginChild("ServerListChild", { 0, -FooterHeight }, true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
if (ImGui::BeginTable("##ServerBrowser_ServerList", 5, ImGuiTableFlags_Resizable))
{
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch, 20);
ImGui::TableSetupColumn("Map", ImGuiTableColumnFlags_WidthStretch, 25);
ImGui::TableSetupColumn("Port", ImGuiTableColumnFlags_WidthStretch, 5);
ImGui::TableSetupColumn("Playlist", ImGuiTableColumnFlags_WidthStretch, 5);
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch, 5);
ImGui::TableHeadersRow();
for (ServerListing& server : m_vServerList)
{
const char* name = server.svServerName.c_str();
const char* map = server.svMapName.c_str();
const char* port = server.svPort.c_str();
const char* playlist = server.svPlaylist.c_str();
if (m_imServerBrowserFilter.PassFilter(name)
|| m_imServerBrowserFilter.PassFilter(map)
|| m_imServerBrowserFilter.PassFilter(port))
{
ImGui::TableNextColumn();
ImGui::Text(name);
ImGui::TableNextColumn();
ImGui::Text(map);
ImGui::TableNextColumn();
ImGui::Text(port);
ImGui::TableNextColumn();
ImGui::Text(playlist);
ImGui::TableNextColumn();
std::string selectButtonText = "Connect##";
selectButtonText += (server.svServerName + server.svIpAddress + server.svMapName);
if (ImGui::Button(selectButtonText.c_str()))
{
ConnectToServer(server.svIpAddress, server.svPort, server.svEncryptionKey);
}
}
}
ImGui::EndTable();
}
ImGui::EndChild();
ImGui::Separator();
ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth() / 4);
{
ImGui::InputTextWithHint("##ServerBrowser_ServerConnString", "Enter IP address or \"localhost\"", m_chServerConnStringBuffer, IM_ARRAYSIZE(m_chServerConnStringBuffer));
ImGui::SameLine();
ImGui::InputTextWithHint("##ServerBrowser_ServerEncKey", "Enter encryption key", m_chServerEncKeyBuffer, IM_ARRAYSIZE(m_chServerEncKeyBuffer));
ImGui::SameLine();
if (ImGui::Button("Connect##ServerBrowser_ConnectByIp", ImVec2(ImGui::GetWindowContentRegionWidth() / 4.2, 18.5)))
{
ConnectToServer(m_chServerConnStringBuffer, m_chServerEncKeyBuffer);
}
ImGui::SameLine();
if (ImGui::Button("Private Servers##ServerBrowser_HiddenServersButton", ImVec2(ImGui::GetWindowContentRegionWidth() / 4.2, 18.5)))
{
ImGui::OpenPopup("Connect to Private Server##HiddenServersConnectModal");
}
HiddenServersModal();
}
ImGui::PopItemWidth();
}
//-----------------------------------------------------------------------------
// Purpose: draws the hidden private server modal
//-----------------------------------------------------------------------------
void IBrowser::HiddenServersModal()
{
bool modalOpen = true;
if (ImGui::BeginPopupModal("Connect to Private Server##HiddenServersConnectModal", &modalOpen))
{
ImGui::SetWindowSize(ImVec2(400.f, 200.f), ImGuiCond_Always);
if (!m_idLockedIcon)
{
bool ret = LoadTextureBuffer((unsigned char*)m_vucLockedIconBlob, 0x1000 /*TODO [ AMOS ]: Calculate size dynamically*/, &m_idLockedIcon, &m_nLockedIconWidth, &m_nLockedIconHeight);
IM_ASSERT(ret);
}
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.00f, 0.00f, 0.00f, 0.00f)); // Override the style color for child bg.
ImGui::BeginChild("##HiddenServersConnectModal_IconParent", ImVec2(m_nLockedIconWidth, m_nLockedIconHeight));
ImGui::Image(m_idLockedIcon, ImVec2(m_nLockedIconWidth, m_nLockedIconHeight)); // Display texture.
ImGui::EndChild();
ImGui::PopStyleColor(); // Pop the override for the child bg.
ImGui::SameLine();
ImGui::Text("Enter the token to connect");
ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth()); // Override item width.
ImGui::InputTextWithHint("##HiddenServersConnectModal_TokenInput", "Token", &m_szHiddenServerToken);
ImGui::PopItemWidth();
ImGui::Dummy(ImVec2(ImGui::GetWindowContentRegionWidth(), 19.f)); // Place a dummy, basically making space inserting a blank element.
ImGui::TextColored(m_ivHiddenServerMessageColor, m_szHiddenServerRequestMessage.c_str());
ImGui::Separator();
if (ImGui::Button("Connect##HiddenServersConnectModal_ConnectButton", ImVec2(ImGui::GetWindowContentRegionWidth() / 2, 24)))
{
m_szHiddenServerRequestMessage.clear();
ServerListing server;
bool result = g_pR5net->GetServerByToken(server, m_szHiddenServerRequestMessage, m_szHiddenServerToken); // Send token connect request.
if (!server.svServerName.empty())
{
ConnectToServer(server.svIpAddress, server.svPort, server.svEncryptionKey); // Connect to the server
m_szHiddenServerRequestMessage = "Found Server: " + server.svServerName;
m_ivHiddenServerMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f);
ImGui::CloseCurrentPopup();
}
else
{
m_szHiddenServerRequestMessage = "Error: " + m_szHiddenServerRequestMessage;
m_ivHiddenServerMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
}
}
ImGui::SameLine();
if (ImGui::Button("Close##HiddenServersConnectModal_CloseButton", ImVec2(ImGui::GetWindowContentRegionWidth() / 2, 24)))
{
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}
//-----------------------------------------------------------------------------
// Purpose: draws the host section
//-----------------------------------------------------------------------------
void IBrowser::HostServerSection()
{
static std::string szServerNameErr = "";
ImGui::InputTextWithHint("##ServerHost_ServerName", "Server Name (Required)", &m_Server.svServerName);
ImGui::Spacing();
if (ImGui::BeginCombo("Playlist##ServerHost_PlaylistBox", m_Server.svPlaylist.c_str()))
{
for (auto& item : g_szAllPlaylists)
{
if (ImGui::Selectable(item.c_str(), item == m_Server.svPlaylist))
{
m_Server.svPlaylist = item;
}
}
ImGui::EndCombo();
}
if (ImGui::BeginCombo("Map##ServerHost_MapListBox", m_Server.svMapName.c_str()))
{
for (auto& item : m_vszMapsList)
{
if (ImGui::Selectable(item.c_str(), item == m_Server.svMapName))
{
m_Server.svMapName = item;
for (auto it = mapArray.begin(); it != mapArray.end(); ++it)
{
if (it->second.compare(m_Server.svMapName) == NULL)
{
m_Server.svMapName = it->first;
}
}
}
}
ImGui::EndCombo();
}
ImGui::Checkbox("Load Global Ban List##ServerHost_CheckCompBanDBCheckbox", &g_bCheckCompBanDB);
ImGui::Spacing();
ImGui::SameLine();
ImGui::Text("Server Visiblity");
if (ImGui::SameLine(); ImGui::RadioButton("Offline##ServerHost_ServerChoice1", eServerVisibility == EServerVisibility::OFFLINE))
{
eServerVisibility = EServerVisibility::OFFLINE;
}
if (ImGui::SameLine(); ImGui::RadioButton("Hidden##ServerHost_ServerChoice2", eServerVisibility == EServerVisibility::HIDDEN))
{
eServerVisibility = EServerVisibility::HIDDEN;
}
if (ImGui::SameLine(); ImGui::RadioButton("Public##ServerHost_ServerChoice2", eServerVisibility == EServerVisibility::PUBLIC))
{
eServerVisibility = EServerVisibility::PUBLIC;
}
ImGui::Spacing();
ImGui::Separator();
if (!g_pHostState->m_bActiveGame)
{
if (ImGui::Button("Start Server##ServerHost_StartServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
{
szServerNameErr.clear();
if (!m_Server.svServerName.empty() && !m_Server.svPlaylist.empty() && !m_Server.svMapName.empty())
{
DevMsg(eDLL_T::ENGINE, "Starting Server with name '%s', map '%s' and playlist '%s'\n", m_Server.svServerName.c_str(), m_Server.svMapName.c_str(), m_Server.svPlaylist.c_str());
szServerNameErr = std::string();
UpdateHostingStatus();
/*
* Playlist gets parsed in two instances, first in LoadPlaylist all the neccessary values.
* Then when you would normally call launchplaylist which calls StartPlaylist it would cmd call mp_gamemode which parses the gamemode specific part of the playlist..
*/
KeyValues_LoadPlaylist(m_Server.svPlaylist.c_str());
std::stringstream cgmd;
cgmd << "mp_gamemode " << m_Server.svPlaylist;
ProcessCommand(cgmd.str().c_str());
// This is to avoid a race condition.
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::stringstream cmd;
cmd << "map " << m_Server.svMapName;
ProcessCommand(cmd.str().c_str());
}
else
{
if (m_Server.svServerName.empty())
{
szServerNameErr = "No Server Name assigned.";
}
else if (m_Server.svPlaylist.empty())
{
szServerNameErr = "No Playlist assigned.";
}
else if (m_Server.svMapName.empty())
{
szServerNameErr = "'levelname' was empty.";
}
}
}
}
if (ImGui::Button("Force Start##ServerHost_ForceStart", ImVec2(ImGui::GetWindowSize().x, 32)))
{
szServerNameErr.clear();
if (!m_Server.svPlaylist.empty() && !m_Server.svMapName.empty())
{
DevMsg(eDLL_T::ENGINE, "Starting Server with map '%s' and playlist '%s'\n", m_Server.svMapName.c_str(), m_Server.svPlaylist.c_str());
szServerNameErr = std::string();
UpdateHostingStatus();
/*
* Playlist gets parsed in two instances, first in LoadPlaylist all the neccessary values.
* Then when you would normally call launchplaylist which calls StartPlaylist it would cmd call mp_gamemode which parses the gamemode specific part of the playlist..
*/
KeyValues_LoadPlaylist(m_Server.svPlaylist.c_str());
std::stringstream cgmd;
cgmd << "mp_gamemode " << m_Server.svPlaylist;
ProcessCommand(cgmd.str().c_str());
// This is to avoid a race condition.
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::stringstream cmd;
cmd << "map " << m_Server.svMapName;
ProcessCommand(cmd.str().c_str());
}
else
{
if (m_Server.svPlaylist.empty())
{
szServerNameErr = "No Playlist assigned.";
}
else if (m_Server.svMapName.empty())
{
szServerNameErr = "'levelname' was empty.";
}
}
}
ImGui::TextColored(ImVec4(1.00f, 0.00f, 0.00f, 1.00f), szServerNameErr.c_str());
ImGui::TextColored(m_iv4HostRequestMessageColor, m_szHostRequestMessage.c_str());
if (!m_szHostToken.empty())
{
ImGui::InputText("##ServerHost_HostToken", &m_szHostToken, ImGuiInputTextFlags_ReadOnly);
}
if (g_pHostState->m_bActiveGame)
{
if (ImGui::Button("Reload Scripts##ServerHost_ReloadServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
{
DevMsg(eDLL_T::ENGINE, "Recompiling scripts\n");
ProcessCommand("reparse_weapons");
ProcessCommand("reload");
}
if (ImGui::Button("Change Level##ServerHost_ChangeLevel", ImVec2(ImGui::GetWindowSize().x, 32)))
{
if (!m_Server.svMapName.empty())
{
strncpy_s(g_pHostState->m_levelName, m_Server.svMapName.c_str(), 64); // Copy new map into hoststate levelname. 64 is size of m_levelname.
g_pHostState->m_iNextState = HostStates_t::HS_CHANGE_LEVEL_MP; // Force CHostState::FrameUpdate to change the level.
}
else
{
szServerNameErr = "Failed to change level: 'levelname' was empty.";
}
}
if (ImGui::Button("Stop Server##ServerHost_StopServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
{
ProcessCommand("LeaveMatch"); // TODO: use script callback instead.
g_pHostState->m_iNextState = HostStates_t::HS_GAME_SHUTDOWN; // Force CHostState::FrameUpdate to shutdown the server for dedicated.
}
}
else
{
if (ImGui::Button("Reload Playlist from Disk##ServerHost_ReloadPlaylist", ImVec2(ImGui::GetWindowSize().x, 32)))
{
DownloadPlaylists_f_CompletionFunc();
CKeyValueSystem_InitPlaylist(); // Re-Init playlist.
}
}
}
//-----------------------------------------------------------------------------
// Purpose: draws the settings section
//-----------------------------------------------------------------------------
void IBrowser::SettingsSection()
{
ImGui::InputTextWithHint("Hostname##MatchmakingServerString", "Matchmaking Server String", &m_szMatchmakingHostName);
if (ImGui::Button("Update Hostname"))
{
r5net_matchmaking_hostname->m_pzsCurrentValue = m_szMatchmakingHostName.c_str();
if (g_pR5net)
{
delete g_pR5net;
g_pR5net = new R5Net::Client(r5net_matchmaking_hostname->m_pzsCurrentValue);
}
}
ImGui::InputText("Netkey##SettingsSection_EncKey", (char*)g_szNetKey.c_str(), ImGuiInputTextFlags_ReadOnly);
if (ImGui::Button("Regenerate Encryption Key##SettingsSection_RegenEncKey"))
{
RegenerateEncryptionKey();
}
}
//-----------------------------------------------------------------------------
// Purpose: draws the main browser frontend
//-----------------------------------------------------------------------------
void IBrowser::Draw(const char* title, bool* bDraw)
{
if (!m_bThemeSet)
{
SetStyleVar();
m_bThemeSet = true;
}
if (!ImGui::Begin(title, bDraw))
{
ImGui::End();
return;
}
ImGui::End();
if (*bDraw == NULL)
{
g_bShowBrowser = false;
}
ImGui::SetNextWindowSize(ImVec2(840, 600), ImGuiCond_FirstUseEver);
ImGui::SetWindowPos(ImVec2(-500, 50), ImGuiCond_FirstUseEver);
ImGui::Begin(title, NULL, ImGuiWindowFlags_NoScrollbar);
{
CompMenu();
switch (eCurrentSection)
{
case ESection::SERVER_BROWSER:
ServerBrowserSection();
break;
case ESection::HOST_SERVER:
HostServerSection();
break;
case ESection::SETTINGS:
SettingsSection();
break;
default:
break;
}
}
ImGui::End();
}
//-----------------------------------------------------------------------------
// Purpose: executes submitted commands in a separate thread
//-----------------------------------------------------------------------------
void IBrowser::ProcessCommand(const char* command_line)
{
std::thread t(IVEngineClient_CommandExecute, this, command_line);
t.detach(); // Detach from render thread.
// This is to avoid a race condition.
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
//-----------------------------------------------------------------------------
// Purpose: connects to specified server
//-----------------------------------------------------------------------------
void IBrowser::ConnectToServer(const std::string ip, const std::string port, const std::string encKey)
{
if (!encKey.empty())
{
ChangeEncryptionKeyTo(encKey);
}
std::stringstream cmd;
cmd << "connect " << ip << ":" << port;
ProcessCommand(cmd.str().c_str());
}
//-----------------------------------------------------------------------------
// Purpose: connects to specified server
//-----------------------------------------------------------------------------
void IBrowser::ConnectToServer(const std::string connString, const std::string encKey)
{
if (!encKey.empty())
{
ChangeEncryptionKeyTo(encKey);
}
std::stringstream cmd;
cmd << "connect " << connString;
ProcessCommand(cmd.str().c_str());
}
//-----------------------------------------------------------------------------
// Purpose: regenerates encryption key
//-----------------------------------------------------------------------------
void IBrowser::RegenerateEncryptionKey()
{
HNET_GenerateKey();
}
//-----------------------------------------------------------------------------
// Purpose: changes encryption key to specified one
//-----------------------------------------------------------------------------
void IBrowser::ChangeEncryptionKeyTo(const std::string str)
{
HNET_SetKey(str);
}
//#############################################################################
// ENTRYPOINT
//#############################################################################
IBrowser* g_pServerBrowser = nullptr;
void DrawBrowser(bool* bDraw)
{
static IBrowser browser;
static bool AssignPtr = []()
{
g_pServerBrowser = &browser;
return true;
} ();
browser.Draw("Server Browser", bDraw);
}

View File

@ -1,173 +0,0 @@
#pragma once
#ifndef DEDICATED
#include "networksystem/serverlisting.h"
#include "networksystem/r5net.h"
void DrawBrowser(bool* bDraw);
class IBrowser
{
private:
bool m_bThemeSet = false;
public:
IBrowser();
~IBrowser();
////////////////////
// Enums //
////////////////////
enum class ESection
{
SERVER_BROWSER,
HOST_SERVER,
SETTINGS
} eCurrentSection = ESection::SERVER_BROWSER;
enum class EHostStatus
{
NOT_HOSTING,
HOSTING
} eHostingStatus = EHostStatus::NOT_HOSTING;
enum class EServerVisibility
{
OFFLINE,
HIDDEN,
PUBLIC
} eServerVisibility = EServerVisibility::OFFLINE;
////////////////////
// Server Browser //
////////////////////
public:
std::vector<ServerListing> m_vServerList;
ImGuiTextFilter m_imServerBrowserFilter;
char m_chServerConnStringBuffer[256] = { 0 };
char m_chServerEncKeyBuffer[30] = { 0 };
std::string m_szServerListMessage = std::string();
std::map<std::string, std::string> mapArray =
{
{ "mp_rr_canyonlands_64k_x_64k", "King's Canyon Season 0" },
{ "mp_rr_desertlands_64k_x_64k", "World's Edge Season 3" },
{ "mp_rr_canyonlands_mu1", "King's Canyon Season 2" },
{ "mp_rr_canyonlands_mu1_night", "King's Canyon Season 2 After Dark" },
{ "mp_rr_desertlands_64k_x_64k_nx", "World's Edge Season 3 After Dark" },
{ "mp_lobby", "Lobby Season 3" },
{ "mp_rr_canyonlands_staging", "King's Canyon Firing Range" }
};
////////////////////
// Settings //
////////////////////
std::string m_szMatchmakingHostName;
////////////////////
// Host Server //
////////////////////
ServerListing m_Server;
std::vector<std::string> m_vszMapsList;
std::string m_szHostRequestMessage = "";
std::string m_szHostToken = "";
ImVec4 m_iv4HostRequestMessageColor = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
////////////////////
// Private Server //
////////////////////
std::string m_szHiddenServerToken = "";
std::string m_szHiddenServerRequestMessage = "";
ImVec4 m_ivHiddenServerMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f);
/* Texture */
ID3D11ShaderResourceView* m_idLockedIcon = nullptr;
int m_nLockedIconWidth = 0;
int m_nLockedIconHeight = 0;
std::vector<unsigned char>* m_vucLockedIconBlob;
void SetSection(ESection section)
{
eCurrentSection = section;
}
////////////////////
// Style //
////////////////////
void SetStyleVar()
{
ImGuiStyle& style = ImGui::GetStyle();
ImVec4* colors = style.Colors;
colors[ImGuiCol_Text] = ImVec4(0.81f, 0.81f, 0.81f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.56f, 0.56f, 0.56f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f);
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_PopupBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f);
colors[ImGuiCol_Border] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.04f, 0.04f, 0.04f, 0.64f);
colors[ImGuiCol_FrameBg] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.24f, 0.24f, 0.24f, 1.00f);
colors[ImGuiCol_TitleBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_MenuBarBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f);
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f);
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f);
colors[ImGuiCol_CheckMark] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
colors[ImGuiCol_SliderGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f);
colors[ImGuiCol_Button] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f);
colors[ImGuiCol_ButtonActive] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f);
colors[ImGuiCol_Header] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f);
colors[ImGuiCol_Separator] = ImVec4(0.53f, 0.53f, 0.57f, 1.00f);
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f);
colors[ImGuiCol_ResizeGrip] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f);
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f);
colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f);
colors[ImGuiCol_TabHovered] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
colors[ImGuiCol_TabActive] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
style.WindowBorderSize = 0.0f;
style.FrameBorderSize = 1.0f;
style.ChildBorderSize = 1.0f;
style.PopupBorderSize = 1.0f;
style.TabBorderSize = 1.0f;
style.WindowRounding = 2.5f;
style.FrameRounding = 0.0f;
style.ChildRounding = 0.0f;
style.PopupRounding = 0.0f;
style.TabRounding = 1.0f;
style.ScrollbarRounding = 1.0f;
style.ItemSpacing = ImVec2(4, 4);
style.WindowPadding = ImVec2(5, 5);
}
void RefreshServerList();
void SendHostingPostRequest();
void CompMenu();
void ServerBrowserSection();
void SettingsSection();
void HiddenServersModal();
void HostServerSection();
void Draw(const char* title, bool* bDraw);
void UpdateHostingStatus();
void ProcessCommand(const char* command_line);
void RegenerateEncryptionKey();
void ChangeEncryptionKeyTo(const std::string str);
void ConnectToServer(const std::string ip, const std::string port, const std::string encKey);
void ConnectToServer(const std::string connString, const std::string encKey);
};
extern IBrowser* g_pServerBrowser;
#endif

View File

@ -0,0 +1,132 @@
#pragma once
namespace R5Net {
struct NetGameMod
{
std::string package;
int number;
bool requiredForClients;
std::string downloadLink;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(NetGameMod, package, number, requiredForClients, downloadLink)
};
struct NetGameServer
{
std::string name;
std::string description;
std::string password;
int playerCount;
int maxPlayerCount;
std::string playlist;
std::string mapName;
std::vector<NetGameMod> mods;
std::string ipAddress;
int gamePort;
std::string encryptionKey;
std::string remoteChecksum;
std::string reloadedVersion;
std::string publicRef;
int lastPing = -1;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(NetGameServer, name, description, password, playerCount, maxPlayerCount, playlist, mapName, mods, ipAddress, gamePort, encryptionKey, remoteChecksum, reloadedVersion, publicRef)
};
////// Requests
struct UpdateGameServerMSRequest
{
NetGameServer gameServer;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(UpdateGameServerMSRequest, gameServer)
};
struct GetIsUserBannedMSRequest
{
int oid;
std::string ipAddress;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(GetIsUserBannedMSRequest, oid, ipAddress)
};
struct GetPrivateGameServerInfoMSRequest
{
std::string publicRef;
std::string password;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(GetPrivateGameServerInfoMSRequest, publicRef, password)
};
/// <summary>
/// Responses
/// </summary>
///
///
enum class EResponseStatus
{
NO_REACH,
SUCCESS,
FORBIDDEN,
NOT_FOUND,
MS_ERROR,
UNKNOWN
};
struct DefaultMSResponse
{
EResponseStatus status = EResponseStatus::NO_REACH;
std::string error;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(DefaultMSResponse, error)
};
struct GetGlobalStatsMSResponse : DefaultMSResponse
{
int noPlayers;
int noServers;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(GetGlobalStatsMSResponse, noPlayers, noServers)
};
struct GetGameServersListMSResponse : DefaultMSResponse
{
std::vector<NetGameServer> publicServers;
std::vector<NetGameServer> privateServers;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(GetGameServersListMSResponse, publicServers, privateServers)
};
struct UpdateGameServerMSResponse : DefaultMSResponse
{
NetGameServer gameServer;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(UpdateGameServerMSResponse, gameServer)
};
struct GetIsUserBannedMSResponse : DefaultMSResponse
{
bool isBanned;
std::string metaString;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(GetIsUserBannedMSResponse, isBanned, metaString)
};
struct GetPrivateGameServerInfoMSResponse : DefaultMSResponse
{
NetGameServer gameServer;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(GetPrivateGameServerInfoMSResponse, gameServer)
};
}

View File

@ -2,327 +2,6 @@
//
#include "core/stdafx.h"
#include "tier0/basetypes.h"
#include "tier0/cvar.h"
#include "engine/sys_utils.h"
#include "networksystem/r5net.h"
#include <networksystem/r5net.h>
//-----------------------------------------------------------------------------
// Purpose: returns the sdk version string.
//-----------------------------------------------------------------------------
std::string R5Net::Client::GetSDKVersion()
{
return SDK_VERSION;
}
//-----------------------------------------------------------------------------
// Purpose: returns a vector of hosted servers.
//-----------------------------------------------------------------------------
std::vector<ServerListing> R5Net::Client::GetServersList(std::string& svOutMessage)
{
std::vector<ServerListing> vslList{};
nlohmann::json jsReqBody = nlohmann::json::object();
jsReqBody["version"] = GetSDKVersion();
std::string reqBodyStr = jsReqBody.dump();
if (r5net_show_debug->m_pParent->m_iValue > 0)
{
DevMsg(eDLL_T::ENGINE, "Sending GetServerList post.\n");
}
httplib::Result htResults = m_HttpClient.Post("/servers", jsReqBody.dump().c_str(), jsReqBody.dump().length(), "application/json");
if (r5net_show_debug->m_pParent->m_iValue > 0)
{
DevMsg(eDLL_T::ENGINE, "GetServerList replied with '%d'.\n", htResults->status);
}
if (htResults && htResults->status == 200) // STATUS_OK
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["success"].is_boolean() && jsResultBody["success"].get<bool>())
{
for (auto &obj : jsResultBody["servers"])
{
vslList.push_back(
ServerListing{
obj.value("name",""),
obj.value("map", ""),
obj.value("ip", ""),
obj.value("port", ""),
obj.value("gamemode", ""),
obj.value("hidden", "false") == "true",
obj.value("remote_checksum", ""),
obj.value("version", GetSDKVersion()),
obj.value("encKey", "")
}
);
}
}
else
{
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<std::string>();
}
else
{
svOutMessage = "An unknown error occured!";
}
}
}
else
{
if (htResults)
{
if (!htResults->body.empty())
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<std::string>();
}
else
{
svOutMessage = std::string("Failed to reach comp-server ") + std::to_string(htResults->status);
}
return vslList;
}
svOutMessage = std::string("Failed to reach comp-server ") + std::to_string(htResults->status);
return vslList;
}
svOutMessage = "Failed to reach comp-server. Unknown error code.";
return vslList;
}
return vslList;
}
//-----------------------------------------------------------------------------
// Purpose: Sends host server POST request.
// Input : &svOutMessage -
// &svOutToken -
// &slServerListing -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool R5Net::Client::PostServerHost(std::string& svOutMessage, std::string& svOutToken, const ServerListing& slServerListing)
{
nlohmann::json jsRequestBody = nlohmann::json::object();
jsRequestBody["name"] = slServerListing.svServerName;
jsRequestBody["map"] = slServerListing.svMapName;
jsRequestBody["port"] = slServerListing.svPort;
jsRequestBody["remote_checksum"] = slServerListing.svRemoteChecksum;
jsRequestBody["version"] = GetSDKVersion();
jsRequestBody["gamemode"] = slServerListing.svPlaylist;
jsRequestBody["encKey"] = slServerListing.svEncryptionKey;
jsRequestBody["hidden"] = slServerListing.bHidden;
std::string svRequestBody = jsRequestBody.dump();
if (r5net_show_debug->m_pParent->m_iValue > 0)
{
DevMsg(eDLL_T::ENGINE, "Sending PostServerHost post '%s'.\n", svRequestBody.c_str());
}
httplib::Result htResults = m_HttpClient.Post("/servers/add", svRequestBody.c_str(), svRequestBody.length(), "application/json");
if (r5net_show_debug->m_pParent->m_iValue > 0)
{
DevMsg(eDLL_T::ENGINE, "PostServerHost replied with '%d'.\n", htResults->status);
}
if (htResults && htResults->status == 200) // STATUS_OK
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["success"].is_boolean() && jsResultBody["success"].get<bool>())
{
if (jsResultBody["token"].is_string())
{
svOutToken = jsResultBody["token"].get<std::string>();
}
else
{
svOutToken = std::string();
}
return true;
}
else
{
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<std::string>();
}
else
{
svOutMessage = "An unknown error occured!";
}
return false;
}
}
else
{
if (htResults)
{
if (!htResults->body.empty())
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<std::string>();
}
else
{
svOutMessage = std::string("Failed to reach comp-server ") + std::to_string(htResults->status);
}
svOutToken = std::string();
return false;
}
svOutToken = std::string();
svOutMessage = std::string("Failed to reach comp-server ") + std::to_string(htResults->status);
return false;
}
svOutToken = std::string();
svOutMessage = "Failed to reach comp-server. Unknown error code.";
return false;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Gets the server by token string.
// Input : &slOutServer -
// &svOutMessage -
// svToken -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool R5Net::Client::GetServerByToken(ServerListing& slOutServer, std::string& svOutMessage, const std::string svToken)
{
nlohmann::json jsRequestBody = nlohmann::json::object();
jsRequestBody["token"] = svToken;
if (r5net_show_debug->m_pParent->m_iValue > 0)
{
DevMsg(eDLL_T::ENGINE, "Sending GetServerByToken post.\n");
}
httplib::Result htResults = m_HttpClient.Post("/server/byToken", jsRequestBody.dump().c_str(), jsRequestBody.dump().length(), "application/json");
if (r5net_show_debug->m_pParent->m_iValue > 0)
{
DevMsg(eDLL_T::ENGINE, "GetServerByToken replied with '%d'\n", htResults->status);
}
if (htResults && htResults->status == 200) // STATUS_OK
{
if (!htResults->body.empty())
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (htResults && jsResultBody["success"].is_boolean() && jsResultBody["success"])
{
slOutServer = ServerListing{
jsResultBody["server"].value("name",""),
jsResultBody["server"].value("map", ""),
jsResultBody["server"].value("ip", ""),
jsResultBody["server"].value("port", ""),
jsResultBody["server"].value("gamemode", ""),
jsResultBody["server"].value("hidden", "false") == "true",
jsResultBody["server"].value("remote_checksum", ""),
jsResultBody["server"].value("version", GetSDKVersion()),
jsResultBody["server"].value("encKey", "")
};
return true;
}
else
{
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<std::string>();
}
else
{
svOutMessage = "";
}
slOutServer = ServerListing{};
return false;
}
}
}
else
{
if (htResults)
{
if (!htResults->body.empty())
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<std::string>();
}
else
{
svOutMessage = std::string("Failed to reach comp-server ") + std::to_string(htResults->status);
}
return false;
}
svOutMessage = std::string("Failed to reach comp-server ") + std::to_string(htResults->status);
return false;
}
svOutMessage = "Failed to reach comp-server. Unknown error code.";
slOutServer = ServerListing{};
return false;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Checks if client is banned on the comp server.
// Input : svIpAddress -
// nOriginID -
// &svOutErrCl -
// Output : Returns true if banned, false if not banned.
//-----------------------------------------------------------------------------
bool R5Net::Client::GetClientIsBanned(const std::string svIpAddress, std::int64_t nOriginID, std::string& svOutErrCl)
{
nlohmann::json jsRequestBody = nlohmann::json::object();
jsRequestBody["ip"] = svIpAddress;
jsRequestBody["orid"] = nOriginID;
httplib::Result htResults = m_HttpClient.Post("/banlist/isBanned", jsRequestBody.dump().c_str(), jsRequestBody.dump().length(), "application/json");
if (htResults && htResults->status == 200)
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["success"].is_boolean() && jsResultBody["success"].get<bool>())
{
if (jsResultBody["isBanned"].is_boolean() && jsResultBody["isBanned"].get<bool>())
{
svOutErrCl = jsResultBody.value("errCl", "Generic error (code:gen). Contact R5Reloaded developers.");
return true;
}
}
}
return false;
}
///////////////////////////////////////////////////////////////////////////////
R5Net::Client* g_pR5net(new R5Net::Client("r5a-comp-sv.herokuapp.com"));
R5Net::Client* g_pR5net = new R5Net::Client("127.0.0.1:3000");

View File

@ -1,27 +1,124 @@
#pragma once
#include "serverlisting.h"
#include "net_structs.h"
#include "core/stdafx.h"
namespace R5Net
{
class Client
#define R5NET_GET_ENDPOINT(FuncName, Route, ResponseStructType)\
ResponseStructType FuncName() {\
ResponseStructType result{};\
httplib::Result response = HttpClient.Get(Route);\
if(response == nullptr) return result;\
switch(response->status)\
{\
case 403:\
{\
result.status = EResponseStatus::FORBIDDEN;\
break;\
}\
case 404:\
{\
result.status = EResponseStatus::NOT_FOUND;\
break;\
}\
case 500:\
{\
result.status = EResponseStatus::MS_ERROR;\
break;\
}\
case 200:\
{\
result.status = EResponseStatus::SUCCESS;\
break;\
}\
default: \
{\
result.status = EResponseStatus::UNKNOWN;\
break;\
}\
}\
nlohmann::json response_body = nlohmann::json::parse(response->body);\
from_json(response_body, result);\
return result;\
}\
\
void FuncName##_Async(std::function<void(ResponseStructType)> Callback) {\
std::thread t([&]() {\
Callback(FuncName());\
});\
t.detach();\
}\
#define R5NET_POST_ENDPOINT(FuncName, Route, RequestStructType, ResponseStructType)\
ResponseStructType FuncName(const RequestStructType& request) {\
ResponseStructType result{};\
nlohmann::json request_body;\
to_json(request_body, request);\
httplib::Result response = HttpClient.Post(Route, request_body.dump(), "application/json");\
if (response == nullptr) return result;\
switch(response->status)\
{\
case 403:\
{\
result.status = EResponseStatus::FORBIDDEN;\
break;\
}\
case 404:\
{\
result.status = EResponseStatus::NOT_FOUND;\
break;\
}\
case 500:\
{\
result.status = EResponseStatus::MS_ERROR;\
break;\
}\
case 200:\
{\
result.status = EResponseStatus::SUCCESS;\
break;\
}\
default: \
{\
result.status = EResponseStatus::UNKNOWN;\
break;\
}\
}\
nlohmann::json response_body = nlohmann::json::parse(response->body);\
from_json(response_body, result);\
return result;\
}\
\
void FuncName##_Async(const RequestStructType& request, std::function<void(ResponseStructType)> Callback) {\
std::thread t([&]() {\
Callback(FuncName(request));\
});\
t.detach();\
}\
class Client
{
httplib::Client HttpClient;
public:
Client(std::string serverString) : m_HttpClient(serverString.c_str())
Client(std::string masterServerConnectionString) : HttpClient(masterServerConnectionString.c_str())
{
m_HttpClient.set_connection_timeout(10);
HttpClient.set_connection_timeout(25);
}
std::vector<ServerListing> GetServersList(std::string& svOutMessage);
bool PostServerHost(std::string& svOutMessage, std::string& svOutToken, const ServerListing& slServerListing);
bool GetServerByToken(ServerListing& slOutServer, std::string& svOutMessage, const std::string svToken);
bool GetClientIsBanned(std::string svIpAddress, std::int64_t nOriginID, std::string& svOutErrCl);
std::string GetSDKVersion();
Client* pR5net = nullptr;
Client* GetR5Net() { return pR5net; }
private:
httplib::Client m_HttpClient;
R5NET_GET_ENDPOINT(GetGlobalStats, "/api/stats", GetGlobalStatsMSResponse)
R5NET_GET_ENDPOINT(GetGameServersList, "/api/game_servers/list", GetGameServersListMSResponse)
R5NET_POST_ENDPOINT(UpdateMyGameServer, "/api/game_servers/update", UpdateGameServerMSRequest, UpdateGameServerMSResponse)
R5NET_POST_ENDPOINT(GetPrivateGameServerInfo, "/api/game_servers/game_server_private_info", GetPrivateGameServerInfoMSRequest, GetPrivateGameServerInfoMSResponse)
R5NET_POST_ENDPOINT(GetClientIsBanned, "/api/ban_system/is_user_banned", GetIsUserBannedMSRequest, GetIsUserBannedMSResponse)
};
}
extern R5Net::Client* g_pR5net;
extern R5Net::Client* g_pR5net;

View File

@ -1,14 +0,0 @@
#pragma once
struct ServerListing
{
std::string svServerName;
std::string svMapName = "mp_rr_canyonlands_staging";
std::string svIpAddress;
std::string svPort;
std::string svPlaylist = "survival_dev";
bool bHidden{};
std::string svRemoteChecksum;
std::string svVersion;
std::string svEncryptionKey;
};

View File

@ -2483,7 +2483,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63)
#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
#define NLOHMANN_JSON_FROM(v1) try { nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1); } catch(...) {}
/*!
@brief macro

View File

@ -40,7 +40,7 @@
<ClCompile Include="engine\sys_dll2.cpp" />
<ClCompile Include="engine\sys_utils.cpp" />
<ClCompile Include="gameui\IConsole.cpp" />
<ClCompile Include="gameui\IBrowser.cpp" />
<ClCompile Include="IDevPallete.cpp" />
<ClCompile Include="inputsystem\inputsystem.cpp" />
<ClCompile Include="launcher\IApplication.cpp" />
<ClCompile Include="mathlib\adler32.cpp" />
@ -133,7 +133,7 @@
<ClInclude Include="engine\sys_dll2.h" />
<ClInclude Include="engine\sys_utils.h" />
<ClInclude Include="gameui\IConsole.h" />
<ClInclude Include="gameui\IBrowser.h" />
<ClInclude Include="IDevPalette.h" />
<ClInclude Include="inputsystem\ButtonCode.h" />
<ClInclude Include="inputsystem\inputsystem.h" />
<ClInclude Include="launcher\IApplication.h" />
@ -142,8 +142,8 @@
<ClInclude Include="mathlib\IceKey.H" />
<ClInclude Include="mathlib\parallel_for.h" />
<ClInclude Include="mathlib\vector.h" />
<ClInclude Include="networksystem\net_structs.h" />
<ClInclude Include="networksystem\r5net.h" />
<ClInclude Include="networksystem\serverlisting.h" />
<ClInclude Include="networksystem\sm_protocol.h" />
<ClInclude Include="public\include\memaddr.h" />
<ClInclude Include="public\include\bansystem.h" />

View File

@ -156,9 +156,6 @@
<ClCompile Include="engine\baseclientstate.cpp">
<Filter>sdk\engine</Filter>
</ClCompile>
<ClCompile Include="gameui\IBrowser.cpp">
<Filter>sdk\gameui</Filter>
</ClCompile>
<ClCompile Include="gameui\IConsole.cpp">
<Filter>sdk\gameui</Filter>
</ClCompile>
@ -306,6 +303,9 @@
<ClCompile Include="windows\system.cpp">
<Filter>windows</Filter>
</ClCompile>
<ClCompile Include="IDevPallete.cpp">
<Filter>sdk\gameui</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="client\cdll_engine_int.h">
@ -344,9 +344,6 @@
<ClInclude Include="engine\baseclient.h">
<Filter>sdk\engine</Filter>
</ClInclude>
<ClInclude Include="gameui\IBrowser.h">
<Filter>sdk\gameui</Filter>
</ClInclude>
<ClInclude Include="gameui\IConsole.h">
<Filter>sdk\gameui</Filter>
</ClInclude>
@ -791,9 +788,6 @@
<ClInclude Include="networksystem\r5net.h">
<Filter>sdk\networksystem</Filter>
</ClInclude>
<ClInclude Include="networksystem\serverlisting.h">
<Filter>sdk\networksystem</Filter>
</ClInclude>
<ClInclude Include="mathlib\parallel_for.h">
<Filter>sdk\mathlib</Filter>
</ClInclude>
@ -844,6 +838,12 @@
</ClInclude>
<ClInclude Include="windows\system.h">
<Filter>windows</Filter>
</ClInclude>
<ClInclude Include="networksystem\net_structs.h">
<Filter>sdk\networksystem</Filter>
</ClInclude>
<ClInclude Include="IDevPalette.h">
<Filter>sdk\gameui</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>

View File

@ -12,7 +12,16 @@
void IsClientBanned(R5Net::Client* pR5net, const std::string svIPAddr, std::int64_t nNucleusID)
{
std::string svError = std::string();
bool bCompBanned = pR5net && pR5net->GetClientIsBanned(svIPAddr, nNucleusID, svError);
R5Net::GetIsUserBannedMSRequest req{nNucleusID, svIPAddr};
R5Net::GetIsUserBannedMSResponse res = pR5net->GetClientIsBanned(req);
switch (res.status)
{
// TODO: EVENTUALLY IMPLEMENT SITUATIONS WHERE REQUEST DIDNT SUCCEED
}
bool bCompBanned = res.isBanned;
if (bCompBanned)
{
while (bCompBanned)

View File

@ -33,7 +33,6 @@ namespace
void CServer_Attach();
void CServer_Detach();
void IsClientBanned(R5Net::Client* r5net, const std::string ipaddr, std::int64_t nucleus_id);
void* HCServer_Authenticate(void* cserver, user_creds* inpacket);
extern bool g_bCheckCompBanDB;

View File

@ -6,10 +6,10 @@
#include "windows/id3dx.h"
#include "windows/input.h"
#include "gameui/IConsole.h"
#include "gameui/IBrowser.h"
#include "engine/sys_utils.h"
#include "inputsystem/inputsystem.h"
#include "public/include/stb_image.h"
#include <IDevPalette.h>
/**********************************************************************************
-----------------------------------------------------------------------------------
@ -282,8 +282,8 @@ void DrawImGui()
}
if (g_bShowBrowser)
{
g_pInputSystem->EnableInput(false); // Disable input to game when browser is drawn.
DrawBrowser(&bShowBrowser);
g_pInputSystem->EnableInput(false);
DrawDevPalette(&bShowBrowser);
}
if (!g_bShowConsole && !g_bShowBrowser)
{