gameServer2/src/server/handlers/lobby.rs
author Wuzzy <Wuzzy2@mail.ru>
Thu, 15 Feb 2018 18:32:28 +0100
changeset 13009 67cc3cac4c8e
parent 12852 bd35cb2302b3
child 13119 1e39b8749072
permissions -rw-r--r--
TrophyRace: Show fastest team times (instead of clan times)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12147
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
     1
use mio;
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
     2
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
     3
use server::server::HWServer;
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
     4
use server::actions::Action;
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
     5
use server::actions::Action::*;
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
     6
use protocol::messages::HWProtocolMessage;
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
     7
use protocol::messages::HWServerMessage::*;
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
     8
12852
bd35cb2302b3 Quick dirty fix for building
unc0rr
parents: 12147
diff changeset
     9
pub fn handle(server: &mut HWServer, token: usize, poll: &mio::Poll, message: HWProtocolMessage) {
12147
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    10
    match message {
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    11
        HWProtocolMessage::Chat(msg) => {
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    12
            let chat_msg = ChatMsg(&server.clients[token].nick, &msg).to_raw_protocol();
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    13
            server.react(token, poll, vec![SendAllButMe(chat_msg)]);
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    14
        },
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    15
        HWProtocolMessage::CreateRoom(name, password) => {
12852
bd35cb2302b3 Quick dirty fix for building
unc0rr
parents: 12147
diff changeset
    16
            let room_exists = server.rooms.iter().find(|&(_, r)| r.name == name).is_some();
12147
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    17
            if room_exists {
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    18
                server.react(token, poll, vec![Warn("Room exists".to_string())]);
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    19
            } else {
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    20
                let flags_msg = ClientFlags("+hr", &[&server.clients[token].nick]).to_raw_protocol();
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    21
                {
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    22
                    let c = &mut server.clients[token];
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    23
                    c.is_master = true;
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    24
                    c.is_ready = true;
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    25
                    c.is_joined_mid_game = false;
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    26
                }
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    27
                server.react(token, poll, vec![
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    28
                    AddRoom(name, password)
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    29
                    , SendMe(flags_msg)
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    30
                    ]);
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    31
            }
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    32
        },
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    33
        HWProtocolMessage::Join(name, password) => {
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    34
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    35
        },
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    36
        HWProtocolMessage::List => warn!("Deprecated LIST message received"),
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    37
        _ => warn!("Incorrect command in lobby state"),
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    38
    }
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    39
}