2020-01-10 08:36:57 +01:00
|
|
|
import Messaging;
|
|
|
|
import Session;
|
|
|
|
import Table;
|
|
|
|
|
2020-01-13 23:08:20 +01:00
|
|
|
var players = Table.make(function(o) {return o.value});
|
2020-01-10 08:36:57 +01:00
|
|
|
initMessageHandlers();
|
|
|
|
|
|
|
|
return {
|
2020-01-14 17:27:56 +01:00
|
|
|
player: player,
|
2020-01-13 08:39:32 +01:00
|
|
|
players: players
|
2020-01-10 08:36:57 +01:00
|
|
|
};
|
|
|
|
|
2020-01-14 17:27:56 +01:00
|
|
|
function player(key) {
|
2020-01-13 23:08:20 +01:00
|
|
|
return {id: key, name: players.get(key)};
|
2020-01-10 08:36:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function initMessageHandlers() {
|
|
|
|
Messaging.addEventListener(["Okaeri"], function(o) {
|
2020-01-13 08:39:32 +01:00
|
|
|
players.insertAll(o.room);
|
2020-01-10 08:36:57 +01:00
|
|
|
});
|
|
|
|
Messaging.addEventListener(["Welcome"], function(o) {
|
2020-01-13 08:39:32 +01:00
|
|
|
players.insertAll(o.room);
|
2020-01-10 08:36:57 +01:00
|
|
|
});
|
|
|
|
Messaging.addEventListener(["LogIn"], function(o) {
|
|
|
|
if(!Session.is(o.from)) {
|
2020-01-13 08:39:32 +01:00
|
|
|
players.insert(o.from, o.as);
|
2020-01-10 08:36:57 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
Messaging.addEventListener(["LogOut"], function(o) {
|
2020-01-13 08:39:32 +01:00
|
|
|
players.remove(o.from);
|
2020-01-10 08:36:57 +01:00
|
|
|
});
|
|
|
|
}
|