summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/CRSMConfig.cpp15
-rw-r--r--src/CRSMConfig.hpp14
-rw-r--r--src/crsm.cpp10
-rw-r--r--src/crsm.hpp32
4 files changed, 50 insertions, 21 deletions
diff --git a/src/CRSMConfig.cpp b/src/CRSMConfig.cpp
index 747aaa2..54b0e8f 100644
--- a/src/CRSMConfig.cpp
+++ b/src/CRSMConfig.cpp
@@ -45,20 +45,27 @@ CRSMConfigValueBase& CRSMConfigBase::getConfigValue(const QString& name)
}
}
-QString CRSMConfigBase::read(const QString &fileName)
+QString CRSMConfigBase::read(const QString &fileName, bool writeDefault)
{
QString ret = "";
QFile config(fileName);
if(!config.exists())
{
- if(write(fileName))
+ if(writeDefault)
{
- return fileName + ": The config-file did not exist, a new one with default values has been created.\n";
+ if(write(fileName))
+ {
+ return fileName + ": The config-file did not exist, a new one with default values has been created.\n";
+ }
+ else
+ {
+ return fileName + ": The config-file did not exist, a new one could not be created.\n";
+ }
}
else
{
- return fileName + ": The config-file did not exist, a new one could not be created.\n";
+ return ret;
}
}
else if(config.open(QIODevice::ReadOnly | QIODevice::Text))
diff --git a/src/CRSMConfig.hpp b/src/CRSMConfig.hpp
index 731698c..b875d6f 100644
--- a/src/CRSMConfig.hpp
+++ b/src/CRSMConfig.hpp
@@ -51,6 +51,9 @@ using Boolean = bool;
#define List(Type) QList<Type>
#define Map(KeyType, ValueType) QMap<KeyType, ValueType>
+
+#define ConfigValue(Value) {#Value, mkConfigValue(Value)}
+
template<>
class CRSMConfigValue<String> : public CRSMConfigValueBase {
String& config;
@@ -214,7 +217,7 @@ public:
void addConfigListEntry(const QString& name, const QString& value);
void setConfigMapValue(const QString& name, const QString& key, const QString& value);
- QString read(const QString& fileName);
+ QString read(const QString& fileName, bool writeDefault = true);
bool write(const QString& fileName);
protected:
@@ -302,7 +305,6 @@ public:
Integer RereadLimit = 50;
} Readline;
-#define ConfigValue(Value) {#Value, mkConfigValue(Value)}
explicit CRSMConfig() : CRSMConfigBase({
ConfigValue(CRSM.ManagementPort),
ConfigValue(CRSM.ListFolder),
@@ -359,14 +361,6 @@ public:
ConfigValue(Readline.PromptEnabled),
ConfigValue(Readline.RereadLimit)
}) {}
-#undef ConfigValue
void clear();
};
-
-
-#undef String
-#undef Integer
-#undef Boolean
-#undef List
-#undef Map
diff --git a/src/crsm.cpp b/src/crsm.cpp
index 4506c4b..2e7f1a4 100644
--- a/src/crsm.cpp
+++ b/src/crsm.cpp
@@ -62,8 +62,11 @@ CRSM::CRSM(QObject *parent) :
if(processManager->isRunning())
{
+ Session.read(SESSION_FILE_NAME, false);
writeToServer("Server Manager läuft wieder.\nBis zur nächsten Runde könnte unerwartetes Verhalten auftreten.\n");
}
+ QFile sessionFile(SESSION_FILE_NAME);
+ if(sessionFile.exists()) sessionFile.remove();
setupCmds();
@@ -275,6 +278,11 @@ void CRSM::readServerOutput()
{
Session.CountDown = countDownExp.cap(1).toInt();
}
+ static QRegExp countDownExp2(R"(^(\d+)\.\.\.)");
+ if(countDownExp2.exactMatch(what))
+ {
+ Session.CountDown = countDownExp2.cap(1).toInt();
+ }
static QRegExp countDownStopExp("^(?:Spielstart abgebrochen\\.|Game start aborted\\.)");
if(countDownStopExp.exactMatch(what))
@@ -294,6 +302,7 @@ void CRSM::readInput()
}
Config.Auto.ProcessManager.ReattachId = processManager->ID();
writeConfig();
+ Session.write(SESSION_FILE_NAME);
QCoreApplication::quit();
return;
}
@@ -2042,6 +2051,7 @@ CMD_FUNCTION_IMPL(exit)
CMD_FUNCTION_IMPL(exitDetach)
Config.Auto.ProcessManager.ReattachId = processManager->ID();
writeConfig();
+ Session.write(SESSION_FILE_NAME);
QCoreApplication::quit();
}
diff --git a/src/crsm.hpp b/src/crsm.hpp
index 43a15ae..b2f0671 100644
--- a/src/crsm.hpp
+++ b/src/crsm.hpp
@@ -23,6 +23,7 @@
#include "CRSMConfig.hpp"
#define CONFIG_FILE_NAME "CrServerManager.conf"
+#define SESSION_FILE_NAME "CrServerManager.session"
#define CUR_SCEN_FILE_NAME "curscen.txt"
#define LAST_SCEN_FILE_NAME "lastscen.txt"
#define SCOREBOARD_FILE_NAME Config.Auto.Volatile.Clonk.Directory + "scoreboard.html"
@@ -106,29 +107,46 @@ private:
CRSMConfig Config;
- struct CRSMSession {
- bool League = false;
+ struct CRSMSession : public CRSMConfigBase {
+ Boolean League = false;
enum {None = -1, Lobby = 0, Loading = 1, Running = 2} State = None;
- bool UserWish = false;
- int CountDown = -1;
- QString ScenarioName = "";
+ Boolean UserWish = false;
+ Integer CountDown = -1;
+ String ScenarioName = "";
struct {
ClientInfo Admin;
- QMap<QString, ClientInfo> Clients;
+ Map(String, ClientInfo) Clients;
QMap<ClientInfo, QDateTime> LeaveAdmins;
} Clonk;
struct {
ClientInfo Admin;
- bool UseIngameChat = false;
+ Boolean UseIngameChat = false;
} IRC;
void clear()
{
+ auto configVals = configValues;
*this = CRSMSession();
+ configValues = configVals;
}
+
+ CRSMSession() : CRSMConfigBase::CRSMConfigBase({
+ ConfigValue(League),
+ ConfigValue((Integer&)State),
+ ConfigValue(UserWish),
+ ConfigValue(CountDown),
+ ConfigValue(ScenarioName),
+
+ ConfigValue(Clonk.Admin),
+ ConfigValue(Clonk.Clients),
+ ConfigValue(Clonk.Clients),
+
+ ConfigValue(IRC.Admin),
+ ConfigValue(IRC.UseIngameChat),
+ }) {}
} Session;
QList<ScenarioSettings> userlist;