aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2020-03-19 07:58:35 +0100
committerKatharina Fey <kookie@spacekookie.de>2020-03-19 07:58:35 +0100
commit8d1556fce91bbd4301cd13d4ad087640d343fad1 (patch)
tree7d532d67ffb33baa4f10b16a5b407b51a93ad661
parent32a202068b177c1218632fee41179f651e3b08e9 (diff)
Adding update methods to the map
-rw-r--r--src/main.rs1
-rw-r--r--src/map.rs21
-rw-r--r--src/wire/mod.rs27
-rw-r--r--src/wire/update.rs34
4 files changed, 67 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs
index 647fec9b18b2..e51b38750ead 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,6 +6,7 @@ mod io;
mod map;
mod stats;
mod wire;
+mod server;
use ggez::{
self, conf,
diff --git a/src/map.rs b/src/map.rs
index dd1fe1c6347e..6d279db468e3 100644
--- a/src/map.rs
+++ b/src/map.rs
@@ -1,6 +1,10 @@
//! Implements a map graph and world logic
-use crate::data::{Link, Node};
+use crate::{
+ data::{Link, Node},
+ server::{Result, ServerErr},
+ wire::Response
+};
use async_std::sync::Arc;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
@@ -11,7 +15,7 @@ use std::collections::BTreeMap;
/// the map nodes are placed, how much spacing there is, etc. All
/// this information is encoded in the same structs because it's
/// static, and just more convenient.
-#[derive(Serialize, Deserialize)]
+#[derive(Default, Serialize, Deserialize)]
pub struct Map {
/// Node IDs mapped to node objects
nodes: BTreeMap<u16, Arc<Node>>,
@@ -19,4 +23,15 @@ pub struct Map {
links: BTreeMap<u16, Arc<Link>>,
}
-impl Map {}
+impl Map {
+ pub fn new() -> Arc<Self> {
+ Arc::new(Self::default())
+ }
+
+ pub fn update<F>(&mut self, cb: F) -> Result<Response>
+ where
+ F: Fn(&mut Map) -> Result<Response>,
+ {
+ unimplemented!()
+ }
+}
diff --git a/src/wire/mod.rs b/src/wire/mod.rs
index 257333ee118c..78d618627d34 100644
--- a/src/wire/mod.rs
+++ b/src/wire/mod.rs
@@ -1,9 +1,16 @@
//! Network formats and container messages
mod action;
+pub use action::*;
+
mod req;
+pub use req::*;
+
mod resp;
+pub use resp::*;
+
mod update;
+pub use update::*;
use crate::{
data::{Color, Player},
@@ -27,7 +34,7 @@ pub struct User {
/// A more lobby specific abstraction for a user
#[derive(Serialize, Deserialize)]
-struct LobbyUser {
+pub struct LobbyUser {
/// The user ID
id: UserId,
/// Their nick name
@@ -45,13 +52,13 @@ pub type LobbyId = usize;
#[derive(Serialize, Deserialize)]
pub struct Lobby {
/// The ID of the lobby
- id: LobbyId,
+ pub id: LobbyId,
/// A set of user IDs
- players: Vec<LobbyUser>,
+ pub players: Vec<LobbyUser>,
/// The name of the map
- map: String,
+ pub map: String,
/// Settings
- settings: Vec<String>,
+ pub settings: Vec<String>,
}
/// An alias for a match ID
@@ -60,16 +67,16 @@ pub type MatchId = usize;
/// Mapping users to a player in game
#[derive(Serialize, Deserialize)]
pub struct MatchUser {
- user: User,
- player: Player,
+ pub user: User,
+ pub player: Player,
}
#[derive(Serialize, Deserialize)]
pub struct Match {
/// The match id
- id: MatchId,
+ pub id: MatchId,
/// The list of active players
- players: Vec<MatchUser>,
+ pub players: Vec<MatchUser>,
/// The active game map
- map: Map,
+ pub map: Map,
}
diff --git a/src/wire/update.rs b/src/wire/update.rs
index 27f2d0ddded3..a1b47ff07e50 100644
--- a/src/wire/update.rs
+++ b/src/wire/update.rs
@@ -1,6 +1,7 @@
//! Update to the game state
use super::UserId;
+use crate::data::{NodeId, PacketId, Player, Upgrade};
use serde::{Deserialize, Serialize};
/// An update provided by the game server
@@ -20,15 +21,34 @@ pub enum Update {
/// Update made to a node
#[derive(Serialize, Deserialize)]
-pub enum NodeUpdate {}
+pub enum NodeUpdate {
+ /// The node owner changed
+ Owner(Player),
+ /// Represent a new upgrade state
+ Level { node: NodeId, new: Upgrade },
+ /// A new packet was consumed from a link
+ NewPacket(PacketId),
+ /// Remove a packet from the node buffer
+ SentPacket(PacketId),
+ /// Dropped a packet
+ DropPacket(PacketId),
+}
/// Update made to a link
#[derive(Serialize, Deserialize)]
-pub enum LinkUpdate {}
+pub enum LinkUpdate {
+ /// Take a packet from a node's buffer
+ TakePacket(PacketId),
+ /// Give a packet to a node's buffer
+ GivePacket(PacketId),
+}
/// Update made to a packet
#[derive(Serialize, Deserialize)]
-pub enum PacketUpdate {}
+pub enum PacketUpdate {
+ /// Advance a packet along one step along the link
+ Increment(PacketId),
+}
/// Update made to the user set
#[derive(Serialize, Deserialize)]
@@ -41,4 +61,12 @@ pub enum UserUpdate {
pub enum UpdateError {
/// You are the last user in the match
LastUser,
+ /// The game crashed, so kick all
+ GameCrashed,
+ /// The server's time was behind the client time
+ ///
+ /// This means that newer events will be dropped from the map
+ /// state. This should prompt the client to warn the user this
+ /// has happened, then resync the time of the game states.
+ TimeAheadServer,
}