remove regex aleta sio because of crash bug: https://github.com/otland/forgottenserver/pull/2965

This commit is contained in:
ErikasKontenis 2020-04-27 17:27:24 +03:00
parent 24a3e9b18c
commit 869e101428
2 changed files with 10 additions and 49 deletions

View File

@ -392,8 +392,7 @@ void AccessList::parseList(const std::string& list)
{
playerList.clear();
guildList.clear();
expressionList.clear();
regExList.clear();
allowEveryone = false;
this->list = list;
if (list.empty()) {
return;
@ -402,7 +401,12 @@ void AccessList::parseList(const std::string& list)
std::istringstream listStream(list);
std::string line;
int lineNo = 1;
while (getline(listStream, line)) {
if (++lineNo > 100) {
break;
}
trimString(line);
trim_left(line, '\t');
trim_right(line, '\t');
@ -418,7 +422,7 @@ void AccessList::parseList(const std::string& list)
if (at_pos != std::string::npos) {
addGuild(line.substr(at_pos + 1));
} else if (line.find("!") != std::string::npos || line.find("*") != std::string::npos || line.find("?") != std::string::npos) {
addExpression(line);
continue; // regexp no longer supported
} else {
addPlayer(line);
}
@ -446,50 +450,10 @@ void AccessList::addGuild(const std::string& name)
}
}
void AccessList::addExpression(const std::string& expression)
{
if (std::find(expressionList.begin(), expressionList.end(), expression) != expressionList.end()) {
return;
}
std::string outExp;
outExp.reserve(expression.length());
std::string metachars = ".[{}()\\+|^$";
for (const char c : expression) {
if (metachars.find(c) != std::string::npos) {
outExp.push_back('\\');
}
outExp.push_back(c);
}
replaceString(outExp, "*", ".*");
replaceString(outExp, "?", ".?");
try {
if (!outExp.empty()) {
expressionList.push_back(outExp);
if (outExp.front() == '!') {
if (outExp.length() > 1) {
regExList.emplace_front(std::regex(outExp.substr(1)), false);
}
} else {
regExList.emplace_back(std::regex(outExp), true);
}
}
} catch (...) {}
}
bool AccessList::isInList(const Player* player)
{
std::string name = asLowerCaseString(player->getName());
std::cmatch what;
for (const auto& it : regExList) {
if (std::regex_match(name.c_str(), what, it.first)) {
return it.second;
}
if (allowEveryone) {
return true;
}
auto playerIt = playerList.find(player->getGUID());

View File

@ -20,7 +20,6 @@
#ifndef FS_HOUSE_H_EB9732E7771A438F9CD0EFA8CB4C58C4
#define FS_HOUSE_H_EB9732E7771A438F9CD0EFA8CB4C58C4
#include <regex>
#include <set>
#include "container.h"
@ -37,7 +36,6 @@ class AccessList
void parseList(const std::string& list);
void addPlayer(const std::string& name);
void addGuild(const std::string& name);
void addExpression(const std::string& expression);
bool isInList(const Player* player);
@ -47,8 +45,7 @@ class AccessList
std::string list;
std::unordered_set<uint32_t> playerList;
std::unordered_set<uint32_t> guildList; // TODO: include ranks
std::list<std::string> expressionList;
std::list<std::pair<std::regex, bool>> regExList;
bool allowEveryone = false;
};
class Door final : public Item