equal
deleted
inserted
replaced
14 use std::{io, io::Write, iter::once, mem::replace}; |
14 use std::{io, io::Write, iter::once, mem::replace}; |
15 |
15 |
16 #[cfg(feature = "official-server")] |
16 #[cfg(feature = "official-server")] |
17 use super::database; |
17 use super::database; |
18 |
18 |
|
19 pub enum DestinationRoom { |
|
20 All, |
|
21 Lobby, |
|
22 Room(RoomId), |
|
23 } |
|
24 |
19 pub enum Destination { |
25 pub enum Destination { |
20 ToId(ClientId), |
26 ToId(ClientId), |
21 ToSelf, |
27 ToSelf, |
22 ToAll { |
28 ToAll { |
23 room_id: Option<RoomId>, |
29 room_id: DestinationRoom, |
24 protocol: Option<u16>, |
30 protocol: Option<u16>, |
25 skip_self: bool, |
31 skip_self: bool, |
26 }, |
32 }, |
27 } |
33 } |
28 |
34 |
46 } |
52 } |
47 } |
53 } |
48 |
54 |
49 pub fn send_all(message: HWServerMessage) -> PendingMessage { |
55 pub fn send_all(message: HWServerMessage) -> PendingMessage { |
50 let destination = Destination::ToAll { |
56 let destination = Destination::ToAll { |
51 room_id: None, |
57 room_id: DestinationRoom::All, |
52 protocol: None, |
58 protocol: None, |
53 skip_self: false, |
59 skip_self: false, |
54 }; |
60 }; |
55 PendingMessage { |
61 PendingMessage { |
56 destination, |
62 destination, |
61 pub fn in_room(mut self, clients_room_id: RoomId) -> PendingMessage { |
67 pub fn in_room(mut self, clients_room_id: RoomId) -> PendingMessage { |
62 if let Destination::ToAll { |
68 if let Destination::ToAll { |
63 ref mut room_id, .. |
69 ref mut room_id, .. |
64 } = self.destination |
70 } = self.destination |
65 { |
71 { |
66 *room_id = Some(clients_room_id) |
72 *room_id = DestinationRoom::Room(clients_room_id) |
|
73 } |
|
74 self |
|
75 } |
|
76 |
|
77 pub fn in_lobby(mut self) -> PendingMessage { |
|
78 if let Destination::ToAll { |
|
79 ref mut room_id, .. |
|
80 } = self.destination |
|
81 { |
|
82 *room_id = DestinationRoom::Lobby |
67 } |
83 } |
68 self |
84 self |
69 } |
85 } |
70 |
86 |
71 pub fn with_protocol(mut self, protocol_number: u16) -> PendingMessage { |
87 pub fn with_protocol(mut self, protocol_number: u16) -> PendingMessage { |