rust/hedgewars-server/src/server/actions.rs
author alfadur <mail@none>
Wed, 06 Feb 2019 00:14:04 +0300
changeset 14686 9f98086de1b6
parent 14683 932ff7683653
child 14687 5122c584804e
permissions -rw-r--r--
Server action refactoring part 9 of N
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
     1
use super::{
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
     2
    client::HWClient,
14374
e5db279308d7 dispose of server mods
alfadur
parents: 14350
diff changeset
     3
    core::HWServer,
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
     4
    coretypes::{ClientId, GameCfg, RoomId, VoteType},
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
     5
    handlers,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
     6
    room::HWRoom,
13523
8c5dd562c9f7 Add room flags
alfadur
parents: 13520
diff changeset
     7
    room::{GameInfo, RoomFlags},
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
     8
};
13666
09f4a30e50cc Rust 2018 conversion
alfadur
parents: 13527
diff changeset
     9
use crate::{
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    10
    protocol::messages::{server_chat, HWProtocolMessage, HWServerMessage, HWServerMessage::*},
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    11
    utils::to_engine_msg,
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    12
};
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    13
use rand::{distributions::Uniform, thread_rng, Rng};
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    14
use std::{io, io::Write, iter::once, mem::replace};
12138
e0bf51609062 Introduce actions, just like in the old server
unc0rr
parents:
diff changeset
    15
14456
a077aac9df01 Start database interaction implementation
unc0rr
parents: 14415
diff changeset
    16
#[cfg(feature = "official-server")]
a077aac9df01 Start database interaction implementation
unc0rr
parents: 14415
diff changeset
    17
use super::database;
a077aac9df01 Start database interaction implementation
unc0rr
parents: 14415
diff changeset
    18
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    19
pub enum Destination {
13426
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
    20
    ToId(ClientId),
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    21
    ToSelf,
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
    22
    ToAll {
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    23
        room_id: Option<RoomId>,
13520
1ee192f13456 Better packing for clients
alfadur
parents: 13480
diff changeset
    24
        protocol: Option<u16>,
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    25
        skip_self: bool,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    26
    },
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    27
}
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    28
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    29
pub struct PendingMessage {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    30
    pub destination: Destination,
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    31
    pub message: HWServerMessage,
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    32
}
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    33
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    34
impl PendingMessage {
13426
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
    35
    pub fn send(message: HWServerMessage, client_id: ClientId) -> PendingMessage {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    36
        PendingMessage {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    37
            destination: Destination::ToId(client_id),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    38
            message,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    39
        }
13426
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
    40
    }
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
    41
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    42
    pub fn send_self(message: HWServerMessage) -> PendingMessage {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    43
        PendingMessage {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    44
            destination: Destination::ToSelf,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    45
            message,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    46
        }
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    47
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    48
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    49
    pub fn send_all(message: HWServerMessage) -> PendingMessage {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    50
        let destination = Destination::ToAll {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    51
            room_id: None,
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    52
            protocol: None,
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    53
            skip_self: false,
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    54
        };
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    55
        PendingMessage {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    56
            destination,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    57
            message,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    58
        }
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    59
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    60
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    61
    pub fn in_room(mut self, clients_room_id: RoomId) -> PendingMessage {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    62
        if let Destination::ToAll {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    63
            ref mut room_id, ..
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    64
        } = self.destination
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    65
        {
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    66
            *room_id = Some(clients_room_id)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    67
        }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    68
        self
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    69
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    70
13520
1ee192f13456 Better packing for clients
alfadur
parents: 13480
diff changeset
    71
    pub fn with_protocol(mut self, protocol_number: u16) -> PendingMessage {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    72
        if let Destination::ToAll {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    73
            ref mut protocol, ..
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    74
        } = self.destination
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    75
        {
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    76
            *protocol = Some(protocol_number)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    77
        }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    78
        self
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    79
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    80
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    81
    pub fn but_self(mut self) -> PendingMessage {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    82
        if let Destination::ToAll {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    83
            ref mut skip_self, ..
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    84
        } = self.destination
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    85
        {
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    86
            *skip_self = true
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    87
        }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    88
        self
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    89
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    90
}
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    91
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
    92
impl HWServerMessage {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    93
    pub fn send(self, client_id: ClientId) -> PendingMessage {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    94
        PendingMessage::send(self, client_id)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    95
    }
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    96
    pub fn send_self(self) -> PendingMessage {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    97
        PendingMessage::send_self(self)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    98
    }
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
    99
    pub fn send_all(self) -> PendingMessage {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   100
        PendingMessage::send_all(self)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   101
    }
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
   102
}
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
   103
12138
e0bf51609062 Introduce actions, just like in the old server
unc0rr
parents:
diff changeset
   104
pub enum Action {
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
   105
    ChangeMaster(RoomId, Option<ClientId>),
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   106
    StartRoomGame(RoomId),
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   107
    SendTeamRemovalMessage(String),
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   108
    FinishRoomGame(RoomId),
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   109
    SendRoomData {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   110
        to: ClientId,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   111
        teams: bool,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   112
        config: bool,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   113
        flags: bool,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   114
    },
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   115
    ApplyVoting(VoteType, RoomId),
12138
e0bf51609062 Introduce actions, just like in the old server
unc0rr
parents:
diff changeset
   116
}
12144
589a2d7d3dc5 More refactoring
unc0rr
parents: 12143
diff changeset
   117
589a2d7d3dc5 More refactoring
unc0rr
parents: 12143
diff changeset
   118
use self::Action::*;
589a2d7d3dc5 More refactoring
unc0rr
parents: 12143
diff changeset
   119
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
   120
pub fn run_action(server: &mut HWServer, client_id: usize, action: Action) {
12144
589a2d7d3dc5 More refactoring
unc0rr
parents: 12143
diff changeset
   121
    match action {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   122
        SendRoomData {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   123
            to,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   124
            teams,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   125
            config,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   126
            flags,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   127
        } => {
13424
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   128
            let room_id = server.clients[client_id].room_id;
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   129
            if let Some(r) = room_id.and_then(|id| server.rooms.get(id)) {
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   130
                if config {
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   131
                    /*                    actions.push(
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   132
                        ConfigEntry("FULLMAPCONFIG".to_string(), r.map_config())
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   133
                            .send(to)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   134
                            .action(),
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   135
                    )*/
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   136
;
13524
5359ff75da3a indulge clippy
alfadur
parents: 13523
diff changeset
   137
                    for cfg in r.game_config() {
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   138
                        //actions.push(cfg.to_server_msg().send(to).action());
13424
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   139
                    }
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   140
                }
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   141
                if teams {
13427
6f6a866c86a2 Send more data on room joining
alfadur
parents: 13426
diff changeset
   142
                    let current_teams = match r.game_info {
6f6a866c86a2 Send more data on room joining
alfadur
parents: 13426
diff changeset
   143
                        Some(ref info) => &info.teams_at_start,
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   144
                        None => &r.teams,
13427
6f6a866c86a2 Send more data on room joining
alfadur
parents: 13426
diff changeset
   145
                    };
6f6a866c86a2 Send more data on room joining
alfadur
parents: 13426
diff changeset
   146
                    for (owner_id, team) in current_teams.iter() {
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   147
                        /*actions.push(
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   148
                            TeamAdd(HWRoom::team_info(&server.clients[*owner_id], &team))
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   149
                                .send(to)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   150
                                .action(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   151
                        );
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   152
                        actions.push(TeamColor(team.name.clone(), team.color).send(to).action());
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   153
                        actions.push(
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   154
                            HedgehogsNumber(team.name.clone(), team.hedgehogs_number)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   155
                                .send(to)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   156
                                .action(),
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   157
                        );*/
13424
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   158
                    }
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   159
                }
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   160
                if flags {
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   161
                    if let Some(id) = r.master_id {
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   162
                        /*
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   163
                                                actions.push(
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   164
                                                    ClientFlags("+h".to_string(), vec![server.clients[id].nick.clone()])
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   165
                                                        .send(to)
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   166
                                                        .action(),
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   167
                                                );
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   168
                        */
13424
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   169
                    }
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   170
                    let nicks: Vec<_> = server
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   171
                        .clients
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   172
                        .iter()
13520
1ee192f13456 Better packing for clients
alfadur
parents: 13480
diff changeset
   173
                        .filter(|(_, c)| c.room_id == Some(r.id) && c.is_ready())
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   174
                        .map(|(_, c)| c.nick.clone())
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   175
                        .collect();
13424
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   176
                    if !nicks.is_empty() {
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   177
                        /*actions.push(ClientFlags("+r".to_string(), nicks).send(to).action())*/
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   178
;
13424
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   179
                    }
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   180
                }
d8354cb98b98 Send teams&flags on entering a room
alfadur
parents: 13423
diff changeset
   181
            }
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   182
        }
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   183
        ApplyVoting(kind, room_id) => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   184
            let mut actions = Vec::new();
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   185
            let mut id = client_id;
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   186
            match kind {
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   187
                VoteType::Kick(nick) => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   188
                    if let Some(c) = server.find_client(&nick) {
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   189
                        if c.room_id == Some(room_id) {
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   190
                            id = c.id;
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   191
                            //actions.push(Kicked.send_self().action());
14675
dfe652c53470 Server action refactoring part 6 of N
alfadur <mail@none>
parents: 14673
diff changeset
   192
                            //actions.push(MoveToLobby("kicked".to_string()));
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   193
                        }
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   194
                    }
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   195
                }
13527
e3ae9eea0689 Implement map voting
alfadur
parents: 13524
diff changeset
   196
                VoteType::Map(None) => (),
e3ae9eea0689 Implement map voting
alfadur
parents: 13524
diff changeset
   197
                VoteType::Map(Some(name)) => {
e3ae9eea0689 Implement map voting
alfadur
parents: 13524
diff changeset
   198
                    if let Some(location) = server.rooms[room_id].load_config(&name) {
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   199
                        /*actions.push(
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   200
                            server_chat(location.to_string())
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   201
                                .send_all()
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   202
                                .in_room(room_id)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   203
                                .action(),
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   204
                        );*/
14686
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   205
                        //actions.push(SendRoomUpdate(None));
13527
e3ae9eea0689 Implement map voting
alfadur
parents: 13524
diff changeset
   206
                        for (_, c) in server.clients.iter() {
e3ae9eea0689 Implement map voting
alfadur
parents: 13524
diff changeset
   207
                            if c.room_id == Some(room_id) {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   208
                                actions.push(SendRoomData {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   209
                                    to: c.id,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   210
                                    teams: false,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   211
                                    config: true,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   212
                                    flags: false,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   213
                                })
13527
e3ae9eea0689 Implement map voting
alfadur
parents: 13524
diff changeset
   214
                            }
e3ae9eea0689 Implement map voting
alfadur
parents: 13524
diff changeset
   215
                        }
e3ae9eea0689 Implement map voting
alfadur
parents: 13524
diff changeset
   216
                    }
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   217
                }
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   218
                VoteType::Pause => {
13480
fb37745c5bca complete newseed voting
alfadur
parents: 13478
diff changeset
   219
                    if let Some(ref mut info) = server.rooms[room_id].game_info {
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   220
                        info.is_paused = !info.is_paused;
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   221
                        /*actions.push(
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   222
                            server_chat("Pause toggled.".to_string())
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   223
                                .send_all()
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   224
                                .in_room(room_id)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   225
                                .action(),
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   226
                        );*/
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   227
                        /*actions.push(
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   228
                            ForwardEngineMessage(vec![to_engine_msg(once(b'I'))])
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   229
                                .send_all()
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   230
                                .in_room(room_id)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   231
                                .action(),
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   232
                        );*/
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   233
                    }
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   234
                }
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   235
                VoteType::NewSeed => {
13480
fb37745c5bca complete newseed voting
alfadur
parents: 13478
diff changeset
   236
                    let seed = thread_rng().gen_range(0, 1_000_000_000).to_string();
fb37745c5bca complete newseed voting
alfadur
parents: 13478
diff changeset
   237
                    let cfg = GameCfg::Seed(seed);
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   238
                    /*actions.push(cfg.to_server_msg().send_all().in_room(room_id).action());*/
13480
fb37745c5bca complete newseed voting
alfadur
parents: 13478
diff changeset
   239
                    server.rooms[room_id].set_config(cfg);
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   240
                }
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   241
                VoteType::HedgehogsPerTeam(number) => {
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   242
                    let r = &mut server.rooms[room_id];
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   243
                    let nicks = r.set_hedgehogs_number(number);
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   244
                    /*actions.extend(nicks.into_iter().map(|n| {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   245
                        HedgehogsNumber(n, number)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   246
                            .send_all()
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   247
                            .in_room(room_id)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   248
                            .action()
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   249
                    }));*/
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   250
                }
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   251
            }
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
   252
        }
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
   253
        ChangeMaster(room_id, new_id) => {
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
   254
            let room_client_ids = server.room_clients(room_id);
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   255
            let new_id = if server
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   256
                .room(client_id)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   257
                .map(|r| r.is_fixed())
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   258
                .unwrap_or(false)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   259
            {
13477
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13443
diff changeset
   260
                new_id
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13443
diff changeset
   261
            } else {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   262
                new_id.or_else(|| room_client_ids.iter().find(|id| **id != client_id).cloned())
13477
f748a72432f2 Implement greetings & fixed rooms
alfadur
parents: 13443
diff changeset
   263
            };
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
   264
            let new_nick = new_id.map(|id| server.clients[id].nick.clone());
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
   265
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
   266
            if let (c, Some(r)) = server.client_and_room(client_id) {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
   267
                match r.master_id {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
   268
                    Some(id) if id == c.id => {
13520
1ee192f13456 Better packing for clients
alfadur
parents: 13480
diff changeset
   269
                        c.set_is_master(false);
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
   270
                        r.master_id = None;
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   271
                        /*actions.push(
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   272
                            ClientFlags("-h".to_string(), vec![c.nick.clone()])
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   273
                                .send_all()
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   274
                                .in_room(r.id)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   275
                                .action(),
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   276
                        );*/
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
   277
                    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
   278
                    Some(_) => unreachable!(),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13416
diff changeset
   279
                    None => {}
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
   280
                }
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
   281
                r.master_id = new_id;
13801
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13666
diff changeset
   282
                if !r.is_fixed() && c.protocol_number < 42 {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   283
                    r.name
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   284
                        .replace_range(.., new_nick.as_ref().map_or("[]", String::as_str));
13801
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13666
diff changeset
   285
                }
13523
8c5dd562c9f7 Add room flags
alfadur
parents: 13520
diff changeset
   286
                r.set_join_restriction(false);
8c5dd562c9f7 Add room flags
alfadur
parents: 13520
diff changeset
   287
                r.set_team_add_restriction(false);
8c5dd562c9f7 Add room flags
alfadur
parents: 13520
diff changeset
   288
                let is_fixed = r.is_fixed();
8c5dd562c9f7 Add room flags
alfadur
parents: 13520
diff changeset
   289
                r.set_unregistered_players_restriction(is_fixed);
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
   290
                if let Some(nick) = new_nick {
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   291
                    /*actions.push(
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   292
                        ClientFlags("+h".to_string(), vec![nick])
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   293
                            .send_all()
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   294
                            .in_room(r.id)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   295
                            .action(),
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   296
                    );*/
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
   297
                }
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
   298
            }
13666
09f4a30e50cc Rust 2018 conversion
alfadur
parents: 13527
diff changeset
   299
            if let Some(id) = new_id {
09f4a30e50cc Rust 2018 conversion
alfadur
parents: 13527
diff changeset
   300
                server.clients[id].set_is_master(true)
09f4a30e50cc Rust 2018 conversion
alfadur
parents: 13527
diff changeset
   301
            }
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   302
        }
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   303
        StartRoomGame(room_id) => {
14686
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   304
            let (room_clients, room_nicks): (Vec<_>, Vec<_>) = server
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   305
                .clients
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   306
                .iter()
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   307
                .map(|(id, c)| (id, c.nick.clone()))
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   308
                .unzip();
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   309
            let room = &mut server.rooms[room_id];
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   310
14686
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   311
            if !room.has_multiple_clans() {
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   312
                /*Warn(
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   313
                    "The game can't be started with less than two clans!".to_string(),
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   314
                )*/
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   315
            } else if room.protocol_number <= 43 && room.players_number != room.ready_players_number
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   316
            {
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   317
                /*Warn("Not all players are ready".to_string())*/
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   318
            } else if room.game_info.is_some() {
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   319
                /*Warn("The game is already in progress".to_string())*/
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   320
            } else {
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   321
                room.start_round();
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   322
                for id in room_clients {
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   323
                    let c = &mut server.clients[id];
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   324
                    c.set_is_in_game(false);
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   325
                    c.team_indices = room.client_team_indices(c.id);
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   326
                }
14686
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   327
                /*RunGame.send_all().in_room(room.id).action(),*/
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   328
                //SendRoomUpdate(None),
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   329
                /*ClientFlags("+g".to_string(), room_nicks)
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   330
                .send_all()
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   331
                .in_room(room.id)
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   332
                .action(),*/
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   333
            }
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
   334
        }
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   335
        SendTeamRemovalMessage(team_name) => {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   336
            let mut actions = Vec::new();
13527
e3ae9eea0689 Implement map voting
alfadur
parents: 13524
diff changeset
   337
            if let Some(r) = server.room(client_id) {
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   338
                if let Some(ref mut info) = r.game_info {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   339
                    let msg = once(b'F').chain(team_name.bytes());
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   340
                    /*actions.push(
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   341
                        ForwardEngineMessage(vec![to_engine_msg(msg)])
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   342
                            .send_all()
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   343
                            .in_room(r.id)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   344
                            .but_self()
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   345
                            .action(),
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   346
                    );*/
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   347
                    info.teams_in_game -= 1;
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   348
                    if info.teams_in_game == 0 {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   349
                        actions.push(FinishRoomGame(r.id));
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   350
                    }
13427
6f6a866c86a2 Send more data on room joining
alfadur
parents: 13426
diff changeset
   351
                    let remove_msg = to_engine_msg(once(b'F').chain(team_name.bytes()));
13443
2501428303a2 Fix team remove synchronization
alfadur
parents: 13439
diff changeset
   352
                    if let Some(m) = &info.sync_msg {
2501428303a2 Fix team remove synchronization
alfadur
parents: 13439
diff changeset
   353
                        info.msg_log.push(m.clone());
13427
6f6a866c86a2 Send more data on room joining
alfadur
parents: 13426
diff changeset
   354
                    }
13443
2501428303a2 Fix team remove synchronization
alfadur
parents: 13439
diff changeset
   355
                    if info.sync_msg.is_some() {
2501428303a2 Fix team remove synchronization
alfadur
parents: 13439
diff changeset
   356
                        info.sync_msg = None
2501428303a2 Fix team remove synchronization
alfadur
parents: 13439
diff changeset
   357
                    }
2501428303a2 Fix team remove synchronization
alfadur
parents: 13439
diff changeset
   358
                    info.msg_log.push(remove_msg.clone());
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   359
                    /*actions.push(
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   360
                        ForwardEngineMessage(vec![remove_msg])
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   361
                            .send_all()
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   362
                            .in_room(r.id)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   363
                            .but_self()
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   364
                            .action(),
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   365
                    );*/
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   366
                }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   367
            }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   368
        }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   369
        FinishRoomGame(room_id) => {
13426
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
   370
            let mut actions = Vec::new();
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
   371
13801
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13666
diff changeset
   372
            let r = &mut server.rooms[room_id];
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13666
diff changeset
   373
            r.ready_players_number = 1;
14686
9f98086de1b6 Server action refactoring part 9 of N
alfadur <mail@none>
parents: 14683
diff changeset
   374
            //actions.push(SendRoomUpdate(None));
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   375
            //actions.push(RoundFinished.send_all().in_room(r.id).action());
13801
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13666
diff changeset
   376
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13666
diff changeset
   377
            if let Some(info) = replace(&mut r.game_info, None) {
13426
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
   378
                for (_, c) in server.clients.iter() {
13520
1ee192f13456 Better packing for clients
alfadur
parents: 13480
diff changeset
   379
                    if c.room_id == Some(room_id) && c.is_joined_mid_game() {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   380
                        actions.push(SendRoomData {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   381
                            to: c.id,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   382
                            teams: false,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   383
                            config: true,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   384
                            flags: false,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   385
                        });
13524
5359ff75da3a indulge clippy
alfadur
parents: 13523
diff changeset
   386
                        for name in &info.left_teams {
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   387
                            //actions.push(TeamRemove(name.clone()).send(c.id).action());
13426
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
   388
                        }
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
   389
                    }
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
   390
                }
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
   391
            }
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
   392
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   393
            let nicks: Vec<_> = server
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   394
                .clients
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   395
                .iter_mut()
13426
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
   396
                .filter(|(_, c)| c.room_id == Some(room_id))
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
   397
                .map(|(_, c)| {
13666
09f4a30e50cc Rust 2018 conversion
alfadur
parents: 13527
diff changeset
   398
                    c.set_is_ready(c.is_master());
13520
1ee192f13456 Better packing for clients
alfadur
parents: 13480
diff changeset
   399
                    c.set_is_joined_mid_game(false);
13426
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
   400
                    c
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   401
                })
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   402
                .filter_map(|c| {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   403
                    if !c.is_master() {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   404
                        Some(c.nick.clone())
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   405
                    } else {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   406
                        None
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   407
                    }
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   408
                })
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14456
diff changeset
   409
                .collect();
13801
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13666
diff changeset
   410
13426
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
   411
            if !nicks.is_empty() {
13801
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13666
diff changeset
   412
                let msg = if r.protocol_number < 38 {
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13666
diff changeset
   413
                    LegacyReady(false, nicks)
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13666
diff changeset
   414
                } else {
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13666
diff changeset
   415
                    ClientFlags("-r".to_string(), nicks)
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13666
diff changeset
   416
                };
14683
932ff7683653 Server action refactoring part 8 of N
alfadur <mail@none>
parents: 14675
diff changeset
   417
                //actions.push(msg.send_all().in_room(room_id).action());
13426
f091f69d59e4 Additional round cleanup
alfadur
parents: 13424
diff changeset
   418
            }
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13422
diff changeset
   419
        }
12144
589a2d7d3dc5 More refactoring
unc0rr
parents: 12143
diff changeset
   420
    }
589a2d7d3dc5 More refactoring
unc0rr
parents: 12143
diff changeset
   421
}