35 lines
616 B
JavaScript
35 lines
616 B
JavaScript
|
import Messaging;
|
||
|
import Session;
|
||
|
import Table;
|
||
|
|
||
|
var room = Table.make(player, 'name');
|
||
|
initMessageHandlers();
|
||
|
|
||
|
return {
|
||
|
room: room
|
||
|
};
|
||
|
|
||
|
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);
|
||
|
});
|
||
|
}
|