aboutsummaryrefslogtreecommitdiff
path: root/games/rstnode/rst-core/src/wire/game/update.rs
blob: 44a2e646bd34c0cfb580ad6f4ca1d4f1e5824d78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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,
}