summaryrefslogtreecommitdiffstats
path: root/backend/tasks
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-07-29 00:59:35 +0200
committerPetr Mrázek <peterix@gmail.com>2013-07-29 00:59:35 +0200
commit2e0cbf393a5320dbf5448ca44a9b5905314b0be8 (patch)
tree4baac9cf015ca7b15d83de33c705e0d8d4497d30 /backend/tasks
parent8808a8b108b82916eaf30f9aca50cd3ab16af230 (diff)
downloadMultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar
MultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar.gz
MultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar.lz
MultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar.xz
MultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.zip
Massive renaming in the backend folder, all around restructure in the same.
Diffstat (limited to 'backend/tasks')
-rw-r--r--backend/tasks/GameUpdateTask.cpp283
-rw-r--r--backend/tasks/GameUpdateTask.h157
-rw-r--r--backend/tasks/LoginResponse.cpp69
-rw-r--r--backend/tasks/LoginResponse.h94
-rw-r--r--backend/tasks/LoginTask.cpp121
-rw-r--r--backend/tasks/LoginTask.h49
-rw-r--r--backend/tasks/Task.cpp83
-rw-r--r--backend/tasks/Task.h78
-rw-r--r--backend/tasks/UserInfo.cpp49
-rw-r--r--backend/tasks/UserInfo.h41
10 files changed, 1024 insertions, 0 deletions
diff --git a/backend/tasks/GameUpdateTask.cpp b/backend/tasks/GameUpdateTask.cpp
new file mode 100644
index 00000000..0a1df0e1
--- /dev/null
+++ b/backend/tasks/GameUpdateTask.cpp
@@ -0,0 +1,283 @@
+/* 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 "GameUpdateTask.h"
+
+#include <QtNetwork>
+
+#include <QFile>
+#include <QFileInfo>
+#include <QTextStream>
+#include <QDataStream>
+
+#include <QDebug>
+
+#include "lists/MinecraftVersionList.h"
+#include "VersionFactory.h"
+#include "OneSixVersion.h"
+
+#include "pathutils.h"
+
+
+GameUpdateTask::GameUpdateTask(const LoginResponse &response, BaseInstance *inst, QObject *parent) :
+ Task(parent), m_response(response)
+{
+ m_inst = inst;
+ m_updateState = StateInit;
+}
+
+void GameUpdateTask::executeTask()
+{
+ updateStatus();
+
+ // Get a pointer to the version object that corresponds to the instance's version.
+ targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList().
+ findVersion(m_inst->intendedVersion());
+ 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);
+ return;
+ }
+
+ /////////////////////////
+ // BUILD DOWNLOAD LIST //
+ /////////////////////////
+ // Build a list of URLs that will need to be downloaded.
+
+ setState(StateDetermineURLs);
+
+ if (targetVersion->versionSource() == MinecraftVersion::Launcher16)
+ {
+ determineNewVersion();
+ }
+ else
+ {
+ getLegacyJar();
+ }
+ QEventLoop loop;
+ loop.exec();
+}
+
+void GameUpdateTask::determineNewVersion()
+{
+ QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/");
+ urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".json";
+ auto dljob = DownloadJob::create(QUrl(urlstr));
+ specificVersionDownloadJob.reset(new JobList());
+ specificVersionDownloadJob->add(dljob);
+ connect(specificVersionDownloadJob.data(), SIGNAL(finished()), SLOT(versionFileFinished()));
+ connect(specificVersionDownloadJob.data(), SIGNAL(failed()), SLOT(versionFileFailed()));
+ connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+ download_queue.enqueue(specificVersionDownloadJob);
+}
+
+void GameUpdateTask::versionFileFinished()
+{
+ JobPtr firstJob = specificVersionDownloadJob->getFirstJob();
+ auto DlJob = firstJob.dynamicCast<DownloadJob>();
+ FullVersionFactory parser;
+ auto version = parser.parse(DlJob->m_data);
+
+ if(!version)
+ {
+ error(parser.error_string);
+ exit(0);
+ }
+
+ if(version->isLegacy)
+ {
+ getLegacyJar();
+ return;
+ }
+
+ // save the version file in $instanceId/version.json and versions/$version/$version.json
+ QString version_id = targetVersion->descriptor();
+ QString mc_dir = m_inst->minecraftDir();
+ QString inst_dir = m_inst->rootDir();
+ QString version1 = PathCombine(inst_dir, "/version.json");
+ QString version2 = QString("versions/") + version_id + "/" + version_id + ".json";
+ DownloadJob::ensurePathExists(version1);
+ DownloadJob::ensurePathExists(version2);
+ QFile vfile1 (version1);
+ QFile vfile2 (version2);
+ vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly );
+ vfile2.open(QIODevice::Truncate | QIODevice::WriteOnly );
+ vfile1.write(DlJob->m_data);
+ vfile2.write(DlJob->m_data);
+ vfile1.close();
+ vfile2.close();
+
+ // download the right jar, save it in versions/$version/$version.jar
+ QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/");
+ urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".jar";
+ QString targetstr ("versions/");
+ targetstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".jar";
+ auto dljob = DownloadJob::create(QUrl(urlstr), targetstr);
+
+ jarlibDownloadJob.reset(new JobList());
+ jarlibDownloadJob->add(dljob);
+ connect(jarlibDownloadJob.data(), SIGNAL(finished()), SLOT(jarlibFinished()));
+ connect(jarlibDownloadJob.data(), SIGNAL(failed()), SLOT(jarlibFailed()));
+ connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+ // determine and download all the libraries, save them in libraries/whatever...
+ download_queue.enqueue(jarlibDownloadJob);
+}
+
+void GameUpdateTask::jarlibFinished()
+{
+ m_inst->setCurrentVersion(targetVersion->descriptor());
+ m_inst->setShouldUpdate(false);
+ // m_inst->setIsForNewLauncher(true);
+ exit(1);
+}
+
+void GameUpdateTask::jarlibFailed()
+{
+ error("Failed to download the binary garbage. Try again. Maybe. IF YOU DARE");
+ exit(0);
+}
+
+void GameUpdateTask::versionFileFailed()
+{
+ error("Failed to download the version description. Try again.");
+ exit(0);
+}
+
+
+// this is legacy minecraft...
+void GameUpdateTask::getLegacyJar()
+{
+ // Make directories
+ QDir binDir(m_inst->binDir());
+ if (!binDir.exists() && !binDir.mkpath("."))
+ {
+ error("Failed to create bin folder.");
+ return;
+ }
+
+ // Add the URL for minecraft.jar
+ // This will be either 'minecraft' or the version number, depending on where
+ // we're downloading from.
+ QString jarFilename = "minecraft";
+ if (targetVersion->versionSource() == MinecraftVersion::Launcher16)
+ {
+ jarFilename = targetVersion->descriptor();
+ }
+
+ QUrl mcJarURL = targetVersion->downloadURL() + jarFilename + ".jar";
+ qDebug() << mcJarURL.toString();
+ auto dljob = DownloadJob::create(mcJarURL, PathCombine(m_inst->minecraftDir(), "bin/minecraft.jar"));
+
+ legacyDownloadJob.reset(new JobList());
+ legacyDownloadJob->add(dljob);
+ connect(legacyDownloadJob.data(), SIGNAL(finished()), SLOT(legacyJarFinished()));
+ connect(legacyDownloadJob.data(), SIGNAL(failed()), SLOT(legacyJarFailed()));
+ connect(legacyDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+
+ download_queue.enqueue(legacyDownloadJob);
+}
+
+
+void GameUpdateTask::legacyJarFinished()
+{
+ setState(StateFinished);
+ emit gameUpdateComplete(m_response);
+ // m_inst->setIsForNewLauncher(true);
+ exit(1);
+}
+
+void GameUpdateTask::legacyJarFailed()
+{
+ emit gameUpdateError("failed to download the minecraft.jar");
+ 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);
+}
+
+void GameUpdateTask::updateDownloadProgress(qint64 current, qint64 total)
+{
+ // The progress on the current file is current / total
+ float currentDLProgress = (float) current / (float) total;
+ setProgress((int)(currentDLProgress * 100)); // convert to percentage
+}
+
diff --git a/backend/tasks/GameUpdateTask.h b/backend/tasks/GameUpdateTask.h
new file mode 100644
index 00000000..94e798f1
--- /dev/null
+++ b/backend/tasks/GameUpdateTask.h
@@ -0,0 +1,157 @@
+/* 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 <QObject>
+
+#include <QList>
+
+#include <QNetworkAccessManager>
+#include <QUrl>
+#include "dlqueue.h"
+
+#include "Task.h"
+#include "tasks/LoginResponse.h"
+#include "BaseInstance.h"
+
+#include "libmmc_config.h"
+
+class MinecraftVersion;
+
+/*!
+ * The game update task is the task that handles downloading instances' files.
+ */
+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 //
+ /////////////////////////
+
+ 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);
+ void legacyJarFinished();
+ void legacyJarFailed();
+
+ void versionFileFinished();
+ void versionFileFailed();
+
+ void jarlibFinished();
+ void jarlibFailed();
+
+signals:
+ /*!
+ * \brief Signal emitted when the game update is complete.
+ * \param response The login response received from login task.
+ */
+ void gameUpdateComplete(const LoginResponse &response);
+
+ /*!
+ * \brief Signal emitted if an error occurrs during the update.
+ * \param errorMsg An error message to be displayed to the user.
+ */
+ 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;
+ JobListQueue download_queue;
+
+ // target version, determined during this task
+ MinecraftVersion *targetVersion;
+};
+
+
diff --git a/backend/tasks/LoginResponse.cpp b/backend/tasks/LoginResponse.cpp
new file mode 100644
index 00000000..218f51c1
--- /dev/null
+++ b/backend/tasks/LoginResponse.cpp
@@ -0,0 +1,69 @@
+/* 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
new file mode 100644
index 00000000..60875619
--- /dev/null
+++ b/backend/tasks/LoginResponse.h
@@ -0,0 +1,94 @@
+/* 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 <QObject>
+
+#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
new file mode 100644
index 00000000..11f58f28
--- /dev/null
+++ b/backend/tasks/LoginTask.cpp
@@ -0,0 +1,121 @@
+/* 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 "LoginTask.h"
+
+#include <QStringList>
+
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkReply>
+#include <QtNetwork/QNetworkRequest>
+
+#include <QUrl>
+#include <QUrlQuery>
+
+LoginTask::LoginTask( const UserInfo& uInfo, QObject* parent ) :
+ Task(parent), uInfo(uInfo)
+{
+
+}
+
+void LoginTask::executeTask()
+{
+ setStatus("Logging in...");
+
+ QNetworkAccessManager netMgr;
+ connect(&netMgr, SIGNAL(finished(QNetworkReply*)),
+ SLOT(processNetReply(QNetworkReply*)));
+
+ QUrl loginURL("https://login.minecraft.net/");
+ QNetworkRequest netRequest(loginURL);
+ netRequest.setHeader(QNetworkRequest::ContentTypeHeader,
+ "application/x-www-form-urlencoded");
+
+ QUrlQuery params;
+ params.addQueryItem("user", uInfo.username());
+ params.addQueryItem("password", uInfo.password());
+ params.addQueryItem("version", "13");
+
+ netReply = netMgr.post(netRequest, params.query(QUrl::EncodeSpaces).toUtf8());
+ exec();
+}
+
+void LoginTask::processNetReply(QNetworkReply *reply)
+{
+ // Check for errors.
+ switch (reply->error())
+ {
+ case QNetworkReply::NoError:
+ {
+ // Check the response code.
+ int responseCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+
+ if (responseCode == 200)
+ {
+ QString responseStr(reply->readAll());
+
+ QStringList strings = responseStr.split(":");
+ if (strings.count() >= 4)
+ {
+ bool parseSuccess;
+ qint64 latestVersion = strings[0].toLongLong(&parseSuccess);
+ if (parseSuccess)
+ {
+ // strings[1] is the download ticket. It isn't used anymore.
+ QString username = strings[2];
+ QString sessionID = strings[3];
+
+ LoginResponse response(username, sessionID, latestVersion);
+ emit loginComplete(response);
+ }
+ else
+ {
+ emit loginFailed("Failed to parse Minecraft version string.");
+ }
+ }
+ else
+ {
+ if (responseStr.toLower() == "bad login")
+ emit loginFailed("Invalid username or password.");
+ else if (responseStr.toLower() == "old version")
+ emit loginFailed("Launcher outdated, please update.");
+ else
+ emit loginFailed("Login failed: " + responseStr);
+ }
+ }
+ else if (responseCode == 503)
+ {
+ emit loginFailed("The login servers are currently unavailable. "
+ "Check http://help.mojang.com/ for more info.");
+ }
+ else
+ {
+ emit loginFailed(QString("Login failed: Unknown HTTP error %1 occurred.").
+ arg(QString::number(responseCode)));
+ }
+ break;
+ }
+
+ case QNetworkReply::OperationCanceledError:
+ emit loginFailed("Login canceled.");
+ break;
+
+ default:
+ emit loginFailed("Login failed: " + reply->errorString());
+ break;
+ }
+
+ quit();
+}
diff --git a/backend/tasks/LoginTask.h b/backend/tasks/LoginTask.h
new file mode 100644
index 00000000..e23ea9e9
--- /dev/null
+++ b/backend/tasks/LoginTask.h
@@ -0,0 +1,49 @@
+/* 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.
+ */
+
+#ifndef LOGINTASK_H
+#define LOGINTASK_H
+
+#include "Task.h"
+
+#include "UserInfo.h"
+#include "tasks/LoginResponse.h"
+
+#include "libmmc_config.h"
+
+//class QNetworkAccessManager;
+class QNetworkReply;
+
+class LIBMULTIMC_EXPORT LoginTask : public Task
+{
+ Q_OBJECT
+public:
+ explicit LoginTask(const UserInfo& uInfo, QObject *parent = 0);
+
+public slots:
+ void processNetReply(QNetworkReply* reply);
+
+signals:
+ void loginComplete(LoginResponse loginResponse);
+ void loginFailed(const QString& errorMsg);
+
+protected:
+ void executeTask();
+
+ QNetworkReply* netReply;
+ UserInfo uInfo;
+};
+
+#endif // LOGINTASK_H
diff --git a/backend/tasks/Task.cpp b/backend/tasks/Task.cpp
new file mode 100644
index 00000000..7831ee58
--- /dev/null
+++ b/backend/tasks/Task.cpp
@@ -0,0 +1,83 @@
+/* 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 "Task.h"
+
+Task::Task(QObject *parent) :
+ QThread(parent)
+{
+
+}
+
+QString Task::getStatus() const
+{
+ return status;
+}
+
+void Task::setStatus(const QString &status)
+{
+ this->status = status;
+ emitStatusChange(status);
+}
+
+int Task::getProgress() const
+{
+ return progress;
+}
+
+void Task::calcProgress(int parts, int whole)
+{
+ setProgress((int)((((float)parts) / ((float)whole))*100)); // Not sure if C++ or LISP...
+}
+
+void Task::setProgress(int progress)
+{
+ this->progress = progress;
+ emitProgressChange(progress);
+}
+
+void Task::startTask()
+{
+ start();
+}
+
+void Task::run()
+{
+ emitStarted();
+ executeTask();
+ emitEnded();
+}
+
+void Task::emitStarted()
+{
+ emit started();
+ emit started(this);
+}
+
+void Task::emitEnded()
+{
+ emit ended();
+ emit ended(this);
+}
+
+void Task::emitStatusChange(const QString &status)
+{
+ emit statusChanged(status);
+}
+
+void Task::emitProgressChange(int progress)
+{
+ emit progressChanged(progress);
+}
diff --git a/backend/tasks/Task.h b/backend/tasks/Task.h
new file mode 100644
index 00000000..c8c12c02
--- /dev/null
+++ b/backend/tasks/Task.h
@@ -0,0 +1,78 @@
+/* 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.
+ */
+
+#ifndef TASK_H
+#define TASK_H
+
+#include <QObject>
+#include <QThread>
+#include <QString>
+
+#include "libmmc_config.h"
+
+class LIBMULTIMC_EXPORT Task : public QThread
+{
+ Q_OBJECT
+public:
+ explicit Task(QObject *parent = 0);
+
+ // Starts the task.
+ void startTask();
+
+ QString getStatus() const;
+ int getProgress() const;
+
+ /*!
+ * \brief Calculates and sets the task's progress based on the number of parts completed out of the total number to complete.
+ * This is essentially just shorthand for setProgress((parts / whole) * 100);
+ * \param parts The parts out of the whole completed. This parameter should
+ * be less than whole. If it is greater than whole, progress is set to 100.
+ * \param whole The total number of things that need to be completed.
+ */
+ void calcProgress(int parts, int whole);
+
+public slots:
+ void setStatus(const QString& status);
+ void setProgress(int progress);
+
+signals:
+ void started(Task* task);
+ void ended(Task* task);
+
+ void started();
+ void ended();
+
+
+ void statusChanged(Task* task, const QString& status);
+ void progressChanged(Task* task, int progress);
+
+ void statusChanged(const QString& status);
+ void progressChanged(int progress);
+
+protected:
+ virtual void run();
+ virtual void executeTask() = 0;
+
+ virtual void emitStarted();
+ virtual void emitEnded();
+
+ virtual void emitStatusChange(const QString &status);
+ virtual void emitProgressChange(int progress);
+
+ QString status;
+ int progress;
+};
+
+#endif // TASK_H
diff --git a/backend/tasks/UserInfo.cpp b/backend/tasks/UserInfo.cpp
new file mode 100644
index 00000000..82225309
--- /dev/null
+++ b/backend/tasks/UserInfo.cpp
@@ -0,0 +1,49 @@
+/* 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 "UserInfo.h"
+
+UserInfo::UserInfo(const QString &username, const QString &password, QObject *parent) :
+ QObject(parent)
+{
+ this->m_username = username;
+ this->m_password = password;
+}
+
+UserInfo::UserInfo(const UserInfo &other)
+{
+ this->m_username = other.m_username;
+ this->m_password = other.m_password;
+}
+
+QString UserInfo::username() const
+{
+ return m_username;
+}
+
+void UserInfo::setUsername(const QString &username)
+{
+ this->m_username = username;
+}
+
+QString UserInfo::password() const
+{
+ return m_password;
+}
+
+void UserInfo::setPassword(const QString &password)
+{
+ this->m_password = password;
+}
diff --git a/backend/tasks/UserInfo.h b/backend/tasks/UserInfo.h
new file mode 100644
index 00000000..280f98de
--- /dev/null
+++ b/backend/tasks/UserInfo.h
@@ -0,0 +1,41 @@
+/* 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.
+ */
+
+#ifndef USERINFO_H
+#define USERINFO_H
+
+#include <QObject>
+
+#include "libmmc_config.h"
+
+class LIBMULTIMC_EXPORT UserInfo : public QObject
+{
+ Q_OBJECT
+public:
+ explicit UserInfo(const QString& username, const QString& password, QObject *parent = 0);
+ explicit UserInfo(const UserInfo& other);
+
+ QString username() const;
+ void setUsername(const QString& username);
+
+ QString password() const;
+ void setPassword(const QString& password);
+
+protected:
+ QString m_username;
+ QString m_password;
+};
+
+#endif // USERINFO_H