From 4f73091bb5bdbdb91329b9a4ef647fc8286d423c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 3 Aug 2013 23:58:39 +0200 Subject: Errr... I forgot. --- backend/BaseInstance.h | 33 +++----- backend/CMakeLists.txt | 8 +- backend/InstanceFactory.cpp | 12 ++- backend/InstanceFactory.h | 3 +- backend/LegacyInstance.cpp | 14 +++- backend/LegacyInstance.h | 4 +- backend/OneSixAssets.cpp | 157 +++++++++++++++++++++++++++++++++++++++ backend/OneSixAssets.h | 21 ++++++ backend/OneSixInstance.cpp | 22 +++++- backend/OneSixInstance.h | 4 + backend/tasks/GameUpdateTask.cpp | 90 ++-------------------- backend/tasks/GameUpdateTask.h | 81 +------------------- backend/tasks/LoginResponse.cpp | 69 ----------------- backend/tasks/LoginResponse.h | 94 ----------------------- backend/tasks/LoginTask.cpp | 2 +- backend/tasks/LoginTask.h | 9 ++- 16 files changed, 256 insertions(+), 367 deletions(-) create mode 100644 backend/OneSixAssets.cpp create mode 100644 backend/OneSixAssets.h delete mode 100644 backend/tasks/LoginResponse.cpp delete mode 100644 backend/tasks/LoginResponse.h (limited to 'backend') diff --git a/backend/BaseInstance.h b/backend/BaseInstance.h index 088075f2..1bb2ce17 100644 --- a/backend/BaseInstance.h +++ b/backend/BaseInstance.h @@ -57,42 +57,20 @@ public: /// Path to the instance's root directory. QString rootDir() const; - /*! - * \brief Gets the instance list that this instance is a part of. - * Returns NULL if this instance is not in a list - * (the parent is not an InstanceList). - * \return A pointer to the InstanceList containing this instance. - */ - InstanceList *instList() const; - - - //////// INSTANCE INFO //////// - - /// The name of the instance that is displayed to the user. QString name() const; - - /// Set the name of the instance that is displayed to the user. void setName(QString val); - /// The instance's icon key. QString iconKey() const; - - /// Set the instance's icon key. void setIconKey(QString val); - //! The instance's notes. QString notes() const; - - /// set the instance notes text void setNotes(QString val); - //! The instance's group. QString group() const; - - /// set the instance group void setGroup(QString val); - //// Timestamps //// + virtual bool setIntendedVersionId(QString version) = 0; + virtual QString intendedVersionId() = 0; /** * Gets the time that the instance was last launched. @@ -102,6 +80,13 @@ public: /// Sets the last launched time to 'val' milliseconds since epoch void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch()); + /*! + * \brief Gets the instance list that this instance is a part of. + * Returns NULL if this instance is not in a list + * (the parent is not an InstanceList). + * \return A pointer to the InstanceList containing this instance. + */ + InstanceList *instList() const; /*! * \brief Gets a pointer to this instance's version list. diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index 9bd07c01..f79ef8ef 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -26,6 +26,8 @@ LegacyInstance.h OneSixInstance.h InstanceFactory.h +OneSixAssets.h + # Versions InstanceVersion.h MinecraftVersion.h @@ -41,9 +43,8 @@ lists/LwjglVersionList.h # Tasks tasks/Task.h tasks/LoginTask.h -tasks/LoginResponse.h -tasks/UserInfo.h tasks/GameUpdateTask.h +tasks/UserInfo.h MinecraftProcess.h ) @@ -55,6 +56,8 @@ LegacyInstance.cpp OneSixInstance.cpp InstanceFactory.cpp +OneSixAssets.cpp + # Versions InstanceVersion.cpp MinecraftVersion.cpp @@ -72,7 +75,6 @@ tasks/Task.cpp tasks/LoginTask.cpp tasks/GameUpdateTask.cpp tasks/UserInfo.cpp -tasks/LoginResponse.cpp MinecraftProcess.cpp ) diff --git a/backend/InstanceFactory.cpp b/backend/InstanceFactory.cpp index ee582d3f..f3636da3 100644 --- a/backend/InstanceFactory.cpp +++ b/backend/InstanceFactory.cpp @@ -21,6 +21,7 @@ #include "BaseInstance.h" #include "LegacyInstance.h" #include "OneSixInstance.h" +#include "InstanceVersion.h" #include "inifile.h" #include @@ -61,7 +62,7 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst } -InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *&inst, const QString &instDir) +InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& inst, const InstVersion* version, const QString& instDir ) { QDir rootDir(instDir); @@ -70,9 +71,14 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *& { return InstanceFactory::CantCreateDir; } - return InstanceFactory::UnknownCreateError; - //inst = new BaseInstance(instDir, this); + auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg")); + m_settings->registerSetting(new Setting("InstanceType", "Legacy")); + m_settings->set("InstanceType", "OneSix"); + + inst = new OneSixInstance(instDir, m_settings, this); + inst->setIntendedVersionId(version->descriptor()); + //FIXME: really, how do you even know? return InstanceFactory::NoCreateError; } diff --git a/backend/InstanceFactory.h b/backend/InstanceFactory.h index 26857ef9..12139e7d 100644 --- a/backend/InstanceFactory.h +++ b/backend/InstanceFactory.h @@ -21,6 +21,7 @@ #include "libmmc_config.h" +class InstVersion; class BaseInstance; /*! @@ -59,7 +60,7 @@ public: * - InstExists if the given instance directory is already an instance. * - CantCreateDir if the given instance directory cannot be created. */ - InstCreateError createInstance(BaseInstance *&inst, const QString &instDir); + InstCreateError createInstance(BaseInstance *&inst, const InstVersion * version, const QString &instDir); /*! * \brief Loads an instance from the given directory. diff --git a/backend/LegacyInstance.cpp b/backend/LegacyInstance.cpp index 001400e5..b4031eb1 100644 --- a/backend/LegacyInstance.cpp +++ b/backend/LegacyInstance.cpp @@ -206,28 +206,36 @@ void LegacyInstance::setLWJGLVersion ( QString val ) I_D(LegacyInstance); d->m_settings->set ( "LwjglVersion", val ); } -QString LegacyInstance::intendedVersion() const +QString LegacyInstance::intendedVersionId() { I_D(LegacyInstance); return d->m_settings->get ( "IntendedJarVersion" ).toString(); } -void LegacyInstance::setIntendedVersion ( QString val ) +bool LegacyInstance::setIntendedVersionId ( QString version ) { + /* I_D(LegacyInstance); d->m_settings->set ( "IntendedJarVersion", val ); + */ + return false; } bool LegacyInstance::shouldUpdate() const { + /* I_D(LegacyInstance); QVariant var = d->m_settings->get ( "ShouldUpdate" ); if ( !var.isValid() || var.toBool() == false ) { - return intendedVersion() != currentVersion(); + return intendedVersionId() != currentVersion(); } return true; + */ + return false; } void LegacyInstance::setShouldUpdate ( bool val ) { + /* I_D(LegacyInstance); d->m_settings->set ( "ShouldUpdate", val ); + */ } diff --git a/backend/LegacyInstance.h b/backend/LegacyInstance.h index ef449b79..64b7b40a 100644 --- a/backend/LegacyInstance.h +++ b/backend/LegacyInstance.h @@ -84,8 +84,8 @@ public: * If this is not the same as currentVersion, the instance's game updater * will be run on launch. */ - QString intendedVersion() const; - void setIntendedVersion(QString val); + virtual QString intendedVersionId(); + virtual bool setIntendedVersionId ( QString version ); /*! * Whether or not Minecraft should be downloaded when the instance is launched. diff --git a/backend/OneSixAssets.cpp b/backend/OneSixAssets.cpp new file mode 100644 index 00000000..e2894bdd --- /dev/null +++ b/backend/OneSixAssets.cpp @@ -0,0 +1,157 @@ +#include +#include +#include +#include "OneSixAssets.h" +#include "dlqueue.h" + +inline QDomElement getDomElementByTagName(QDomElement parent, QString tagname) +{ + QDomNodeList elementList = parent.elementsByTagName(tagname); + if (elementList.count()) + return elementList.at(0).toElement(); + else + return QDomElement(); +} + +class ThreadedDeleter : public QThread +{ + Q_OBJECT +public: + void run() + { + QDirIterator iter(m_base, QDirIterator::Subdirectories); + QStringList nuke_list; + int base_length = m_base.length(); + while (iter.hasNext()) + { + QString filename = iter.next(); + QFileInfo current(filename); + // we keep the dirs... whatever + if(current.isDir()) + continue; + QString trimmedf = filename; + trimmedf.remove(0, base_length + 1); + if(m_whitelist.contains(trimmedf)) + { + //qDebug() << trimmedf << " gets to live"; + } + else + { + // DO NOT TOLERATE JUNK + //qDebug() << trimmedf << " dies"; + QFile f (filename); + f.remove(); + } + } + }; + QString m_base; + QStringList m_whitelist; +}; + +class NukeAndPaveJob: public Job +{ + Q_OBJECT +public: + + explicit NukeAndPaveJob(QString base, QStringList whitelist) + :Job() + { + QDir dir(base); + deleterThread.m_base = dir.absolutePath(); + deleterThread.m_whitelist = whitelist; + }; +public slots: + virtual void start() + { + connect(&deleterThread, SIGNAL(finished()), SLOT(threadFinished())); + deleterThread.start(); + }; + void threadFinished() + { + emit finish(); + } +private: + ThreadedDeleter deleterThread; +}; + +class Private +{ +public: + JobListQueue dl; + JobListPtr index_job; + JobListPtr files_job; +}; + +OneSixAssets::OneSixAssets(QObject* parent):QObject(parent), d(new Private) {} + +void OneSixAssets::fetchFinished() +{ + QString prefix ( "http://s3.amazonaws.com/Minecraft.Resources/" ); + QString fprefix ( "assets/" ); + QStringList nuke_whitelist; + + JobPtr firstJob = d->index_job->getFirstJob(); + auto DlJob = firstJob.dynamicCast(); + QByteArray ba = DlJob->m_data; + + QString xmlErrorMsg; + QDomDocument doc; + if ( !doc.setContent ( ba, false, &xmlErrorMsg ) ) + { + qDebug() << "Failed to process s3.amazonaws.com/Minecraft.Resources. XML error:" << + xmlErrorMsg << ba; + } + //QRegExp etag_match(".*([a-f0-9]{32}).*"); + QDomNodeList contents = doc.elementsByTagName ( "Contents" ); + + JobList *job = new JobList(); + connect ( job, SIGNAL ( finished() ), SIGNAL(finished()) ); + connect ( job, SIGNAL ( failed() ), SIGNAL(failed()) ); + + for ( int i = 0; i < contents.length(); i++ ) + { + QDomElement element = contents.at ( i ).toElement(); + + if ( element.isNull() ) + continue; + + QDomElement keyElement = getDomElementByTagName ( element, "Key" ); + QDomElement lastmodElement = getDomElementByTagName ( element, "LastModified" ); + QDomElement etagElement = getDomElementByTagName ( element, "ETag" ); + QDomElement sizeElement = getDomElementByTagName ( element, "Size" ); + + if ( keyElement.isNull() || lastmodElement.isNull() || etagElement.isNull() || sizeElement.isNull() ) + continue; + + QString keyStr = keyElement.text(); + QString lastModStr = lastmodElement.text(); + QString etagStr = etagElement.text(); + QString sizeStr = sizeElement.text(); + + //Filter folder keys + if ( sizeStr == "0" ) + continue; + + QString trimmedEtag = etagStr.remove ( '"' ); + job->add ( DownloadJob::create ( QUrl ( prefix + keyStr ),fprefix + keyStr, trimmedEtag ) ); + nuke_whitelist.append ( keyStr ); + } + job->add ( JobPtr ( new NukeAndPaveJob ( fprefix, nuke_whitelist ) ) ); + d->files_job.reset ( job ); + d->dl.enqueue ( d->files_job ); +} +void OneSixAssets::fetchStarted() +{ + qDebug() << "Started downloading!"; +} +void OneSixAssets::start() +{ + JobList *job = new JobList(); + job->add ( DownloadJob::create ( QUrl ( "http://s3.amazonaws.com/Minecraft.Resources/" ) ) ); + connect ( job, SIGNAL ( finished() ), SLOT ( fetchFinished() ) ); + connect ( job, SIGNAL ( started() ), SLOT ( fetchStarted() ) ); + d->index_job.reset ( job ); + d->dl.enqueue ( d->index_job ); +} + +#include "OneSixAssets.moc" \ No newline at end of file diff --git a/backend/OneSixAssets.h b/backend/OneSixAssets.h new file mode 100644 index 00000000..caf67c93 --- /dev/null +++ b/backend/OneSixAssets.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include + +class Private; + +class OneSixAssets : public QObject +{ + Q_OBJECT +signals: + void failed(); + void finished(); + +public slots: + void fetchFinished(); + void fetchStarted(); +public: + explicit OneSixAssets ( QObject* parent = 0 ); + void start(); + QSharedPointer d; +}; diff --git a/backend/OneSixInstance.cpp b/backend/OneSixInstance.cpp index 1932651c..d81ed3b1 100644 --- a/backend/OneSixInstance.cpp +++ b/backend/OneSixInstance.cpp @@ -1,18 +1,32 @@ #include "OneSixInstance.h" #include "OneSixInstance_p.h" +#include "tasks/GameUpdateTask.h" +#include "MinecraftProcess.h" +#include -OneSixInstance::OneSixInstance ( const QString& rootDir, SettingsObject* settings, QObject* parent ) -: BaseInstance ( new OneSixInstancePrivate(), rootDir, settings, parent ) +OneSixInstance::OneSixInstance ( const QString& rootDir, SettingsObject* setting_obj, QObject* parent ) +: BaseInstance ( new OneSixInstancePrivate(), rootDir, setting_obj, parent ) { - + I_D(OneSixInstance); + d->m_settings->registerSetting(new Setting("IntendedVersion", "")); } GameUpdateTask* OneSixInstance::doUpdate() { - return nullptr; + return new GameUpdateTask(this); } MinecraftProcess* OneSixInstance::prepareForLaunch ( QString user, QString session ) { return nullptr; } + +bool OneSixInstance::setIntendedVersionId ( QString version ) +{ + settings().set("IntendedVersion", version); +} + +QString OneSixInstance::intendedVersionId() +{ + return settings().get("IntendedVersion").toString(); +} diff --git a/backend/OneSixInstance.h b/backend/OneSixInstance.h index 2abf5b49..5b4b2d8f 100644 --- a/backend/OneSixInstance.h +++ b/backend/OneSixInstance.h @@ -8,4 +8,8 @@ public: explicit OneSixInstance(const QString &rootDir, SettingsObject * settings, QObject *parent = 0); virtual GameUpdateTask* doUpdate(); virtual MinecraftProcess* prepareForLaunch ( QString user, QString session ); + + virtual bool setIntendedVersionId ( QString version ); + virtual QString intendedVersionId(); + }; \ No newline at end of file diff --git a/backend/tasks/GameUpdateTask.cpp b/backend/tasks/GameUpdateTask.cpp index 2b1acf26..f49b551c 100644 --- a/backend/tasks/GameUpdateTask.cpp +++ b/backend/tasks/GameUpdateTask.cpp @@ -24,6 +24,7 @@ #include +#include "BaseInstance.h" #include "lists/MinecraftVersionList.h" #include "VersionFactory.h" #include "OneSixVersion.h" @@ -31,34 +32,23 @@ #include "pathutils.h" -GameUpdateTask::GameUpdateTask(const LoginResponse &response, BaseInstance *inst, QObject *parent) : - Task(parent), m_response(response) +GameUpdateTask::GameUpdateTask(BaseInstance *inst, QObject *parent) : + Task(parent) { m_inst = inst; - m_updateState = StateInit; } void GameUpdateTask::executeTask() { - updateStatus(); - // Get a pointer to the version object that corresponds to the instance's version. - //FIXME: HACKERY - // targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList().findVersion(m_inst->intendedVersion()); + targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList().findVersion(m_inst->intendedVersionId()); if(targetVersion == NULL) { - //Q_ASSERT_X(targetVersion != NULL, "game update", "instance's intended version is not an actual version"); - setState(StateFinished); - emit gameUpdateComplete(m_response); + emit gameUpdateComplete(); return; } - ///////////////////////// - // BUILD DOWNLOAD LIST // - ///////////////////////// - // Build a list of URLs that will need to be downloaded. - - setState(StateDetermineURLs); + setStatus("Getting the version files from Mojang."); QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".json"; @@ -121,10 +111,6 @@ void GameUpdateTask::versionFileFinished() void GameUpdateTask::jarlibFinished() { - //FIXME: HACKERY - // m_inst->setCurrentVersion(targetVersion->descriptor()); - // m_inst->setShouldUpdate(false); - // m_inst->setIsForNewLauncher(true); exit(1); } @@ -140,70 +126,6 @@ void GameUpdateTask::versionFileFailed() exit(0); } - -int GameUpdateTask::state() const -{ - return m_updateState; -} - -void GameUpdateTask::setState(int state, bool resetSubStatus) -{ - m_updateState = state; - if (resetSubStatus) - setSubStatus(""); - else // We only need to update if we're not resetting substatus becasue setSubStatus updates status for us. - updateStatus(); -} - -QString GameUpdateTask::subStatus() const -{ - return m_subStatusMsg; -} - -void GameUpdateTask::setSubStatus(const QString &msg) -{ - m_subStatusMsg = msg; - updateStatus(); -} - -QString GameUpdateTask::getStateMessage(int state) -{ - switch (state) - { - case StateInit: - return "Initializing"; - - case StateDetermineURLs: - return "Determining files to download"; - - case StateDownloadFiles: - return "Downloading files"; - - case StateInstall: - return "Installing"; - - case StateFinished: - return "Finished"; - - default: - return "Downloading instance files"; - } -} - -void GameUpdateTask::updateStatus() -{ - QString newStatus; - - newStatus = getStateMessage(state()); - if (!subStatus().isEmpty()) - newStatus += ": " + subStatus(); - else - newStatus += "..."; - - setStatus(newStatus); -} - - void GameUpdateTask::error(const QString &msg) { emit gameUpdateError(msg); diff --git a/backend/tasks/GameUpdateTask.h b/backend/tasks/GameUpdateTask.h index ea0cf658..f13f42d1 100644 --- a/backend/tasks/GameUpdateTask.h +++ b/backend/tasks/GameUpdateTask.h @@ -24,12 +24,10 @@ #include "dlqueue.h" #include "Task.h" -#include "tasks/LoginResponse.h" -#include "BaseInstance.h" - #include "libmmc_config.h" class MinecraftVersion; +class BaseInstance; /*! * The game update task is the task that handles downloading instances' files. @@ -37,58 +35,14 @@ class MinecraftVersion; class LIBMULTIMC_EXPORT GameUpdateTask : public Task { Q_OBJECT - - /*! - * The task's state. - * A certain state message will be shown depending on what this is set to. - */ - Q_PROPERTY(int state READ state WRITE setState) - - /*! - * The substatus message. - * This will be next to the the state message in the task's status. - */ - Q_PROPERTY(QString subStatus READ subStatus WRITE setSubStatus) public: - explicit GameUpdateTask(const LoginResponse &response, BaseInstance *inst, QObject *parent = 0); - - - ///////////////////////// - // EXECUTION FUNCTIONS // - ///////////////////////// + explicit GameUpdateTask(BaseInstance *inst, QObject *parent = 0); virtual void executeTask(); - ////////////////////// - // STATE AND STATUS // - ////////////////////// - - virtual int state() const; - virtual void setState(int state, bool resetSubStatus = true); - - virtual QString subStatus() const; - virtual void setSubStatus(const QString &msg); - - /*! - * Gets the message that will be displated for the given state. - */ - virtual QString getStateMessage(int state); - -private: - void getLegacyJar(); - void determineNewVersion(); - public slots: - - /*! - * Updates the status message based on the state and substatus message. - */ - virtual void updateStatus(); - - virtual void error(const QString &msg); - private slots: void updateDownloadProgress(qint64 current, qint64 total); @@ -103,7 +57,7 @@ signals: * \brief Signal emitted when the game update is complete. * \param response The login response received from login task. */ - void gameUpdateComplete(const LoginResponse &response); + void gameUpdateComplete(); /*! * \brief Signal emitted if an error occurrs during the update. @@ -112,37 +66,10 @@ signals: void gameUpdateError(const QString &errorMsg); private: - /////////// - // STUFF // - /////////// - BaseInstance *m_inst; - LoginResponse m_response; - - //////////////////////////// - // STATE AND STATUS STUFF // - //////////////////////////// - - int m_updateState; + QString m_subStatusMsg; - enum UpdateState - { - // Initializing - StateInit = 0, - - // Determining files to download - StateDetermineURLs, - - // Downloading files - StateDownloadFiles, - - // Installing files - StateInstall, - - // Finished - StateFinished - }; JobListPtr legacyDownloadJob; JobListPtr specificVersionDownloadJob; JobListPtr jarlibDownloadJob; diff --git a/backend/tasks/LoginResponse.cpp b/backend/tasks/LoginResponse.cpp deleted file mode 100644 index 218f51c1..00000000 --- a/backend/tasks/LoginResponse.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "tasks/LoginResponse.h" - -LoginResponse::LoginResponse(const QString& username, const QString& sessionID, - qint64 latestVersion, QObject *parent) : - QObject(parent) -{ - this->m_username = username; - this->m_sessionID = sessionID; - this->m_latestVersion = latestVersion; -} - -LoginResponse::LoginResponse() -{ - this->m_username = ""; - this->m_sessionID = ""; - this->m_latestVersion = 0; -} - -LoginResponse::LoginResponse(const LoginResponse &other) -{ - this->m_username = other.username(); - this->m_sessionID = other.sessionID(); - this->m_latestVersion = other.latestVersion(); -} - -QString LoginResponse::username() const -{ - return m_username; -} - -void LoginResponse::setUsername(const QString& username) -{ - this->m_username = username; -} - -QString LoginResponse::sessionID() const -{ - return m_sessionID; -} - -void LoginResponse::setSessionID(const QString& sessionID) -{ - this->m_sessionID = sessionID; -} - -qint64 LoginResponse::latestVersion() const -{ - return m_latestVersion; -} - -void LoginResponse::setLatestVersion(qint64 v) -{ - this->m_latestVersion = v; -} diff --git a/backend/tasks/LoginResponse.h b/backend/tasks/LoginResponse.h deleted file mode 100644 index 60875619..00000000 --- a/backend/tasks/LoginResponse.h +++ /dev/null @@ -1,94 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#include "libmmc_config.h" - -/*! - * \brief The LoginResponse class represents a response received from Minecraft's login servers. - */ -class LIBMULTIMC_EXPORT LoginResponse : public QObject -{ - Q_OBJECT -public: - /*! - * \brief Creates a new instance of the LoginResponse class. - * \param username The user's username. - * \param sessionID The user's session ID. - * \param latestVersion The latest version of Minecraft. - * \param parent The parent object. - */ - explicit LoginResponse(const QString &username, const QString &sessionID, - qint64 latestVersion, QObject *parent = 0); - LoginResponse(); - LoginResponse(const LoginResponse& other); - - /*! - * \brief Gets the username. - * This one should go without saying. - * \return The username. - * \sa setUsername() - */ - QString username() const; - - /*! - * \brief setUsername Sets the username. - * \param username The new username. - * \sa username() - */ - void setUsername(const QString& username); - - - /*! - * \brief Gets the session ID. - * \return The session ID. - * \sa setSessionID() - */ - QString sessionID() const; - - /*! - * \brief Sets the session ID. - * \param sessionID The new session ID. - * \sa sessionID() - */ - void setSessionID(const QString& sessionID); - - - /*! - * \brief Gets the latest version. - * This is a value returned by the login servers when a user logs in. - * \return The latest version. - * \sa setLatestVersion() - */ - qint64 latestVersion() const; - - /*! - * \brief Sets the latest version. - * \param v The new latest version. - * \sa latestVersion() - */ - void setLatestVersion(qint64 v); - -private: - QString m_username; - QString m_sessionID; - qint64 m_latestVersion; -}; - -Q_DECLARE_METATYPE(LoginResponse) - diff --git a/backend/tasks/LoginTask.cpp b/backend/tasks/LoginTask.cpp index 11f58f28..999a718e 100644 --- a/backend/tasks/LoginTask.cpp +++ b/backend/tasks/LoginTask.cpp @@ -77,7 +77,7 @@ void LoginTask::processNetReply(QNetworkReply *reply) QString username = strings[2]; QString sessionID = strings[3]; - LoginResponse response(username, sessionID, latestVersion); + LoginResponse response{username, sessionID, latestVersion}; emit loginComplete(response); } else diff --git a/backend/tasks/LoginTask.h b/backend/tasks/LoginTask.h index e23ea9e9..cb606204 100644 --- a/backend/tasks/LoginTask.h +++ b/backend/tasks/LoginTask.h @@ -19,10 +19,15 @@ #include "Task.h" #include "UserInfo.h" -#include "tasks/LoginResponse.h" - #include "libmmc_config.h" +struct LoginResponse +{ + QString username; + QString sessionID; + qint64 latestVersion; +}; + //class QNetworkAccessManager; class QNetworkReply; -- cgit v1.2.3