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
|
|
|
}
|
|
|
|
|
2020-01-25 10:56:55 +01:00
|
|
|
function enterAll(o) {
|
|
|
|
for(key in o) {
|
|
|
|
enterPlayer(key, o[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function enterPlayer(key, name) {
|
|
|
|
if(!Session.is(key)) {
|
|
|
|
players.insert(key, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 08:36:57 +01:00
|
|
|
function initMessageHandlers() {
|
2020-01-25 10:56:55 +01:00
|
|
|
Messaging.addEventListener(["Okaeri"], function(o) {enterAll(o.room);});
|
|
|
|
Messaging.addEventListener(["Welcome"], function(o) {enterAll(o.room);});
|
|
|
|
Messaging.addEventListener(["LogIn"], function(o) {enterPlayer(o.from, o.as);});
|
|
|
|
Messaging.addEventListener(["LogOut"], function(o) {players.remove(o.from);});
|
2020-01-10 08:36:57 +01:00
|
|
|
}
|