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
+23
View File
@@ -12,6 +12,7 @@ use http::MnmlHttpError;
use names::{name as generate_name};
use construct::{Construct, ConstructSkeleton, construct_spawn};
use instance::{Instance, instance_delete};
use instance;
use mtx::{Mtx, FREE_MTX};
use pg::Db;
use img;
@@ -502,3 +503,25 @@ pub fn img_check(account: &Account) -> Result<Uuid, Error> {
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);
}
+4
View File
@@ -353,6 +353,10 @@ impl Handler for Connection {
let wheel = account::chat_wheel(&db, a.id).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.commit().unwrap();
} else {