Added server private message functionality to allow server based PM notifications.

Ban based notification to other online moderators is the first form implemented by this PR.
This commit is contained in:
woogerboy21
2015-09-17 15:32:10 -04:00
parent afc425e6a5
commit b0693299c7
6 changed files with 84 additions and 26 deletions

View File

@@ -51,6 +51,7 @@
#include "pb/event_add_to_list.pb.h"
#include "pb/event_remove_from_list.pb.h"
#include "pb/event_notify_user.pb.h"
#include "pb/event_user_message.pb.h"
#include "pb/response_ban_history.pb.h"
#include "pb/response_deck_list.pb.h"
#include "pb/response_deck_download.pb.h"
@@ -520,6 +521,20 @@ void ServerSocketInterface::deckDelDirHelper(int basePathId)
sqlInterface->execSqlQuery(query);
}
void ServerSocketInterface::sendServerMessage(const QString userName, const QString message)
{
ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName));
if (user) {
Event_UserMessage event;
event.set_sender_name("Servatrice");
event.set_receiver_name(userName.toStdString());
event.set_message(message.toStdString());
SessionEvent *se = user->prepareSessionEvent(event);
user->sendProtocolItem(*se);
delete se;
}
}
Response::ResponseCode ServerSocketInterface::cmdDeckDelDir(const Command_DeckDelDir &cmd, ResponseContainer & /*rc*/)
{
if (authState != PasswordRight)
@@ -795,7 +810,7 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban
if (!userName.isEmpty()) {
ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName));
if (user)
if (user && !userList.contains(user))
userList.append(user);
}
@@ -831,6 +846,23 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban
}
servatrice->clientsLock.unlock();
QList<QString> moderatorList = server->getOnlineModeratorList();
QListIterator<QString> modIterator(moderatorList);
foreach(QString moderator, moderatorList) {
QString notificationMessage = "A ban has been put in with the following details:";
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;
}
@@ -863,6 +895,9 @@ Response::ResponseCode ServerSocketInterface::cmdRegisterAccount(const Command_R
return Response::RespUsernameInvalid;
}
if (userName.toLower() == "servatrice")
return Response::RespUsernameInvalid;
if(sqlInterface->userExists(userName))
return Response::RespUserAlreadyExists;

View File

@@ -86,6 +86,7 @@ private:
Response::ResponseCode cmdDeckList(const Command_DeckList &cmd, ResponseContainer &rc);
Response::ResponseCode cmdDeckNewDir(const Command_DeckNewDir &cmd, ResponseContainer &rc);
void deckDelDirHelper(int basePathId);
void sendServerMessage(const QString userName, const QString message);
Response::ResponseCode cmdDeckDelDir(const Command_DeckDelDir &cmd, ResponseContainer &rc);
Response::ResponseCode cmdDeckDel(const Command_DeckDel &cmd, ResponseContainer &rc);
Response::ResponseCode cmdDeckUpload(const Command_DeckUpload &cmd, ResponseContainer &rc);