equal
deleted
inserted
replaced
10 }, |
10 }, |
11 utils::is_name_illegal, |
11 utils::is_name_illegal, |
12 }; |
12 }; |
13 use log::*; |
13 use log::*; |
14 |
14 |
15 pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) { |
15 pub fn handle( |
|
16 server: &mut HWServer, |
|
17 client_id: ClientId, |
|
18 response: &mut super::Response, |
|
19 message: HWProtocolMessage, |
|
20 ) { |
16 use crate::protocol::messages::HWProtocolMessage::*; |
21 use crate::protocol::messages::HWProtocolMessage::*; |
17 match message { |
22 match message { |
18 CreateRoom(name, password) => { |
23 CreateRoom(name, password) => { |
19 let actions = if is_name_illegal(&name) { |
24 let actions = if is_name_illegal(&name) { |
20 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())] |
25 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())] |
30 |
35 |
31 let room_id = server.create_room(client_id, name, password); |
36 let room_id = server.create_room(client_id, name, password); |
32 let room = &server.rooms[room_id]; |
37 let room = &server.rooms[room_id]; |
33 let client = &server.clients[client_id]; |
38 let client = &server.clients[client_id]; |
34 |
39 |
35 vec![ |
40 response.add( |
36 RoomAdd(room.info(Some(&client))) |
41 RoomAdd(room.info(Some(&client))) |
37 .send_all() |
42 .send_all() |
38 .with_protocol(room.protocol_number) |
43 .with_protocol(room.protocol_number), |
39 .action(), |
44 ); |
40 flags_msg.send_self().action(), |
45 response.add(flags_msg.send_self()); |
41 ] |
46 |
|
47 response.add(ClientFlags("+i".to_string(), vec![client.nick.clone()]).send_self()); |
|
48 vec![] |
42 }; |
49 }; |
43 server.react(client_id, actions) |
50 server.react(client_id, actions); |
44 } |
51 } |
45 Chat(msg) => { |
52 Chat(msg) => { |
46 let actions = vec![ChatMsg { |
53 let actions = vec![ChatMsg { |
47 nick: server.clients[client_id].nick.clone(), |
54 nick: server.clients[client_id].nick.clone(), |
48 msg, |
55 msg, |
73 vec![Warn( |
80 vec![Warn( |
74 "Access denied. This room currently doesn't allow joining.".to_string(), |
81 "Access denied. This room currently doesn't allow joining.".to_string(), |
75 )] |
82 )] |
76 } else if r.players_number == u8::max_value() { |
83 } else if r.players_number == u8::max_value() { |
77 vec![Warn("This room is already full".to_string())] |
84 vec![Warn("This room is already full".to_string())] |
|
85 } else if let Some(room_id) = room_id { |
|
86 let nick = c.nick.clone(); |
|
87 server.move_to_room(client_id, room_id); |
|
88 |
|
89 response.add(RoomJoined(vec![nick.clone()]).send_all().in_room(room_id)); |
|
90 response.add(ClientFlags("+i".to_string(), vec![nick]).send_all()); |
|
91 response.add(RoomJoined(nicks).send_self()); |
|
92 |
|
93 let room = &server.rooms[room_id]; |
|
94 |
|
95 if !room.greeting.is_empty() { |
|
96 response.add( |
|
97 ChatMsg { |
|
98 nick: "[greeting]".to_string(), |
|
99 msg: room.greeting.clone(), |
|
100 } |
|
101 .send_self(), |
|
102 ); |
|
103 } |
|
104 |
|
105 vec![] |
78 } else { |
106 } else { |
79 vec![MoveToRoom(r.id), RoomJoined(nicks).send_self().action()] |
107 vec![] |
80 } |
108 } |
81 } else { |
109 } else { |
82 vec![Warn("No such room.".to_string())] |
110 vec![Warn("No such room.".to_string())] |
83 }; |
111 }; |
84 server.react(client_id, actions); |
112 server.react(client_id, actions); |