gameServer2/src/server/handlers/inroom.rs
author alfadur
Sat, 07 Jul 2018 20:22:31 +0300
changeset 13483 d79795acaa73
parent 13482 f748a72432f2
child 13485 fb37745c5bca
permissions -rw-r--r--
Mostly implement voting
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12152
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
     1
use mio;
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
     2
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
     3
use protocol::messages::{
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
     4
    HWProtocolMessage,
13483
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
     5
    HWServerMessage::*,
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
     6
    server_chat
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
     7
};
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
     8
use server::{
13483
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
     9
    coretypes::{ClientId, Voting, VoteType},
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    10
    server::HWServer,
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    11
    room::HWRoom,
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    12
    actions::{Action, Action::*}
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    13
};
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    14
use utils::is_name_illegal;
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    15
use std::mem::swap;
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    16
use base64::{encode, decode};
13450
d3c86ade3d4d Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13449
diff changeset
    17
use super::common::rnd_action;
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    18
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    19
#[derive(Clone)]
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    20
struct ByMsg<'a> {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    21
    messages: &'a[u8]
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    22
}
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    23
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    24
impl <'a> Iterator for ByMsg<'a> {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    25
    type Item = &'a[u8];
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    26
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    27
    fn next(&mut self) -> Option<<Self as Iterator>::Item> {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    28
        if let Some(size) = self.messages.get(0) {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    29
            let (msg, next) = self.messages.split_at(*size as usize + 1);
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    30
            self.messages = next;
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    31
            Some(msg)
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    32
        } else {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    33
            None
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    34
        }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    35
    }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    36
}
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    37
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    38
fn by_msg(source: &Vec<u8>) -> ByMsg {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    39
    ByMsg {messages: &source[..]}
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    40
}
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    41
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    42
const VALID_MESSAGES: &[u8] =
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    43
    b"M#+LlRrUuDdZzAaSjJ,NpPwtgfhbc12345\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A";
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    44
const NON_TIMED_MESSAGES: &[u8] = b"M#hb";
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    45
13434
4c5ed27b1ff8 stabilization
alfadur
parents: 13433
diff changeset
    46
#[cfg(canhazslicepatterns)]
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    47
fn is_msg_valid(msg: &[u8], team_indices: &[u8]) -> bool {
13429
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13428
diff changeset
    48
    match msg {
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13428
diff changeset
    49
        [size, typ, body..] => VALID_MESSAGES.contains(typ)
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13428
diff changeset
    50
            && match body {
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    51
                [1...8, team, ..] if *typ == b'h' => team_indices.contains(team),
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    52
                _ => *typ != b'h'
13429
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13428
diff changeset
    53
            },
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13428
diff changeset
    54
        _ => false
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    55
    }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    56
}
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    57
13434
4c5ed27b1ff8 stabilization
alfadur
parents: 13433
diff changeset
    58
fn is_msg_valid(msg: &[u8], team_indices: &[u8]) -> bool {
4c5ed27b1ff8 stabilization
alfadur
parents: 13433
diff changeset
    59
    if let Some(typ) = msg.get(1) {
4c5ed27b1ff8 stabilization
alfadur
parents: 13433
diff changeset
    60
        VALID_MESSAGES.contains(typ)
4c5ed27b1ff8 stabilization
alfadur
parents: 13433
diff changeset
    61
    } else {
4c5ed27b1ff8 stabilization
alfadur
parents: 13433
diff changeset
    62
        false
4c5ed27b1ff8 stabilization
alfadur
parents: 13433
diff changeset
    63
    }
4c5ed27b1ff8 stabilization
alfadur
parents: 13433
diff changeset
    64
}
4c5ed27b1ff8 stabilization
alfadur
parents: 13433
diff changeset
    65
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    66
fn is_msg_empty(msg: &[u8]) -> bool {
13434
4c5ed27b1ff8 stabilization
alfadur
parents: 13433
diff changeset
    67
    msg.get(1).filter(|t| **t == b'+').is_some()
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    68
}
12152
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    69
13448
2501428303a2 Fix team remove synchronization
alfadur
parents: 13444
diff changeset
    70
fn is_msg_timed(msg: &[u8]) -> bool {
2501428303a2 Fix team remove synchronization
alfadur
parents: 13444
diff changeset
    71
    msg.get(1).filter(|t| !NON_TIMED_MESSAGES.contains(t)).is_some()
2501428303a2 Fix team remove synchronization
alfadur
parents: 13444
diff changeset
    72
}
2501428303a2 Fix team remove synchronization
alfadur
parents: 13444
diff changeset
    73
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    74
pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) {
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    75
    use protocol::messages::HWProtocolMessage::*;
12152
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
    76
    match message {
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    77
        Part(None) => server.react(client_id, vec![
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    78
            MoveToLobby("part".to_string())]),
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    79
        Part(Some(msg)) => server.react(client_id, vec![
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    80
            MoveToLobby(format!("part: {}", msg))]),
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    81
        Chat(msg) => {
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    82
            let actions = {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    83
                let c = &mut server.clients[client_id];
13449
914f9b970f4d Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13448
diff changeset
    84
                let chat_msg = ChatMsg {nick: c.nick.clone(), msg: msg};
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    85
                if let Some(room_id) = c.room_id {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    86
                    vec![chat_msg.send_all().in_room(room_id).but_self().action()]
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    87
                } else {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    88
                    Vec::new()
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    89
                }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    90
            };
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    91
            server.react(client_id, actions);
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    92
        },
13482
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
    93
        Fix => {
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
    94
            if let (c, Some(r)) = server.client_and_room(client_id) {
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
    95
                if c.is_admin { r.is_fixed = true }
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
    96
            }
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
    97
        }
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
    98
        Unfix => {
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
    99
            if let (c, Some(r)) = server.client_and_room(client_id) {
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   100
                if c.is_admin { r.is_fixed = false }
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   101
            }
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   102
        }
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   103
        Greeting(text) => {
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   104
            if let (c, Some(r)) = server.client_and_room(client_id) {
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   105
                if c.is_admin || c.is_master && !r.is_fixed {
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   106
                    r.greeting = text
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   107
                }
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   108
            }
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   109
        }
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   110
        RoomName(new_name) => {
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   111
            let actions =
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   112
                if is_name_illegal(&new_name) {
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   113
                    vec![Warn("Illegal room name! A room name must be between 1-40 characters long, must not have a trailing or leading space and must not have any of these characters: $()*+?[]^{|}".to_string())]
13482
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   114
                } else if server.room(client_id).map(|r| r.is_fixed).unwrap_or(false) {
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   115
                    vec![Warn("Access denied.".to_string())]
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   116
                } else if server.has_room(&new_name) {
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   117
                    vec![Warn("A room with the same name already exists.".to_string())]
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   118
                } else {
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   119
                    let mut old_name = new_name.clone();
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   120
                    if let (_, Some(r)) = server.client_and_room(client_id) {
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   121
                        swap(&mut r.name, &mut old_name);
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   122
                        vec![SendRoomUpdate(Some(old_name))]
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   123
                    } else {
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   124
                        Vec::new()
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   125
                    }
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   126
                };
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   127
            server.react(client_id, actions);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   128
        },
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   129
        ToggleReady => {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   130
            let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   131
                let flags = if c.is_ready {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   132
                    r.ready_players_number -= 1;
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   133
                    "-r"
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   134
                } else {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   135
                    r.ready_players_number += 1;
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   136
                    "+r"
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   137
                };
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   138
                c.is_ready = !c.is_ready;
13482
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   139
                let mut v =
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   140
                    vec![ClientFlags(flags.to_string(), vec![c.nick.clone()])
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   141
                        .send_all().in_room(r.id).action()];
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   142
                if r.is_fixed && r.ready_players_number as u32 == r.players_number {
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   143
                    v.push(StartRoomGame(r.id))
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   144
                }
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   145
                v
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   146
            } else {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   147
                Vec::new()
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   148
            };
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   149
            server.react(client_id, actions);
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   150
        }
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   151
        AddTeam(info) => {
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   152
            let mut actions = Vec::new();
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   153
            if let (c, Some(r)) = server.client_and_room(client_id) {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   154
                let room_id = r.id;
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   155
                if r.teams.len() >= r.team_limit as usize {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   156
                    actions.push(Warn("Too many teams!".to_string()))
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   157
                } else if r.addable_hedgehogs() == 0 {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   158
                    actions.push(Warn("Too many hedgehogs!".to_string()))
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   159
                } else if r.find_team(|t| t.name == info.name) != None {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   160
                    actions.push(Warn("There's already a team with same name in the list.".to_string()))
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   161
                } else if r.game_info.is_some() {
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   162
                    actions.push(Warn("Joining not possible: Round is in progress.".to_string()))
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   163
                } else {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   164
                    let team = r.add_team(c.id, info);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   165
                    c.teams_in_game += 1;
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   166
                    c.clan = Some(team.color);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   167
                    actions.push(TeamAccepted(team.name.clone())
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   168
                        .send_self().action());
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   169
                    actions.push(TeamAdd(HWRoom::team_info(&c, team))
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   170
                        .send_all().in_room(room_id).but_self().action());
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   171
                    actions.push(TeamColor(team.name.clone(), team.color)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   172
                        .send_all().in_room(room_id).action());
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   173
                    actions.push(HedgehogsNumber(team.name.clone(), team.hedgehogs_number)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   174
                        .send_all().in_room(room_id).action());
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   175
                    actions.push(SendRoomUpdate(None));
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   176
                }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   177
            }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   178
            server.react(client_id, actions);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   179
        },
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   180
        RemoveTeam(name) => {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   181
            let mut actions = Vec::new();
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   182
            if let (c, Some(r)) = server.client_and_room(client_id) {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   183
                match r.find_team_owner(&name) {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   184
                    None =>
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   185
                        actions.push(Warn("Error: The team you tried to remove does not exist.".to_string())),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   186
                    Some((id, _)) if id != client_id =>
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   187
                        actions.push(Warn("You can't remove a team you don't own.".to_string())),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   188
                    Some((_, name)) => {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   189
                        c.teams_in_game -= 1;
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   190
                        c.clan = r.find_team_color(c.id);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   191
                        actions.push(Action::RemoveTeam(name.to_string()));
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   192
                    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   193
                }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   194
            };
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   195
            server.react(client_id, actions);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   196
        },
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   197
        SetHedgehogsNumber(team_name, number) => {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   198
            let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   199
                let room_id = r.id;
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   200
                let addable_hedgehogs = r.addable_hedgehogs();
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   201
                if let Some((_, mut team)) = r.find_team_and_owner_mut(|t| t.name == team_name) {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   202
                    if !c.is_master {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   203
                        vec![ProtocolError("You're not the room master!".to_string())]
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   204
                    } else if number < 1 || number > 8
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   205
                           || number > addable_hedgehogs + team.hedgehogs_number {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   206
                        vec![HedgehogsNumber(team.name.clone(), team.hedgehogs_number)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   207
                            .send_self().action()]
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   208
                    } else {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   209
                        team.hedgehogs_number = number;
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   210
                        vec![HedgehogsNumber(team.name.clone(), number)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   211
                            .send_all().in_room(room_id).but_self().action()]
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   212
                    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   213
                } else {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   214
                    vec![(Warn("No such team.".to_string()))]
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   215
                }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   216
            } else {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   217
                Vec::new()
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   218
            };
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   219
            server.react(client_id, actions);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   220
        },
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   221
        SetTeamColor(team_name, color) => {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   222
            let mut owner_id = None;
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   223
            let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   224
                let room_id = r.id;
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   225
                if let Some((owner, mut team)) = r.find_team_and_owner_mut(|t| t.name == team_name) {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   226
                    if !c.is_master {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   227
                        vec![ProtocolError("You're not the room master!".to_string())]
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   228
                    } else if false  {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   229
                        Vec::new()
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   230
                    } else {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   231
                        owner_id = Some(owner);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   232
                        team.color = color;
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   233
                        vec![TeamColor(team.name.clone(), color)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   234
                            .send_all().in_room(room_id).but_self().action()]
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   235
                    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   236
                } else {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   237
                    vec![(Warn("No such team.".to_string()))]
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   238
                }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   239
            } else {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   240
                Vec::new()
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   241
            };
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   242
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   243
            if let Some(id) = owner_id {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   244
                server.clients[id].clan = Some(color);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   245
            }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   246
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   247
            server.react(client_id, actions);
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   248
        },
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   249
        Cfg(cfg) => {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   250
            let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
13482
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   251
                if r.is_fixed {
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   252
                    vec![Warn("Access denied.".to_string())]
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13450
diff changeset
   253
                } else if !c.is_master {
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   254
                    vec![ProtocolError("You're not the room master!".to_string())]
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   255
                } else {
13444
c4f917c6be51 add missing message tests
alfadur
parents: 13434
diff changeset
   256
                    let v = vec![cfg.to_server_msg()
c4f917c6be51 add missing message tests
alfadur
parents: 13434
diff changeset
   257
                        .send_all().in_room(r.id).but_self().action()];
c4f917c6be51 add missing message tests
alfadur
parents: 13434
diff changeset
   258
                    r.set_config(cfg);
c4f917c6be51 add missing message tests
alfadur
parents: 13434
diff changeset
   259
                    v
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   260
                }
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   261
            } else {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   262
                Vec::new()
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   263
            };
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   264
            server.react(client_id, actions);
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   265
        }
13483
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   266
        CallVote(None) => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   267
            server.react(client_id, vec![
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   268
                server_chat("Available callvote commands: kick <nickname>, map <name>, pause, newseed, hedgehogs <number>")
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   269
                    .send_self().action()])
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   270
        }
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   271
        CallVote(Some(kind)) => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   272
            let (room_id, is_in_game) = server.room(client_id)
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   273
                .map(|r| (r.id, r.game_info.is_some())).unwrap();
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   274
            let error = match &kind {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   275
                VoteType::Kick(nick) => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   276
                    if server.find_client(&nick).filter(|c| c.room_id == Some(room_id)).is_some() {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   277
                        None
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   278
                    } else {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   279
                        Some("/callvote kick: No such user!")
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   280
                    }
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   281
                },
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   282
                VoteType::Map(None) => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   283
                    Some("/callvote map: Not implemented")
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   284
                },
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   285
                VoteType::Map(Some(name)) => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   286
                    Some("/callvote map: Not implemented")
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   287
                },
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   288
                VoteType::Pause => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   289
                    if is_in_game {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   290
                        None
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   291
                    } else {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   292
                        Some("/callvote pause: No game in progress!")
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   293
                    }
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   294
                },
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   295
                VoteType::NewSeed => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   296
                    None
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   297
                },
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   298
                VoteType::HedgehogsPerTeam(number) => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   299
                    match number {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   300
                        1...8 => None,
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   301
                        _ => Some("/callvote hedgehogs: Specify number from 1 to 8.")
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   302
                    }
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   303
                },
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   304
            };
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   305
            match error {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   306
                None => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   307
                    let voting = Voting::new(kind, server.room_clients(client_id));
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   308
                    server.room(client_id).unwrap().voting = Some(voting);
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   309
                    server.react(client_id, vec![
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   310
                        server_chat("New voting started: ")
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   311
                            .send_all().in_room(room_id).action(),
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   312
                        AddVote{ vote: true, is_forced: false}]);
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   313
                }
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   314
                Some(msg) => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   315
                    server.react(client_id, vec![
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   316
                        server_chat(msg).send_self().action()])
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   317
                }
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   318
            }
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   319
        }
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   320
        Vote(vote) => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   321
            let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   322
                vec![AddVote{ vote, is_forced: false }]
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   323
            } else {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   324
                Vec::new()
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   325
            };
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   326
            server.react(client_id, actions);
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   327
        }
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   328
        ForceVote(vote) => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   329
            let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   330
                vec![AddVote{ vote, is_forced: c.is_admin} ]
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   331
            } else {
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   332
                Vec::new()
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   333
            };
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   334
            server.react(client_id, actions);
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
   335
        }
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   336
        StartGame => {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   337
            let actions = if let (_, Some(r)) = server.client_and_room(client_id) {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   338
                vec![StartRoomGame(r.id)]
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   339
            } else {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   340
                Vec::new()
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   341
            };
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   342
            server.react(client_id, actions);
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   343
        }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   344
        EngineMessage(em) => {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   345
            let mut actions = Vec::new();
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   346
            if let (c, Some(r)) = server.client_and_room(client_id) {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   347
                if c.teams_in_game > 0 {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   348
                    let decoding = decode(&em[..]).unwrap();
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   349
                    let messages = by_msg(&decoding);
13448
2501428303a2 Fix team remove synchronization
alfadur
parents: 13444
diff changeset
   350
                    let valid = messages.filter(|m| is_msg_valid(m, &c.team_indices));
2501428303a2 Fix team remove synchronization
alfadur
parents: 13444
diff changeset
   351
                    let non_empty = valid.clone().filter(|m| !is_msg_empty(m));
2501428303a2 Fix team remove synchronization
alfadur
parents: 13444
diff changeset
   352
                    let sync_msg = valid.clone().filter(|m| is_msg_timed(m))
2501428303a2 Fix team remove synchronization
alfadur
parents: 13444
diff changeset
   353
                        .last().map(|m| if is_msg_empty(m) {Some(encode(m))} else {None});
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   354
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   355
                    let em_response = encode(&valid.flat_map(|msg| msg).cloned().collect::<Vec<_>>());
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   356
                    if !em_response.is_empty() {
13433
c8425fbcf1d9 Fix spectators joining midgame
alfadur
parents: 13432
diff changeset
   357
                        actions.push(ForwardEngineMessage(vec![em_response])
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   358
                            .send_all().in_room(r.id).but_self().action());
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   359
                    }
13432
6f6a866c86a2 Send more data on room joining
alfadur
parents: 13431
diff changeset
   360
                    let em_log = encode(&non_empty.flat_map(|msg| msg).cloned().collect::<Vec<_>>());
6f6a866c86a2 Send more data on room joining
alfadur
parents: 13431
diff changeset
   361
                    if let Some(ref mut info) = r.game_info {
13434
4c5ed27b1ff8 stabilization
alfadur
parents: 13433
diff changeset
   362
                        if !em_log.is_empty() {
13433
c8425fbcf1d9 Fix spectators joining midgame
alfadur
parents: 13432
diff changeset
   363
                            info.msg_log.push(em_log);
c8425fbcf1d9 Fix spectators joining midgame
alfadur
parents: 13432
diff changeset
   364
                        }
13448
2501428303a2 Fix team remove synchronization
alfadur
parents: 13444
diff changeset
   365
                        if let Some(msg) = sync_msg {
2501428303a2 Fix team remove synchronization
alfadur
parents: 13444
diff changeset
   366
                            info.sync_msg = msg;
13432
6f6a866c86a2 Send more data on room joining
alfadur
parents: 13431
diff changeset
   367
                        }
6f6a866c86a2 Send more data on room joining
alfadur
parents: 13431
diff changeset
   368
                    }
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   369
                }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   370
            }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   371
            server.react(client_id, actions)
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   372
        }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   373
        RoundFinished => {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   374
            let mut actions = Vec::new();
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   375
            if let (c, Some(r)) = server.client_and_room(client_id) {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   376
                if c.is_in_game {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   377
                    c.is_in_game = false;
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   378
                    actions.push(ClientFlags("-g".to_string(), vec![c.nick.clone()]).
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   379
                        send_all().in_room(r.id).action());
13431
f091f69d59e4 Additional round cleanup
alfadur
parents: 13429
diff changeset
   380
                    if r.game_info.is_some() {
f091f69d59e4 Additional round cleanup
alfadur
parents: 13429
diff changeset
   381
                        for team in r.client_teams(c.id) {
f091f69d59e4 Additional round cleanup
alfadur
parents: 13429
diff changeset
   382
                            actions.push(SendTeamRemovalMessage(team.name.clone()));
f091f69d59e4 Additional round cleanup
alfadur
parents: 13429
diff changeset
   383
                        }
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   384
                    }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   385
                }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   386
            }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   387
            server.react(client_id, actions)
13449
914f9b970f4d Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13448
diff changeset
   388
        },
13450
d3c86ade3d4d Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13449
diff changeset
   389
        Rnd(v) => {
d3c86ade3d4d Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13449
diff changeset
   390
            let actions = rnd_action(v, server.room(client_id));
d3c86ade3d4d Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13449
diff changeset
   391
            server.react(client_id, actions)
d3c86ade3d4d Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13449
diff changeset
   392
        },
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   393
        _ => warn!("Unimplemented!")
12152
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
   394
    }
03ccb89820f3 Room creation halfplemented
unc0rr
parents:
diff changeset
   395
}