rust/hedgewars-server/src/server/handlers.rs
author unc0rr
Sun, 16 Dec 2018 00:12:29 +0100
changeset 14462 98ef2913ec73
parent 14420 06672690d71b
child 14676 455865ccd36c
permissions -rw-r--r--
Apply rustfmt to all files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
     1
use mio;
13526
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
     2
use std::{io, io::Write};
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
     3
13526
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
     4
use super::{
14462
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
     5
    actions::{Action, Action::*},
14380
cc99f7c673c7 try again 🙃
alfadur
parents: 13810
diff changeset
     6
    core::HWServer,
14462
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
     7
    coretypes::ClientId,
13526
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
     8
};
14462
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
     9
use crate::protocol::messages::{HWProtocolMessage, HWServerMessage::*};
13810
0463a4221327 cleanup crate imports
alfadur
parents: 13803
diff changeset
    10
use log::*;
13671
09f4a30e50cc Rust 2018 conversion
alfadur
parents: 13526
diff changeset
    11
14462
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    12
mod checker;
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    13
mod common;
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    14
mod inroom;
14462
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    15
mod lobby;
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    16
mod loggingin;
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    17
13526
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
    18
pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) {
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    19
    match message {
14462
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    20
        HWProtocolMessage::Ping => server.react(client_id, vec![Pong.send_self().action()]),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    21
        HWProtocolMessage::Quit(Some(msg)) => {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    22
            server.react(client_id, vec![ByeClient("User quit: ".to_string() + &msg)])
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    23
        }
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    24
        HWProtocolMessage::Quit(None) => {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    25
            server.react(client_id, vec![ByeClient("User quit".to_string())])
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    26
        }
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    27
        HWProtocolMessage::Malformed => warn!("Malformed/unknown message"),
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    28
        HWProtocolMessage::Empty => warn!("Empty message"),
14462
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    29
        _ => match server.clients[client_id].room_id {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    30
            None => loggingin::handle(server, client_id, message),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    31
            Some(id) if id == server.lobby_id => lobby::handle(server, client_id, message),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14420
diff changeset
    32
            Some(id) => inroom::handle(server, client_id, id, message),
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    33
        },
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    34
    }
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    35
}