diff options
Diffstat (limited to 'games/rstnode/rst-core/src/wire/game')
-rw-r--r-- | games/rstnode/rst-core/src/wire/game/action.rs | 33 | ||||
-rw-r--r-- | games/rstnode/rst-core/src/wire/game/mod.rs | 5 | ||||
-rw-r--r-- | games/rstnode/rst-core/src/wire/game/update.rs | 75 |
3 files changed, 113 insertions, 0 deletions
diff --git a/games/rstnode/rst-core/src/wire/game/action.rs b/games/rstnode/rst-core/src/wire/game/action.rs new file mode 100644 index 000000000000..22ab7ce6868e --- /dev/null +++ b/games/rstnode/rst-core/src/wire/game/action.rs @@ -0,0 +1,33 @@ +use crate::data::{NodeId, Upgrade}; +use serde::{Deserialize, Serialize}; + +/// All actions that a user can trigger via the UI +#[derive(Serialize, Deserialize)] +pub enum Action { + /// Cancel the running action + Cancel(NodeId), + /// Start a capture action + Capture { from: NodeId, to: NodeId }, + /// Set the compute targets + Compute { from: NodeId, to: Vec<NodeId> }, + /// Set to payload analysis mode + Payload(NodeId), + /// Send an exploit across the network + Reset { + from: NodeId, + to: NodeId, + exp: Exploit, + }, + /// Try to upgrade the node to a level + Upgrade { node: NodeId, level: Upgrade }, +} + +/// A type of exploit a node can start running +#[derive(Serialize, Deserialize)] +pub enum Exploit { + Reset, + CNS, + Nitm, + Virus, + TakeOver, +} diff --git a/games/rstnode/rst-core/src/wire/game/mod.rs b/games/rstnode/rst-core/src/wire/game/mod.rs new file mode 100644 index 000000000000..2cb32cbaa79c --- /dev/null +++ b/games/rstnode/rst-core/src/wire/game/mod.rs @@ -0,0 +1,5 @@ +mod action; +pub use action::*; + +mod update; +pub use update::*; diff --git a/games/rstnode/rst-core/src/wire/game/update.rs b/games/rstnode/rst-core/src/wire/game/update.rs new file mode 100644 index 000000000000..44a2e646bd34 --- /dev/null +++ b/games/rstnode/rst-core/src/wire/game/update.rs @@ -0,0 +1,75 @@ +//! Update to the game state + +use crate::{ + data::{NodeId, PacketId, Player, Upgrade}, + wire::UserId, +}; +use serde::{Deserialize, Serialize}; + +/// An update provided by the game server +#[derive(Clone, Serialize, Deserialize)] +pub enum Update { + /// Update made to a node + Node(NodeUpdate), + /// Update made to a link + Link(LinkUpdate), + /// Update made to a packet + Packet(PacketUpdate), + /// Update made to the user set + User(UserUpdate), + /// An error occured, can be non-fatal + Error(UpdateError), +} + +/// Update made to a node +#[derive(Clone, Serialize, Deserialize)] +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(Clone, Serialize, Deserialize)] +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(Clone, Serialize, Deserialize)] +pub enum PacketUpdate { + /// Advance a packet along one step along the link + Increment(PacketId), +} + +/// Update made to the user set +#[derive(Clone, Serialize, Deserialize)] +pub enum UserUpdate { + UserLeft(UserId), + UserPaused(UserId), +} + +/// An error occured, can be non-fatal +#[derive(Clone, Serialize, Deserialize)] +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, +} |