Added client to Zone.Get.Initial.Entity.Positions

Added type field to Zone.Get.Initial.Entity.Positions
Added method Zone.Move.Entity, currently in test mode
Made modifications to explode function in web_interface_utils.h
This commit is contained in:
Akkadius 2014-08-07 20:13:37 -05:00
parent c6d8b7e337
commit 34913c2046
8 changed files with 98 additions and 9 deletions

View File

@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using namespace rapidjson; using namespace rapidjson;
using namespace std; using namespace std;
std::vector<std::string> explode(std::string const & s, char delim) std::vector<std::string> explode_string(std::string const & s, char delim)
{ {
std::vector<std::string> result; std::vector<std::string> result;
std::istringstream iss(s); std::istringstream iss(s);
@ -48,10 +48,10 @@ std::string MakeJSON(std::string json)
Writer<StringBuffer> writer(s); Writer<StringBuffer> writer(s);
writer.StartObject(); writer.StartObject();
auto arg_c = explode(json, ','); auto arg_c = explode_string(json, ',');
if (arg_c.size() == 0) if (arg_c.size() == 0)
{ {
auto arg_v = explode(json, ':'); auto arg_v = explode_string(json, ':');
if (arg_v.size() > 0) if (arg_v.size() > 0)
{ {
for (int j = 0; j < arg_v.size(); j++) 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++) 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++) for (int j = 0; j < arg_v.size(); j++)
{ {
writer.String(arg_v[j].c_str()); writer.String(arg_v[j].c_str());

View File

@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <vector> #include <vector>
#include <utility> #include <utility>
std::vector<std::string> explode_string(std::string const & s, char delim);
std::string MakeJSON(std::string json); std::string MakeJSON(std::string json);
#endif #endif

View File

@ -14,7 +14,8 @@ void register_authorized_methods()
authorized_methods["World.GetZoneDetails"] = std::make_pair(10, handle_method_world); 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.Subscribe"] = std::make_pair(10, handle_method_zone);
authorized_methods["Zone.Unsubscribe"] = 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() void register_unauthorized_methods()

View File

@ -27,6 +27,7 @@
#include <sstream> #include <sstream>
#include <set> #include <set>
#ifdef _WINDOWS #ifdef _WINDOWS
#define snprintf _snprintf #define snprintf _snprintf
#define strncasecmp _strnicmp #define strncasecmp _strnicmp
@ -69,6 +70,8 @@
#include "merc.h" #include "merc.h"
#include "../common/ZoneNumbers.h" #include "../common/ZoneNumbers.h"
#include "QuestParserCollection.h" #include "QuestParserCollection.h"
#include "remote_call.h"
#include "remote_call_subscribe.h"
extern Zone* zone; extern Zone* zone;
extern volatile bool ZoneLoaded; extern volatile bool ZoneLoaded;
@ -1023,6 +1026,20 @@ void Client::Handle_OP_ClientUpdate(const EQApplicationPacket *app)
} }
PlayerPositionUpdateClient_Struct* ppu = (PlayerPositionUpdateClient_Struct*)app->pBuffer; PlayerPositionUpdateClient_Struct* ppu = (PlayerPositionUpdateClient_Struct*)app->pBuffer;
/* Web Interface */
if (IsClient()) {
std::vector<std::string> 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()) { if(ppu->spawn_id != GetID()) {
// check if the id is for a boat the player is controlling // check if the id is for a boat the player is controlling
if (ppu->spawn_id == BoatID) { if (ppu->spawn_id == BoatID) {

View File

@ -23,6 +23,7 @@
#include <string.h> #include <string.h>
#include <iostream> #include <iostream>
#ifdef _WINDOWS #ifdef _WINDOWS
#include <process.h> #include <process.h>
#else #else
@ -44,6 +45,8 @@
#include "guild_mgr.h" #include "guild_mgr.h"
#include "raids.h" #include "raids.h"
#include "QuestParserCollection.h" #include "QuestParserCollection.h"
#include "remote_call.h"
#include "remote_call_subscribe.h"
#ifdef _WINDOWS #ifdef _WINDOWS
#define snprintf _snprintf #define snprintf _snprintf
@ -2367,6 +2370,11 @@ void EntityList::Depop(bool StartSpawnTimer)
if (pnpc->IsFindable()) if (pnpc->IsFindable())
UpdateFindableNPCState(pnpc, true); UpdateFindableNPCState(pnpc, true);
/* Web Interface Depop Entities */
std::vector<std::string> params;
params.push_back(std::to_string((long)pnpc->GetID()));
RemoteCallSubscriptionHandler::Instance()->OnEvent("NPC.Depop", params);
pnpc->Depop(StartSpawnTimer); 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) { for (auto it = npc_list.begin(); it != npc_list.end(); ++it) {
NPC *pnpc = it->second; NPC *pnpc = it->second;
if (pnpc && (pnpc->GetNPCTypeID() == (uint32)NPCTypeID)) if (pnpc && (pnpc->GetNPCTypeID() == (uint32)NPCTypeID)){
pnpc->Depop(StartSpawnTimer); pnpc->Depop(StartSpawnTimer);
/* Web Interface Depop Entities */
std::vector<std::string> params;
params.push_back(std::to_string((long)pnpc->GetID()));
RemoteCallSubscriptionHandler::Instance()->OnEvent("NPC.Depop", params);
}
} }
} }

View File

@ -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)y_pos));
params.push_back(std::to_string((double)z_pos)); params.push_back(std::to_string((double)z_pos));
params.push_back(std::to_string((double)heading)); params.push_back(std::to_string((double)heading));
RemoteCallSubscriptionHandler::Instance()->OnEvent("NPCPosition", params); RemoteCallSubscriptionHandler::Instance()->OnEvent("NPC.Position", params);
} }
} }

View File

@ -13,6 +13,8 @@
#include "zone.h" #include "zone.h"
#include "entity.h" #include "entity.h"
#include "npc.h" #include "npc.h"
#include "mob.h"
#include "client.h"
#include <string> #include <string>
std::map<std::string, RemoteCallHandler> remote_call_methods; std::map<std::string, RemoteCallHandler> remote_call_methods;
@ -77,7 +79,8 @@ void RemoteCall(const std::string &connection_id, const std::string &method, con
void register_remote_call_handlers() { void register_remote_call_handlers() {
remote_call_methods["Zone.Subscribe"] = handle_rc_subscribe; remote_call_methods["Zone.Subscribe"] = handle_rc_subscribe;
remote_call_methods["Zone.Unsubscribe"] = handle_rc_unsubscribe; 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<std::string> &params) { void handle_rc_subscribe(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> &params) {
@ -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["zone_id"] = std::to_string((long)zone->GetZoneID());
res["instance_id"] = std::to_string((long)zone->GetInstanceID()); res["instance_id"] = std::to_string((long)zone->GetInstanceID());
res["ent_id"] = std::to_string((long)npc->GetID()); res["ent_id"] = std::to_string((long)npc->GetID());
res["type"] = "NPC";
res["name"] = npc->GetName(); res["name"] = npc->GetName();
res["x"] = std::to_string((double)npc->GetX()); res["x"] = std::to_string((double)npc->GetX());
res["y"] = std::to_string((double)npc->GetY()); 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()); res["h"] = std::to_string((double)npc->GetHeading());
RemoteCallResponse(connection_id, request_id, res, error); RemoteCallResponse(connection_id, request_id, res, error);
} }
std::list<Client*> client_list;
entity_list.GetClientList(client_list);
for (std::list<Client*>::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<std::string> &params) {
std::string error;
std::map<std::string, std::string> 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());
}
}
} }

View File

@ -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<std::string> &params); void handle_rc_subscribe(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> &params);
void handle_rc_unsubscribe(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> &params); void handle_rc_unsubscribe(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> &params);
void handle_rc_get_initial_entity_positions(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> &params); void handle_rc_get_initial_entity_positions(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> &params);
void handle_rc_move_entity(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> &params);
#endif #endif