--- a/rust/hedgewars-server/src/server/actions.rs Thu Apr 11 01:42:14 2019 +0300
+++ b/rust/hedgewars-server/src/server/actions.rs Thu Apr 11 19:30:22 2019 +0300
@@ -16,18 +16,19 @@
#[cfg(feature = "official-server")]
use super::database;
-pub enum DestinationRoom {
+pub enum DestinationGroup {
All,
Lobby,
Room(RoomId),
+ Protocol(u16),
}
pub enum Destination {
ToId(ClientId),
+ ToIds(Vec<ClientId>),
ToSelf,
ToAll {
- room_id: DestinationRoom,
- protocol: Option<u16>,
+ group: DestinationGroup,
skip_self: bool,
},
}
@@ -45,6 +46,13 @@
}
}
+ pub fn send_many(message: HWServerMessage, client_ids: Vec<ClientId>) -> PendingMessage {
+ PendingMessage {
+ destination: Destination::ToIds(client_ids),
+ message,
+ }
+ }
+
pub fn send_self(message: HWServerMessage) -> PendingMessage {
PendingMessage {
destination: Destination::ToSelf,
@@ -54,8 +62,7 @@
pub fn send_all(message: HWServerMessage) -> PendingMessage {
let destination = Destination::ToAll {
- room_id: DestinationRoom::All,
- protocol: None,
+ group: DestinationGroup::All,
skip_self: false,
};
PendingMessage {
@@ -65,31 +72,22 @@
}
pub fn in_room(mut self, clients_room_id: RoomId) -> PendingMessage {
- if let Destination::ToAll {
- ref mut room_id, ..
- } = self.destination
- {
- *room_id = DestinationRoom::Room(clients_room_id)
+ if let Destination::ToAll { ref mut group, .. } = self.destination {
+ *group = DestinationGroup::Room(clients_room_id)
}
self
}
pub fn in_lobby(mut self) -> PendingMessage {
- if let Destination::ToAll {
- ref mut room_id, ..
- } = self.destination
- {
- *room_id = DestinationRoom::Lobby
+ if let Destination::ToAll { ref mut group, .. } = self.destination {
+ *group = DestinationGroup::Lobby
}
self
}
pub fn with_protocol(mut self, protocol_number: u16) -> PendingMessage {
- if let Destination::ToAll {
- ref mut protocol, ..
- } = self.destination
- {
- *protocol = Some(protocol_number)
+ if let Destination::ToAll { ref mut group, .. } = self.destination {
+ *group = DestinationGroup::Protocol(protocol_number)
}
self
}
@@ -109,6 +107,9 @@
pub fn send(self, client_id: ClientId) -> PendingMessage {
PendingMessage::send(self, client_id)
}
+ pub fn send_many(self, client_ids: Vec<ClientId>) -> PendingMessage {
+ PendingMessage::send_many(self, client_ids)
+ }
pub fn send_self(self) -> PendingMessage {
PendingMessage::send_self(self)
}