From 55923469796d720ea7f583269750808e5202db96 Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Mon, 23 Jun 2014 00:07:12 -0400 Subject: [PATCH 01/17] added server log filtering added log filtering based on configuration file setting 0 = log everything 1 = log nothing 2 = chat logging only --- servatrice/src/server_logger.cpp | 40 ++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/servatrice/src/server_logger.cpp b/servatrice/src/server_logger.cpp index 3eac4f36..bfd979fd 100644 --- a/servatrice/src/server_logger.cpp +++ b/servatrice/src/server_logger.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #ifdef Q_OS_UNIX # include @@ -44,13 +45,44 @@ void ServerLogger::logMessage(QString message, void *caller) if (!logFile) return; - bufferMutex.lock(); QString callerString; if (caller) callerString = QString::number((qulonglong) caller, 16) + " "; - buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message); - bufferMutex.unlock(); - + + //filter out all log entries based on loglevel value in configuration file + QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat); + int found = 0; int capture = 0; int loglevel = 0; + loglevel = settings->value("server/loglevel").toInt(); + switch (loglevel) + { + case 1: + break; + + case 2: + + // filter message log data + found = message.indexOf("Adding room: ID=", Qt::CaseInsensitive); if (found != -1){ capture = 1; } + found = message.indexOf("Starting status update clock", Qt::CaseInsensitive); if (found != -1){ capture = 1; } + found = message.indexOf("Starting server on port", Qt::CaseInsensitive); if (found != -1){ capture = 1; } + found = message.indexOf("Server listening.", Qt::CaseInsensitive); if (found != -1){ capture = 1; } + found = message.indexOf("Server::loginUser:", Qt::CaseInsensitive); if (found != -1){ capture = 1; } + found = message.indexOf("Server::removeClient:", Qt::CaseInsensitive); if (found != -1){ capture = 1; } + found = message.indexOf("Command_Login.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; } + found = message.indexOf("Command_RoomSay.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; } + found = message.indexOf("Command_Message.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; } + found = message.indexOf("Command_GameSay.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; } + if (capture != 0){ + bufferMutex.lock(); + buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message); + bufferMutex.unlock(); + } + break; + + default: + bufferMutex.lock(); + buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message); + bufferMutex.unlock(); + } emit sigFlushBuffer(); } From 236e0a419730b77954c063bc54fc01fe77ae0ef7 Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Mon, 23 Jun 2014 00:09:21 -0400 Subject: [PATCH 02/17] added loglevel variable added log filtering variable --- servatrice/servatrice.ini.example | 1 + 1 file changed, 1 insertion(+) diff --git a/servatrice/servatrice.ini.example b/servatrice/servatrice.ini.example index bce91360..5c5e2488 100644 --- a/servatrice/servatrice.ini.example +++ b/servatrice/servatrice.ini.example @@ -5,6 +5,7 @@ logfile=server.log name="My Cockatrice server" id=1 number_pools=1 +loglevel=0 [servernetwork] active=0 From 46ceeadbbd142f5e8c1373dce38a071a4714731c Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Mon, 23 Jun 2014 03:41:46 -0400 Subject: [PATCH 03/17] updated code structure cleaned code structure up for clarity --- servatrice/src/server_logger.cpp | 48 +++++++++++++++++++------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/servatrice/src/server_logger.cpp b/servatrice/src/server_logger.cpp index bfd979fd..07648035 100644 --- a/servatrice/src/server_logger.cpp +++ b/servatrice/src/server_logger.cpp @@ -5,11 +5,13 @@ #include #include #include +#include #ifdef Q_OS_UNIX # include # include # include #endif +using namespace std; ServerLogger::ServerLogger(bool _logToConsole, QObject *parent) : QObject(parent), logToConsole(_logToConsole), flushRunning(false) @@ -51,37 +53,45 @@ void ServerLogger::logMessage(QString message, void *caller) //filter out all log entries based on loglevel value in configuration file QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat); - int found = 0; int capture = 0; int loglevel = 0; + int found = 0; int capture = 0; int loglevel = 0; list lst_str; loglevel = settings->value("server/loglevel").toInt(); + + switch (loglevel) { case 1: + capture = 0; break; case 2: - // filter message log data - found = message.indexOf("Adding room: ID=", Qt::CaseInsensitive); if (found != -1){ capture = 1; } - found = message.indexOf("Starting status update clock", Qt::CaseInsensitive); if (found != -1){ capture = 1; } - found = message.indexOf("Starting server on port", Qt::CaseInsensitive); if (found != -1){ capture = 1; } - found = message.indexOf("Server listening.", Qt::CaseInsensitive); if (found != -1){ capture = 1; } - found = message.indexOf("Server::loginUser:", Qt::CaseInsensitive); if (found != -1){ capture = 1; } - found = message.indexOf("Server::removeClient:", Qt::CaseInsensitive); if (found != -1){ capture = 1; } - found = message.indexOf("Command_Login.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; } - found = message.indexOf("Command_RoomSay.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; } - found = message.indexOf("Command_Message.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; } - found = message.indexOf("Command_GameSay.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; } - if (capture != 0){ - bufferMutex.lock(); - buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message); - bufferMutex.unlock(); + lst_str.push_back("Adding room: ID="); + lst_str.push_back("Starting status update clock"); + lst_str.push_back("Starting server on port"); + lst_str.push_back("Server listening."); + lst_str.push_back("Server::loginUser:"); + lst_str.push_back("Server::removeClient:"); + lst_str.push_back("Command_Login.ext"); + lst_str.push_back("Command_RoomSay.ext"); + lst_str.push_back("Command_Message.ext"); + lst_str.push_back("Command_GameSay.ext"); + for (list::iterator i = lst_str.begin(); i != lst_str.end(); i++) + { + if(message.indexOf((*i).c_str(), Qt::CaseInsensitive) != -1) { + capture = 1; + break; + } } break; default: - bufferMutex.lock(); - buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message); - bufferMutex.unlock(); + capture = 1; + } + + if (capture != 0){ + bufferMutex.lock(); + buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message); + bufferMutex.unlock(); } emit sigFlushBuffer(); } From ec00bdebed8e7ef839f147dcce2ffc75202b6535 Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Mon, 23 Jun 2014 09:18:49 -0400 Subject: [PATCH 04/17] verbose incrementation removed un-used variables changed switch case to increase verbose level as loglevel increases captured unset loglevel to default to highest verbose log level --- servatrice/src/server_logger.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/servatrice/src/server_logger.cpp b/servatrice/src/server_logger.cpp index 07648035..a5c33bc8 100644 --- a/servatrice/src/server_logger.cpp +++ b/servatrice/src/server_logger.cpp @@ -53,9 +53,10 @@ void ServerLogger::logMessage(QString message, void *caller) //filter out all log entries based on loglevel value in configuration file QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat); - int found = 0; int capture = 0; int loglevel = 0; list lst_str; - loglevel = settings->value("server/loglevel").toInt(); - + int capture = 0; list lst_str; + int loglevel = settings->value("server/loglevel").toInt(); + if (!loglevel) + loglevel = 999; switch (loglevel) { From 91a96643f03395242acf2bf3ab30d40aa832c967 Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Thu, 26 Jun 2014 00:38:43 -0400 Subject: [PATCH 05/17] updated filtering code rewrote filtering code to allow for user input code only filters on single string at the moment (still needs updated). --- servatrice/src/server_logger.cpp | 55 +++++++++----------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/servatrice/src/server_logger.cpp b/servatrice/src/server_logger.cpp index a5c33bc8..1fff3f8b 100644 --- a/servatrice/src/server_logger.cpp +++ b/servatrice/src/server_logger.cpp @@ -5,13 +5,11 @@ #include #include #include -#include #ifdef Q_OS_UNIX # include # include # include #endif -using namespace std; ServerLogger::ServerLogger(bool _logToConsole, QObject *parent) : QObject(parent), logToConsole(_logToConsole), flushRunning(false) @@ -53,48 +51,25 @@ void ServerLogger::logMessage(QString message, void *caller) //filter out all log entries based on loglevel value in configuration file QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat); - int capture = 0; list lst_str; - int loglevel = settings->value("server/loglevel").toInt(); - if (!loglevel) - loglevel = 999; + bool shouldWeWriteLog = settings->value("server/writelog").toBool(); + //allowedLogStatements << "Adding room: ID=" << "Starting status update clock" << "Starting server on port" << + // "Server listening." << "Server::loginUser:" << "Server::removeClient:" << "Command_Login.ext" << + // "Command_RoomSay.ext" << "Command_Message.ext" << "Command_GameSay.ext"; - switch (loglevel) - { - case 1: - capture = 0; - break; + if (shouldWeWriteLog){ + QString logFilters = settings->value("server/logfilters").toString(); + bool shouldWeSkipLine = false; + if (!logFilters.trimmed().isEmpty()) + shouldWeSkipLine = !message.contains(logFilters); + + if (shouldWeSkipLine) + return; - case 2: - // filter message log data - lst_str.push_back("Adding room: ID="); - lst_str.push_back("Starting status update clock"); - lst_str.push_back("Starting server on port"); - lst_str.push_back("Server listening."); - lst_str.push_back("Server::loginUser:"); - lst_str.push_back("Server::removeClient:"); - lst_str.push_back("Command_Login.ext"); - lst_str.push_back("Command_RoomSay.ext"); - lst_str.push_back("Command_Message.ext"); - lst_str.push_back("Command_GameSay.ext"); - for (list::iterator i = lst_str.begin(); i != lst_str.end(); i++) - { - if(message.indexOf((*i).c_str(), Qt::CaseInsensitive) != -1) { - capture = 1; - break; - } - } - break; - - default: - capture = 1; - } - - if (capture != 0){ bufferMutex.lock(); - buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message); - bufferMutex.unlock(); + buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message); + bufferMutex.unlock(); + emit sigFlushBuffer(); } - emit sigFlushBuffer(); } void ServerLogger::flushBuffer() From 977cf7340ab50d471e47a7d1d11bcfa004938b1f Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Thu, 26 Jun 2014 00:40:21 -0400 Subject: [PATCH 06/17] settings update/addition updated settings name (loglevel) to a more descriptive name (writelog) added logfilters setting to allow user defined filters. --- servatrice/servatrice.ini.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/servatrice/servatrice.ini.example b/servatrice/servatrice.ini.example index 5c5e2488..c50ff9f1 100644 --- a/servatrice/servatrice.ini.example +++ b/servatrice/servatrice.ini.example @@ -5,7 +5,8 @@ logfile=server.log name="My Cockatrice server" id=1 number_pools=1 -loglevel=0 +writelog=1 +logfilters="" [servernetwork] active=0 From 365de1fdd059ad93688953dfe2ece88d66ff9d5b Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Thu, 26 Jun 2014 14:38:57 -0400 Subject: [PATCH 07/17] added multiple filter capabilities changed the single qstring log filtering to qstringlist to allow multiple filtering capabilities --- servatrice/src/server_logger.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/servatrice/src/server_logger.cpp b/servatrice/src/server_logger.cpp index 1fff3f8b..0264c2fd 100644 --- a/servatrice/src/server_logger.cpp +++ b/servatrice/src/server_logger.cpp @@ -49,19 +49,25 @@ void ServerLogger::logMessage(QString message, void *caller) if (caller) callerString = QString::number((qulonglong) caller, 16) + " "; - //filter out all log entries based on loglevel value in configuration file + //filter out all log entries based on values in configuration file QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat); bool shouldWeWriteLog = settings->value("server/writelog").toBool(); - //allowedLogStatements << "Adding room: ID=" << "Starting status update clock" << "Starting server on port" << - // "Server listening." << "Server::loginUser:" << "Server::removeClient:" << "Command_Login.ext" << - // "Command_RoomSay.ext" << "Command_Message.ext" << "Command_GameSay.ext"; if (shouldWeWriteLog){ QString logFilters = settings->value("server/logfilters").toString(); + QStringList listlogFilters = logFilters.split(",", QString::SkipEmptyParts); bool shouldWeSkipLine = false; - if (!logFilters.trimmed().isEmpty()) - shouldWeSkipLine = !message.contains(logFilters); - + if (!logFilters.trimmed().isEmpty()){ + shouldWeSkipLine = true; + foreach(QString logFilter, listlogFilters){ + if (message.contains(logFilter, Qt::CaseInsensitive)){ + shouldWeSkipLine = false; + break; + } + } + } + + if (shouldWeSkipLine) return; From b83fe95b058d9b898881ce1f3a7940b6bf52b6bd Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Thu, 26 Jun 2014 14:46:22 -0400 Subject: [PATCH 08/17] removed extra un-needed empty line. removed extra un-needed empty line. --- servatrice/src/server_logger.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/servatrice/src/server_logger.cpp b/servatrice/src/server_logger.cpp index 0264c2fd..9566ba17 100644 --- a/servatrice/src/server_logger.cpp +++ b/servatrice/src/server_logger.cpp @@ -67,7 +67,6 @@ void ServerLogger::logMessage(QString message, void *caller) } } - if (shouldWeSkipLine) return; From 080fd326ed3d672e66d74e73a5f36a241918cc75 Mon Sep 17 00:00:00 2001 From: arxanas Date: Thu, 26 Jun 2014 16:57:47 -0400 Subject: [PATCH 09/17] Fixed #131: Compiles on OS X now. --- cockatrice/src/carddatabase.cpp | 4 ++-- cockatrice/src/carddatabase.h | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 5a942b0f..1677cf69 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -275,7 +275,7 @@ CardInfo::CardInfo(CardDatabase *_db, bool _cipt, int _tableRow, const SetList &_sets, - QMap _muIds) + MuidMap _muIds) : db(_db), name(_name), isToken(_isToken), @@ -610,7 +610,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml) if (xml.name() == "card") { QString name, manacost, type, pt, text; QStringList colors; - QMap muids; + MuidMap muids; SetList sets; int tableRow = 0; int loyalty = 0; diff --git a/cockatrice/src/carddatabase.h b/cockatrice/src/carddatabase.h index 70d77bca..28d56d13 100644 --- a/cockatrice/src/carddatabase.h +++ b/cockatrice/src/carddatabase.h @@ -20,6 +20,9 @@ class QNetworkRequest; typedef QMap QStringMap; +// If we don't typedef this, CardInfo::CardInfo will refuse to compile on OS X. +typedef QMap MuidMap; + class CardSet : public QList { private: QString shortName, longName; @@ -100,7 +103,7 @@ private: QString text; QStringList colors; int loyalty; - QMap muIds; + MuidMap muIds; bool cipt; int tableRow; QPixmap *pixmap; @@ -118,7 +121,7 @@ public: bool _cipt = false, int _tableRow = 0, const SetList &_sets = SetList(), - QMap muids = QMap()); + MuidMap muids = MuidMap()); ~CardInfo(); const QString &getName() const { return name; } bool getIsToken() const { return isToken; } From f685bd2abe58013b03da0a87a3b6b5fd2dc2847b Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Fri, 27 Jun 2014 18:18:03 -0400 Subject: [PATCH 10/17] formatting 4 space indent + code flow rewrite for easier readability. --- servatrice/src/server_logger.cpp | 165 ++++++++++++++++--------------- 1 file changed, 83 insertions(+), 82 deletions(-) diff --git a/servatrice/src/server_logger.cpp b/servatrice/src/server_logger.cpp index 9566ba17..2dbbc5e5 100644 --- a/servatrice/src/server_logger.cpp +++ b/servatrice/src/server_logger.cpp @@ -12,121 +12,122 @@ #endif ServerLogger::ServerLogger(bool _logToConsole, QObject *parent) - : QObject(parent), logToConsole(_logToConsole), flushRunning(false) + : QObject(parent), logToConsole(_logToConsole), flushRunning(false) { } ServerLogger::~ServerLogger() { - flushBuffer(); - // This does not work with the destroyed() signal as this destructor is called after the main event loop is done. - thread()->quit(); + flushBuffer(); + // This does not work with the destroyed() signal as this destructor is called after the main event loop is done. + thread()->quit(); } void ServerLogger::startLog(const QString &logFileName) { - if (!logFileName.isEmpty()) { - logFile = new QFile("server.log", this); - logFile->open(QIODevice::Append); + if (!logFileName.isEmpty()) { + logFile = new QFile("server.log", this); + logFile->open(QIODevice::Append); #ifdef Q_OS_UNIX - ::socketpair(AF_UNIX, SOCK_STREAM, 0, sigHupFD); + ::socketpair(AF_UNIX, SOCK_STREAM, 0, sigHupFD); - snHup = new QSocketNotifier(sigHupFD[1], QSocketNotifier::Read, this); - connect(snHup, SIGNAL(activated(int)), this, SLOT(handleSigHup())); + snHup = new QSocketNotifier(sigHupFD[1], QSocketNotifier::Read, this); + connect(snHup, SIGNAL(activated(int)), this, SLOT(handleSigHup())); #endif - } else - logFile = 0; - - connect(this, SIGNAL(sigFlushBuffer()), this, SLOT(flushBuffer()), Qt::QueuedConnection); + } else + logFile = 0; + + connect(this, SIGNAL(sigFlushBuffer()), this, SLOT(flushBuffer()), Qt::QueuedConnection); } void ServerLogger::logMessage(QString message, void *caller) { - if (!logFile) - return; - - QString callerString; - if (caller) - callerString = QString::number((qulonglong) caller, 16) + " "; - - //filter out all log entries based on values in configuration file - QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat); - bool shouldWeWriteLog = settings->value("server/writelog").toBool(); - - if (shouldWeWriteLog){ - QString logFilters = settings->value("server/logfilters").toString(); - QStringList listlogFilters = logFilters.split(",", QString::SkipEmptyParts); - bool shouldWeSkipLine = false; - if (!logFilters.trimmed().isEmpty()){ - shouldWeSkipLine = true; - foreach(QString logFilter, listlogFilters){ - if (message.contains(logFilter, Qt::CaseInsensitive)){ - shouldWeSkipLine = false; - break; - } - } - } + if (!logFile) + return; + + QString callerString; + if (caller) + callerString = QString::number((qulonglong) caller, 16) + " "; + + //filter out all log entries based on values in configuration file + QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat); + bool shouldWeWriteLog = settings->value("server/writelog").toBool(); + QString logFilters = settings->value("server/logfilters").toString(); + QStringList listlogFilters = logFilters.split(",", QString::SkipEmptyParts); + bool shouldWeSkipLine = false; + + if (!shouldWeWriteLog) + return; - if (shouldWeSkipLine) - return; + if (!logFilters.trimmed().isEmpty()){ + shouldWeSkipLine = true; + foreach(QString logFilter, listlogFilters){ + if (message.contains(logFilter, Qt::CaseInsensitive)){ + shouldWeSkipLine = false; + break; + } + } + } - bufferMutex.lock(); - buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message); - bufferMutex.unlock(); - emit sigFlushBuffer(); - } + if (shouldWeSkipLine) + return; + + bufferMutex.lock(); + buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message); + bufferMutex.unlock(); + emit sigFlushBuffer(); } void ServerLogger::flushBuffer() { - if (flushRunning) - return; - - flushRunning = true; - QTextStream stream(logFile); - forever { - bufferMutex.lock(); - if (buffer.isEmpty()) { - bufferMutex.unlock(); - flushRunning = false; - return; - } - QString message = buffer.takeFirst(); - bufferMutex.unlock(); - - stream << message << "\n"; - stream.flush(); - - if (logToConsole) - std::cout << message.toStdString() << std::endl; - } + if (flushRunning) + return; + + flushRunning = true; + QTextStream stream(logFile); + forever { + bufferMutex.lock(); + if (buffer.isEmpty()) { + bufferMutex.unlock(); + flushRunning = false; + return; + } + QString message = buffer.takeFirst(); + bufferMutex.unlock(); + + stream << message << "\n"; + stream.flush(); + + if (logToConsole) + std::cout << message.toStdString() << std::endl; + } } void ServerLogger::hupSignalHandler(int /*unused*/) { #ifdef Q_OS_UNIX - if (!logFile) - return; - - char a = 1; - ::write(sigHupFD[0], &a, sizeof(a)); + if (!logFile) + return; + + char a = 1; + ::write(sigHupFD[0], &a, sizeof(a)); #endif } void ServerLogger::handleSigHup() { #ifdef Q_OS_UNIX - if (!logFile) - return; - - snHup->setEnabled(false); - char tmp; - ::read(sigHupFD[1], &tmp, sizeof(tmp)); - - logFile->close(); - logFile->open(QIODevice::Append); - - snHup->setEnabled(true); + if (!logFile) + return; + + snHup->setEnabled(false); + char tmp; + ::read(sigHupFD[1], &tmp, sizeof(tmp)); + + logFile->close(); + logFile->open(QIODevice::Append); + + snHup->setEnabled(true); #endif } From 1d02e0d5ec3288d90272e426e79056c78b007be3 Mon Sep 17 00:00:00 2001 From: Daenyth Date: Fri, 27 Jun 2014 20:00:29 -0400 Subject: [PATCH 11/17] Clarify comment about typedef for OSX compiling --- cockatrice/src/carddatabase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cockatrice/src/carddatabase.h b/cockatrice/src/carddatabase.h index 28d56d13..09edeff4 100644 --- a/cockatrice/src/carddatabase.h +++ b/cockatrice/src/carddatabase.h @@ -20,7 +20,7 @@ class QNetworkRequest; typedef QMap QStringMap; -// If we don't typedef this, CardInfo::CardInfo will refuse to compile on OS X. +// If we don't typedef this, CardInfo::CardInfo will refuse to compile on OS X < 10.9 typedef QMap MuidMap; class CardSet : public QList { From d3b4ef38a0b068e0f2c54178044a97fd70097a02 Mon Sep 17 00:00:00 2001 From: Daenyth Date: Fri, 27 Jun 2014 20:42:19 -0400 Subject: [PATCH 12/17] Compile servatrice on travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 803f316c..74f6feff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,6 @@ os: compiler: - gcc - clang -script: mkdir build && cd build && cmake .. && make +script: mkdir build && cd build && cmake .. -DWITH_SERVER=1 && make install: ./travis-dependencies.sh cache: apt From 6d3fe428e73530bfb34a2368f86518a56657ed3e Mon Sep 17 00:00:00 2001 From: Daenyth Date: Fri, 27 Jun 2014 22:19:23 -0400 Subject: [PATCH 13/17] Fix some warnings Ref #127 --- CMakeLists.txt | 4 ++-- cockatrice/src/abstractclient.h | 2 +- cockatrice/src/carddatabase.cpp | 8 ++++---- cockatrice/src/cardfilter.h | 2 +- cockatrice/src/decklistmodel.cpp | 3 +++ cockatrice/src/filtertree.h | 4 ++-- cockatrice/src/main.cpp | 2 +- cockatrice/src/main.h | 2 ++ common/decklist.cpp | 3 +++ common/server_response_containers.cpp | 2 +- oracle/src/oracleimporter.h | 2 +- 11 files changed, 21 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97142397..5404e120 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,8 +58,8 @@ IF(MSVC) #set(CMAKE_CXX_FLAGS_DEBUG "/Zi") ELSEIF (CMAKE_COMPILER_IS_GNUCXX) # linux/gcc, bsd/gcc, windows/mingw - set(CMAKE_CXX_FLAGS_RELEASE "-s -O2") - set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0") + set(CMAKE_CXX_FLAGS_RELEASE "-s -O2 -Wall -Wextra -pedantic -Werror -Wcast-align -Wmissing-declarations -Winline -Wno-long-long -Wno-error=extra -Wno-unused-parameter -Wno-inline -Wno-delete-non-virtual-dtor -Wno-error=sign-compare -Wno-reorder -Wno-missing-declarations") + set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0 -Wall -Wextra -pedantic -Werror -Wcast-align -Wmissing-declarations -Winline -Wno-long-long -Wno-error=extra -Wno-error=unused-parameter -Wno-inline -Wno-error=delete-non-virtual-dtor -W-noerror=sign-compare -Wno-error=reorder -Wno-error=missing-declarations") ELSE() # other: osx/llvm, bsd/llvm set(CMAKE_CXX_FLAGS_RELEASE "-O2") diff --git a/cockatrice/src/abstractclient.h b/cockatrice/src/abstractclient.h index 130c85b5..4dc9af2b 100644 --- a/cockatrice/src/abstractclient.h +++ b/cockatrice/src/abstractclient.h @@ -31,7 +31,7 @@ enum ClientStatus { StatusConnecting, StatusAwaitingWelcome, StatusLoggingIn, - StatusLoggedIn, + StatusLoggedIn }; class AbstractClient : public QObject { diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 1677cf69..eff101f9 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -16,7 +16,7 @@ const int CardDatabase::versionNeeded = 3; -QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardSet *set) +static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardSet *set) { xml.writeStartElement("set"); xml.writeTextElement("name", set->getShortName()); @@ -280,13 +280,13 @@ CardInfo::CardInfo(CardDatabase *_db, name(_name), isToken(_isToken), sets(_sets), - muIds(_muIds), manacost(_manacost), cardtype(_cardtype), powtough(_powtough), text(_text), colors(_colors), loyalty(_loyalty), + muIds(_muIds), cipt(_cipt), tableRow(_tableRow), pixmap(NULL) @@ -434,7 +434,7 @@ int CardInfo::getPreferredMuId() return muIds[getPreferredSet()->getShortName()]; } -QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info) +static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info) { xml.writeStartElement("card"); xml.writeTextElement("name", info->getName()); @@ -473,7 +473,7 @@ QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info) } CardDatabase::CardDatabase(QObject *parent) - : QObject(parent), loadStatus(NotLoaded), noCard(0) + : QObject(parent), noCard(0), loadStatus(NotLoaded) { connect(settingsCache, SIGNAL(picsPathChanged()), this, SLOT(picsPathChanged())); connect(settingsCache, SIGNAL(cardDatabasePathChanged()), this, SLOT(loadCardDatabase())); diff --git a/cockatrice/src/cardfilter.h b/cockatrice/src/cardfilter.h index 47a85ea6..e5f88123 100644 --- a/cockatrice/src/cardfilter.h +++ b/cockatrice/src/cardfilter.h @@ -26,9 +26,9 @@ public: }; private: + QString trm; enum Type t; enum Attr a; - QString trm; public: CardFilter(QString term, Type type, Attr attr) : trm(term), t(type), a(attr) {}; diff --git a/cockatrice/src/decklistmodel.cpp b/cockatrice/src/decklistmodel.cpp index 00d92fae..a98ee261 100644 --- a/cockatrice/src/decklistmodel.cpp +++ b/cockatrice/src/decklistmodel.cpp @@ -340,6 +340,9 @@ void DeckListModel::sort(int column, Qt::SortOrder order) break; case 2: sortMethod = ByPrice; + break; + default: + sortMethod = ByName; } root->setSortMethod(sortMethod); sortHelper(root, order); diff --git a/cockatrice/src/filtertree.h b/cockatrice/src/filtertree.h index 9a5fc531..a6c4536d 100644 --- a/cockatrice/src/filtertree.h +++ b/cockatrice/src/filtertree.h @@ -66,7 +66,7 @@ public: const CardFilter::Attr attr; LogicMap(CardFilter::Attr a, FilterTree *parent) - : attr(a), p(parent) {} + : p(parent), attr(a) {} const FilterItemList *findTypeList(CardFilter::Type type) const; FilterItemList *typeList(CardFilter::Type type); FilterTreeNode *parent() const; @@ -81,7 +81,7 @@ public: const CardFilter::Type type; FilterItemList(CardFilter::Type t, LogicMap *parent) - : type(t), p(parent) {} + : p(parent), type(t) {} CardFilter::Attr attr() const { return p->attr; } FilterTreeNode *parent() const { return p; } int termIndex(const QString &term) const; diff --git a/cockatrice/src/main.cpp b/cockatrice/src/main.cpp index c618c1ae..22e1fe12 100644 --- a/cockatrice/src/main.cpp +++ b/cockatrice/src/main.cpp @@ -55,7 +55,7 @@ QString translationPath = TRANSLATION_PATH; QString translationPath = QString(); #endif -void myMessageOutput(QtMsgType /*type*/, const char *msg) +static void myMessageOutput(QtMsgType /*type*/, const char *msg) { QFile file("qdebug.txt"); file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text); diff --git a/cockatrice/src/main.h b/cockatrice/src/main.h index 4a1d234f..9237f23c 100644 --- a/cockatrice/src/main.h +++ b/cockatrice/src/main.h @@ -13,4 +13,6 @@ extern QString translationPath; void installNewTranslator(); +bool settingsValid(); + #endif diff --git a/common/decklist.cpp b/common/decklist.cpp index e81a0629..c0721556 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -180,6 +180,7 @@ bool InnerDecklistNode::compare(AbstractDecklistNode *other) const case 2: return comparePrice(other); } + return 0; } bool InnerDecklistNode::compareNumber(AbstractDecklistNode *other) const @@ -226,6 +227,7 @@ bool AbstractDecklistCardNode::compare(AbstractDecklistNode *other) const case ByPrice: return compareTotalPrice(other); } + return 0; } bool AbstractDecklistCardNode::compareNumber(AbstractDecklistNode *other) const @@ -351,6 +353,7 @@ DeckList::DeckList() root = new InnerDecklistNode; } +// TODO: http://qt-project.org/doc/qt-4.8/qobject.html#no-copy-constructor-or-assignment-operator DeckList::DeckList(const DeckList &other) : name(other.name), comments(other.comments), diff --git a/common/server_response_containers.cpp b/common/server_response_containers.cpp index 8b6d2730..bc36222e 100644 --- a/common/server_response_containers.cpp +++ b/common/server_response_containers.cpp @@ -64,7 +64,7 @@ void GameEventStorage::sendToGame(Server_Game *game) } ResponseContainer::ResponseContainer(int _cmdId) - : responseExtension(0), cmdId(_cmdId) + : cmdId(_cmdId), responseExtension(0) { } diff --git a/oracle/src/oracleimporter.h b/oracle/src/oracleimporter.h index 1f705eeb..4c36a211 100644 --- a/oracle/src/oracleimporter.h +++ b/oracle/src/oracleimporter.h @@ -17,7 +17,7 @@ public: bool getImport() const { return import; } void setImport(bool _import) { import = _import; } SetToDownload(const QString &_shortName, const QString &_longName, const QVariant &_cards, bool _import) - : shortName(_shortName), longName(_longName), cards(_cards), import(_import) { } + : shortName(_shortName), longName(_longName), import(_import), cards(_cards) { } bool operator<(const SetToDownload &set) const { return longName.compare(set.longName, Qt::CaseInsensitive) < 0; } }; From 38aa1f60ed3f9ce19509de753c61a59bcf56b289 Mon Sep 17 00:00:00 2001 From: Daenyth Date: Fri, 27 Jun 2014 22:50:21 -0400 Subject: [PATCH 14/17] Don't pass warn/err flags for release mode build. It's making travis complicated --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5404e120..96894f17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ IF(MSVC) #set(CMAKE_CXX_FLAGS_DEBUG "/Zi") ELSEIF (CMAKE_COMPILER_IS_GNUCXX) # linux/gcc, bsd/gcc, windows/mingw - set(CMAKE_CXX_FLAGS_RELEASE "-s -O2 -Wall -Wextra -pedantic -Werror -Wcast-align -Wmissing-declarations -Winline -Wno-long-long -Wno-error=extra -Wno-unused-parameter -Wno-inline -Wno-delete-non-virtual-dtor -Wno-error=sign-compare -Wno-reorder -Wno-missing-declarations") + set(CMAKE_CXX_FLAGS_RELEASE "-s -O2") set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0 -Wall -Wextra -pedantic -Werror -Wcast-align -Wmissing-declarations -Winline -Wno-long-long -Wno-error=extra -Wno-error=unused-parameter -Wno-inline -Wno-error=delete-non-virtual-dtor -W-noerror=sign-compare -Wno-error=reorder -Wno-error=missing-declarations") ELSE() # other: osx/llvm, bsd/llvm From c0bd7db658fb54d6f5834f1e99838c150b94379a Mon Sep 17 00:00:00 2001 From: Daenyth Date: Fri, 27 Jun 2014 22:57:24 -0400 Subject: [PATCH 15/17] Install libgcrypt on osx travis --- travis-dependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis-dependencies.sh b/travis-dependencies.sh index 533a213b..0c6c62e6 100755 --- a/travis-dependencies.sh +++ b/travis-dependencies.sh @@ -2,7 +2,7 @@ if [[ $TRAVIS_OS_NAME == "osx" ]] ; then brew update - brew install qt cmake protobuf + brew install qt cmake protobuf libgcrypt else sudo apt-get update -qq sudo apt-get install -y qtmobility-dev libprotobuf-dev protobuf-compiler libqt4-dev From 4c2a553f03da8f04aafe613c943f7296458086e9 Mon Sep 17 00:00:00 2001 From: Daenyth Date: Sat, 28 Jun 2014 00:36:08 -0400 Subject: [PATCH 16/17] Have servatrice inform players of sideboard size Ref #142 --- cockatrice/src/messagelogwidget.cpp | 12 ++++++++---- cockatrice/src/messagelogwidget.h | 2 +- cockatrice/src/tab_game.cpp | 5 ++++- common/decklist.cpp | 17 ++++++++++++++++- common/decklist.h | 4 +++- common/pb/context_deck_select.proto | 9 +++++---- common/server_player.cpp | 1 + 7 files changed, 38 insertions(+), 12 deletions(-) diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index ec9b90cb..cdf173b2 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -86,12 +86,16 @@ void MessageLogWidget::logLeaveSpectator(QString name) appendHtml(tr("%1 is not watching the game any more.").arg(sanitizeHtml(name))); } -void MessageLogWidget::logDeckSelect(Player *player, QString deckHash) +void MessageLogWidget::logDeckSelect(Player *player, QString deckHash, int sideboardSize) { - if (isFemale(player)) - appendHtml(tr("%1 has loaded a deck (%2).", "female").arg(sanitizeHtml(player->getName())).arg(deckHash)); + const char* gender = isFemale(player) ? "female" : "male"; + if (sideboardSize < 0) + appendHtml(tr("%1 has loaded a deck (%2).", gender).arg(sanitizeHtml(player->getName())).arg(deckHash)); else - appendHtml(tr("%1 has loaded a deck (%2).", "male").arg(sanitizeHtml(player->getName())).arg(deckHash)); + appendHtml(tr("%1 has loaded a deck with (%2) sideboard cards (%3).", gender). + arg(sanitizeHtml(player->getName())). + arg(sideboardSize). + arg(deckHash)); } void MessageLogWidget::logReadyStart(Player *player) diff --git a/cockatrice/src/messagelogwidget.h b/cockatrice/src/messagelogwidget.h index 1747a338..2b12b3c5 100644 --- a/cockatrice/src/messagelogwidget.h +++ b/cockatrice/src/messagelogwidget.h @@ -48,7 +48,7 @@ public slots: void logKicked(); void logJoinSpectator(QString name); void logLeaveSpectator(QString name); - void logDeckSelect(Player *player, QString deckHash); + void logDeckSelect(Player *player, QString deckHash, int sideboardSize); void logReadyStart(Player *player); void logNotReadyStart(Player *player); void logSetSideboardLock(Player *player, bool locked); diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index cee00037..b99fff02 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -1012,7 +1012,10 @@ void TabGame::eventPlayerPropertiesChanged(const Event_PlayerPropertiesChanged & break; } case GameEventContext::DECK_SELECT: { - messageLog->logDeckSelect(player, QString::fromStdString(context.GetExtension(Context_DeckSelect::ext).deck_hash())); + Context_DeckSelect deckSelect = context.GetExtension(Context_DeckSelect::ext); + messageLog->logDeckSelect(player, + QString::fromStdString(deckSelect.deck_hash()), + deckSelect.sideboard_size()); break; } case GameEventContext::SET_SIDEBOARD_LOCK: { diff --git a/common/decklist.cpp b/common/decklist.cpp index c0721556..90b5cb7e 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -633,12 +633,27 @@ QStringList DeckList::getCardList() const return result.toList(); } +int DeckList::getSideboardSize() const +{ + int size = 0; + for (int i = 0; i < root->size(); ++i) { + InnerDecklistNode *node = dynamic_cast(root->at(i)); + if (node->getName() != "side") + continue; + for (int j = 0; j < node->size(); j++) { + DecklistCardNode *card = dynamic_cast(node->at(j)); + size += card->getNumber(); + } + } + return size; +} + DecklistCardNode *DeckList::addCard(const QString &cardName, const QString &zoneName) { InnerDecklistNode *zoneNode = dynamic_cast(root->findChild(zoneName)); if (!zoneNode) zoneNode = new InnerDecklistNode(zoneName, root); - + DecklistCardNode *node = new DecklistCardNode(cardName, 1, zoneNode); updateDeckHash(); return node; diff --git a/common/decklist.h b/common/decklist.h index 94df407a..2eed52fc 100644 --- a/common/decklist.h +++ b/common/decklist.h @@ -160,7 +160,9 @@ public: void cleanList(); bool isEmpty() const { return root->isEmpty() && name.isEmpty() && comments.isEmpty() && sideboardPlans.isEmpty(); } QStringList getCardList() const; - + + int getSideboardSize() const; + QString getDeckHash() const { return deckHash; } void updateDeckHash(); diff --git a/common/pb/context_deck_select.proto b/common/pb/context_deck_select.proto index df4a95b5..f36c8b6c 100644 --- a/common/pb/context_deck_select.proto +++ b/common/pb/context_deck_select.proto @@ -1,8 +1,9 @@ import "game_event_context.proto"; message Context_DeckSelect { - extend GameEventContext { - optional Context_DeckSelect ext = 1002; - } - optional string deck_hash = 1; + extend GameEventContext { + optional Context_DeckSelect ext = 1002; + } + optional string deck_hash = 1; + optional int32 sideboard_size = 2 [default = -1]; } diff --git a/common/server_player.cpp b/common/server_player.cpp index a029abed..76cd260d 100644 --- a/common/server_player.cpp +++ b/common/server_player.cpp @@ -657,6 +657,7 @@ Response::ResponseCode Server_Player::cmdDeckSelect(const Command_DeckSelect &cm Context_DeckSelect context; context.set_deck_hash(deck->getDeckHash().toStdString()); + context.set_sideboard_size(deck->getSideboardSize()); ges.setGameEventContext(context); Response_DeckDownload *re = new Response_DeckDownload; From 8d31fe6cbc5d1260cf1ca34df05b70f8666bf75c Mon Sep 17 00:00:00 2001 From: Daenyth Date: Sat, 28 Jun 2014 09:04:45 -0400 Subject: [PATCH 17/17] Clean up deck load chat message --- cockatrice/src/messagelogwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index cdf173b2..d40b1068 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -92,7 +92,7 @@ void MessageLogWidget::logDeckSelect(Player *player, QString deckHash, int sideb if (sideboardSize < 0) appendHtml(tr("%1 has loaded a deck (%2).", gender).arg(sanitizeHtml(player->getName())).arg(deckHash)); else - appendHtml(tr("%1 has loaded a deck with (%2) sideboard cards (%3).", gender). + appendHtml(tr("%1 has loaded a deck with %2 sideboard cards (%3).", gender). arg(sanitizeHtml(player->getName())). arg(sideboardSize). arg(deckHash));