9
3

WorldWeb.cpp 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. /*
  2. EQ2Emu: Everquest II Server Emulator
  3. Copyright (C) 2007-2025 EQ2Emu Development Team (https://www.eq2emu.com)
  4. This file is part of EQ2Emu.
  5. EQ2Emu is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emu is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emu. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "HTTPSClientPool.h"
  17. #include "../World.h"
  18. #include "../WorldDatabase.h"
  19. #include "../LoginServer.h"
  20. #include "../LuaInterface.h"
  21. #include "../Guilds/Guild.h"
  22. #include <boost/property_tree/ptree.hpp>
  23. #include <boost/property_tree/json_parser.hpp>
  24. #include <sstream>
  25. extern ZoneList zone_list;
  26. extern World world;
  27. extern LoginServer loginserver;
  28. extern sint32 numclients;
  29. extern WorldDatabase database;
  30. extern ZoneList zone_list;
  31. extern ZoneAuth zone_auth;
  32. extern LuaInterface* lua_interface;
  33. extern ConfigReader configReader;
  34. extern MasterQuestList master_quest_list;
  35. extern MasterSpellList master_spell_list;
  36. extern MasterFactionList master_faction_list;
  37. extern ClientList client_list;
  38. extern GuildList guild_list;
  39. PeerManager peer_manager;
  40. HTTPSClientPool peer_https_pool;
  41. void World::Web_worldhandle_status(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  42. res.set(http::field::content_type, "application/json; charset=utf-8");
  43. boost::property_tree::ptree pt;
  44. pt.put("web_status", "online");
  45. bool world_online = world.world_loaded;
  46. pt.put("world_status", world.world_loaded ? "online" : "offline");
  47. pt.put("world_uptime", (getCurrentTimestamp() - world.world_uptime));
  48. auto [days, hours, minutes, seconds] = convertTimestampDuration((getCurrentTimestamp() - world.world_uptime));
  49. std::string uptime_str("Days: " + std::to_string(days) + ", " + "Hours: " + std::to_string(hours) + ", " + "Minutes: " + std::to_string(minutes) + ", " + "Seconds: " + std::to_string(seconds));
  50. pt.put("world_uptime_string", uptime_str);
  51. pt.put("login_connected", loginserver.Connected() ? "connected" : "disconnected");
  52. pt.put("player_count", zone_list.GetZonesPlayersCount());
  53. pt.put("client_count", numclients);
  54. pt.put("zones_connected", zone_list.Count());
  55. pt.put("world_reloading", world.IsReloadingSubsystems() ? "yes" : "no");
  56. pt.put("peer_primary", net.is_primary);
  57. pt.put("peer_priority", net.GetPeerPriority());
  58. std::ostringstream oss;
  59. boost::property_tree::write_json(oss, pt);
  60. std::string json = oss.str();
  61. res.body() = json;
  62. res.prepare_payload();
  63. }
  64. void World::Web_worldhandle_clients(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  65. zone_list.PopulateClientList(res);
  66. }
  67. void ZoneList::PopulateClientList(http::response<http::string_body>& res) {
  68. res.set(http::field::content_type, "application/json; charset=utf-8");
  69. boost::property_tree::ptree maintree;
  70. std::ostringstream oss;
  71. MClientList.lock();
  72. map<string, Client*>::iterator itr;
  73. for (itr = client_map.begin(); itr != client_map.end(); itr++) {
  74. if (itr->second) {
  75. Client* cur = (Client*)itr->second;
  76. boost::property_tree::ptree pt;
  77. pt.put("character_id", cur->GetCharacterID());
  78. pt.put("character_name", cur->GetPlayer() ? cur->GetPlayer()->GetName() : "");
  79. pt.put("subtitle", cur->GetPlayer() ? cur->GetPlayer()->appearance.sub_title : "");
  80. pt.put("class1", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_class1() : 0);
  81. pt.put("class2", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_class2() : 0);
  82. pt.put("class3", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_class3() : 0);
  83. pt.put("deity", cur->GetPlayer() ? cur->GetPlayer()->GetDeity() : 0);
  84. pt.put("tradeskill_class1", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_tradeskill_class1() : 0);
  85. pt.put("tradeskill_class2", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_tradeskill_class2() : 0);
  86. pt.put("tradeskill_class3", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_tradeskill_class3() : 0);
  87. pt.put("race", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_race() : 0);
  88. pt.put("level", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_level() : 0);
  89. pt.put("effective_level", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_effective_level() : 0);
  90. pt.put("tradeskill_level", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_tradeskill_level() : 0);
  91. pt.put("account_age", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_account_age_base() : 0);
  92. pt.put("account_id", cur->GetAccountID());
  93. pt.put("version", cur->GetVersion());
  94. pt.put("status", cur->GetAdminStatus());
  95. pt.put("guild_id", cur->GetPlayer()->GetGuild() != nullptr ? cur->GetPlayer()->GetGuild()->GetID() : 0);
  96. pt.put("flags", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_flags() : 0);
  97. pt.put("flags2", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_flags2() : 0);
  98. pt.put("adventure_class", cur->GetPlayer() ? cur->GetPlayer()->GetAdventureClass() : 0);
  99. pt.put("tradeskill_class", cur->GetPlayer() ? cur->GetPlayer()->GetTradeskillClass() : 0);
  100. pt.put("is_zoning", (cur->IsZoning() || !cur->IsReadyForUpdates()));
  101. bool linkdead = cur->GetPlayer() ? (((cur->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)) : false;
  102. pt.put("is_linkdead", linkdead);
  103. pt.put("in_zone", cur->IsReadyForUpdates());
  104. pt.put("zone_id", (cur->GetPlayer() && cur->GetPlayer()->GetZone()) ? cur->GetPlayer()->GetZone()->GetZoneID() : 0);
  105. pt.put("instance_id", (cur->GetPlayer() && cur->GetPlayer()->GetZone()) ? cur->GetPlayer()->GetZone()->GetInstanceID() : 0);
  106. pt.put("zonename", (cur->GetPlayer() && cur->GetPlayer()->GetZone()) ? cur->GetPlayer()->GetZone()->GetZoneName() : "N/A");
  107. pt.put("zonedescription", (cur->GetPlayer() && cur->GetPlayer()->GetZone()) ? cur->GetPlayer()->GetZone()->GetZoneDescription() : "");
  108. GroupMemberInfo* gmi = cur->GetPlayer()->GetGroupMemberInfo();
  109. int32 group_id = 0;
  110. bool group_leader = false;
  111. if (gmi && gmi->group_id) {
  112. group_id = gmi->group_id;
  113. group_leader = gmi->leader;
  114. }
  115. pt.put("group_id", group_id);
  116. pt.put("group_leader", group_leader);
  117. maintree.push_back(std::make_pair("", pt));
  118. }
  119. }
  120. MClientList.unlock();
  121. boost::property_tree::ptree result;
  122. result.add_child("Clients", maintree);
  123. boost::property_tree::write_json(oss, result);
  124. std::string json = oss.str();
  125. res.body() = json;
  126. res.prepare_payload();
  127. }
  128. void World::Web_worldhandle_setadminstatus(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  129. res.set(http::field::content_type, "application/json; charset=utf-8");
  130. boost::property_tree::ptree pt, json_tree;
  131. std::istringstream json_stream(req.body());
  132. boost::property_tree::read_json(json_stream, json_tree);
  133. sint16 status = 0;
  134. std::string charname("");
  135. bool got_status_field = false;
  136. if (auto name = json_tree.get_optional<std::string>("character_name")) {
  137. charname = name.get();
  138. }
  139. if (auto new_status = json_tree.get_optional<sint16>("new_status")) {
  140. status = new_status.get();
  141. got_status_field = true;
  142. }
  143. sint32 success = 0;
  144. if (got_status_field && charname.size() > 0 && database.UpdateAdminStatus((char*)charname.c_str(), status)) {
  145. Client* target = zone_list.GetClientByCharName(charname.c_str());
  146. if (target) {
  147. target->SetAdminStatus(status);
  148. target->Message(CHANNEL_COLOR_YELLOW, "Your admin status has been set to %i.", status);
  149. }
  150. success = 1;
  151. }
  152. else if (!got_status_field || charname.size() < 1) {
  153. success = -1;
  154. }
  155. pt.put("success", success);
  156. std::ostringstream oss;
  157. boost::property_tree::write_json(oss, pt);
  158. std::string json = oss.str();
  159. res.body() = json;
  160. res.prepare_payload();
  161. }
  162. void World::Web_worldhandle_reloadrules(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  163. res.set(http::field::content_type, "application/json; charset=utf-8");
  164. boost::property_tree::ptree pt, json_tree;
  165. std::istringstream json_stream(req.body());
  166. boost::property_tree::read_json(json_stream, json_tree);
  167. database.LoadRuleSets(true);
  168. pt.put("success", 1);
  169. std::ostringstream oss;
  170. boost::property_tree::write_json(oss, pt);
  171. std::string json = oss.str();
  172. res.body() = json;
  173. res.prepare_payload();
  174. }
  175. void World::Web_worldhandle_reloadcommand(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  176. res.set(http::field::content_type, "application/json; charset=utf-8");
  177. boost::property_tree::ptree pt, json_tree;
  178. std::istringstream json_stream(req.body());
  179. boost::property_tree::read_json(json_stream, json_tree);
  180. int32 reload_command = 0, sub_command = 0;
  181. if (auto command = json_tree.get_optional<int32>("reload_command")) {
  182. reload_command = command.get();
  183. }
  184. if (auto subcommand = json_tree.get_optional<int32>("sub_command")) {
  185. sub_command = subcommand.get();
  186. }
  187. int32 success = 1;
  188. switch (reload_command) {
  189. case COMMAND_RELOADSTRUCTS: {
  190. world.SetReloadingSubsystem("Structs");
  191. configReader.ReloadStructs();
  192. world.RemoveReloadingSubSystem("Structs");
  193. break;
  194. }
  195. case COMMAND_RELOAD_QUESTS: {
  196. world.SetReloadingSubsystem("Quests");
  197. master_quest_list.Reload();
  198. client_list.ReloadQuests();
  199. zone_list.ReloadClientQuests();
  200. world.RemoveReloadingSubSystem("Quests");
  201. break;
  202. }
  203. case COMMAND_RELOAD_SPELLS: {
  204. if (sub_command == 1) { // npc only
  205. world.PurgeNPCSpells();
  206. database.LoadNPCSpells();
  207. }
  208. else {
  209. world.SetReloadingSubsystem("Spells");
  210. zone_list.DeleteSpellProcess();
  211. if (lua_interface)
  212. lua_interface->DestroySpells();
  213. master_spell_list.Reload();
  214. zone_list.LoadSpellProcess();
  215. world.RemoveReloadingSubSystem("Spells");
  216. world.PurgeNPCSpells();
  217. database.LoadNPCSpells();
  218. }
  219. break;
  220. }
  221. case COMMAND_RELOAD_ZONESCRIPTS: {
  222. world.SetReloadingSubsystem("ZoneScripts");
  223. world.ResetZoneScripts();
  224. database.LoadZoneScriptData();
  225. if (lua_interface)
  226. lua_interface->DestroyZoneScripts();
  227. world.RemoveReloadingSubSystem("ZoneScripts");
  228. break;
  229. }
  230. case COMMAND_RELOAD_FACTIONS: {
  231. world.SetReloadingSubsystem("Factions");
  232. master_faction_list.Clear();
  233. database.LoadFactionList();
  234. world.RemoveReloadingSubSystem("Factions");
  235. break;
  236. }
  237. case COMMAND_RELOAD_MAIL: {
  238. zone_list.ReloadMail();
  239. break;
  240. }
  241. case COMMAND_RELOAD_GUILDS: {
  242. world.ReloadGuilds();
  243. break;
  244. }
  245. case COMMAND_RELOAD_RULES: {
  246. database.LoadRuleSets(true);
  247. break;
  248. }
  249. case COMMAND_RELOAD_STARTABILITIES: {
  250. world.PurgeStartingLists();
  251. world.LoadStartingLists();
  252. break;
  253. }
  254. case COMMAND_RELOAD_VOICEOVERS: {
  255. world.PurgeVoiceOvers();
  256. world.LoadVoiceOvers();
  257. break;
  258. }
  259. case COMMAND_RELOADSPAWNSCRIPTS: {
  260. if (lua_interface)
  261. lua_interface->SetLuaSystemReloading(true);
  262. world.ResetSpawnScripts();
  263. database.LoadSpawnScriptData();
  264. if (lua_interface) {
  265. lua_interface->DestroySpawnScripts();
  266. lua_interface->SetLuaSystemReloading(false);
  267. }
  268. break;
  269. }
  270. case COMMAND_RELOADREGIONSCRIPTS: {
  271. if (lua_interface) {
  272. lua_interface->DestroyRegionScripts();
  273. }
  274. break;
  275. }
  276. case COMMAND_RELOADLUASYSTEM: {
  277. world.SetReloadingSubsystem("LuaSystem");
  278. if (lua_interface) {
  279. lua_interface->SetLuaSystemReloading(true);
  280. }
  281. zone_list.DeleteSpellProcess();
  282. if (lua_interface)
  283. lua_interface->DestroySpells();
  284. master_spell_list.Reload();
  285. zone_list.LoadSpellProcess();
  286. if (lua_interface) {
  287. map<Client*, int32> debug_clients = lua_interface->GetDebugClients();
  288. map<Client*, int32>::iterator itr;
  289. for (itr = debug_clients.begin(); itr != debug_clients.end(); itr++) {
  290. if (lua_interface)
  291. lua_interface->UpdateDebugClients(itr->first);
  292. }
  293. }
  294. world.ResetSpawnScripts();
  295. database.LoadSpawnScriptData();
  296. world.ResetZoneScripts();
  297. database.LoadZoneScriptData();
  298. if (lua_interface) {
  299. lua_interface->DestroySpawnScripts();
  300. lua_interface->DestroyRegionScripts();
  301. lua_interface->DestroyQuests();
  302. lua_interface->DestroyItemScripts();
  303. lua_interface->DestroyZoneScripts();
  304. }
  305. int32 quest_count = database.LoadQuests();
  306. int32 spell_count = 0;
  307. if (lua_interface) {
  308. spell_count = database.LoadSpellScriptData();
  309. lua_interface->SetLuaSystemReloading(false);
  310. }
  311. world.RemoveReloadingSubSystem("LuaSystem");
  312. break;
  313. }
  314. default: {
  315. success = 0;
  316. break;
  317. }
  318. }
  319. pt.put("success", success);
  320. std::ostringstream oss;
  321. boost::property_tree::write_json(oss, pt);
  322. std::string json = oss.str();
  323. res.body() = json;
  324. res.prepare_payload();
  325. }
  326. void World::Web_worldhandle_addpeer(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  327. res.set(http::field::content_type, "application/json; charset=utf-8");
  328. boost::property_tree::ptree pt, json_tree;
  329. std::istringstream json_stream(req.body());
  330. boost::property_tree::read_json(json_stream, json_tree);
  331. int16 client_port = 0;
  332. std::string client_addr("");
  333. std::string client_internal_addr("");
  334. int16 web_port = 0;
  335. std::string web_addr("");
  336. bool got_port = false;
  337. bool got_addr = false;
  338. if (auto client_address = json_tree.get_optional<std::string>("client_address")) {
  339. client_addr = client_address.get();
  340. got_addr = true;
  341. }
  342. if (auto client_internal_address = json_tree.get_optional<std::string>("client_internal_address")) {
  343. client_internal_addr = client_internal_address.get();
  344. }
  345. if (auto json_port = json_tree.get_optional<int16>("client_port")) {
  346. client_port = json_port.get();
  347. got_port = true;
  348. }
  349. if (auto world_address = json_tree.get_optional<std::string>("web_address")) {
  350. web_addr = world_address.get();
  351. }
  352. else if (got_addr)
  353. got_addr = false;
  354. if (auto port = json_tree.get_optional<int16>("web_port")) {
  355. web_port = port.get();
  356. }
  357. else if (got_port)
  358. got_port = false;
  359. sint32 success = 0;
  360. std::string peerName = peer_manager.isPeer(web_addr, web_port);
  361. if (got_port && got_addr && peerName.size() < 1) {
  362. std::string name = peer_manager.assignUniqueNameForSecondary("eq2emu_", client_addr, client_internal_addr, client_port, web_addr, web_port);
  363. peer_https_pool.addPeerClient(name, web_addr, std::to_string(web_port), "/addpeer");
  364. pt.put("assigned_peer_name", name.c_str());
  365. pt.put("peer_client_address", std::string(net.GetWorldAddress()));
  366. pt.put("peer_client_internal_address", std::string(net.GetInternalWorldAddress()));
  367. pt.put("peer_client_port", std::to_string(net.GetWorldPort()));
  368. pt.put("peer_web_address", std::string(net.GetWebWorldAddress()));
  369. pt.put("peer_web_port", std::to_string(net.GetWebWorldPort()));
  370. if (!peer_manager.hasPeers() && !net.is_primary) {
  371. net.SetPrimary();
  372. }
  373. pt.put("peer_primary", net.is_primary);
  374. }
  375. else {
  376. peer_manager.updatePeer(web_addr, web_port, client_addr, client_internal_addr, client_port, false);
  377. pt.put("assigned_peer_name", peerName);
  378. pt.put("peer_client_address", std::string(net.GetWorldAddress()));
  379. pt.put("peer_client_internal_address", std::string(net.GetInternalWorldAddress()));
  380. pt.put("peer_client_port", std::to_string(net.GetWorldPort()));
  381. pt.put("peer_web_address", std::string(net.GetWebWorldAddress()));
  382. pt.put("peer_web_port", std::to_string(net.GetWebWorldPort()));
  383. pt.put("peer_primary", net.is_primary);
  384. }
  385. std::ostringstream oss;
  386. boost::property_tree::write_json(oss, pt);
  387. std::string json = oss.str();
  388. res.body() = json;
  389. res.prepare_payload();
  390. }
  391. void World::Web_worldhandle_zones(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  392. zone_list.PopulateZoneList(res);
  393. }
  394. void ZoneList::PopulateZoneList(http::response<http::string_body>& res) {
  395. res.set(http::field::content_type, "application/json; charset=utf-8");
  396. boost::property_tree::ptree maintree;
  397. std::ostringstream oss;
  398. list<ZoneServer*>::iterator zone_iter;
  399. ZoneServer* tmp = 0;
  400. MZoneList.readlock(__FUNCTION__, __LINE__);
  401. int zonesListed = 0;
  402. for (zone_iter = zlist.begin(); zone_iter != zlist.end(); zone_iter++) {
  403. tmp = *zone_iter;
  404. boost::property_tree::ptree pt;
  405. pt.put("zone_name", tmp->GetZoneName());
  406. pt.put("zone_file_name", tmp->GetZoneFile());
  407. pt.put("zone_id", tmp->GetZoneID());
  408. pt.put("instance_id", tmp->GetInstanceID());
  409. pt.put("shutting_down", tmp->isZoneShuttingDown());
  410. pt.put("instance_zone", tmp->IsInstanceZone());
  411. pt.put("num_players", tmp->NumPlayers());
  412. pt.put("city_zone", tmp->IsCityZone());
  413. pt.put("safe_x", tmp->GetSafeX());
  414. pt.put("safe_y", tmp->GetSafeY());
  415. pt.put("safe_z", tmp->GetSafeZ());
  416. pt.put("safe_heading", tmp->GetSafeHeading());
  417. pt.put("lock_state", tmp->GetZoneLockState());
  418. pt.put("min_status", tmp->GetMinimumStatus());
  419. pt.put("min_level", tmp->GetMinimumLevel());
  420. pt.put("max_level", tmp->GetMaximumLevel());
  421. pt.put("min_version", tmp->GetMinimumVersion());
  422. pt.put("default_lockout_time", tmp->GetDefaultLockoutTime());
  423. pt.put("default_reenter_time", tmp->GetDefaultReenterTime());
  424. pt.put("instance_type", (int8)tmp->GetInstanceType());
  425. pt.put("always_loaded", tmp->AlwaysLoaded());
  426. zonesListed++;
  427. maintree.push_back(std::make_pair("", pt));
  428. }
  429. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  430. boost::property_tree::ptree result;
  431. result.add_child("Zones", maintree);
  432. boost::property_tree::write_json(oss, result);
  433. std::string json = oss.str();
  434. res.body() = json;
  435. res.prepare_payload();
  436. }
  437. void World::Web_worldhandle_addcharauth(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  438. res.set(http::field::content_type, "application/json; charset=utf-8");
  439. boost::property_tree::ptree pt, json_tree;
  440. std::istringstream json_stream(req.body());
  441. boost::property_tree::read_json(json_stream, json_tree);
  442. int32 account_id = 0;
  443. int32 key = 0;
  444. int32 zoneId, instanceId;
  445. bool firstLogin = false;
  446. std::string clientIP("");
  447. std::string charName(""), zoneName("");
  448. int32 charID = 0;
  449. int32 worldID = 0, fromID = 0;
  450. if (auto acct_id = json_tree.get_optional<int32>("account_id")) {
  451. account_id = acct_id.get();
  452. }
  453. if (auto char_name = json_tree.get_optional<std::string>("character_name")) {
  454. charName = char_name.get();
  455. }
  456. if (auto zone_name = json_tree.get_optional<std::string>("zone_name")) {
  457. zoneName = zone_name.get();
  458. }
  459. if (auto login_key = json_tree.get_optional<int32>("login_key")) {
  460. key = login_key.get();
  461. }
  462. if (auto zone_id = json_tree.get_optional<int32>("zone_id")) {
  463. zoneId = zone_id.get();
  464. }
  465. if (auto instance_id = json_tree.get_optional<int32>("instance_id")) {
  466. instanceId = instance_id.get();
  467. }
  468. if (auto first_login = json_tree.get_optional<bool>("first_login")) {
  469. firstLogin = first_login.get();
  470. }
  471. if (auto clientip = json_tree.get_optional<std::string>("client_ip")) {
  472. clientIP = clientip.get();
  473. }
  474. if (auto character_id = json_tree.get_optional<int32>("character_id")) {
  475. charID = character_id.get();
  476. }
  477. if (auto world_id = json_tree.get_optional<int32>("world_id")) {
  478. worldID = world_id.get();
  479. }
  480. if (auto from_id = json_tree.get_optional<int32>("from_id")) {
  481. fromID = from_id.get();
  482. }
  483. sint32 success = 0;
  484. ZoneChangeDetails details;
  485. if (instanceId || zoneId || zoneName.length() > 0) {
  486. if (!instanceId) {
  487. if ((zone_list.GetZone(&details, zoneId, zoneName, firstLogin, false, true, false)))
  488. success = 1;
  489. }
  490. else {
  491. if ((zone_list.GetZoneByInstance(&details, instanceId, zoneId, firstLogin, false, true, false)))
  492. success = 1;
  493. }
  494. }
  495. if (!success) {
  496. // failed to find zone requested by peer
  497. }
  498. if (success && account_id && key && charName.length() > 0) {
  499. ZoneAuthRequest* zar = new ZoneAuthRequest(account_id, (char*)charName.c_str(), key);
  500. zar->setFirstLogin(firstLogin);
  501. zone_auth.AddAuth(zar);
  502. success = 1;
  503. }
  504. else {
  505. success = 0;
  506. }
  507. pt.put("character_name", charName);
  508. pt.put("account_id", account_id);
  509. pt.put("zone_name", zoneName);
  510. pt.put("zone_id", zoneId);
  511. pt.put("instance_id", instanceId);
  512. pt.put("first_login", firstLogin);
  513. pt.put("peer_client_address", std::string(net.GetWorldAddress()));
  514. pt.put("peer_client_internal_address", std::string(net.GetInternalWorldAddress()));
  515. pt.put("peer_client_port", std::to_string(net.GetWorldPort()));
  516. pt.put("client_ip", clientIP);
  517. pt.put("character_id", std::to_string(charID));
  518. pt.put("login_key", std::to_string(key));
  519. pt.put("world_id", std::to_string(worldID));
  520. pt.put("from_id", std::to_string(fromID));
  521. pt.put("success", success);
  522. std::ostringstream oss;
  523. boost::property_tree::write_json(oss, pt);
  524. std::string json = oss.str();
  525. res.body() = json;
  526. res.prepare_payload();
  527. }
  528. void World::Web_worldhandle_startzone(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  529. res.set(http::field::content_type, "application/json; charset=utf-8");
  530. boost::property_tree::ptree pt, json_tree;
  531. std::istringstream json_stream(req.body());
  532. boost::property_tree::read_json(json_stream, json_tree);
  533. int32 instanceId = 0;
  534. int32 zoneId = 0;
  535. std::string zoneName("");
  536. bool alwaysLoaded = false;
  537. if (auto inst_id = json_tree.get_optional<int32>("instance_id")) {
  538. instanceId = inst_id.get();
  539. }
  540. if (auto zone = json_tree.get_optional<std::string>("zone_name")) {
  541. zoneName = zone.get();
  542. }
  543. if (auto zone_id = json_tree.get_optional<int32>("zone_id")) {
  544. zoneId = zone_id.get();
  545. }
  546. if (auto always_loaded = json_tree.get_optional<bool>("always_loaded")) {
  547. alwaysLoaded = always_loaded.get();
  548. }
  549. sint32 success = 0;
  550. ZoneChangeDetails details;
  551. if (instanceId || zoneId || zoneName.length() > 0) {
  552. if (!instanceId) {
  553. if ((zone_list.GetZone(&details, zoneId, zoneName, true, false, false, false, false, alwaysLoaded)))
  554. success = 1;
  555. }
  556. else {
  557. if ((zone_list.GetZoneByInstance(&details, instanceId, zoneId, true, false, false, false)))
  558. success = 1;
  559. }
  560. }
  561. pt.put("success", success);
  562. pt.put("peer_web_address", net.GetWebWorldAddress());
  563. pt.put("peer_web_port", net.GetWebWorldPort());
  564. if (success) {
  565. pt.put("instance_id", details.instanceId);
  566. pt.put("zone_id", details.zoneId);
  567. pt.put("zone_name", details.zoneName);
  568. }
  569. std::ostringstream oss;
  570. boost::property_tree::write_json(oss, pt);
  571. std::string json = oss.str();
  572. res.body() = json;
  573. res.prepare_payload();
  574. }
  575. void World::Web_worldhandle_sendglobalmessage(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  576. res.set(http::field::content_type, "application/json; charset=utf-8");
  577. boost::property_tree::ptree pt, json_tree;
  578. std::istringstream json_stream(req.body());
  579. boost::property_tree::read_json(json_stream, json_tree);
  580. int32 success = 0;
  581. int8 language = 0;
  582. int16 in_channel = 0;
  583. std::string toName(""), fromName(""), msg("");
  584. int32 group_id = 0;
  585. int32 guild_id = 0;
  586. if (auto name = json_tree.get_optional<std::string>("to_name")) {
  587. toName = name.get();
  588. }
  589. if (auto name = json_tree.get_optional<std::string>("from_name")) {
  590. fromName = name.get();
  591. }
  592. if (auto message = json_tree.get_optional<std::string>("message")) {
  593. msg = message.get();
  594. }
  595. if (auto from_language = json_tree.get_optional<int8>("from_language")) {
  596. language = from_language.get();
  597. }
  598. if (auto channel = json_tree.get_optional<int16>("channel")) {
  599. in_channel = channel.get();
  600. }
  601. if (auto group = json_tree.get_optional<int32>("group_id")) {
  602. group_id = group.get();
  603. }
  604. if (auto guildID = json_tree.get_optional<int32>("guild_id")) {
  605. guild_id = guildID.get();
  606. }
  607. Client* find_client = zone_list.GetClientByCharName(toName.c_str());
  608. if (find_client && find_client->GetPlayer()->IsIgnored(fromName.c_str()))
  609. success = 0;
  610. else {
  611. switch (in_channel) {
  612. case CHANNEL_PRIVATE_TELL: {
  613. if (find_client && find_client->GetPlayer()) {
  614. success = 1;
  615. toName = std::string(find_client->GetPlayer()->GetName());
  616. find_client->HandleTellMessage(fromName.c_str(), msg.c_str(), toName.c_str(), language);
  617. if (find_client->GetPlayer()->get_character_flag(CF_AFK)) {
  618. find_client->HandleTellMessage(toName.c_str(), find_client->GetPlayer()->GetAwayMessage().c_str(), fromName.c_str(), find_client->GetPlayer()->GetCurrentLanguage());
  619. pt.put("away_message", find_client->GetPlayer()->GetAwayMessage());
  620. pt.put("away_language", find_client->GetPlayer()->GetCurrentLanguage());
  621. }
  622. }
  623. break;
  624. }
  625. case CHANNEL_GROUP_SAY:
  626. case CHANNEL_RAID_SAY: {
  627. if (group_id) {
  628. success = 1;
  629. if (fromName.size() > 0) {
  630. world.GetGroupManager()->GroupChatMessage(group_id, fromName, language, msg.c_str(), in_channel);
  631. }
  632. else {
  633. world.GetGroupManager()->GroupMessage(group_id, msg.c_str());
  634. }
  635. }
  636. break;
  637. }
  638. case CHANNEL_OUT_OF_CHARACTER: {
  639. success = 1;
  640. zone_list.SendZoneWideChannelMessage(fromName, "", in_channel, msg.c_str(), 0, "", language);
  641. break;
  642. }
  643. case CHANNEL_GUILD_SAY: {
  644. if (!guild_id)
  645. break;
  646. Guild* guild = guild_list.GetGuild(guild_id);
  647. if (guild) {
  648. guild->HandleGuildSay(fromName, msg.c_str(), language);
  649. }
  650. break;
  651. }
  652. case CHANNEL_OFFICER_SAY: {
  653. if (!guild_id)
  654. break;
  655. Guild* guild = guild_list.GetGuild(guild_id);
  656. if (guild) {
  657. guild->HandleGuildSay(fromName, msg.c_str(), language);
  658. }
  659. break;
  660. }
  661. case CHANNEL_GUILD_EVENT: {
  662. if (!guild_id)
  663. break;
  664. Guild* guild = guild_list.GetGuild(guild_id);
  665. if (guild) {
  666. guild->SendMessageToGuild(CHANNEL_GUILD_EVENT, msg.c_str());
  667. }
  668. break;
  669. }
  670. case CHANNEL_GUILD_CHAT: {
  671. Guild* guild = guild_list.GetGuild(guild_id);
  672. if (guild) {
  673. guild->SendGuildChatMessage(msg.c_str());
  674. }
  675. break;
  676. }
  677. }
  678. }
  679. pt.put("success", success);
  680. pt.put("from_name", fromName);
  681. pt.put("to_name", toName);
  682. pt.put("message", msg);
  683. pt.put("from_language", language);
  684. pt.put("channel", in_channel);
  685. std::ostringstream oss;
  686. boost::property_tree::write_json(oss, pt);
  687. std::string json = oss.str();
  688. res.body() = json;
  689. res.prepare_payload();
  690. }
  691. void World::Web_worldhandle_newgroup(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  692. res.set(http::field::content_type, "application/json; charset=utf-8");
  693. boost::property_tree::ptree pt, json_tree;
  694. std::istringstream json_stream(req.body());
  695. boost::property_tree::read_json(json_stream, json_tree);
  696. GroupOptions options;
  697. int32 group_id = 0;
  698. bool is_client = false;
  699. std::string leader(""), member("");
  700. std::string web_address("");
  701. int16 web_port = 0;
  702. int32 success = 0;
  703. bool is_update = false;
  704. if (auto address = json_tree.get_optional<std::string>("peer_web_address")) {
  705. web_address = address.get();
  706. }
  707. if (auto webport = json_tree.get_optional<int16>("peer_web_port")) {
  708. web_port = webport.get();
  709. }
  710. if (auto leader_name = json_tree.get_optional<std::string>("leader_name")) {
  711. leader = leader_name.get();
  712. }
  713. if (auto member_name = json_tree.get_optional<std::string>("member_name")) {
  714. member = member_name.get();
  715. }
  716. if (auto isclient = json_tree.get_optional<bool>("is_client")) {
  717. is_client = isclient.get();
  718. }
  719. if (auto lootmethod = json_tree.get_optional<int8>("loot_method")) {
  720. options.loot_method = lootmethod.get();
  721. }
  722. if (auto itemrarity = json_tree.get_optional<int8>("loot_item_rarity")) {
  723. options.loot_items_rarity = itemrarity.get();
  724. }
  725. if (auto autosplit = json_tree.get_optional<int8>("auto_split")) {
  726. options.auto_split = autosplit.get();
  727. }
  728. if (auto defaultyell = json_tree.get_optional<int8>("default_yell")) {
  729. options.default_yell = defaultyell.get();
  730. }
  731. if (auto grouplockmethod = json_tree.get_optional<int8>("group_lock_method")) {
  732. options.group_lock_method = grouplockmethod.get();
  733. }
  734. if (auto groupautolock = json_tree.get_optional<int8>("group_auto_lock")) {
  735. options.group_autolock = groupautolock.get();
  736. }
  737. if (auto soloautolock = json_tree.get_optional<int8>("solo_auto_lock")) {
  738. options.solo_autolock = soloautolock.get();
  739. }
  740. if (auto autoloot = json_tree.get_optional<int8>("auto_loot_method")) {
  741. options.auto_loot_method = autoloot.get();
  742. }
  743. if (auto lastlootindex = json_tree.get_optional<int8>("last_looted_index")) {
  744. options.last_looted_index = lastlootindex.get();
  745. }
  746. if (auto groupid = json_tree.get_optional<int32>("group_id")) {
  747. group_id = groupid.get();
  748. }
  749. std::vector<int32> raidGroups;
  750. for (int i = 0; i < 4; i++) {
  751. std::string fieldName("group_id_");
  752. fieldName.append(std::to_string(i));
  753. if (auto raid_group_id = json_tree.get_optional<int32>(fieldName)) {
  754. int32 group_id = raid_group_id.get();
  755. if (group_id) {
  756. raidGroups.push_back(group_id);
  757. }
  758. }
  759. }
  760. if (auto isupdate = json_tree.get_optional<bool>("is_update")) {
  761. is_update = isupdate.get();
  762. }
  763. if (is_update) {
  764. std::vector<int32>::iterator group_itr;
  765. std::vector<int32> emptyGroup;
  766. bool self = false;
  767. if (raidGroups.size() < 1) {
  768. raidGroups.push_back(group_id);
  769. self = true;
  770. }
  771. for (group_itr = raidGroups.begin(); group_itr != raidGroups.end(); group_itr++) {
  772. world.GetGroupManager()->SetGroupOptions((*group_itr), &options);
  773. if (self) {
  774. world.GetGroupManager()->ClearGroupRaid((*group_itr));
  775. world.GetGroupManager()->SendGroupUpdate((*group_itr), nullptr, true);
  776. }
  777. else {
  778. world.GetGroupManager()->ReplaceRaidGroups((*group_itr), &raidGroups);
  779. }
  780. }
  781. success = 1;
  782. }
  783. else if (net.is_primary) {
  784. group_id = world.GetGroupManager()->NewGroup(nullptr, &options);
  785. peer_manager.sendPeersNewGroupRequest(web_address, web_port, group_id, leader, member, &options, "", &raidGroups);
  786. success = 1;
  787. }
  788. else if (group_id) {
  789. int32 result = world.GetGroupManager()->NewGroup(nullptr, &options, group_id);
  790. if (result) {
  791. success = 1;
  792. }
  793. }
  794. pt.put("success", success);
  795. pt.put("group_id", group_id);
  796. pt.put("leader_name", leader);
  797. pt.put("member_name", member);
  798. pt.put("loot_method", options.loot_method);
  799. pt.put("loot_items_rarity", options.loot_items_rarity);
  800. pt.put("auto_split", options.auto_split);
  801. pt.put("default_yell", options.default_yell);
  802. pt.put("group_lock_method", options.group_lock_method);
  803. pt.put("group_autolock", options.group_autolock);
  804. pt.put("solo_autolock", options.solo_autolock);
  805. pt.put("auto_loot_method", options.auto_loot_method);
  806. pt.put("last_looted_index", options.last_looted_index);
  807. std::ostringstream oss;
  808. boost::property_tree::write_json(oss, pt);
  809. std::string json = oss.str();
  810. res.body() = json;
  811. res.prepare_payload();
  812. }
  813. void World::Web_worldhandle_addgroupmember(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  814. res.set(http::field::content_type, "application/json; charset=utf-8");
  815. boost::property_tree::ptree pt, json_tree;
  816. std::istringstream json_stream(req.body());
  817. boost::property_tree::read_json(json_stream, json_tree);
  818. bool is_update = false;
  819. int32 group_id = 0;
  820. GroupMemberInfo info;
  821. if (auto member_name = json_tree.get_optional<std::string>("member_name")) {
  822. info.name = member_name.get();
  823. }
  824. if (auto isclient = json_tree.get_optional<bool>("is_client")) {
  825. info.is_client = isclient.get();
  826. }
  827. if (auto groupid = json_tree.get_optional<int32>("group_id")) {
  828. group_id = groupid.get();
  829. }
  830. if (auto zone = json_tree.get_optional<std::string>("zone")) {
  831. info.zone = zone.get();
  832. }
  833. if (auto hp = json_tree.get_optional<sint32>("current_hp")) {
  834. info.hp_current = hp.get();
  835. }
  836. if (auto hp = json_tree.get_optional<sint32>("max_hp")) {
  837. info.hp_max = hp.get();
  838. }
  839. if (auto power = json_tree.get_optional<sint32>("current_power")) {
  840. info.power_current = power.get();
  841. }
  842. if (auto power = json_tree.get_optional<sint32>("max_power")) {
  843. info.power_max = power.get();
  844. }
  845. if (auto level = json_tree.get_optional<int16>("level_current")) {
  846. info.level_current = level.get();
  847. }
  848. if (auto level = json_tree.get_optional<int16>("level_max")) {
  849. info.level_max = level.get();
  850. }
  851. if (auto race = json_tree.get_optional<int8>("race_id")) {
  852. info.race_id = race.get();
  853. }
  854. if (auto class_ = json_tree.get_optional<int8>("class_id")) {
  855. info.class_id = class_.get();
  856. }
  857. if (auto isleader = json_tree.get_optional<bool>("is_leader")) {
  858. info.leader = isleader.get();
  859. }
  860. if (auto isupdate = json_tree.get_optional<bool>("is_update")) {
  861. is_update = isupdate.get();
  862. }
  863. if (auto mentor_target = json_tree.get_optional<int32>("mentor_target_char_id")) {
  864. info.mentor_target_char_id = mentor_target.get();
  865. }
  866. if (auto zoneID = json_tree.get_optional<int32>("zone_id")) {
  867. info.zone_id = zoneID.get();
  868. }
  869. if (auto instanceID = json_tree.get_optional<int32>("instance_id")) {
  870. info.zone_id = instanceID.get();
  871. }
  872. if (auto clientPeerAddr = json_tree.get_optional<std::string>("client_peer_address")) {
  873. info.client_peer_address = clientPeerAddr.get();
  874. }
  875. if (auto clientPeerPort = json_tree.get_optional<int16>("client_peer_port")) {
  876. info.client_peer_port = clientPeerPort.get();
  877. }
  878. if (auto raidLooter = json_tree.get_optional<bool>("is_raid_looter")) {
  879. info.is_raid_looter = raidLooter.get();
  880. }
  881. else {
  882. info.is_raid_looter = false;
  883. }
  884. bool success = false;
  885. if (is_update) {
  886. world.GetGroupManager()->UpdateGroupMemberInfoFromPeer(group_id, info.name, info.is_client, &info);
  887. world.GetGroupManager()->SendGroupUpdate(group_id);
  888. success = true;
  889. }
  890. else {
  891. success = world.GetGroupManager()->AddGroupMemberFromPeer(group_id, &info);
  892. }
  893. pt.put("success", success);
  894. std::ostringstream oss;
  895. boost::property_tree::write_json(oss, pt);
  896. std::string json = oss.str();
  897. res.body() = json;
  898. res.prepare_payload();
  899. }
  900. void World::Web_worldhandle_removegroupmember(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  901. res.set(http::field::content_type, "application/json; charset=utf-8");
  902. boost::property_tree::ptree pt, json_tree;
  903. std::istringstream json_stream(req.body());
  904. boost::property_tree::read_json(json_stream, json_tree);
  905. int32 group_id = 0;
  906. int32 char_id = 0;
  907. std::string name("");
  908. bool is_client = false;
  909. if (auto member_name = json_tree.get_optional<std::string>("member_name")) {
  910. name = member_name.get();
  911. }
  912. if (auto isclient = json_tree.get_optional<bool>("is_client")) {
  913. is_client = isclient.get();
  914. }
  915. if (auto groupid = json_tree.get_optional<int32>("group_id")) {
  916. group_id = groupid.get();
  917. }
  918. if (auto charid = json_tree.get_optional<int32>("character_id")) {
  919. char_id = charid.get();
  920. }
  921. bool success = world.GetGroupManager()->RemoveGroupMember(group_id, name, is_client, char_id);
  922. pt.put("success", success);
  923. std::ostringstream oss;
  924. boost::property_tree::write_json(oss, pt);
  925. std::string json = oss.str();
  926. res.body() = json;
  927. res.prepare_payload();
  928. }
  929. void World::Web_worldhandle_disbandgroup(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  930. res.set(http::field::content_type, "application/json; charset=utf-8");
  931. boost::property_tree::ptree pt, json_tree;
  932. std::istringstream json_stream(req.body());
  933. boost::property_tree::read_json(json_stream, json_tree);
  934. int32 group_id = 0;
  935. if (auto groupid = json_tree.get_optional<int32>("group_id")) {
  936. group_id = groupid.get();
  937. }
  938. world.GetGroupManager()->RemoveGroup(group_id);
  939. pt.put("success", true);
  940. std::ostringstream oss;
  941. boost::property_tree::write_json(oss, pt);
  942. std::string json = oss.str();
  943. res.body() = json;
  944. res.prepare_payload();
  945. }
  946. void World::Web_worldhandle_createguild(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  947. res.set(http::field::content_type, "application/json; charset=utf-8");
  948. boost::property_tree::ptree pt, json_tree;
  949. std::istringstream json_stream(req.body());
  950. boost::property_tree::read_json(json_stream, json_tree);
  951. std::string newGuildName(""), leaderName("");
  952. int32 guildID = 0;
  953. if (auto name = json_tree.get_optional<std::string>("guild_name")) {
  954. newGuildName = name.get();
  955. }
  956. if (auto name = json_tree.get_optional<std::string>("leader_name")) {
  957. leaderName = name.get();
  958. }
  959. if (auto guild_id = json_tree.get_optional<int32>("guild_id")) {
  960. guildID = guild_id.get();
  961. }
  962. bool success = false;
  963. if (net.is_primary) {
  964. if (newGuildName.size() > 0) {
  965. guildID = world.CreateGuild(newGuildName.c_str());
  966. if (guildID) {
  967. peer_manager.sendPeersCreateGuild(guildID);
  968. success = true;
  969. }
  970. }
  971. }
  972. else if (guildID) {
  973. database.LoadGuild(guildID);
  974. success = true;
  975. }
  976. pt.put("success", success);
  977. pt.put("guild_id", guildID);
  978. pt.put("guild_name", newGuildName);
  979. pt.put("leader_name", leaderName);
  980. std::ostringstream oss;
  981. boost::property_tree::write_json(oss, pt);
  982. std::string json = oss.str();
  983. res.body() = json;
  984. res.prepare_payload();
  985. }
  986. void World::Web_worldhandle_addguildmember(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  987. res.set(http::field::content_type, "application/json; charset=utf-8");
  988. boost::property_tree::ptree pt, json_tree;
  989. std::istringstream json_stream(req.body());
  990. boost::property_tree::read_json(json_stream, json_tree);
  991. std::string invitedBy("");
  992. int32 guildID = 0, charID = 0, joinTimestamp = 0;
  993. int8 guildRank = 0;
  994. if (auto character_id = json_tree.get_optional<int32>("character_id")) {
  995. charID = character_id.get();
  996. }
  997. if (auto name = json_tree.get_optional<std::string>("invited_by")) {
  998. invitedBy = name.get();
  999. }
  1000. if (auto guild_id = json_tree.get_optional<int32>("guild_id")) {
  1001. guildID = guild_id.get();
  1002. }
  1003. if (auto join_timestamp = json_tree.get_optional<int8>("join_timestamp")) {
  1004. joinTimestamp = join_timestamp.get();
  1005. }
  1006. if (auto rank = json_tree.get_optional<int8>("rank")) {
  1007. guildRank = rank.get();
  1008. }
  1009. bool success = false;
  1010. if (guildID) {
  1011. Guild* guild = guild_list.GetGuild(guildID);
  1012. if (guild) {
  1013. guild->AddNewGuildMember(charID, invitedBy.c_str(), joinTimestamp, guildRank);
  1014. success = true;
  1015. }
  1016. }
  1017. pt.put("success", success);
  1018. pt.put("guild_id", guildID);
  1019. pt.put("invited_by", invitedBy);
  1020. pt.put("character_id", charID);
  1021. std::ostringstream oss;
  1022. boost::property_tree::write_json(oss, pt);
  1023. std::string json = oss.str();
  1024. res.body() = json;
  1025. res.prepare_payload();
  1026. }
  1027. void World::Web_worldhandle_removeguildmember(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  1028. res.set(http::field::content_type, "application/json; charset=utf-8");
  1029. boost::property_tree::ptree pt, json_tree;
  1030. std::istringstream json_stream(req.body());
  1031. boost::property_tree::read_json(json_stream, json_tree);
  1032. std::string removedBy("");
  1033. int32 guildID = 0, charID = 0;
  1034. if (auto character_id = json_tree.get_optional<int32>("character_id")) {
  1035. charID = character_id.get();
  1036. }
  1037. if (auto name = json_tree.get_optional<std::string>("removed_by")) {
  1038. removedBy = name.get();
  1039. }
  1040. if (auto guild_id = json_tree.get_optional<int32>("guild_id")) {
  1041. guildID = guild_id.get();
  1042. }
  1043. bool success = false;
  1044. if (guildID) {
  1045. Guild* guild = guild_list.GetGuild(guildID);
  1046. if (guild) {
  1047. guild->RemoveGuildMember(charID, true);
  1048. success = true;
  1049. }
  1050. }
  1051. pt.put("success", success);
  1052. pt.put("guild_id", guildID);
  1053. pt.put("removed_by", removedBy);
  1054. pt.put("character_id", charID);
  1055. std::ostringstream oss;
  1056. boost::property_tree::write_json(oss, pt);
  1057. std::string json = oss.str();
  1058. res.body() = json;
  1059. res.prepare_payload();
  1060. }
  1061. void World::Web_worldhandle_setguildpermission(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  1062. res.set(http::field::content_type, "application/json; charset=utf-8");
  1063. boost::property_tree::ptree pt, json_tree;
  1064. std::istringstream json_stream(req.body());
  1065. boost::property_tree::read_json(json_stream, json_tree);
  1066. int32 guildID = 0;
  1067. int8 rank = 0, permission = 0, value_ = 0;
  1068. if (auto guild_id = json_tree.get_optional<int32>("guild_id")) {
  1069. guildID = guild_id.get();
  1070. }
  1071. if (auto in_rank = json_tree.get_optional<int8>("rank")) {
  1072. rank = in_rank.get();
  1073. }
  1074. if (auto in_permission = json_tree.get_optional<int8>("permission")) {
  1075. permission = in_permission.get();
  1076. }
  1077. if (auto in_value = json_tree.get_optional<int8>("value")) {
  1078. value_ = in_value.get();
  1079. }
  1080. bool success = false;
  1081. if (guildID) {
  1082. Guild* guild = guild_list.GetGuild(guildID);
  1083. if (guild) {
  1084. guild->SetPermission(rank, permission, value_, true, false);
  1085. success = true;
  1086. }
  1087. }
  1088. pt.put("success", success);
  1089. pt.put("guild_id", guildID);
  1090. std::ostringstream oss;
  1091. boost::property_tree::write_json(oss, pt);
  1092. std::string json = oss.str();
  1093. res.body() = json;
  1094. res.prepare_payload();
  1095. }
  1096. void World::Web_worldhandle_setguildeventfilter(const http::request<http::string_body>& req, http::response<http::string_body>& res) {
  1097. res.set(http::field::content_type, "application/json; charset=utf-8");
  1098. boost::property_tree::ptree pt, json_tree;
  1099. std::istringstream json_stream(req.body());
  1100. boost::property_tree::read_json(json_stream, json_tree);
  1101. int32 guildID = 0;
  1102. int8 eventID = 0, category = 0, value_ = 0;
  1103. if (auto guild_id = json_tree.get_optional<int32>("guild_id")) {
  1104. guildID = guild_id.get();
  1105. }
  1106. if (auto event_id = json_tree.get_optional<int8>("event_id")) {
  1107. eventID = event_id.get();
  1108. }
  1109. if (auto in_category = json_tree.get_optional<int8>("category")) {
  1110. category = in_category.get();
  1111. }
  1112. if (auto in_value = json_tree.get_optional<int8>("value")) {
  1113. value_ = in_value.get();
  1114. }
  1115. bool success = false;
  1116. if (guildID) {
  1117. Guild* guild = guild_list.GetGuild(guildID);
  1118. if (guild) {
  1119. guild->SetEventFilter(eventID, category, value_, true, false);
  1120. success = true;
  1121. }
  1122. }
  1123. pt.put("success", success);
  1124. pt.put("guild_id", guildID);
  1125. std::ostringstream oss;
  1126. boost::property_tree::write_json(oss, pt);
  1127. std::string json = oss.str();
  1128. res.body() = json;
  1129. res.prepare_payload();
  1130. }