Make code redemption case-insensitive

This commit is contained in:
Gent S 2020-12-23 00:34:42 -05:00
parent ae75324153
commit 52389c2c69

View File

@ -723,7 +723,18 @@ void redeemCommand(std::string full, std::vector<std::string>& args, CNSocket* s
return; return;
} }
std::string code = args[1]; // convert string to all lowercase
const char* codeRaw = args[1].c_str();
if (args[1].size() > 256) { // prevent overflow
ChatManager::sendServerMessage(sock, "/redeem: Code too long");
return;
}
char buf[256];
for (int i = 0; i < args[1].size(); i++)
buf[i] = std::tolower(codeRaw[i]);
std::string code(buf, args[1].size());
if (ItemManager::CodeItems.find(code) == ItemManager::CodeItems.end()) { if (ItemManager::CodeItems.find(code) == ItemManager::CodeItems.end()) {
ChatManager::sendServerMessage(sock, "/redeem: Unknown code"); ChatManager::sendServerMessage(sock, "/redeem: Unknown code");
return; return;