From 28325467da1036ffb0fb17d25b97751a9854f192 Mon Sep 17 00:00:00 2001 From: KimLS Date: Fri, 13 Jan 2017 23:46:20 -0800 Subject: [PATCH] Add client and zone subscriptions --- wi/test.js | 3 +- wi/ws/eqw.js | 3 +- wi/ws/wi_common.js | 6 +-- world/cliententry.cpp | 12 ++++++ world/clientlist.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++- world/clientlist.h | 5 ++- world/zonelist.cpp | 2 +- 7 files changed, 110 insertions(+), 8 deletions(-) diff --git a/wi/test.js b/wi/test.js index 2637ddb37..1ddca8cbf 100644 --- a/wi/test.js +++ b/wi/test.js @@ -2,7 +2,8 @@ const WebSocket = require('ws'); const ws = new WebSocket('ws://localhost:9080'); ws.on('open', function open() { - ws.send(JSON.stringify({authorization: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IktTcHJpdGUxIiwiZXhwIjoxNDg0NzIzNDQxLCJpYXQiOjE0ODQxMTg2NDF9.Lmwm572yMWIu1DUrfer8JVvl1DGEkdnMsMFp5WDzp_A', id: '1', method: 'EQW::Subscribe::WorldZoneUpdate', params: []})); + //ws.send(JSON.stringify({authorization: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IktTcHJpdGUxIiwiZXhwIjoxNDg0NzIzNDQxLCJpYXQiOjE0ODQxMTg2NDF9.Lmwm572yMWIu1DUrfer8JVvl1DGEkdnMsMFp5WDzp_A', method: 'EQW::ZoneUpdate::Subscribe'})); + ws.send(JSON.stringify({authorization: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IktTcHJpdGUxIiwiZXhwIjoxNDg0NzIzNDQxLCJpYXQiOjE0ODQxMTg2NDF9.Lmwm572yMWIu1DUrfer8JVvl1DGEkdnMsMFp5WDzp_A', method: 'EQW::ClientUpdate::Subscribe'})); }); ws.on('message', function(data, flags) { diff --git a/wi/ws/eqw.js b/wi/ws/eqw.js index 15fc5a62c..00f9040d4 100644 --- a/wi/ws/eqw.js +++ b/wi/ws/eqw.js @@ -4,7 +4,8 @@ var RegisterEQW = function(wsi, api) { common.Register('EQW::IsLocked', wsi, api); common.Register('EQW::Lock', wsi, api); common.Register('EQW::Unlock', wsi, api); - common.RegisterSubscription('EQW', 'WorldZoneUpdate', wsi, api); + common.RegisterSubscription('EQW::ZoneUpdate', wsi, api); + common.RegisterSubscription('EQW::ClientUpdate', wsi, api); }; module.exports = { diff --git a/wi/ws/wi_common.js b/wi/ws/wi_common.js index e9eb6577f..a823e7431 100644 --- a/wi/ws/wi_common.js +++ b/wi/ws/wi_common.js @@ -11,12 +11,12 @@ function Register(name, wsi, api) { }, true); } -function RegisterSubscription(namespace, event, wsi, api) { - wsi.Register(namespace + '::Subscribe::' + event, function(request) { +function RegisterSubscription(event, wsi, api) { + wsi.Register(event + '::Subscribe', function(request) { api.Subscribe(event, request.ws); }); - wsi.Register(namespace + '::Unsubscribe::' + event, function(request) { + wsi.Register(event + '::Unsubscribe', function(request) { api.Unsubscribe(event, request.ws); }); } diff --git a/world/cliententry.cpp b/world/cliententry.cpp index 68042acd6..3caa08ad7 100644 --- a/world/cliententry.cpp +++ b/world/cliententry.cpp @@ -46,6 +46,10 @@ ClientListEntry::ClientListEntry(uint32 in_id, uint32 iLSID, const char* iLoginN plocal=(local==1); pinstance = 0; + pLFGFromLevel = 0; + pLFGToLevel = 0; + pLFGMatchFilter = false; + memset(pLFGComments, 0, 64); } ClientListEntry::ClientListEntry(uint32 in_id, uint32 iAccID, const char* iAccName, MD5& iMD5Pass, int16 iAdmin) @@ -63,6 +67,10 @@ ClientListEntry::ClientListEntry(uint32 in_id, uint32 iAccID, const char* iAccNa padmin = iAdmin; pinstance = 0; + pLFGFromLevel = 0; + pLFGToLevel = 0; + pLFGMatchFilter = false; + memset(pLFGComments, 0, 64); } ClientListEntry::ClientListEntry(uint32 in_id, ZoneServer* iZS, ServerClientList_Struct* scl, int8 iOnline) @@ -81,6 +89,10 @@ ClientListEntry::ClientListEntry(uint32 in_id, ZoneServer* iZS, ServerClientList padmin = scl->Admin; pinstance = 0; + pLFGFromLevel = 0; + pLFGToLevel = 0; + pLFGMatchFilter = false; + memset(pLFGComments, 0, 64); if (iOnline >= CLE_Status_Zoning) Update(iZS, scl, iOnline); diff --git a/world/clientlist.cpp b/world/clientlist.cpp index cc246a5d7..0c45a11bf 100644 --- a/world/clientlist.cpp +++ b/world/clientlist.cpp @@ -29,10 +29,13 @@ #include "../common/packet_dump.h" #include "../common/misc.h" #include "../common/misc_functions.h" +#include "../common/json/json.h" +#include "web_interface.h" #include "wguild_mgr.h" - #include +extern WebInterfaceList web_interface; + extern ZSList zoneserver_list; uint32 numplayers = 0; //this really wants to be a member variable of ClientList... @@ -40,6 +43,8 @@ ClientList::ClientList() : CLStale_timer(45000) { NextCLEID = 1; + + m_tick.reset(new EQ::Timer(1000, true, std::bind(&ClientList::OnTick, this, std::placeholders::_1))); } ClientList::~ClientList() { @@ -1358,3 +1363,83 @@ void ClientList::SendClientVersionSummary(const char *Name) ClientTitaniumCount, ClientSoFCount, ClientSoDCount, ClientUnderfootCount, ClientRoFCount, ClientRoF2Count); } +void ClientList::OnTick(EQ::Timer *t) +{ + Json::Value out; + out["event"] = "EQW::ClientUpdate"; + out["data"] = Json::Value(); + + LinkedListIterator Iterator(clientlist); + + Iterator.Reset(); + + while (Iterator.MoreElements()) + { + ClientListEntry* cle = Iterator.GetData(); + + Json::Value outclient; + + outclient["Online"] = cle->Online(); + outclient["ID"] = cle->GetID(); + outclient["IP"] = cle->GetIP(); + outclient["LSID"] = cle->LSID(); + outclient["LSAccountID"] = cle->LSAccountID(); + outclient["LSName"] = cle->LSName(); + outclient["WorldAdmin"] = cle->WorldAdmin(); + + outclient["AccountID"] = cle->AccountID(); + outclient["AccountName"] = cle->AccountName(); + outclient["Admin"] = cle->Admin(); + + auto server = cle->Server(); + if (server) { + outclient["Server"]["CAddress"] = server->GetCAddress(); + outclient["Server"]["CLocalAddress"] = server->GetCLocalAddress(); + outclient["Server"]["CompileTime"] = server->GetCompileTime(); + outclient["Server"]["CPort"] = server->GetCPort(); + outclient["Server"]["ID"] = server->GetID(); + outclient["Server"]["InstanceID"] = server->GetInstanceID(); + outclient["Server"]["IP"] = server->GetIP(); + outclient["Server"]["LaunchedName"] = server->GetLaunchedName(); + outclient["Server"]["LaunchName"] = server->GetLaunchName(); + outclient["Server"]["Port"] = server->GetPort(); + outclient["Server"]["PrevZoneID"] = server->GetPrevZoneID(); + outclient["Server"]["UUID"] = server->GetUUID(); + outclient["Server"]["ZoneID"] = server->GetZoneID(); + outclient["Server"]["ZoneLongName"] = server->GetZoneLongName(); + outclient["Server"]["ZoneName"] = server->GetZoneName(); + outclient["Server"]["ZoneOSProcessID"] = server->GetZoneOSProcessID(); + outclient["Server"]["NumPlayers"] = server->NumPlayers(); + outclient["Server"]["BootingUp"] = server->IsBootingUp(); + outclient["Server"]["StaticZone"] = server->IsStaticZone(); + } + else { + outclient["Server"] = Json::Value(); + } + + outclient["CharID"] = cle->CharID(); + outclient["name"] = cle->name(); + outclient["zone"] = cle->zone(); + outclient["instance"] = cle->instance(); + outclient["level"] = cle->level(); + outclient["class_"] = cle->class_(); + outclient["race"] = cle->race(); + outclient["Anon"] = cle->Anon(); + + outclient["TellsOff"] = cle->TellsOff(); + outclient["GuildID"] = cle->GuildID(); + outclient["LFG"] = cle->LFG(); + outclient["GM"] = cle->GetGM(); + outclient["LocalClient"] = cle->IsLocalClient(); + outclient["LFGFromLevel"] = cle->GetLFGFromLevel(); + outclient["LFGToLevel"] = cle->GetLFGToLevel(); + outclient["LFGMatchFilter"] = cle->GetLFGMatchFilter(); + outclient["LFGComments"] = cle->GetLFGComments(); + outclient["ClientVersion"] = cle->GetClientVersion(); + out["data"].append(outclient); + + Iterator.Advance(); + } + + web_interface.SendEvent(out); +} \ No newline at end of file diff --git a/world/clientlist.h b/world/clientlist.h index 1d5fc6ab8..b6ef3fc73 100644 --- a/world/clientlist.h +++ b/world/clientlist.h @@ -6,6 +6,7 @@ #include "../common/timer.h" #include "../common/rulesys.h" #include "../common/servertalk.h" +#include "../common/event/timer.h" #include #include @@ -66,7 +67,8 @@ public: int GetClientCount(); void GetClients(const char *zone_name, std::vector &into); -protected: +private: + void OnTick(EQ::Timer *t); inline uint32 GetNextCLEID() { return NextCLEID++; } //this is the list of people actively connected to zone @@ -77,6 +79,7 @@ protected: uint32 NextCLEID; LinkedList clientlist; + std::unique_ptr m_tick; }; #endif /*CLIENTLIST_H_*/ diff --git a/world/zonelist.cpp b/world/zonelist.cpp index 1dc6a5636..d134e0a8e 100644 --- a/world/zonelist.cpp +++ b/world/zonelist.cpp @@ -699,7 +699,7 @@ void ZSList::WorldShutDown(uint32 time, uint32 interval) void ZSList::OnTick(EQ::Timer *t) { Json::Value out; - out["event"] = "WorldZoneUpdate"; + out["event"] = "EQW::ZoneUpdate"; out["data"] = Json::Value(); for (auto &zone : list)