mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
sq server browser clean up (#63)
* sq server browser clean up * Properly loop through std::vector on GetAvailableMaps. Co-authored-by: IcePixelx <41352111+PixieCore@users.noreply.github.com>
This commit is contained in:
parent
829e122cea
commit
b366e4ce82
@ -55,6 +55,7 @@ IBrowser::IBrowser()
|
||||
{
|
||||
m_vszMapsList.push_back(filename);
|
||||
}
|
||||
m_vszMapFileNameList.push_back(filename);
|
||||
}
|
||||
|
||||
static std::thread hostingServerRequestThread([this]()
|
||||
@ -92,24 +93,22 @@ IBrowser::~IBrowser()
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets needed create game vars
|
||||
//-----------------------------------------------------------------------------
|
||||
void IBrowser::SetMenuVars(std::string name, std::string vis)
|
||||
void IBrowser::SetMenuVars(std::string name, EServerVisibility vis)
|
||||
{
|
||||
if (vis == "Public")
|
||||
switch (vis)
|
||||
{
|
||||
case EServerVisibility::PUBLIC:
|
||||
m_Server.bHidden = false;
|
||||
eServerVisibility = EServerVisibility::PUBLIC;
|
||||
}
|
||||
else if (vis == "Private")
|
||||
{
|
||||
eServerVisibility = EServerVisibility::HIDDEN;
|
||||
break;
|
||||
case EServerVisibility::HIDDEN:
|
||||
m_Server.bHidden = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
default:
|
||||
m_Server.bHidden = true;
|
||||
eServerVisibility = EServerVisibility::OFFLINE;
|
||||
break;
|
||||
}
|
||||
|
||||
eServerVisibility = vis;
|
||||
m_Server.svServerName = name;
|
||||
|
||||
UpdateHostingStatus();
|
||||
|
@ -3,11 +3,42 @@
|
||||
#include "networksystem/serverlisting.h"
|
||||
#include "networksystem/r5net.h"
|
||||
|
||||
enum class ESection
|
||||
{
|
||||
SERVER_BROWSER,
|
||||
HOST_SERVER,
|
||||
SETTINGS
|
||||
};
|
||||
|
||||
enum class EHostStatus
|
||||
{
|
||||
NOT_HOSTING,
|
||||
HOSTING
|
||||
};
|
||||
|
||||
enum class EServerVisibility
|
||||
{
|
||||
OFFLINE,
|
||||
HIDDEN,
|
||||
PUBLIC
|
||||
};
|
||||
|
||||
class IBrowser
|
||||
{
|
||||
private:
|
||||
bool m_bInitialized = false;
|
||||
public:
|
||||
////////////////////
|
||||
// Enum Vars //
|
||||
////////////////////
|
||||
|
||||
ESection eCurrentSection = ESection::SERVER_BROWSER;
|
||||
EHostStatus eHostingStatus = EHostStatus::NOT_HOSTING;
|
||||
EServerVisibility eServerVisibility = EServerVisibility::OFFLINE;
|
||||
public:
|
||||
////////////////////
|
||||
// Funcs //
|
||||
////////////////////
|
||||
IBrowser();
|
||||
~IBrowser();
|
||||
|
||||
@ -20,7 +51,7 @@ public:
|
||||
|
||||
void ConnectToServer(const std::string ip, const std::string port, const std::string encKey);
|
||||
void ConnectToServer(const std::string connString, const std::string encKey);
|
||||
void SetMenuVars(std::string name, std::string vis);
|
||||
void SetMenuVars(std::string name, EServerVisibility vis);
|
||||
|
||||
void HiddenServersModal();
|
||||
void HostServerSection();
|
||||
@ -37,29 +68,6 @@ public:
|
||||
|
||||
void SetStyleVar();
|
||||
|
||||
////////////////////
|
||||
// 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 //
|
||||
////////////////////
|
||||
@ -93,6 +101,7 @@ public:
|
||||
////////////////////
|
||||
ServerListing m_Server;
|
||||
std::vector<std::string> m_vszMapsList;
|
||||
std::vector<std::string> m_vszMapFileNameList;
|
||||
std::string m_szHostRequestMessage = "";
|
||||
std::string m_szHostToken = "";
|
||||
ImVec4 m_iv4HostRequestMessageColor = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||
|
@ -38,11 +38,11 @@ namespace SQNativeFunctions
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
SQRESULT GetServerAmount(void* sqvm)
|
||||
SQRESULT GetServerCount(void* sqvm)
|
||||
{
|
||||
g_pIBrowser->GetServerList(); // Refresh server list.
|
||||
|
||||
hsq_pushinteger(sqvm, g_pIBrowser->m_vServerList.size() - 1); // please fix the -1 rexx okay thank you.
|
||||
hsq_pushinteger(sqvm, g_pIBrowser->m_vServerList.size());
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
@ -128,14 +128,13 @@ namespace SQNativeFunctions
|
||||
std::string svName = hsq_getstring(sqvm, 1);
|
||||
std::string svMapName = hsq_getstring(sqvm, 2);
|
||||
std::string svPlaylist = hsq_getstring(sqvm, 3);
|
||||
std::string svVisibility = hsq_getstring(sqvm, 4); // Rexx please change this to an integer, so we don't have that ghetto switch case in SetMenuVars.
|
||||
EServerVisibility svVisibility = (EServerVisibility)hsq_getinteger(sqvm, 4);
|
||||
|
||||
if (svMapName.empty() || svPlaylist.empty() || svVisibility.empty())
|
||||
if (svMapName.empty() || svPlaylist.empty())
|
||||
return SQ_OK;
|
||||
|
||||
g_pIBrowser->SetMenuVars(svName, svVisibility); // Pass integer instead
|
||||
|
||||
|
||||
/* Changing this up to call a IBrowser method eventually. */
|
||||
DevMsg(eDLL_T::ENGINE, "Starting Server with map '%s' and playlist '%s'\n", svMapName.c_str(), svPlaylist.c_str());
|
||||
|
||||
@ -203,5 +202,22 @@ namespace SQNativeFunctions
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
SQRESULT GetAvailableMaps(void* sqvm)
|
||||
{
|
||||
std::vector<std::string> mapList = g_pIBrowser->m_vszMapFileNameList;
|
||||
|
||||
DevMsg(eDLL_T::UI, "Requesting an array of %i available maps from script\n", mapList.size());
|
||||
|
||||
hsq_newarray(sqvm, 0);
|
||||
|
||||
for (auto& it : mapList)
|
||||
{
|
||||
hsq_pushstring(sqvm, it.c_str(), -1);
|
||||
hsq_arrayappend(sqvm, -2);
|
||||
}
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ namespace SQNativeFunctions
|
||||
SQRESULT GetServerName(void* sqvm);
|
||||
SQRESULT GetServerPlaylist(void* sqvm);
|
||||
SQRESULT GetServerMap(void* sqvm);
|
||||
SQRESULT GetServerAmount(void* sqvm);
|
||||
SQRESULT GetServerCount(void* sqvm);
|
||||
SQRESULT GetSDKVersion(void* sqvm);
|
||||
SQRESULT GetPromoData(void* sqvm);
|
||||
SQRESULT SetEncKeyAndConnect(void* sqvm);
|
||||
@ -16,5 +16,6 @@ namespace SQNativeFunctions
|
||||
SQRESULT JoinPrivateServerFromMenu(void* sqvm);
|
||||
SQRESULT GetPrivateServerMessage(void* sqvm);
|
||||
SQRESULT ConnectToIPFromMenu(void* sqvm);
|
||||
SQRESULT GetAvailableMaps(void* sqvm);
|
||||
}
|
||||
}
|
@ -248,23 +248,28 @@ int HSQVM_NativeTest(void* sqvm)
|
||||
|
||||
void RegisterUIScriptFunctions(void* sqvm)
|
||||
{
|
||||
HSQVM_RegisterFunction(sqvm, "UINativeTest", "native ui function", "void", "", &HSQVM_NativeTest);
|
||||
//Server Browser Data
|
||||
HSQVM_RegisterFunction(sqvm, "GetServerName", "native ui function", "string", "int", &SQNativeFunctions::IBrowser::GetServerName);
|
||||
HSQVM_RegisterFunction(sqvm, "GetServerPlaylist", "native ui function", "string", "int", &SQNativeFunctions::IBrowser::GetServerPlaylist);
|
||||
HSQVM_RegisterFunction(sqvm, "GetServerMap", "native ui function", "string", "int", &SQNativeFunctions::IBrowser::GetServerMap);
|
||||
HSQVM_RegisterFunction(sqvm, "GetServerAmmount", "native ui function", "int", "", &SQNativeFunctions::IBrowser::GetServerAmount);
|
||||
#ifndef DEDICATED
|
||||
HSQVM_RegisterFunction(sqvm, "UINativeTest", "native ui test function", "void", "", &HSQVM_NativeTest);
|
||||
|
||||
//Main Menu Data
|
||||
HSQVM_RegisterFunction(sqvm, "GetSDKVersion", "native ui function", "string", "", &SQNativeFunctions::IBrowser::GetSDKVersion);
|
||||
HSQVM_RegisterFunction(sqvm, "GetPromoData", "native ui function", "string", "int", &SQNativeFunctions::IBrowser::GetPromoData);
|
||||
// functions for retrieving server browser data
|
||||
HSQVM_RegisterFunction(sqvm, "GetServerName", "get name of the server at the specified index of the server list", "string", "int", &SQNativeFunctions::IBrowser::GetServerName);
|
||||
HSQVM_RegisterFunction(sqvm, "GetServerPlaylist", "get playlist of the server at the specified index of the server list", "string", "int", &SQNativeFunctions::IBrowser::GetServerPlaylist);
|
||||
HSQVM_RegisterFunction(sqvm, "GetServerMap", "get map of the server at the specified index of the server list", "string", "int", &SQNativeFunctions::IBrowser::GetServerMap);
|
||||
HSQVM_RegisterFunction(sqvm, "GetServerCount", "get number of public servers", "int", "", &SQNativeFunctions::IBrowser::GetServerCount);
|
||||
|
||||
//Connecting To Servers
|
||||
HSQVM_RegisterFunction(sqvm, "CreateServer", "native ui function", "void", "string,string,string,string", &SQNativeFunctions::IBrowser::CreateServerFromMenu);
|
||||
HSQVM_RegisterFunction(sqvm, "SetEncKeyAndConnect", "native ui function", "void", "int", &SQNativeFunctions::IBrowser::SetEncKeyAndConnect);
|
||||
HSQVM_RegisterFunction(sqvm, "JoinPrivateServerFromMenu", "native ui function", "void", "string", &SQNativeFunctions::IBrowser::JoinPrivateServerFromMenu);
|
||||
HSQVM_RegisterFunction(sqvm, "GetPrivateServerMessage", "native ui function", "string", "string", &SQNativeFunctions::IBrowser::GetPrivateServerMessage);
|
||||
HSQVM_RegisterFunction(sqvm, "ConnectToIPFromMenu", "native ui function", "void", "string,string", &SQNativeFunctions::IBrowser::ConnectToIPFromMenu);
|
||||
// misc main menu functions
|
||||
HSQVM_RegisterFunction(sqvm, "GetSDKVersion", "get sdk version as a string", "string", "", &SQNativeFunctions::IBrowser::GetSDKVersion);
|
||||
HSQVM_RegisterFunction(sqvm, "GetPromoData", "get promo data for specified slot type", "string", "int", &SQNativeFunctions::IBrowser::GetPromoData);
|
||||
|
||||
// functions for connecting to servers
|
||||
HSQVM_RegisterFunction(sqvm, "CreateServer", "start server with the specified settings", "void", "string,string,string,int", &SQNativeFunctions::IBrowser::CreateServerFromMenu);
|
||||
HSQVM_RegisterFunction(sqvm, "SetEncKeyAndConnect", "set the encryption key to that of the specified server and connects to it", "void", "int", &SQNativeFunctions::IBrowser::SetEncKeyAndConnect);
|
||||
HSQVM_RegisterFunction(sqvm, "JoinPrivateServerFromMenu", "join private server by token", "void", "string", &SQNativeFunctions::IBrowser::JoinPrivateServerFromMenu);
|
||||
HSQVM_RegisterFunction(sqvm, "GetPrivateServerMessage", "get private server join status message", "string", "string", &SQNativeFunctions::IBrowser::GetPrivateServerMessage);
|
||||
HSQVM_RegisterFunction(sqvm, "ConnectToIPFromMenu", "join server by ip and encryption key", "void", "string,string", &SQNativeFunctions::IBrowser::ConnectToIPFromMenu);
|
||||
|
||||
HSQVM_RegisterFunction(sqvm, "GetAvailableMaps", "gets an array of all the available maps that can be used to host a server", "array<string>", "", &SQNativeFunctions::IBrowser::GetAvailableMaps);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RegisterClientScriptFunctions(void* sqvm)
|
||||
|
Loading…
x
Reference in New Issue
Block a user