gameServer2/src/server/handlers/lobby.rs
author nemo
Tue, 21 Aug 2018 15:11:28 -0400
branch0.9.24
changeset 13682 f60b3998ba56
parent 13119 1e39b8749072
child 13416 cdf69667593b
permissions -rw-r--r--
only-stats should never create visual gears. and lua should never rely on visual gears being created. critical is just to help ensure ones important to gameplay don't get lost in fast-forward
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
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
     9
pub fn handle(server: &mut HWServer, token: usize, message: HWProtocolMessage) {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    10
    use protocol::messages::HWProtocolMessage::*;
12147
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    11
    match message {
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    12
        Chat(msg) => {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    13
            let chat_msg = ChatMsg(server.clients[token].nick.clone(), msg);
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    14
            server.react(token, vec![SendAllButMe(chat_msg)]);
12147
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    15
        },
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    16
        CreateRoom(name, password) => {
12852
bd35cb2302b3 Quick dirty fix for building
unc0rr
parents: 12147
diff changeset
    17
            let room_exists = server.rooms.iter().find(|&(_, r)| r.name == name).is_some();
12147
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    18
            if room_exists {
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    19
                server.react(token, vec![Warn("Room exists".to_string())]);
12147
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    20
            } else {
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    21
                let flags_msg = ClientFlags("+hr".to_string(), vec![server.clients[token].nick.clone()]);
12147
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    22
                {
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    23
                    let c = &mut server.clients[token];
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    24
                    c.is_master = true;
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    25
                    c.is_ready = true;
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    26
                    c.is_joined_mid_game = false;
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    27
                }
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    28
                server.react(token, vec![
12147
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    29
                    AddRoom(name, password)
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    30
                    , SendMe(flags_msg)
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
        },
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    34
        Join(name, password) => {
12147
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    35
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    36
        },
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    37
        List => warn!("Deprecated LIST message received"),
12147
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    38
        _ => warn!("Incorrect command in lobby state"),
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    39
    }
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    40
}