Re-Implemented the moderator notification upon user warning/ban

This commit is contained in:
woogerboy21 2015-09-28 18:19:10 -04:00
parent 9c4bd8ebed
commit acbe2b0b3c
3 changed files with 42 additions and 1 deletions

View file

@ -262,6 +262,18 @@ void Server::removeClient(Server_ProtocolHandler *client)
qDebug() << "Server::removeClient: removed" << (void *) client << ";" << clients.size() << "clients; " << users.size() << "users left"; qDebug() << "Server::removeClient: removed" << (void *) client << ";" << clients.size() << "clients; " << users.size() << "users left";
} }
QList<QString> Server::getOnlineModeratorList()
{
// clients list should be locked by calling function prior to iteration otherwise sigfaults may occur
QList<QString> results;
for (int i = 0; i < clients.size(); ++i) {
ServerInfo_User *data = clients[i]->getUserInfo();
if (data->user_level() & ServerInfo_User::IsModerator || data->user_level() & ServerInfo_User::IsAdmin) //TODO: this line should be updated in the event there is any type of new user level created
results << QString::fromStdString(data->name()).simplified();
}
return results;
}
void Server::externalUserJoined(const ServerInfo_User &userInfo) void Server::externalUserJoined(const ServerInfo_User &userInfo)
{ {
// This function is always called from the main thread via signal/slot. // This function is always called from the main thread via signal/slot.

View file

@ -57,6 +57,7 @@ public:
virtual QMap<QString, bool> getServerRequiredFeatureList() const { return QMap<QString, bool>(); } virtual QMap<QString, bool> getServerRequiredFeatureList() const { return QMap<QString, bool>(); }
void addClient(Server_ProtocolHandler *player); void addClient(Server_ProtocolHandler *player);
void removeClient(Server_ProtocolHandler *player); void removeClient(Server_ProtocolHandler *player);
QList<QString> getOnlineModeratorList();
virtual QString getLoginMessage() const { return QString(); } virtual QString getLoginMessage() const { return QString(); }
virtual bool permitUnregisteredUsers() const { return true; } virtual bool permitUnregisteredUsers() const { return true; }
virtual bool getGameShouldPing() const { return false; } virtual bool getGameShouldPing() const { return false; }

View file

@ -858,7 +858,11 @@ Response::ResponseCode ServerSocketInterface::cmdWarnUser(const Command_WarnUser
QString sendingModerator = QString::fromStdString(userInfo->name()).simplified(); QString sendingModerator = QString::fromStdString(userInfo->name()).simplified();
if (sqlInterface->addWarning(userName, sendingModerator, warningReason, clientID)) { if (sqlInterface->addWarning(userName, sendingModerator, warningReason, clientID)) {
servatrice->clientsLock.lockForRead();
ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName)); ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName));
QList<QString> moderatorList = server->getOnlineModeratorList();
servatrice->clientsLock.unlock();
if (user) { if (user) {
Event_NotifyUser event; Event_NotifyUser event;
event.set_type(Event_NotifyUser::WARNING); event.set_type(Event_NotifyUser::WARNING);
@ -868,6 +872,13 @@ Response::ResponseCode ServerSocketInterface::cmdWarnUser(const Command_WarnUser
delete se; delete se;
} }
QListIterator<QString> modIterator(moderatorList);
foreach(QString moderator, moderatorList) {
QString notificationMessage = sendingModerator + " has sent a warning with the following information";
notificationMessage.append("\n Username: " + userName);
notificationMessage.append("\n Reason: " + warningReason);
sendServerMessage(moderator.simplified(), notificationMessage);
}
return Response::RespOk; return Response::RespOk;
} else { } else {
@ -903,6 +914,7 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban
sqlInterface->execSqlQuery(query); sqlInterface->execSqlQuery(query);
servatrice->clientsLock.lockForRead(); servatrice->clientsLock.lockForRead();
QList<QString> moderatorList = server->getOnlineModeratorList();
QList<ServerSocketInterface *> userList = servatrice->getUsersWithAddressAsList(QHostAddress(address)); QList<ServerSocketInterface *> userList = servatrice->getUsersWithAddressAsList(QHostAddress(address));
if (!userName.isEmpty()) { if (!userName.isEmpty()) {
@ -926,6 +938,7 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban
} }
} }
} }
servatrice->clientsLock.unlock();
if (!userList.isEmpty()) { if (!userList.isEmpty()) {
Event_ConnectionClosed event; Event_ConnectionClosed event;
@ -941,7 +954,22 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban
QMetaObject::invokeMethod(userList[i], "prepareDestroy", Qt::QueuedConnection); QMetaObject::invokeMethod(userList[i], "prepareDestroy", Qt::QueuedConnection);
} }
} }
servatrice->clientsLock.unlock();
QListIterator<QString> modIterator(moderatorList);
foreach(QString moderator, moderatorList) {
QString notificationMessage = QString::fromStdString(userInfo->name()).simplified() + " has placed a ban with the following information";
if (!userName.isEmpty())
notificationMessage.append("\n Username: " + userName);
if (!address.isEmpty())
notificationMessage.append("\n IP Address: " + address);
if (!clientID.isEmpty())
notificationMessage.append("\n Client ID: " + clientID);
notificationMessage.append("\n Length: " + QString::number(minutes) + " minute(s)");
notificationMessage.append("\n Internal Reason: " + QString::fromStdString(cmd.reason()));
notificationMessage.append("\n Visible Reason: " + QString::fromStdString(cmd.visible_reason()));
sendServerMessage(moderator.simplified(), notificationMessage);
}
return Response::RespOk; return Response::RespOk;
} }