fix: terrorist behaviour on ES maps with buyzone. (fixes #155).

fix: help commands causing host overflow when translated.
crlib: use fnv1a for string hashes.
crlib: add hash () method  to String & StringRef classes.
This commit is contained in:
ds 2020-09-11 16:01:33 +03:00
commit 8acd84fdc8
6 changed files with 35 additions and 48 deletions

View file

@ -1064,7 +1064,7 @@ void Bot::checkMsgQueue () {
// prevent terrorists from buying on es maps
if (game.mapIs (MapFlags::Escape) && m_team == Team::Terrorist) {
m_buyState = 6;
m_buyState = BuyState::Done;;
}
// prevent teams from buying on fun maps

View file

@ -764,23 +764,17 @@ const char *BotConfig::translate (StringRef input) {
return input.chars (); // nothing found
}
uint32 BotConfig::hashLangString (const char *input) {
auto str = reinterpret_cast <uint8 *> (const_cast <char *> (input));
uint32_t hash = 0;
uint32 BotConfig::hashLangString (StringRef str) {
auto test = [] (const char ch) {
return (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
};
String res;
for (; *str; ++str) {
if (!isalnum (*str)) {
for (const auto &ch : str) {
if (!test (ch)) {
continue;
}
hash += *str;
hash += (hash << 10);
hash ^= (hash >> 6);
res += ch;
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return hash;
return res.empty () ? 0 : res.hash ();
}

View file

@ -360,7 +360,9 @@ int BotControl::cmdNode () {
if (strValue (cmd) == "help" && hasArg (cmd2) && commands.has (strValue (cmd2))) {
auto &item = commands[strValue (cmd2)];
msg ("Command: \"%s %s %s\"\nFormat: %s\nHelp: %s", m_args[root], m_args[alias], item.name, item.format, conf.translate (item.help));
msg ("Command: \"%s %s %s\"", m_args[root], m_args[alias], item.name);
msg ("Format: %s", item.format);
msg ("Help: %s", conf.translate (item.help));
}
else {
for (auto &desc : descriptions) {
@ -1583,7 +1585,9 @@ bool BotControl::executeCommands () {
}
if ((hasSecondArg && aliasMatch (item.name, m_args[2], cmd)) || !hasSecondArg) {
msg ("Command: \"%s %s\"\nFormat: %s\nHelp: %s", prefix, cmd, item.format, conf.translate (item.help));
msg ("Command: \"%s %s\"", prefix, cmd);
msg ("Format: %s", item.format);
msg ("Help: %s", conf.translate (item.help));
auto aliases = item.name.split ("/");