parent
7f718503bd
commit
59d1623dbd
|
@ -305,6 +305,9 @@ void Room::chat(ServerPlayer *sender, const QString &jsonData) {
|
||||||
auto msg = doc["msg"].toString();
|
auto msg = doc["msg"].toString();
|
||||||
msg.replace(".", "․");
|
msg.replace(".", "․");
|
||||||
doc["msg"] = msg;
|
doc["msg"] = msg;
|
||||||
|
if (!server->checkBanWord(msg)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (type == 1) {
|
if (type == 1) {
|
||||||
doc["userName"] = sender->getScreenName();
|
doc["userName"] = sender->getScreenName();
|
||||||
|
|
|
@ -95,6 +95,12 @@ bool Server::listen(const QHostAddress &address, ushort port) {
|
||||||
|
|
||||||
void Server::createRoom(ServerPlayer *owner, const QString &name, int capacity,
|
void Server::createRoom(ServerPlayer *owner, const QString &name, int capacity,
|
||||||
int timeout, const QByteArray &settings) {
|
int timeout, const QByteArray &settings) {
|
||||||
|
if (!checkBanWord(name)) {
|
||||||
|
if (owner) {
|
||||||
|
owner->doNotify("ErrorMsg", "unk error");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
Room *room;
|
Room *room;
|
||||||
if (!idle_rooms.isEmpty()) {
|
if (!idle_rooms.isEmpty()) {
|
||||||
room = idle_rooms.pop();
|
room = idle_rooms.pop();
|
||||||
|
@ -332,7 +338,7 @@ void Server::handleNameAndPassword(ClientSocket *client, const QString &name,
|
||||||
QJsonArray result;
|
QJsonArray result;
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
|
|
||||||
if (CheckSqlString(name)) {
|
if (CheckSqlString(name) && checkBanWord(name)) {
|
||||||
// Then we check the database,
|
// Then we check the database,
|
||||||
QString sql_find = QString("SELECT * FROM userinfo \
|
QString sql_find = QString("SELECT * FROM userinfo \
|
||||||
WHERE name='%1';")
|
WHERE name='%1';")
|
||||||
|
@ -541,3 +547,17 @@ void Server::readConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonValue Server::getConfig(const QString &key) { return config.value(key); }
|
QJsonValue Server::getConfig(const QString &key) { return config.value(key); }
|
||||||
|
|
||||||
|
bool Server::checkBanWord(const QString &str) {
|
||||||
|
auto arr = getConfig("banwords").toArray();
|
||||||
|
if (arr.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
foreach (auto v, arr) {
|
||||||
|
auto s = v.toString();
|
||||||
|
if (str.indexOf(s) != -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ public:
|
||||||
bool isListening;
|
bool isListening;
|
||||||
|
|
||||||
QJsonValue getConfig(const QString &command);
|
QJsonValue getConfig(const QString &command);
|
||||||
|
bool checkBanWord(const QString &str);
|
||||||
signals:
|
signals:
|
||||||
void roomCreated(Room *room);
|
void roomCreated(Room *room);
|
||||||
void playerAdded(ServerPlayer *player);
|
void playerAdded(ServerPlayer *player);
|
||||||
|
|
Loading…
Reference in New Issue