Advertisement
Baoulettes

Untested_D_EL_TR

Mar 5th, 2020
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.94 KB | None | 0 0
  1. #include <restclient-cpp/restclient.h>
  2. #include <parallel_hashmap/phmap.h>
  3. #include <unidokkan/database.h>
  4. #include <nlohmann/json.hpp>
  5. #include <unidokkan/hook.h>
  6. #include <unidokkan/log.h>
  7. #include <dokkan/crypto.h>
  8. #include <string>
  9. //Set base host url as variable so you can edit all of them together.
  10. static std::string Base_Host                =   "https://www.baoulettes.fr/DokkanEvent/image/";
  11.  
  12. //Banner image with both event type, name and in general a character icon at the right. (600x120)
  13. static std::string  Banner_image_text       =   "quest_list_banner_";
  14.  
  15. //Put together the base url & banners.
  16. static std::string  Banners_URL             =   Base_Host + Banner_image_text;
  17.  
  18. //Same as line 12. but for eza only.
  19. static std::string  Banner_image_EZA_text   =   "zbattle_list_banner_";
  20.  
  21. //Put together the base url & banners (eza ones).
  22. static std::string  Banners_EZA_URL         =   Base_Host + Banner_image_EZA_text;
  23.  
  24. //Top big image that show event logo , character it awaken etc, a presentation picture. (600x120)
  25. static std::string  Event_image_text        =   "quest_top_banner_";
  26.  
  27. //Put together the base url & (Top event prensation image).
  28. static std::string  Event_Top_image_URL     =   Base_Host + Event_image_text;
  29.  
  30. //Mini banner use in story part of the game to show available events. (220x240)
  31. static std::string  Minibanner_image_text   =   "quest_event_banner_";
  32.  
  33. //Put together the base url & mini banners.
  34. static std::string  Minibanner_URL          =   Base_Host + Minibanner_image_text;
  35.  
  36. bool ShowEventsBanners(NetworkResponse *response) {
  37.     using namespace std::string_view_literals;
  38.    
  39.     //Set "json" to use "nlohmann::json".
  40.     using json = nlohmann::json;
  41.    
  42.     //Log to tell it properly goes in function
  43.     UD_LOGI("Demo Event List : Loading . . .");
  44.    
  45.     //Query setup to to fetch id & name from table quests
  46.     constexpr std::string_view kGetQuests = R"SQL(SELECT
  47.         quests.id,
  48.         quests.name
  49.     FROM
  50.         quests)SQL"sv;
  51.  
  52.     //Store Quests list as Json with ID as key for faster lookup.
  53.     phmap::parallel_flat_hash_map<int, json> Quests_List_Keyed = UniDokkan::Database::selectKeyedInt(kGetQuests, 0);
  54.    
  55.     //Crawling "eventkagi_events" response. (Event including dokkan, stories etc unpon keys use.)
  56.     for (auto &EventList_Kagi : response->jsonBody["eventkagi_events"]) {
  57.        
  58.         //Store Event ID as string.
  59.         std::string Event_ID_long       =   to_string(EventList_Kagi["id"]);
  60.        
  61.         //Only keep 3 number of the id and remove the "_1", "_2", "_3" etc).
  62.         std::string Event_ID            =   Event_ID_long.substr(0, 3);
  63.        
  64.         //Checking if the current Event has Stage(s) (should be at least one).
  65.         for (auto &Quests_Name_Kagi : EventList_Kagi["quests"]) {
  66.            
  67.             //Store Quest ID as Integer.
  68.             int Quest_ID        =   Quests_Name_Kagi["id"];
  69.            
  70.             //Store Selected Quest name as string.
  71.             std::string Quest_Name      =   Quests_List_Keyed[Quest_ID]["name"].get<std::string>();
  72.            
  73.             //Modify response quest name into the one from database.db.
  74.             Quests_Name_Kagi["name"]    =   Quest_Name;
  75.         }
  76.        
  77.         //Checking if the file exist on server.
  78.         if (RestClient::head(Banners_URL + Event_ID + ".png").code == 200) {
  79.            
  80.             //Modify response banner's image link into the one from our server (check lines from 9 to 21).
  81.             EventList_Kagi["banner_image"]      =   Banners_URL + Event_ID + ".png";
  82.         } else {
  83.            
  84.             //If the file does not exist print in Unidokkan logs files the requested url that failed.
  85.             static std::string logstring = Banner_image_text + Event_ID + ".png";
  86.             UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());
  87.         }
  88.        
  89.         //Checking if the file exist on server.
  90.         if (RestClient::head(Event_Top_image_URL + Event_ID + ".png").code == 200) {
  91.            
  92.             //Modify response event presentation's image link into the one from our server (check lines from 9 to 21).
  93.             EventList_Kagi["event_image"]       =   Event_Top_image_URL + Event_ID + ".png";
  94.         } else {
  95.            
  96.             //If the file does not exist print in Unidokkan logs files the requested url that failed.
  97.             static std::string logstring = Event_image_text + Event_ID + ".png";
  98.             UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());
  99.            
  100.         }
  101.        
  102.         //Checking if the file exist on server.
  103.         if (RestClient::head(Minibanner_URL + Event_ID + ".png").code == 200) {
  104.  
  105.             //Modify response mini banner's image link into the one from our server (check lines from 9 to 21).
  106.             EventList_Kagi["minibanner_image"]  =   Minibanner_URL + Event_ID + ".png";
  107.         } else {
  108.            
  109.             //If the file does not exist print in Unidokkan logs files the requested url that failed.
  110.             static std::string logstring = Minibanner_image_text + Event_ID + ".png";
  111.             UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());          
  112.         }
  113.     }
  114.    
  115.     //Crawling "eventkagi_z_battle_stages" response (EZA list available unpon keys use)
  116.     for (auto &EZAList_Kagi : response->jsonBody["eventkagi_z_battle_stages"]) {
  117.        
  118.         //Store EZA ID as string.
  119.         std::string EZA_ID              =   to_string(EZAList_Kagi["id"]);
  120.        
  121.         //Checking if the file exist on server.
  122.         if (RestClient::head(Banners_EZA_URL + EZA_ID + ".png").code == 200) {
  123.            
  124.             //Modify response Eza banner's image link into the one from our server (check lines from 9 to 21).
  125.             EZAList_Kagi["banner_image"]    =   Banners_EZA_URL + EZA_ID + ".png";
  126.         } else {
  127.            
  128.             //If the file does not exist print in Unidokkan logs files the requested url that failed.
  129.             static std::string logstring = Banner_image_EZA_text + EZA_ID + ".png";
  130.             UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());              
  131.         }
  132.     }
  133.    
  134.     //Crawling "events" response (Currently available dokkan, stories etc)
  135.     for (auto &EventList : response->jsonBody["events"]) {
  136.         //Store Event ID as string.
  137.         std::string Event_ID_long       =   to_string(EventList["id"]);
  138.        
  139.         //Only keep 3 number of the id and remove the "_1", "_2", "_3" etc).
  140.         std::string Event_ID            =   Event_ID_long.substr(0, 3);
  141.        
  142.         //Checking if the current Event has Stage(s) (should be at least one).
  143.         for (auto &Quests_Name : EventList["quests"]) {
  144.            
  145.             //Store Quest ID as Integer.
  146.             int Quest_ID            =   Quests_Name["id"];
  147.            
  148.             //Store Selected Quest name as string.
  149.             std::string Quest_Name  =   Quests_List_Keyed[Quest_ID]["name"].get<std::string>();
  150.            
  151.             //Modify response quest name into the one from database.db.
  152.             Quests_Name["name"]     =   Quest_Name;
  153.         }
  154.        
  155.         //Checking if the file exist on server.
  156.         if (RestClient::head(Banners_URL + Event_ID + ".png").code == 200) {
  157.            
  158.             //Modify response banner's image link into the one from our server (check lines from 9 to 21).
  159.             EventList["banner_image"]   =   Banners_URL + Event_ID + ".png";
  160.         } else {
  161.            
  162.             //If the file does not exist print in Unidokkan logs files the requested url that failed.
  163.             static std::string logstring = Banner_image_text + Event_ID + ".png";
  164.             UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());      
  165.         }
  166.        
  167.         //Checking if the file exist on server.
  168.         if (RestClient::head(Event_Top_image_URL + Event_ID + ".png").code == 200) {
  169.            
  170.             //Modify response event presentation's image link into the one from our server (check lines from 9 to 21).
  171.             EventList["event_image"]    =   Event_Top_image_URL + Event_ID + ".png";
  172.         } else {
  173.            
  174.             //If the file does not exist print in Unidokkan logs files the requested url that failed.
  175.             static std::string logstring = Event_image_text + Event_ID + ".png";
  176.             UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());      
  177.         }
  178.        
  179.         //Checking if the file exist on server.
  180.         if (RestClient::head(Minibanner_URL + Event_ID + ".png").code == 200) {
  181.  
  182.             //Modify response mini banner's image link into the one from our server (check lines from 9 to 21).
  183.             EventList["minibanner_image"]   =   Minibanner_URL + Event_ID + ".png";
  184.         } else {
  185.            
  186.             //If the file does not exist print in Unidokkan logs files the requested url that failed.
  187.             static std::string logstring = Minibanner_image_text + Event_ID + ".png";
  188.             UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());                  
  189.         }
  190.     }
  191.    
  192.     //Crawling "z_battle_stages" response (Current available EZA without keys requirement.)
  193.     for (auto &EZAList : response->jsonBody["z_battle_stages"]) {
  194.        
  195.         //Store EZA ID as string.
  196.         std::string EZA_ID              =   to_string(EZAList["id"]);
  197.        
  198.         //Checking if the file exist on server.
  199.         if (RestClient::head(Banners_EZA_URL + EZA_ID + ".png").code == 200) {
  200.            
  201.             //Modify response Eza banner's image link into the one from our server (check lines from 9 to 21).
  202.             EZAList["banner_image"] =   Banners_EZA_URL + EZA_ID + ".png";
  203.         } else {
  204.            
  205.             //If the file does not exist print in Unidokkan logs files the requested url that failed.
  206.             static std::string logstring = Banner_image_EZA_text + EZA_ID + ".png";
  207.             UD_LOGI("Demo Event List : Error 404 : %s =", logstring.c_str());  
  208.         }
  209.     }
  210.     return true;
  211. }
  212. extern "C" {
  213.     int unidokkan_init_v2(HookLib* hook_lib) {
  214.         hook_lib->addResponseHook("^/events$", ShowEventsBanners);
  215.         if (!hook_lib) {
  216.             UD_LOGI("Demo Event List : Not Loaded");
  217.             return 1;
  218.         }
  219.         UD_LOGI("Demo Event List : Loaded");
  220.         return 0;
  221.     }
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement