aboutsummaryrefslogtreecommitdiff
path: root/games/rstnode/rst-core/src/server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'games/rstnode/rst-core/src/server.rs')
-rw-r--r--games/rstnode/rst-core/src/server.rs62
1 files changed, 30 insertions, 32 deletions
diff --git a/games/rstnode/rst-core/src/server.rs b/games/rstnode/rst-core/src/server.rs
index 3d95c3638c98..68fa2a074e34 100644
--- a/games/rstnode/rst-core/src/server.rs
+++ b/games/rstnode/rst-core/src/server.rs
@@ -4,18 +4,17 @@
//! connections according to a address given to the initialiser.
use crate::{
- _if::GameIf,
- _match::Match,
data::Player,
lobby::LobbyList,
map::Map,
users::UserStore,
wire::{
- Action, AuthErr, Lobby, LobbyErr, LobbyId, LobbyUpdate, MatchErr, MatchId, RegErr,
+ game::Action, AuthErr, Lobby, LobbyErr, LobbyId, LobbyUpdate, MatchErr, MatchId, RegErr,
Response, UpdateState, User, UserId,
},
+ GameIf, Match,
};
-use async_std::sync::{Arc, Mutex, RwLock};
+use async_std::sync::{Arc, Mutex};
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use std::{collections::BTreeMap, path::Path};
@@ -40,12 +39,12 @@ pub struct Server {
impl Server {
/// Create a new game server
- fn new() -> Self {
- Self {
+ pub(crate) fn new() -> Arc<Self> {
+ Arc::new(Self {
matches: Default::default(),
users: UserStore::new(),
lobbies: LobbyList::new(),
- }
+ })
}
/// Open the state dir of a game server
@@ -68,15 +67,15 @@ impl Server {
Ok(0)
}
- pub async fn update_map<F>(self: Arc<Self>, id: MatchId, cb: F) -> ServerResult<Response>
- where
- F: Fn(&mut Map) -> ServerResult<Response>,
- {
- match self.matches.get(&id) {
- Some(ref m) => m.lock().await.map.update(cb),
- None => Err(ServerErr::NoSuchMatch),
- }
- }
+ // pub async fn update_map<F>(self: Arc<Self>, id: MatchId, cb: F) -> ServerResult<Response>
+ // where
+ // F: Fn(&mut Map) -> ServerResult<Response>,
+ // {
+ // match self.matches.get(&id) {
+ // Some(ref m) => m.lock().await.map.update(cb),
+ // None => Err(ServerErr::NoSuchMatch),
+ // }
+ // }
pub async fn update_players<F>(self: Arc<Self>, id: MatchId, cb: F) -> ServerResult<Response>
where
@@ -91,31 +90,32 @@ impl Server {
#[async_trait]
impl GameIf for Server {
- async fn register(self: Arc<Self>, name: String, pw: String) -> Result<UserId, RegErr> {
- unimplemented!()
+ async fn register(self: Arc<Self>, _name: String, _pw: String) -> Result<UserId, RegErr> {
+ todo!()
}
- async fn login(self: Arc<Self>, name: String, pw: String) -> Result<User, AuthErr> {
- unimplemented!()
+ async fn login(self: Arc<Self>, _name: String, _pw: String) -> Result<User, AuthErr> {
+ todo!()
}
- async fn logout(self: Arc<Self>, user: User) -> Result<(), AuthErr> {
- unimplemented!()
+ async fn logout(self: Arc<Self>, _user: User) -> Result<(), AuthErr> {
+ todo!()
}
async fn anonymous(self: Arc<Self>, name: String) -> Result<User, AuthErr> {
- let (_, auth) = self.users.add(name, None, true).await;
- Ok(auth)
+ // let (_, auth) = self.users.add(name, None, true).await;
+ // Ok(auth)
+ todo!()
}
async fn join(self: Arc<Self>, user: User, lobby: LobbyId) -> Result<Lobby, LobbyErr> {
let mu = self.users.get(&user).await?;
- self.lobbies.get_mut(lobby, |mut l| l.join(&mu)).await
+ self.lobbies.get_mut(lobby, |l| l.join(&mu)).await
}
async fn leave(self: Arc<Self>, user: User, lobby: LobbyId) -> Result<(), LobbyErr> {
let mu = self.users.get(&user).await?;
- self.lobbies.get_mut(lobby, |mut l| l.leave(&mu)).await
+ self.lobbies.get_mut(lobby, |l| l.leave(&mu)).await
}
async fn ready(
@@ -124,9 +124,7 @@ impl GameIf for Server {
lobby: LobbyId,
ready: bool,
) -> Result<LobbyUpdate, LobbyErr> {
- self.lobbies
- .get_mut(lobby, |mut l| l.ready(user, ready))
- .await
+ self.lobbies.get_mut(lobby, |l| l.ready(user, ready)).await
}
/// A start request was received
@@ -135,8 +133,8 @@ impl GameIf for Server {
user: UserId,
lobby: LobbyId,
) -> Result<DateTime<Utc>, LobbyErr> {
- self.lobbies.get_mut(lobby, |mut l| l.start(user)).await?;
- let lob = self.lobbies.consume(lobby).await?;
+ self.lobbies.get_mut(lobby, |l| l.start(user)).await??;
+ let _lob = self.lobbies.consume(lobby).await?;
Ok(Utc::now())
}
@@ -149,7 +147,7 @@ impl GameIf for Server {
unimplemented!()
}
- async fn leave_match(self: Arc<Self>, user: User, mtch: MatchId) -> Result<(), MatchErr> {
+ async fn leave_match(self: Arc<Self>, _user: User, _mtch: MatchId) -> Result<(), MatchErr> {
unimplemented!()
}
}