authenticated msgs

This commit is contained in:
ntr 2019-12-24 12:23:33 +10:00
parent 395bf640c9
commit cf4972a1b8
6 changed files with 29 additions and 24 deletions

View File

@ -100,25 +100,23 @@ function Play(args) {
const list = () => { const list = () => {
return ( return (
<div> <div class='list play'>
<div class='list play'> <figure>
<figure> <button
<button class="ready"
class="ready" onClick={() => sendInstancePractice()}>
onClick={() => sendInstancePractice()}> Tutorial
Tutorial </button>
</button> <figcaption>Learn MNML</figcaption>
<figcaption>Learn MNML</figcaption> </figure>
</figure> <figure>
<figure> <button
<button class='discord-btn'
class='discord-btn' onClick={() => window.open('https://discord.gg/YJJgurM') }>
onClick={() => window.open('https://discord.gg/YJJgurM') }> &nbsp;
&nbsp; </button>
</button> <figcaption>Join the Community</figcaption>
<figcaption>Join the Community</figcaption> </figure>
</figure>
</div>
</div> </div>
); );
}; };
@ -127,8 +125,9 @@ function Play(args) {
<section class="top"> <section class="top">
<div class="news"> <div class="news">
<h1>Welcome to MNML</h1> <h1>Welcome to MNML</h1>
{news}
{list()} {list()}
<hr />
{news}
</div> </div>
<Welcome /> <Welcome />
</section> </section>

View File

@ -104,6 +104,10 @@ function registerEvents(store) {
} }
function setAccount(account) { function setAccount(account) {
store.dispatch(actions.setAccount(account));
}
function setAuthenticated(account) {
if (account && window.Notification) { if (account && window.Notification) {
window.Notification.requestPermission(); window.Notification.requestPermission();
} }
@ -113,6 +117,7 @@ function registerEvents(store) {
} }
store.dispatch(actions.setAccount(account)); store.dispatch(actions.setAccount(account));
store.dispatch(actions.setAuthenticated(true));
} }
function setEmail(email) { function setEmail(email) {
@ -223,6 +228,7 @@ function registerEvents(store) {
clearTutorial, clearTutorial,
clearTutorialGame, clearTutorialGame,
setAccount, setAccount,
setAuthenticated,
setAccountInstances, setAccountInstances,
setActiveItem, setActiveItem,
setActiveSkill, setActiveSkill,

View File

@ -270,7 +270,7 @@ function createSocket(events) {
// this object wraps the reply types to a function // this object wraps the reply types to a function
const handlers = { const handlers = {
AccountState: onAccount, AccountState: onAccount,
AccountAuthenticated: events.setAuthenticated, AccountAuthenticated: account => events.setAuthenticated(account),
AccountConstructs: onAccountConstructs, AccountConstructs: onAccountConstructs,
AccountTeam: onAccountTeam, AccountTeam: onAccountTeam,
AccountInstances: onAccountInstances, AccountInstances: onAccountInstances,

View File

@ -44,7 +44,7 @@ use http::{AUTH_CLEAR, TOKEN_HEADER};
#[derive(Debug,Clone,Serialize)] #[derive(Debug,Clone,Serialize)]
pub enum RpcMessage { pub enum RpcMessage {
AccountState(Account), AccountState(Account),
AccountAuthenticated(()), AccountAuthenticated(Account),
AccountConstructs(Vec<Construct>), AccountConstructs(Vec<Construct>),
AccountTeam(Vec<Construct>), AccountTeam(Vec<Construct>),
AccountInstances(Vec<Instance>), AccountInstances(Vec<Instance>),

View File

@ -50,7 +50,6 @@ impl User for Anonymous {
self.send(RpcMessage::AccountState(self.account.clone()), events, ws)?; self.send(RpcMessage::AccountState(self.account.clone()), events, ws)?;
self.send(RpcMessage::StartTutorial(()), events, ws)?; self.send(RpcMessage::StartTutorial(()), events, ws)?;
self.send(RpcMessage::ItemInfo(item_info()), events, ws)?;
Ok(()) Ok(())
} }
@ -75,6 +74,7 @@ impl User for Anonymous {
match v { match v {
RpcRequest::Ping {} => return Ok(RpcMessage::Pong(())), RpcRequest::Ping {} => return Ok(RpcMessage::Pong(())),
RpcRequest::ItemInfo {} => return Ok(RpcMessage::ItemInfo(item_info())),
RpcRequest::InstancePractice {} => RpcRequest::InstancePractice {} =>
Ok(RpcMessage::InstanceState(pg::instance_demo(&self.account)?)), Ok(RpcMessage::InstanceState(pg::instance_demo(&self.account)?)),

View File

@ -71,7 +71,7 @@ impl User for Authorised {
info!("authenticated connection account={:?}", self.account); info!("authenticated connection account={:?}", self.account);
let a = &self.account; let a = &self.account;
ws.send(RpcMessage::AccountAuthenticated(()))?; ws.send(RpcMessage::AccountAuthenticated(a.clone()))?;
// tell events we have connected // tell events we have connected
events.send(Event::Connect(self.id, a.clone(), ws.clone()))?; events.send(Event::Connect(self.id, a.clone(), ws.clone()))?;