summaryrefslogtreecommitdiff
path: root/game_server/src/scribble_group.rs
diff options
context:
space:
mode:
authornatrixaeria <janng@gmx.de>2019-05-19 22:38:25 +0200
committernatrixaeria <janng@gmx.de>2019-05-19 22:38:25 +0200
commit054a2bfe069ed4118d2f9fd1f01428632049057b (patch)
treeba017b1597e3f140d260ef0f6a3218591136c600 /game_server/src/scribble_group.rs
parent2d815af3f6d062d55da2f2598ce5d506ee74cb6e (diff)
Add a client handling system
Diffstat (limited to 'game_server/src/scribble_group.rs')
-rw-r--r--game_server/src/scribble_group.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/game_server/src/scribble_group.rs b/game_server/src/scribble_group.rs
new file mode 100644
index 0000000..c240264
--- /dev/null
+++ b/game_server/src/scribble_group.rs
@@ -0,0 +1,42 @@
+use super::group::{Group, GroupId};
+use super::server::{UserId, GameClient};
+use std::collections::HashMap;
+
+pub struct ScribbleGroup {
+ id: GroupId,
+ name: String,
+ clients: HashMap<UserId, GameClient>
+}
+
+impl Group for ScribbleGroup {
+ fn id(&self) -> GroupId {
+ self.id
+ }
+
+ fn group_type(&self) -> String {
+ "scribble".to_string()
+ }
+
+ fn name(&self) -> String {
+ self.name.clone()
+ }
+
+ fn run(&mut self) {
+ info!("a new group {}:'{}' runs now", self.id, self.name);
+ }
+
+ fn add_client(&mut self, id: UserId, client: GameClient) {
+ debug!("user {} joined the group {}:'{}'", id, self.id, self.name);
+ self.clients.insert(id, client);
+ }
+
+ fn get_client(&self, client_id: UserId) -> Option<&GameClient> {
+ self.clients.get(&client_id)
+ }
+}
+
+impl ScribbleGroup {
+ pub fn new(id: GroupId, name: String) -> Self {
+ Self { id, name, clients: HashMap::new() }
+ }
+}