diff --git a/src/client/ClientServices.cpp b/src/client/ClientServices.cpp index 737ff04..1bb36a7 100644 --- a/src/client/ClientServices.cpp +++ b/src/client/ClientServices.cpp @@ -84,6 +84,10 @@ const char* ClientServices::GetSelectedRealmName() { return ClientServices::s_realmNameVar->GetString(); } +const REALM_INFO* ClientServices::GetSelectedRealm() { + return &ClientServices::s_selectRealmInfo; +} + void ClientServices::Initialize() { if (!g_clientConnection) { auto adapterMem = SMemAlloc(sizeof(ClientRealmResponseAdapter), __FILE__, __LINE__, 0x0); diff --git a/src/client/ClientServices.hpp b/src/client/ClientServices.hpp index af9befa..7b80b60 100644 --- a/src/client/ClientServices.hpp +++ b/src/client/ClientServices.hpp @@ -27,6 +27,7 @@ class ClientServices : public LoginResponse { static ClientServices* GetInstance(); static REALM_INFO* GetRealmInfoByIndex(int32_t index); static const char* GetSelectedRealmName(); + static const REALM_INFO* GetSelectedRealm(); static void Initialize(); static Login* LoginConnection(); static void Logon(const char* accountName, const char* password); diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 353be13..a4cadf6 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -12,6 +12,7 @@ target_include_directories(ui target_link_libraries(ui PRIVATE client + db event glue gx diff --git a/src/ui/ScriptFunctionsGlueScriptEvents.cpp b/src/ui/ScriptFunctionsGlueScriptEvents.cpp index 86765a8..574a069 100644 --- a/src/ui/ScriptFunctionsGlueScriptEvents.cpp +++ b/src/ui/ScriptFunctionsGlueScriptEvents.cpp @@ -1,6 +1,7 @@ #include "ui/ScriptFunctions.hpp" #include "client/Client.hpp" #include "client/ClientServices.hpp" +#include "db/Db.hpp" #include "glue/CGlueMgr.hpp" #include "gx/Coordinate.hpp" #include "net/connection/ClientConnection.hpp" @@ -204,7 +205,54 @@ int32_t Script_StatusDialogClick(lua_State* L) { } int32_t Script_GetServerName(lua_State* L) { - WHOA_UNIMPLEMENTED(); + auto selectedRealmName = ClientServices::GetSelectedRealmName(); + auto selectedRealm = ClientServices::GetSelectedRealm(); + + auto pvp = false; + auto rp = false; + + // default down to true: if realm config isn't found, consider realm down + auto down = true; + + if (selectedRealm) { + for (int32_t i = 0; i < g_cfg_ConfigsDB.m_numRecords; i++) { + auto config = g_cfg_ConfigsDB.GetRecordByIndex(i); + + if (config->m_realmType == selectedRealm->type) { + pvp = config->m_playerKillingAllowed != 0; + rp = config->m_roleplaying != 0; + down = selectedRealm->flags & 0x2; + + break; + } + } + } + + // name + lua_pushstring(L, selectedRealmName); + + // pvp + if (pvp) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + // rp + if (rp) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + // down + if (down) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + return 4; } int32_t Script_DisconnectFromServer(lua_State* L) {