Will be redoing the event interface for subscriptions, some work for the wi and crash fixes

This commit is contained in:
KimLS
2017-01-30 23:22:52 -08:00
parent a8699eb40c
commit d5bd773a46
17 changed files with 205 additions and 98 deletions
+5
View File
@@ -30,6 +30,7 @@
#include "../common/misc.h"
#include "../common/misc_functions.h"
#include "../common/json/json.h"
#include "../common/event_sub.h"
#include "web_interface.h"
#include "wguild_mgr.h"
#include <set>
@@ -1365,6 +1366,10 @@ void ClientList::SendClientVersionSummary(const char *Name)
void ClientList::OnTick(EQ::Timer *t)
{
if (!EventSubscriptionWatcher::Get()->IsSubscribed("EQW::ClientUpdate")) {
return;
}
Json::Value out;
out["event"] = "EQW::ClientUpdate";
out["data"] = Json::Value();
+33 -56
View File
@@ -52,112 +52,89 @@ LoginServerList::~LoginServerList() {
void LoginServerList::Add(const char* iAddress, uint16 iPort, const char* Account, const char* Password, bool Legacy)
{
auto loginserver = new LoginServer(iAddress, iPort, Account, Password, Legacy);
list.Insert(loginserver);
m_list.push_back(std::unique_ptr<LoginServer>(loginserver));
}
bool LoginServerList::SendInfo() {
LinkedListIterator<LoginServer*> iterator(list);
iterator.Reset();
while(iterator.MoreElements()){
iterator.GetData()->SendInfo();
iterator.Advance();
for (auto &iter : m_list) {
(*iter).SendInfo();
}
return true;
}
bool LoginServerList::SendNewInfo() {
LinkedListIterator<LoginServer*> iterator(list);
iterator.Reset();
while(iterator.MoreElements()){
iterator.GetData()->SendNewInfo();
iterator.Advance();
for (auto &iter : m_list) {
(*iter).SendNewInfo();
}
return true;
}
bool LoginServerList::SendStatus() {
LinkedListIterator<LoginServer*> iterator(list);
iterator.Reset();
while(iterator.MoreElements()){
iterator.GetData()->SendStatus();
iterator.Advance();
for (auto &iter : m_list) {
(*iter).SendStatus();
}
return true;
}
bool LoginServerList::SendPacket(ServerPacket* pack) {
LinkedListIterator<LoginServer*> iterator(list);
iterator.Reset();
while(iterator.MoreElements()){
iterator.GetData()->SendPacket(pack);
iterator.Advance();
for (auto &iter : m_list) {
(*iter).SendPacket(pack);
}
return true;
}
bool LoginServerList::SendAccountUpdate(ServerPacket* pack) {
LinkedListIterator<LoginServer*> iterator(list);
Log.Out(Logs::Detail, Logs::World_Server, "Requested to send ServerOP_LSAccountUpdate packet to all loginservers");
iterator.Reset();
while(iterator.MoreElements()){
if(iterator.GetData()->CanUpdate()) {
iterator.GetData()->SendAccountUpdate(pack);
for (auto &iter : m_list) {
if ((*iter).CanUpdate()) {
(*iter).SendAccountUpdate(pack);
}
iterator.Advance();
}
return true;
}
bool LoginServerList::Connected() {
LinkedListIterator<LoginServer*> iterator(list);
iterator.Reset();
while(iterator.MoreElements()){
if(iterator.GetData()->Connected())
for (auto &iter : m_list) {
if ((*iter).Connected()) {
return true;
iterator.Advance();
}
}
return false;
}
bool LoginServerList::AllConnected() {
LinkedListIterator<LoginServer*> iterator(list);
iterator.Reset();
while(iterator.MoreElements()){
if(iterator.GetData()->Connected() == false)
for (auto &iter : m_list) {
if (!(*iter).Connected()) {
return false;
iterator.Advance();
}
}
return true;
}
bool LoginServerList::MiniLogin() {
LinkedListIterator<LoginServer*> iterator(list);
iterator.Reset();
while(iterator.MoreElements()){
if(iterator.GetData()->MiniLogin())
for (auto &iter : m_list) {
if ((*iter).MiniLogin()) {
return true;
iterator.Advance();
}
}
return false;
}
bool LoginServerList::CanUpdate() {
LinkedListIterator<LoginServer*> iterator(list);
iterator.Reset();
while(iterator.MoreElements()){
if(iterator.GetData()->CanUpdate())
for (auto &iter : m_list) {
if ((*iter).CanUpdate()) {
return true;
iterator.Advance();
}
}
return false;
}
+3 -2
View File
@@ -2,11 +2,11 @@
#define LOGINSERVERLIST_H_
#include "../common/servertalk.h"
#include "../common/linked_list.h"
#include "../common/timer.h"
#include "../common/queue.h"
#include "../common/eq_packet_structs.h"
#include "../common/mutex.h"
#include <list>
class LoginServer;
@@ -27,9 +27,10 @@ public:
bool AllConnected();
bool MiniLogin();
bool CanUpdate();
size_t GetServerCount() const { return m_list.size(); }
protected:
LinkedList<LoginServer*> list;
std::list<std::unique_ptr<LoginServer>> m_list;
};
+3 -1
View File
@@ -21,7 +21,9 @@ void UCSConnection::SetConnection(std::shared_ptr<EQ::Net::ServertalkServerConne
}
Stream = inStream;
Stream->OnMessage(std::bind(&UCSConnection::ProcessPacket, this, std::placeholders::_1, std::placeholders::_2));
if (Stream) {
Stream->OnMessage(std::bind(&UCSConnection::ProcessPacket, this, std::placeholders::_1, std::placeholders::_2));
}
}
void UCSConnection::ProcessPacket(uint16 opcode, EQ::Net::Packet &p)
+2 -1
View File
@@ -65,7 +65,7 @@ void WebInterface::OnCall(uint16 opcode, EQ::Net::Packet &p)
auto iter = m_calls.find(method);
if (iter == m_calls.end()) {
//if not exist then error
SendError("Invalid request: method not found");
SendError("Invalid request: method not found", id);
return;
}
@@ -99,6 +99,7 @@ void WebInterface::SendError(const std::string &message)
void WebInterface::SendError(const std::string &message, const std::string &id)
{
Json::Value error;
error["id"] = id;
error["error"] = Json::Value();
error["error"]["message"] = message;
+46
View File
@@ -2,8 +2,29 @@
#include "web_interface.h"
#include "world_config.h"
#include "login_server_list.h"
#include "clientlist.h"
#include "zonelist.h"
#include "launcher_list.h"
extern LoginServerList loginserverlist;
extern ClientList client_list;
extern ZSList zoneserver_list;
extern LauncherList launcher_list;
void EQW__GetConfig(WebInterface *i, const std::string& method, const std::string& id, const Json::Value& params) {
if (params.isArray() && params.size() == 1) {
auto config_name = params[0];
if (config_name.isString()) {
auto config = config_name.asString();
Json::Value ret = WorldConfig::get()->GetByName(config);
i->SendResponse(id, ret);
return;
}
}
i->SendError("EBADPARAMS", id);
}
void EQW__IsLocked(WebInterface *i, const std::string& method, const std::string& id, const Json::Value& params) {
Json::Value ret = WorldConfig::get()->Locked;
@@ -32,9 +53,34 @@ void EQW__Unlock(WebInterface *i, const std::string& method, const std::string&
i->SendResponse(id, ret);
}
void EQW__GetPlayerCount(WebInterface *i, const std::string& method, const std::string& id, const Json::Value& params) {
Json::Value ret = client_list.GetClientCount();
i->SendResponse(id, ret);
}
void EQW__GetZoneCount(WebInterface *i, const std::string& method, const std::string& id, const Json::Value& params) {
Json::Value ret = zoneserver_list.GetZoneCount();
i->SendResponse(id, ret);
}
void EQW__GetLauncherCount(WebInterface *i, const std::string& method, const std::string& id, const Json::Value& params) {
Json::Value ret = launcher_list.GetLauncherCount();
i->SendResponse(id, ret);
}
void EQW__GetLoginServerCount(WebInterface *i, const std::string& method, const std::string& id, const Json::Value& params) {
Json::Value ret = loginserverlist.GetServerCount();
i->SendResponse(id, ret);
}
void RegisterEQW(WebInterface *i)
{
i->AddCall("EQW::GetConfig", std::bind(EQW__GetConfig, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
i->AddCall("EQW::IsLocked", std::bind(EQW__IsLocked, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
i->AddCall("EQW::Lock", std::bind(EQW__Lock, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
i->AddCall("EQW::Unlock", std::bind(EQW__Unlock, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
i->AddCall("EQW::GetPlayerCount", std::bind(EQW__GetPlayerCount, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
i->AddCall("EQW::GetZoneCount", std::bind(EQW__GetZoneCount, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
i->AddCall("EQW::GetLauncherCount", std::bind(EQW__GetLauncherCount, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
i->AddCall("EQW::GetLoginServerCount", std::bind(EQW__GetLoginServerCount, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
}
+6 -1
View File
@@ -25,6 +25,7 @@
#include "../common/string_util.h"
#include "../common/random.h"
#include "../common/json/json.h"
#include "../common/event_sub.h"
#include "web_interface.h"
extern uint32 numzones;
@@ -657,7 +658,7 @@ void ZSList::SendLSZones(){
}
int ZSList::GetZoneCount() {
return(numzones);
return(list.size());
}
void ZSList::GetZoneIDList(std::vector<uint32> &zones) {
@@ -698,6 +699,10 @@ void ZSList::WorldShutDown(uint32 time, uint32 interval)
void ZSList::OnTick(EQ::Timer *t)
{
if (!EventSubscriptionWatcher::Get()->IsSubscribed("EQW::ZoneUpdate")) {
return;
}
Json::Value out;
out["event"] = "EQW::ZoneUpdate";
out["data"] = Json::Value();