slamma jamma into instance when you first register

This commit is contained in:
ntr 2019-11-11 14:00:23 +11:00
parent eb51cad036
commit 61a8db708b
3 changed files with 28 additions and 13 deletions

View File

@ -318,11 +318,8 @@ function createSocket(events) {
return handlers[msgType](params); return handlers[msgType](params);
} }
let attempts = 1;
// Connection opened // Connection opened
function onOpen() { function onOpen() {
attempts = 0;
toast.info({ toast.info({
message: 'connected', message: 'connected',
position: 'topRight', position: 'topRight',
@ -341,21 +338,12 @@ function createSocket(events) {
} }
function onClose(event) { function onClose(event) {
attempts *= 2;
if (attempts > 10) {
toast.warning({
message: 'unable to connect, refreshing...',
position: 'topRight',
});
setTimeout(() => window.location.reload(true), 2000);
}
console.error('WebSocket closed', event); console.error('WebSocket closed', event);
toast.warning({ toast.warning({
message: 'disconnected', message: 'disconnected',
position: 'topRight', position: 'topRight',
}); });
return setTimeout(connect, attempts * 1000); return setTimeout(connect, 2000);
} }
function connect() { function connect() {

View File

@ -12,6 +12,7 @@ use http::MnmlHttpError;
use names::{name as generate_name}; use names::{name as generate_name};
use construct::{Construct, ConstructSkeleton, construct_spawn}; use construct::{Construct, ConstructSkeleton, construct_spawn};
use instance::{Instance, instance_delete}; use instance::{Instance, instance_delete};
use instance;
use mtx::{Mtx, FREE_MTX}; use mtx::{Mtx, FREE_MTX};
use pg::Db; use pg::Db;
use img; use img;
@ -502,3 +503,25 @@ pub fn img_check(account: &Account) -> Result<Uuid, Error> {
false => Ok(account.img), false => Ok(account.img),
} }
} }
pub fn tutorial(tx: &mut Transaction, account: &Account) -> Result<Option<Instance>, Error> {
let query = "
SELECT count(id)
FROM players
WHERE account = $1;
";
let result = tx
.query(query, &[&account.id])?;
let row = result.iter().next()
.ok_or(format_err!("unable to fetch joined games account={:?}", account))?;
let count: i64 = row.get(0);
if count == 0 {
return Ok(Some(instance::instance_practice(tx, account)?));
}
return Ok(None);
}

View File

@ -353,6 +353,10 @@ impl Handler for Connection {
let wheel = account::chat_wheel(&db, a.id).unwrap(); let wheel = account::chat_wheel(&db, a.id).unwrap();
self.send(RpcMessage::ChatWheel(wheel)).unwrap(); self.send(RpcMessage::ChatWheel(wheel)).unwrap();
if let Some(instance) = account::tutorial(&mut tx, &a).unwrap() {
self.send(RpcMessage::InstanceState(instance)).unwrap();
}
// tx should do nothing // tx should do nothing
tx.commit().unwrap(); tx.commit().unwrap();
} else { } else {