summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-29 19:33:42 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-30 00:01:49 +0200
commitf0e1cd01298237dc32413fb0c19e145c45baa2e8 (patch)
tree6255cdf54522073b108516559a0f6f3b005085e6 /src/network
parent8b9f1147dfec4efe3451dd3e111276a1dab3bb99 (diff)
downloadopenttd-f0e1cd01298237dc32413fb0c19e145c45baa2e8.tar.xz
Codechange: [Network] Let server rcon result use std::string
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network_func.h2
-rw-r--r--src/network/network_server.cpp12
-rw-r--r--src/network/network_server.h2
3 files changed, 7 insertions, 9 deletions
diff --git a/src/network/network_func.h b/src/network/network_func.h
index a50166e2a..6a21eb80a 100644
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -77,7 +77,7 @@ bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_na
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 NetworkServerKickClient(ClientID client_id, const char *reason);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index b770dbda3..d15263e53 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -785,7 +785,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGame()
* @param colour The colour of the result.
* @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);
@@ -1424,22 +1424,20 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p)
{
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;
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) {
DEBUG(net, 1, "[rcon] Wrong password from client-id %d", this->client_id);
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;
- IConsoleCmdExec(command);
+ IConsoleCmdExec(command.c_str());
_redirect_console_to_client = INVALID_CLIENT_ID;
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 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);
}
diff --git a/src/network/network_server.h b/src/network/network_server.h
index 98b2f9b6e..850b56007 100644
--- a/src/network/network_server.h
+++ b/src/network/network_server.h
@@ -89,7 +89,7 @@ public:
NetworkRecvStatus SendQuit(ClientID client_id);
NetworkRecvStatus SendShutdown();
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 SendClientInfo(NetworkClientInfo *ci);