mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-25 15:07:28 +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;
|
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::vector<std::u16string> vector = std::vector<std::u16string>();
|
||||||
std::u16string current;
|
std::u16string current;
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ namespace GeneralUtils {
|
|||||||
|
|
||||||
std::vector<std::wstring> SplitString(std::wstring& str, wchar_t delimiter);
|
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);
|
std::vector<std::string> SplitString(const std::string& str, char delimiter);
|
||||||
|
|
||||||
|
@ -82,44 +82,24 @@
|
|||||||
#include "CDZoneTableTable.h"
|
#include "CDZoneTableTable.h"
|
||||||
|
|
||||||
void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entity* entity, const SystemAddress& sysAddr) {
|
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::string chatCommand;
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
|
auto wideCommand = GeneralUtils::SplitString(commandCopy, u' ');
|
||||||
|
if (wideCommand.empty()) return;
|
||||||
|
|
||||||
uint32_t breakIndex = 0;
|
// Convert the command to lowercase
|
||||||
for (uint32_t i = 1; i < command.size(); ++i) {
|
chatCommand = GeneralUtils::UTF16ToWTF8(wideCommand.front());
|
||||||
if (command[i] == L' ') {
|
std::transform(chatCommand.begin(), chatCommand.end(), chatCommand.begin(), ::tolower);
|
||||||
breakIndex = i;
|
wideCommand.erase(wideCommand.begin());
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
chatCommand.push_back(static_cast<unsigned char>(command[i]));
|
// Convert the arguements to not u16strings
|
||||||
breakIndex++;
|
for (auto wideArg : wideCommand) args.push_back(GeneralUtils::UTF16ToWTF8(wideArg));
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
|
|
||||||
User* user = UserManager::Instance()->GetUser(sysAddr);
|
User* user = UserManager::Instance()->GetUser(sysAddr);
|
||||||
if ((chatCommand == "setgmlevel" || chatCommand == "makegm" || chatCommand == "gmlevel") && user->GetMaxGMLevel() > eGameMasterLevel::CIVILIAN) {
|
if ((chatCommand == "setgmlevel" || chatCommand == "makegm" || chatCommand == "gmlevel") && user->GetMaxGMLevel() > eGameMasterLevel::CIVILIAN) {
|
||||||
|
Loading…
Reference in New Issue
Block a user