mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-22 21:43:35 +00:00
Allow case insensitive commands (#1047)
This commit is contained in:
parent
541250176c
commit
33f9e9c8cb
@ -241,7 +241,7 @@ std::vector<std::wstring> GeneralUtils::SplitString(std::wstring& str, wchar_t d
|
||||
return vector;
|
||||
}
|
||||
|
||||
std::vector<std::u16string> GeneralUtils::SplitString(std::u16string& str, char16_t delimiter) {
|
||||
std::vector<std::u16string> GeneralUtils::SplitString(const std::u16string& str, char16_t delimiter) {
|
||||
std::vector<std::u16string> vector = std::vector<std::u16string>();
|
||||
std::u16string current;
|
||||
|
||||
|
@ -139,7 +139,7 @@ namespace GeneralUtils {
|
||||
|
||||
std::vector<std::wstring> SplitString(std::wstring& str, wchar_t delimiter);
|
||||
|
||||
std::vector<std::u16string> SplitString(std::u16string& str, char16_t delimiter);
|
||||
std::vector<std::u16string> SplitString(const std::u16string& str, char16_t delimiter);
|
||||
|
||||
std::vector<std::string> SplitString(const std::string& str, char delimiter);
|
||||
|
||||
|
@ -82,44 +82,24 @@
|
||||
#include "CDZoneTableTable.h"
|
||||
|
||||
void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entity* entity, const SystemAddress& sysAddr) {
|
||||
auto commandCopy = command;
|
||||
// Sanity check that a command was given
|
||||
if (command.empty() || command.front() != u'/') return;
|
||||
commandCopy.erase(commandCopy.begin());
|
||||
|
||||
// Split the command by spaces
|
||||
std::string chatCommand;
|
||||
std::vector<std::string> args;
|
||||
auto wideCommand = GeneralUtils::SplitString(commandCopy, u' ');
|
||||
if (wideCommand.empty()) return;
|
||||
|
||||
uint32_t breakIndex = 0;
|
||||
for (uint32_t i = 1; i < command.size(); ++i) {
|
||||
if (command[i] == L' ') {
|
||||
breakIndex = i;
|
||||
break;
|
||||
}
|
||||
// Convert the command to lowercase
|
||||
chatCommand = GeneralUtils::UTF16ToWTF8(wideCommand.front());
|
||||
std::transform(chatCommand.begin(), chatCommand.end(), chatCommand.begin(), ::tolower);
|
||||
wideCommand.erase(wideCommand.begin());
|
||||
|
||||
chatCommand.push_back(static_cast<unsigned char>(command[i]));
|
||||
breakIndex++;
|
||||
}
|
||||
|
||||
uint32_t index = ++breakIndex;
|
||||
while (true) {
|
||||
std::string arg;
|
||||
|
||||
while (index < command.size()) {
|
||||
if (command[index] == L' ') {
|
||||
args.push_back(arg);
|
||||
arg = "";
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
|
||||
arg.push_back(static_cast<char>(command[index]));
|
||||
index++;
|
||||
}
|
||||
|
||||
if (arg != "") {
|
||||
args.push_back(arg);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
//Game::logger->Log("SlashCommandHandler", "Received chat command \"%s\"", GeneralUtils::UTF16ToWTF8(command).c_str());
|
||||
// Convert the arguements to not u16strings
|
||||
for (auto wideArg : wideCommand) args.push_back(GeneralUtils::UTF16ToWTF8(wideArg));
|
||||
|
||||
User* user = UserManager::Instance()->GetUser(sysAddr);
|
||||
if ((chatCommand == "setgmlevel" || chatCommand == "makegm" || chatCommand == "gmlevel") && user->GetMaxGMLevel() > eGameMasterLevel::CIVILIAN) {
|
||||
|
Loading…
Reference in New Issue
Block a user