veloren_server/sys/msg/
mod.rs

1pub mod character_screen;
2pub mod general;
3pub mod in_game;
4pub mod network_events;
5pub mod ping;
6pub mod register;
7pub mod terrain;
8
9use crate::{
10    client::Client,
11    sys::{loot, pets},
12};
13use common_ecs::{System, dispatch};
14use serde::de::DeserializeOwned;
15use specs::DispatcherBuilder;
16
17pub fn add_server_systems(dispatch_builder: &mut DispatcherBuilder) {
18    //run ping after general, as its super fast anyway. also don't get duplicate
19    // disconnect then.
20    dispatch::<character_screen::Sys>(dispatch_builder, &[]);
21    dispatch::<general::Sys>(dispatch_builder, &[]);
22    dispatch::<in_game::Sys>(dispatch_builder, &[]);
23    dispatch::<ping::Sys>(dispatch_builder, &[&general::Sys::sys_name()]);
24    dispatch::<register::Sys>(dispatch_builder, &[]);
25    dispatch::<terrain::Sys>(dispatch_builder, &[]);
26    dispatch::<pets::Sys>(dispatch_builder, &[]);
27    dispatch::<loot::Sys>(dispatch_builder, &[]);
28    dispatch::<network_events::Sys>(dispatch_builder, &[]);
29}
30
31/// handles all send msg and calls a handle fn
32/// Aborts when a error occurred returns cnt of successful msg otherwise
33pub(crate) fn try_recv_all<M, F>(
34    client: &mut Client,
35    stream_id: u8,
36    mut f: F,
37) -> Result<u64, crate::error::Error>
38where
39    M: DeserializeOwned,
40    F: FnMut(&Client, M) -> Result<(), crate::error::Error>,
41{
42    let mut cnt = 0u64;
43    loop {
44        let msg = match client.recv(stream_id) {
45            Ok(Some(msg)) => msg,
46            Ok(None) => break Ok(cnt),
47            Err(e) => break Err(e.into()),
48        };
49        if let Err(e) = f(client, msg) {
50            break Err(e);
51        }
52        cnt += 1;
53    }
54}