From 87a64da1bc7898b0a08b3708a74bd7f70acef117 Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Sat, 12 Sep 2015 13:46:22 -0400 Subject: [PATCH] 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. --- cockatrice/src/chatview.cpp | 18 +++++++++++---- cockatrice/src/chatview.h | 3 ++- cockatrice/src/dlg_settings.cpp | 7 +++++- cockatrice/src/dlg_settings.h | 1 + cockatrice/src/localserver.cpp | 2 +- cockatrice/src/messagelogwidget.cpp | 4 ++-- cockatrice/src/settingscache.cpp | 6 +++++ cockatrice/src/settingscache.h | 3 +++ cockatrice/src/tab_message.cpp | 2 +- cockatrice/src/tab_room.cpp | 15 ++++++++++++- common/featureset.cpp | 1 + common/pb/CMakeLists.txt | 1 + common/pb/event_room_say.proto | 7 ++++++ common/pb/serverinfo_chat_message.proto | 16 ++++++++++++++ common/room_message_type.h | 15 +++++++++++++ common/server_protocolhandler.cpp | 11 ++++++++++ common/server_room.cpp | 22 +++++++++++++++++-- common/server_room.h | 6 ++++- .../migrations/servatrice_0008_to_0009.sql | 6 +++++ servatrice/servatrice.ini.example | 3 +++ servatrice/servatrice.sql | 1 + servatrice/src/servatrice.cpp | 5 ++++- .../src/servatrice_database_interface.h | 2 +- 23 files changed, 141 insertions(+), 16 deletions(-) create mode 100644 common/pb/serverinfo_chat_message.proto create mode 100644 common/room_message_type.h create mode 100644 servatrice/migrations/servatrice_0008_to_0009.sql diff --git a/cockatrice/src/chatview.cpp b/cockatrice/src/chatview.cpp index 9f77faaf..b1b13984 100644 --- a/cockatrice/src/chatview.cpp +++ b/cockatrice/src/chatview.cpp @@ -12,6 +12,7 @@ #include "settingscache.h" #include "tab_userlists.h" #include "soundengine.h" +#include "room_message_type.h" const QColor DEFAULT_MENTION_COLOR = QColor(194, 31, 47); const QColor OTHER_USER_COLOR = QColor(0, 65, 255); // dark blue @@ -121,7 +122,7 @@ void ChatView::appendUrlTag(QTextCursor &cursor, QString url) cursor.setCharFormat(oldFormat); } -void ChatView::appendMessage(QString message, QString sender, UserLevelFlags userLevel, bool playerBold) +void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType, QString sender, UserLevelFlags userLevel, bool playerBold) { bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum(); bool sameSender = (sender == lastSender) && !lastSender.isEmpty(); @@ -129,7 +130,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use lastSender = sender; // timestamp - if (showTimestamps && !sameSender) { + if (showTimestamps && !sameSender && !sender.isEmpty()) { QTextCharFormat timeFormat; timeFormat.setForeground(QColor(SERVER_MESSAGE_COLOR)); if (sender.isEmpty()) @@ -168,8 +169,17 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use // use different color for server messages defaultFormat = QTextCharFormat(); if (sender.isEmpty()) { - defaultFormat.setForeground(Qt::darkGreen); - defaultFormat.setFontWeight(QFont::Bold); + switch (messageType) { + case Event_RoomSay::Welcome: + defaultFormat.setForeground(Qt::darkGreen); + defaultFormat.setFontWeight(QFont::Bold); + break; + case Event_RoomSay::ChatHistory: + defaultFormat.setForeground(Qt::gray); + defaultFormat.setFontWeight(QFont::Light); + defaultFormat.setFontItalic(true); + break; + } } cursor.setCharFormat(defaultFormat); diff --git a/cockatrice/src/chatview.h b/cockatrice/src/chatview.h index d8fdc764..cae54a91 100644 --- a/cockatrice/src/chatview.h +++ b/cockatrice/src/chatview.h @@ -8,6 +8,7 @@ #include #include "userlist.h" #include "user_level.h" +#include "room_message_type.h" #include "tab_supervisor.h" class QTextTable; @@ -59,7 +60,7 @@ public: void retranslateUi(); void appendHtml(const QString &html); void appendHtmlServerMessage(const QString &html, bool optionalIsBold = false, QString optionalFontColor = QString()); - void appendMessage(QString message, QString sender = QString(), UserLevelFlags userLevel = UserLevelFlags(), bool playerBold = false); + void appendMessage(QString message, RoomMessageTypeFlags messageType = 0, QString sender = QString(), UserLevelFlags userLevel = UserLevelFlags(), bool playerBold = false); void clearChat(); protected: void enterEvent(QEvent *event); diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index b8b64e7b..8f84001f 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -483,6 +483,9 @@ MessagesSettingsPage::MessagesSettingsPage() mentionPopups.setChecked(settingsCache->getShowMentionPopup()); connect(&mentionPopups, SIGNAL(stateChanged(int)), settingsCache, SLOT(setShowMentionPopups(int))); + roomHistory.setChecked(settingsCache->getRoomHistory()); + connect(&roomHistory, SIGNAL(stateChanged(int)), settingsCache, SLOT(setRoomHistory(int))); + customAlertString = new QLineEdit(); customAlertString->setPlaceholderText("Word1 Word2 Word3"); customAlertString->setText(settingsCache->getHighlightWords()); @@ -498,6 +501,7 @@ MessagesSettingsPage::MessagesSettingsPage() chatGrid->addWidget(&ignoreUnregUserMessages, 3, 0); chatGrid->addWidget(&messagePopups, 4, 0); chatGrid->addWidget(&mentionPopups, 5, 0); + chatGrid->addWidget(&roomHistory, 6, 0); chatGroupBox = new QGroupBox; chatGroupBox->setLayout(chatGrid); @@ -626,7 +630,8 @@ void MessagesSettingsPage::retranslateUi() invertMentionForeground.setText(tr("Invert text color")); invertHighlightForeground.setText(tr("Invert text color")); messagePopups.setText(tr("Enable desktop notifications for private messages")); - mentionPopups.setText(tr("Enable desktop notification for mentions.")); + mentionPopups.setText(tr("Enable desktop notification for mentions")); + roomHistory.setText(tr("Enable room message history on join")); hexLabel.setText(tr("(Color is hexadecimal)")); hexHighlightLabel.setText(tr("(Color is hexadecimal)")); customAlertStringLabel.setText(tr("Separate words with a space, alphanumeric characters only")); diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index 741f2812..7b746564 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -153,6 +153,7 @@ private: QCheckBox ignoreUnregUserMessages; QCheckBox messagePopups; QCheckBox mentionPopups; + QCheckBox roomHistory; QGroupBox *chatGroupBox; QGroupBox *highlightGroupBox; QGroupBox *messageShortcuts; diff --git a/cockatrice/src/localserver.cpp b/cockatrice/src/localserver.cpp index 88c93404..426dedbf 100644 --- a/cockatrice/src/localserver.cpp +++ b/cockatrice/src/localserver.cpp @@ -6,7 +6,7 @@ LocalServer::LocalServer(QObject *parent) : Server(false, parent) { setDatabaseInterface(new LocalServer_DatabaseInterface(this)); - addRoom(new Server_Room(0, QString(), QString(), QString(), false, QString(), QStringList(), this)); + addRoom(new Server_Room(0, 0, QString(), QString(), QString(), false, QString(), QStringList(), this)); } LocalServer::~LocalServer() diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index 127c0d3d..8f28e4e3 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -168,12 +168,12 @@ void MessageLogWidget::logConnectionStateChanged(Player *player, bool connection void MessageLogWidget::logSay(Player *player, QString message) { - appendMessage(message, player->getName(), UserLevelFlags(player->getUserInfo()->user_level()), true); + appendMessage(message, 0, player->getName(), UserLevelFlags(player->getUserInfo()->user_level()), true); } void MessageLogWidget::logSpectatorSay(QString spectatorName, UserLevelFlags spectatorUserLevel, QString message) { - appendMessage(message, spectatorName, spectatorUserLevel, false); + appendMessage(message, 0, spectatorName, spectatorUserLevel, false); } void MessageLogWidget::logShuffle(Player *player, CardZone *zone) diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index 5af5f19f..d5eb062d 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -208,6 +208,7 @@ SettingsCache::SettingsCache() scaleCards = settings->value("cards/scaleCards", true).toBool(); showMessagePopups = settings->value("chat/showmessagepopups", true).toBool(); showMentionPopups = settings->value("chat/showmentionpopups", true).toBool(); + roomHistory = settings->value("chat/roomhistory", true).toBool(); leftJustified = settings->value("interface/leftjustified", false).toBool(); @@ -265,6 +266,11 @@ void SettingsCache::setShowMentionPopups(const int _showMentionPopus) { settings->setValue("chat/showmentionpopups", showMentionPopups); } +void SettingsCache::setRoomHistory(const int _roomHistory) { + roomHistory = _roomHistory; + settings->setValue("chat/roomhistory", roomHistory); +} + void SettingsCache::setLang(const QString &_lang) { lang = _lang; diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index 7e374e86..722ccac1 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -95,6 +95,7 @@ private: bool scaleCards; bool showMessagePopups; bool showMentionPopups; + bool roomHistory; bool leftJustified; int masterVolume; int cardInfoViewMode; @@ -166,6 +167,7 @@ public: bool getScaleCards() const { return scaleCards; } bool getShowMessagePopup() const { return showMessagePopups; } bool getShowMentionPopup() const { return showMentionPopups; } + bool getRoomHistory() const { return roomHistory; } bool getLeftJustified() const { return leftJustified; } int getMasterVolume() const { return masterVolume; } int getCardInfoViewMode() const { return cardInfoViewMode; } @@ -236,6 +238,7 @@ public slots: void setCardScaling(const int _scaleCards); void setShowMessagePopups(const int _showMessagePopups); void setShowMentionPopups(const int _showMentionPopups); + void setRoomHistory(const int _roomHistory); void setLeftJustified( const int _leftJustified); void setMasterVolume(const int _masterVolume); void setCardInfoViewMode(const int _viewMode); diff --git a/cockatrice/src/tab_message.cpp b/cockatrice/src/tab_message.cpp index 61a23fc6..7e9fcf75 100644 --- a/cockatrice/src/tab_message.cpp +++ b/cockatrice/src/tab_message.cpp @@ -111,7 +111,7 @@ void TabMessage::actLeave() void TabMessage::processUserMessageEvent(const Event_UserMessage &event) { const UserLevelFlags userLevel(event.sender_name() == otherUserInfo->name() ? otherUserInfo->user_level() : ownUserInfo->user_level()); - chatView->appendMessage(QString::fromStdString(event.message()), QString::fromStdString(event.sender_name()), userLevel, true); + chatView->appendMessage(QString::fromStdString(event.message()), 0,QString::fromStdString(event.sender_name()), userLevel, true); if (tabSupervisor->currentIndex() != tabSupervisor->indexOf(this)) soundEngine->playSound("private_message"); if (settingsCache->getShowMessagePopup() && shouldShowSystemPopup(event)) diff --git a/cockatrice/src/tab_room.cpp b/cockatrice/src/tab_room.cpp index 53aaf083..5f6143c3 100644 --- a/cockatrice/src/tab_room.cpp +++ b/cockatrice/src/tab_room.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "tab_supervisor.h" #include "tab_room.h" #include "tab_userlists.h" @@ -34,6 +35,7 @@ #include "pending_command.h" #include "dlg_settings.h" + TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerInfo_User *_ownUser, const ServerInfo_Room &info) : Tab(_tabSupervisor), client(_client), roomId(info.room_id()), roomName(QString::fromStdString(info.name())), ownUser(_ownUser) { @@ -265,8 +267,11 @@ void TabRoom::processLeaveRoomEvent(const Event_LeaveRoom &event) void TabRoom::processRoomSayEvent(const Event_RoomSay &event) { QString senderName = QString::fromStdString(event.name()); + QString message = QString::fromStdString(event.message()); + if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(senderName)) return; + UserListTWI *twi = userList->getUsers().value(senderName); UserLevelFlags userLevel; if (twi) { @@ -274,7 +279,15 @@ void TabRoom::processRoomSayEvent(const Event_RoomSay &event) if (settingsCache->getIgnoreUnregisteredUsers() && !userLevel.testFlag(ServerInfo_User::IsRegistered)) return; } - chatView->appendMessage(QString::fromStdString(event.message()), senderName, userLevel, true); + + if (event.message_type() == Event_RoomSay::ChatHistory && !settingsCache->getRoomHistory()) + return; + + if (event.message_type() == Event_RoomSay::ChatHistory) + message = "[" + QString(QDateTime::fromMSecsSinceEpoch(event.time_of()).toLocalTime().toString("d MMM yyyy HH:mm:ss")) + "] " + message; + + + chatView->appendMessage(message, event.message_type(), senderName, userLevel, true); emit userEvent(false); } diff --git a/common/featureset.cpp b/common/featureset.cpp index 5ed53ac2..a1d44511 100644 --- a/common/featureset.cpp +++ b/common/featureset.cpp @@ -17,6 +17,7 @@ void FeatureSet::initalizeFeatureList(QMap &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 &featureList, QString featureName){ diff --git a/common/pb/CMakeLists.txt b/common/pb/CMakeLists.txt index 3aaf9860..32063204 100644 --- a/common/pb/CMakeLists.txt +++ b/common/pb/CMakeLists.txt @@ -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 diff --git a/common/pb/event_room_say.proto b/common/pb/event_room_say.proto index 49e70e69..122f0f45 100644 --- a/common/pb/event_room_say.proto +++ b/common/pb/event_room_say.proto @@ -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; + } diff --git a/common/pb/serverinfo_chat_message.proto b/common/pb/serverinfo_chat_message.proto new file mode 100644 index 00000000..27d4386e --- /dev/null +++ b/common/pb/serverinfo_chat_message.proto @@ -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 +} diff --git a/common/room_message_type.h b/common/room_message_type.h new file mode 100644 index 00000000..8439ce93 --- /dev/null +++ b/common/room_message_type.h @@ -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 + +Q_DECLARE_FLAGS(RoomMessageTypeFlags, Event_RoomSay::RoomMessageType) +Q_DECLARE_OPERATORS_FOR_FLAGS(RoomMessageTypeFlags) + +#endif diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 70191566..0be08125 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -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); diff --git a/common/server_room.cpp b/common/server_room.cpp index 6ce86c8e..a53fdd97 100644 --- a/common/server_room.cpp +++ b/common/server_room.cpp @@ -2,6 +2,7 @@ #include "server_protocolhandler.h" #include "server_game.h" #include +#include #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 -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) diff --git a/common/server_room.h b/common/server_room.h index 3bb0e05e..6e79ba6b 100644 --- a/common/server_room.h +++ b/common/server_room.h @@ -9,6 +9,7 @@ #include #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 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 getGamesOfUser(const QString &name) const; + QList getChatHistory() { return chatHistory; } void addClient(Server_ProtocolHandler *client); void removeClient(Server_ProtocolHandler *client); diff --git a/servatrice/migrations/servatrice_0008_to_0009.sql b/servatrice/migrations/servatrice_0008_to_0009.sql new file mode 100644 index 00000000..3874b9fc --- /dev/null +++ b/servatrice/migrations/servatrice_0008_to_0009.sql @@ -0,0 +1,6 @@ +-- Servatrice db migration from version 8 to version 9 + +alter table cockatrice_rooms add chat_history_size int(4) not null after join_message; +update cockatrice_rooms set chat_history_size = 100; + +UPDATE cockatrice_schema_version SET version=9 WHERE version=8; diff --git a/servatrice/servatrice.ini.example b/servatrice/servatrice.ini.example index 842fb032..a300c44a 100644 --- a/servatrice/servatrice.ini.example +++ b/servatrice/servatrice.ini.example @@ -188,6 +188,9 @@ roomlist\1\autojoin=true ; Message displayed to each user when he joins room number 1 roomlist\1\joinmessage="This message is only here to show that rooms can have a join message." +; The number of chat history messages to save that gets presented to a user joining the room +roomlist\1\chathistorysize=100 + ; Number of game types allowed (defined) in the room number 1 roomlist\1\game_types\size=3 diff --git a/servatrice/servatrice.sql b/servatrice/servatrice.sql index 2c4d0b67..50161676 100644 --- a/servatrice/servatrice.sql +++ b/servatrice/servatrice.sql @@ -185,6 +185,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_rooms` ( `permissionlevel` varchar(20) NOT NULL, `auto_join` tinyint(1) default 0, `join_message` varchar(255) NOT NULL, + `chat_history_size` int(4) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index f1f29191..df7dea96 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -222,7 +222,7 @@ bool Servatrice::initServer() const QString roomMethod = settingsCache->value("rooms/method").toString(); if (roomMethod == "sql") { - QSqlQuery *query = servatriceDatabaseInterface->prepareQuery("select id, name, descr, permissionlevel, auto_join, join_message from {prefix}_rooms order by id asc"); + QSqlQuery *query = servatriceDatabaseInterface->prepareQuery("select id, name, descr, permissionlevel, auto_join, join_message, chat_history_size from {prefix}_rooms order by id asc"); servatriceDatabaseInterface->execSqlQuery(query); while (query->next()) { QSqlQuery *query2 = servatriceDatabaseInterface->prepareQuery("select name from {prefix}_rooms_gametypes where id_room = :id_room"); @@ -233,6 +233,7 @@ bool Servatrice::initServer() gameTypes.append(query2->value(0).toString()); addRoom(new Server_Room(query->value(0).toInt(), + query->value(6).toInt(), query->value(1).toString(), query->value(2).toString(), query->value(3).toString().toLower(), @@ -257,6 +258,7 @@ bool Servatrice::initServer() Server_Room *newRoom = new Server_Room( i, + settingsCache->value("chathistorysize").toInt(), settingsCache->value("name").toString(), settingsCache->value("description").toString(), settingsCache->value("permissionlevel").toString().toLower(), @@ -273,6 +275,7 @@ bool Servatrice::initServer() // no room defined in config, add a dummy one Server_Room *newRoom = new Server_Room( 0, + 100, "General room", "Play anything here.", "none", diff --git a/servatrice/src/servatrice_database_interface.h b/servatrice/src/servatrice_database_interface.h index de9c31fc..2319cd6f 100644 --- a/servatrice/src/servatrice_database_interface.h +++ b/servatrice/src/servatrice_database_interface.h @@ -9,7 +9,7 @@ #include "server.h" #include "server_database_interface.h" -#define DATABASE_SCHEMA_VERSION 8 +#define DATABASE_SCHEMA_VERSION 9 class Servatrice;