mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-03 21:56:36 +00:00
Will be redoing the event interface for subscriptions, some work for the wi and crash fixes
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
var auth = require('../core/jwt_auth.js').auth;
|
||||
|
||||
function RegisterFunction(path, fn, app, api) {
|
||||
app.post(path, auth, function (req, res) {
|
||||
var params = req.body.params || [];
|
||||
|
||||
api.Call(fn, params)
|
||||
.then(function(value) {
|
||||
res.send({ response: value });
|
||||
})
|
||||
.catch(function(reason) {
|
||||
if(reason.message) {
|
||||
res.send({ status: reason.message });
|
||||
}
|
||||
else if(reason === 'Not connected to world server.') {
|
||||
res.send({ status: 'ENCONNECTED' });
|
||||
} else {
|
||||
res.sendStatus(500);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'Register': RegisterFunction
|
||||
}
|
||||
+10
-31
@@ -1,37 +1,16 @@
|
||||
var auth = require('../core/jwt_auth.js').auth;
|
||||
const common = require('./common.js');
|
||||
|
||||
var RegisterEQW = function(app, api) {
|
||||
app.post('/api/eqw/islocked', auth, function (req, res) {
|
||||
api.Call('EQW::IsLocked', [])
|
||||
.then(function(value) {
|
||||
res.send({ response: value });
|
||||
})
|
||||
.catch(function(reason) {
|
||||
res.sendStatus(500);
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/eqw/lock', auth, function (req, res) {
|
||||
api.Call('EQW::Lock', [])
|
||||
.then(function(value) {
|
||||
res.send({ response: value });
|
||||
})
|
||||
.catch(function(reason) {
|
||||
res.sendStatus(500);
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/eqw/unlock', auth, function (req, res) {
|
||||
api.Call('EQW::Unlock', [])
|
||||
.then(function(value) {
|
||||
res.send({ response: value });
|
||||
})
|
||||
.catch(function(reason) {
|
||||
res.sendStatus(500);
|
||||
});
|
||||
});
|
||||
common.Register('/api/eqw/getconfig', 'EQW::GetConfig', app, api);
|
||||
common.Register('/api/eqw/islocked', 'EQW::IsLocked', app, api);
|
||||
common.Register('/api/eqw/lock', 'EQW::Lock', app, api);
|
||||
common.Register('/api/eqw/unlock', 'EQW::Unlock', app, api);
|
||||
common.Register('/api/eqw/getplayercount', 'EQW::GetPlayerCount', app, api);
|
||||
common.Register('/api/eqw/getzonecount', 'EQW::GetZoneCount', app, api);
|
||||
common.Register('/api/eqw/getlaunchercount', 'EQW::GetLauncherCount', app, api);
|
||||
common.Register('/api/eqw/getloginservercount', 'EQW::GetLoginServerCount', app, api);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
'Register': RegisterEQW
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,20 +113,26 @@ class ServertalkAPI
|
||||
|
||||
var subs = this.subscriptions[event_id];
|
||||
if(subs) {
|
||||
console.log('Subscribe', who.uuid, 'to', event_id);
|
||||
//console.log('Subscribe', who.uuid, 'to', event_id);
|
||||
subs[who.uuid] = who;
|
||||
} else {
|
||||
console.log('Subscribe', who.uuid, 'to', event_id);
|
||||
//console.log('Subscribe', who.uuid, 'to', event_id);
|
||||
this.subscriptions[event_id] = { };
|
||||
this.subscriptions[event_id][who.uuid] = who;
|
||||
//Tell our server we have a subscription for event_id
|
||||
}
|
||||
}
|
||||
|
||||
Unsubscribe(event_id, who) {
|
||||
var subs = this.subscriptions[event_id];
|
||||
if(subs) {
|
||||
console.log('Unsubscribe', who.uuid, 'from', event_id);
|
||||
//console.log('Unsubscribe', who.uuid, 'from', event_id);
|
||||
delete subs[who.uuid];
|
||||
|
||||
if(Object.keys(subs).length === 0) {
|
||||
delete this.subscriptions[event_id];
|
||||
//Tell our server we no longer have a subscription for event_id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -2,8 +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', method: 'EQW::ZoneUpdate::Subscribe'}));
|
||||
ws.send(JSON.stringify({authorization: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IktTcHJpdGUxIiwiZXhwIjoxNDg0NzIzNDQxLCJpYXQiOjE0ODQxMTg2NDF9.Lmwm572yMWIu1DUrfer8JVvl1DGEkdnMsMFp5WDzp_A', method: 'EQW::ClientUpdate::Subscribe'}));
|
||||
ws.send(JSON.stringify({authorization: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IktTcHJpdGUxIiwiZXhwIjoxNDg2MzI4MDI3LCJpYXQiOjE0ODU3MjMyMjd9.fJUeSQsxb5C13ICANox81YdE5yImkrVw-lRCP3O40-E', method: 'EQW::ZoneUpdate::Subscribe'}));
|
||||
ws.send(JSON.stringify({authorization: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IktTcHJpdGUxIiwiZXhwIjoxNDg2MzI4MDI3LCJpYXQiOjE0ODU3MjMyMjd9.fJUeSQsxb5C13ICANox81YdE5yImkrVw-lRCP3O40-E', method: 'EQW::ClientUpdate::Subscribe'}));
|
||||
});
|
||||
|
||||
ws.on('message', function(data, flags) {
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
const common = require('./wi_common.js');
|
||||
|
||||
var RegisterEQW = function(wsi, api) {
|
||||
common.Register('EQW::GetConfig', wsi, api);
|
||||
common.Register('EQW::IsLocked', wsi, api);
|
||||
common.Register('EQW::Lock', wsi, api);
|
||||
common.Register('EQW::Unlock', wsi, api);
|
||||
common.Register('EQW::GetPlayerCount', wsi, api);
|
||||
common.Register('EQW::GetZoneCount', wsi, api);
|
||||
common.Register('EQW::GetLauncherCount', wsi, api);
|
||||
common.Register('EQW::GetLoginServerCount', wsi, api);
|
||||
common.RegisterSubscription('EQW::ZoneUpdate', wsi, api);
|
||||
common.RegisterSubscription('EQW::ClientUpdate', wsi, api);
|
||||
};
|
||||
|
||||
+1
-1
@@ -24,4 +24,4 @@ function RegisterSubscription(event, wsi, api) {
|
||||
module.exports = {
|
||||
'Register': Register,
|
||||
'RegisterSubscription': RegisterSubscription
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user