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
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use server::*;

/// All possible server packets.
///
/// This is an enum of all possible packet
/// message types.
///
/// Some packets do not contain any data
/// and thus do not have any data within
/// their enum variants.
/// 
/// The [`From`][0] trait has been implemented
/// for all the structs that correspond to the
/// variants of this enum. This means that instead
/// of directly constructing an instance of 
/// `ServerPacket`, [`into()`][1] can be called
/// instead.
/// 
/// [0]: https://doc.rust-lang.org/std/convert/trait.From.html
/// [1]: https://doc.rust-lang.org/std/convert/trait.Into.html#tymethod.into
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum ServerPacket {
	Login(Login),
	Backup,
	Ping(Ping),
	PingResult(PingResult),
	Ack,
	Error(Error),
	CommandReply(CommandReply),
	PlayerNew(PlayerNew),
	PlayerLeave(PlayerLeave),
	PlayerUpdate(PlayerUpdate),
	PlayerFire(PlayerFire),
	PlayerRespawn(PlayerRespawn),
	PlayerFlag(PlayerFlag),
	PlayerHit(PlayerHit),
	PlayerKill(PlayerKill),
	PlayerUpgrade(PlayerUpgrade),
	PlayerType(PlayerType),
	PlayerPowerup(PlayerPowerup),
	PlayerLevel(PlayerLevel),
	PlayerReteam(PlayerReteam),
	GameFlag(GameFlag),
	GameSpectate(GameSpectate),
	GamePlayersAlive(GamePlayersAlive),
	GameFirewall(GameFirewall),
	EventRepel(EventRepel),
	EventBoost(EventBoost),
	EventBounce(EventBounce),
	EventStealth(EventStealth),
	EventLeaveHorizon(EventLeaveHorizon),
	MobUpdate(MobUpdate),
	MobUpdateStationary(MobUpdateStationary),
	MobDespawn(MobDespawn),
	MobDespawnCoords(MobDespawnCoords),
	ScoreUpdate(ScoreUpdate),
	ScoreBoard(ScoreBoard),
	ScoreDetailedFFA(ScoreDetailedFFA),
	ScoreDetailedCTF(ScoreDetailedCTF),
	ScoreDetailedBTR(ScoreDetailedBTR),
	ChatTeam(ChatTeam),
	ChatPublic(ChatPublic),
	ChatSay(ChatSay),
	ChatWhisper(ChatWhisper),
	ChatVoteMutePassed(ChatVoteMutePassed),
	ChatVoteMuted,
	ServerMessage(ServerMessage),
	ServerCustom(ServerCustom),
}

macro_rules! impl_from_newtype {
	($type:tt) => {
		impl_from_newtype_inner!(ServerPacket, $type);
	};
}

macro_rules! impl_from_empty {
	($type:tt) => {
		impl_from_empty_inner!(ServerPacket, $type);
	};
}

impl_from_newtype!(Login);
impl_from_newtype!(Ping);
impl_from_newtype!(PingResult);
impl_from_newtype!(Error);
impl_from_newtype!(CommandReply);
impl_from_newtype!(PlayerNew);
impl_from_newtype!(PlayerLeave);
impl_from_newtype!(PlayerUpdate);
impl_from_newtype!(PlayerFire);
impl_from_newtype!(PlayerRespawn);
impl_from_newtype!(PlayerFlag);
impl_from_newtype!(PlayerHit);
impl_from_newtype!(PlayerKill);
impl_from_newtype!(PlayerUpgrade);
impl_from_newtype!(PlayerType);
impl_from_newtype!(PlayerPowerup);
impl_from_newtype!(PlayerLevel);
impl_from_newtype!(PlayerReteam);
impl_from_newtype!(GameFlag);
impl_from_newtype!(GameSpectate);
impl_from_newtype!(GamePlayersAlive);
impl_from_newtype!(GameFirewall);
impl_from_newtype!(EventRepel);
impl_from_newtype!(EventBoost);
impl_from_newtype!(EventBounce);
impl_from_newtype!(EventStealth);
impl_from_newtype!(EventLeaveHorizon);
impl_from_newtype!(MobUpdate);
impl_from_newtype!(MobUpdateStationary);
impl_from_newtype!(MobDespawn);
impl_from_newtype!(MobDespawnCoords);
impl_from_newtype!(ScoreUpdate);
impl_from_newtype!(ScoreBoard);
impl_from_newtype!(ScoreDetailedFFA);
impl_from_newtype!(ScoreDetailedCTF);
impl_from_newtype!(ScoreDetailedBTR);
impl_from_newtype!(ChatTeam);
impl_from_newtype!(ChatPublic);
impl_from_newtype!(ChatSay);
impl_from_newtype!(ChatWhisper);
impl_from_newtype!(ChatVoteMutePassed);
impl_from_newtype!(ServerMessage);
impl_from_newtype!(ServerCustom);

impl_from_empty!(Backup);
impl_from_empty!(Ack);
impl_from_empty!(ChatVoteMuted);