Skip to content
Permalink
Browse files

Merge pull request #98 from Turupawn/devel

Auth and Mod State improvements
  • Loading branch information...
Turupawn committed Jul 23, 2019
2 parents 7c6d1d8 + edfb2c1 commit 91ae0c4854e4f74e0acd2aa75a0a2413680234c6
@@ -10,6 +10,7 @@ namespace modio
{
extern std::string API_KEY;
extern std::string ACCESS_TOKEN;
extern bool IS_LOGGED_IN;
extern u32 GAME_ID;
extern std::string ROOT_PATH;
extern u32 DEBUG_LEVEL;
@@ -23,6 +24,7 @@ namespace modio
extern u32 BACKGROUND_DOWNLOADS;
extern u32 RETRY_AFTER;
extern ModioUser current_user;
extern std::vector<u32> downloaded_mods;
extern void (*event_listener_callback)(ModioResponse response, ModioModEvent* events_array, u32 events_array_size);
extern void (*download_callback)(u32 response_code, u32 mod_id);
extern void (*upload_callback)(u32 response_code, u32 mod_id);
@@ -95,6 +95,7 @@ typedef int i32;
#define MODIO_PRIORITIZING_OTHER_DOWNLOAD 8
#define MODIO_MOD_STARTING_UPLOAD 9
#define MODIO_MOD_UPLOADING 10
#define MODIO_MOD_DOWNLOADED 11

// Maturity options
#define MODIO_MATURITY_NONE 0
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2013-2019 Niels Lohmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,22 @@
COPYRIGHT AND PERMISSION NOTICE

Copyright (c) 1996 - 2019, Daniel Stenberg, <daniel@haxx.se>, and many
contributors, see the THANKS file.

All rights reserved.

Permission to use, copy, modify, and distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright
notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of a copyright holder shall not
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization of the copyright holder.
@@ -0,0 +1,22 @@
Copyright 2013-2014 RAD Game Tools and Valve Software
Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC

All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -4,6 +4,7 @@ namespace modio
{
std::string API_KEY;
std::string ACCESS_TOKEN = "";
bool IS_LOGGED_IN = false;
u32 GAME_ID;
std::string ROOT_PATH = "";
u32 DEBUG_LEVEL = MODIO_DEBUGLEVEL_LOG;
@@ -15,6 +16,7 @@ namespace modio
u32 RETRY_AFTER = 0;
u32 MAX_CACHE_TIME = 3600;
ModioUser current_user;
std::vector<u32> downloaded_mods;
void (*event_listener_callback)(ModioResponse response, ModioModEvent* events_array, u32 events_array_size) = NULL;
void (*download_callback)(u32 response_code, u32 mod_id) = NULL;
void (*upload_callback)(u32 response_code, u32 mod_id) = NULL;
@@ -58,13 +58,13 @@ void installDownloadedMods()
{
modio::writeLogLine("Installing downloaded mods...", MODIO_DEBUGLEVEL_LOG);

nlohmann::json downloaded_mods = modio::openJson(modio::getModIODirectory() + "downloaded_mods.json");
nlohmann::json downloaded_mods_json = modio::openJson(modio::getModIODirectory() + "downloaded_mods.json");

for (auto &downloaded_mod : downloaded_mods)
for (auto &downloaded_mod_json : downloaded_mods_json)
{
std::string installation_path = downloaded_mod["installation_path"];
std::string downloaded_zip_path = downloaded_mod["downloaded_zip_path"];
nlohmann::json mod_json = downloaded_mod["mod"];
std::string installation_path = downloaded_mod_json["installation_path"];
std::string downloaded_zip_path = downloaded_mod_json["downloaded_zip_path"];
nlohmann::json mod_json = downloaded_mod_json["mod"];

if (modio::hasKey(mod_json, "id") &&
modio::hasKey(mod_json, "modfile") &&
@@ -98,10 +98,11 @@ void installDownloadedMods()
}
nlohmann::json empty_json;
modio::writeJson(modio::getModIODirectory() + "downloaded_mods.json", empty_json);
modio::downloaded_mods.clear();
modio::writeLogLine("Finished installing downloaded mods", MODIO_DEBUGLEVEL_LOG);
}

static nlohmann::json createInstalledModJson(std::string installation_path, std::string downloaded_zip_path, nlohmann::json mod_json)
static nlohmann::json createDownloadedModJson(std::string installation_path, std::string downloaded_zip_path, nlohmann::json mod_json)
{
nlohmann::json downloaded_mod;
downloaded_mod["installation_path"] = installation_path;
@@ -112,25 +113,25 @@ static nlohmann::json createInstalledModJson(std::string installation_path, std:

void addToDownloadedModsJson(std::string installation_path, std::string downloaded_zip_path, nlohmann::json mod_json)
{
nlohmann::json downloaded_mods = modio::openJson(modio::getModIODirectory() + "downloaded_mods.json");
nlohmann::json downloaded_mods_json = modio::openJson(modio::getModIODirectory() + "downloaded_mods.json");

bool already_downloaded = false;

for (auto &downloaded_mod : downloaded_mods)
{
if (modio::hasKey(downloaded_mod, "mod") &&
modio::hasKey(downloaded_mod["mod"], "id") &&
downloaded_mod["mod"]["id"] == mod_json["id"])
if (downloaded_mod == mod_json["id"])
{
already_downloaded = true;
downloaded_mod = createInstalledModJson(installation_path, downloaded_zip_path, mod_json);
break;
}
}

if (!already_downloaded)
downloaded_mods.push_back(createInstalledModJson(installation_path, downloaded_zip_path, mod_json));

modio::writeJson(modio::getModIODirectory() + "downloaded_mods.json", downloaded_mods);
{
downloaded_mods.push_back(mod_json["id"]);
downloaded_mods_json.push_back(createDownloadedModJson(installation_path, downloaded_zip_path, mod_json));
modio::writeJson(modio::getModIODirectory() + "downloaded_mods.json", downloaded_mods_json);
}
}

void addToInstalledModsJson(u32 mod_id, std::string path, u32 modfile_id, u32 date_updated)
@@ -36,7 +36,7 @@ extern "C"

bool modioIsLoggedIn()
{
return modio::ACCESS_TOKEN!="";
return modio::IS_LOGGED_IN;
}

void modioLogout()
@@ -94,13 +94,19 @@ u32 modioGetAllInstalledModsCount()

u32 modioGetModState(u32 mod_id)
{
for(auto queued_mod_download : modio::curlwrapper::getModDownloadQueue())
for(auto& queued_mod_download : modio::curlwrapper::getModDownloadQueue())
{
if(queued_mod_download->mod_id == mod_id)
return queued_mod_download->state;
}

for(auto installed_mod : modio::installed_mods)
for(auto& downloaded_mod : modio::downloaded_mods)
{
if(downloaded_mod == mod_id)
return MODIO_MOD_DOWNLOADED;
}

for(auto& installed_mod : modio::installed_mods)
{
if(modio::hasKey(installed_mod, "mod_id") && installed_mod["mod_id"] == mod_id)
return MODIO_MOD_INSTALLED;
@@ -16,12 +16,19 @@ void modioOnGetAuthenticatedUser(u32 call_number, u32 response_code, nlohmann::j

modioInitUser(&modio::current_user, response_json);

modio::IS_LOGGED_IN = false;
if(response_code >= 200 && response_code < 300)
{
nlohmann::json authentication_json = modio::openJson(modio::getModIODirectory() + "authentication.json");
authentication_json["user"] = response_json;
modio::writeJson(modio::getModIODirectory() + "authentication.json", authentication_json);
modio::IS_LOGGED_IN = true;
}else if(response_code >= 401)
{
nlohmann::json blank_json;
modio::writeJson(modio::getModIODirectory() + "authentication.json", blank_json);
}


get_authenticated_user_callbacks[call_number]->callback(get_authenticated_user_callbacks[call_number]->object, response, modio::current_user);

@@ -96,7 +96,7 @@ void modioInit(u32 environment, u32 game_id, char const *api_key, char const *ro
if (modio::hasKey(authentication_json, "user"))
modioInitUser(&modio::current_user, authentication_json["user"]);

if (modioIsLoggedIn())
if (modio::ACCESS_TOKEN != "")
modioGetAuthenticatedUser(NULL, &modio::onUpdateCurrentUser);

modio::writeLogLine("SDK Initialized", MODIO_DEBUGLEVEL_LOG);

0 comments on commit 91ae0c4

Please sign in to comment.
You can’t perform that action at this time.