From 054a2bfe069ed4118d2f9fd1f01428632049057b Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Sun, 19 May 2019 22:38:25 +0200 Subject: Add a client handling system --- game_server/src/scribble_group.rs | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 game_server/src/scribble_group.rs (limited to 'game_server/src/scribble_group.rs') 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 +} + +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() } + } +} -- cgit v1.2.3-54-g00ecf