diff --git a/server/src/account.rs b/server/src/account.rs index 83a7d7e4..60d05de4 100644 --- a/server/src/account.rs +++ b/server/src/account.rs @@ -530,3 +530,24 @@ pub fn img_check(account: &Account) -> Result { } } +pub fn tutorial(tx: &mut Transaction, account: &Account) -> Result, 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_practice(tx, account)?)); + } + + return Ok(None); +} \ No newline at end of file diff --git a/server/src/user_authenticated.rs b/server/src/user_authenticated.rs index 27dd4638..a127368b 100644 --- a/server/src/user_authenticated.rs +++ b/server/src/user_authenticated.rs @@ -128,6 +128,10 @@ impl User for Authenticated { let wheel = account::chat_wheel(&db, a.id)?; self.ws.send(RpcMessage::ChatWheel(wheel))?; + if let Some(instance) = account::tutorial(&mut tx, &a)? { + self.ws.send(RpcMessage::InstanceState(instance))?; + } + // tx should do nothing tx.commit()?;