Codechange: let IConsoleCmdExec accept std::string

pull/603/head
Rubidium 11 months ago committed by rubidium42
parent fd380127f0
commit f333372dd1

@ -225,7 +225,7 @@ static void IConsoleAliasExec(const IConsoleAlias *alias, byte tokencount, char
break;
case ';': // Cmd separator; execute previous and start new command
IConsoleCmdExec(alias_buffer.c_str(), recurse_count);
IConsoleCmdExec(alias_buffer, recurse_count);
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
* 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;
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 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)) {
IConsolePrint(CC_ERROR, "Command '{}' contains malformed characters.", cmdstr);
IConsolePrint(CC_ERROR, "Command '{}' contains malformed characters.", command_string);
return;
}
}
Debug(console, 4, "Executing cmdline: '{}'", cmdstr);
Debug(console, 4, "Executing cmdline: '{}'", command_string);
memset(&tokens, 0, sizeof(tokens));
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
* 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 */
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)) {
IConsolePrint(CC_ERROR, "Command line too long.");
return;

@ -47,7 +47,7 @@ static inline void IConsolePrint(TextColour colour_code, const T &format, A firs
}
/* 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);

@ -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);
_redirect_console_to_admin = this->index;
IConsoleCmdExec(command.c_str());
IConsoleCmdExec(command);
_redirect_console_to_admin = INVALID_ADMIN_ID;
return this->SendRconEnd(command);
}

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

Loading…
Cancel
Save