mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-22 07:28:32 +00:00
More work on getting remote calls up and running, added two remote calls list_zones and get_zone_info.
This commit is contained in:
@@ -23,6 +23,7 @@ SET(world_sources
|
||||
perl_EQW.cpp
|
||||
perl_HTTPRequest.cpp
|
||||
queryserv.cpp
|
||||
remote_call.cpp
|
||||
ucs.cpp
|
||||
web_interface.cpp
|
||||
wguild_mgr.cpp
|
||||
@@ -54,6 +55,7 @@ SET(world_headers
|
||||
LoginServerList.h
|
||||
net.h
|
||||
queryserv.h
|
||||
remote_call.h
|
||||
SoFCharCreateData.h
|
||||
ucs.h
|
||||
web_interface.h
|
||||
|
||||
+2
-1
@@ -87,6 +87,7 @@
|
||||
#include "ucs.h"
|
||||
#include "queryserv.h"
|
||||
#include "web_interface.h"
|
||||
#include "remote_call.h"
|
||||
|
||||
TimeoutManager timeout_manager;
|
||||
EQStreamFactory eqsf(WorldStream,9000);
|
||||
@@ -107,7 +108,6 @@ uint32 numclients = 0;
|
||||
uint32 numzones = 0;
|
||||
bool holdzones = false;
|
||||
|
||||
|
||||
extern ConsoleList console_list;
|
||||
|
||||
void CatchSignal(int sig_num);
|
||||
@@ -115,6 +115,7 @@ void CatchSignal(int sig_num);
|
||||
int main(int argc, char** argv) {
|
||||
RegisterExecutablePlatform(ExePlatformWorld);
|
||||
set_exception_handler();
|
||||
register_remote_call_handlers();
|
||||
|
||||
// Load server configuration
|
||||
_log(WORLD__INIT, "Loading server configuration..");
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
#include "../common/debug.h"
|
||||
#include "../common/logsys.h"
|
||||
#include "../common/logtypes.h"
|
||||
#include "../common/md5.h"
|
||||
#include "../common/EmuTCPConnection.h"
|
||||
#include "../common/packet_dump.h"
|
||||
#include "WorldConfig.h"
|
||||
#include "clientlist.h"
|
||||
#include "zonelist.h"
|
||||
#include "web_interface.h"
|
||||
#include "remote_call.h"
|
||||
#include "zoneserver.h"
|
||||
|
||||
extern ClientList client_list;
|
||||
extern ZSList zoneserver_list;
|
||||
extern WebInterfaceConnection WILink;
|
||||
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) {
|
||||
uint32 sz = connection_id.size() + request_id.size() + error.size() + 3 + 16;
|
||||
uint32 res_sz = res.size();
|
||||
for(uint32 i = 0; i < res_sz; ++i) {
|
||||
sz += res[i].size() + 5;
|
||||
}
|
||||
|
||||
ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCallResponse, 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)error.size());
|
||||
pack->WriteString(error.c_str());
|
||||
pack->WriteUInt32((uint32)res_sz);
|
||||
for (uint32 i = 0; i < res_sz; ++i) {
|
||||
auto &r = res[i];
|
||||
pack->WriteUInt32((uint32)r.size());
|
||||
pack->WriteString(r.c_str());
|
||||
}
|
||||
|
||||
WILink.SendPacket(pack);
|
||||
}
|
||||
|
||||
void register_remote_call_handlers() {
|
||||
remote_call_methods["list_zones"] = handle_rc_list_zones;
|
||||
remote_call_methods["get_zone_info"] = handle_rc_get_zone_info;
|
||||
}
|
||||
|
||||
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) {
|
||||
std::vector<uint32> zones;
|
||||
zoneserver_list.GetZoneIDList(zones);
|
||||
|
||||
std::vector<std::string> res;
|
||||
uint32 sz = (uint32)zones.size();
|
||||
for(uint32 i = 0; i < sz; ++i) {
|
||||
res.push_back(itoa(zones[i]));
|
||||
}
|
||||
|
||||
std::string error;
|
||||
RemoteCallResponse(connection_id, request_id, res, error);
|
||||
}
|
||||
|
||||
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) {
|
||||
std::string error;
|
||||
std::vector<std::string> res;
|
||||
if(params.size() != 1) {
|
||||
error = "Expected only one zone_id.";
|
||||
RemoteCallResponse(connection_id, request_id, res, error);
|
||||
return;
|
||||
}
|
||||
|
||||
ZoneServer *zs = zoneserver_list.FindByID(atoi(params[0].c_str()));
|
||||
if(zs == nullptr) {
|
||||
error = "Invalid zone";
|
||||
RemoteCallResponse(connection_id, request_id, res, error);
|
||||
return;
|
||||
}
|
||||
|
||||
res.push_back(zs->IsStaticZone() ? "static" : "dynamic");
|
||||
res.push_back(itoa(zs->GetZoneID()));
|
||||
res.push_back(itoa(zs->GetInstanceID()));
|
||||
res.push_back(zs->GetLaunchName());
|
||||
res.push_back(zs->GetLaunchedName());
|
||||
res.push_back(zs->GetZoneName());
|
||||
res.push_back(zs->GetZoneLongName());
|
||||
res.push_back(itoa(zs->GetCPort()));
|
||||
res.push_back(itoa(zs->NumPlayers()));
|
||||
RemoteCallResponse(connection_id, request_id, res, error);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2014 EQEMu Development Team (http://eqemulator.net)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
are required to give you total support for your newly bought product;
|
||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef WORLD_REMOTE_CALL_H
|
||||
#define WORLD_REMOTE_CALL_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
typedef void(*RemoteCallHandler)(const std::string&, const std::string&, const std::string&, const std::vector<std::string>&);
|
||||
|
||||
void RemoteCallResponse(const std::string &connection_id, const std::string &request_id, const std::vector<std::string> &res, const std::string &error);
|
||||
|
||||
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_get_zone_info(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> ¶ms);
|
||||
|
||||
#endif
|
||||
|
||||
+33
-11
@@ -3,6 +3,7 @@
|
||||
#include "WorldConfig.h"
|
||||
#include "clientlist.h"
|
||||
#include "zonelist.h"
|
||||
#include "remote_call.h"
|
||||
#include "../common/logsys.h"
|
||||
#include "../common/logtypes.h"
|
||||
#include "../common/md5.h"
|
||||
@@ -11,6 +12,7 @@
|
||||
|
||||
extern ClientList client_list;
|
||||
extern ZSList zoneserver_list;
|
||||
extern std::map<std::string, RemoteCallHandler> remote_call_methods;
|
||||
|
||||
WebInterfaceConnection::WebInterfaceConnection()
|
||||
{
|
||||
@@ -99,18 +101,38 @@ bool WebInterfaceConnection::Process()
|
||||
_log(WEB_INTERFACE__ERROR, "Got authentication from WebInterface when they are already authenticated.");
|
||||
break;
|
||||
}
|
||||
case ServerOP_WIServGeneric:
|
||||
case ServerOP_WIRemoteCall:
|
||||
{
|
||||
zoneserver_list.SendPacket(pack); // Send to all zones to test
|
||||
break;
|
||||
}
|
||||
case ServerOP_WIClientRequest:
|
||||
{
|
||||
std::string Data;
|
||||
WI_Client_Request_Struct* WICR = (WI_Client_Request_Struct*)pack->pBuffer;
|
||||
Data.assign(WICR->JSON_Data, pack->size - 64);
|
||||
_log(WEB_INTERFACE__ERROR, "Recieved ServerOPcode from WebInterface 0x%04x \nSize %d\nData '%s' from client:\n%s\n", pack->opcode, pack->size, Data.c_str(), WICR->Client_UUID);
|
||||
zoneserver_list.SendPacket(pack); // Send to all zones to test
|
||||
char *id = nullptr;
|
||||
char *session_id = nullptr;
|
||||
char *method = nullptr;
|
||||
|
||||
id = new char[pack->ReadUInt32() + 1];
|
||||
pack->ReadString(id);
|
||||
|
||||
session_id = new char[pack->ReadUInt32() + 1];
|
||||
pack->ReadString(session_id);
|
||||
|
||||
method = new char[pack->ReadUInt32() + 1];
|
||||
pack->ReadString(method);
|
||||
|
||||
uint32 param_count = pack->ReadUInt32();
|
||||
std::vector<std::string> params;
|
||||
for(uint32 i = 0; i < param_count; ++i) {
|
||||
char *p = new char[pack->ReadUInt32() + 1];
|
||||
pack->ReadString(p);
|
||||
params.push_back(p);
|
||||
safe_delete_array(p);
|
||||
}
|
||||
|
||||
if (remote_call_methods.count(method) != 0) {
|
||||
auto f = remote_call_methods[method];
|
||||
f(method, session_id, id, params);
|
||||
}
|
||||
|
||||
safe_delete_array(id);
|
||||
safe_delete_array(session_id);
|
||||
safe_delete_array(method);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -1303,10 +1303,6 @@ bool ZoneServer::Process() {
|
||||
case ServerOP_CZSignalClientByName:
|
||||
case ServerOP_CZMessagePlayer:
|
||||
case ServerOP_CZSignalClient:
|
||||
{
|
||||
zoneserver_list.SendPacket(pack);
|
||||
break;
|
||||
}
|
||||
case ServerOP_DepopAllPlayersCorpses:
|
||||
case ServerOP_DepopPlayerCorpse:
|
||||
case ServerOP_ReloadTitles:
|
||||
@@ -1318,12 +1314,6 @@ bool ZoneServer::Process() {
|
||||
zoneserver_list.SendPacket(pack);
|
||||
break;
|
||||
}
|
||||
case ServerOP_WIWorldResponse:
|
||||
{
|
||||
_log(WEB_INTERFACE__ERROR, "ServerOP_WIWorldResponse for WebInterface 0x%04x, size %d", pack->opcode, pack->size);
|
||||
WILink.SendPacket(pack);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
zlog(WORLD__ZONE_ERR,"Unknown ServerOPcode from zone 0x%04x, size %d",pack->opcode,pack->size);
|
||||
|
||||
Reference in New Issue
Block a user