Skip to content

Commit

Permalink
emit more stats to observers
Browse files Browse the repository at this point in the history
  • Loading branch information
aurbano committed Mar 16, 2017
1 parent c3f2185 commit e6f0821
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sudo: false
language: node_js
node_js:
- '6.9.2'
- '6'

after_success:
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
43 changes: 26 additions & 17 deletions src/lib/online.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ function onlineGame(options) {
io.on('connection', function (socket) {
if (socket.handshake.query.client) {
// a client (observer) has connected, don't add to player list
// send a summary of the server
socket.emit('stats', {
type: 'stats',
payload: {
players: serverInfo.players,
games: [],
},
});
return true;
}

Expand Down Expand Up @@ -217,7 +225,7 @@ function addPlayer(player) {
index = serverInfo.players.push(player) - 1;
}
log('Connected "' + player + '"', true);
serverInfo.io.emit('status', {
serverInfo.io.emit('stats', {
type: 'connect',
payload: player,
});
Expand All @@ -231,7 +239,7 @@ function removePlayer(player) {
serverInfo.players.splice(index, 1);
}
log('Disconnected "' + player + '"', true);
serverInfo.io.emit('status', {
serverInfo.io.emit('stats', {
type: 'disconnect',
payload: player,
});
Expand Down Expand Up @@ -265,7 +273,7 @@ function startSession(session, settings){
'"'
);

serverInfo.io.emit('status', {
serverInfo.io.emit('stats', {
type: 'session-start',
payload: {
players: [
Expand All @@ -275,19 +283,20 @@ function startSession(session, settings){
},
});

const server = {
timeout: options.timeout || 100,
maxGames: options.games || 1000,
state: new State(),
session: session,
currentPlayer: 0,
firstPlayer: 0,
game: new UTTT(),
gameStart: null,
progressBar: null,
};

if (serverInfo.ui.enabled) {
const server = {
timeout: options.timeout || 100,
maxGames: options.games || 1000,
state: new State(),
session: session,
currentPlayer: 0,
firstPlayer: 0,
game: new UTTT(),
gameStart: null,
ui: getGameBox(),
progressBar: null,
};
server.ui = getGameBox();

server.ui.append(blessed.text({
top: 0,
Expand Down Expand Up @@ -380,7 +389,7 @@ function startSession(session, settings){
}


serverInfo.io.emit('status', {
serverInfo.io.emit('stats', {
type: 'session-end',
payload: {
players: [
Expand Down Expand Up @@ -441,7 +450,7 @@ function startSession(session, settings){
server.currentPlayer = server.firstPlayer;
server.game.init();

serverInfo.io.emit('status', {
serverInfo.io.emit('stats', {
type: 'game-start',
payload: {
players: [
Expand Down

0 comments on commit e6f0821

Please sign in to comment.