Merge branch 'develop' of ssh://git.mnml.gg:40022/~/mnml into develop

This commit is contained in:
Mashy 2019-10-18 10:09:46 +10:00
commit 8753d97650
6 changed files with 80 additions and 12 deletions

View File

@ -14,6 +14,9 @@
* can't reset password without knowing password =\ * can't reset password without knowing password =\
* Invert recharge * Invert recharge
* serde serialize privatise
* chat
## SOON ## SOON
* equip from shop (buy and equip without putting in your inventory) for bases * equip from shop (buy and equip without putting in your inventory) for bases
@ -21,7 +24,6 @@
* bot game grind * bot game grind
* ACP * ACP
* essential * essential
* serde serialize privatise
* msg pane / chatwheel * msg pane / chatwheel
* audio * audio
* treats * treats

View File

@ -171,7 +171,17 @@ impl Events {
for (client_id, client) in self.clients.iter() { for (client_id, client) in self.clients.iter() {
if client.subs.contains(&id) { if client.subs.contains(&id) {
subs += 1; subs += 1;
match client.tx.send(msg.clone()) {
let redacted = match client.account {
Some(a) => match msg {
RpcMessage::InstanceState(ref i) => RpcMessage::InstanceState(i.clone().redact(a)),
RpcMessage::GameState(ref i) => RpcMessage::GameState(i.clone().redact(a)),
_ => msg.clone(),
}
None => msg.clone(),
};
match client.tx.send(redacted) {
Ok(_) => (), Ok(_) => (),
Err(e) => { Err(e) => {
warn!("unable to send msg to client err={:?}", e); warn!("unable to send msg to client err={:?}", e);

View File

@ -62,6 +62,17 @@ impl Game {
}; };
} }
pub fn redact(mut self, account: Uuid) -> Game {
self.players = self.players.into_iter()
.map(|p| p.redact(account))
.collect();
self.stack
.retain(|s| s.source_player_id == account);
self
}
pub fn set_time_control(&mut self, tc: TimeControl) -> &mut Game { pub fn set_time_control(&mut self, tc: TimeControl) -> &mut Game {
self.time_control = tc; self.time_control = tc;
self.phase_end = Some(tc.lobby_timeout()); self.phase_end = Some(tc.lobby_timeout());
@ -631,8 +642,8 @@ pub fn game_write(tx: &mut Transaction, game: &Game) -> Result<(), Error> {
return Ok(()); return Ok(());
} }
pub fn game_state(tx: &mut Transaction, _account: &Account, id: Uuid) -> Result<Game, Error> { pub fn game_state(tx: &mut Transaction, account: &Account, id: Uuid) -> Result<Game, Error> {
return game_get(tx, id) Ok(game_get(tx, id)?.redact(account.id))
} }
pub fn game_get(tx: &mut Transaction, id: Uuid) -> Result<Game, Error> { pub fn game_get(tx: &mut Transaction, id: Uuid) -> Result<Game, Error> {

View File

@ -126,6 +126,14 @@ impl Instance {
} }
} }
pub fn redact(mut self, account: Uuid) -> Instance {
self.players = self.players.into_iter()
.map(|p| p.redact(account))
.collect();
self
}
fn phase_timed_out(&self) -> bool { fn phase_timed_out(&self) -> bool {
match self.phase_end { match self.phase_end {
Some(t) => Utc::now().signed_duration_since(t).num_milliseconds() > 0, Some(t) => Utc::now().signed_duration_since(t).num_milliseconds() > 0,

View File

@ -103,6 +103,24 @@ impl Player {
} }
} }
pub fn redact(mut self, account: Uuid) -> Player {
// all g
if account == self.id {
return self;
}
// remove vbox
self.vbox = Vbox::new();
// hide skills
for construct in self.constructs.iter_mut() {
construct.skills = vec![];
construct.specs = vec![];
}
self
}
pub fn set_bot(mut self, bot: bool) -> Player { pub fn set_bot(mut self, bot: bool) -> Player {
self.bot = bot; self.bot = bot;
self self

View File

@ -257,6 +257,25 @@ impl Connection {
}, },
} }
} }
// this is where last minute processing happens
// use it to modify outgoing messages, update subs, serialize in some way...
fn send(&self, msg: RpcMessage) -> Result<(), Error> {
let msg = match self.account {
Some(ref a) => match msg {
RpcMessage::InstanceState(v) => RpcMessage::InstanceState(v.redact(a.id)),
RpcMessage::AccountInstances(v) =>
RpcMessage::AccountInstances(v.into_iter().map(|i| i.redact(a.id)).collect()),
RpcMessage::GameState(v) => RpcMessage::GameState(v.redact(a.id)),
_ => msg,
},
None => msg,
};
self.ws.send(msg).unwrap();
Ok(())
}
} }
// we unwrap everything in here cause really // we unwrap everything in here cause really
@ -272,7 +291,7 @@ impl Handler for Connection {
// if user logged in do some prep work // if user logged in do some prep work
if let Some(ref a) = self.account { if let Some(ref a) = self.account {
self.ws.send(RpcMessage::AccountState(a.clone())).unwrap(); self.send(RpcMessage::AccountState(a.clone())).unwrap();
self.events.send(Event::Subscribe(self.id, a.id)).unwrap(); self.events.send(Event::Subscribe(self.id, a.id)).unwrap();
// check if they have an image that needs to be generated // check if they have an image that needs to be generated
@ -283,23 +302,23 @@ impl Handler for Connection {
// send account constructs // send account constructs
let account_constructs = account::constructs(&mut tx, a).unwrap(); let account_constructs = account::constructs(&mut tx, a).unwrap();
self.ws.send(RpcMessage::AccountConstructs(account_constructs)).unwrap(); self.send(RpcMessage::AccountConstructs(account_constructs)).unwrap();
// get account instances // get account instances
// and send them to the client // and send them to the client
let account_instances = account::account_instances(&mut tx, a).unwrap(); let account_instances = account::account_instances(&mut tx, a).unwrap();
self.ws.send(RpcMessage::AccountInstances(account_instances)).unwrap(); self.send(RpcMessage::AccountInstances(account_instances)).unwrap();
let shop = mtx::account_shop(&mut tx, &a).unwrap(); let shop = mtx::account_shop(&mut tx, &a).unwrap();
self.ws.send(RpcMessage::AccountShop(shop)).unwrap(); self.send(RpcMessage::AccountShop(shop)).unwrap();
let team = account::team(&mut tx, &a).unwrap(); let team = account::team(&mut tx, &a).unwrap();
self.ws.send(RpcMessage::AccountTeam(team)).unwrap(); self.send(RpcMessage::AccountTeam(team)).unwrap();
// tx should do nothing // tx should do nothing
tx.commit().unwrap(); tx.commit().unwrap();
} else { } else {
self.ws.send(RpcMessage::Demo(demo().unwrap())).unwrap(); self.send(RpcMessage::Demo(demo().unwrap())).unwrap();
} }
Ok(()) Ok(())
@ -327,11 +346,11 @@ impl Handler for Connection {
_ => (), _ => (),
}; };
self.ws.send(reply).unwrap(); self.send(reply).unwrap();
}, },
Err(e) => { Err(e) => {
warn!("{:?}", e); warn!("{:?}", e);
self.ws.send(RpcMessage::Error(e.to_string())).unwrap(); self.send(RpcMessage::Error(e.to_string())).unwrap();
}, },
}; };
}, },