Net: Log sent and received game packets with type and status names
This commit is contained in:
@@ -134,6 +134,7 @@ SendPacketsState NetworkTCPSocketHandler::SendPackets(bool closing_down)
|
|||||||
/* Is this packet sent? */
|
/* Is this packet sent? */
|
||||||
if (p->RemainingBytesToTransfer() == 0) {
|
if (p->RemainingBytesToTransfer() == 0) {
|
||||||
/* Go to the next packet */
|
/* Go to the next packet */
|
||||||
|
if (_debug_net_level >= 3) this->LogSentPacket(*p);
|
||||||
this->packet_queue.pop_front();
|
this->packet_queue.pop_front();
|
||||||
} else {
|
} else {
|
||||||
return SPS_PARTLY_SENT;
|
return SPS_PARTLY_SENT;
|
||||||
@@ -216,6 +217,8 @@ std::unique_ptr<Packet> NetworkTCPSocketHandler::ReceivePacket()
|
|||||||
return std::move(this->packet_recv);
|
return std::move(this->packet_recv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetworkTCPSocketHandler::LogSentPacket(const Packet &pkt) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether this socket can send or receive something.
|
* Check whether this socket can send or receive something.
|
||||||
* @return \c true when there is something to receive.
|
* @return \c true when there is something to receive.
|
||||||
|
@@ -54,6 +54,7 @@ public:
|
|||||||
SendPacketsState SendPackets(bool closing_down = false);
|
SendPacketsState SendPackets(bool closing_down = false);
|
||||||
|
|
||||||
virtual std::unique_ptr<Packet> ReceivePacket();
|
virtual std::unique_ptr<Packet> ReceivePacket();
|
||||||
|
virtual void LogSentPacket(const Packet &pkt);
|
||||||
|
|
||||||
bool CanSendReceive();
|
bool CanSendReceive();
|
||||||
|
|
||||||
|
@@ -20,6 +20,65 @@
|
|||||||
|
|
||||||
#include "../../safeguards.h"
|
#include "../../safeguards.h"
|
||||||
|
|
||||||
|
static const char* _packet_game_type_names[] {
|
||||||
|
"SERVER_FULL",
|
||||||
|
"SERVER_BANNED",
|
||||||
|
"CLIENT_JOIN",
|
||||||
|
"SERVER_ERROR",
|
||||||
|
"CLIENT_COMPANY_INFO",
|
||||||
|
"SERVER_COMPANY_INFO",
|
||||||
|
"SERVER_CHECK_NEWGRFS",
|
||||||
|
"CLIENT_NEWGRFS_CHECKED",
|
||||||
|
"SERVER_NEED_GAME_PASSWORD",
|
||||||
|
"CLIENT_GAME_PASSWORD",
|
||||||
|
"SERVER_NEED_COMPANY_PASSWORD",
|
||||||
|
"CLIENT_COMPANY_PASSWORD",
|
||||||
|
"CLIENT_SETTINGS_PASSWORD",
|
||||||
|
"SERVER_SETTINGS_ACCESS",
|
||||||
|
"SERVER_WELCOME",
|
||||||
|
"SERVER_CLIENT_INFO",
|
||||||
|
"CLIENT_GETMAP",
|
||||||
|
"SERVER_WAIT",
|
||||||
|
"SERVER_MAP_BEGIN",
|
||||||
|
"SERVER_MAP_SIZE",
|
||||||
|
"SERVER_MAP_DATA",
|
||||||
|
"SERVER_MAP_DONE",
|
||||||
|
"CLIENT_MAP_OK",
|
||||||
|
"SERVER_JOIN",
|
||||||
|
"SERVER_FRAME",
|
||||||
|
"CLIENT_ACK",
|
||||||
|
"SERVER_SYNC",
|
||||||
|
"CLIENT_COMMAND",
|
||||||
|
"SERVER_COMMAND",
|
||||||
|
"CLIENT_CHAT",
|
||||||
|
"SERVER_CHAT",
|
||||||
|
"CLIENT_RCON",
|
||||||
|
"SERVER_RCON",
|
||||||
|
"CLIENT_MOVE",
|
||||||
|
"SERVER_MOVE",
|
||||||
|
"CLIENT_SET_PASSWORD",
|
||||||
|
"CLIENT_SET_NAME",
|
||||||
|
"SERVER_COMPANY_UPDATE",
|
||||||
|
"SERVER_CONFIG_UPDATE",
|
||||||
|
"SERVER_NEWGAME",
|
||||||
|
"SERVER_SHUTDOWN",
|
||||||
|
"CLIENT_QUIT",
|
||||||
|
"SERVER_QUIT",
|
||||||
|
"CLIENT_ERROR",
|
||||||
|
"SERVER_ERROR_QUIT",
|
||||||
|
"CLIENT_DESYNC_LOG",
|
||||||
|
"SERVER_DESYNC_LOG",
|
||||||
|
"CLIENT_DESYNC_MSG",
|
||||||
|
};
|
||||||
|
static_assert(lengthof(_packet_game_type_names) == PACKET_END);
|
||||||
|
|
||||||
|
const char *GetPacketGameTypeName(PacketGameType type)
|
||||||
|
{
|
||||||
|
if (type >= PACKET_END) return "[invalid packet type]";
|
||||||
|
|
||||||
|
return _packet_game_type_names[type];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new socket for the game connection.
|
* Create a new socket for the game connection.
|
||||||
* @param s The socket to connect with.
|
* @param s The socket to connect with.
|
||||||
@@ -69,7 +128,7 @@ NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p)
|
|||||||
this->last_packet = std::chrono::steady_clock::now();
|
this->last_packet = std::chrono::steady_clock::now();
|
||||||
this->last_pkt_type = type;
|
this->last_pkt_type = type;
|
||||||
|
|
||||||
DEBUG(net, 3, "[tcp/game] received packet type %d from client %d, %s", type, this->client_id, this->GetDebugInfo().c_str());
|
DEBUG(net, 3, "[tcp/game] received packet type %d (%s) from client %d, %s", type, GetPacketGameTypeName(type), this->client_id, this->GetDebugInfo().c_str());
|
||||||
|
|
||||||
switch (this->HasClientQuit() ? PACKET_END : type) {
|
switch (this->HasClientQuit() ? PACKET_END : type) {
|
||||||
case PACKET_SERVER_FULL: return this->Receive_SERVER_FULL(p);
|
case PACKET_SERVER_FULL: return this->Receive_SERVER_FULL(p);
|
||||||
@@ -212,3 +271,9 @@ NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet
|
|||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CONFIG_UPDATE); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CONFIG_UPDATE); }
|
||||||
|
|
||||||
std::string NetworkGameSocketHandler::GetDebugInfo() const { return ""; }
|
std::string NetworkGameSocketHandler::GetDebugInfo() const { return ""; }
|
||||||
|
|
||||||
|
void NetworkGameSocketHandler::LogSentPacket(const Packet &pkt)
|
||||||
|
{
|
||||||
|
PacketGameType type = (PacketGameType)pkt.GetPacketType();
|
||||||
|
DEBUG(net, 3, "[tcp/game] sent packet type %d (%s) to client %d, %s", type, GetPacketGameTypeName(type), this->client_id, this->GetDebugInfo().c_str());
|
||||||
|
}
|
||||||
|
@@ -129,6 +129,8 @@ enum PacketGameType {
|
|||||||
PACKET_END, ///< Must ALWAYS be on the end of this list!! (period)
|
PACKET_END, ///< Must ALWAYS be on the end of this list!! (period)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const char *GetPacketTypeName(PacketGameType type);
|
||||||
|
|
||||||
/** Packet that wraps a command */
|
/** Packet that wraps a command */
|
||||||
struct CommandPacket;
|
struct CommandPacket;
|
||||||
|
|
||||||
@@ -584,6 +586,7 @@ public:
|
|||||||
void SendCommand(Packet *p, const CommandPacket *cp);
|
void SendCommand(Packet *p, const CommandPacket *cp);
|
||||||
|
|
||||||
virtual std::string GetDebugInfo() const;
|
virtual std::string GetDebugInfo() const;
|
||||||
|
virtual void LogSentPacket(const Packet &pkt);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* NETWORK_CORE_TCP_GAME_H */
|
#endif /* NETWORK_CORE_TCP_GAME_H */
|
||||||
|
@@ -1362,9 +1362,28 @@ void ClientNetworkGameSocketHandler::CheckConnection()
|
|||||||
ShowErrorMessage(STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION_CAPTION, STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION, WL_INFO);
|
ShowErrorMessage(STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION_CAPTION, STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION, WL_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *ClientNetworkGameSocketHandler::GetServerStatusName(ServerStatus status)
|
||||||
|
{
|
||||||
|
static const char* _server_status_names[] {
|
||||||
|
"INACTIVE",
|
||||||
|
"COMPANY_INFO",
|
||||||
|
"JOIN",
|
||||||
|
"NEWGRFS_CHECK",
|
||||||
|
"AUTH_GAME",
|
||||||
|
"AUTH_COMPANY",
|
||||||
|
"AUTHORIZED",
|
||||||
|
"MAP_WAIT",
|
||||||
|
"MAP",
|
||||||
|
"ACTIVE",
|
||||||
|
"CLOSING",
|
||||||
|
};
|
||||||
|
static_assert(lengthof(_server_status_names) == STATUS_END);
|
||||||
|
return status < STATUS_END ? _server_status_names[status] : "[invalid status]";
|
||||||
|
}
|
||||||
|
|
||||||
std::string ClientNetworkGameSocketHandler::GetDebugInfo() const
|
std::string ClientNetworkGameSocketHandler::GetDebugInfo() const
|
||||||
{
|
{
|
||||||
return stdstr_fmt("status: %d", this->status);
|
return stdstr_fmt("status: %d (%s)", this->status, GetServerStatusName(this->status));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -40,6 +40,8 @@ private:
|
|||||||
std::string server_desync_log;
|
std::string server_desync_log;
|
||||||
bool emergency_save_done = false;
|
bool emergency_save_done = false;
|
||||||
|
|
||||||
|
static const char *GetServerStatusName(ServerStatus status);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend void NetworkExecuteLocalCommandQueue();
|
friend void NetworkExecuteLocalCommandQueue();
|
||||||
friend void NetworkClose(bool close_admins);
|
friend void NetworkClose(bool close_admins);
|
||||||
|
@@ -1584,9 +1584,28 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet *p)
|
|||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *ServerNetworkGameSocketHandler::GetClientStatusName(ClientStatus status)
|
||||||
|
{
|
||||||
|
static const char* _client_status_names[] {
|
||||||
|
"INACTIVE",
|
||||||
|
"NEWGRFS_CHECK",
|
||||||
|
"AUTH_GAME",
|
||||||
|
"AUTH_COMPANY",
|
||||||
|
"AUTHORIZED",
|
||||||
|
"MAP_WAIT",
|
||||||
|
"MAP",
|
||||||
|
"DONE_MAP",
|
||||||
|
"PRE_ACTIVE",
|
||||||
|
"ACTIVE",
|
||||||
|
"CLOSE_PENDING",
|
||||||
|
};
|
||||||
|
static_assert(lengthof(_client_status_names) == STATUS_END);
|
||||||
|
return status < STATUS_END ? _client_status_names[status] : "[invalid status]";
|
||||||
|
}
|
||||||
|
|
||||||
std::string ServerNetworkGameSocketHandler::GetDebugInfo() const
|
std::string ServerNetworkGameSocketHandler::GetDebugInfo() const
|
||||||
{
|
{
|
||||||
return stdstr_fmt("status: %d", this->status);
|
return stdstr_fmt("status: %d (%s)", this->status, GetClientStatusName(this->status));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -66,6 +66,8 @@ public:
|
|||||||
STATUS_END, ///< Must ALWAYS be on the end of this list!! (period).
|
STATUS_END, ///< Must ALWAYS be on the end of this list!! (period).
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char *GetClientStatusName(ClientStatus status);
|
||||||
|
|
||||||
byte lag_test; ///< Byte used for lag-testing the client
|
byte lag_test; ///< Byte used for lag-testing the client
|
||||||
byte last_token; ///< The last random token we did send to verify the client is listening
|
byte last_token; ///< The last random token we did send to verify the client is listening
|
||||||
uint32 last_token_frame; ///< The last frame we received the right token
|
uint32 last_token_frame; ///< The last frame we received the right token
|
||||||
|
Reference in New Issue
Block a user