You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
953 B
JavaScript

onload(() => {
const socket = io.connect(document.location.host);
socket.on('flash_msg', flash_msg);
socket.on('player_state', (data) => {
if (!data.secret) {
// our secret seems to be to old
localStorage.removeItem('secret');
return register();
}
//flash_msg("Logged in!");
localStorage.setItem('secret', data.secret);
localStorage.setItem('name', data.username);
document.cookie = `secret=${data.secret}`;
window.username = data.username;
$('.username').innerText = 'playing as ' + window.username;
});
function register() {
const name = localStorage.getItem('name') || prompt("Whats your username?");
socket.emit('signup', name)
}
if (!localStorage.getItem('secret')) {
register()
} else {
socket.emit('resume', localStorage.getItem('secret'))
}
window.socket = socket;
});