-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the MasterServer,Client, and add Events + DashMap.
- Loading branch information
Showing
15 changed files
with
636 additions
and
87 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
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,5 @@ | ||
pub enum Event { | ||
Connection(u32), | ||
Disconnection(u32), | ||
ReceivedData(u32, Vec<u8>), | ||
} |
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,15 @@ | ||
pub struct ScopeCall<F: FnMut()> { | ||
pub c: F | ||
} | ||
impl<F: FnMut()> Drop for ScopeCall<F> { | ||
fn drop(&mut self) { | ||
(self.c)(); | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! defer { | ||
($e:expr) => ( | ||
let _scope_call = $crate::macros::defer::ScopeCall { c: || -> () { $e; } }; | ||
) | ||
} |
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,2 @@ | ||
pub mod defer; | ||
pub mod logging; |
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 |
---|---|---|
@@ -1,22 +1,23 @@ | ||
use crate::{ transport::{BaseServer, ServerType}, utils::constants }; | ||
|
||
pub struct MasterServer { | ||
base: BaseServer, | ||
pub base: BaseServer, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum MasterServerError { | ||
// TODO Implement | ||
} | ||
|
||
// TODO Implement | ||
impl MasterServer { | ||
pub async fn new() -> Result<Self, (MasterServerError, String)> { | ||
pub async fn new(max_connections: Option<u32>, port: Option<u16>) -> Result<Self, (MasterServerError, String)> { | ||
Ok(MasterServer { | ||
base: BaseServer::new(ServerType::MasterServer, 0, Some(constants::MASTER_PORT)).await.unwrap(), | ||
base: BaseServer::new(ServerType::MasterServer, max_connections, port).await.unwrap(), | ||
}) | ||
} | ||
|
||
pub fn run(&self) { | ||
println!("Master server started"); | ||
pub async fn start(&mut self) { | ||
self.base.start().await; | ||
} | ||
} |
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.