39 lines
710 B
JavaScript
39 lines
710 B
JavaScript
import Messaging;
|
|
import Session;
|
|
import Table;
|
|
|
|
var room = Table.make(player, 'name');
|
|
initMessageHandlers();
|
|
|
|
return {
|
|
opponent: opponent,
|
|
room: room
|
|
};
|
|
|
|
function opponent(key) {
|
|
return {id: key, name: room.get(key).name};
|
|
}
|
|
|
|
function player(key, name) {
|
|
return {
|
|
key: key,
|
|
name: name
|
|
};
|
|
}
|
|
|
|
function initMessageHandlers() {
|
|
Messaging.addEventListener(["Okaeri"], function(o) {
|
|
room.insertAll(o.room);
|
|
});
|
|
Messaging.addEventListener(["Welcome"], function(o) {
|
|
room.insertAll(o.room);
|
|
});
|
|
Messaging.addEventListener(["LogIn"], function(o) {
|
|
if(!Session.is(o.from)) {
|
|
room.insert(o.from, o.as);
|
|
}
|
|
});
|
|
Messaging.addEventListener(["LogOut"], function(o) {
|
|
room.remove(o.from);
|
|
});
|
|
}
|