mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-12 16:22:27 +00:00
Work on relay
This commit is contained in:
parent
780789fbad
commit
002f5e3bcc
@ -188,6 +188,7 @@
|
|||||||
|
|
||||||
#define ServerOP_WIRemoteCall 0x5001
|
#define ServerOP_WIRemoteCall 0x5001
|
||||||
#define ServerOP_WIRemoteCallResponse 0x5002
|
#define ServerOP_WIRemoteCallResponse 0x5002
|
||||||
|
#define ServerOP_WIClientSession 0x5003
|
||||||
|
|
||||||
enum { QSG_LFGuild = 0 };
|
enum { QSG_LFGuild = 0 };
|
||||||
enum { QSG_LFGuild_PlayerMatches = 0, QSG_LFGuild_UpdatePlayerInfo, QSG_LFGuild_RequestPlayerInfo, QSG_LFGuild_UpdateGuildInfo, QSG_LFGuild_GuildMatches,
|
enum { QSG_LFGuild_PlayerMatches = 0, QSG_LFGuild_UpdatePlayerInfo, QSG_LFGuild_RequestPlayerInfo, QSG_LFGuild_UpdateGuildInfo, QSG_LFGuild_GuildMatches,
|
||||||
|
|||||||
@ -27,12 +27,9 @@ void register_methods()
|
|||||||
|
|
||||||
void handle_method_token_auth(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method)
|
void handle_method_token_auth(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method)
|
||||||
{
|
{
|
||||||
if (!document.HasMember("token")) {
|
CheckParams(1, "[token]");
|
||||||
WriteWebCallResponseString(session, document, "Auth token missing", true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
session->auth = document["token"].GetString();
|
session->auth = document["params"][(rapidjson::SizeType)0].GetString();
|
||||||
if (!CheckTokenAuthorization(session)) {
|
if (!CheckTokenAuthorization(session)) {
|
||||||
WriteWebCallResponseBoolean(session, document, "false", false);
|
WriteWebCallResponseBoolean(session, document, "false", false);
|
||||||
} else {
|
} else {
|
||||||
@ -44,7 +41,8 @@ void handle_method_no_args(per_session_data_eqemu *session, rapidjson::Document
|
|||||||
{
|
{
|
||||||
CheckParams(0, "[]");
|
CheckParams(0, "[]");
|
||||||
VerifyID();
|
VerifyID();
|
||||||
uint32 sz = (uint32)(id.size() + session->uuid.size() + method.size() + 3 + 16);
|
CalculateSize();
|
||||||
|
|
||||||
ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCall, sz);
|
ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCall, sz);
|
||||||
pack->WriteUInt32((uint32)id.size());
|
pack->WriteUInt32((uint32)id.size());
|
||||||
pack->WriteString(id.c_str());
|
pack->WriteString(id.c_str());
|
||||||
@ -61,16 +59,7 @@ void handle_method_get_zone_info(per_session_data_eqemu *session, rapidjson::Doc
|
|||||||
{
|
{
|
||||||
CheckParams(1, "[zoneserver_id]");
|
CheckParams(1, "[zoneserver_id]");
|
||||||
VerifyID();
|
VerifyID();
|
||||||
uint32 sz = (uint32)(id.size() + session->uuid.size() + method.size() + 3 + 16);
|
CalculateSize();
|
||||||
auto ¶ms = document["params"];
|
|
||||||
auto ¶m = params[(rapidjson::SizeType)0];
|
|
||||||
if(param.IsNull()) {
|
|
||||||
sz += 5;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sz += (uint32)strlen(param.GetString());
|
|
||||||
sz += 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCall, sz);
|
ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCall, sz);
|
||||||
pack->WriteUInt32((uint32)id.size());
|
pack->WriteUInt32((uint32)id.size());
|
||||||
@ -80,6 +69,9 @@ void handle_method_get_zone_info(per_session_data_eqemu *session, rapidjson::Doc
|
|||||||
pack->WriteUInt32((uint32)method.size());
|
pack->WriteUInt32((uint32)method.size());
|
||||||
pack->WriteString(method.c_str());
|
pack->WriteString(method.c_str());
|
||||||
pack->WriteUInt32(1);
|
pack->WriteUInt32(1);
|
||||||
|
|
||||||
|
auto ¶ms = document["params"];
|
||||||
|
auto ¶m = params[(rapidjson::SizeType)0];
|
||||||
pack->WriteUInt32((uint32)strlen(param.GetString()));
|
pack->WriteUInt32((uint32)strlen(param.GetString()));
|
||||||
pack->WriteString(param.GetString());
|
pack->WriteString(param.GetString());
|
||||||
worldserver->SendPacket(pack);
|
worldserver->SendPacket(pack);
|
||||||
@ -87,17 +79,31 @@ void handle_method_get_zone_info(per_session_data_eqemu *session, rapidjson::Doc
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handle_method_subscribe(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) {
|
||||||
CheckParams(3, "[event, zone_id, instance_id]");
|
CheckParams(3, "[zone_id, instance_id, event_name]");
|
||||||
VerifyID();
|
VerifyID();
|
||||||
uint32 sz = (uint32)(id.size() + session->uuid.size() + method.size() + 3 + 16);
|
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 ¶ms = document["params"];
|
||||||
for(int i = 0; i < 3; ++i) {
|
auto ¶m = params[(rapidjson::SizeType)0];
|
||||||
auto ¶m = params[i];
|
pack->WriteUInt32((uint32)strlen(param.GetString()));
|
||||||
if(param.IsNull()) {
|
pack->WriteString(param.GetString());
|
||||||
sz += 5;
|
|
||||||
} else {
|
param = params[1];
|
||||||
sz += (uint32)strlen(param.GetString());
|
pack->WriteUInt32((uint32)strlen(param.GetString()));
|
||||||
sz += 5;
|
pack->WriteString(param.GetString());
|
||||||
}
|
|
||||||
}
|
param = params[2];
|
||||||
|
pack->WriteUInt32((uint32)strlen(param.GetString()));
|
||||||
|
pack->WriteString(param.GetString());
|
||||||
|
worldserver->SendPacket(pack);
|
||||||
|
safe_delete(pack);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,6 +40,21 @@
|
|||||||
id = document["id"].GetString(); \
|
id = document["id"].GetString(); \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
|
#define CalculateSize() uint32 sz = (uint32)(id.size() + session->uuid.size() + method.size() + 3 + 16); \
|
||||||
|
if(document.HasMember("params")) { \
|
||||||
|
auto ¶ms = document["params"]; \
|
||||||
|
uint32 p_sz = (uint32)params.Size(); \
|
||||||
|
for(uint32 i = 0; i < p_sz; ++i) { \
|
||||||
|
auto ¶m = params[i]; \
|
||||||
|
if(param.IsNull()) { \
|
||||||
|
sz += 5; \
|
||||||
|
} \
|
||||||
|
else { \
|
||||||
|
sz += (uint32)strlen(param.GetString()); \
|
||||||
|
sz += 5; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
|
||||||
void register_methods();
|
void register_methods();
|
||||||
void handle_method_token_auth(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method);
|
void handle_method_token_auth(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method);
|
||||||
|
|||||||
@ -98,13 +98,7 @@ void WorldServer::Process(){
|
|||||||
writer.Bool(true);
|
writer.Bool(true);
|
||||||
|
|
||||||
writer.String("result");
|
writer.String("result");
|
||||||
writer.StartArray();
|
writer.String(error);
|
||||||
if(params.size() > 0) {
|
|
||||||
writer.String(params[0].c_str());
|
|
||||||
} else {
|
|
||||||
writer.String("");
|
|
||||||
}
|
|
||||||
writer.EndArray();
|
|
||||||
} else {
|
} else {
|
||||||
writer.String("error");
|
writer.String("error");
|
||||||
writer.Null();
|
writer.Null();
|
||||||
|
|||||||
@ -17,10 +17,10 @@ extern WebInterfaceConnection WILink;
|
|||||||
std::map<std::string, RemoteCallHandler> remote_call_methods;
|
std::map<std::string, RemoteCallHandler> remote_call_methods;
|
||||||
|
|
||||||
void RemoteCallResponse(const std::string &connection_id, const std::string &request_id, const std::vector<std::string> &res, const std::string &error) {
|
void RemoteCallResponse(const std::string &connection_id, const std::string &request_id, const std::vector<std::string> &res, const std::string &error) {
|
||||||
uint32 sz = connection_id.size() + request_id.size() + error.size() + 3 + 16;
|
uint32 sz = (uint32)(connection_id.size() + request_id.size() + error.size() + 3 + 16);
|
||||||
uint32 res_sz = res.size();
|
uint32 res_sz = (uint32)res.size();
|
||||||
for(uint32 i = 0; i < res_sz; ++i) {
|
for(uint32 i = 0; i < res_sz; ++i) {
|
||||||
sz += res[i].size() + 5;
|
sz += (uint32)res[i].size() + 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCallResponse, sz);
|
ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCallResponse, sz);
|
||||||
@ -43,6 +43,7 @@ void RemoteCallResponse(const std::string &connection_id, const std::string &req
|
|||||||
void register_remote_call_handlers() {
|
void register_remote_call_handlers() {
|
||||||
remote_call_methods["list_zones"] = handle_rc_list_zones;
|
remote_call_methods["list_zones"] = handle_rc_list_zones;
|
||||||
remote_call_methods["get_zone_info"] = handle_rc_get_zone_info;
|
remote_call_methods["get_zone_info"] = handle_rc_get_zone_info;
|
||||||
|
remote_call_methods["subscribe"] = handle_rc_relay;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_rc_list_zones(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> ¶ms) {
|
void handle_rc_list_zones(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> ¶ms) {
|
||||||
@ -86,3 +87,64 @@ void handle_rc_get_zone_info(const std::string &method, const std::string &conne
|
|||||||
res.push_back(itoa(zs->NumPlayers()));
|
res.push_back(itoa(zs->NumPlayers()));
|
||||||
RemoteCallResponse(connection_id, request_id, res, error);
|
RemoteCallResponse(connection_id, request_id, res, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handle_rc_relay(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> ¶ms) {
|
||||||
|
std::string error;
|
||||||
|
std::vector<std::string> res;
|
||||||
|
uint32 zone_id = 0;
|
||||||
|
uint32 instance_id = 0;
|
||||||
|
ZoneServer *zs = nullptr;
|
||||||
|
|
||||||
|
if(params.size() < 2) {
|
||||||
|
error = "Missing zone relay params";
|
||||||
|
RemoteCallResponse(connection_id, request_id, res, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
zone_id = (uint32)atoi(params[0].c_str());
|
||||||
|
instance_id = (uint32)atoi(params[1].c_str());
|
||||||
|
if(!zone_id && !instance_id) {
|
||||||
|
error = "Zone not booted";
|
||||||
|
RemoteCallResponse(connection_id, request_id, res, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(instance_id) {
|
||||||
|
zs = zoneserver_list.FindByInstanceID(instance_id);
|
||||||
|
} else {
|
||||||
|
zs = zoneserver_list.FindByZoneID(zone_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!zs) {
|
||||||
|
error = "Zone server not found";
|
||||||
|
RemoteCallResponse(connection_id, request_id, res, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32 sz = (uint32)(request_id.size() + connection_id.size() + method.size() + 3 + 16);
|
||||||
|
uint32 p_sz = (uint32)params.size() - 2;
|
||||||
|
for(uint32 i = 0; i < p_sz; ++i) {
|
||||||
|
auto ¶m = params[i + 2];
|
||||||
|
sz += (uint32)param.size();
|
||||||
|
sz += 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCall, sz);
|
||||||
|
pack->WriteUInt32((uint32)request_id.size());
|
||||||
|
pack->WriteString(request_id.c_str());
|
||||||
|
pack->WriteUInt32((uint32)connection_id.size());
|
||||||
|
pack->WriteString(connection_id.c_str());
|
||||||
|
pack->WriteUInt32((uint32)method.size());
|
||||||
|
pack->WriteString(method.c_str());
|
||||||
|
pack->WriteUInt32(p_sz);
|
||||||
|
|
||||||
|
for(uint32 i = 0; i < p_sz; ++i) {
|
||||||
|
auto ¶m = params[i + 2];
|
||||||
|
pack->WriteUInt32((uint32)param.size());
|
||||||
|
pack->WriteString(param.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
zs->SendPacket(pack);
|
||||||
|
safe_delete(pack);
|
||||||
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ void RemoteCallResponse(const std::string &connection_id, const std::string &req
|
|||||||
void register_remote_call_handlers();
|
void register_remote_call_handlers();
|
||||||
void handle_rc_list_zones(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> ¶ms);
|
void handle_rc_list_zones(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> ¶ms);
|
||||||
void handle_rc_get_zone_info(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> ¶ms);
|
void handle_rc_get_zone_info(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> ¶ms);
|
||||||
|
void handle_rc_relay(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> ¶ms);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -1812,6 +1812,10 @@ void WorldServer::Process() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ServerOP_WIRemoteCall:
|
||||||
|
printf("Recv remote call from WI but atm doing anything with it is not yet implemented (BUT SOON)\n");
|
||||||
|
DumpPacket(pack);
|
||||||
|
break;
|
||||||
default: {
|
default: {
|
||||||
std::cout << " Unknown ZSopcode:" << (int)pack->opcode;
|
std::cout << " Unknown ZSopcode:" << (int)pack->opcode;
|
||||||
std::cout << " size:" << pack->size << std::endl;
|
std::cout << " size:" << pack->size << std::endl;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user