mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-28 11:53:11 -07:00
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:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user