Stub placeholder for ServerStatus

This commit is contained in:
DankParrot 2020-07-24 20:44:00 -07:00
parent 2b72aa6335
commit 0a5017d023
4 changed files with 54 additions and 4 deletions

View File

@ -1,10 +1,16 @@
#include "DedicatedServer.h" #include "DedicatedServer.h"
#include "config/ServerProperties.h"
namespace Feather namespace Feather
{ {
DedicatedServer::DedicatedServer(uint16_t port) DedicatedServer::DedicatedServer(ServerProperties* properties) :
: m_listener(port) m_properties(properties),
m_listener(properties->serverPort.GetValue()),
m_status()
{ {
m_status.descriptionText = properties->motd.GetValue();
m_status.maxPlayers = properties->maxPlayers.GetValue();
while (1) while (1)
{ {

View File

@ -1,15 +1,21 @@
#pragma once #pragma once
#include "network/TCPListener.h" #include "network/TCPListener.h"
#include "network/ServerStatus.h"
namespace Feather namespace Feather
{ {
class ServerProperties;
class DedicatedServer class DedicatedServer
{ {
public: public:
DedicatedServer(uint16_t port); DedicatedServer(ServerProperties* properties);
~DedicatedServer(); ~DedicatedServer();
private: private:
ServerProperties* m_properties;
Network::TCPListener m_listener; Network::TCPListener m_listener;
Network::ServerStatus m_status;
}; };
} }

View File

@ -10,7 +10,7 @@ int main()
properties.Save(); properties.Save();
printf("Starting server on port %d\n", properties.serverPort.GetValue()); printf("Starting server on port %d\n", properties.serverPort.GetValue());
auto server = DedicatedServer(properties.serverPort.GetValue()); auto server = DedicatedServer(&properties);
return 1; return 1;
} }

View File

@ -0,0 +1,38 @@
#pragma once
#include <string>
#include <sstream>
using string = std::string;
using stringstream = std::stringstream;
namespace Feather::Network
{
class ServerStatus
{
public:
// Version
string versionName = "1.16.1";
int protocol = 736;
// Players
int maxPlayers;
int numPlayers;
// Description
string descriptionText = "";
string GetServerStatusJSON()
{
// TODO: PLACEHOLDER for real JSON
stringstream j;
j << "{";
j << "\"version\":{\"name\":\"" << versionName << "\",\"protocol\":" << protocol << "},";
j << "\"players\":{\"max\":" << maxPlayers << ",\"online\":" << numPlayers << ",\"sample\":[]},";
j << "\"description\": {\"text\":\"" << descriptionText << "\"}";
j << "}";
return j.str();
}
};
}