diff --git a/common/web_interface_utils.cpp b/common/web_interface_utils.cpp index bd666f375..18f332af7 100644 --- a/common/web_interface_utils.cpp +++ b/common/web_interface_utils.cpp @@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA using namespace rapidjson; using namespace std; -std::vector explode(std::string const & s, char delim) +std::vector explode_string(std::string const & s, char delim) { std::vector result; std::istringstream iss(s); @@ -48,10 +48,10 @@ std::string MakeJSON(std::string json) Writer writer(s); writer.StartObject(); - auto arg_c = explode(json, ','); + auto arg_c = explode_string(json, ','); if (arg_c.size() == 0) { - auto arg_v = explode(json, ':'); + auto arg_v = explode_string(json, ':'); if (arg_v.size() > 0) { for (int j = 0; j < arg_v.size(); j++) @@ -64,7 +64,7 @@ std::string MakeJSON(std::string json) { for (int i = 0; i < arg_c.size(); i++) { - auto arg_v = explode(arg_c[i], ':'); + auto arg_v = explode_string(arg_c[i], ':'); for (int j = 0; j < arg_v.size(); j++) { writer.String(arg_v[j].c_str()); diff --git a/common/web_interface_utils.h b/common/web_interface_utils.h index bea3016c6..c4c88e4c3 100644 --- a/common/web_interface_utils.h +++ b/common/web_interface_utils.h @@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include +std::vector explode_string(std::string const & s, char delim); std::string MakeJSON(std::string json); #endif diff --git a/web_interface/method_handler.cpp b/web_interface/method_handler.cpp index 04175b394..e24339f66 100644 --- a/web_interface/method_handler.cpp +++ b/web_interface/method_handler.cpp @@ -14,7 +14,8 @@ void register_authorized_methods() authorized_methods["World.GetZoneDetails"] = std::make_pair(10, handle_method_world); authorized_methods["Zone.Subscribe"] = std::make_pair(10, handle_method_zone); authorized_methods["Zone.Unsubscribe"] = std::make_pair(10, handle_method_zone); - authorized_methods["Zone.GetInitialEntityPositions"] = std::make_pair(10, handle_method_zone); + authorized_methods["Zone.Get.Initial.Entity.Positions"] = std::make_pair(10, handle_method_zone); + authorized_methods["Zone.Move.Entity"] = std::make_pair(10, handle_method_zone); } void register_unauthorized_methods() diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 01e768c1f..c5254352c 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -27,6 +27,7 @@ #include #include + #ifdef _WINDOWS #define snprintf _snprintf #define strncasecmp _strnicmp @@ -69,6 +70,8 @@ #include "merc.h" #include "../common/ZoneNumbers.h" #include "QuestParserCollection.h" +#include "remote_call.h" +#include "remote_call_subscribe.h" extern Zone* zone; extern volatile bool ZoneLoaded; @@ -1023,6 +1026,20 @@ void Client::Handle_OP_ClientUpdate(const EQApplicationPacket *app) } PlayerPositionUpdateClient_Struct* ppu = (PlayerPositionUpdateClient_Struct*)app->pBuffer; + /* Web Interface */ + if (IsClient()) { + std::vector params; + params.push_back(std::to_string((long)zone->GetZoneID())); + params.push_back(std::to_string((long)zone->GetInstanceID())); + params.push_back(std::to_string((long)GetID())); + params.push_back(GetCleanName()); + params.push_back(std::to_string((double)ppu->x_pos)); + params.push_back(std::to_string((double)ppu->y_pos)); + params.push_back(std::to_string((double)ppu->z_pos)); + params.push_back(std::to_string((double)heading)); + RemoteCallSubscriptionHandler::Instance()->OnEvent("Client.Position", params); + } + if(ppu->spawn_id != GetID()) { // check if the id is for a boat the player is controlling if (ppu->spawn_id == BoatID) { diff --git a/zone/entity.cpp b/zone/entity.cpp index 3d316585d..9700f1c92 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -23,6 +23,7 @@ #include #include + #ifdef _WINDOWS #include #else @@ -44,6 +45,8 @@ #include "guild_mgr.h" #include "raids.h" #include "QuestParserCollection.h" +#include "remote_call.h" +#include "remote_call_subscribe.h" #ifdef _WINDOWS #define snprintf _snprintf @@ -2367,6 +2370,11 @@ void EntityList::Depop(bool StartSpawnTimer) if (pnpc->IsFindable()) UpdateFindableNPCState(pnpc, true); + /* Web Interface Depop Entities */ + std::vector params; + params.push_back(std::to_string((long)pnpc->GetID())); + RemoteCallSubscriptionHandler::Instance()->OnEvent("NPC.Depop", params); + pnpc->Depop(StartSpawnTimer); } } @@ -2376,8 +2384,14 @@ void EntityList::DepopAll(int NPCTypeID, bool StartSpawnTimer) { for (auto it = npc_list.begin(); it != npc_list.end(); ++it) { NPC *pnpc = it->second; - if (pnpc && (pnpc->GetNPCTypeID() == (uint32)NPCTypeID)) - pnpc->Depop(StartSpawnTimer); + if (pnpc && (pnpc->GetNPCTypeID() == (uint32)NPCTypeID)){ + pnpc->Depop(StartSpawnTimer); + + /* Web Interface Depop Entities */ + std::vector params; + params.push_back(std::to_string((long)pnpc->GetID())); + RemoteCallSubscriptionHandler::Instance()->OnEvent("NPC.Depop", params); + } } } diff --git a/zone/mob.cpp b/zone/mob.cpp index 9a1258b70..1ed63bcaa 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -1225,7 +1225,7 @@ void Mob::MakeSpawnUpdateNoDelta(PlayerPositionUpdateServer_Struct *spu){ params.push_back(std::to_string((double)y_pos)); params.push_back(std::to_string((double)z_pos)); params.push_back(std::to_string((double)heading)); - RemoteCallSubscriptionHandler::Instance()->OnEvent("NPCPosition", params); + RemoteCallSubscriptionHandler::Instance()->OnEvent("NPC.Position", params); } } diff --git a/zone/remote_call.cpp b/zone/remote_call.cpp index 411d658e0..74695d0bd 100644 --- a/zone/remote_call.cpp +++ b/zone/remote_call.cpp @@ -13,6 +13,8 @@ #include "zone.h" #include "entity.h" #include "npc.h" +#include "mob.h" +#include "client.h" #include std::map remote_call_methods; @@ -77,7 +79,8 @@ void RemoteCall(const std::string &connection_id, const std::string &method, con void register_remote_call_handlers() { remote_call_methods["Zone.Subscribe"] = handle_rc_subscribe; remote_call_methods["Zone.Unsubscribe"] = handle_rc_unsubscribe; - remote_call_methods["Zone.GetInitialEntityPositions"] = handle_rc_get_initial_entity_positions; + remote_call_methods["Zone.Get.Initial.Entity.Positions"] = handle_rc_get_initial_entity_positions; + remote_call_methods["Zone.Move.Entity"] = handle_rc_move_entity; } void handle_rc_subscribe(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector ¶ms) { @@ -130,6 +133,7 @@ void handle_rc_get_initial_entity_positions(const std::string &method, const std res["zone_id"] = std::to_string((long)zone->GetZoneID()); res["instance_id"] = std::to_string((long)zone->GetInstanceID()); res["ent_id"] = std::to_string((long)npc->GetID()); + res["type"] = "NPC"; res["name"] = npc->GetName(); res["x"] = std::to_string((double)npc->GetX()); res["y"] = std::to_string((double)npc->GetY()); @@ -137,4 +141,55 @@ void handle_rc_get_initial_entity_positions(const std::string &method, const std res["h"] = std::to_string((double)npc->GetHeading()); RemoteCallResponse(connection_id, request_id, res, error); } + std::list client_list; + entity_list.GetClientList(client_list); + for (std::list::iterator itr = client_list.begin(); itr != client_list.end(); ++itr) { + Client* c = *itr; + res["zone_id"] = itoa(zone->GetZoneID()); + res["instance_id"] = itoa(zone->GetInstanceID()); + res["ent_id"] = itoa(c->GetID()); + res["type"] = "Client"; + res["name"] = c->GetCleanName(); + res["x"] = itoa(c->GetX()); + res["y"] = itoa(c->GetY()); + res["z"] = itoa(c->GetZ()); + res["h"] = itoa(c->GetHeading()); + RemoteCallResponse(connection_id, request_id, res, error); + } } + +void handle_rc_move_entity(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector ¶ms) { + std::string error; + std::map res; + + if (params.size() != 1) { + error = "Missing function data"; + RemoteCallResponse(connection_id, request_id, res, error); + return; + + } + + printf("params 0 = %s\n", params[0].c_str()); + printf("params 1 = %s\n", params[1].c_str()); + printf("params 2 = %s\n", params[2].c_str()); + printf("params 3 = %s\n", params[3].c_str()); + return; + auto arg_v = explode_string(params[0].c_str(), ':'); + /* + 0 = Ent ID + 1 = X + 2 = Y + 3 = Z + 4 = H + */ + Mob *ent = entity_list.GetMob(atoi(arg_v[0].c_str())); + if (ent){ + if (ent->IsClient()){ + ent->CastToClient()->MovePC(zone->GetZoneID(), zone->GetInstanceID(), atoi(arg_v[1].c_str()), atoi(arg_v[2].c_str()), ent->GetGroundZ(atoi(arg_v[1].c_str()), atoi(arg_v[2].c_str())), ent->GetHeading()); + + } + else{ + ent->GMMove(atoi(arg_v[1].c_str()), atoi(arg_v[2].c_str()), ent->GetGroundZ(atoi(arg_v[1].c_str()), atoi(arg_v[2].c_str())), ent->GetHeading()); + } + } +} \ No newline at end of file diff --git a/zone/remote_call.h b/zone/remote_call.h index 2097e2cca..2339921c1 100644 --- a/zone/remote_call.h +++ b/zone/remote_call.h @@ -32,6 +32,7 @@ void register_remote_call_handlers(); void handle_rc_subscribe(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector ¶ms); void handle_rc_unsubscribe(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector ¶ms); void handle_rc_get_initial_entity_positions(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector ¶ms); +void handle_rc_move_entity(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector ¶ms); #endif