summaryrefslogtreecommitdiff
path: root/game_server/src/lobby.rs
diff options
context:
space:
mode:
Diffstat (limited to 'game_server/src/lobby.rs')
-rw-r--r--game_server/src/lobby.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/game_server/src/lobby.rs b/game_server/src/lobby.rs
new file mode 100644
index 0000000..fe3bdee
--- /dev/null
+++ b/game_server/src/lobby.rs
@@ -0,0 +1,35 @@
+use std::collections::HashMap;
+
+use super::group::{Group, GroupId};
+
+pub struct Lobby {
+ groups: HashMap<GroupId, Box<Group>>,
+}
+
+impl Lobby {
+ pub fn new() -> Lobby {
+ Self {
+ groups: HashMap::new(),
+ }
+ }
+
+ pub fn add_group(&mut self, group: Box<Group>) {
+ self.groups.insert(group.id(), group);
+ }
+
+ pub fn iter<'a>(&'a self) -> GroupIterator<'a> {
+ GroupIterator { groups: self.groups.values() }
+ }
+}
+
+pub struct GroupIterator<'a> {
+ groups: std::collections::hash_map::Values<'a, GroupId, Box<Group>>
+}
+
+impl<'a> Iterator for GroupIterator<'a> {
+ type Item = &'a Box<Group>;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ self.groups.next()
+ }
+}