equal
deleted
inserted
replaced
1 use slab; |
1 use slab; |
2 use utils; |
2 use utils; |
3 use super::{ |
3 use super::{ |
4 client::*, room::*, actions, handlers, |
4 client::HWClient, room::HWRoom, actions, handlers, |
|
5 coretypes::{ClientId, RoomId}, |
5 actions::{Destination, PendingMessage} |
6 actions::{Destination, PendingMessage} |
6 }; |
7 }; |
7 use protocol::messages::*; |
8 use protocol::messages::*; |
8 |
9 |
9 type Slab<T> = slab::Slab<T>; |
10 type Slab<T> = slab::Slab<T>; |
103 |
104 |
104 pub fn find_room_mut(&mut self, name: &str) -> Option<&mut HWRoom> { |
105 pub fn find_room_mut(&mut self, name: &str) -> Option<&mut HWRoom> { |
105 self.rooms.iter_mut().find(|(_, r)| r.name == name).map(|(_, r)| r) |
106 self.rooms.iter_mut().find(|(_, r)| r.name == name).map(|(_, r)| r) |
106 } |
107 } |
107 |
108 |
|
109 pub fn find_client(&self, nick: &str) -> Option<&HWClient> { |
|
110 self.clients.iter().find(|(_, c)| c.nick == nick).map(|(_, c)| c) |
|
111 } |
|
112 |
|
113 pub fn find_client_mut(&mut self, nick: &str) -> Option<&mut HWClient> { |
|
114 self.clients.iter_mut().find(|(_, c)| c.nick == nick).map(|(_, c)| c) |
|
115 } |
|
116 |
108 pub fn select_clients<F>(&self, f: F) -> Vec<ClientId> |
117 pub fn select_clients<F>(&self, f: F) -> Vec<ClientId> |
109 where F: Fn(&(usize, &HWClient)) -> bool { |
118 where F: Fn(&(usize, &HWClient)) -> bool { |
110 self.clients.iter().filter(f) |
119 self.clients.iter().filter(f) |
111 .map(|(_, c)| c.id).collect() |
120 .map(|(_, c)| c.id).collect() |
112 } |
121 } |