diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2015-04-01 15:28:35 +0200 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2015-04-01 15:28:35 +0200 |
| commit | 64bfe2fa7bd43de041d69b5fa1687d0a04004866 (patch) | |
| tree | 41bcfde17f6ecc235ba97b16af05304730faeecc /crsm.cpp | |
| parent | 282ca19b2e72c3c9d66caed3421318aabcaed192 (diff) | |
| download | manager-64bfe2fa7bd43de041d69b5fa1687d0a04004866.tar.gz manager-64bfe2fa7bd43de041d69b5fa1687d0a04004866.zip | |
Added option to randomly walk through scenarios.lst
(RandomizeAutoHosting).
Diffstat (limited to 'crsm.cpp')
| -rw-r--r-- | crsm.cpp | 51 |
1 files changed, 36 insertions, 15 deletions
@@ -15,6 +15,7 @@ CRSM::CRSM(QObject *parent) : QObject(parent) { + qsrand(QDateTime::currentMSecsSinceEpoch()); codec = QTextCodec::codecForName("Windows-1252"); qout = new QTextStream(stdout, QIODevice::WriteOnly | QIODevice::Unbuffered); qin = new QTextStream(stdin, QIODevice::ReadOnly); @@ -24,7 +25,6 @@ CRSM::CRSM(QObject *parent) : outputBuffer.open(QFile::WriteOnly | QFile::Unbuffered); args << "/fullscreen" << "/config:config" << "/lobby:60" << "/nosignup"; - current = 0; finish = false; readConfig(); @@ -350,8 +350,9 @@ void CRSM::nextScen() } else { - startScen(autolist.at(current), args); - if(++current >= autolist.length()) current = 0; + startScen(nextAutoScens.first(), args); + nextAutoScens.removeFirst(); + updateNextAutoScens(); } } @@ -607,6 +608,22 @@ void CRSM::managementConnectionDisconnected() } } +void CRSM::updateNextAutoScens() +{ + while(nextAutoScens.length() < settings["UserListLength"].toInt()) + { + if(settings["RandomizeAutoHosting"] == "true") + { + nextAutoScens.append(autolist.at(qrand() % autolist.length())); + } + else + { + nextAutoScens.append(autolist.at(current)); + if(++current >= autolist.length()) current = 0; + } + } +} + void CRSM::startScen(const ScenarioSettings &scen, QStringList argList) { QString filename; @@ -650,6 +667,8 @@ void CRSM::startScen(const ScenarioSettings &scen, QStringList argList) void CRSM::readConfig() { + lists.clear(); + settings.clear(); settings["EmptyTimer"] = "60"; QFile config(CONFIG_FILE_NAME); if(!config.exists() || !config.open(QIODevice::ReadOnly | QIODevice::Text)) @@ -764,6 +783,8 @@ void CRSM::readScenarios() QStringList scenlist = QString(scenfile.readAll()).trimmed().split("\n",QString::SkipEmptyParts); out("Scenarios in list:\n"); autolist.clear(); + nextAutoScens.clear(); + current = 0; foreach(const QString &args, scenlist) { ScenarioSettings scen(args, ClientInfo::autoClient()); @@ -788,6 +809,7 @@ void CRSM::readScenarios() out("\n"); scenfile.close(); + updateNextAutoScens(); } QMap<QString, QString> CRSM::defaultSettings() @@ -924,21 +946,22 @@ QString CRSM::printQueue() return "Die Warteschlange ist leer.\n"; } ret = "Folgende Szenarien befinden sich in der Warteschlange:\n"; - if(autoHost) + for(int i = 0; i < settings["UserListLength"].toInt(); ++i) { - for(int i = 0; i<settings["UserListLength"].toInt(); i++) + const ScenarioSettings *scen; + if(i < userlist.length()) { - ret += "\t"+QString::number(i+1)+". "+(userlist.length()>i?userlist.at(i).name + " (" + userlist.at(i).wishClient.toString() + ")" + (userlist.at(i).league ? " in der Liga" : ""):autolist.at((i-userlist.length() + current)%autolist.length()).name + " " + autolist.at((i-userlist.length() + current)%autolist.length()).wishClient.toString() + (autolist.at((i-userlist.length() + current)%autolist.length()).league ? " in der Liga" : ""))+"\n"; + scen = &userlist.at(i); } - } - else - { - int i = 1; - foreach(const ScenarioSettings& scen, userlist) + else if(!autoHost) { - ret += "\t" + QString::number(i) + ". " + scen.name + " (" + scen.wishClient.toString() + ")" + (scen.league ? " in der Liga" : "") + "\n"; - ++i; + break; } + else + { + scen = &nextAutoScens.at(i - userlist.length()); + } + ret += "\t" + QString::number(i + 1) + ". " + scen->name + (scen->league ? " in der Liga" : "") + " (" + scen->wishClient.toString() + ")\n"; } return ret; } @@ -1939,8 +1962,6 @@ CMD_FUNCTION_IMPL(exitAfter) CMD_FUNCTION_IMPL(reload) { out("Reloading configuration..."); - lists.clear(); - settings.clear(); ircModChecks.clear(); ircMods.clear(); ircModFifosOld.clear(); |
