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

@ -130,7 +130,7 @@ void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType,
lastSender = sender;
// timestamp
if (showTimestamps && !sameSender && !sender.isEmpty()) {
if (showTimestamps && (!sameSender || sender.toLower() == "servatrice") && !sender.isEmpty()) {
QTextCharFormat timeFormat;
timeFormat.setForeground(QColor(SERVER_MESSAGE_COLOR));
if (sender.isEmpty())
@ -140,8 +140,10 @@ void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType,
}
// nickname
if (sender.toLower() != "servatrice") {
QTextCharFormat senderFormat;
if (tabSupervisor && tabSupervisor->getUserInfo() && (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) {
if (tabSupervisor && tabSupervisor->getUserInfo() &&
(sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) {
senderFormat.setForeground(QBrush(getCustomMentionColor()));
senderFormat.setFontWeight(QFont::Bold);
} else {
@ -157,7 +159,8 @@ void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType,
if (!sender.isEmpty() && tabSupervisor->getUserListsTab()) {
const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize();
QMap<QString, UserListTWI *> buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers();
cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel, buddyList.contains(sender)).toImage());
cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel,
buddyList.contains(sender)).toImage());
cursor.insertText(" ");
}
cursor.setCharFormat(senderFormat);
@ -165,6 +168,7 @@ void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType,
sender.append(": ");
cursor.insertText(sender);
}
}
// use different color for server messages
defaultFormat = QTextCharFormat();
@ -180,6 +184,9 @@ void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType,
defaultFormat.setFontItalic(true);
break;
}
} else if (sender.toLower() == "servatrice") {
defaultFormat.setForeground(Qt::darkGreen);
defaultFormat.setFontWeight(QFont::Bold);
}
cursor.setCharFormat(defaultFormat);

View file

@ -116,6 +116,8 @@ void TabMessage::processUserMessageEvent(const Event_UserMessage &event)
soundEngine->playSound("private_message");
if (settingsCache->getShowMessagePopup() && shouldShowSystemPopup(event))
showSystemPopup(event);
if (QString::fromStdString(event.sender_name()).simplified() == "Servatrice")
sayEdit->setDisabled(true);
emit userEvent();
}

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";
}
QList<QString> Server::getOnlineModeratorList()
{
QList<QString> results;
QReadLocker clientsLocker(&clientsLock);
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.

View file

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

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);