diff --git a/common/server.cpp b/common/server.cpp index 7274800c..2540ea52 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -262,6 +262,18 @@ void Server::removeClient(Server_ProtocolHandler *client) qDebug() << "Server::removeClient: removed" << (void *) client << ";" << clients.size() << "clients; " << users.size() << "users left"; } +QList Server::getOnlineModeratorList() +{ + // clients list should be locked by calling function prior to iteration otherwise sigfaults may occur + QList 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) { // This function is always called from the main thread via signal/slot. diff --git a/common/server.h b/common/server.h index 56af0bc4..9dc40fff 100644 --- a/common/server.h +++ b/common/server.h @@ -57,6 +57,7 @@ public: virtual QMap getServerRequiredFeatureList() const { return QMap(); } void addClient(Server_ProtocolHandler *player); void removeClient(Server_ProtocolHandler *player); + QList getOnlineModeratorList(); virtual QString getLoginMessage() const { return QString(); } virtual bool permitUnregisteredUsers() const { return true; } virtual bool getGameShouldPing() const { return false; } diff --git a/servatrice/src/serversocketinterface.cpp b/servatrice/src/serversocketinterface.cpp index e55104ca..ccf8cb87 100644 --- a/servatrice/src/serversocketinterface.cpp +++ b/servatrice/src/serversocketinterface.cpp @@ -858,7 +858,11 @@ Response::ResponseCode ServerSocketInterface::cmdWarnUser(const Command_WarnUser QString sendingModerator = QString::fromStdString(userInfo->name()).simplified(); if (sqlInterface->addWarning(userName, sendingModerator, warningReason, clientID)) { + servatrice->clientsLock.lockForRead(); ServerSocketInterface *user = static_cast(server->getUsers().value(userName)); + QList moderatorList = server->getOnlineModeratorList(); + servatrice->clientsLock.unlock(); + if (user) { Event_NotifyUser event; event.set_type(Event_NotifyUser::WARNING); @@ -868,6 +872,13 @@ Response::ResponseCode ServerSocketInterface::cmdWarnUser(const Command_WarnUser delete se; } + QListIterator 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; } else { @@ -903,6 +914,7 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban sqlInterface->execSqlQuery(query); servatrice->clientsLock.lockForRead(); + QList moderatorList = server->getOnlineModeratorList(); QList userList = servatrice->getUsersWithAddressAsList(QHostAddress(address)); if (!userName.isEmpty()) { @@ -926,6 +938,7 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban } } } + servatrice->clientsLock.unlock(); if (!userList.isEmpty()) { Event_ConnectionClosed event; @@ -941,7 +954,22 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban QMetaObject::invokeMethod(userList[i], "prepareDestroy", Qt::QueuedConnection); } } - servatrice->clientsLock.unlock(); + + QListIterator 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; }