gameServer2/src/server/handlers/mod.rs
author alfadur
Mon, 16 Jul 2018 22:32:04 +0300
changeset 13526 ba5211dddb21
parent 13449 914f9b970f4d
child 13671 09f4a30e50cc
permissions -rw-r--r--
Assorted chat fixes
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::{
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
     5
    server::HWServer,
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
     6
    actions::{Action, Action::*},
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
     7
    coretypes::ClientId
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
     8
};
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
     9
use protocol::messages::{
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
    10
    HWProtocolMessage,
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
    11
    HWServerMessage::*
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
    12
};
13449
914f9b970f4d Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13424
diff changeset
    13
mod common;
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    14
mod loggingin;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    15
mod lobby;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    16
mod inroom;
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 {
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    20
        HWProtocolMessage::Ping =>
13526
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
    21
            server.react(client_id, vec![Pong.send_self().action()]),
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    22
        HWProtocolMessage::Quit(Some(msg)) =>
13526
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
    23
            server.react(client_id, vec![ByeClient("User quit: ".to_string() + &msg)]),
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    24
        HWProtocolMessage::Quit(None) =>
13526
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
    25
            server.react(client_id, vec![ByeClient("User quit".to_string())]),
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    26
        HWProtocolMessage::Malformed => warn!("Malformed/unknown message"),
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    27
        HWProtocolMessage::Empty => warn!("Empty message"),
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    28
        _ => {
13526
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
    29
            match server.clients[client_id].room_id {
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    30
                None =>
13526
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
    31
                    loggingin::handle(server, client_id, message),
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    32
                Some(id) if id == server.lobby_id =>
13526
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
    33
                    lobby::handle(server, client_id, message),
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
    34
                Some(id) =>
ba5211dddb21 Assorted chat fixes
alfadur
parents: 13449
diff changeset
    35
                    inroom::handle(server, client_id, id, message)
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    36
            }
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    37
        },
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    38
    }
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    39
}