2020-08-07 01:59:28 +00:00
|
|
|
use super::SysTimer;
|
|
|
|
use crate::client::Client;
|
|
|
|
use common::{
|
|
|
|
comp::group::{Invite, PendingInvites},
|
Redo Network Frontend.
Rather than having a single Stream to handle ALL data, seperate into multiple streams:
- Ping Stream, for seperate PINGS
- Register Stream, only used till the client is registered, then no longer used!
- General Stream, used for msg that can occur always
- NotInGame Stream, used for everything NOT ingame, e.g. Character Screen
- InGame Stream, used for all GAME data, players, terrain, entities, etc...
This version does compile, and gets the client registered (with auth too) but doesnt get to the char screen yet.
This fixes also the ignoring messages problem we had, as we are not sending data to the register stream!
This fixes also the problem that the server had to sleep for the Stream Creation, as the Server is now creating the streams and client has to sleep.
2020-10-04 18:20:18 +00:00
|
|
|
msg::{InviteAnswer, ServerInGameMsg},
|
2020-08-29 06:39:16 +00:00
|
|
|
span,
|
2020-08-07 01:59:28 +00:00
|
|
|
sync::Uid,
|
|
|
|
};
|
|
|
|
use specs::{Entities, Join, ReadStorage, System, Write, WriteStorage};
|
|
|
|
|
|
|
|
/// This system removes timed out group invites
|
|
|
|
pub struct Sys;
|
|
|
|
impl<'a> System<'a> for Sys {
|
|
|
|
#[allow(clippy::type_complexity)] // TODO: Pending review in #587
|
|
|
|
type SystemData = (
|
|
|
|
Entities<'a>,
|
|
|
|
WriteStorage<'a, Invite>,
|
|
|
|
WriteStorage<'a, PendingInvites>,
|
|
|
|
WriteStorage<'a, Client>,
|
|
|
|
ReadStorage<'a, Uid>,
|
|
|
|
Write<'a, SysTimer<Self>>,
|
|
|
|
);
|
|
|
|
|
|
|
|
fn run(
|
|
|
|
&mut self,
|
|
|
|
(entities, mut invites, mut pending_invites, mut clients, uids, mut timer): Self::SystemData,
|
|
|
|
) {
|
2020-09-07 04:59:16 +00:00
|
|
|
span!(_guard, "run", "invite_timeout::Sys::run");
|
2020-08-07 01:59:28 +00:00
|
|
|
timer.start();
|
|
|
|
|
|
|
|
let now = std::time::Instant::now();
|
|
|
|
|
|
|
|
let timed_out_invites = (&entities, &invites)
|
|
|
|
.join()
|
|
|
|
.filter_map(|(invitee, Invite(inviter))| {
|
|
|
|
// Retrieve timeout invite from pending invites
|
|
|
|
let pending = &mut pending_invites.get_mut(*inviter)?.0;
|
|
|
|
let index = pending.iter().position(|p| p.0 == invitee)?;
|
|
|
|
|
|
|
|
// Stop if not timed out
|
|
|
|
if pending[index].1 > now {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove pending entry
|
|
|
|
pending.swap_remove(index);
|
|
|
|
|
|
|
|
// If no pending invites remain remove the component
|
|
|
|
if pending.is_empty() {
|
|
|
|
pending_invites.remove(*inviter);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inform inviter of timeout
|
|
|
|
if let (Some(client), Some(target)) =
|
|
|
|
(clients.get_mut(*inviter), uids.get(invitee).copied())
|
|
|
|
{
|
Redo Network Frontend.
Rather than having a single Stream to handle ALL data, seperate into multiple streams:
- Ping Stream, for seperate PINGS
- Register Stream, only used till the client is registered, then no longer used!
- General Stream, used for msg that can occur always
- NotInGame Stream, used for everything NOT ingame, e.g. Character Screen
- InGame Stream, used for all GAME data, players, terrain, entities, etc...
This version does compile, and gets the client registered (with auth too) but doesnt get to the char screen yet.
This fixes also the ignoring messages problem we had, as we are not sending data to the register stream!
This fixes also the problem that the server had to sleep for the Stream Creation, as the Server is now creating the streams and client has to sleep.
2020-10-04 18:20:18 +00:00
|
|
|
client.send_in_game(ServerInGameMsg::InviteComplete {
|
2020-08-07 01:59:28 +00:00
|
|
|
target,
|
|
|
|
answer: InviteAnswer::TimedOut,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(invitee)
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
for entity in timed_out_invites {
|
|
|
|
invites.remove(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
timer.end();
|
|
|
|
}
|
|
|
|
}
|