author | alfadur |
Mon, 16 Jul 2018 22:32:04 +0300 | |
changeset 13521 | ba5211dddb21 |
parent 13478 | d79795acaa73 |
child 13523 | 8c5dd562c9f7 |
permissions | -rw-r--r-- |
12147 | 1 |
use mio; |
2 |
||
13416 | 3 |
use server::{ |
4 |
server::HWServer, |
|
13478 | 5 |
coretypes::ClientId, |
13416 | 6 |
actions::{Action, Action::*} |
7 |
}; |
|
8 |
use protocol::messages::{ |
|
9 |
HWProtocolMessage, |
|
10 |
HWServerMessage::* |
|
11 |
}; |
|
12 |
use utils::is_name_illegal; |
|
13521 | 13 |
use super::common::rnd_reply; |
12147 | 14 |
|
13419 | 15 |
pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
16 |
use protocol::messages::HWProtocolMessage::*; |
12147 | 17 |
match message { |
13416 | 18 |
CreateRoom(name, password) => { |
19 |
let actions = |
|
20 |
if is_name_illegal(&name) { |
|
21 |
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())] |
|
22 |
} else if server.has_room(&name) { |
|
23 |
vec![Warn("A room with the same name already exists.".to_string())] |
|
24 |
} else { |
|
25 |
let flags_msg = ClientFlags( |
|
26 |
"+hr".to_string(), |
|
13419 | 27 |
vec![server.clients[client_id].nick.clone()]); |
13416 | 28 |
vec![AddRoom(name, password), |
13419 | 29 |
flags_msg.send_self().action()] |
13416 | 30 |
}; |
13419 | 31 |
server.react(client_id, actions); |
13416 | 32 |
}, |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
33 |
Chat(msg) => { |
13521 | 34 |
let actions = vec![ChatMsg {nick: server.clients[client_id].nick.clone(), msg} |
35 |
.send_all().in_room(server.lobby_id).but_self().action()]; |
|
36 |
server.react(client_id, actions); |
|
12147 | 37 |
}, |
13416 | 38 |
JoinRoom(name, password) => { |
39 |
let actions; |
|
40 |
{ |
|
41 |
let room = server.rooms.iter().find(|(_, r)| r.name == name); |
|
42 |
let room_id = room.map(|(_, r)| r.id); |
|
43 |
let nicks = server.clients.iter() |
|
44 |
.filter(|(_, c)| c.room_id == room_id) |
|
45 |
.map(|(_, c)| c.nick.clone()) |
|
46 |
.collect(); |
|
13419 | 47 |
let c = &mut server.clients[client_id]; |
13427 | 48 |
|
49 |
actions = if let Some((_, r)) = room { |
|
50 |
if c.protocol_number != r.protocol_number { |
|
51 |
vec![Warn("Room version incompatible to your Hedgewars version!".to_string())] |
|
52 |
} else { |
|
53 |
vec![MoveToRoom(r.id), |
|
54 |
RoomJoined(nicks).send_self().action()] |
|
13416 | 55 |
} |
13427 | 56 |
} else { |
57 |
vec![Warn("No such room.".to_string())] |
|
13416 | 58 |
}; |
12147 | 59 |
} |
13419 | 60 |
server.react(client_id, actions); |
12147 | 61 |
}, |
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
62 |
Rnd(v) => { |
13521 | 63 |
server.react(client_id, vec![rnd_reply(&v).send_self().action()]); |
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
64 |
}, |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
65 |
List => warn!("Deprecated LIST message received"), |
12147 | 66 |
_ => warn!("Incorrect command in lobby state"), |
67 |
} |
|
68 |
} |