¶ Incoming listenersIncoming listeners are fired in response to incoming messages |
(function (node) {
if (!node) {
console.log('nodeGame not found. Cannot add incoming listeners');
return false;
}
var GameMsg = node.GameMsg,
GameState = node.GameState,
PlayerList = node.PlayerList,
Player = node.Player,
J = node.JSUS;
var action = node.action,
target = node.target;
var say = action.SAY + '.',
set = action.SET + '.',
get = action.GET + '.',
IN = node.IN;
|
¶ in.say.PCONNECTAdds a new player to the player list from the data contained in the message See
Game.pl
|
node.on( IN + say + 'PCONNECT', function (msg) {
if (!msg.data) return;
node.game.pl.add(new Player(msg.data));
node.emit('UPDATED_PLIST');
node.game.pl.checkState();
});
|
¶ in.say.PDISCONNECTRemoves a player from the player list based on the data contained in the message See
Game.pl
|
node.on( IN + say + 'PDISCONNECT', function (msg) {
if (!msg.data) return;
node.game.pl.remove(msg.data.id);
node.emit('UPDATED_PLIST');
node.game.pl.checkState();
}); |
¶ in.say.MCONNECTAdds a new monitor to the monitor list from the data contained in the message See
Game.ml
|
node.on( IN + say + 'MCONNECT', function (msg) {
if (!msg.data) return;
node.game.ml.add(new Player(msg.data));
node.emit('UPDATED_MLIST');
});
|
¶ in.say.MDISCONNECTRemoves a monitor from the player list based on the data contained in the message See
Game.ml
|
node.on( IN + say + 'MDISCONNECT', function (msg) {
if (!msg.data) return;
node.game.ml.remove(msg.data.id);
node.emit('UPDATED_MLIST');
});
|
node.on( IN + say + 'PLIST', function (msg) {
if (!msg.data) return;
node.game.pl = new PlayerList({}, msg.data);
node.emit('UPDATED_PLIST');
});
|
|
node.on( IN + say + 'MLIST', function (msg) {
if (!msg.data) return;
node.game.ml = new PlayerList({}, msg.data);
node.emit('UPDATED_MLIST');
});
|
|
¶ in.get.DATAExperimental feature. Undocumented (for now) |
node.on( IN + get + 'DATA', function (msg) {
if (msg.text === 'LOOP'){
node.socket.sendDATA(action.SAY, node.game.gameLoop, msg.from, 'GAME');
} |
}); |
|
¶ in.set.STATEAdds an entry to the memory object |
node.on( IN + set + 'STATE', function (msg) {
node.game.memory.add(msg.text, msg.data, msg.from);
}); |
¶ in.set.DATAAdds an entry to the memory object |
node.on( IN + set + 'DATA', function (msg) {
node.game.memory.add(msg.text, msg.data, msg.from);
}); |
¶ in.say.STATEUpdates the game state or updates a player's state in the player-list object If the message is from the server, it updates the game state, else the state in the player-list object from the player who sent the message is updated @emit UPDATED_PLIST @see Game.pl |
node.on( IN + say + 'STATE', function (msg) { |
|
|
console.log(node.socket.serverid + 'AAAAAA'); |
if (node.socket.serverid && msg.from === node.socket.serverid) { |
|
}
if (node.game.pl.exist(msg.from)) { |
console.log('EXIST') |
node.game.pl.updatePlayerState(msg.from, msg.data);
node.emit('UPDATED_PLIST');
node.game.pl.checkState();
} |
else { |
|
console.log('NOT EXISTS') |
node.game.updateState(msg.data);
}
});
|
node.on( IN + say + 'REDIRECT', function (msg) {
if (!msg.data) return;
if ('undefined' === typeof window || !window.location) {
node.log('window.location not found. Cannot redirect', 'err');
return false;
}
window.location = msg.data;
}); |
|
node.on( IN + say + 'SETUP', function (msg) {
if (!msg.text) return;
node.setup(msg.text, msg.data);
}); |
|
node.on( IN + say + 'GAMECOMMAND', function (msg) {
if (!msg.text) return;
if (!node.gamecommand[msg.text]) return;
node.emit('NODEGAME_GAMECOMMAND_' + msg.text,msg.data);
});
node.log('incoming listeners added');
})('undefined' !== typeof node ? node : module.parent.exports); |
|