1
0
Fork 0

Codechange: let IConsoleCmdExec accept std::string

pull/11083/head
Rubidium 2023-06-28 22:40:03 +02:00 committed by rubidium42
parent fd380127f0
commit f333372dd1
4 changed files with 12 additions and 12 deletions

View File

@ -225,7 +225,7 @@ static void IConsoleAliasExec(const IConsoleAlias *alias, byte tokencount, char
break; break;
case ';': // Cmd separator; execute previous and start new command case ';': // Cmd separator; execute previous and start new command
IConsoleCmdExec(alias_buffer.c_str(), recurse_count); IConsoleCmdExec(alias_buffer, recurse_count);
alias_buffer.clear(); alias_buffer.clear();
@ -283,15 +283,15 @@ static void IConsoleAliasExec(const IConsoleAlias *alias, byte tokencount, char
} }
} }
IConsoleCmdExec(alias_buffer.c_str(), recurse_count); IConsoleCmdExec(alias_buffer, recurse_count);
} }
/** /**
* Execute a given command passed to us. First chop it up into * Execute a given command passed to us. First chop it up into
* individual tokens (separated by spaces), then execute it if possible * individual tokens (separated by spaces), then execute it if possible
* @param cmdstr string to be parsed and executed * @param command_string string to be parsed and executed
*/ */
void IConsoleCmdExec(const char *cmdstr, const uint recurse_count) void IConsoleCmdExec(const std::string &command_string, const uint recurse_count)
{ {
const char *cmdptr; const char *cmdptr;
char *tokens[ICON_TOKEN_COUNT], tokenstream[ICON_MAX_STREAMSIZE]; char *tokens[ICON_TOKEN_COUNT], tokenstream[ICON_MAX_STREAMSIZE];
@ -300,16 +300,16 @@ void IConsoleCmdExec(const char *cmdstr, const uint recurse_count)
bool longtoken = false; bool longtoken = false;
bool foundtoken = false; bool foundtoken = false;
if (cmdstr[0] == '#') return; // comments if (command_string[0] == '#') return; // comments
for (cmdptr = cmdstr; *cmdptr != '\0'; cmdptr++) { for (cmdptr = command_string.c_str(); *cmdptr != '\0'; cmdptr++) {
if (!IsValidChar(*cmdptr, CS_ALPHANUMERAL)) { if (!IsValidChar(*cmdptr, CS_ALPHANUMERAL)) {
IConsolePrint(CC_ERROR, "Command '{}' contains malformed characters.", cmdstr); IConsolePrint(CC_ERROR, "Command '{}' contains malformed characters.", command_string);
return; return;
} }
} }
Debug(console, 4, "Executing cmdline: '{}'", cmdstr); Debug(console, 4, "Executing cmdline: '{}'", command_string);
memset(&tokens, 0, sizeof(tokens)); memset(&tokens, 0, sizeof(tokens));
memset(&tokenstream, 0, sizeof(tokenstream)); memset(&tokenstream, 0, sizeof(tokenstream));
@ -317,7 +317,7 @@ void IConsoleCmdExec(const char *cmdstr, const uint recurse_count)
/* 1. Split up commandline into tokens, separated by spaces, commands /* 1. Split up commandline into tokens, separated by spaces, commands
* enclosed in "" are taken as one token. We can only go as far as the amount * enclosed in "" are taken as one token. We can only go as far as the amount
* of characters in our stream or the max amount of tokens we can handle */ * of characters in our stream or the max amount of tokens we can handle */
for (cmdptr = cmdstr, t_index = 0, tstream_i = 0; *cmdptr != '\0'; cmdptr++) { for (cmdptr = command_string.c_str(), t_index = 0, tstream_i = 0; *cmdptr != '\0'; cmdptr++) {
if (tstream_i >= lengthof(tokenstream)) { if (tstream_i >= lengthof(tokenstream)) {
IConsolePrint(CC_ERROR, "Command line too long."); IConsolePrint(CC_ERROR, "Command line too long.");
return; return;

View File

@ -47,7 +47,7 @@ static inline void IConsolePrint(TextColour colour_code, const T &format, A firs
} }
/* Parser */ /* Parser */
void IConsoleCmdExec(const char *cmdstr, const uint recurse_count = 0); void IConsoleCmdExec(const std::string &command_string, const uint recurse_count = 0);
bool IsValidConsoleColour(TextColour c); bool IsValidConsoleColour(TextColour c);

View File

@ -501,7 +501,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_RCON(Packet *p)
Debug(net, 3, "[admin] Rcon command from '{}' ({}): {}", this->admin_name, this->admin_version, command); Debug(net, 3, "[admin] Rcon command from '{}' ({}): {}", this->admin_name, this->admin_version, command);
_redirect_console_to_admin = this->index; _redirect_console_to_admin = this->index;
IConsoleCmdExec(command.c_str()); IConsoleCmdExec(command);
_redirect_console_to_admin = INVALID_ADMIN_ID; _redirect_console_to_admin = INVALID_ADMIN_ID;
return this->SendRconEnd(command); return this->SendRconEnd(command);
} }

View File

@ -1402,7 +1402,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p)
Debug(net, 3, "[rcon] Client-id {} executed: {}", this->client_id, command); Debug(net, 3, "[rcon] Client-id {} executed: {}", this->client_id, command);
_redirect_console_to_client = this->client_id; _redirect_console_to_client = this->client_id;
IConsoleCmdExec(command.c_str()); IConsoleCmdExec(command);
_redirect_console_to_client = INVALID_CLIENT_ID; _redirect_console_to_client = INVALID_CLIENT_ID;
return NETWORK_RECV_STATUS_OKAY; return NETWORK_RECV_STATUS_OKAY;
} }