Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
73c963e9
Commit
73c963e9
authored
Oct 03, 2014
by
Gavin Bisesi
Browse files
Merge pull request #346 from ctrlaltca/servatrice_win32
Servatrice win32 fixes
parents
277aba79
871f5f7c
Changes
8
Hide whitespace changes
Inline
Side-by-side
cmake/NSIS.template.in
View file @
73c963e9
...
...
@@ -75,12 +75,15 @@ Section Uninstall
Delete "$INSTDIR\uninstall.exe"
Delete "$INSTDIR\cockatrice.exe"
Delete "$INSTDIR\oracle.exe"
Delete "$INSTDIR\servatrice.exe"
Delete "$INSTDIR\Usermanual.pdf"
Delete "$INSTDIR\libprotobuf.lib"
Delete "$INSTDIR\Qt*.dll"
Delete "$INSTDIR\icu*.dll"
Delete "$INSTDIR\qt.conf"
Delete "$INSTDIR\qdebug.txt"
Delete "$INSTDIR\servatrice.sql"
Delete "$INSTDIR\servatrice.ini.example"
RMDir "$INSTDIR"
RMDir "$SMPROGRAMS\Cockatrice"
...
...
servatrice/CMakeLists.txt
View file @
73c963e9
...
...
@@ -12,6 +12,7 @@ SET(servatrice_SOURCES
src/servatrice_database_interface.cpp
src/server_logger.cpp
src/serversocketinterface.cpp
src/settingscache.cpp
src/isl_interface.cpp
${
VERSION_STRING_CPP
}
)
...
...
servatrice/src/main.cpp
View file @
73c963e9
...
...
@@ -20,13 +20,14 @@
#include
<QCoreApplication>
#include
<QTextCodec>
#include
<QtGlobal>
#include
<iostream>
#include
<QMetaType>
#include
<QSettings>
#include
<QDateTime>
#include
"passwordhasher.h"
#include
"servatrice.h"
#include
"server_logger.h"
#include
"settingscache.h"
#include
"rng_sfmt.h"
#include
"version_string.h"
#include
<google/protobuf/stubs/common.h>
...
...
@@ -37,6 +38,7 @@
RNG_Abstract
*
rng
;
ServerLogger
*
logger
;
QThread
*
loggerThread
;
SettingsCache
*
settingsCache
;
/* Prototypes */
...
...
@@ -150,6 +152,10 @@ int main(int argc, char *argv[])
bool
testRandom
=
args
.
contains
(
"--test-random"
);
bool
testHashFunction
=
args
.
contains
(
"--test-hash"
);
bool
logToConsole
=
args
.
contains
(
"--log-to-console"
);
QString
configPath
;
int
hasConfigPath
=
args
.
indexOf
(
"--config"
);
if
(
hasConfigPath
>
-
1
&&
args
.
count
()
>
hasConfigPath
+
1
)
configPath
=
args
.
at
(
hasConfigPath
+
1
);
qRegisterMetaType
<
QList
<
int
>
>
(
"QList<int>"
);
...
...
@@ -158,7 +164,9 @@ int main(int argc, char *argv[])
QTextCodec
::
setCodecForCStrings
(
QTextCodec
::
codecForName
(
"UTF-8"
));
#endif
QSettings
*
settings
=
new
QSettings
(
"servatrice.ini"
,
QSettings
::
IniFormat
);
configPath
=
SettingsCache
::
guessConfigurationPath
(
configPath
);
qWarning
()
<<
"Using configuration file: "
<<
configPath
;
settingsCache
=
new
SettingsCache
();
loggerThread
=
new
QThread
;
loggerThread
->
setObjectName
(
"logger"
);
...
...
@@ -166,7 +174,7 @@ int main(int argc, char *argv[])
logger
->
moveToThread
(
loggerThread
);
loggerThread
->
start
();
QMetaObject
::
invokeMethod
(
logger
,
"startLog"
,
Qt
::
BlockingQueuedConnection
,
Q_ARG
(
QString
,
settings
->
value
(
"server/logfile"
).
toString
()));
QMetaObject
::
invokeMethod
(
logger
,
"startLog"
,
Qt
::
BlockingQueuedConnection
,
Q_ARG
(
QString
,
settings
Cache
->
value
(
"server/logfile"
,
QString
(
"server.log"
)
).
toString
()));
#if QT_VERSION < 0x050000
if
(
logToConsole
)
...
...
@@ -209,7 +217,7 @@ int main(int argc, char *argv[])
if
(
testHashFunction
)
testHash
();
Servatrice
*
server
=
new
Servatrice
(
settings
);
Servatrice
*
server
=
new
Servatrice
();
QObject
::
connect
(
server
,
SIGNAL
(
destroyed
()),
&
app
,
SLOT
(
quit
()),
Qt
::
QueuedConnection
);
int
retval
=
0
;
if
(
server
->
initServer
())
{
...
...
@@ -228,7 +236,7 @@ int main(int argc, char *argv[])
}
delete
rng
;
delete
settings
;
delete
settings
Cache
;
logger
->
deleteLater
();
loggerThread
->
wait
();
...
...
servatrice/src/servatrice.cpp
View file @
73c963e9
...
...
@@ -18,7 +18,6 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include
<QSqlQuery>
#include
<QSettings>
#include
<QFile>
#include
<QTimer>
#include
<QDateTime>
...
...
@@ -28,6 +27,7 @@
#include
"servatrice_database_interface.h"
#include
"servatrice_connection_pool.h"
#include
"server_room.h"
#include
"settingscache.h"
#include
"serversocketinterface.h"
#include
"isl_interface.h"
#include
"server_logger.h"
...
...
@@ -120,8 +120,8 @@ void Servatrice_IslServer::incomingConnection(int socketDescriptor)
QMetaObject
::
invokeMethod
(
interface
,
"initServer"
,
Qt
::
QueuedConnection
);
}
Servatrice
::
Servatrice
(
QSettings
*
_settings
,
QObject
*
parent
)
:
Server
(
true
,
parent
),
settings
(
_settings
),
uptime
(
0
),
shutdownTimer
(
0
)
Servatrice
::
Servatrice
(
QObject
*
parent
)
:
Server
(
true
,
parent
),
uptime
(
0
),
shutdownTimer
(
0
)
{
qRegisterMetaType
<
QSqlDatabase
>
(
"QSqlDatabase"
);
}
...
...
@@ -134,11 +134,11 @@ Servatrice::~Servatrice()
bool
Servatrice
::
initServer
()
{
serverName
=
settings
->
value
(
"server/name"
).
toString
();
serverId
=
settings
->
value
(
"server/id"
,
0
).
toInt
();
bool
regServerOnly
=
settings
->
value
(
"server/regonly"
,
0
).
toBool
();
serverName
=
settings
Cache
->
value
(
"server/name"
,
"My Cockatrice server"
).
toString
();
serverId
=
settings
Cache
->
value
(
"server/id"
,
0
).
toInt
();
bool
regServerOnly
=
settings
Cache
->
value
(
"server/regonly"
,
0
).
toBool
();
const
QString
authenticationMethodStr
=
settings
->
value
(
"authentication/method"
).
toString
();
const
QString
authenticationMethodStr
=
settings
Cache
->
value
(
"authentication/method"
).
toString
();
if
(
authenticationMethodStr
==
"sql"
)
{
authenticationMethod
=
AuthenticationSql
;
}
else
{
...
...
@@ -149,7 +149,7 @@ bool Servatrice::initServer()
authenticationMethod
=
AuthenticationNone
;
}
QString
dbTypeStr
=
settings
->
value
(
"database/type"
).
toString
();
QString
dbTypeStr
=
settings
Cache
->
value
(
"database/type"
).
toString
();
if
(
dbTypeStr
==
"mysql"
)
databaseType
=
DatabaseMySql
;
else
...
...
@@ -159,14 +159,14 @@ bool Servatrice::initServer()
setDatabaseInterface
(
servatriceDatabaseInterface
);
if
(
databaseType
!=
DatabaseNone
)
{
settings
->
beginGroup
(
"database"
);
dbPrefix
=
settings
->
value
(
"prefix"
).
toString
();
settings
Cache
->
beginGroup
(
"database"
);
dbPrefix
=
settings
Cache
->
value
(
"prefix"
).
toString
();
servatriceDatabaseInterface
->
initDatabase
(
"QMYSQL"
,
settings
->
value
(
"hostname"
).
toString
(),
settings
->
value
(
"database"
).
toString
(),
settings
->
value
(
"user"
).
toString
(),
settings
->
value
(
"password"
).
toString
());
settings
->
endGroup
();
settings
Cache
->
value
(
"hostname"
).
toString
(),
settings
Cache
->
value
(
"database"
).
toString
(),
settings
Cache
->
value
(
"user"
).
toString
(),
settings
Cache
->
value
(
"password"
).
toString
());
settings
Cache
->
endGroup
();
updateServerList
();
...
...
@@ -174,7 +174,7 @@ bool Servatrice::initServer()
servatriceDatabaseInterface
->
clearSessionTables
();
}
const
QString
roomMethod
=
settings
->
value
(
"rooms/method"
).
toString
();
const
QString
roomMethod
=
settings
Cache
->
value
(
"rooms/method"
).
toString
();
if
(
roomMethod
==
"sql"
)
{
QSqlQuery
query
(
servatriceDatabaseInterface
->
getDatabase
());
query
.
prepare
(
"select id, name, descr, auto_join, join_message from "
+
dbPrefix
+
"_rooms order by id asc"
);
...
...
@@ -198,47 +198,63 @@ bool Servatrice::initServer()
));
}
}
else
{
int
size
=
settings
->
beginReadArray
(
"rooms/roomlist"
);
int
size
=
settings
Cache
->
beginReadArray
(
"rooms/roomlist"
);
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
settings
->
setArrayIndex
(
i
);
settings
Cache
->
setArrayIndex
(
i
);
QStringList
gameTypes
;
int
size2
=
settings
->
beginReadArray
(
"game_types"
);
int
size2
=
settings
Cache
->
beginReadArray
(
"game_types"
);
for
(
int
j
=
0
;
j
<
size2
;
++
j
)
{
settings
->
setArrayIndex
(
j
);
gameTypes
.
append
(
settings
->
value
(
"name"
).
toString
());
settings
Cache
->
setArrayIndex
(
j
);
gameTypes
.
append
(
settings
Cache
->
value
(
"name"
).
toString
());
}
settings
->
endArray
();
settings
Cache
->
endArray
();
Server_Room
*
newRoom
=
new
Server_Room
(
i
,
settings
->
value
(
"name"
).
toString
(),
settings
->
value
(
"description"
).
toString
(),
settings
->
value
(
"autojoin"
).
toBool
(),
settings
->
value
(
"joinmessage"
).
toString
(),
settings
Cache
->
value
(
"name"
).
toString
(),
settings
Cache
->
value
(
"description"
).
toString
(),
settings
Cache
->
value
(
"autojoin"
).
toBool
(),
settings
Cache
->
value
(
"joinmessage"
).
toString
(),
gameTypes
,
this
);
addRoom
(
newRoom
);
}
settings
->
endArray
();
if
(
size
==
0
)
{
// no room defined in config, add a dummy one
Server_Room
*
newRoom
=
new
Server_Room
(
0
,
"General room"
,
"Play anything here."
,
true
,
""
,
QStringList
(
"Standard"
),
this
);
addRoom
(
newRoom
);
}
settingsCache
->
endArray
();
}
updateLoginMessage
();
maxGameInactivityTime
=
settings
->
value
(
"game/max_game_inactivity_time"
).
toInt
();
maxPlayerInactivityTime
=
settings
->
value
(
"game/max_player_inactivity_time"
).
toInt
();
maxGameInactivityTime
=
settings
Cache
->
value
(
"game/max_game_inactivity_time"
,
120
).
toInt
();
maxPlayerInactivityTime
=
settings
Cache
->
value
(
"game/max_player_inactivity_time"
,
15
).
toInt
();
maxUsersPerAddress
=
settings
->
value
(
"security/max_users_per_address"
).
toInt
();
messageCountingInterval
=
settings
->
value
(
"security/message_counting_interval"
).
toInt
();
maxMessageCountPerInterval
=
settings
->
value
(
"security/max_message_count_per_interval"
).
toInt
();
maxMessageSizePerInterval
=
settings
->
value
(
"security/max_message_size_per_interval"
).
toInt
();
maxGamesPerUser
=
settings
->
value
(
"security/max_games_per_user"
).
toInt
();
maxUsersPerAddress
=
settings
Cache
->
value
(
"security/max_users_per_address"
,
4
).
toInt
();
messageCountingInterval
=
settings
Cache
->
value
(
"security/message_counting_interval"
,
10
).
toInt
();
maxMessageCountPerInterval
=
settings
Cache
->
value
(
"security/max_message_count_per_interval"
,
10
).
toInt
();
maxMessageSizePerInterval
=
settings
Cache
->
value
(
"security/max_message_size_per_interval"
,
1000
).
toInt
();
maxGamesPerUser
=
settings
Cache
->
value
(
"security/max_games_per_user"
,
5
).
toInt
();
try
{
if
(
settings
->
value
(
"servernetwork/active"
,
0
).
toInt
())
{
try
{
if
(
settings
Cache
->
value
(
"servernetwork/active"
,
0
).
toInt
())
{
qDebug
()
<<
"Connecting to ISL network."
;
const
QString
certFileName
=
settings
->
value
(
"servernetwork/ssl_cert"
).
toString
();
const
QString
keyFileName
=
settings
->
value
(
"servernetwork/ssl_key"
).
toString
();
const
QString
certFileName
=
settings
Cache
->
value
(
"servernetwork/ssl_cert"
).
toString
();
const
QString
keyFileName
=
settings
Cache
->
value
(
"servernetwork/ssl_key"
).
toString
();
qDebug
()
<<
"Loading certificate..."
;
QFile
certFile
(
certFileName
);
if
(
!
certFile
.
open
(
QIODevice
::
ReadOnly
))
...
...
@@ -282,7 +298,7 @@ bool Servatrice::initServer()
QMetaObject
::
invokeMethod
(
interface
,
"initClient"
,
Qt
::
BlockingQueuedConnection
);
}
const
int
networkPort
=
settings
->
value
(
"servernetwork/port"
,
14747
).
toInt
();
const
int
networkPort
=
settings
Cache
->
value
(
"servernetwork/port"
,
14747
).
toInt
();
qDebug
()
<<
"Starting ISL server on port"
<<
networkPort
;
islServer
=
new
Servatrice_IslServer
(
this
,
cert
,
key
,
this
);
...
...
@@ -299,7 +315,7 @@ bool Servatrice::initServer()
connect
(
pingClock
,
SIGNAL
(
timeout
()),
this
,
SIGNAL
(
pingClockTimeout
()));
pingClock
->
start
(
1000
);
int
statusUpdateTime
=
settings
->
value
(
"server/statusupdate"
).
toInt
();
int
statusUpdateTime
=
settings
Cache
->
value
(
"server/statusupdate"
,
15000
).
toInt
();
statusUpdateClock
=
new
QTimer
(
this
);
connect
(
statusUpdateClock
,
SIGNAL
(
timeout
()),
this
,
SLOT
(
statusUpdate
()));
if
(
statusUpdateTime
!=
0
)
{
...
...
@@ -307,10 +323,10 @@ bool Servatrice::initServer()
statusUpdateClock
->
start
(
statusUpdateTime
);
}
const
int
numberPools
=
settings
->
value
(
"server/number_pools"
,
1
).
toInt
();
const
int
numberPools
=
settings
Cache
->
value
(
"server/number_pools"
,
1
).
toInt
();
gameServer
=
new
Servatrice_GameServer
(
this
,
numberPools
,
servatriceDatabaseInterface
->
getDatabase
(),
this
);
gameServer
->
setMaxPendingConnections
(
1000
);
const
int
gamePort
=
settings
->
value
(
"server/port"
,
4747
).
toInt
();
const
int
gamePort
=
settings
Cache
->
value
(
"server/port"
,
4747
).
toInt
();
qDebug
()
<<
"Starting server on port"
<<
gamePort
;
if
(
gameServer
->
listen
(
QHostAddress
::
Any
,
gamePort
))
qDebug
()
<<
"Server listening."
;
...
...
servatrice/src/servatrice.h
View file @
73c963e9
...
...
@@ -32,7 +32,6 @@
Q_DECLARE_METATYPE
(
QSqlDatabase
)
class
QSettings
;
class
QSqlQuery
;
class
QTimer
;
...
...
@@ -106,7 +105,6 @@ private:
mutable
QMutex
loginMessageMutex
;
QString
loginMessage
;
QString
dbPrefix
;
QSettings
*
settings
;
Servatrice_DatabaseInterface
*
servatriceDatabaseInterface
;
int
serverId
;
int
uptime
;
...
...
@@ -128,7 +126,7 @@ public slots:
void
scheduleShutdown
(
const
QString
&
reason
,
int
minutes
);
void
updateLoginMessage
();
public:
Servatrice
(
QSettings
*
_settings
,
QObject
*
parent
=
0
);
Servatrice
(
QObject
*
parent
=
0
);
~
Servatrice
();
bool
initServer
();
QString
getServerName
()
const
{
return
serverName
;
}
...
...
servatrice/src/server_logger.cpp
View file @
73c963e9
#include
"server_logger.h"
#include
"settingscache.h"
#include
<QSocketNotifier>
#include
<QFile>
#include
<QTextStream>
#include
<QDateTime>
#include
<QSettings>
#include
<iostream>
#ifdef Q_OS_UNIX
# include <sys/types.h>
...
...
@@ -26,7 +26,7 @@ ServerLogger::~ServerLogger()
void
ServerLogger
::
startLog
(
const
QString
&
logFileName
)
{
if
(
!
logFileName
.
isEmpty
())
{
logFile
=
new
QFile
(
"server.log"
,
this
);
logFile
=
new
QFile
(
logFileName
,
this
);
logFile
->
open
(
QIODevice
::
Append
);
#ifdef Q_OS_UNIX
::
socketpair
(
AF_UNIX
,
SOCK_STREAM
,
0
,
sigHupFD
);
...
...
@@ -50,9 +50,8 @@ void ServerLogger::logMessage(QString message, void *caller)
callerString
=
QString
::
number
((
qulonglong
)
caller
,
16
)
+
" "
;
//filter out all log entries based on values in configuration file
QSettings
settings
(
"servatrice.ini"
,
QSettings
::
IniFormat
);
bool
shouldWeWriteLog
=
settings
.
value
(
"server/writelog"
).
toBool
();
QString
logFilters
=
settings
.
value
(
"server/logfilters"
).
toString
();
bool
shouldWeWriteLog
=
settingsCache
->
value
(
"server/writelog"
).
toBool
();
QString
logFilters
=
settingsCache
->
value
(
"server/logfilters"
).
toString
();
QStringList
listlogFilters
=
logFilters
.
split
(
","
,
QString
::
SkipEmptyParts
);
bool
shouldWeSkipLine
=
false
;
...
...
servatrice/src/settingscache.cpp
0 → 100644
View file @
73c963e9
#include
"settingscache.h"
#include
<QCoreApplication>
#include
<QFile>
#if QT_VERSION >= 0x050000
#include
<QStandardPaths>
#else
#include
<QDesktopServices>
#endif
QString
SettingsCache
::
guessConfigurationPath
(
QString
&
specificPath
)
{
const
QString
fileName
=
"servatrice.ini"
;
QString
guessFileName
;
// specific path
if
(
!
specificPath
.
isEmpty
()
&&
QFile
::
exists
(
specificPath
))
return
specificPath
;
// application directory path
guessFileName
=
QCoreApplication
::
applicationDirPath
()
+
"/"
+
fileName
;
if
(
QFile
::
exists
(
guessFileName
))
return
guessFileName
;
#ifdef Q_OS_UNIX
// /etc
guessFileName
=
"/etc/servatrice/"
+
fileName
;
if
(
QFile
::
exists
(
guessFileName
))
return
guessFileName
;
#endif
#if QT_VERSION >= 0x050000
guessFileName
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
DataLocation
)
+
"/"
+
fileName
;
#else
guessFileName
=
QDesktopServices
::
storageLocation
(
QDesktopServices
::
DataLocation
)
+
"/"
+
fileName
;
#endif
return
guessFileName
;
}
\ No newline at end of file
servatrice/src/settingscache.h
0 → 100644
View file @
73c963e9
#ifndef SERVATRICE_SETTINGSCACHE_H
#define SERVATRICE_SETTINGSCACHE_H
#include
<QSettings>
#include
<QString>
class
SettingsCache
:
public
QSettings
{
Q_OBJECT
private:
QSettings
*
settings
;
public:
SettingsCache
(
const
QString
&
fileName
=
"servatrice.ini"
,
QSettings
::
Format
format
=
QSettings
::
IniFormat
,
QObject
*
parent
=
0
)
{
};
static
QString
guessConfigurationPath
(
QString
&
specificPath
);
};
extern
SettingsCache
*
settingsCache
;
#endif
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment