add server mspt (+procotol format)

This commit is contained in:
2023-01-02 15:07:34 +01:00
parent 5a547b6514
commit 512fb23d0e
7 changed files with 43 additions and 32 deletions

View File

@@ -12,6 +12,7 @@ private:
std::uint8_t m_ConnectionID;
std::string m_DisconnectReason;
float m_ServerTPS;
float m_ServerMSPT;
int m_Ping = 0;
public:
ClientConnexion();
@@ -25,6 +26,7 @@ public:
const std::string& GetDisconnectReason() const { return m_DisconnectReason; }
float GetServerTPS() const { return m_ServerTPS; }
float GetServerMSPT() const { return m_ServerMSPT; }
int GetServerPing() const { return m_Ping; }
REMOVE_COPY(ClientConnexion);

View File

@@ -22,6 +22,7 @@ typedef std::map<std::uint8_t, ServerConnexion> ConnexionMap;
class TickCounter {
private:
float m_TPS;
float m_MSPT;
std::uint64_t m_LastTPSTime;
std::uint8_t m_TickCount;
public:
@@ -46,6 +47,9 @@ public:
}
float GetTPS() const { return m_TPS; }
float GetMSPT() const { return m_MSPT; }
void SetMSPT(float mspt) { m_MSPT = mspt; }
};
class Server {

View File

@@ -373,10 +373,11 @@ public:
class ServerTpsPacket : public Packet {
private:
float m_TPS;
float m_MSPT;
std::uint64_t m_PacketSendTime; // used to calculate ping
public:
ServerTpsPacket() {}
ServerTpsPacket(float tps, std::uint64_t sendTime) : m_TPS(tps), m_PacketSendTime(sendTime) {}
ServerTpsPacket(float tps, float mspt, std::uint64_t sendTime) : m_TPS(tps), m_MSPT(mspt), m_PacketSendTime(sendTime) {}
virtual ~ServerTpsPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
@@ -384,6 +385,7 @@ public:
virtual void Dispatch(PacketHandler* handler) const;
float GetTPS() const { return m_TPS; }
float GetMSPT() const { return m_MSPT; }
std::uint64_t GetPacketSendTime() const { return m_PacketSendTime; }
virtual PacketType GetType() const { return PacketType::ServerTps; }