updated code structure

cleaned code structure up for clarity
This commit is contained in:
woogerboy21 2014-06-23 03:41:46 -04:00
parent 236e0a4197
commit 46ceeadbbd

View file

@ -5,11 +5,13 @@
#include <QDateTime>
#include <QSettings>
#include <iostream>
#include <list>
#ifdef Q_OS_UNIX
# include <sys/types.h>
# include <sys/socket.h>
# include <unistd.h>
#endif
using namespace std;
ServerLogger::ServerLogger(bool _logToConsole, QObject *parent)
: QObject(parent), logToConsole(_logToConsole), flushRunning(false)
@ -51,34 +53,42 @@ 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<string> 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<string>::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();