Add server identification packet

This commit is contained in:
Tixx 2024-10-04 20:49:05 +02:00
parent 4f052a3e0a
commit 6aeb2eb736
3 changed files with 8 additions and 2 deletions

View File

@ -29,6 +29,7 @@ public:
//~THeartbeatThread();
void operator()() override;
static inline std::string lastCall = "";
private:
std::string GenerateCall();
std::string GetPlayers();

View File

@ -140,8 +140,7 @@ void THeartbeatThread::operator()() {
std::string THeartbeatThread::GenerateCall() {
std::stringstream Ret;
Ret << "uuid=" << Application::Settings.getAsString(Settings::Key::General_AuthKey)
<< "&players=" << mServer.ClientCount()
Ret << "players=" << mServer.ClientCount()
<< "&maxplayers=" << Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)
<< "&port=" << Application::Settings.getAsInt(Settings::Key::General_Port)
<< "&map=" << Application::Settings.getAsString(Settings::Key::General_Map)
@ -156,6 +155,8 @@ std::string THeartbeatThread::GenerateCall() {
<< "&modstotal=" << mResourceManager.ModsLoaded()
<< "&playerslist=" << GetPlayers()
<< "&desc=" << Application::Settings.getAsString(Settings::Key::General_Description);
lastCall = Ret.str();
Ret << "&uuid=" << Application::Settings.getAsString(Settings::Key::General_AuthKey);
return Ret.str();
}
THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& Server)

View File

@ -20,6 +20,7 @@
#include "Client.h"
#include "Common.h"
#include "LuaAPI.h"
#include "THeartbeatThread.h"
#include "TLuaEngine.h"
#include "TScopedTimer.h"
#include "nlohmann/json.hpp"
@ -246,6 +247,9 @@ void TNetwork::Identify(TConnection&& RawConnection) {
boost::system::error_code ec;
write(RawConnection.Socket, buffer("P"), ec);
return;
} else if (Code == 'I') {
boost::system::error_code ec;
write(RawConnection.Socket, buffer(THeartbeatThread::lastCall), ec);
} else {
beammp_errorf("Invalid code got in Identify: '{}'", Code);
}