|
|
|
@ -2,11 +2,12 @@ use crate::{ |
|
|
|
|
data::Player, |
|
|
|
|
lobby::MetaLobby, |
|
|
|
|
map::Map, |
|
|
|
|
wire::{LobbyUser, MatchId, UserId}, |
|
|
|
|
wire::{Action, LobbyUser, MatchId, UserId}, |
|
|
|
|
}; |
|
|
|
|
use async_std::sync::Arc; |
|
|
|
|
use async_std::sync::{Arc, RwLock}; |
|
|
|
|
use chrono::{DateTime, Utc}; |
|
|
|
|
use serde::{Deserialize, Serialize}; |
|
|
|
|
use std::collections::VecDeque; |
|
|
|
|
|
|
|
|
|
/// Describes a match for the server
|
|
|
|
|
pub struct Match { |
|
|
|
@ -16,10 +17,12 @@ pub struct Match { |
|
|
|
|
pub players: Vec<Player>, |
|
|
|
|
/// The active game map
|
|
|
|
|
pub map: Map, |
|
|
|
|
/// Input inbox,
|
|
|
|
|
inbox: RwLock<VecDeque<Action>>, |
|
|
|
|
/// The time the match was initialised
|
|
|
|
|
pub init_t: DateTime<Utc>, |
|
|
|
|
init_t: DateTime<Utc>, |
|
|
|
|
/// The synced time the match was started
|
|
|
|
|
pub start_t: Option<DateTime<Utc>>, |
|
|
|
|
start_t: Option<DateTime<Utc>>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl From<MetaLobby> for Match { |
|
|
|
@ -38,6 +41,7 @@ impl From<MetaLobby> for Match { |
|
|
|
|
}) |
|
|
|
|
.collect(), |
|
|
|
|
map: Map::new(), |
|
|
|
|
inbox: Default::default(), |
|
|
|
|
init_t: Utc::now(), |
|
|
|
|
start_t: None, |
|
|
|
|
} |
|
|
|
@ -49,4 +53,15 @@ impl Match { |
|
|
|
|
pub fn set_start(&mut self, t: DateTime<Utc>) { |
|
|
|
|
self.start_t = Some(t); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Queue a new game action
|
|
|
|
|
pub async fn queue(&self, cmd: Action) { |
|
|
|
|
self.inbox.write().await.push_back(cmd); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub async fn handle_inbex(&mut self) { |
|
|
|
|
for act in self.inbox.write().await.drain() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|