Skip to content

Commit

Permalink
A first look for GDUtils 2.206
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouca committed Jun 3, 2024
1 parent 2d5fb79 commit 7de25e2
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ build/
.DS_Store
.vscode/settings.json

.idea/
.idea/
tempCodeRunnerFile.bat
124 changes: 116 additions & 8 deletions src/MoreLeaderboards/MoreLeaderboards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

static StatsListType g_tab = StatsListType::Diamonds;

static std::unordered_map<std::string, web::WebTask> RUNNING_REQUESTS {};

std::vector<std::string> MoreLeaderboards::getWords(std::string s, std::string delim) {
std::vector<std::string> res;
std::string token = "";
Expand Down Expand Up @@ -98,17 +100,19 @@ bool MoreLeaderboards::init(std::string type) {
this->addChild(background);

// Change region
/*auto menu = CCMenu::create();
auto menu_region = CCMenu::create();

auto regionSpr = CCSprite::createWithSpriteFrameName("GJ_plusBtn_001.png");
auto regionSpr = CCSprite::create(Mod::get()->expandSpriteName("earth_btn.png"));
regionSpr->setScale(.8f);
auto regionBtn = CCMenuItemSpriteExtra::create(
regionSpr,
this,
menu_selector(MoreLeaderboards::onMoreLeaderboards)
);
regionBtn->setPosition(239, 20);
menu->addChild(regionBtn);*/
regionBtn->setPosition(239, 0);
menu_region->addChild(regionBtn);

this->addChild(menu_region);

// Corners
CCSprite* corner_left = CCSprite::createWithSpriteFrameName("GJ_sideArt_001.png");
Expand Down Expand Up @@ -248,7 +252,32 @@ void MoreLeaderboards::startLoadingMods() {
loading_circle->setParentLayer(this);
loading_circle->show();

web::AsyncWebRequest()
const geode::utils::MiniFunction<void(std::string const&)> then = [this](std::string const& data) {
fadeLoadingCircle();
handle_request_mods(data);
};
const geode::utils::MiniFunction<void(std::string const&)> expect = [this](std::string const& error) {
fadeLoadingCircle();
};

geode::utils::web::WebRequest request = web::WebRequest();
RUNNING_REQUESTS.emplace(
"@loaderModListCheck",
request.get("https://clarifygdps.com/gdutils/modslist.php").map(
[expect = std::move(expect), then = std::move(then)](web::WebResponse* response) {
if (response->ok()) {
then(response->string().value());
} else {
expect("An error occured while sending a request on our server. Please try again later.");
}

RUNNING_REQUESTS.erase("@loaderModListCheck");
return *response;
}
)
);

/*web::AsyncWebRequest()
.fetch("https://clarifygdps.com/gdutils/modslist.php")
.text()
.then([this](std::string const& data) {
Expand All @@ -258,7 +287,7 @@ void MoreLeaderboards::startLoadingMods() {
})
.expect([this](std::string const& error) {
fadeLoadingCircle();
});
});*/
};

void MoreLeaderboards::loadPageMods() {
Expand Down Expand Up @@ -293,7 +322,86 @@ void MoreLeaderboards::startLoadingMore() {
}

this->retain();
web::AsyncWebRequest()

geode::utils::web::WebRequest request = web::WebRequest();
const geode::utils::MiniFunction<void(std::string const&)> then = [this](std::string const& data) {
loading = false;
auto scene = CCDirector::sharedDirector()->getRunningScene();
auto layer = scene->getChildren()->objectAtIndex(0);
if (layer == nullptr) return this->release();
if (misc::getNodeName(layer) != "MoreLeaderboards") return this->release(); // prevent le crash, even though the layer shouldve already been destructed
if (data == "-1" || data.length() < 2) {
fadeLoadingCircle();
geode::createQuickPopup(
"Error",
"An error occured while sending a request on <cy>our server</c>. Please try again later.",
"OK", nullptr,
[this](auto, bool btn2) {
if (!btn2) {
g_tab = StatsListType::Diamonds;
keyBackClicked();
}
}
);
this->release();
return;
}
fadeLoadingCircle();

handle_request_more(data);
loading = false;

m_diamondsTabBtn->setEnabled(true);
m_usercoinsTabBtn->setEnabled(true);
m_demonsTabBtn->setEnabled(true);
m_moonsTabBtn->setEnabled(true);
m_creatorsTabBtn->setEnabled(true);
this->release();
};
const geode::utils::MiniFunction<void(std::string const&)> expect = [this](std::string const& error) {
loading = false;
auto scene = CCDirector::sharedDirector()->getRunningScene();
auto layer = scene->getChildren()->objectAtIndex(0);
if (layer == nullptr) return this->release();
if (misc::getNodeName(layer) != "MoreLeaderboards") return this->release();
geode::createQuickPopup(
"Error",
"An error occured while sending a request on <cy>our server</c>. Please try again later.",
"OK", nullptr,
[this](auto, bool btn2) {
if (!btn2) {
g_tab = StatsListType::Diamonds;
keyBackClicked();
}
}
);
fadeLoadingCircle();
loading = false;
m_diamondsTabBtn->setEnabled(true);
m_usercoinsTabBtn->setEnabled(true);
m_demonsTabBtn->setEnabled(true);
m_moonsTabBtn->setEnabled(true);
m_creatorsTabBtn->setEnabled(true);
this->release();
};

RUNNING_REQUESTS.emplace(
"@loaderMoreLeaderboardCheck",
request.bodyString(fmt::format("type={}", type)).post("https://clarifygdps.com/gdutils/moreleaderboards.php").map(
[expect = std::move(expect), then = std::move(then)](web::WebResponse* response) {
if (response->ok()) {
then(response->string().value());
} else {
expect("An error occured while sending a request on our server. Please try again later.");
}

RUNNING_REQUESTS.erase("@loaderMoreLeaderboardCheck");
return *response;
}
)
);

/*web::AsyncWebRequest()
.postRequest()
.bodyRaw(fmt::format("type={}", type))
.fetch("https://clarifygdps.com/gdutils/moreleaderboards.php")
Expand Down Expand Up @@ -357,7 +465,7 @@ void MoreLeaderboards::startLoadingMore() {
m_moonsTabBtn->setEnabled(true);
m_creatorsTabBtn->setEnabled(true);
this->release();
});
});*/
};

void MoreLeaderboards::handle_request_more(std::string const& data) {
Expand Down
2 changes: 1 addition & 1 deletion src/MoreLeaderboards/MoreLeaderboards.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "../includes.h"
#include <Geode/utils/web.hpp>
#include <Geode/utils/web2.hpp>
#include "MoreLeaderboardsListView.h"

#include <iostream>
Expand Down
52 changes: 48 additions & 4 deletions src/Notifications/EventsPush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include "../Settings/CustomSettings.hpp"
#include "Geode/utils/general.hpp"
#include <queue>
#include <Geode/utils/web.hpp>
#include <Geode/utils/web2.hpp>

static std::unordered_map<std::string, web::WebTask> RUNNING_REQUESTS {};

std::queue<sio::message::ptr> eventQueue;
bool processingEvents = false;
Expand Down Expand Up @@ -279,9 +281,51 @@ void EventsPush::onClickBtn(CCObject* ret) {
#else // mac os
int level_id = events_layer->levelId;
#endif
//std::string const& url = "https://clarifygdps.com/getGJLevels21.php";
std::string const& fields = "secret=Wmfd2893gb7&gameVersion=22&type=0&binaryVersion=35&gdw=0&diff=-&len=-&count=1&str=" + std::to_string(level_id);
web::AsyncWebRequest()

geode::utils::web::WebRequest request = web::WebRequest();
RUNNING_REQUESTS.emplace(
"@loaderEventRateNotification",
request.bodyString(fields).post(url).map(
[](web::WebResponse* response) {
if (response->ok()) {
if (response->data().empty()) {
FLAlertLayer::create(nullptr,
"Error",
"An server error happened.",
"OK",
nullptr,
180.0F
)->show();
} else {
auto data_result = response->string().value();
if (data_result != "-1") {
auto scene = CCScene::create();
auto layer = LevelInfoLayer::create(EventsPush::convertLevelToJSON(data_result), false);
layer->downloadLevel();
scene->addChild(layer);
CCDirector::sharedDirector()->pushScene(cocos2d::CCTransitionFade::create(0.5f, scene));
} else {
log::info("Level not found. (-1)");
}
}
} else {
FLAlertLayer::create(nullptr,
"Error",
"An server error happened.",
"OK",
nullptr,
180.0F
)->show();
}

RUNNING_REQUESTS.erase("@loaderEventRateNotification");
return *response;
}
)
);

/*web::AsyncWebRequest()
.bodyRaw(fields)
.postRequest()
.fetch(url).text()
Expand All @@ -297,7 +341,7 @@ void EventsPush::onClickBtn(CCObject* ret) {
}
}).expect([](std::string const& error) {
log::error("Error occured while doing a web request: {}", error);
});
});*/
} else { // copy to clipboard
#ifndef GEODE_IS_MACOS
clipboard::write(std::to_string(events_layer->level->m_levelID));
Expand Down
59 changes: 56 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <Geode/modify/CCSprite.hpp>
#include <Geode/modify/CCScale9Sprite.hpp>
#include <Geode/loader/Log.hpp>
#include <Geode/utils/web.hpp>
#include <Geode/utils/web2.hpp>
#include "includes.h"
#include "Settings/CustomSettings.hpp"
#include "Notifications/EventsPush.h"
Expand All @@ -24,6 +24,8 @@
#include <sstream>
#include <codecvt>

static std::unordered_map<std::string, web::WebTask> RUNNING_REQUESTS {};

int reconnectionDelay = 1000;
int reconnectionDelayMax = 5000;
int reconnectionAttempts = 1000;
Expand Down Expand Up @@ -215,7 +217,58 @@ class $modify(CCScheduler) { // GD Protocol part
std::string const& url = "https://www.boomlings.com/database/getGJLevels21.php";
std::string const& fields = "secret=Wmfd2893gb7&type=0&str=" + levelName;

std::cout << fields << std::endl;
geode::utils::web::WebRequest request = web::WebRequest();
RUNNING_REQUESTS.emplace(
"@loaderLevelProtocolURL",
request.bodyString(fields).post(url).map(
[](web::WebResponse* response) {
if (response->ok()) {
if (response->data().empty()) {
FLAlertLayer::create(nullptr,
"Error",
"An server error happened.",
"OK",
nullptr,
180.0F
)->show();
} else {
auto data = response->string().value();
if (data != "-1") {
auto scene = CCScene::create();

GJGameLevel* gjgl = EventsPush::convertLevelToJSON(data);

auto layer = LevelInfoLayer::create(gjgl, false);
layer->downloadLevel();
scene->addChild(layer);
CCDirector::sharedDirector()->pushScene(cocos2d::CCTransitionFade::create(0.5f, scene));
} else {
FLAlertLayer::create(nullptr,
"Error",
"Level not found.",
"OK",
nullptr,
180.0F
)->show();
}
}
} else {
FLAlertLayer::create(nullptr,
"Error",
"An server error happened.",
"OK",
nullptr,
180.0F
)->show();
}

RUNNING_REQUESTS.erase("@loaderLevelProtocolURL");
return *response;
}
)
);

/*
web::AsyncWebRequest()
.bodyRaw(fields)
.postRequest()
Expand Down Expand Up @@ -247,7 +300,7 @@ class $modify(CCScheduler) { // GD Protocol part
nullptr,
350.0F
)->show();
});
});*/
}
}
} catch (const std::exception& e) {}
Expand Down

0 comments on commit 7de25e2

Please sign in to comment.