Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Robosturm committed Oct 3, 2023
1 parent a07d232 commit ebdede9
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
"typeinfo": "cpp",
"qnetworkinterface": "cpp",
"qsslsocket": "cpp",
"qvector": "cpp"
"qvector": "cpp",
"qjsonobject": "cpp",
"qjsonvalueref": "cpp"
},
}
2 changes: 1 addition & 1 deletion coreengine/gameconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ void GameConsole::logActions(bool log)

void GameConsole::extractResources()
{
QString targetDir = "extractedResources/";
QString targetDir = QString("extractedResources_Version_") + Mainapp::getGameVersion().replace(".", "_") + "/";
QDir target(targetDir);
if (target.exists())
{
Expand Down
2 changes: 1 addition & 1 deletion coreengine/mainapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public slots:
*/
static QString getGameVersion()
{
return "Version: " + QString::number(VERSION_MAJOR) + "." + QString::number(VERSION_MINOR) + "." + QString::number(VERSION_REVISION)+ "-" + QString(VERSION_SUFFIX);
return QString::number(VERSION_MAJOR) + "." + QString::number(VERSION_MINOR) + "." + QString::number(VERSION_REVISION)+ "-" + QString(VERSION_SUFFIX);
}
/**
* @brief showCrashReport
Expand Down
11 changes: 10 additions & 1 deletion game/gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,16 @@ void GameRules::serializeObject(QDataStream& pStream, bool forHash) const
{
pStream << m_multiplayerObserver;
pStream << m_maxPerkCount;
pStream << m_matchType;
if (Mainapp::getSlave())
{
pStream << m_matchType;
}
else
{
// don't save match type on clients
QString dummy;
pStream << dummy;
}
pStream << m_mapPalette;
}
pStream << static_cast<qint32>(m_damageFormula);
Expand Down
3 changes: 2 additions & 1 deletion general.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,8 @@
<file>ai/training/heavyai_training.js</file>
<file>ai/training/normalai_training.js</file>
<file>ai/training/situation_training.js</file>
<file>templates/serverscript/matchMaking/tournee.js</file>
<file>templates/serverscript/matchMaking/automatchmaker.js</file>
<file>templates/serverscript/matchMaking/automatchmaker.json</file>
<file>resources/scripts/building/field_base.js</file>
<file>resources/scripts/actions/ACTION_FOCUSMAP.js</file>
</qresource>
Expand Down
2 changes: 1 addition & 1 deletion menue/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Mainwindow::Mainwindow(const QString & initialView)
style.color = Qt::black;
spLabel pTextfield = MemoryManagement::create<Label>(300);
pTextfield->setStyle(style);
pTextfield->setHtmlText(Mainapp::getGameVersion());
pTextfield->setHtmlText("Version: " + Mainapp::getGameVersion());
pTextfield->setPosition(oxygine::Stage::getStage()->getWidth() - 10 - pTextfield->getTextRect().width(), oxygine::Stage::getStage()->getHeight() - 10 - pTextfield->getTextRect().height());
pTextfield->addClickListener([this](oxygine::Event*)
{
Expand Down
27 changes: 25 additions & 2 deletions network/automatchmaker.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <QJsonObject>
#include <QJsonValueRef>
#include <QJsonArray>
#include <QJsonDocument>

Expand Down Expand Up @@ -80,19 +81,26 @@ void AutoMatchMaker::onNewMatchResultData(const QJsonObject & objData)
pInterpreter->doFunction(m_matchId, "onNewMatchResultData", args);
}

void AutoMatchMaker::createNewGame(const QString players)
void AutoMatchMaker::createNewGame(const QStringList players, const QStringList modList)
{
spNetworkInterface dummy;
Multiplayermenu multiplayermenu(dummy, "", Multiplayermenu::NetworkMode::Host);
Interpreter* pInterpreter = Interpreter::getInstance();
QJSValueList args({pInterpreter->newQObject(this),
pInterpreter->newQObject(&multiplayermenu),
players,
pInterpreter->arraytoJSValue(players),
pInterpreter->newQObject(&m_mainServer)});
pInterpreter->doFunction(m_matchId, "onCreateNewGame", args);
QString saveFile = "savegames/" + m_matchId + QString::number(m_matchCounter) + ".lsav";
auto doc = multiplayermenu.doSaveLobbyState(saveFile, "");
QJsonObject objData = doc.object();
objData.remove(JsonKeys::JSONKEY_USEDMODS);
QJsonObject mods;
for (qint32 i = 0; i < modList.size(); ++i)
{
mods.insert(JsonKeys::JSONKEY_MOD + QString::number(i), modList[i]);
}
objData.insert(JsonKeys::JSONKEY_USEDMODS, mods);
m_mainServer.onSlaveInfoDespawning(0, objData);
++m_matchCounter;
}
Expand Down Expand Up @@ -431,6 +439,21 @@ QJsonObject AutoMatchMaker::getBracketGraphInfo()
return graphInfo;
}

QString AutoMatchMaker::readDataFromJson(const QString & filePath)
{
if (QFile::exists(filePath))
{
QFile file(filePath);
file.open(QIODevice::ReadOnly);
QTextStream stream(&file);
return stream.readAll();
}
else
{
return "";
}
}

bool AutoMatchMaker::getRunning() const
{
return m_running;
Expand Down
3 changes: 2 additions & 1 deletion network/automatchmaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class AutoMatchMaker : public QObject, public FileSerializable
*/
QJsonObject getBracketGraphInfo();
Q_INVOKABLE bool getSignedUp(const QString playerId);
Q_INVOKABLE void createNewGame(const QString players);
Q_INVOKABLE void createNewGame(const QStringList players, const QStringList modList);
Q_INVOKABLE QString getMatchId() const;
Q_INVOKABLE void updateMmr(const QString player1, const QString player2, qint32 maxEloChange, GameEnums::GameResult gameResultForPlayer1);
Q_INVOKABLE bool setMmr(const QString player, qint32 mmr);
Expand Down Expand Up @@ -130,6 +130,7 @@ class AutoMatchMaker : public QObject, public FileSerializable
Q_INVOKABLE static QString getBracketGraphPreviousMatchId();
Q_INVOKABLE static QString getBracketGraphPreviousWinnersId();
Q_INVOKABLE static QString getBracketGraphPreviousPlayersId();
Q_INVOKABLE QString readDataFromJson(const QString & filePath);
private:
QString m_matchId;
MainServer & m_mainServer;
Expand Down
55 changes: 55 additions & 0 deletions templates/serverscript/matchMaking/automatchmaker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
var AUTOMATCHMAKER =
{
jsonFileName = "server/automatchmaker.json",
getName = function(autoMatchMaker, server)
{
var obj = JSON.parse(autoMatchMaker.readDataFromJson(AUTOMATCHMAKER.jsonFileName));
return obj.name;
},

getDescription = function(autoMatchMaker, server)
{
var obj = JSON.parse(autoMatchMaker.readDataFromJson(AUTOMATCHMAKER.jsonFileName));
return obj.description;
},

getIsSignUpChangeAllowed = function(autoMatchMaker, server)
{
var obj = JSON.parse(autoMatchMaker.readDataFromJson(AUTOMATCHMAKER.jsonFileName));
return obj.isSignUpChangeAllowed;
},

onNewMatchResultData = function(autoMatchMaker, usernames, results, server)
{
var obj = JSON.parse(autoMatchMaker.readDataFromJson(AUTOMATCHMAKER.jsonFileName));
autoMatchMaker.updateMmr(usernames[0], usernames[1], obj.maxMmrChange, results[0])
for (var i = 0; i < usernames.length; ++i)
{
AUTOMATCHMAKER.createNewMatchForPlayer(autoMatchMaker, usernames[i], server);
}
},

onCreateNewGame = function(autoMatchMaker, multiplayerMenu, players, server)
{
// todo
},

createNewMatchForPlayer = function(autoMatchMaker, usernames, server)
{

},

onNewPlayerData = function(autoMatchMaker, player, minGames, maxGames, server)
{
for (var i = 0; i < minGames; ++i)
{
AUTOMATCHMAKER.createNewMatchForPlayer(autoMatchMaker, player, server);
}
},

getBracketGraphInfo = function(autoMatchMaker, server)
{
// JSON.stringify()
return "";
},
}
11 changes: 11 additions & 0 deletions templates/serverscript/matchMaking/automatchmaker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name" : "My auto mach",
"description" : "My auto match description",
"isSignUpChangeAllowed" : true,
"maxMmrChange" : 30,
"searchRangeSteps" : 100,
"matchHistory" : 10,
"maps" : [],
"rule" : "",
"mods" : []
}
3 changes: 0 additions & 3 deletions templates/serverscript/matchMaking/tournee.js

This file was deleted.

0 comments on commit ebdede9

Please sign in to comment.