aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/scriptserverbrowser.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-08-05 03:17:54 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-08-05 03:17:54 +0100
commit02e422166baa12bbdc8af8806376cb2340fef896 (patch)
tree0ec856650684f0ee6644446d8e865ad1f6ec8859 /NorthstarDedicatedTest/scriptserverbrowser.cpp
parentbf176fe728400b93295118e8d256c346c8c52d41 (diff)
downloadNorthstarLauncher-02e422166baa12bbdc8af8806376cb2340fef896.tar.gz
NorthstarLauncher-02e422166baa12bbdc8af8806376cb2340fef896.zip
add support for requesting server list from masterserver
Diffstat (limited to 'NorthstarDedicatedTest/scriptserverbrowser.cpp')
-rw-r--r--NorthstarDedicatedTest/scriptserverbrowser.cpp122
1 files changed, 91 insertions, 31 deletions
diff --git a/NorthstarDedicatedTest/scriptserverbrowser.cpp b/NorthstarDedicatedTest/scriptserverbrowser.cpp
index 2f1c95a4..7f7bd369 100644
--- a/NorthstarDedicatedTest/scriptserverbrowser.cpp
+++ b/NorthstarDedicatedTest/scriptserverbrowser.cpp
@@ -1,67 +1,114 @@
#include "pch.h"
#include "scriptserverbrowser.h"
#include "squirrel.h"
+#include "masterserver.h"
// functions for viewing server browser
-// bool function NSPollServerPage( int page )
-SQInteger SQ_PollServerPage(void* sqvm)
+// void NSRequestServerList()
+SQInteger SQ_RequestServerList(void* sqvm)
{
- SQInteger page = ClientSq_getinteger(sqvm, 1);
+ g_MasterServerManager->RequestServerList();
+ return 0;
+}
- ClientSq_pushbool(sqvm, true);
+// bool function NSIsRequestingServerList()
+SQInteger SQ_IsRequestingServerList(void* sqvm)
+{
+ ClientSq_pushbool(sqvm, g_MasterServerManager->m_scriptRequestingServerList);
return 1;
}
-// int function NSGetNumServersOnPage( int page )
-SQInteger SQ_GetNumServersOnPage(void* sqvm)
+// bool function NSMasterServerConnectionSuccessful()
+SQInteger SQ_MasterServerConnectionSuccessful(void* sqvm)
{
- SQInteger page = ClientSq_getinteger(sqvm, 1);
+ ClientSq_pushbool(sqvm, g_MasterServerManager->m_successfullyConnected);
+ return 1;
+}
- ClientSq_pushinteger(sqvm, 1);
+// int function NSGetServerCount()
+SQInteger SQ_GetServerCount(void* sqvm)
+{
+ ClientSq_pushinteger(sqvm, g_MasterServerManager->m_remoteServers.size());
return 1;
}
-// string function NSGetServerName( int page, int serverIndex )
+// string function NSGetServerName( int serverIndex )
SQInteger SQ_GetServerName(void* sqvm)
{
- SQInteger page = ClientSq_getinteger(sqvm, 1);
- SQInteger serverIndex = ClientSq_getinteger(sqvm, 2);
+ SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
+
+ if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
+ {
+ spdlog::warn("Tried to get name of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
+ return 0;
+ }
+
+ auto iterator = g_MasterServerManager->m_remoteServers.begin();
+ std::advance(iterator, serverIndex);
- ClientSq_pushstring(sqvm, "cool", -1);
+ ClientSq_pushstring(sqvm, iterator->name, -1);
return 1;
}
-// string function NSGetServerMap( int page, int serverIndex )
+// string function NSGetServerMap( int serverIndex )
SQInteger SQ_GetServerMap(void* sqvm)
{
- SQInteger page = ClientSq_getinteger(sqvm, 1);
- SQInteger serverIndex = ClientSq_getinteger(sqvm, 2);
+ SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
- ClientSq_pushstring(sqvm, "mp_thaw", -1);
+ if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
+ {
+ spdlog::warn("Tried to get map of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
+ return 0;
+ }
+
+ auto iterator = g_MasterServerManager->m_remoteServers.begin();
+ std::advance(iterator, serverIndex);
+
+ ClientSq_pushstring(sqvm, iterator->map, -1);
return 1;
}
-// string function NSGetServerMode( int page, int serverIndex )
-SQInteger SQ_GetServerMode(void* sqvm)
+// string function NSGetServerPlaylist( int serverIndex )
+SQInteger SQ_GetServerPlaylist(void* sqvm)
{
- SQInteger page = ClientSq_getinteger(sqvm, 1);
- SQInteger serverIndex = ClientSq_getinteger(sqvm, 2);
+ SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
+
+ if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
+ {
+ spdlog::warn("Tried to get playlist of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
+ return 0;
+ }
+
+ auto iterator = g_MasterServerManager->m_remoteServers.begin();
+ std::advance(iterator, serverIndex);
- ClientSq_pushstring(sqvm, "ffa", -1);
+ ClientSq_pushstring(sqvm, iterator->playlist, -1);
return 1;
}
-// string function NSGetServerID( int page, int serverIndex )
+// string function NSGetServerID( int serverIndex )
SQInteger SQ_GetServerID(void* sqvm)
{
+ SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
- return 0;
+ if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
+ {
+ spdlog::warn("Tried to get id of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
+ return 0;
+ }
+
+ auto iterator = g_MasterServerManager->m_remoteServers.begin();
+ std::advance(iterator, serverIndex);
+
+ ClientSq_pushstring(sqvm, iterator->id, -1);
+ return 1;
}
-// void function NSResetRecievedServers()
-SQInteger SQ_ResetRecievedServers(void* sqvm)
+// void function NSClearRecievedServerList()
+SQInteger SQ_ClearRecievedServerList(void* sqvm)
{
+ g_MasterServerManager->ClearServerList();
return 0;
}
@@ -94,10 +141,23 @@ SQInteger SQ_TryGetAuthedServerToken(void* sqvm)
void InitialiseScriptServerBrowser(HMODULE baseAddress)
{
- g_UISquirrelManager->AddFuncRegistration("bool", "NSPollServerPage", "int page", "", SQ_PollServerPage);
- g_UISquirrelManager->AddFuncRegistration("int", "NSGetNumServersOnPage", "int page", "", SQ_GetNumServersOnPage);
- g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerName", "int page, int serverIndex", "", SQ_GetServerName);
- g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerMap", "int page, int serverIndex", "", SQ_GetServerMap);
- g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerMode", "int page, int serverIndex", "", SQ_GetServerMode);
- g_UISquirrelManager->AddFuncRegistration("void", "NSResetRecievedServers", "", "", SQ_ResetRecievedServers);
+ g_UISquirrelManager->AddFuncRegistration("void", "NSRequestServerList", "", "", SQ_RequestServerList);
+ g_UISquirrelManager->AddFuncRegistration("bool", "NSIsRequestingServerList", "", "", SQ_IsRequestingServerList);
+ g_UISquirrelManager->AddFuncRegistration("bool", "NSMasterServerConnectionSuccessful", "", "", SQ_MasterServerConnectionSuccessful);
+ g_UISquirrelManager->AddFuncRegistration("int", "NSGetServerCount", "", "", SQ_GetServerCount);
+ g_UISquirrelManager->AddFuncRegistration("void", "NSClearRecievedServerList", "", "", SQ_ClearRecievedServerList);
+
+ g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerName", "int serverIndex", "", SQ_GetServerName);
+ g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerMap", "int serverIndex", "", SQ_GetServerMap);
+ g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerPlaylist", "int serverIndex", "", SQ_GetServerPlaylist);
+ g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerID", "int serverIndex", "", SQ_GetServerID);
+
+ //g_UISquirrelManager->AddFuncRegistration("bool", "NSPollServerPage", "int page", "", SQ_PollServerPage);
+ //g_UISquirrelManager->AddFuncRegistration("int", "NSGetNumServersOnPage", "int page", "", SQ_GetNumServersOnPage);
+ //g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerName", "int page, int serverIndex", "", SQ_GetServerName);
+ //g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerMap", "int page, int serverIndex", "", SQ_GetServerMap);
+ //g_UISquirrelManager->AddFuncRegistration("string", "NSGetServerMode", "int page, int serverIndex", "", SQ_GetServerMode);
+ //g_UISquirrelManager->AddFuncRegistration("void", "NSResetRecievedServers", "", "", SQ_ResetRecievedServers);
+ //
+ //g_UISquirrelManager->AddFuncRegistration("string", "NSTryGetAuthedServerToken", "", "", SQ_TryGetAuthedServerToken);
} \ No newline at end of file