-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handling for INFOSERVER and LISTCLIENTS
- Loading branch information
Showing
6 changed files
with
259 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use flurry::HashSet as ConcurrentHashSet; | ||
use std::collections::HashSet as StdHashSet; | ||
use std::net::SocketAddr; | ||
use std::time::SystemTime; | ||
use types::server::ConnectedClient; | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct ClientHandler { | ||
clients: ConcurrentHashSet<ConnectedClient>, | ||
} | ||
|
||
impl ClientHandler { | ||
pub fn new() -> Self { | ||
Self { | ||
clients: ConcurrentHashSet::new(), | ||
} | ||
} | ||
|
||
pub fn connect(&self, addr: SocketAddr) -> ConnectedClient { | ||
let client = ConnectedClient { | ||
address: format!("{addr}"), | ||
time_connected: SystemTime::now(), | ||
}; | ||
let pinned = self.clients.pin(); | ||
pinned.insert(client.clone()); | ||
client | ||
} | ||
|
||
pub fn disconnect(&self, client: &ConnectedClient) { | ||
let pinned = self.clients.pin(); | ||
pinned.remove(client); | ||
} | ||
|
||
pub fn list(&self) -> StdHashSet<ConnectedClient> { | ||
let pinned = self.clients.pin(); | ||
pinned.into_iter().cloned().collect() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.