-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
235 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "pingpong.h" | ||
|
||
void PingPongPacket::write(IStream *stream) | ||
{ | ||
stream->writeLong(payload); | ||
} | ||
|
||
void PingPongPacket::read(IStream *stream) | ||
{ | ||
payload = stream->readLong(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @file pingpong.h | ||
* @author Mathieu Cayeux | ||
* @brief The file containing logic for pinging the server | ||
* @version 1.0 | ||
* @date 2023-06-13 | ||
* | ||
* @copyright Copyright (c) 2023 | ||
* | ||
*/ | ||
|
||
#ifndef MINESERVER_PINGPONG_H | ||
#define MINESERVER_PINGPONG_H | ||
|
||
#include <net/packet.h> | ||
|
||
/** | ||
* @brief The Ping Pong Packet | ||
* | ||
* Packet for detecting the ping between | ||
* the client and the server. | ||
*/ | ||
class PingPongPacket : public IPacket | ||
{ | ||
protected: | ||
/** | ||
* @brief Write Packet Data | ||
* | ||
* Writes back the payload obtained | ||
* @param stream the stream to write to | ||
*/ | ||
void write(IStream *stream) override; | ||
|
||
public: | ||
/** | ||
* @brief Construct a new Server List Packet object | ||
* | ||
*/ | ||
PingPongPacket() : IPacket(0x01), payload(0) {} | ||
/** | ||
* @brief Destroy the Server List Packet object | ||
* | ||
*/ | ||
~PingPongPacket() = default; | ||
|
||
long payload; | ||
|
||
/** | ||
* @brief Read Packet Data | ||
* | ||
* Reads the payload from the client | ||
* @param stream the stream to read from | ||
*/ | ||
void read(IStream *stream) override; | ||
}; | ||
|
||
#endif // MINESERVER_PINGPONG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "serverlist.h" | ||
#include <rapidjson/document.h> | ||
#include <rapidjson/stringbuffer.h> | ||
#include <rapidjson/writer.h> | ||
#include <utils/config.h> | ||
#include <utils/logger.h> | ||
|
||
void ServerListPacket::write(IStream *stream) | ||
{ | ||
rapidjson::Document document; | ||
document.SetObject(); | ||
|
||
auto &alloc = document.GetAllocator(); | ||
|
||
rapidjson::Value version(rapidjson::kObjectType); | ||
version.AddMember("name", MC_VERSION_NAME, alloc); | ||
version.AddMember("protocol", MC_VERSION_NUMBER, alloc); | ||
document.AddMember("version", version, alloc); | ||
|
||
rapidjson::Value players(rapidjson::kObjectType); | ||
players.AddMember("max", Config::inst()->MAX_PLAYERS.getValue(), alloc); | ||
// TODO Display actual number of connected players with sample | ||
players.AddMember("online", 0, alloc); | ||
// players.AddMember("sample", rapidjson::Value(rapidjson::kArrayType), alloc); | ||
document.AddMember("players", players, alloc); | ||
|
||
rapidjson::Value description(rapidjson::kObjectType); | ||
Config::inst()->MOTD.getValue().save(description, alloc); | ||
document.AddMember("description", description, alloc); | ||
|
||
// TODO Add favicon in base64 with prepending "data:image/png;base64," | ||
// rapidjson::Value favicon(rapidjson::kStringType); | ||
// --- load the favicon from config --- | ||
// document.AddMember("favicon", favicon, alloc); | ||
|
||
rapidjson::StringBuffer buffer; | ||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); | ||
document.Accept(writer); | ||
|
||
stream->writeString(std::string(buffer.GetString(), buffer.GetSize())); | ||
} | ||
|
||
void ServerListPacket::read(IStream *stream) | ||
{ | ||
/* Nothing wrong if you call it but just unecessary bloat */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @file serverlist.h | ||
* @author Mathieu Cayeux | ||
* @brief The file containing packet logic for server list | ||
* @version 1.0 | ||
* @date 2023-06-13 | ||
* | ||
* @copyright Copyright (c) 2023 | ||
* | ||
*/ | ||
|
||
#ifndef MINESERVER_SERVERLIST_H | ||
#define MINESERVER_SERVERLIST_H | ||
|
||
#include <net/packet.h> | ||
|
||
class ServerListPacket : public IPacket | ||
{ | ||
protected: | ||
/** | ||
* @brief Write Packet Data | ||
* | ||
* Writes server list data to stream | ||
* @param stream the stream to write to | ||
*/ | ||
void write(IStream *stream) override; | ||
|
||
public: | ||
/** | ||
* @brief Construct a new Server List Packet object | ||
* | ||
*/ | ||
ServerListPacket() : IPacket(0x00) {} | ||
/** | ||
* @brief Destroy the Server List Packet object | ||
* | ||
*/ | ||
~ServerListPacket() = default; | ||
|
||
/** | ||
* @brief Read Packet Data | ||
* | ||
* Reads server list data from the stream, | ||
* does nothing for the current protocol version. | ||
* @param stream the stream to read from | ||
* @deprecated No need to call it, it does nothing | ||
*/ | ||
void read(IStream *stream) override; | ||
}; | ||
|
||
#endif // MINESERVER_SERVERLIST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters