mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-15 00:01:28 +00:00
More cleanup
This commit is contained in:
parent
40b555a55b
commit
ae30d8b257
50
web_interface/test/we.html
Normal file
50
web_interface/test/we.html
Normal file
@ -0,0 +1,50 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>WS</title>
|
||||
</head>
|
||||
<body>
|
||||
<span id="content"></span>
|
||||
</body>
|
||||
<script>
|
||||
function generateUUID() {
|
||||
var d = new Date().getTime();
|
||||
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = (d + Math.random()*16)%16 | 0;
|
||||
d = Math.floor(d/16);
|
||||
return (c=='x' ? r : (r&0x7|0x8)).toString(16);
|
||||
});
|
||||
return uuid;
|
||||
};
|
||||
|
||||
var socket = new WebSocket("ws://localhost:9888", "eqemu");
|
||||
socket.onopen = function(e) {
|
||||
var obj = {};
|
||||
obj.id = 'token_auth_id';
|
||||
obj.method = 'WebInterface::Authorize';
|
||||
obj.params = ['c5b80ec8-4174-4c4c-d332-dbf3c3a551fc'];
|
||||
socket.send(JSON.stringify(obj));
|
||||
};
|
||||
|
||||
socket.onmessage = function (event) {
|
||||
var obj = JSON.parse(event.data);
|
||||
console.log(obj);
|
||||
|
||||
if(obj.id == 'token_auth_id') {
|
||||
socket.send(JSON.stringify({id: 'list_zones_id', method: 'World::ListZones', params: []}));
|
||||
} else if(obj.id == 'list_zones_id') {
|
||||
for (var key in obj.result) {
|
||||
if(obj.result.hasOwnProperty(key)) {
|
||||
var str = JSON.stringify({id: 'get_zone_info_id', method: 'World::GetZoneDetails', params: [obj.result[key]]});
|
||||
console.log(str);
|
||||
socket.send(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(obj.id == 'get_zone_info_id') {
|
||||
socket.send(JSON.stringify({id: 'subscribe_id', method: 'Zone::Subscribe', params: [obj.result["zone_id"], obj.result["instance_id"], 'NPC::MakeSpawnUpdateNoDelta']}));
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</html>
|
||||
@ -90,7 +90,7 @@ void handle_rc_get_zone_info(const std::string &method, const std::string &conne
|
||||
res["short_name"] = zs->GetZoneName();
|
||||
res["long_name"] = zs->GetZoneLongName();
|
||||
res["port"] = itoa(zs->GetCPort());
|
||||
res["num_players"] = itoa(zs->NumPlayers());
|
||||
res["player_count"] = itoa(zs->NumPlayers());
|
||||
RemoteCallResponse(connection_id, request_id, res, error);
|
||||
}
|
||||
|
||||
|
||||
36
zone/mob.cpp
36
zone/mob.cpp
@ -1216,32 +1216,16 @@ void Mob::MakeSpawnUpdateNoDelta(PlayerPositionUpdateServer_Struct *spu){
|
||||
spu->padding0018 =0x5df27;
|
||||
|
||||
if(IsNPC()) {
|
||||
//zone_id
|
||||
//instance_id
|
||||
//entity_id
|
||||
//x
|
||||
//y
|
||||
//z
|
||||
//h
|
||||
const auto &conns = RemoteCallSubscriptionHandler::Instance()->GetSubscribers("NPC::MakeSpawnUpdateNoDelta");
|
||||
if(conns.size() > 0) {
|
||||
std::string method = "NPC::MakeSpawnUpdateNoDelta";
|
||||
std::vector<std::string> params;
|
||||
params.push_back(std::to_string((long)zone->GetZoneID()));
|
||||
params.push_back(std::to_string((long)zone->GetInstanceID()));
|
||||
params.push_back(std::to_string((long)GetID()));
|
||||
params.push_back(GetName());
|
||||
params.push_back(std::to_string((double)x_pos));
|
||||
params.push_back(std::to_string((double)y_pos));
|
||||
params.push_back(std::to_string((double)z_pos));
|
||||
params.push_back(std::to_string((double)heading));
|
||||
|
||||
auto &iter = conns.begin();
|
||||
while(iter != conns.end()) {
|
||||
RemoteCall((*iter), method, params);
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
std::vector<std::string> params;
|
||||
params.push_back(std::to_string((long)zone->GetZoneID()));
|
||||
params.push_back(std::to_string((long)zone->GetInstanceID()));
|
||||
params.push_back(std::to_string((long)GetID()));
|
||||
params.push_back(GetName());
|
||||
params.push_back(std::to_string((double)x_pos));
|
||||
params.push_back(std::to_string((double)y_pos));
|
||||
params.push_back(std::to_string((double)z_pos));
|
||||
params.push_back(std::to_string((double)heading));
|
||||
RemoteCallSubscriptionHandler::Instance()->OnEvent("NPC::MakeSpawnUpdateNoDelta", params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include "../common/packet_dump.h"
|
||||
#include "../common/servertalk.h"
|
||||
#include "remote_call_subscribe.h"
|
||||
#include "remote_call.h"
|
||||
#include "worldserver.h"
|
||||
#include "zone.h"
|
||||
|
||||
@ -90,12 +91,28 @@ bool RemoteCallSubscriptionHandler::Unsubscribe(std::string connection_id, std::
|
||||
return false;
|
||||
}
|
||||
|
||||
void RemoteCallSubscriptionHandler::OnEvent(std::string method, std::vector<std::string> ¶ms) {
|
||||
if(registered_events.count(method) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string func = "WebInterface::DispatchEvent::" + method;
|
||||
std::vector<std::string> &conns = registered_events[method];
|
||||
if(conns.size() > 0) {
|
||||
auto &iter = conns.begin();
|
||||
while(iter != conns.end()) {
|
||||
RemoteCall((*iter), func, params);
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteCallSubscriptionHandler::Process() {
|
||||
//create a check for all these connection ids packet
|
||||
uint32 sz = 12;
|
||||
auto iter = connection_ids.begin();
|
||||
while(iter != connection_ids.end()) {
|
||||
sz += iter->first.size();
|
||||
sz += (uint32)iter->first.size();
|
||||
sz += 5;
|
||||
++iter;
|
||||
}
|
||||
@ -116,15 +133,6 @@ void RemoteCallSubscriptionHandler::Process() {
|
||||
safe_delete(pack);
|
||||
}
|
||||
|
||||
const std::vector<std::string> &RemoteCallSubscriptionHandler::GetSubscribers(std::string event_name) {
|
||||
if(registered_events.count(event_name) == 0) {
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::vector<std::string> &r = registered_events[event_name];
|
||||
return r;
|
||||
}
|
||||
|
||||
void RemoteCallSubscriptionHandler::ClearConnection(std::string connection_id) {
|
||||
if(connection_ids.count(connection_id) != 0) {
|
||||
connection_ids.erase(connection_id);
|
||||
@ -138,7 +146,6 @@ void RemoteCallSubscriptionHandler::ClearConnection(std::string connection_id) {
|
||||
if(conn_iter->compare(connection_id) == 0) {
|
||||
conns.erase(conn_iter);
|
||||
registered_events[iter->first] = conns;
|
||||
printf("Removing connection: %s from event %s\n", connection_id.c_str(), iter->first.c_str());
|
||||
break;
|
||||
}
|
||||
++conn_iter;
|
||||
@ -149,10 +156,6 @@ void RemoteCallSubscriptionHandler::ClearConnection(std::string connection_id) {
|
||||
}
|
||||
|
||||
void RemoteCallSubscriptionHandler::ClearAllConnections() {
|
||||
//
|
||||
//std::map<std::string, std::vector<std::string>> registered_events;
|
||||
//std::map<std::string, int> connection_ids;
|
||||
|
||||
registered_events.clear();
|
||||
connection_ids.clear();
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ public:
|
||||
static RemoteCallSubscriptionHandler *Instance();
|
||||
bool Subscribe(std::string connection_id, std::string event_name);
|
||||
bool Unsubscribe(std::string connection_id, std::string event_name);
|
||||
const std::vector<std::string> &GetSubscribers(std::string event_name);
|
||||
void OnEvent(std::string method, std::vector<std::string> ¶ms);
|
||||
|
||||
void Process();
|
||||
void ClearConnection(std::string connection_id);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user