Basic work on subscriptions

This commit is contained in:
KimLS
2017-01-13 21:52:08 -08:00
parent f24770489e
commit 1cafd6831d
12 changed files with 196 additions and 42 deletions
+21
View File
@@ -105,6 +105,21 @@ void WebInterface::SendError(const std::string &message, const std::string &id)
Send(error);
}
void WebInterface::SendEvent(const Json::Value &value)
{
try {
std::stringstream ss;
ss << value;
EQ::Net::DynamicPacket p;
p.PutString(0, ss.str());
m_connection->Send(ServerOP_WebInterfaceEvent, p);
}
catch (std::exception) {
//Log error
}
}
void WebInterface::AddCall(const std::string &method, WebInterfaceCall call)
{
m_calls.insert(std::make_pair(method, call));
@@ -149,6 +164,12 @@ void WebInterfaceList::SendResponse(const std::string &uuid, std::string &id, co
}
}
void WebInterfaceList::SendEvent(const Json::Value &value) {
for (auto &i : m_interfaces) {
i.second->SendEvent(value);
}
}
void WebInterfaceList::SendError(const std::string &uuid, const std::string &message) {
auto iter = m_interfaces.find(uuid);
if (iter != m_interfaces.end()) {
+2
View File
@@ -19,6 +19,7 @@ public:
void SendResponse(const std::string &id, const Json::Value &response);
void SendError(const std::string &message);
void SendError(const std::string &message, const std::string &id);
void SendEvent(const Json::Value &value);
void AddCall(const std::string &method, WebInterfaceCall call);
private:
void OnCall(uint16 opcode, EQ::Net::Packet &p);
@@ -37,6 +38,7 @@ public:
void AddConnection(std::shared_ptr<EQ::Net::ServertalkServerConnection> connection);
void RemoveConnection(std::shared_ptr<EQ::Net::ServertalkServerConnection> connection);
void SendResponse(const std::string &uuid, std::string &id, const Json::Value &response);
void SendEvent(const Json::Value &value);
void SendError(const std::string &uuid, const std::string &message);
void SendError(const std::string &uuid, const std::string &message, const std::string &id);
+41
View File
@@ -24,10 +24,13 @@
#include "../common/servertalk.h"
#include "../common/string_util.h"
#include "../common/random.h"
#include "../common/json/json.h"
#include "web_interface.h"
extern uint32 numzones;
extern bool holdzones;
extern EQEmu::Random emu_random;
extern WebInterfaceList web_interface;
void CatchSignal(int sig_num);
ZSList::ZSList()
@@ -36,6 +39,8 @@ ZSList::ZSList()
CurGroupID = 1;
LastAllocatedPort=0;
memset(pLockedZones, 0, sizeof(pLockedZones));
m_tick.reset(new EQ::Timer(1000, true, std::bind(&ZSList::OnTick, this, std::placeholders::_1)));
}
ZSList::~ZSList() {
@@ -690,3 +695,39 @@ void ZSList::WorldShutDown(uint32 time, uint32 interval)
CatchSignal(2);
}
}
void ZSList::OnTick(EQ::Timer *t)
{
Json::Value out;
out["event"] = "WorldZoneUpdate";
out["data"] = Json::Value();
for (auto &zone : list)
{
Json::Value outzone;
outzone["CAddress"] = zone->GetCAddress();
outzone["CLocalAddress"] = zone->GetCLocalAddress();
outzone["CompileTime"] = zone->GetCompileTime();
outzone["CPort"] = zone->GetCPort();
outzone["ID"] = zone->GetID();
outzone["InstanceID"] = zone->GetInstanceID();
outzone["IP"] = zone->GetIP();
outzone["LaunchedName"] = zone->GetLaunchedName();
outzone["LaunchName"] = zone->GetLaunchName();
outzone["Port"] = zone->GetPort();
outzone["PrevZoneID"] = zone->GetPrevZoneID();
outzone["UUID"] = zone->GetUUID();
outzone["ZoneID"] = zone->GetZoneID();
outzone["ZoneLongName"] = zone->GetZoneLongName();
outzone["ZoneName"] = zone->GetZoneName();
outzone["ZoneOSProcessID"] = zone->GetZoneOSProcessID();
outzone["NumPlayers"] = zone->NumPlayers();
outzone["BootingUp"] = zone->IsBootingUp();
outzone["StaticZone"] = zone->IsStaticZone();
out["data"].append(outzone);
}
web_interface.SendEvent(out);
}
+4 -3
View File
@@ -4,7 +4,7 @@
#include "../common/types.h"
#include "../common/eqtime.h"
#include "../common/timer.h"
#include "../common/linked_list.h"
#include "../common/event/timer.h"
#include <vector>
#include <memory>
@@ -60,14 +60,15 @@ public:
void GetZoneIDList(std::vector<uint32> &zones);
void WorldShutDown(uint32 time, uint32 interval);
protected:
private:
void OnTick(EQ::Timer *t);
uint32 NextID;
std::list<std::unique_ptr<ZoneServer>> list;
uint16 pLockedZones[MaxLockedZones];
uint32 CurGroupID;
uint16 LastAllocatedPort;
std::unique_ptr<EQ::Timer> m_tick;
};
#endif /*ZONELIST_H_*/