diff --git a/source/WorldServer/Web/WorldWeb.cpp b/source/WorldServer/Web/WorldWeb.cpp index 5c9440d..2e8bd00 100644 --- a/source/WorldServer/Web/WorldWeb.cpp +++ b/source/WorldServer/Web/WorldWeb.cpp @@ -1,4 +1,5 @@ #include "../World.h" +#include "../WorldDatabase.h" #include "../LoginServer.h" #include @@ -9,6 +10,7 @@ extern ZoneList zone_list; extern World world; extern LoginServer loginserver; extern sint32 numclients; +extern WorldDatabase database; void World::Web_worldhandle_status(const http::request& req, http::response& res) { res.set(http::field::content_type, "application/json"); @@ -65,6 +67,7 @@ void ZoneList::PopulateClientList(http::response& res) { pt.put("account_age", cur->GetPlayer() ? cur->GetPlayer()->GetInfoStruct()->get_account_age_base() : 0); pt.put("account_id", cur->GetAccountID()); pt.put("version", cur->GetVersion()); + pt.put("status", cur->GetAdminStatus()); pt.put("is_zoning", (cur->IsZoning() || !cur->IsReadyForUpdates())); bool linkdead = cur->GetPlayer() ? (((cur->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)) : false; @@ -84,3 +87,44 @@ void ZoneList::PopulateClientList(http::response& res) { res.prepare_payload(); } +void World::Web_worldhandle_setadminstatus(const http::request& req, http::response& res) { + res.set(http::field::content_type, "application/json"); + boost::property_tree::ptree pt, json_tree; + + std::istringstream json_stream(req.body()); + boost::property_tree::read_json(json_stream, json_tree); + + sint16 status = 0; + std::string charname(""); + bool got_status_field = false; + if (auto name = json_tree.get_optional("character_name")) { + charname = name.get(); + } + if (auto new_status = json_tree.get_optional("new_status")) { + status = new_status.get(); + got_status_field = true; + } + + sint32 success = 0; + + if(got_status_field && charname.size() > 0 && database.UpdateAdminStatus((char*)charname.c_str(),status)) { + + Client* target = zone_list.GetClientByCharName(charname.c_str()); + if (target) { + target->SetAdminStatus(status); + target->Message(CHANNEL_COLOR_YELLOW, "Your admin status has been set to %i.", status); + } + success = 1; + } + else if(!got_status_field || charname.size() < 1) { + success = -1; + } + + pt.put("success", success); + + std::ostringstream oss; + boost::property_tree::write_json(oss, pt); + std::string json = oss.str(); + res.body() = json; + res.prepare_payload(); +} \ No newline at end of file diff --git a/source/WorldServer/World.cpp b/source/WorldServer/World.cpp index 707638a..b53a805 100644 --- a/source/WorldServer/World.cpp +++ b/source/WorldServer/World.cpp @@ -245,6 +245,7 @@ void World::init(std::string web_ipaddr, int16 web_port, std::string cert_file, world_webserver->register_route("/status", World::Web_worldhandle_status); world_webserver->register_route("/clients", World::Web_worldhandle_clients); + world_webserver->register_route("/setadminstatus", World::Web_worldhandle_setadminstatus); world_webserver->run(); LogWrite(INIT__INFO, 0, "Init", "World Web Server is listening on %s:%u..", web_ipaddr.c_str(), web_port); } diff --git a/source/WorldServer/World.h b/source/WorldServer/World.h index b0a9527..ebb167c 100644 --- a/source/WorldServer/World.h +++ b/source/WorldServer/World.h @@ -651,6 +651,7 @@ public: static void Web_worldhandle_status(const http::request& req, http::response& res); static void Web_worldhandle_clients(const http::request& req, http::response& res); + static void Web_worldhandle_setadminstatus(const http::request& req, http::response& res); Mutex MVoiceOvers;