Merge branch 'develop' of ssh://git.mnml.gg:40022/~/mnml into develop
This commit is contained in:
commit
8753d97650
@ -14,6 +14,9 @@
|
||||
* can't reset password without knowing password =\
|
||||
* Invert recharge
|
||||
|
||||
* serde serialize privatise
|
||||
* chat
|
||||
|
||||
## SOON
|
||||
|
||||
* equip from shop (buy and equip without putting in your inventory) for bases
|
||||
@ -21,7 +24,6 @@
|
||||
* bot game grind
|
||||
* ACP
|
||||
* essential
|
||||
* serde serialize privatise
|
||||
* msg pane / chatwheel
|
||||
* audio
|
||||
* treats
|
||||
|
||||
@ -171,7 +171,17 @@ impl Events {
|
||||
for (client_id, client) in self.clients.iter() {
|
||||
if client.subs.contains(&id) {
|
||||
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(_) => (),
|
||||
Err(e) => {
|
||||
warn!("unable to send msg to client err={:?}", e);
|
||||
|
||||
@ -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 {
|
||||
self.time_control = tc;
|
||||
self.phase_end = Some(tc.lobby_timeout());
|
||||
@ -631,8 +642,8 @@ pub fn game_write(tx: &mut Transaction, game: &Game) -> Result<(), Error> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn game_state(tx: &mut Transaction, _account: &Account, id: Uuid) -> Result<Game, Error> {
|
||||
return game_get(tx, id)
|
||||
pub fn game_state(tx: &mut Transaction, account: &Account, id: Uuid) -> Result<Game, Error> {
|
||||
Ok(game_get(tx, id)?.redact(account.id))
|
||||
}
|
||||
|
||||
pub fn game_get(tx: &mut Transaction, id: Uuid) -> Result<Game, Error> {
|
||||
|
||||
@ -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 {
|
||||
match self.phase_end {
|
||||
Some(t) => Utc::now().signed_duration_since(t).num_milliseconds() > 0,
|
||||
|
||||
@ -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 {
|
||||
self.bot = bot;
|
||||
self
|
||||
|
||||
@ -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
|
||||
@ -272,7 +291,7 @@ impl Handler for Connection {
|
||||
|
||||
// if user logged in do some prep work
|
||||
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();
|
||||
|
||||
// check if they have an image that needs to be generated
|
||||
@ -283,23 +302,23 @@ impl Handler for Connection {
|
||||
|
||||
// send account constructs
|
||||
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
|
||||
// and send them to the client
|
||||
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();
|
||||
self.ws.send(RpcMessage::AccountShop(shop)).unwrap();
|
||||
self.send(RpcMessage::AccountShop(shop)).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.commit().unwrap();
|
||||
} else {
|
||||
self.ws.send(RpcMessage::Demo(demo().unwrap())).unwrap();
|
||||
self.send(RpcMessage::Demo(demo().unwrap())).unwrap();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -327,11 +346,11 @@ impl Handler for Connection {
|
||||
_ => (),
|
||||
};
|
||||
|
||||
self.ws.send(reply).unwrap();
|
||||
self.send(reply).unwrap();
|
||||
},
|
||||
Err(e) => {
|
||||
warn!("{:?}", e);
|
||||
self.ws.send(RpcMessage::Error(e.to_string())).unwrap();
|
||||
self.send(RpcMessage::Error(e.to_string())).unwrap();
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user