Skip to content

Commit 0a14972

Browse files
committed
Add server-side getServerIpFromMasterServer
1 parent 72ee8c0 commit 0a14972

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

Server/mods/deathmatch/logic/luadefs/CLuaGenericDefs.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
#include "CLuaGenericDefs.h"
1313
#include "CStaticFunctionDefinitions.h"
1414
#include "CScriptArgReader.h"
15+
#include "CMasterServerAnnouncer.h"
16+
17+
static auto GetServerIpFromMasterServer() -> std::string
18+
{
19+
return g_pGame->GetMasterServerAnnouncer()->GetRemoteAddress();
20+
}
1521

1622
void CLuaGenericDefs::LoadFunctions()
1723
{
@@ -24,6 +30,7 @@ void CLuaGenericDefs::LoadFunctions()
2430
{"outputConsole", ArgumentParserWarn<false, OutputConsole>},
2531
{"outputDebugString", ArgumentParserWarn<false, OutputScriptDebugLog>},
2632
{"outputServerLog", ArgumentParserWarn<false, OutputServerLog>},
33+
{"getServerIpFromMasterServer", ArgumentParser<GetServerIpFromMasterServer>},
2734
{"getServerName", ArgumentParserWarn<nullptr, GetServerName>},
2835
{"getServerHttpPort", ArgumentParserWarn<nullptr, GetServerHttpPort>},
2936
{"getServerPassword", ArgumentParserWarn<nullptr, GetServerPassword>},

Server/mods/deathmatch/utils/CMasterServerAnnouncer.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#pragma once
1212

13+
#include "ASE.h"
1314
#include "version.h"
1415

1516
struct SMasterServerDefinition
@@ -129,10 +130,15 @@ class CMasterServer : public CRefCountable
129130
if (m_Stage < ANNOUNCE_STAGE_REMINDER)
130131
{
131132
m_Stage = ANNOUNCE_STAGE_REMINDER;
133+
134+
CArgMap argMap;
135+
argMap.SetFromString(result.pData);
136+
137+
if (result.iErrorCode == 200)
138+
m_remoteAddress = argMap.Get("remote_addr");
139+
132140
if (!m_Definition.bHideSuccess)
133141
{
134-
CArgMap argMap;
135-
argMap.SetFromString(result.pData);
136142
SString strOkMessage = argMap.Get("ok_message");
137143

138144
// Log successful initial announcement
@@ -178,6 +184,9 @@ class CMasterServer : public CRefCountable
178184

179185
const SMasterServerDefinition& GetDefinition() const { return m_Definition; }
180186

187+
bool HasRemoteAddress() const noexcept { return !m_remoteAddress.empty(); }
188+
const std::string& GetRemoteAddress() const noexcept { return m_remoteAddress; }
189+
181190
//
182191
// Get http downloader used for master server comms etc.
183192
//
@@ -192,6 +201,7 @@ class CMasterServer : public CRefCountable
192201
long long m_llLastAnnounceTime;
193202
long long m_llLastPushTime;
194203
const SMasterServerDefinition m_Definition;
204+
std::string m_remoteAddress;
195205
};
196206

197207
////////////////////////////////////////////////////////////////////
@@ -270,6 +280,21 @@ class CMasterServerAnnouncer
270280
}
271281
}
272282

283+
/*
284+
* @brief Get remote address of the first master server that has it.
285+
*/
286+
const std::string& GetRemoteAddress() const noexcept
287+
{
288+
for (CMasterServer* masterServer : m_MasterServerList)
289+
{
290+
if (masterServer->HasRemoteAddress())
291+
return masterServer->GetRemoteAddress();
292+
}
293+
294+
static std::string empty;
295+
return empty;
296+
}
297+
273298
protected:
274299
std::vector<CMasterServer*> m_MasterServerList;
275300
};

0 commit comments

Comments
 (0)