1
0
Fork 0

Codechange: [Network] Let server rcon result use std::string

pull/9312/head
rubidium42 2021-05-29 19:33:42 +02:00 committed by rubidium42
parent 8b9f1147df
commit f0e1cd0129
3 changed files with 7 additions and 9 deletions

View File

@ -77,7 +77,7 @@ bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_na
void NetworkServerDoMove(ClientID client_id, CompanyID company_id); void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const char *string); void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const std::string &string);
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64 data = 0, bool from_admin = false); void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64 data = 0, bool from_admin = false);
void NetworkServerKickClient(ClientID client_id, const char *reason); void NetworkServerKickClient(ClientID client_id, const char *reason);

View File

@ -785,7 +785,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGame()
* @param colour The colour of the result. * @param colour The colour of the result.
* @param command The command that was executed. * @param command The command that was executed.
*/ */
NetworkRecvStatus ServerNetworkGameSocketHandler::SendRConResult(uint16 colour, const char *command) NetworkRecvStatus ServerNetworkGameSocketHandler::SendRConResult(uint16 colour, const std::string &command)
{ {
Packet *p = new Packet(PACKET_SERVER_RCON); Packet *p = new Packet(PACKET_SERVER_RCON);
@ -1424,22 +1424,20 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p)
{ {
if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED); if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
char command[NETWORK_RCONCOMMAND_LENGTH];
if (_settings_client.network.rcon_password.empty()) return NETWORK_RECV_STATUS_OKAY; if (_settings_client.network.rcon_password.empty()) return NETWORK_RECV_STATUS_OKAY;
std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH); std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
p->Recv_string(command, sizeof(command)); std::string command = p->Recv_string(NETWORK_RCONCOMMAND_LENGTH);
if (_settings_client.network.rcon_password.compare(password) != 0) { if (_settings_client.network.rcon_password.compare(password) != 0) {
DEBUG(net, 1, "[rcon] Wrong password from client-id %d", this->client_id); DEBUG(net, 1, "[rcon] Wrong password from client-id %d", this->client_id);
return NETWORK_RECV_STATUS_OKAY; return NETWORK_RECV_STATUS_OKAY;
} }
DEBUG(net, 3, "[rcon] Client-id %d executed: %s", this->client_id, command); DEBUG(net, 3, "[rcon] Client-id %d executed: %s", this->client_id, command.c_str());
_redirect_console_to_client = this->client_id; _redirect_console_to_client = this->client_id;
IConsoleCmdExec(command); IConsoleCmdExec(command.c_str());
_redirect_console_to_client = INVALID_CLIENT_ID; _redirect_console_to_client = INVALID_CLIENT_ID;
return NETWORK_RECV_STATUS_OKAY; return NETWORK_RECV_STATUS_OKAY;
} }
@ -2046,7 +2044,7 @@ void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
* @param colour_code The colour of the text. * @param colour_code The colour of the text.
* @param string The actual reply. * @param string The actual reply.
*/ */
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const char *string) void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const std::string &string)
{ {
NetworkClientSocket::GetByClientID(client_id)->SendRConResult(colour_code, string); NetworkClientSocket::GetByClientID(client_id)->SendRConResult(colour_code, string);
} }

View File

@ -89,7 +89,7 @@ public:
NetworkRecvStatus SendQuit(ClientID client_id); NetworkRecvStatus SendQuit(ClientID client_id);
NetworkRecvStatus SendShutdown(); NetworkRecvStatus SendShutdown();
NetworkRecvStatus SendNewGame(); NetworkRecvStatus SendNewGame();
NetworkRecvStatus SendRConResult(uint16 colour, const char *command); NetworkRecvStatus SendRConResult(uint16 colour, const std::string &command);
NetworkRecvStatus SendMove(ClientID client_id, CompanyID company_id); NetworkRecvStatus SendMove(ClientID client_id, CompanyID company_id);
NetworkRecvStatus SendClientInfo(NetworkClientInfo *ci); NetworkRecvStatus SendClientInfo(NetworkClientInfo *ci);