mirror of
https://github.com/EQEmu/Server.git
synced 2026-02-26 02:02:25 +00:00
Cleanup of various things, made writing method handlers in web_interface easier now you just have to check args
This commit is contained in:
parent
dd88d0096b
commit
2ed960d733
@ -14,7 +14,7 @@ void register_authorized_methods()
|
||||
authorized_methods["World.GetZoneDetails"] = std::make_pair(10, handle_method_get_zone_info);
|
||||
authorized_methods["Zone.Subscribe"] = std::make_pair(10, handle_method_subscribe);
|
||||
authorized_methods["Zone.Unsubscribe"] = std::make_pair(10, handle_method_subscribe);
|
||||
authorized_methods["Zone.GetInitialEntityPositions"] = std::make_pair(10, handle_method_void_event);
|
||||
authorized_methods["Zone.GetInitialEntityPositions"] = std::make_pair(10, handle_method_zone_no_args);
|
||||
}
|
||||
|
||||
void register_unauthorized_methods()
|
||||
@ -45,17 +45,7 @@ void handle_method_no_args(per_session_data_eqemu *session, rapidjson::Document
|
||||
CheckParams(0, "[]");
|
||||
VerifyID();
|
||||
CalculateSize();
|
||||
|
||||
ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCall, sz);
|
||||
pack->WriteUInt32((uint32)id.size());
|
||||
pack->WriteString(id.c_str());
|
||||
pack->WriteUInt32((uint32)session->uuid.size());
|
||||
pack->WriteString(session->uuid.c_str());
|
||||
pack->WriteUInt32((uint32)method.size());
|
||||
pack->WriteString(method.c_str());
|
||||
pack->WriteUInt32(0);
|
||||
worldserver->SendPacket(pack);
|
||||
safe_delete(pack);
|
||||
WriteWebProtocolPacket();
|
||||
}
|
||||
|
||||
void handle_method_get_zone_info(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method)
|
||||
@ -63,77 +53,19 @@ void handle_method_get_zone_info(per_session_data_eqemu *session, rapidjson::Doc
|
||||
CheckParams(1, "[zoneserver_id]");
|
||||
VerifyID();
|
||||
CalculateSize();
|
||||
|
||||
ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCall, sz);
|
||||
pack->WriteUInt32((uint32)id.size());
|
||||
pack->WriteString(id.c_str());
|
||||
pack->WriteUInt32((uint32)session->uuid.size());
|
||||
pack->WriteString(session->uuid.c_str());
|
||||
pack->WriteUInt32((uint32)method.size());
|
||||
pack->WriteString(method.c_str());
|
||||
pack->WriteUInt32(1);
|
||||
|
||||
auto ¶ms = document["params"];
|
||||
auto ¶m = params[(rapidjson::SizeType)0];
|
||||
pack->WriteUInt32((uint32)strlen(param.GetString()));
|
||||
pack->WriteString(param.GetString());
|
||||
worldserver->SendPacket(pack);
|
||||
safe_delete(pack);
|
||||
WriteWebProtocolPacket();
|
||||
}
|
||||
|
||||
void handle_method_subscribe(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method) {
|
||||
CheckParams(3, "[zone_id, instance_id, event_name]");
|
||||
VerifyID();
|
||||
CalculateSize();
|
||||
|
||||
ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCall, sz);
|
||||
pack->WriteUInt32((uint32)id.size());
|
||||
pack->WriteString(id.c_str());
|
||||
pack->WriteUInt32((uint32)session->uuid.size());
|
||||
pack->WriteString(session->uuid.c_str());
|
||||
pack->WriteUInt32((uint32)method.size());
|
||||
pack->WriteString(method.c_str());
|
||||
pack->WriteUInt32(3);
|
||||
|
||||
auto ¶ms = document["params"];
|
||||
auto ¶m = params[(rapidjson::SizeType)0];
|
||||
pack->WriteUInt32((uint32)strlen(param.GetString()));
|
||||
pack->WriteString(param.GetString());
|
||||
|
||||
param = params[1];
|
||||
pack->WriteUInt32((uint32)strlen(param.GetString()));
|
||||
pack->WriteString(param.GetString());
|
||||
|
||||
param = params[2];
|
||||
pack->WriteUInt32((uint32)strlen(param.GetString()));
|
||||
pack->WriteString(param.GetString());
|
||||
worldserver->SendPacket(pack);
|
||||
safe_delete(pack);
|
||||
WriteWebProtocolPacket();
|
||||
}
|
||||
|
||||
void handle_method_void_event(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method) {
|
||||
void handle_method_zone_no_args(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method) {
|
||||
CheckParams(2, "[zone_id, instance_id]");
|
||||
VerifyID();
|
||||
CalculateSize();
|
||||
|
||||
ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCall, sz);
|
||||
pack->WriteUInt32((uint32)id.size());
|
||||
pack->WriteString(id.c_str());
|
||||
pack->WriteUInt32((uint32)session->uuid.size());
|
||||
pack->WriteString(session->uuid.c_str());
|
||||
pack->WriteUInt32((uint32)method.size());
|
||||
pack->WriteString(method.c_str());
|
||||
pack->WriteUInt32(2);
|
||||
|
||||
auto ¶ms = document["params"];
|
||||
auto ¶m = params[(rapidjson::SizeType)0];
|
||||
pack->WriteUInt32((uint32)strlen(param.GetString()));
|
||||
pack->WriteString(param.GetString());
|
||||
|
||||
param = params[1];
|
||||
pack->WriteUInt32((uint32)strlen(param.GetString()));
|
||||
pack->WriteString(param.GetString());
|
||||
|
||||
worldserver->SendPacket(pack);
|
||||
safe_delete(pack);
|
||||
WriteWebProtocolPacket();
|
||||
}
|
||||
@ -29,7 +29,7 @@
|
||||
WriteWebCallResponseString(session, document, "Missing parameters, expected: " + std::string(msg), true); \
|
||||
return; \
|
||||
} \
|
||||
if(params.Size() != sz) { \
|
||||
if(params.Size() < sz) { \
|
||||
WriteWebCallResponseString(session, document, "Missing parameters, expected: " + std::string(msg), true); \
|
||||
return; \
|
||||
} \
|
||||
@ -56,12 +56,30 @@
|
||||
} \
|
||||
} \
|
||||
|
||||
#define WriteWebProtocolPacket() ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCall, sz); \
|
||||
pack->WriteUInt32((uint32)id.size()); \
|
||||
pack->WriteString(id.c_str()); \
|
||||
pack->WriteUInt32((uint32)session->uuid.size()); \
|
||||
pack->WriteString(session->uuid.c_str()); \
|
||||
pack->WriteUInt32((uint32)method.size()); \
|
||||
pack->WriteString(method.c_str()); \
|
||||
auto ¶ms = document["params"]; \
|
||||
auto params_sz = params.Size(); \
|
||||
pack->WriteUInt32(params_sz); \
|
||||
for(rapidjson::SizeType i = 0; i < params_sz; ++i) { \
|
||||
auto ¶m = params[(rapidjson::SizeType)i]; \
|
||||
pack->WriteUInt32((uint32)strlen(param.GetString())); \
|
||||
pack->WriteString(param.GetString()); \
|
||||
} \
|
||||
worldserver->SendPacket(pack); \
|
||||
safe_delete(pack); \
|
||||
|
||||
void register_methods();
|
||||
void handle_method_token_auth(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method);
|
||||
void handle_method_no_args(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method);
|
||||
void handle_method_get_zone_info(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method);
|
||||
void handle_method_subscribe(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method);
|
||||
void handle_method_void_event(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method);
|
||||
void handle_method_zone_no_args(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -43,7 +43,8 @@
|
||||
}
|
||||
else if(obj.id == 'get_zone_info_id') {
|
||||
socket.send(JSON.stringify({id: 'subscribe_id', method: 'Zone.Subscribe', params: [obj.result["zone_id"], obj.result["instance_id"], 'NPCPosition']}));
|
||||
} else if(obj.method = "On.NPCPosition") {
|
||||
socket.send(JSON.stringify({id: 'on_entity_pos_id', method: 'Zone.GetInitialEntityPositions', params: [obj.result["zone_id"], obj.result["instance_id"]]}));
|
||||
} else if(obj.method == "On.NPCPosition") {
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@ -132,7 +132,7 @@ int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocke
|
||||
|
||||
static struct libwebsocket_protocols protocols[] = {
|
||||
{ "http-only", callback_http, 0, 0, },
|
||||
{ "eqemu", callback_eqemu, sizeof(per_session_data_eqemu), 0, },
|
||||
{ "eqemu", callback_eqemu, sizeof(per_session_data_eqemu), 65536, },
|
||||
{ nullptr, nullptr, 0, 0 }
|
||||
};
|
||||
|
||||
@ -159,7 +159,7 @@ int main() {
|
||||
memset(&info, 0, sizeof info);
|
||||
info.port = config->WebInterfacePort;
|
||||
info.protocols = protocols;
|
||||
info.extensions = libwebsocket_get_internal_extensions();
|
||||
info.extensions = nullptr;
|
||||
info.gid = -1;
|
||||
info.uid = -1;
|
||||
|
||||
|
||||
@ -137,8 +137,6 @@ void WorldServer::Process(){
|
||||
char *session_id = nullptr;
|
||||
char *method = nullptr;
|
||||
|
||||
DumpPacket(pack);
|
||||
|
||||
session_id = new char[pack->ReadUInt32() + 1];
|
||||
pack->ReadString(session_id);
|
||||
|
||||
@ -207,7 +205,7 @@ void WorldServer::Process(){
|
||||
uint32 sz = 12;
|
||||
size_t isz = invalidate.size();
|
||||
for(size_t i = 0; i < isz; ++i) {
|
||||
sz += invalidate[i].size();
|
||||
sz += (uint32)invalidate[i].size();
|
||||
sz += 5;
|
||||
}
|
||||
|
||||
|
||||
@ -80,39 +80,6 @@ void register_remote_call_handlers() {
|
||||
remote_call_methods["Zone.GetInitialEntityPositions"] = handle_rc_get_initial_entity_positions;
|
||||
}
|
||||
|
||||
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> ¶ms) {
|
||||
std::string error;
|
||||
std::map<std::string, std::string> res;
|
||||
|
||||
int16 i = 0;
|
||||
std::list<NPC*> npc_list;
|
||||
entity_list.GetNPCList(npc_list);
|
||||
for (std::list<NPC*>::iterator itr = npc_list.begin(); itr != npc_list.end(); ++itr) {
|
||||
NPC* npc = *itr;
|
||||
// res[std::to_string(npc->GetID())] = MakeJSON(
|
||||
// "zone_id:" + std::to_string(zone->GetZoneID()) +
|
||||
// ",inst_id:" + std::to_string(zone->GetInstanceID()) +
|
||||
// ",ent_id:" + std::to_string(npc->GetID()) +
|
||||
// ",name:" + npc->GetName() +
|
||||
// ",x:" + std::to_string(npc->GetX()) +
|
||||
// ",y:" + std::to_string(npc->GetX()) +
|
||||
// ",z:" + std::to_string(npc->GetX()) +
|
||||
// ",h:" + std::to_string(npc->GetHeading())
|
||||
// );
|
||||
res["zone_id"] = itoa(zone->GetZoneID());
|
||||
res["instance_id"] = itoa(zone->GetInstanceID());
|
||||
res["ent_id"] = itoa(npc->GetID());
|
||||
res["name"] = npc->GetName();
|
||||
res["x"] = itoa(npc->GetX());
|
||||
res["y"] = itoa(npc->GetY());
|
||||
res["z"] = itoa(npc->GetZ());
|
||||
res["h"] = itoa(npc->GetHeading());
|
||||
RemoteCallResponse(connection_id, request_id, res, error);
|
||||
i++;
|
||||
printf("Response ent pos %i \n", i);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_rc_subscribe(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> ¶ms) {
|
||||
std::string error;
|
||||
std::map<std::string, std::string> res;
|
||||
@ -151,3 +118,23 @@ void handle_rc_unsubscribe(const std::string &method, const std::string &connect
|
||||
|
||||
RemoteCallResponse(connection_id, request_id, res, error);
|
||||
}
|
||||
|
||||
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> ¶ms) {
|
||||
std::string error;
|
||||
std::map<std::string, std::string> res;
|
||||
|
||||
std::list<NPC*> npc_list;
|
||||
entity_list.GetNPCList(npc_list);
|
||||
for(std::list<NPC*>::iterator itr = npc_list.begin(); itr != npc_list.end(); ++itr) {
|
||||
NPC* npc = *itr;
|
||||
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["name"] = npc->GetName();
|
||||
res["x"] = std::to_string((double)npc->GetX());
|
||||
res["y"] = std::to_string((double)npc->GetY());
|
||||
res["z"] = std::to_string((double)npc->GetZ());
|
||||
res["h"] = std::to_string((double)npc->GetHeading());
|
||||
RemoteCallResponse(connection_id, request_id, res, error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,9 +29,9 @@ void RemoteCall(const std::string &connection_id, const std::string &method, con
|
||||
|
||||
void register_remote_call_handlers();
|
||||
|
||||
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> ¶ms);
|
||||
void handle_rc_subscribe(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> ¶ms);
|
||||
void handle_rc_unsubscribe(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> ¶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<std::string> ¶ms);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user