Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <restclient-cpp/restclient.h>
- #include <parallel_hashmap/phmap.h>
- #include <unidokkan/database.h>
- #include <nlohmann/json.hpp>
- #include <unidokkan/hook.h>
- #include <unidokkan/log.h>
- #include <dokkan/crypto.h>
- #include <string>
- //Set base host url as variable so you can edit all of them together.
- static std::string Base_Host = "https://www.baoulettes.fr/DokkanEvent/image/";
- //Banner image with both event type, name and in general a character icon at the right. (600x120)
- static std::string Banner_image_text = "quest_list_banner_";
- //Put together the base url & banners.
- static std::string Banners_URL = Base_Host + Banner_image_text;
- //Same as line 12. but for eza only.
- static std::string Banner_image_EZA_text = "zbattle_list_banner_";
- //Put together the base url & banners (eza ones).
- static std::string Banners_EZA_URL = Base_Host + Banner_image_EZA_text;
- //Top big image that show event logo , character it awaken etc, a presentation picture. (600x120)
- static std::string Event_image_text = "quest_top_banner_";
- //Put together the base url & (Top event prensation image).
- static std::string Event_Top_image_URL = Base_Host + Event_image_text;
- //Mini banner use in story part of the game to show available events. (220x240)
- static std::string Minibanner_image_text = "quest_event_banner_";
- //Put together the base url & mini banners.
- static std::string Minibanner_URL = Base_Host + Minibanner_image_text;
- bool ShowEventsBanners(NetworkResponse *response) {
- using namespace std::string_view_literals;
- //Set "json" to use "nlohmann::json".
- using json = nlohmann::json;
- //Log to tell it properly goes in function
- UD_LOGI("Demo Event List : Loading . . .");
- //Query setup to to fetch id & name from table quests
- constexpr std::string_view kGetQuests = R"SQL(SELECT
- quests.id,
- quests.name
- FROM
- quests)SQL"sv;
- //Store Quests list as Json with ID as key for faster lookup.
- phmap::parallel_flat_hash_map<int, json> Quests_List_Keyed = UniDokkan::Database::selectKeyedInt(kGetQuests, 0);
- //Crawling "eventkagi_events" response. (Event including dokkan, stories etc unpon keys use.)
- for (auto &EventList_Kagi : response->jsonBody["eventkagi_events"]) {
- //Store Event ID as string.
- std::string Event_ID_long = to_string(EventList_Kagi["id"]);
- //Only keep 3 number of the id and remove the "_1", "_2", "_3" etc).
- std::string Event_ID = Event_ID_long.substr(0, 3);
- //Checking if the current Event has Stage(s) (should be at least one).
- for (auto &Quests_Name_Kagi : EventList_Kagi["quests"]) {
- //Store Quest ID as Integer.
- int Quest_ID = Quests_Name_Kagi["id"];
- //Store Selected Quest name as string.
- std::string Quest_Name = Quests_List_Keyed[Quest_ID]["name"].get<std::string>();
- //Modify response quest name into the one from database.db.
- Quests_Name_Kagi["name"] = Quest_Name;
- }
- //Checking if the file exist on server.
- if (RestClient::head(Banners_URL + Event_ID + ".png").code == 200) {
- //Modify response banner's image link into the one from our server (check lines from 9 to 21).
- EventList_Kagi["banner_image"] = Banners_URL + Event_ID + ".png";
- } else {
- //If the file does not exist print in Unidokkan logs files the requested url that failed.
- static std::string logstring = Banner_image_text + Event_ID + ".png";
- UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());
- }
- //Checking if the file exist on server.
- if (RestClient::head(Event_Top_image_URL + Event_ID + ".png").code == 200) {
- //Modify response event presentation's image link into the one from our server (check lines from 9 to 21).
- EventList_Kagi["event_image"] = Event_Top_image_URL + Event_ID + ".png";
- } else {
- //If the file does not exist print in Unidokkan logs files the requested url that failed.
- static std::string logstring = Event_image_text + Event_ID + ".png";
- UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());
- }
- //Checking if the file exist on server.
- if (RestClient::head(Minibanner_URL + Event_ID + ".png").code == 200) {
- //Modify response mini banner's image link into the one from our server (check lines from 9 to 21).
- EventList_Kagi["minibanner_image"] = Minibanner_URL + Event_ID + ".png";
- } else {
- //If the file does not exist print in Unidokkan logs files the requested url that failed.
- static std::string logstring = Minibanner_image_text + Event_ID + ".png";
- UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());
- }
- }
- //Crawling "eventkagi_z_battle_stages" response (EZA list available unpon keys use)
- for (auto &EZAList_Kagi : response->jsonBody["eventkagi_z_battle_stages"]) {
- //Store EZA ID as string.
- std::string EZA_ID = to_string(EZAList_Kagi["id"]);
- //Checking if the file exist on server.
- if (RestClient::head(Banners_EZA_URL + EZA_ID + ".png").code == 200) {
- //Modify response Eza banner's image link into the one from our server (check lines from 9 to 21).
- EZAList_Kagi["banner_image"] = Banners_EZA_URL + EZA_ID + ".png";
- } else {
- //If the file does not exist print in Unidokkan logs files the requested url that failed.
- static std::string logstring = Banner_image_EZA_text + EZA_ID + ".png";
- UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());
- }
- }
- //Crawling "events" response (Currently available dokkan, stories etc)
- for (auto &EventList : response->jsonBody["events"]) {
- //Store Event ID as string.
- std::string Event_ID_long = to_string(EventList["id"]);
- //Only keep 3 number of the id and remove the "_1", "_2", "_3" etc).
- std::string Event_ID = Event_ID_long.substr(0, 3);
- //Checking if the current Event has Stage(s) (should be at least one).
- for (auto &Quests_Name : EventList["quests"]) {
- //Store Quest ID as Integer.
- int Quest_ID = Quests_Name["id"];
- //Store Selected Quest name as string.
- std::string Quest_Name = Quests_List_Keyed[Quest_ID]["name"].get<std::string>();
- //Modify response quest name into the one from database.db.
- Quests_Name["name"] = Quest_Name;
- }
- //Checking if the file exist on server.
- if (RestClient::head(Banners_URL + Event_ID + ".png").code == 200) {
- //Modify response banner's image link into the one from our server (check lines from 9 to 21).
- EventList["banner_image"] = Banners_URL + Event_ID + ".png";
- } else {
- //If the file does not exist print in Unidokkan logs files the requested url that failed.
- static std::string logstring = Banner_image_text + Event_ID + ".png";
- UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());
- }
- //Checking if the file exist on server.
- if (RestClient::head(Event_Top_image_URL + Event_ID + ".png").code == 200) {
- //Modify response event presentation's image link into the one from our server (check lines from 9 to 21).
- EventList["event_image"] = Event_Top_image_URL + Event_ID + ".png";
- } else {
- //If the file does not exist print in Unidokkan logs files the requested url that failed.
- static std::string logstring = Event_image_text + Event_ID + ".png";
- UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());
- }
- //Checking if the file exist on server.
- if (RestClient::head(Minibanner_URL + Event_ID + ".png").code == 200) {
- //Modify response mini banner's image link into the one from our server (check lines from 9 to 21).
- EventList["minibanner_image"] = Minibanner_URL + Event_ID + ".png";
- } else {
- //If the file does not exist print in Unidokkan logs files the requested url that failed.
- static std::string logstring = Minibanner_image_text + Event_ID + ".png";
- UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());
- }
- }
- //Crawling "z_battle_stages" response (Current available EZA without keys requirement.)
- for (auto &EZAList : response->jsonBody["z_battle_stages"]) {
- //Store EZA ID as string.
- std::string EZA_ID = to_string(EZAList["id"]);
- //Checking if the file exist on server.
- if (RestClient::head(Banners_EZA_URL + EZA_ID + ".png").code == 200) {
- //Modify response Eza banner's image link into the one from our server (check lines from 9 to 21).
- EZAList["banner_image"] = Banners_EZA_URL + EZA_ID + ".png";
- } else {
- //If the file does not exist print in Unidokkan logs files the requested url that failed.
- static std::string logstring = Banner_image_EZA_text + EZA_ID + ".png";
- UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());
- }
- }
- return true;
- }
- extern "C" {
- int unidokkan_init_v2(HookLib* hook_lib) {
- hook_lib->addResponseHook("^/events$", ShowEventsBanners);
- if (!hook_lib) {
- UD_LOGI("Demo Event List : Not Loaded");
- return 1;
- }
- UD_LOGI("Demo Event List : Loaded");
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement