mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-22 20:51:23 +00:00
Added gather skeleton and auth error checking
This commit is contained in:
parent
6883b0b938
commit
9618fb80ca
6 changed files with 123 additions and 32 deletions
|
@ -4,35 +4,17 @@ var fs = require("fs");
|
|||
var path = require("path");
|
||||
var enslClient = require(path.join(__dirname, "../lib/ensl/client"))();
|
||||
var chatController = require(path.join(__dirname, "../lib/chat/controller"));
|
||||
var gatherController = require(path.join(__dirname, "../lib/gather/controller"));
|
||||
var winston = require("winston");
|
||||
|
||||
var rootNamespace;
|
||||
|
||||
var userCache = {};
|
||||
|
||||
module.exports = function (io) {
|
||||
var root = io.of("/");
|
||||
var authorised = io.of("/authorised");
|
||||
|
||||
var id = 2131;
|
||||
|
||||
// Authorisation
|
||||
root.use(function (socket, next) {
|
||||
enslClient.getUserById({
|
||||
id: id
|
||||
}, function (error, response, body) {
|
||||
if (error) {
|
||||
winston.error(error);
|
||||
return next(error)
|
||||
};
|
||||
socket._user = body;
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
var refreshUsers = function (socket) {
|
||||
var receiver = (socket !== undefined) ? socket : root;
|
||||
var refreshUsers = function (socket) {
|
||||
var receiver = (socket !== undefined) ? socket : rootNamespace;
|
||||
|
||||
var newCache = {};
|
||||
root.sockets.forEach(function (socket) {
|
||||
rootNamespace.sockets.forEach(function (socket) {
|
||||
var user = socket._user;
|
||||
newCache[user.id] = user;
|
||||
});
|
||||
|
@ -50,10 +32,26 @@ module.exports = function (io) {
|
|||
count: users.length,
|
||||
users: users
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
// Activate chat controller on root namespace
|
||||
chatController(root);
|
||||
module.exports = function (io) {
|
||||
rootNamespace = io.of("/");
|
||||
|
||||
var id = 2131;
|
||||
|
||||
// Authorisation
|
||||
rootNamespace.use(function (socket, next) {
|
||||
enslClient.getUserById({
|
||||
id: id
|
||||
}, function (error, response, body) {
|
||||
if (error) {
|
||||
winston.error(error);
|
||||
return next(error)
|
||||
};
|
||||
socket._user = body;
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
io.on('connection', function (socket) {
|
||||
refreshUsers();
|
||||
|
@ -66,8 +64,11 @@ module.exports = function (io) {
|
|||
enslClient.getUserById({
|
||||
id: id
|
||||
}, function (error, response, body) {
|
||||
if (error) {
|
||||
return winston.error(error);
|
||||
if (error || response.statusCode !== 200) {
|
||||
winston.error("An error occurred in authorising id", id);
|
||||
winston.error(error);
|
||||
winston.error("ENSL API status:", response.statusCode);
|
||||
return;
|
||||
}
|
||||
socket._user = body;
|
||||
refreshUsers();
|
||||
|
@ -78,4 +79,10 @@ module.exports = function (io) {
|
|||
refreshUsers();
|
||||
});
|
||||
});
|
||||
|
||||
// Activate chat controller on rootNamespace namespace
|
||||
chatController(rootNamespace);
|
||||
|
||||
// Activate gather controller on rootNamespace namespace
|
||||
gatherController(rootNamespace);
|
||||
};
|
||||
|
|
15
lib/gather/controller.js
Normal file
15
lib/gather/controller.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
"use strict";
|
||||
|
||||
/*
|
||||
* Gather Controller
|
||||
*
|
||||
* Server API
|
||||
* Client API
|
||||
*
|
||||
*/
|
||||
|
||||
var Gather = require("./gather");
|
||||
|
||||
module.exports = function (namespace) {
|
||||
|
||||
};
|
26
lib/gather/gather.js
Normal file
26
lib/gather/gather.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
"use strict";
|
||||
|
||||
/*
|
||||
* Implements Gather Model
|
||||
*
|
||||
* Gather States
|
||||
* - Picking
|
||||
* - Election
|
||||
* - Selection
|
||||
* - Done
|
||||
*
|
||||
*/
|
||||
|
||||
var Gatherer = require("./gatherer");
|
||||
|
||||
function Gather () {
|
||||
if (!(this instanceof Gather)) {
|
||||
return new Gather();
|
||||
}
|
||||
|
||||
this.gatherers = [];
|
||||
this.marines = [];
|
||||
this.aliens = [];
|
||||
}
|
||||
|
||||
module.exports = Gather;
|
17
lib/gather/gatherer.js
Normal file
17
lib/gather/gatherer.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
|
||||
/*
|
||||
* Implements Gatherer
|
||||
*
|
||||
* Stores necessary information including:
|
||||
* - user data
|
||||
* - voting preferences
|
||||
* - leader status
|
||||
*
|
||||
*/
|
||||
|
||||
function Gatherer () {
|
||||
|
||||
}
|
||||
|
||||
module.exports = Gatherer;
|
13
lib/gather/map.js
Normal file
13
lib/gather/map.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
"use strict";
|
||||
|
||||
/*
|
||||
* Implements Map
|
||||
*
|
||||
* Will eventually pull maps off ENSL API
|
||||
*/
|
||||
|
||||
function Map () {
|
||||
|
||||
}
|
||||
|
||||
module.exports = Map;
|
13
lib/gather/server.js
Normal file
13
lib/gather/server.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
"use strict";
|
||||
|
||||
/*
|
||||
* Implements Server
|
||||
*
|
||||
* Will eventually pull servers off ENSL API
|
||||
*/
|
||||
|
||||
function Server () {
|
||||
|
||||
}
|
||||
|
||||
module.exports = Server;
|
Loading…
Reference in a new issue