1
0
Fork 0

Codechange: [Network] Make admin name and version std::string

pull/9312/head
rubidium42 2021-05-14 17:25:16 +02:00 committed by rubidium42
parent 97c461d1e7
commit 8a918ce170
3 changed files with 18 additions and 20 deletions

View File

@ -30,8 +30,6 @@ static_assert((int)CRR_END == (int)ADMIN_CRR_END);
NetworkAdminSocketHandler::NetworkAdminSocketHandler(SOCKET s) : status(ADMIN_STATUS_INACTIVE) NetworkAdminSocketHandler::NetworkAdminSocketHandler(SOCKET s) : status(ADMIN_STATUS_INACTIVE)
{ {
this->sock = s; this->sock = s;
this->admin_name[0] = '\0';
this->admin_version[0] = '\0';
} }
NetworkRecvStatus NetworkAdminSocketHandler::CloseConnection(bool error) NetworkRecvStatus NetworkAdminSocketHandler::CloseConnection(bool error)
@ -89,9 +87,9 @@ NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p)
default: default:
if (this->HasClientQuit()) { if (this->HasClientQuit()) {
DEBUG(net, 0, "[tcp/admin] Received invalid packet type %d from '%s' (%s)", type, this->admin_name, this->admin_version); DEBUG(net, 0, "[tcp/admin] Received invalid packet type %d from '%s' (%s)", type, this->admin_name.c_str(), this->admin_version.c_str());
} else { } else {
DEBUG(net, 0, "[tcp/admin] Received illegal packet from '%s' (%s)", this->admin_name, this->admin_version); DEBUG(net, 0, "[tcp/admin] Received illegal packet from '%s' (%s)", this->admin_name.c_str(), this->admin_version.c_str());
} }
this->CloseConnection(); this->CloseConnection();
@ -125,7 +123,7 @@ NetworkRecvStatus NetworkAdminSocketHandler::ReceivePackets()
*/ */
NetworkRecvStatus NetworkAdminSocketHandler::ReceiveInvalidPacket(PacketAdminType type) NetworkRecvStatus NetworkAdminSocketHandler::ReceiveInvalidPacket(PacketAdminType type)
{ {
DEBUG(net, 0, "[tcp/admin] Received illegal packet type %d from admin %s (%s)", type, this->admin_name, this->admin_version); DEBUG(net, 0, "[tcp/admin] Received illegal packet type %d from admin %s (%s)", type, this->admin_name.c_str(), this->admin_version.c_str());
return NETWORK_RECV_STATUS_MALFORMED_PACKET; return NETWORK_RECV_STATUS_MALFORMED_PACKET;
} }

View File

@ -109,9 +109,9 @@ enum AdminCompanyRemoveReason {
/** Main socket handler for admin related connections. */ /** Main socket handler for admin related connections. */
class NetworkAdminSocketHandler : public NetworkTCPSocketHandler { class NetworkAdminSocketHandler : public NetworkTCPSocketHandler {
protected: protected:
char admin_name[NETWORK_CLIENT_NAME_LENGTH]; ///< Name of the admin. std::string admin_name; ///< Name of the admin.
char admin_version[NETWORK_REVISION_LENGTH]; ///< Version string of the admin. std::string admin_version; ///< Version string of the admin.
AdminStatus status; ///< Status of this admin. AdminStatus status; ///< Status of this admin.
NetworkRecvStatus ReceiveInvalidPacket(PacketAdminType type); NetworkRecvStatus ReceiveInvalidPacket(PacketAdminType type);

View File

@ -74,7 +74,7 @@ ServerNetworkAdminSocketHandler::ServerNetworkAdminSocketHandler(SOCKET s) : Net
ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler() ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler()
{ {
_network_admins_connected--; _network_admins_connected--;
DEBUG(net, 3, "[admin] '%s' (%s) has disconnected", this->admin_name, this->admin_version); DEBUG(net, 3, "[admin] '%s' (%s) has disconnected", this->admin_name.c_str(), this->admin_version.c_str());
if (_redirect_console_to_admin == this->index) _redirect_console_to_admin = INVALID_ADMIN_ID; if (_redirect_console_to_admin == this->index) _redirect_console_to_admin = INVALID_ADMIN_ID;
} }
@ -135,7 +135,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendError(NetworkErrorCode er
std::string error_message = GetString(GetNetworkErrorMsg(error)); std::string error_message = GetString(GetNetworkErrorMsg(error));
DEBUG(net, 1, "[admin] The admin '%s' (%s) made an error and has been disconnected: '%s'", this->admin_name, this->admin_version, error_message.c_str()); DEBUG(net, 1, "[admin] The admin '%s' (%s) made an error and has been disconnected: '%s'", this->admin_name.c_str(), this->admin_version.c_str(), error_message.c_str());
return this->CloseConnection(true); return this->CloseConnection(true);
} }
@ -502,7 +502,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_RCON(Packet *p)
p->Recv_string(command, sizeof(command)); p->Recv_string(command, sizeof(command));
DEBUG(net, 3, "[admin] Rcon command from '%s' (%s): %s", this->admin_name, this->admin_version, command); DEBUG(net, 3, "[admin] Rcon command from '%s' (%s): %s", this->admin_name.c_str(), this->admin_version.c_str(), command);
_redirect_console_to_admin = this->index; _redirect_console_to_admin = this->index;
IConsoleCmdExec(command); IConsoleCmdExec(command);
@ -518,7 +518,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT(Pack
p->Recv_string(json, sizeof(json)); p->Recv_string(json, sizeof(json));
DEBUG(net, 6, "[admin] GameScript JSON from '%s' (%s): %s", this->admin_name, this->admin_version, json); DEBUG(net, 6, "[admin] GameScript JSON from '%s' (%s): %s", this->admin_name.c_str(), this->admin_version.c_str(), json);
Game::NewEvent(new ScriptEventAdminPort(json)); Game::NewEvent(new ScriptEventAdminPort(json));
return NETWORK_RECV_STATUS_OKAY; return NETWORK_RECV_STATUS_OKAY;
@ -530,7 +530,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_PING(Packet *p)
uint32 d1 = p->Recv_uint32(); uint32 d1 = p->Recv_uint32();
DEBUG(net, 6, "[admin] Ping from '%s' (%s): %d", this->admin_name, this->admin_version, d1); DEBUG(net, 6, "[admin] Ping from '%s' (%s): %d", this->admin_name.c_str(), this->admin_version.c_str(), d1);
return this->SendPong(d1); return this->SendPong(d1);
} }
@ -656,17 +656,17 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet *p)
return this->SendError(NETWORK_ERROR_WRONG_PASSWORD); return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
} }
p->Recv_string(this->admin_name, sizeof(this->admin_name)); this->admin_name = p->Recv_string(NETWORK_CLIENT_NAME_LENGTH);
p->Recv_string(this->admin_version, sizeof(this->admin_version)); this->admin_version = p->Recv_string(NETWORK_REVISION_LENGTH);
if (StrEmpty(this->admin_name) || StrEmpty(this->admin_version)) { if (this->admin_name.empty() || this->admin_version.empty()) {
/* no name or version supplied */ /* no name or version supplied */
return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET); return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET);
} }
this->status = ADMIN_STATUS_ACTIVE; this->status = ADMIN_STATUS_ACTIVE;
DEBUG(net, 3, "[admin] '%s' (%s) has connected", this->admin_name, this->admin_version); DEBUG(net, 3, "[admin] '%s' (%s) has connected", this->admin_name.c_str(), this->admin_version.c_str());
return this->SendProtocol(); return this->SendProtocol();
} }
@ -686,7 +686,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENC
if (type >= ADMIN_UPDATE_END || (_admin_update_type_frequencies[type] & freq) != freq) { if (type >= ADMIN_UPDATE_END || (_admin_update_type_frequencies[type] & freq) != freq) {
/* The server does not know of this UpdateType. */ /* The server does not know of this UpdateType. */
DEBUG(net, 1, "[admin] Not supported update frequency %d (%d) from '%s' (%s)", type, freq, this->admin_name, this->admin_version); DEBUG(net, 1, "[admin] Not supported update frequency %d (%d) from '%s' (%s)", type, freq, this->admin_name.c_str(), this->admin_version.c_str());
return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET); return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET);
} }
@ -754,7 +754,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet *p)
default: default:
/* An unsupported "poll" update type. */ /* An unsupported "poll" update type. */
DEBUG(net, 1, "[admin] Not supported poll %d (%d) from '%s' (%s).", type, d1, this->admin_name, this->admin_version); DEBUG(net, 1, "[admin] Not supported poll %d (%d) from '%s' (%s).", type, d1, this->admin_name.c_str(), this->admin_version.c_str());
return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET); return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET);
} }
@ -780,7 +780,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT(Packet *p)
break; break;
default: default:
DEBUG(net, 1, "[admin] Invalid chat action %d from admin '%s' (%s).", action, this->admin_name, this->admin_version); DEBUG(net, 1, "[admin] Invalid chat action %d from admin '%s' (%s).", action, this->admin_name.c_str(), this->admin_version.c_str());
return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET); return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET);
} }