2018-05-11 12:31:53 +02:00
|
|
|
function Session(modules) {
|
|
|
|
var key = null;
|
|
|
|
var name = null;
|
2019-11-24 22:54:46 +01:00
|
|
|
var loggedIn = false;
|
2018-05-11 12:31:53 +02:00
|
|
|
|
|
|
|
modules.messaging.addEventListener(["Welcome"], function(o) {
|
|
|
|
key = o.key;
|
2019-11-24 22:54:46 +01:00
|
|
|
modules.save.set('player.id', key);
|
2018-05-11 12:31:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
modules.messaging.addEventListener(["Relay", "LogIn"], function(o) {
|
|
|
|
if(is(o.from)) {
|
|
|
|
name = o.message.name;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
is: is,
|
2018-05-12 15:32:00 +02:00
|
|
|
getKey: getKey,
|
2019-11-24 22:54:46 +01:00
|
|
|
loggedIn: loggedIn,
|
|
|
|
start: start
|
2018-05-11 12:31:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function is(sessionKey) {
|
|
|
|
return key == sessionKey;
|
|
|
|
}
|
|
|
|
|
2018-05-12 15:32:00 +02:00
|
|
|
function getKey() {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2019-11-24 22:54:46 +01:00
|
|
|
function isLoggedIn() {
|
|
|
|
return loggedIn;
|
|
|
|
}
|
|
|
|
|
|
|
|
function start(name) {
|
|
|
|
var myID = modules.save.get('player.id');
|
|
|
|
if(myID != undefined) {
|
|
|
|
modules.messaging.send({tag: 'Tadaima', myID: myID, name: name});
|
|
|
|
} else {
|
|
|
|
modules.messaging.send({tag: 'Hello', name: name});
|
|
|
|
}
|
|
|
|
modules.save.set('player.name', name);
|
2018-05-11 12:31:53 +02:00
|
|
|
}
|
|
|
|
}
|