Skip to content

Commit

Permalink
👣 Bugfixed commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Lygaen committed Feb 9, 2024
1 parent 60049ad commit 01f4e1e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cmd/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ CommandsManager::CallCommandError CommandsManager::callCommand(const ISender::Se
if (type != ISender::SenderType::CONSOLE)
throw std::runtime_error("Player and console logic not yet implemented");

// Remove trailing spaces
commandString = std::regex_replace(commandString, std::regex(" +$"), "");
commandString += " ";

size_t pos, startPos = 0;
std::vector<std::string> splittedString;
while ((pos = commandString.find(" ", startPos)) != std::string::npos)
Expand All @@ -64,6 +67,9 @@ CommandsManager::CallCommandError CommandsManager::callCommand(const ISender::Se
std::string name = splittedString[0];
std::vector<std::string> args(splittedString.begin() + 1, splittedString.end());

if (!std::regex_match(name, nameRegex))
return CommandsManager::FORMAT;

if (!commands.contains(name))
return CommandsManager::COMMAND_NOT_FOUND;

Expand Down

0 comments on commit 01f4e1e

Please sign in to comment.