Send network client desync log messages to server
This commit is contained in:
@@ -313,12 +313,13 @@ struct DesyncMsgLogEntry {
|
|||||||
Date date;
|
Date date;
|
||||||
DateFract date_fract;
|
DateFract date_fract;
|
||||||
uint8 tick_skip_counter;
|
uint8 tick_skip_counter;
|
||||||
|
uint32 src_id;
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|
||||||
DesyncMsgLogEntry() { }
|
DesyncMsgLogEntry() { }
|
||||||
|
|
||||||
DesyncMsgLogEntry(std::string msg)
|
DesyncMsgLogEntry(std::string msg)
|
||||||
: date(_date), date_fract(_date_fract), tick_skip_counter(_tick_skip_counter), msg(msg) { }
|
: date(_date), date_fract(_date_fract), tick_skip_counter(_tick_skip_counter), src_id(0), msg(msg) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DesyncMsgLog {
|
struct DesyncMsgLog {
|
||||||
@@ -332,14 +333,15 @@ struct DesyncMsgLog {
|
|||||||
this->next = 0;
|
this->next = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogMsg(std::string msg)
|
void LogMsg(DesyncMsgLogEntry entry)
|
||||||
{
|
{
|
||||||
this->log[this->next] = DesyncMsgLogEntry(std::move(msg));
|
this->log[this->next] = std::move(entry);
|
||||||
this->next = (this->next + 1) % this->log.size();
|
this->next = (this->next + 1) % this->log.size();
|
||||||
this->count++;
|
this->count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *Dump(char *buffer, const char *last)
|
template <typename F>
|
||||||
|
char *Dump(char *buffer, const char *last, const char *prefix, F handler)
|
||||||
{
|
{
|
||||||
if (!this->count) return buffer;
|
if (!this->count) return buffer;
|
||||||
|
|
||||||
@@ -347,14 +349,12 @@ struct DesyncMsgLog {
|
|||||||
unsigned int log_index = (this->next + this->log.size() - count) % this->log.size();
|
unsigned int log_index = (this->next + this->log.size() - count) % this->log.size();
|
||||||
unsigned int display_num = this->count - count;
|
unsigned int display_num = this->count - count;
|
||||||
|
|
||||||
buffer += seprintf(buffer, last, "Desync Msg Log:\n Showing most recent %u of %u messages\n", count, this->count);
|
buffer += seprintf(buffer, last, "%s:\n Showing most recent %u of %u messages\n", prefix, count, this->count);
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < count; i++) {
|
for (unsigned int i = 0 ; i < count; i++) {
|
||||||
const DesyncMsgLogEntry &entry = this->log[log_index];
|
const DesyncMsgLogEntry &entry = this->log[log_index];
|
||||||
|
|
||||||
YearMonthDay ymd;
|
buffer += handler(display_num, buffer, last, entry);
|
||||||
ConvertDateToYMD(entry.date, &ymd);
|
|
||||||
buffer += seprintf(buffer, last, "%5u | %4i-%02i-%02i, %2i, %3i | %s\n", display_num, ymd.year, ymd.month + 1, ymd.day, entry.date_fract, entry.tick_skip_counter, entry.msg.c_str());
|
|
||||||
log_index = (log_index + 1) % this->log.size();
|
log_index = (log_index + 1) % this->log.size();
|
||||||
display_num++;
|
display_num++;
|
||||||
}
|
}
|
||||||
@@ -364,6 +364,7 @@ struct DesyncMsgLog {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static DesyncMsgLog _desync_msg_log;
|
static DesyncMsgLog _desync_msg_log;
|
||||||
|
static DesyncMsgLog _remote_desync_msg_log;
|
||||||
|
|
||||||
void ClearDesyncMsgLog()
|
void ClearDesyncMsgLog()
|
||||||
{
|
{
|
||||||
@@ -372,11 +373,33 @@ void ClearDesyncMsgLog()
|
|||||||
|
|
||||||
char *DumpDesyncMsgLog(char *buffer, const char *last)
|
char *DumpDesyncMsgLog(char *buffer, const char *last)
|
||||||
{
|
{
|
||||||
buffer = _desync_msg_log.Dump(buffer, last);
|
buffer = _desync_msg_log.Dump(buffer, last, "Desync Msg Log", [](int display_num, char *buffer, const char *last, const DesyncMsgLogEntry &entry) -> int {
|
||||||
|
YearMonthDay ymd;
|
||||||
|
ConvertDateToYMD(entry.date, &ymd);
|
||||||
|
return seprintf(buffer, last, "%5u | %4i-%02i-%02i, %2i, %3i | %s\n", display_num, ymd.year, ymd.month + 1, ymd.day, entry.date_fract, entry.tick_skip_counter, entry.msg.c_str());
|
||||||
|
});
|
||||||
|
buffer = _remote_desync_msg_log.Dump(buffer, last, "Remote Client Desync Msg Log", [](int display_num, char *buffer, const char *last, const DesyncMsgLogEntry &entry) -> int {
|
||||||
|
YearMonthDay ymd;
|
||||||
|
ConvertDateToYMD(entry.date, &ymd);
|
||||||
|
return seprintf(buffer, last, "%5u | Client %5u | %4i-%02i-%02i, %2i, %3i | %s\n", display_num, entry.src_id, ymd.year, ymd.month + 1, ymd.day, entry.date_fract, entry.tick_skip_counter, entry.msg.c_str());
|
||||||
|
});
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogDesyncMsg(std::string msg)
|
void LogDesyncMsg(std::string msg)
|
||||||
{
|
{
|
||||||
_desync_msg_log.LogMsg(std::move(msg));
|
if (_networking && !_network_server) {
|
||||||
|
NetworkClientSendDesyncMsg(msg.c_str());
|
||||||
|
}
|
||||||
|
_desync_msg_log.LogMsg(DesyncMsgLogEntry(std::move(msg)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogRemoteDesyncMsg(Date date, DateFract date_fract, uint8 tick_skip_counter, uint32 src_id, std::string msg)
|
||||||
|
{
|
||||||
|
DesyncMsgLogEntry entry(std::move(msg));
|
||||||
|
entry.date = date;
|
||||||
|
entry.date_fract = date_fract;
|
||||||
|
entry.tick_skip_counter = tick_skip_counter;
|
||||||
|
entry.src_id = src_id;
|
||||||
|
_remote_desync_msg_log.LogMsg(std::move(entry));
|
||||||
}
|
}
|
||||||
|
@@ -104,6 +104,7 @@ NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p)
|
|||||||
case PACKET_CLIENT_ERROR: return this->Receive_CLIENT_ERROR(p);
|
case PACKET_CLIENT_ERROR: return this->Receive_CLIENT_ERROR(p);
|
||||||
case PACKET_CLIENT_DESYNC_LOG: return this->Receive_CLIENT_DESYNC_LOG(p);
|
case PACKET_CLIENT_DESYNC_LOG: return this->Receive_CLIENT_DESYNC_LOG(p);
|
||||||
case PACKET_SERVER_DESYNC_LOG: return this->Receive_SERVER_DESYNC_LOG(p);
|
case PACKET_SERVER_DESYNC_LOG: return this->Receive_SERVER_DESYNC_LOG(p);
|
||||||
|
case PACKET_CLIENT_DESYNC_MSG: return this->Receive_CLIENT_DESYNC_MSG(p);
|
||||||
case PACKET_SERVER_QUIT: return this->Receive_SERVER_QUIT(p);
|
case PACKET_SERVER_QUIT: return this->Receive_SERVER_QUIT(p);
|
||||||
case PACKET_SERVER_ERROR_QUIT: return this->Receive_SERVER_ERROR_QUIT(p);
|
case PACKET_SERVER_ERROR_QUIT: return this->Receive_SERVER_ERROR_QUIT(p);
|
||||||
case PACKET_SERVER_SHUTDOWN: return this->Receive_SERVER_SHUTDOWN(p);
|
case PACKET_SERVER_SHUTDOWN: return this->Receive_SERVER_SHUTDOWN(p);
|
||||||
@@ -193,6 +194,7 @@ NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_QUIT(Packet *p) { ret
|
|||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ERROR(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_ERROR); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ERROR(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_ERROR); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_DESYNC_LOG(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_DESYNC_LOG); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_DESYNC_LOG(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_DESYNC_LOG); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_DESYNC_LOG(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_DESYNC_LOG); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_DESYNC_LOG(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_DESYNC_LOG); }
|
||||||
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_DESYNC_MSG(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_DESYNC_LOG); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_QUIT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_QUIT); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_QUIT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_QUIT); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_ERROR_QUIT); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_ERROR_QUIT); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_SHUTDOWN); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_SHUTDOWN); }
|
||||||
|
@@ -124,6 +124,7 @@ enum PacketGameType {
|
|||||||
PACKET_SERVER_ERROR_QUIT, ///< A server tells that a client has hit an error and did quit.
|
PACKET_SERVER_ERROR_QUIT, ///< A server tells that a client has hit an error and did quit.
|
||||||
PACKET_CLIENT_DESYNC_LOG, ///< A client reports a desync log
|
PACKET_CLIENT_DESYNC_LOG, ///< A client reports a desync log
|
||||||
PACKET_SERVER_DESYNC_LOG, ///< A server reports a desync log
|
PACKET_SERVER_DESYNC_LOG, ///< A server reports a desync log
|
||||||
|
PACKET_CLIENT_DESYNC_MSG, ///< A client reports a desync message
|
||||||
|
|
||||||
PACKET_END, ///< Must ALWAYS be on the end of this list!! (period)
|
PACKET_END, ///< Must ALWAYS be on the end of this list!! (period)
|
||||||
};
|
};
|
||||||
@@ -447,6 +448,7 @@ protected:
|
|||||||
virtual NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p);
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_DESYNC_LOG(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_DESYNC_LOG(Packet *p);
|
||||||
virtual NetworkRecvStatus Receive_SERVER_DESYNC_LOG(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_DESYNC_LOG(Packet *p);
|
||||||
|
virtual NetworkRecvStatus Receive_CLIENT_DESYNC_MSG(Packet *p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification that a client left the game:
|
* Notification that a client left the game:
|
||||||
|
@@ -569,6 +569,18 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendDesyncLog(const std::strin
|
|||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Send an error-packet over the network */
|
||||||
|
NetworkRecvStatus ClientNetworkGameSocketHandler::SendDesyncMessage(const char *msg)
|
||||||
|
{
|
||||||
|
Packet *p = new Packet(PACKET_CLIENT_DESYNC_MSG);
|
||||||
|
p->Send_uint32(_date);
|
||||||
|
p->Send_uint16(_date_fract);
|
||||||
|
p->Send_uint8(_tick_skip_counter);
|
||||||
|
p->Send_string(msg);
|
||||||
|
my_client->SendPacket(p);
|
||||||
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell the server that we like to change the password of the company.
|
* Tell the server that we like to change the password of the company.
|
||||||
* @param password The new password.
|
* @param password The new password.
|
||||||
@@ -1438,6 +1450,12 @@ void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const
|
|||||||
MyClient::SendChat(action, type, dest, msg, data);
|
MyClient::SendChat(action, type, dest, msg, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void NetworkClientSendDesyncMsg(const char *msg)
|
||||||
|
{
|
||||||
|
MyClient::SendDesyncMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set/Reset company password on the client side.
|
* Set/Reset company password on the client side.
|
||||||
* @param password Password to be set.
|
* @param password Password to be set.
|
||||||
|
@@ -92,6 +92,7 @@ public:
|
|||||||
static NetworkRecvStatus SendCommand(const CommandPacket *cp);
|
static NetworkRecvStatus SendCommand(const CommandPacket *cp);
|
||||||
static NetworkRecvStatus SendError(NetworkErrorCode errorno);
|
static NetworkRecvStatus SendError(NetworkErrorCode errorno);
|
||||||
static NetworkRecvStatus SendDesyncLog(const std::string &log);
|
static NetworkRecvStatus SendDesyncLog(const std::string &log);
|
||||||
|
static NetworkRecvStatus SendDesyncMessage(const char *msg);
|
||||||
static NetworkRecvStatus SendQuit();
|
static NetworkRecvStatus SendQuit();
|
||||||
static NetworkRecvStatus SendAck();
|
static NetworkRecvStatus SendAck();
|
||||||
|
|
||||||
|
@@ -54,6 +54,7 @@ void NetworkClientRequestMove(CompanyID company, const char *pass = "");
|
|||||||
void NetworkClientSendRcon(const char *password, const char *command);
|
void NetworkClientSendRcon(const char *password, const char *command);
|
||||||
void NetworkClientSendSettingsPassword(const char *password);
|
void NetworkClientSendSettingsPassword(const char *password);
|
||||||
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, NetworkTextMessageData data = NetworkTextMessageData());
|
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, NetworkTextMessageData data = NetworkTextMessageData());
|
||||||
|
void NetworkClientSendDesyncMsg(const char *msg);
|
||||||
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio);
|
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio);
|
||||||
bool NetworkCompanyIsPassworded(CompanyID company_id);
|
bool NetworkCompanyIsPassworded(CompanyID company_id);
|
||||||
bool NetworkMaxCompaniesReached();
|
bool NetworkMaxCompaniesReached();
|
||||||
|
@@ -1286,6 +1286,19 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_DESYNC_LOG(Pack
|
|||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_DESYNC_MSG(Packet *p)
|
||||||
|
{
|
||||||
|
Date date = p->Recv_uint32();
|
||||||
|
DateFract date_fract = p->Recv_uint16();
|
||||||
|
uint8 tick_skip_counter = p->Recv_uint8();
|
||||||
|
std::string msg;
|
||||||
|
p->Recv_string(msg);
|
||||||
|
DEBUG(desync, 0, "Client-id %d desync msg: %s", this->client_id, msg.c_str());
|
||||||
|
extern void LogRemoteDesyncMsg(Date date, DateFract date_fract, uint8 tick_skip_counter, uint32 src_id, std::string msg);
|
||||||
|
LogRemoteDesyncMsg(date, date_fract, tick_skip_counter, this->client_id, std::move(msg));
|
||||||
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_QUIT(Packet *p)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_QUIT(Packet *p)
|
||||||
{
|
{
|
||||||
/* The client wants to leave. Display this and report it to the other
|
/* The client wants to leave. Display this and report it to the other
|
||||||
|
@@ -38,6 +38,7 @@ protected:
|
|||||||
NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_DESYNC_LOG(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_DESYNC_LOG(Packet *p) override;
|
||||||
|
NetworkRecvStatus Receive_CLIENT_DESYNC_MSG(Packet *p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_RCON(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_RCON(Packet *p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p) override;
|
||||||
|
Reference in New Issue
Block a user