mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Light squirrel code cleanup
* Renamed 'SetEncKeyAndConnect' to 'ConnectToListedServer'. * Renamed 'JoinPrivateServerFromMenu' to 'ConnectToHiddenServer'. * Renamed 'GetPrivateServerMessage' to 'GetHiddenServerConnectStatus'. * Cache game server ref in 'ConnectToListedServer'.
This commit is contained in:
parent
ab75233fa1
commit
29ca97f6b0
@ -400,34 +400,12 @@ namespace VSquirrel
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: set netchannel encryption key and connect to server
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT SetEncKeyAndConnect(HSQUIRRELVM v)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
|
||||
|
||||
SQInteger iServer = sq_getinteger(v, 1);
|
||||
SQInteger iCount = static_cast<SQInteger>(g_pServerListManager->m_vServerList.size());
|
||||
|
||||
if (iServer >= iCount)
|
||||
{
|
||||
v_SQVM_RaiseError(v, "Index must be less than %i.\n", iCount);
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
g_pServerListManager->ConnectToServer(g_pServerListManager->m_vServerList[iServer].m_svIpAddress,
|
||||
g_pServerListManager->m_vServerList[iServer].m_svGamePort,
|
||||
g_pServerListManager->m_vServerList[iServer].m_svEncryptionKey);
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: create server via native serverbrowser entries
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT CreateServerFromMenu(HSQUIRRELVM v)
|
||||
SQRESULT CreateServer(HSQUIRRELVM v)
|
||||
{
|
||||
#ifndef CLIENT_DLL
|
||||
string svServerName = sq_getstring(v, 1);
|
||||
string svServerDescription = sq_getstring(v, 2);
|
||||
string svServerMapName = sq_getstring(v, 3);
|
||||
@ -449,13 +427,58 @@ namespace VSquirrel
|
||||
// Launch server.
|
||||
g_pServerListManager->LaunchServer();
|
||||
|
||||
return SQ_OK;
|
||||
#else
|
||||
v_SQVM_RaiseError(v, "\"%s\" is not supported for client builds.\n", "CreateServer");
|
||||
return SQ_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: connect to server from native server browser entries
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT ConnectToServer(HSQUIRRELVM v)
|
||||
{
|
||||
string svIpAddr = sq_getstring(v, 1);
|
||||
string svEncKey = sq_getstring(v, 2);
|
||||
|
||||
if (svIpAddr.empty() || svEncKey.empty())
|
||||
return SQ_OK;
|
||||
|
||||
DevMsg(eDLL_T::UI, "Connecting to server with ip address '%s' and encryption key '%s'\n", svIpAddr.c_str(), svEncKey.c_str());
|
||||
g_pServerListManager->ConnectToServer(svIpAddr, svEncKey);
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: set netchannel encryption key and connect to server
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT ConnectToListedServer(HSQUIRRELVM v)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
|
||||
|
||||
SQInteger iServer = sq_getinteger(v, 1);
|
||||
SQInteger iCount = static_cast<SQInteger>(g_pServerListManager->m_vServerList.size());
|
||||
|
||||
if (iServer >= iCount)
|
||||
{
|
||||
v_SQVM_RaiseError(v, "Index must be less than %i.\n", iCount);
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
const NetGameServer_t& gameServer = g_pServerListManager->m_vServerList[iServer];
|
||||
|
||||
g_pServerListManager->ConnectToServer(gameServer.m_svIpAddress, gameServer.m_svGamePort,
|
||||
gameServer.m_svEncryptionKey);
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: request token from pylon and join server with result.
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT JoinPrivateServerFromMenu(HSQUIRRELVM v)
|
||||
SQRESULT ConnectToHiddenServer(HSQUIRRELVM v)
|
||||
{
|
||||
string svHiddenServerRequestMessage;
|
||||
string svToken = sq_getstring(v, 1);
|
||||
@ -473,7 +496,7 @@ namespace VSquirrel
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: get response from private server request
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT GetPrivateServerMessage(HSQUIRRELVM v)
|
||||
SQRESULT GetHiddenServerConnectStatus(HSQUIRRELVM v)
|
||||
{
|
||||
string svHiddenServerRequestMessage;
|
||||
string svToken = sq_getstring(v, 1);
|
||||
@ -482,34 +505,15 @@ namespace VSquirrel
|
||||
bool result = g_pMasterServer->GetServerByToken(serverListing, svHiddenServerRequestMessage, svToken); // Send token connect request.
|
||||
if (!serverListing.m_svHostName.empty())
|
||||
{
|
||||
svHiddenServerRequestMessage = "Found Server: " + serverListing.m_svHostName;
|
||||
svHiddenServerRequestMessage = fmt::format("Found server: {:s}", serverListing.m_svHostName);
|
||||
sq_pushstring(v, svHiddenServerRequestMessage.c_str(), -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
svHiddenServerRequestMessage = "Error: Server Not Found";
|
||||
svHiddenServerRequestMessage = "Server not found";
|
||||
sq_pushstring(v, svHiddenServerRequestMessage.c_str(), -1);
|
||||
}
|
||||
|
||||
DevMsg(eDLL_T::UI, "GetPrivateServeMessage response: %s\n", svHiddenServerRequestMessage.c_str());
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: connect to server from native server browser entries
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT ConnectToIPFromMenu(HSQUIRRELVM v)
|
||||
{
|
||||
string svIpAddr = sq_getstring(v, 1);
|
||||
string svEncKey = sq_getstring(v, 2);
|
||||
|
||||
if (svIpAddr.empty() || svEncKey.empty())
|
||||
return SQ_OK;
|
||||
|
||||
DevMsg(eDLL_T::UI, "Connecting to server with ip address '%s' and encryption key '%s'\n", svIpAddr.c_str(), svEncKey.c_str());
|
||||
g_pServerListManager->ConnectToServer(svIpAddr, svEncKey);
|
||||
|
||||
return SQ_OK;
|
||||
}
|
||||
}
|
||||
|
@ -53,11 +53,11 @@ namespace VSquirrel
|
||||
SQRESULT GetServerMaxPlayers(HSQUIRRELVM v);
|
||||
SQRESULT GetServerCount(HSQUIRRELVM v);
|
||||
SQRESULT GetPromoData(HSQUIRRELVM v);
|
||||
SQRESULT SetEncKeyAndConnect(HSQUIRRELVM v);
|
||||
SQRESULT CreateServerFromMenu(HSQUIRRELVM v);
|
||||
SQRESULT JoinPrivateServerFromMenu(HSQUIRRELVM v);
|
||||
SQRESULT GetPrivateServerMessage(HSQUIRRELVM v);
|
||||
SQRESULT ConnectToIPFromMenu(HSQUIRRELVM v);
|
||||
SQRESULT ConnectToListedServer(HSQUIRRELVM v);
|
||||
SQRESULT CreateServer(HSQUIRRELVM v);
|
||||
SQRESULT ConnectToHiddenServer(HSQUIRRELVM v);
|
||||
SQRESULT GetHiddenServerConnectStatus(HSQUIRRELVM v);
|
||||
SQRESULT ConnectToServer(HSQUIRRELVM v);
|
||||
}
|
||||
#endif // !DEDICATED
|
||||
}
|
||||
|
@ -102,6 +102,7 @@ void Script_RegisterClientFunctions(CSquirrelVM* s)
|
||||
void Script_RegisterUIFunctions(CSquirrelVM* s)
|
||||
{
|
||||
Script_RegisterFunction(s, "SDKNativeTest", "Script_SDKNativeTest", "Native UI test function", "void", "", &VSquirrel::SHARED::SDKNativeTest);
|
||||
Script_RegisterFunction(s, "GetSDKVersion", "Script_GetSDKVersion", "Gets the SDK version as a string", "string", "", &VSquirrel::SHARED::GetSDKVersion);
|
||||
|
||||
Script_RegisterFunction(s, "RefreshServerList", "Script_RefreshServerList", "Refreshes the public server list and returns the count", "int", "", &VSquirrel::UI::RefreshServerCount);
|
||||
|
||||
@ -115,15 +116,14 @@ void Script_RegisterUIFunctions(CSquirrelVM* s)
|
||||
Script_RegisterFunction(s, "GetServerCount", "Script_GetServerCount", "Gets the number of public servers", "int", "", &VSquirrel::UI::GetServerCount);
|
||||
|
||||
// Misc main menu functions
|
||||
Script_RegisterFunction(s, "GetSDKVersion", "Script_GetSDKVersion", "Gets the SDK version as a string", "string", "", &VSquirrel::SHARED::GetSDKVersion);
|
||||
Script_RegisterFunction(s, "GetPromoData", "Script_GetPromoData", "Gets promo data for specified slot type", "string", "int", &VSquirrel::UI::GetPromoData);
|
||||
|
||||
// Functions for connecting to servers
|
||||
Script_RegisterFunction(s, "CreateServer", "Script_CreateServer", "Start server with the specified settings", "void", "string, string, string, string, int", &VSquirrel::UI::CreateServerFromMenu);
|
||||
Script_RegisterFunction(s, "SetEncKeyAndConnect", "Script_SetEncKeyAndConnect", "Set the encryption key to that of the specified server and connects to it", "void", "int", &VSquirrel::UI::SetEncKeyAndConnect);
|
||||
Script_RegisterFunction(s, "JoinPrivateServerFromMenu", "Script_JoinPrivateServerFromMenu", "Joins private server by token", "void", "string", &VSquirrel::UI::JoinPrivateServerFromMenu);
|
||||
Script_RegisterFunction(s, "GetPrivateServerMessage", "Script_GetPrivateServerMessage", "Gets private server join status message", "string", "string", &VSquirrel::UI::GetPrivateServerMessage);
|
||||
Script_RegisterFunction(s, "ConnectToIPFromMenu", "Script_ConnectToIPFromMenu", "Joins server by ip address and encryption key", "void", "string, string", &VSquirrel::UI::ConnectToIPFromMenu);
|
||||
Script_RegisterFunction(s, "CreateServer", "Script_CreateServer", "Start server with the specified settings", "void", "string, string, string, string, int", &VSquirrel::UI::CreateServer);
|
||||
Script_RegisterFunction(s, "ConnectToServer", "Script_ConnectToServer", "Joins server by ip address and encryption key", "void", "string, string", &VSquirrel::UI::ConnectToServer);
|
||||
Script_RegisterFunction(s, "ConnectToListedServer", "Script_ConnectToListedServer", "Joins listed server by index", "void", "int", &VSquirrel::UI::ConnectToListedServer);
|
||||
Script_RegisterFunction(s, "ConnectToHiddenServer", "Script_ConnectToHiddenServer", "Joins hidden server by token", "void", "string", &VSquirrel::UI::ConnectToHiddenServer);
|
||||
Script_RegisterFunction(s, "GetHiddenServerConnectStatus", "Script_GetHiddenServerConnectStatus", "Gets hidden server join status message", "string", "string", &VSquirrel::UI::GetHiddenServerConnectStatus);
|
||||
|
||||
Script_RegisterFunction(s, "GetAvailableMaps", "Script_GetAvailableMaps", "Gets an array of all available maps", "array< string >", "", &VSquirrel::SHARED::GetAvailableMaps);
|
||||
Script_RegisterFunction(s, "GetAvailablePlaylists", "Script_GetAvailablePlaylists", "Gets an array of all available playlists", "array< string >", "", &VSquirrel::SHARED::GetAvailablePlaylists);
|
||||
|
Loading…
x
Reference in New Issue
Block a user