|
|
@ -6,6 +6,7 @@
|
|
|
|
#include <Getche.h>
|
|
|
|
#include <Getche.h>
|
|
|
|
#include <sstream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <RakPeerInterface.h>
|
|
|
|
#include <RakPeerInterface.h>
|
|
|
|
#include "MasterClient.hpp"
|
|
|
|
#include "MasterClient.hpp"
|
|
|
|
#include <components/openmw-mp/Log.hpp>
|
|
|
|
#include <components/openmw-mp/Log.hpp>
|
|
|
@ -19,12 +20,10 @@ MasterClient::MasterClient(std::string queryAddr, unsigned short queryPort, std:
|
|
|
|
unsigned short serverPort) : queryAddr(queryAddr), queryPort(queryPort),
|
|
|
|
unsigned short serverPort) : queryAddr(queryAddr), queryPort(queryPort),
|
|
|
|
serverAddr(serverAddr), serverPort(serverPort)
|
|
|
|
serverAddr(serverAddr), serverPort(serverPort)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
httpConnection = RakNet::HTTPConnection2::GetInstance();
|
|
|
|
|
|
|
|
tcpInterface.Start(0, 64);
|
|
|
|
|
|
|
|
tcpInterface.AttachPlugin(httpConnection);
|
|
|
|
|
|
|
|
players = 0;
|
|
|
|
players = 0;
|
|
|
|
maxPlayers = 0;
|
|
|
|
maxPlayers = 0;
|
|
|
|
motd = "";
|
|
|
|
hostname = "";
|
|
|
|
|
|
|
|
modname = "";
|
|
|
|
timeout = 1000; // every 1 seconds
|
|
|
|
timeout = 1000; // every 1 seconds
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -42,14 +41,22 @@ void MasterClient::SetMaxPlayers(unsigned pl)
|
|
|
|
mutexData.unlock();
|
|
|
|
mutexData.unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MasterClient::SetMOTD(std::string &motd)
|
|
|
|
void MasterClient::SetHostname(std::string hostname)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mutexData.lock();
|
|
|
|
mutexData.lock();
|
|
|
|
this->motd = motd.substr(0, 200);
|
|
|
|
this->hostname = hostname.substr(0, 200);
|
|
|
|
mutexData.unlock();
|
|
|
|
mutexData.unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RakNet::RakString MasterClient::Send(std::string motd, unsigned players, unsigned maxPlayers, bool update)
|
|
|
|
void MasterClient::SetModname(std::string modname)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mutexData.lock();
|
|
|
|
|
|
|
|
this->modname = modname.substr(0, 200);
|
|
|
|
|
|
|
|
mutexData.unlock();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RakNet::RakString
|
|
|
|
|
|
|
|
MasterClient::Send(std::string hostname, std::string modname, unsigned maxPlayers, bool update, unsigned players)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/*static unsigned short oldServerPort, oldQueryPort;
|
|
|
|
/*static unsigned short oldServerPort, oldQueryPort;
|
|
|
|
static string oldMotd;
|
|
|
|
static string oldMotd;
|
|
|
@ -59,7 +66,8 @@ RakNet::RakString MasterClient::Send(std::string motd, unsigned players, unsigne
|
|
|
|
sstr << "{";
|
|
|
|
sstr << "{";
|
|
|
|
sstr << "\"port\": " << serverPort << ", ";
|
|
|
|
sstr << "\"port\": " << serverPort << ", ";
|
|
|
|
sstr << "\"query_port\": " << queryPort << ", ";
|
|
|
|
sstr << "\"query_port\": " << queryPort << ", ";
|
|
|
|
sstr << "\"motd\": \"" << motd << "\", ";
|
|
|
|
sstr << "\"hostname\": \"" << hostname.c_str() << "\", ";
|
|
|
|
|
|
|
|
sstr << "\"hostname\": \"" << modname.c_str() << "\", ";
|
|
|
|
sstr << "\"players\": " << players << ", ";
|
|
|
|
sstr << "\"players\": " << players << ", ";
|
|
|
|
sstr << "\"max_players\": " << maxPlayers;
|
|
|
|
sstr << "\"max_players\": " << maxPlayers;
|
|
|
|
sstr << "}";
|
|
|
|
sstr << "}";
|
|
|
@ -126,7 +134,12 @@ RakNet::RakString MasterClient::Send(std::string motd, unsigned players, unsigne
|
|
|
|
void MasterClient::Update()
|
|
|
|
void MasterClient::Update()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
assert(!sRun);
|
|
|
|
assert(!sRun);
|
|
|
|
RakNet::RakString response = Send(motd, players, maxPlayers, false);
|
|
|
|
|
|
|
|
|
|
|
|
httpConnection = RakNet::HTTPConnection2::GetInstance();
|
|
|
|
|
|
|
|
tcpInterface.Start(0, 64);
|
|
|
|
|
|
|
|
tcpInterface.AttachPlugin(httpConnection);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RakNet::RakString response = Send(hostname, std::__cxx11::string(), maxPlayers, false, players);
|
|
|
|
bool update = true;
|
|
|
|
bool update = true;
|
|
|
|
sRun = true;
|
|
|
|
sRun = true;
|
|
|
|
while (sRun)
|
|
|
|
while (sRun)
|
|
|
@ -151,15 +164,22 @@ void MasterClient::Update()
|
|
|
|
RakSleep(timeout);
|
|
|
|
RakSleep(timeout);
|
|
|
|
;
|
|
|
|
;
|
|
|
|
players = mwmp::Networking::get().numberOfConnections();
|
|
|
|
players = mwmp::Networking::get().numberOfConnections();
|
|
|
|
response = Send(motd, players, maxPlayers, update);
|
|
|
|
response = Send(hostname, std::__cxx11::string(), maxPlayers, update, players);
|
|
|
|
update = true;
|
|
|
|
update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MasterClient::Start()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
thrQuery = thread(&MasterClient::Update, this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MasterClient::Stop()
|
|
|
|
void MasterClient::Stop()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sRun = false;
|
|
|
|
sRun = false;
|
|
|
|
|
|
|
|
if(thrQuery.joinable())
|
|
|
|
|
|
|
|
thrQuery.join();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MasterClient::SetUpdateRate(unsigned int rate)
|
|
|
|
void MasterClient::SetUpdateRate(unsigned int rate)
|
|
|
@ -169,4 +189,4 @@ void MasterClient::SetUpdateRate(unsigned int rate)
|
|
|
|
else if (timeout > max_rate)
|
|
|
|
else if (timeout > max_rate)
|
|
|
|
timeout = max_rate;
|
|
|
|
timeout = max_rate;
|
|
|
|
timeout = rate;
|
|
|
|
timeout = rate;
|
|
|
|
}
|
|
|
|
}
|