Revert "Build System Updated"

This commit is contained in:
Alex
2019-10-12 21:07:06 -07:00
committed by GitHub
parent 579471afcc
commit b9f57f1f28
193 changed files with 14124 additions and 10507 deletions
+18
View File
@@ -0,0 +1,18 @@
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);
};
module.exports = {
'Register': RegisterEQW
}
+7
View File
@@ -0,0 +1,7 @@
var RegisterAPI = function(wsi, api) {
require('./eqw.js').Register(wsi, api);
};
module.exports = {
'Register': RegisterAPI
}
+27
View File
@@ -0,0 +1,27 @@
function Register(name, wsi, api) {
wsi.Register(name,
function(request) {
api.Call(name, request.params)
.then(function(value) {
wsi.Send(request, value);
})
.catch(function(reason) {
wsi.SendError(request, reason);
});
}, true);
}
function RegisterSubscription(event, wsi, api) {
wsi.Register(event + '::Subscribe', function(request) {
api.Subscribe(event, request.ws);
});
wsi.Register(event + '::Unsubscribe', function(request) {
api.Unsubscribe(event, request.ws);
});
}
module.exports = {
'Register': Register,
'RegisterSubscription': RegisterSubscription
}
+118
View File
@@ -0,0 +1,118 @@
const WebSocketServer = require('ws').Server;
const jwt = require('jsonwebtoken');
const uuid = require('node-uuid');
class WebSocketInterface
{
constructor(server, key, api) {
this.wss = new WebSocketServer({ server: server });
this.methods = {};
var self = this;
this.wss.on('connection', function connection(ws) {
self.ws = ws;
ws.uuid = uuid.v4();
ws.on('message', function incoming(message) {
try {
var request = JSON.parse(message);
request.ws = ws;
if(request.method) {
var method = self.methods[request.method];
if(!method) {
self.SendError(request, 'Method not found: ' + request.method);
return;
}
if(method.requires_auth) {
if(!request.authorization) {
self.SendError(request, 'Authorization Required');
return;
}
jwt.verify(request.authorization, key, function(err, decoded) {
if(err) {
self.SendError(request, 'Authorization Required');
return;
}
request.token = decoded;
method.fn(request);
});
return;
}
method.fn(request);
} else {
self.SendError(request, 'No method supplied');
}
} catch(ex) {
console.log('Error parsing message:', ex);
self.SendError(null, 'No method supplied');
}
});
ws.on('close', function() {
api.UnsubscribeAll(ws);
});
ws.on('subscriptionMessage', function(msg) {
self.SendRaw(msg);
});
});
}
Register(method, fn, requires_auth) {
var entry = { fn: fn, requires_auth: requires_auth };
this.methods[method] = entry;
}
SendError(request, msg) {
try {
if(this.ws) {
var error = {};
if(request && request.id) {
error.id = request.id;
}
error.error = msg;
this.ws.send(JSON.stringify(error));
}
} catch(ex) {
console.log(ex);
}
}
Send(request, value) {
try {
if(this.ws) {
var response = {};
if(request && request.id) {
response.id = response.id;
}
response.response = value;
this.ws.send(JSON.stringify(response));
}
} catch(ex) {
console.log(ex);
}
}
SendRaw(obj) {
try {
this.ws.send(JSON.stringify(obj));
} catch(ex) {
console.log(ex);
}
}
}
module.exports = {
'wsi': WebSocketInterface
}