Added chat history to a room that is displayed on join.

With this update a new chat history definition is added on a per
room bases which allows operators to specify the number of chat
messages to store and present to the user on join.  Please see
the sample ini for room definitions.
This commit is contained in:
woogerboy21 2015-09-12 13:46:22 -04:00
parent f97a7e8370
commit 87a64da1bc
23 changed files with 141 additions and 16 deletions

View file

@ -17,6 +17,7 @@ void FeatureSet::initalizeFeatureList(QMap<QString, bool> &featureList){
featureList.insert("client_ver", false);
featureList.insert("feature_set", false);
featureList.insert("user_ban_history", false);
featureList.insert("room_chat_history", false);
}
void FeatureSet::enableRequiredFeature(QMap<QString, bool> &featureList, QString featureName){

View file

@ -137,6 +137,7 @@ SET(PROTO_FILES
serverinfo_ban.proto
serverinfo_cardcounter.proto
serverinfo_card.proto
serverinfo_chat_message.proto
serverinfo_counter.proto
serverinfo_deckstorage.proto
serverinfo_game.proto

View file

@ -5,6 +5,13 @@ message Event_RoomSay {
extend RoomEvent {
optional Event_RoomSay ext = 1002;
}
enum RoomMessageType {
Welcome = 1; // rooms welcome message
ChatHistory = 2; // rooms chat history message
}
optional string name = 1;
optional string message = 2;
optional RoomMessageType message_type = 3;
optional uint64 time_of = 4;
}

View file

@ -0,0 +1,16 @@
syntax = "proto2";
/*
* Chat communication of a user to a target.
* Targets can be users or rooms.
* These communications are also stored in the DB log table.
*/
message ServerInfo_ChatMessage {
optional string time = 1; // time chat was sent
optional string sender_id = 2; // id of sender
optional string sender_name = 3; // name of sender
optional string sender_ip = 4; // ip of sender
optional string message = 5; // message
optional string target_type = 6; // target type (room,game,chat)
optional string target_id = 7; // id of target
optional string target_name = 8; // name of target
}

View file

@ -0,0 +1,15 @@
#ifndef ROOM_MESSAGE_TYPE_H
#define ROOM_MESSAGE_TYPE_H
#ifdef Q_OS_OSX
// avoid collision from Mac OS X's ConditionalMacros.h
// https://code.google.com/p/protobuf/issues/detail?id=119
#undef TYPE_BOOL
#endif
#include "pb/event_room_say.pb.h"
#include <QFlags>
Q_DECLARE_FLAGS(RoomMessageTypeFlags, Event_RoomSay::RoomMessageType)
Q_DECLARE_OPERATORS_FOR_FLAGS(RoomMessageTypeFlags)
#endif

View file

@ -600,8 +600,19 @@ Response::ResponseCode Server_ProtocolHandler::cmdJoinRoom(const Command_JoinRoo
Event_RoomSay joinMessageEvent;
joinMessageEvent.set_message(r->getJoinMessage().toStdString());
joinMessageEvent.set_message_type(Event_RoomSay::Welcome);
rc.enqueuePostResponseItem(ServerMessage::ROOM_EVENT, r->prepareRoomEvent(joinMessageEvent));
ServerInfo_ChatMessage chatMessage; for (int i = 0; i < r->chatHistory.size(); ++i) {
chatMessage = r->chatHistory.at(i);
qDebug() << QString::fromStdString(chatMessage.message()).simplified();
Event_RoomSay roomChatHistory;
roomChatHistory.set_message(chatMessage.sender_name() + ": " + chatMessage.message());
roomChatHistory.set_message_type(Event_RoomSay::ChatHistory);
roomChatHistory.set_time_of(QDateTime::fromString(QString::fromStdString(chatMessage.time())).toMSecsSinceEpoch());
rc.enqueuePostResponseItem(ServerMessage::ROOM_EVENT, r->prepareRoomEvent(roomChatHistory));
}
Response_JoinRoom *re = new Response_JoinRoom;
r->getInfo(*re->mutable_room_info(), true);

View file

@ -2,6 +2,7 @@
#include "server_protocolhandler.h"
#include "server_game.h"
#include <QDebug>
#include <QDateTime>
#include "pb/commands.pb.h"
#include "pb/room_commands.pb.h"
@ -10,10 +11,11 @@
#include "pb/event_list_games.pb.h"
#include "pb/event_room_say.pb.h"
#include "pb/serverinfo_room.pb.h"
#include "pb/serverinfo_chat_message.pb.h"
#include <google/protobuf/descriptor.h>
Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, const QString &_permissionLevel, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
: QObject(parent), id(_id), name(_name), description(_description), permissionLevel(_permissionLevel), autoJoin(_autoJoin), joinMessage(_joinMessage), gameTypes(_gameTypes), gamesLock(QReadWriteLock::Recursive)
Server_Room::Server_Room(int _id, int _chatHistorySize, const QString &_name, const QString &_description, const QString &_permissionLevel, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
: QObject(parent), id(_id), chatHistorySize(_chatHistorySize), name(_name), description(_description), permissionLevel(_permissionLevel), autoJoin(_autoJoin), joinMessage(_joinMessage), gameTypes(_gameTypes), gamesLock(QReadWriteLock::Recursive)
{
connect(this, SIGNAL(gameListChanged(ServerInfo_Game)), this, SLOT(broadcastGameListUpdate(ServerInfo_Game)), Qt::QueuedConnection);
}
@ -232,6 +234,22 @@ void Server_Room::say(const QString &userName, const QString &s, bool sendToIsl)
event.set_name(userName.toStdString());
event.set_message(s.toStdString());
sendRoomEvent(prepareRoomEvent(event), sendToIsl);
if (chatHistorySize != 0) {
ServerInfo_ChatMessage chatMessage;
QDateTime dateTime = dateTime.currentDateTimeUtc();
QString dateTimeString = dateTime.toString();
chatMessage.set_time(dateTimeString.toStdString());
chatMessage.set_sender_name(userName.toStdString());
chatMessage.set_message(s.simplified().toStdString());
if (chatHistory.size() >= chatHistorySize)
chatHistory.removeAt(0);
chatHistory << chatMessage;
}
}
void Server_Room::sendRoomEvent(RoomEvent *event, bool sendToIsl)

View file

@ -9,6 +9,7 @@
#include <QReadWriteLock>
#include "serverinfo_user_container.h"
#include "pb/response.pb.h"
#include "pb/serverinfo_chat_message.pb.h"
class Server_DatabaseInterface;
class Server_ProtocolHandler;
@ -30,6 +31,7 @@ signals:
void gameListChanged(const ServerInfo_Game &gameInfo);
private:
int id;
int chatHistorySize;
QString name;
QString description;
QString permissionLevel;
@ -45,7 +47,8 @@ private slots:
public:
mutable QReadWriteLock usersLock;
mutable QReadWriteLock gamesLock;
Server_Room(int _id, const QString &_name, const QString &_description, const QString &_permissionLevel, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent);
QList<ServerInfo_ChatMessage> chatHistory;
Server_Room(int _id, int _chatHistorySize, const QString &_name, const QString &_description, const QString &_permissionLevel, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent );
~Server_Room();
int getId() const { return id; }
QString getName() const { return name; }
@ -60,6 +63,7 @@ public:
const ServerInfo_Room &getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes = false, bool includeExternalData = true) const;
int getGamesCreatedByUser(const QString &name) const;
QList<ServerInfo_Game> getGamesOfUser(const QString &name) const;
QList<ServerInfo_ChatMessage> getChatHistory() { return chatHistory; }
void addClient(Server_ProtocolHandler *client);
void removeClient(Server_ProtocolHandler *client);