Skip to main content

libtw2_gamenet_teeworlds_0_7/msg/
game.rs

1use crate::enums;
2use crate::error::Error;
3use libtw2_buffer::CapacityError;
4use libtw2_common::pretty;
5use libtw2_gamenet_common::debug::DebugSlice;
6use libtw2_packer::Packer;
7use libtw2_packer::Unpacker;
8use libtw2_packer::Warning;
9use libtw2_packer::at_least;
10use libtw2_packer::in_range;
11use libtw2_packer::positive;
12use libtw2_packer::sanitize;
13use libtw2_packer::to_bool;
14use libtw2_packer::with_packer;
15use libtw2_warn::Panic;
16use libtw2_warn::Warn;
17use libtw2_warn::wrap;
18use std::fmt;
19use super::MessageId;
20use super::SystemOrGame;
21
22pub use libtw2_gamenet_common::msg::TuneParam;
23
24impl<'a> Game<'a> {
25    pub fn decode<W>(warn: &mut W, p: &mut Unpacker<'a>) -> Result<Game<'a>, Error>
26        where W: Warn<Warning>
27    {
28        if let SystemOrGame::Game(msg_id) = SystemOrGame::decode_id(warn, p)? {
29            Game::decode_msg(warn, msg_id, p)
30        } else {
31            Err(Error::UnknownId)
32        }
33    }
34    pub fn encode<'d, 's>(&self, mut p: Packer<'d, 's>)
35        -> Result<&'d [u8], CapacityError>
36    {
37        with_packer(&mut p, |p| SystemOrGame::Game(self.msg_id()).encode_id(p))?;
38        with_packer(&mut p, |p| self.encode_msg(p))?;
39        Ok(p.written())
40    }
41}
42
43pub const SV_MOTD: i32 = 1;
44pub const SV_BROADCAST: i32 = 2;
45pub const SV_CHAT: i32 = 3;
46pub const SV_TEAM: i32 = 4;
47pub const SV_KILL_MSG: i32 = 5;
48pub const SV_TUNE_PARAMS: i32 = 6;
49pub const SV_EXTRA_PROJECTILE: i32 = 7;
50pub const SV_READY_TO_ENTER: i32 = 8;
51pub const SV_WEAPON_PICKUP: i32 = 9;
52pub const SV_EMOTICON: i32 = 10;
53pub const SV_VOTE_CLEAR_OPTIONS: i32 = 11;
54pub const SV_VOTE_OPTION_LIST_ADD: i32 = 12;
55pub const SV_VOTE_OPTION_ADD: i32 = 13;
56pub const SV_VOTE_OPTION_REMOVE: i32 = 14;
57pub const SV_VOTE_SET: i32 = 15;
58pub const SV_VOTE_STATUS: i32 = 16;
59pub const SV_SERVER_SETTINGS: i32 = 17;
60pub const SV_CLIENT_INFO: i32 = 18;
61pub const SV_GAME_INFO: i32 = 19;
62pub const SV_CLIENT_DROP: i32 = 20;
63pub const SV_GAME_MSG: i32 = 21;
64pub const DE_CLIENT_ENTER: i32 = 22;
65pub const DE_CLIENT_LEAVE: i32 = 23;
66pub const CL_SAY: i32 = 24;
67pub const CL_SET_TEAM: i32 = 25;
68pub const CL_SET_SPECTATOR_MODE: i32 = 26;
69pub const CL_START_INFO: i32 = 27;
70pub const CL_KILL: i32 = 28;
71pub const CL_READY_CHANGE: i32 = 29;
72pub const CL_EMOTICON: i32 = 30;
73pub const CL_VOTE: i32 = 31;
74pub const CL_CALL_VOTE: i32 = 32;
75pub const SV_SKIN_CHANGE: i32 = 33;
76pub const CL_SKIN_CHANGE: i32 = 34;
77pub const SV_RACE_FINISH: i32 = 35;
78pub const SV_CHECKPOINT: i32 = 36;
79pub const SV_COMMAND_INFO: i32 = 37;
80pub const SV_COMMAND_INFO_REMOVE: i32 = 38;
81pub const CL_COMMAND: i32 = 39;
82
83#[derive(Clone, Copy)]
84pub enum Game<'a> {
85    SvMotd(SvMotd<'a>),
86    SvBroadcast(SvBroadcast<'a>),
87    SvChat(SvChat<'a>),
88    SvTeam(SvTeam),
89    SvKillMsg(SvKillMsg),
90    SvTuneParams(SvTuneParams),
91    SvExtraProjectile(SvExtraProjectile),
92    SvReadyToEnter(SvReadyToEnter),
93    SvWeaponPickup(SvWeaponPickup),
94    SvEmoticon(SvEmoticon),
95    SvVoteClearOptions(SvVoteClearOptions),
96    SvVoteOptionListAdd(SvVoteOptionListAdd),
97    SvVoteOptionAdd(SvVoteOptionAdd<'a>),
98    SvVoteOptionRemove(SvVoteOptionRemove<'a>),
99    SvVoteSet(SvVoteSet<'a>),
100    SvVoteStatus(SvVoteStatus),
101    SvServerSettings(SvServerSettings),
102    SvClientInfo(SvClientInfo<'a>),
103    SvGameInfo(SvGameInfo),
104    SvClientDrop(SvClientDrop<'a>),
105    SvGameMsg(SvGameMsg),
106    DeClientEnter(DeClientEnter<'a>),
107    DeClientLeave(DeClientLeave<'a>),
108    ClSay(ClSay<'a>),
109    ClSetTeam(ClSetTeam),
110    ClSetSpectatorMode(ClSetSpectatorMode),
111    ClStartInfo(ClStartInfo<'a>),
112    ClKill(ClKill),
113    ClReadyChange(ClReadyChange),
114    ClEmoticon(ClEmoticon),
115    ClVote(ClVote),
116    ClCallVote(ClCallVote<'a>),
117    SvSkinChange(SvSkinChange<'a>),
118    ClSkinChange(ClSkinChange<'a>),
119    SvRaceFinish(SvRaceFinish),
120    SvCheckpoint(SvCheckpoint),
121    SvCommandInfo(SvCommandInfo<'a>),
122    SvCommandInfoRemove(SvCommandInfoRemove<'a>),
123    ClCommand(ClCommand<'a>),
124}
125
126impl<'a> Game<'a> {
127    pub fn decode_msg<W: Warn<Warning>>(warn: &mut W, msg_id: MessageId, _p: &mut Unpacker<'a>) -> Result<Game<'a>, Error> {
128        use self::MessageId::*;
129        Ok(match msg_id {
130            Ordinal(SV_MOTD) => Game::SvMotd(SvMotd::decode(warn, _p)?),
131            Ordinal(SV_BROADCAST) => Game::SvBroadcast(SvBroadcast::decode(warn, _p)?),
132            Ordinal(SV_CHAT) => Game::SvChat(SvChat::decode(warn, _p)?),
133            Ordinal(SV_TEAM) => Game::SvTeam(SvTeam::decode(warn, _p)?),
134            Ordinal(SV_KILL_MSG) => Game::SvKillMsg(SvKillMsg::decode(warn, _p)?),
135            Ordinal(SV_TUNE_PARAMS) => Game::SvTuneParams(SvTuneParams::decode(warn, _p)?),
136            Ordinal(SV_EXTRA_PROJECTILE) => Game::SvExtraProjectile(SvExtraProjectile::decode(warn, _p)?),
137            Ordinal(SV_READY_TO_ENTER) => Game::SvReadyToEnter(SvReadyToEnter::decode(warn, _p)?),
138            Ordinal(SV_WEAPON_PICKUP) => Game::SvWeaponPickup(SvWeaponPickup::decode(warn, _p)?),
139            Ordinal(SV_EMOTICON) => Game::SvEmoticon(SvEmoticon::decode(warn, _p)?),
140            Ordinal(SV_VOTE_CLEAR_OPTIONS) => Game::SvVoteClearOptions(SvVoteClearOptions::decode(warn, _p)?),
141            Ordinal(SV_VOTE_OPTION_LIST_ADD) => Game::SvVoteOptionListAdd(SvVoteOptionListAdd::decode(warn, _p)?),
142            Ordinal(SV_VOTE_OPTION_ADD) => Game::SvVoteOptionAdd(SvVoteOptionAdd::decode(warn, _p)?),
143            Ordinal(SV_VOTE_OPTION_REMOVE) => Game::SvVoteOptionRemove(SvVoteOptionRemove::decode(warn, _p)?),
144            Ordinal(SV_VOTE_SET) => Game::SvVoteSet(SvVoteSet::decode(warn, _p)?),
145            Ordinal(SV_VOTE_STATUS) => Game::SvVoteStatus(SvVoteStatus::decode(warn, _p)?),
146            Ordinal(SV_SERVER_SETTINGS) => Game::SvServerSettings(SvServerSettings::decode(warn, _p)?),
147            Ordinal(SV_CLIENT_INFO) => Game::SvClientInfo(SvClientInfo::decode(warn, _p)?),
148            Ordinal(SV_GAME_INFO) => Game::SvGameInfo(SvGameInfo::decode(warn, _p)?),
149            Ordinal(SV_CLIENT_DROP) => Game::SvClientDrop(SvClientDrop::decode(warn, _p)?),
150            Ordinal(SV_GAME_MSG) => Game::SvGameMsg(SvGameMsg::decode(warn, _p)?),
151            Ordinal(DE_CLIENT_ENTER) => Game::DeClientEnter(DeClientEnter::decode(warn, _p)?),
152            Ordinal(DE_CLIENT_LEAVE) => Game::DeClientLeave(DeClientLeave::decode(warn, _p)?),
153            Ordinal(CL_SAY) => Game::ClSay(ClSay::decode(warn, _p)?),
154            Ordinal(CL_SET_TEAM) => Game::ClSetTeam(ClSetTeam::decode(warn, _p)?),
155            Ordinal(CL_SET_SPECTATOR_MODE) => Game::ClSetSpectatorMode(ClSetSpectatorMode::decode(warn, _p)?),
156            Ordinal(CL_START_INFO) => Game::ClStartInfo(ClStartInfo::decode(warn, _p)?),
157            Ordinal(CL_KILL) => Game::ClKill(ClKill::decode(warn, _p)?),
158            Ordinal(CL_READY_CHANGE) => Game::ClReadyChange(ClReadyChange::decode(warn, _p)?),
159            Ordinal(CL_EMOTICON) => Game::ClEmoticon(ClEmoticon::decode(warn, _p)?),
160            Ordinal(CL_VOTE) => Game::ClVote(ClVote::decode(warn, _p)?),
161            Ordinal(CL_CALL_VOTE) => Game::ClCallVote(ClCallVote::decode(warn, _p)?),
162            Ordinal(SV_SKIN_CHANGE) => Game::SvSkinChange(SvSkinChange::decode(warn, _p)?),
163            Ordinal(CL_SKIN_CHANGE) => Game::ClSkinChange(ClSkinChange::decode(warn, _p)?),
164            Ordinal(SV_RACE_FINISH) => Game::SvRaceFinish(SvRaceFinish::decode(warn, _p)?),
165            Ordinal(SV_CHECKPOINT) => Game::SvCheckpoint(SvCheckpoint::decode(warn, _p)?),
166            Ordinal(SV_COMMAND_INFO) => Game::SvCommandInfo(SvCommandInfo::decode(warn, _p)?),
167            Ordinal(SV_COMMAND_INFO_REMOVE) => Game::SvCommandInfoRemove(SvCommandInfoRemove::decode(warn, _p)?),
168            Ordinal(CL_COMMAND) => Game::ClCommand(ClCommand::decode(warn, _p)?),
169            _ => return Err(Error::UnknownId),
170        })
171    }
172    pub fn msg_id(&self) -> MessageId {
173        match *self {
174            Game::SvMotd(_) => MessageId::from(SV_MOTD),
175            Game::SvBroadcast(_) => MessageId::from(SV_BROADCAST),
176            Game::SvChat(_) => MessageId::from(SV_CHAT),
177            Game::SvTeam(_) => MessageId::from(SV_TEAM),
178            Game::SvKillMsg(_) => MessageId::from(SV_KILL_MSG),
179            Game::SvTuneParams(_) => MessageId::from(SV_TUNE_PARAMS),
180            Game::SvExtraProjectile(_) => MessageId::from(SV_EXTRA_PROJECTILE),
181            Game::SvReadyToEnter(_) => MessageId::from(SV_READY_TO_ENTER),
182            Game::SvWeaponPickup(_) => MessageId::from(SV_WEAPON_PICKUP),
183            Game::SvEmoticon(_) => MessageId::from(SV_EMOTICON),
184            Game::SvVoteClearOptions(_) => MessageId::from(SV_VOTE_CLEAR_OPTIONS),
185            Game::SvVoteOptionListAdd(_) => MessageId::from(SV_VOTE_OPTION_LIST_ADD),
186            Game::SvVoteOptionAdd(_) => MessageId::from(SV_VOTE_OPTION_ADD),
187            Game::SvVoteOptionRemove(_) => MessageId::from(SV_VOTE_OPTION_REMOVE),
188            Game::SvVoteSet(_) => MessageId::from(SV_VOTE_SET),
189            Game::SvVoteStatus(_) => MessageId::from(SV_VOTE_STATUS),
190            Game::SvServerSettings(_) => MessageId::from(SV_SERVER_SETTINGS),
191            Game::SvClientInfo(_) => MessageId::from(SV_CLIENT_INFO),
192            Game::SvGameInfo(_) => MessageId::from(SV_GAME_INFO),
193            Game::SvClientDrop(_) => MessageId::from(SV_CLIENT_DROP),
194            Game::SvGameMsg(_) => MessageId::from(SV_GAME_MSG),
195            Game::DeClientEnter(_) => MessageId::from(DE_CLIENT_ENTER),
196            Game::DeClientLeave(_) => MessageId::from(DE_CLIENT_LEAVE),
197            Game::ClSay(_) => MessageId::from(CL_SAY),
198            Game::ClSetTeam(_) => MessageId::from(CL_SET_TEAM),
199            Game::ClSetSpectatorMode(_) => MessageId::from(CL_SET_SPECTATOR_MODE),
200            Game::ClStartInfo(_) => MessageId::from(CL_START_INFO),
201            Game::ClKill(_) => MessageId::from(CL_KILL),
202            Game::ClReadyChange(_) => MessageId::from(CL_READY_CHANGE),
203            Game::ClEmoticon(_) => MessageId::from(CL_EMOTICON),
204            Game::ClVote(_) => MessageId::from(CL_VOTE),
205            Game::ClCallVote(_) => MessageId::from(CL_CALL_VOTE),
206            Game::SvSkinChange(_) => MessageId::from(SV_SKIN_CHANGE),
207            Game::ClSkinChange(_) => MessageId::from(CL_SKIN_CHANGE),
208            Game::SvRaceFinish(_) => MessageId::from(SV_RACE_FINISH),
209            Game::SvCheckpoint(_) => MessageId::from(SV_CHECKPOINT),
210            Game::SvCommandInfo(_) => MessageId::from(SV_COMMAND_INFO),
211            Game::SvCommandInfoRemove(_) => MessageId::from(SV_COMMAND_INFO_REMOVE),
212            Game::ClCommand(_) => MessageId::from(CL_COMMAND),
213        }
214    }
215    pub fn encode_msg<'d, 's>(&self, p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
216        match *self {
217            Game::SvMotd(ref i) => i.encode(p),
218            Game::SvBroadcast(ref i) => i.encode(p),
219            Game::SvChat(ref i) => i.encode(p),
220            Game::SvTeam(ref i) => i.encode(p),
221            Game::SvKillMsg(ref i) => i.encode(p),
222            Game::SvTuneParams(ref i) => i.encode(p),
223            Game::SvExtraProjectile(ref i) => i.encode(p),
224            Game::SvReadyToEnter(ref i) => i.encode(p),
225            Game::SvWeaponPickup(ref i) => i.encode(p),
226            Game::SvEmoticon(ref i) => i.encode(p),
227            Game::SvVoteClearOptions(ref i) => i.encode(p),
228            Game::SvVoteOptionListAdd(ref i) => i.encode(p),
229            Game::SvVoteOptionAdd(ref i) => i.encode(p),
230            Game::SvVoteOptionRemove(ref i) => i.encode(p),
231            Game::SvVoteSet(ref i) => i.encode(p),
232            Game::SvVoteStatus(ref i) => i.encode(p),
233            Game::SvServerSettings(ref i) => i.encode(p),
234            Game::SvClientInfo(ref i) => i.encode(p),
235            Game::SvGameInfo(ref i) => i.encode(p),
236            Game::SvClientDrop(ref i) => i.encode(p),
237            Game::SvGameMsg(ref i) => i.encode(p),
238            Game::DeClientEnter(ref i) => i.encode(p),
239            Game::DeClientLeave(ref i) => i.encode(p),
240            Game::ClSay(ref i) => i.encode(p),
241            Game::ClSetTeam(ref i) => i.encode(p),
242            Game::ClSetSpectatorMode(ref i) => i.encode(p),
243            Game::ClStartInfo(ref i) => i.encode(p),
244            Game::ClKill(ref i) => i.encode(p),
245            Game::ClReadyChange(ref i) => i.encode(p),
246            Game::ClEmoticon(ref i) => i.encode(p),
247            Game::ClVote(ref i) => i.encode(p),
248            Game::ClCallVote(ref i) => i.encode(p),
249            Game::SvSkinChange(ref i) => i.encode(p),
250            Game::ClSkinChange(ref i) => i.encode(p),
251            Game::SvRaceFinish(ref i) => i.encode(p),
252            Game::SvCheckpoint(ref i) => i.encode(p),
253            Game::SvCommandInfo(ref i) => i.encode(p),
254            Game::SvCommandInfoRemove(ref i) => i.encode(p),
255            Game::ClCommand(ref i) => i.encode(p),
256        }
257    }
258}
259
260impl<'a> fmt::Debug for Game<'a> {
261    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
262        match *self {
263            Game::SvMotd(ref i) => i.fmt(f),
264            Game::SvBroadcast(ref i) => i.fmt(f),
265            Game::SvChat(ref i) => i.fmt(f),
266            Game::SvTeam(ref i) => i.fmt(f),
267            Game::SvKillMsg(ref i) => i.fmt(f),
268            Game::SvTuneParams(ref i) => i.fmt(f),
269            Game::SvExtraProjectile(ref i) => i.fmt(f),
270            Game::SvReadyToEnter(ref i) => i.fmt(f),
271            Game::SvWeaponPickup(ref i) => i.fmt(f),
272            Game::SvEmoticon(ref i) => i.fmt(f),
273            Game::SvVoteClearOptions(ref i) => i.fmt(f),
274            Game::SvVoteOptionListAdd(ref i) => i.fmt(f),
275            Game::SvVoteOptionAdd(ref i) => i.fmt(f),
276            Game::SvVoteOptionRemove(ref i) => i.fmt(f),
277            Game::SvVoteSet(ref i) => i.fmt(f),
278            Game::SvVoteStatus(ref i) => i.fmt(f),
279            Game::SvServerSettings(ref i) => i.fmt(f),
280            Game::SvClientInfo(ref i) => i.fmt(f),
281            Game::SvGameInfo(ref i) => i.fmt(f),
282            Game::SvClientDrop(ref i) => i.fmt(f),
283            Game::SvGameMsg(ref i) => i.fmt(f),
284            Game::DeClientEnter(ref i) => i.fmt(f),
285            Game::DeClientLeave(ref i) => i.fmt(f),
286            Game::ClSay(ref i) => i.fmt(f),
287            Game::ClSetTeam(ref i) => i.fmt(f),
288            Game::ClSetSpectatorMode(ref i) => i.fmt(f),
289            Game::ClStartInfo(ref i) => i.fmt(f),
290            Game::ClKill(ref i) => i.fmt(f),
291            Game::ClReadyChange(ref i) => i.fmt(f),
292            Game::ClEmoticon(ref i) => i.fmt(f),
293            Game::ClVote(ref i) => i.fmt(f),
294            Game::ClCallVote(ref i) => i.fmt(f),
295            Game::SvSkinChange(ref i) => i.fmt(f),
296            Game::ClSkinChange(ref i) => i.fmt(f),
297            Game::SvRaceFinish(ref i) => i.fmt(f),
298            Game::SvCheckpoint(ref i) => i.fmt(f),
299            Game::SvCommandInfo(ref i) => i.fmt(f),
300            Game::SvCommandInfoRemove(ref i) => i.fmt(f),
301            Game::ClCommand(ref i) => i.fmt(f),
302        }
303    }
304}
305
306impl<'a> From<SvMotd<'a>> for Game<'a> {
307    fn from(i: SvMotd<'a>) -> Game<'a> {
308        Game::SvMotd(i)
309    }
310}
311
312impl<'a> From<SvBroadcast<'a>> for Game<'a> {
313    fn from(i: SvBroadcast<'a>) -> Game<'a> {
314        Game::SvBroadcast(i)
315    }
316}
317
318impl<'a> From<SvChat<'a>> for Game<'a> {
319    fn from(i: SvChat<'a>) -> Game<'a> {
320        Game::SvChat(i)
321    }
322}
323
324impl<'a> From<SvTeam> for Game<'a> {
325    fn from(i: SvTeam) -> Game<'a> {
326        Game::SvTeam(i)
327    }
328}
329
330impl<'a> From<SvKillMsg> for Game<'a> {
331    fn from(i: SvKillMsg) -> Game<'a> {
332        Game::SvKillMsg(i)
333    }
334}
335
336impl<'a> From<SvTuneParams> for Game<'a> {
337    fn from(i: SvTuneParams) -> Game<'a> {
338        Game::SvTuneParams(i)
339    }
340}
341
342impl<'a> From<SvExtraProjectile> for Game<'a> {
343    fn from(i: SvExtraProjectile) -> Game<'a> {
344        Game::SvExtraProjectile(i)
345    }
346}
347
348impl<'a> From<SvReadyToEnter> for Game<'a> {
349    fn from(i: SvReadyToEnter) -> Game<'a> {
350        Game::SvReadyToEnter(i)
351    }
352}
353
354impl<'a> From<SvWeaponPickup> for Game<'a> {
355    fn from(i: SvWeaponPickup) -> Game<'a> {
356        Game::SvWeaponPickup(i)
357    }
358}
359
360impl<'a> From<SvEmoticon> for Game<'a> {
361    fn from(i: SvEmoticon) -> Game<'a> {
362        Game::SvEmoticon(i)
363    }
364}
365
366impl<'a> From<SvVoteClearOptions> for Game<'a> {
367    fn from(i: SvVoteClearOptions) -> Game<'a> {
368        Game::SvVoteClearOptions(i)
369    }
370}
371
372impl<'a> From<SvVoteOptionListAdd> for Game<'a> {
373    fn from(i: SvVoteOptionListAdd) -> Game<'a> {
374        Game::SvVoteOptionListAdd(i)
375    }
376}
377
378impl<'a> From<SvVoteOptionAdd<'a>> for Game<'a> {
379    fn from(i: SvVoteOptionAdd<'a>) -> Game<'a> {
380        Game::SvVoteOptionAdd(i)
381    }
382}
383
384impl<'a> From<SvVoteOptionRemove<'a>> for Game<'a> {
385    fn from(i: SvVoteOptionRemove<'a>) -> Game<'a> {
386        Game::SvVoteOptionRemove(i)
387    }
388}
389
390impl<'a> From<SvVoteSet<'a>> for Game<'a> {
391    fn from(i: SvVoteSet<'a>) -> Game<'a> {
392        Game::SvVoteSet(i)
393    }
394}
395
396impl<'a> From<SvVoteStatus> for Game<'a> {
397    fn from(i: SvVoteStatus) -> Game<'a> {
398        Game::SvVoteStatus(i)
399    }
400}
401
402impl<'a> From<SvServerSettings> for Game<'a> {
403    fn from(i: SvServerSettings) -> Game<'a> {
404        Game::SvServerSettings(i)
405    }
406}
407
408impl<'a> From<SvClientInfo<'a>> for Game<'a> {
409    fn from(i: SvClientInfo<'a>) -> Game<'a> {
410        Game::SvClientInfo(i)
411    }
412}
413
414impl<'a> From<SvGameInfo> for Game<'a> {
415    fn from(i: SvGameInfo) -> Game<'a> {
416        Game::SvGameInfo(i)
417    }
418}
419
420impl<'a> From<SvClientDrop<'a>> for Game<'a> {
421    fn from(i: SvClientDrop<'a>) -> Game<'a> {
422        Game::SvClientDrop(i)
423    }
424}
425
426impl<'a> From<SvGameMsg> for Game<'a> {
427    fn from(i: SvGameMsg) -> Game<'a> {
428        Game::SvGameMsg(i)
429    }
430}
431
432impl<'a> From<DeClientEnter<'a>> for Game<'a> {
433    fn from(i: DeClientEnter<'a>) -> Game<'a> {
434        Game::DeClientEnter(i)
435    }
436}
437
438impl<'a> From<DeClientLeave<'a>> for Game<'a> {
439    fn from(i: DeClientLeave<'a>) -> Game<'a> {
440        Game::DeClientLeave(i)
441    }
442}
443
444impl<'a> From<ClSay<'a>> for Game<'a> {
445    fn from(i: ClSay<'a>) -> Game<'a> {
446        Game::ClSay(i)
447    }
448}
449
450impl<'a> From<ClSetTeam> for Game<'a> {
451    fn from(i: ClSetTeam) -> Game<'a> {
452        Game::ClSetTeam(i)
453    }
454}
455
456impl<'a> From<ClSetSpectatorMode> for Game<'a> {
457    fn from(i: ClSetSpectatorMode) -> Game<'a> {
458        Game::ClSetSpectatorMode(i)
459    }
460}
461
462impl<'a> From<ClStartInfo<'a>> for Game<'a> {
463    fn from(i: ClStartInfo<'a>) -> Game<'a> {
464        Game::ClStartInfo(i)
465    }
466}
467
468impl<'a> From<ClKill> for Game<'a> {
469    fn from(i: ClKill) -> Game<'a> {
470        Game::ClKill(i)
471    }
472}
473
474impl<'a> From<ClReadyChange> for Game<'a> {
475    fn from(i: ClReadyChange) -> Game<'a> {
476        Game::ClReadyChange(i)
477    }
478}
479
480impl<'a> From<ClEmoticon> for Game<'a> {
481    fn from(i: ClEmoticon) -> Game<'a> {
482        Game::ClEmoticon(i)
483    }
484}
485
486impl<'a> From<ClVote> for Game<'a> {
487    fn from(i: ClVote) -> Game<'a> {
488        Game::ClVote(i)
489    }
490}
491
492impl<'a> From<ClCallVote<'a>> for Game<'a> {
493    fn from(i: ClCallVote<'a>) -> Game<'a> {
494        Game::ClCallVote(i)
495    }
496}
497
498impl<'a> From<SvSkinChange<'a>> for Game<'a> {
499    fn from(i: SvSkinChange<'a>) -> Game<'a> {
500        Game::SvSkinChange(i)
501    }
502}
503
504impl<'a> From<ClSkinChange<'a>> for Game<'a> {
505    fn from(i: ClSkinChange<'a>) -> Game<'a> {
506        Game::ClSkinChange(i)
507    }
508}
509
510impl<'a> From<SvRaceFinish> for Game<'a> {
511    fn from(i: SvRaceFinish) -> Game<'a> {
512        Game::SvRaceFinish(i)
513    }
514}
515
516impl<'a> From<SvCheckpoint> for Game<'a> {
517    fn from(i: SvCheckpoint) -> Game<'a> {
518        Game::SvCheckpoint(i)
519    }
520}
521
522impl<'a> From<SvCommandInfo<'a>> for Game<'a> {
523    fn from(i: SvCommandInfo<'a>) -> Game<'a> {
524        Game::SvCommandInfo(i)
525    }
526}
527
528impl<'a> From<SvCommandInfoRemove<'a>> for Game<'a> {
529    fn from(i: SvCommandInfoRemove<'a>) -> Game<'a> {
530        Game::SvCommandInfoRemove(i)
531    }
532}
533
534impl<'a> From<ClCommand<'a>> for Game<'a> {
535    fn from(i: ClCommand<'a>) -> Game<'a> {
536        Game::ClCommand(i)
537    }
538}
539#[derive(Clone, Copy)]
540pub struct SvMotd<'a> {
541    pub message: &'a [u8],
542}
543
544#[derive(Clone, Copy)]
545pub struct SvBroadcast<'a> {
546    pub message: &'a [u8],
547}
548
549#[derive(Clone, Copy)]
550pub struct SvChat<'a> {
551    pub mode: enums::Chat,
552    pub client_id: i32,
553    pub target_id: i32,
554    pub message: &'a [u8],
555}
556
557#[derive(Clone, Copy)]
558pub struct SvTeam {
559    pub client_id: i32,
560    pub team: enums::Team,
561    pub silent: bool,
562    pub cooldown_tick: crate::snap_obj::Tick,
563}
564
565#[derive(Clone, Copy)]
566pub struct SvKillMsg {
567    pub killer: i32,
568    pub victim: i32,
569    pub weapon: i32,
570    pub mode_special: i32,
571}
572
573#[derive(Clone, Copy)]
574pub struct SvTuneParams {
575    pub ground_control_speed: TuneParam,
576    pub ground_control_accel: TuneParam,
577    pub ground_friction: TuneParam,
578    pub ground_jump_impulse: TuneParam,
579    pub air_jump_impulse: TuneParam,
580    pub air_control_speed: TuneParam,
581    pub air_control_accel: TuneParam,
582    pub air_friction: TuneParam,
583    pub hook_length: TuneParam,
584    pub hook_fire_speed: TuneParam,
585    pub hook_drag_accel: TuneParam,
586    pub hook_drag_speed: TuneParam,
587    pub gravity: TuneParam,
588    pub velramp_start: TuneParam,
589    pub velramp_range: TuneParam,
590    pub velramp_curvature: TuneParam,
591    pub gun_curvature: TuneParam,
592    pub gun_speed: TuneParam,
593    pub gun_lifetime: TuneParam,
594    pub shotgun_curvature: TuneParam,
595    pub shotgun_speed: TuneParam,
596    pub shotgun_speeddiff: TuneParam,
597    pub shotgun_lifetime: TuneParam,
598    pub grenade_curvature: TuneParam,
599    pub grenade_speed: TuneParam,
600    pub grenade_lifetime: TuneParam,
601    pub laser_reach: TuneParam,
602    pub laser_bounce_delay: TuneParam,
603    pub laser_bounce_num: TuneParam,
604    pub laser_bounce_cost: TuneParam,
605    pub player_collision: TuneParam,
606    pub player_hooking: TuneParam,
607}
608
609#[derive(Clone, Copy)]
610pub struct SvExtraProjectile {
611    pub projectile: crate::snap_obj::Projectile,
612}
613
614#[derive(Clone, Copy)]
615pub struct SvReadyToEnter;
616
617#[derive(Clone, Copy)]
618pub struct SvWeaponPickup {
619    pub weapon: enums::Weapon,
620}
621
622#[derive(Clone, Copy)]
623pub struct SvEmoticon {
624    pub client_id: i32,
625    pub emoticon: enums::Emoticon,
626}
627
628#[derive(Clone, Copy)]
629pub struct SvVoteClearOptions;
630
631#[derive(Clone, Copy)]
632pub struct SvVoteOptionListAdd;
633
634#[derive(Clone, Copy)]
635pub struct SvVoteOptionAdd<'a> {
636    pub description: &'a [u8],
637}
638
639#[derive(Clone, Copy)]
640pub struct SvVoteOptionRemove<'a> {
641    pub description: &'a [u8],
642}
643
644#[derive(Clone, Copy)]
645pub struct SvVoteSet<'a> {
646    pub client_id: i32,
647    pub type_: enums::Vote,
648    pub timeout: i32,
649    pub description: &'a [u8],
650    pub reason: &'a [u8],
651}
652
653#[derive(Clone, Copy)]
654pub struct SvVoteStatus {
655    pub yes: i32,
656    pub no: i32,
657    pub pass: i32,
658    pub total: i32,
659}
660
661#[derive(Clone, Copy)]
662pub struct SvServerSettings {
663    pub kick_vote: bool,
664    pub kick_min: i32,
665    pub spec_vote: bool,
666    pub team_lock: bool,
667    pub team_balance: bool,
668    pub player_slots: i32,
669}
670
671#[derive(Clone, Copy)]
672pub struct SvClientInfo<'a> {
673    pub client_id: i32,
674    pub local: bool,
675    pub team: enums::Team,
676    pub name: &'a [u8],
677    pub clan: &'a [u8],
678    pub country: i32,
679    pub skin_part_names: [&'a [u8]; 6],
680    pub use_custom_colors: [bool; 6],
681    pub skin_part_colors: [i32; 6],
682    pub silent: bool,
683}
684
685#[derive(Clone, Copy)]
686pub struct SvGameInfo {
687    pub game_flags: i32,
688    pub score_limit: i32,
689    pub time_limit: i32,
690    pub match_num: i32,
691    pub match_current: i32,
692}
693
694#[derive(Clone, Copy)]
695pub struct SvClientDrop<'a> {
696    pub client_id: i32,
697    pub reason: &'a [u8],
698    pub silent: bool,
699}
700
701#[derive(Clone, Copy)]
702pub struct SvGameMsg;
703
704#[derive(Clone, Copy)]
705pub struct DeClientEnter<'a> {
706    pub name: &'a [u8],
707    pub client_id: i32,
708    pub team: enums::Team,
709}
710
711#[derive(Clone, Copy)]
712pub struct DeClientLeave<'a> {
713    pub name: &'a [u8],
714    pub client_id: i32,
715    pub reason: &'a [u8],
716}
717
718#[derive(Clone, Copy)]
719pub struct ClSay<'a> {
720    pub mode: enums::Chat,
721    pub target: i32,
722    pub message: &'a [u8],
723}
724
725#[derive(Clone, Copy)]
726pub struct ClSetTeam {
727    pub team: enums::Team,
728}
729
730#[derive(Clone, Copy)]
731pub struct ClSetSpectatorMode {
732    pub spec_mode: enums::Spec,
733    pub spectator_id: i32,
734}
735
736#[derive(Clone, Copy)]
737pub struct ClStartInfo<'a> {
738    pub name: &'a [u8],
739    pub clan: &'a [u8],
740    pub country: i32,
741    pub skin_part_names: [&'a [u8]; 6],
742    pub use_custom_colors: [bool; 6],
743    pub skin_part_colors: [i32; 6],
744}
745
746#[derive(Clone, Copy)]
747pub struct ClKill;
748
749#[derive(Clone, Copy)]
750pub struct ClReadyChange;
751
752#[derive(Clone, Copy)]
753pub struct ClEmoticon {
754    pub emoticon: enums::Emoticon,
755}
756
757#[derive(Clone, Copy)]
758pub struct ClVote {
759    pub vote: i32,
760}
761
762#[derive(Clone, Copy)]
763pub struct ClCallVote<'a> {
764    pub type_: &'a [u8],
765    pub value: &'a [u8],
766    pub reason: &'a [u8],
767    pub force: bool,
768}
769
770#[derive(Clone, Copy)]
771pub struct SvSkinChange<'a> {
772    pub client_id: i32,
773    pub skin_part_names: [&'a [u8]; 6],
774    pub use_custom_colors: [bool; 6],
775    pub skin_part_colors: [i32; 6],
776}
777
778#[derive(Clone, Copy)]
779pub struct ClSkinChange<'a> {
780    pub skin_part_names: [&'a [u8]; 6],
781    pub use_custom_colors: [bool; 6],
782    pub skin_part_colors: [i32; 6],
783}
784
785#[derive(Clone, Copy)]
786pub struct SvRaceFinish {
787    pub client_id: i32,
788    pub time: i32,
789    pub diff: i32,
790    pub record_personal: bool,
791    pub record_server: bool,
792}
793
794#[derive(Clone, Copy)]
795pub struct SvCheckpoint {
796    pub diff: i32,
797}
798
799#[derive(Clone, Copy)]
800pub struct SvCommandInfo<'a> {
801    pub name: &'a [u8],
802    pub args_format: &'a [u8],
803    pub help_text: &'a [u8],
804}
805
806#[derive(Clone, Copy)]
807pub struct SvCommandInfoRemove<'a> {
808    pub name: &'a [u8],
809}
810
811#[derive(Clone, Copy)]
812pub struct ClCommand<'a> {
813    pub name: &'a [u8],
814    pub arguments: &'a [u8],
815}
816
817impl<'a> SvMotd<'a> {
818    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<SvMotd<'a>, Error> {
819        let result = Ok(SvMotd {
820            message: _p.read_string()?,
821        });
822        _p.finish(wrap(warn));
823        result
824    }
825    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
826        _p.write_string(self.message)?;
827        Ok(_p.written())
828    }
829}
830impl<'a> fmt::Debug for SvMotd<'a> {
831    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
832        f.debug_struct("SvMotd")
833            .field("message", &pretty::Bytes::new(&self.message))
834            .finish()
835    }
836}
837
838impl<'a> SvBroadcast<'a> {
839    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<SvBroadcast<'a>, Error> {
840        let result = Ok(SvBroadcast {
841            message: _p.read_string()?,
842        });
843        _p.finish(wrap(warn));
844        result
845    }
846    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
847        _p.write_string(self.message)?;
848        Ok(_p.written())
849    }
850}
851impl<'a> fmt::Debug for SvBroadcast<'a> {
852    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
853        f.debug_struct("SvBroadcast")
854            .field("message", &pretty::Bytes::new(&self.message))
855            .finish()
856    }
857}
858
859impl<'a> SvChat<'a> {
860    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<SvChat<'a>, Error> {
861        let result = Ok(SvChat {
862            mode: enums::Chat::from_i32(_p.read_int(warn)?)?,
863            client_id: in_range(_p.read_int(warn)?, -1, 63)?,
864            target_id: in_range(_p.read_int(warn)?, -1, 63)?,
865            message: sanitize(warn, _p.read_string()?)?,
866        });
867        _p.finish(wrap(warn));
868        result
869    }
870    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
871        assert!(-1 <= self.client_id && self.client_id <= 63);
872        assert!(-1 <= self.target_id && self.target_id <= 63);
873        sanitize(&mut Panic, self.message).unwrap();
874        _p.write_int(self.mode.to_i32())?;
875        _p.write_int(self.client_id)?;
876        _p.write_int(self.target_id)?;
877        _p.write_string(self.message)?;
878        Ok(_p.written())
879    }
880}
881impl<'a> fmt::Debug for SvChat<'a> {
882    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
883        f.debug_struct("SvChat")
884            .field("mode", &self.mode)
885            .field("client_id", &self.client_id)
886            .field("target_id", &self.target_id)
887            .field("message", &pretty::Bytes::new(&self.message))
888            .finish()
889    }
890}
891
892impl SvTeam {
893    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvTeam, Error> {
894        let result = Ok(SvTeam {
895            client_id: in_range(_p.read_int(warn)?, -1, 63)?,
896            team: enums::Team::from_i32(_p.read_int(warn)?)?,
897            silent: to_bool(_p.read_int(warn)?)?,
898            cooldown_tick: crate::snap_obj::Tick(_p.read_int(warn)?),
899        });
900        _p.finish(wrap(warn));
901        result
902    }
903    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
904        assert!(-1 <= self.client_id && self.client_id <= 63);
905        _p.write_int(self.client_id)?;
906        _p.write_int(self.team.to_i32())?;
907        _p.write_int(self.silent as i32)?;
908        _p.write_int(self.cooldown_tick.0)?;
909        Ok(_p.written())
910    }
911}
912impl fmt::Debug for SvTeam {
913    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
914        f.debug_struct("SvTeam")
915            .field("client_id", &self.client_id)
916            .field("team", &self.team)
917            .field("silent", &self.silent)
918            .field("cooldown_tick", &self.cooldown_tick)
919            .finish()
920    }
921}
922
923impl SvKillMsg {
924    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvKillMsg, Error> {
925        let result = Ok(SvKillMsg {
926            killer: in_range(_p.read_int(warn)?, -2, 63)?,
927            victim: in_range(_p.read_int(warn)?, 0, 63)?,
928            weapon: in_range(_p.read_int(warn)?, -3, 5)?,
929            mode_special: _p.read_int(warn)?,
930        });
931        _p.finish(wrap(warn));
932        result
933    }
934    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
935        assert!(-2 <= self.killer && self.killer <= 63);
936        assert!(0 <= self.victim && self.victim <= 63);
937        assert!(-3 <= self.weapon && self.weapon <= 5);
938        _p.write_int(self.killer)?;
939        _p.write_int(self.victim)?;
940        _p.write_int(self.weapon)?;
941        _p.write_int(self.mode_special)?;
942        Ok(_p.written())
943    }
944}
945impl fmt::Debug for SvKillMsg {
946    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
947        f.debug_struct("SvKillMsg")
948            .field("killer", &self.killer)
949            .field("victim", &self.victim)
950            .field("weapon", &self.weapon)
951            .field("mode_special", &self.mode_special)
952            .finish()
953    }
954}
955
956impl SvTuneParams {
957    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvTuneParams, Error> {
958        let result = Ok(SvTuneParams {
959            ground_control_speed: TuneParam(_p.read_int(warn)?),
960            ground_control_accel: TuneParam(_p.read_int(warn)?),
961            ground_friction: TuneParam(_p.read_int(warn)?),
962            ground_jump_impulse: TuneParam(_p.read_int(warn)?),
963            air_jump_impulse: TuneParam(_p.read_int(warn)?),
964            air_control_speed: TuneParam(_p.read_int(warn)?),
965            air_control_accel: TuneParam(_p.read_int(warn)?),
966            air_friction: TuneParam(_p.read_int(warn)?),
967            hook_length: TuneParam(_p.read_int(warn)?),
968            hook_fire_speed: TuneParam(_p.read_int(warn)?),
969            hook_drag_accel: TuneParam(_p.read_int(warn)?),
970            hook_drag_speed: TuneParam(_p.read_int(warn)?),
971            gravity: TuneParam(_p.read_int(warn)?),
972            velramp_start: TuneParam(_p.read_int(warn)?),
973            velramp_range: TuneParam(_p.read_int(warn)?),
974            velramp_curvature: TuneParam(_p.read_int(warn)?),
975            gun_curvature: TuneParam(_p.read_int(warn)?),
976            gun_speed: TuneParam(_p.read_int(warn)?),
977            gun_lifetime: TuneParam(_p.read_int(warn)?),
978            shotgun_curvature: TuneParam(_p.read_int(warn)?),
979            shotgun_speed: TuneParam(_p.read_int(warn)?),
980            shotgun_speeddiff: TuneParam(_p.read_int(warn)?),
981            shotgun_lifetime: TuneParam(_p.read_int(warn)?),
982            grenade_curvature: TuneParam(_p.read_int(warn)?),
983            grenade_speed: TuneParam(_p.read_int(warn)?),
984            grenade_lifetime: TuneParam(_p.read_int(warn)?),
985            laser_reach: TuneParam(_p.read_int(warn)?),
986            laser_bounce_delay: TuneParam(_p.read_int(warn)?),
987            laser_bounce_num: TuneParam(_p.read_int(warn)?),
988            laser_bounce_cost: TuneParam(_p.read_int(warn)?),
989            player_collision: TuneParam(_p.read_int(warn)?),
990            player_hooking: TuneParam(_p.read_int(warn)?),
991        });
992        _p.finish(wrap(warn));
993        result
994    }
995    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
996        _p.write_int(self.ground_control_speed.0)?;
997        _p.write_int(self.ground_control_accel.0)?;
998        _p.write_int(self.ground_friction.0)?;
999        _p.write_int(self.ground_jump_impulse.0)?;
1000        _p.write_int(self.air_jump_impulse.0)?;
1001        _p.write_int(self.air_control_speed.0)?;
1002        _p.write_int(self.air_control_accel.0)?;
1003        _p.write_int(self.air_friction.0)?;
1004        _p.write_int(self.hook_length.0)?;
1005        _p.write_int(self.hook_fire_speed.0)?;
1006        _p.write_int(self.hook_drag_accel.0)?;
1007        _p.write_int(self.hook_drag_speed.0)?;
1008        _p.write_int(self.gravity.0)?;
1009        _p.write_int(self.velramp_start.0)?;
1010        _p.write_int(self.velramp_range.0)?;
1011        _p.write_int(self.velramp_curvature.0)?;
1012        _p.write_int(self.gun_curvature.0)?;
1013        _p.write_int(self.gun_speed.0)?;
1014        _p.write_int(self.gun_lifetime.0)?;
1015        _p.write_int(self.shotgun_curvature.0)?;
1016        _p.write_int(self.shotgun_speed.0)?;
1017        _p.write_int(self.shotgun_speeddiff.0)?;
1018        _p.write_int(self.shotgun_lifetime.0)?;
1019        _p.write_int(self.grenade_curvature.0)?;
1020        _p.write_int(self.grenade_speed.0)?;
1021        _p.write_int(self.grenade_lifetime.0)?;
1022        _p.write_int(self.laser_reach.0)?;
1023        _p.write_int(self.laser_bounce_delay.0)?;
1024        _p.write_int(self.laser_bounce_num.0)?;
1025        _p.write_int(self.laser_bounce_cost.0)?;
1026        _p.write_int(self.player_collision.0)?;
1027        _p.write_int(self.player_hooking.0)?;
1028        Ok(_p.written())
1029    }
1030}
1031impl fmt::Debug for SvTuneParams {
1032    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1033        f.debug_struct("SvTuneParams")
1034            .field("ground_control_speed", &self.ground_control_speed)
1035            .field("ground_control_accel", &self.ground_control_accel)
1036            .field("ground_friction", &self.ground_friction)
1037            .field("ground_jump_impulse", &self.ground_jump_impulse)
1038            .field("air_jump_impulse", &self.air_jump_impulse)
1039            .field("air_control_speed", &self.air_control_speed)
1040            .field("air_control_accel", &self.air_control_accel)
1041            .field("air_friction", &self.air_friction)
1042            .field("hook_length", &self.hook_length)
1043            .field("hook_fire_speed", &self.hook_fire_speed)
1044            .field("hook_drag_accel", &self.hook_drag_accel)
1045            .field("hook_drag_speed", &self.hook_drag_speed)
1046            .field("gravity", &self.gravity)
1047            .field("velramp_start", &self.velramp_start)
1048            .field("velramp_range", &self.velramp_range)
1049            .field("velramp_curvature", &self.velramp_curvature)
1050            .field("gun_curvature", &self.gun_curvature)
1051            .field("gun_speed", &self.gun_speed)
1052            .field("gun_lifetime", &self.gun_lifetime)
1053            .field("shotgun_curvature", &self.shotgun_curvature)
1054            .field("shotgun_speed", &self.shotgun_speed)
1055            .field("shotgun_speeddiff", &self.shotgun_speeddiff)
1056            .field("shotgun_lifetime", &self.shotgun_lifetime)
1057            .field("grenade_curvature", &self.grenade_curvature)
1058            .field("grenade_speed", &self.grenade_speed)
1059            .field("grenade_lifetime", &self.grenade_lifetime)
1060            .field("laser_reach", &self.laser_reach)
1061            .field("laser_bounce_delay", &self.laser_bounce_delay)
1062            .field("laser_bounce_num", &self.laser_bounce_num)
1063            .field("laser_bounce_cost", &self.laser_bounce_cost)
1064            .field("player_collision", &self.player_collision)
1065            .field("player_hooking", &self.player_hooking)
1066            .finish()
1067    }
1068}
1069
1070impl SvExtraProjectile {
1071    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvExtraProjectile, Error> {
1072        let result = Ok(SvExtraProjectile {
1073            projectile: crate::snap_obj::Projectile::decode_msg(warn, _p)?,
1074        });
1075        _p.finish(wrap(warn));
1076        result
1077    }
1078    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1079        with_packer(&mut _p, |p| self.projectile.encode_msg(p))?;
1080        Ok(_p.written())
1081    }
1082}
1083impl fmt::Debug for SvExtraProjectile {
1084    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1085        f.debug_struct("SvExtraProjectile")
1086            .field("projectile", &self.projectile)
1087            .finish()
1088    }
1089}
1090
1091impl SvReadyToEnter {
1092    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvReadyToEnter, Error> {
1093        let result = Ok(SvReadyToEnter);
1094        _p.finish(wrap(warn));
1095        result
1096    }
1097    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1098        Ok(_p.written())
1099    }
1100}
1101impl fmt::Debug for SvReadyToEnter {
1102    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1103        f.debug_struct("SvReadyToEnter")
1104            .finish()
1105    }
1106}
1107
1108impl SvWeaponPickup {
1109    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvWeaponPickup, Error> {
1110        let result = Ok(SvWeaponPickup {
1111            weapon: enums::Weapon::from_i32(_p.read_int(warn)?)?,
1112        });
1113        _p.finish(wrap(warn));
1114        result
1115    }
1116    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1117        _p.write_int(self.weapon.to_i32())?;
1118        Ok(_p.written())
1119    }
1120}
1121impl fmt::Debug for SvWeaponPickup {
1122    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1123        f.debug_struct("SvWeaponPickup")
1124            .field("weapon", &self.weapon)
1125            .finish()
1126    }
1127}
1128
1129impl SvEmoticon {
1130    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvEmoticon, Error> {
1131        let result = Ok(SvEmoticon {
1132            client_id: in_range(_p.read_int(warn)?, 0, 63)?,
1133            emoticon: enums::Emoticon::from_i32(_p.read_int(warn)?)?,
1134        });
1135        _p.finish(wrap(warn));
1136        result
1137    }
1138    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1139        assert!(0 <= self.client_id && self.client_id <= 63);
1140        _p.write_int(self.client_id)?;
1141        _p.write_int(self.emoticon.to_i32())?;
1142        Ok(_p.written())
1143    }
1144}
1145impl fmt::Debug for SvEmoticon {
1146    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1147        f.debug_struct("SvEmoticon")
1148            .field("client_id", &self.client_id)
1149            .field("emoticon", &self.emoticon)
1150            .finish()
1151    }
1152}
1153
1154impl SvVoteClearOptions {
1155    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvVoteClearOptions, Error> {
1156        let result = Ok(SvVoteClearOptions);
1157        _p.finish(wrap(warn));
1158        result
1159    }
1160    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1161        Ok(_p.written())
1162    }
1163}
1164impl fmt::Debug for SvVoteClearOptions {
1165    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1166        f.debug_struct("SvVoteClearOptions")
1167            .finish()
1168    }
1169}
1170
1171impl SvVoteOptionListAdd {
1172    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvVoteOptionListAdd, Error> {
1173        let result = Ok(SvVoteOptionListAdd);
1174        _p.finish(wrap(warn));
1175        result
1176    }
1177    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1178        Ok(_p.written())
1179    }
1180}
1181impl fmt::Debug for SvVoteOptionListAdd {
1182    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1183        f.debug_struct("SvVoteOptionListAdd")
1184            .finish()
1185    }
1186}
1187
1188impl<'a> SvVoteOptionAdd<'a> {
1189    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<SvVoteOptionAdd<'a>, Error> {
1190        let result = Ok(SvVoteOptionAdd {
1191            description: sanitize(warn, _p.read_string()?)?,
1192        });
1193        _p.finish(wrap(warn));
1194        result
1195    }
1196    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1197        sanitize(&mut Panic, self.description).unwrap();
1198        _p.write_string(self.description)?;
1199        Ok(_p.written())
1200    }
1201}
1202impl<'a> fmt::Debug for SvVoteOptionAdd<'a> {
1203    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1204        f.debug_struct("SvVoteOptionAdd")
1205            .field("description", &pretty::Bytes::new(&self.description))
1206            .finish()
1207    }
1208}
1209
1210impl<'a> SvVoteOptionRemove<'a> {
1211    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<SvVoteOptionRemove<'a>, Error> {
1212        let result = Ok(SvVoteOptionRemove {
1213            description: sanitize(warn, _p.read_string()?)?,
1214        });
1215        _p.finish(wrap(warn));
1216        result
1217    }
1218    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1219        sanitize(&mut Panic, self.description).unwrap();
1220        _p.write_string(self.description)?;
1221        Ok(_p.written())
1222    }
1223}
1224impl<'a> fmt::Debug for SvVoteOptionRemove<'a> {
1225    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1226        f.debug_struct("SvVoteOptionRemove")
1227            .field("description", &pretty::Bytes::new(&self.description))
1228            .finish()
1229    }
1230}
1231
1232impl<'a> SvVoteSet<'a> {
1233    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<SvVoteSet<'a>, Error> {
1234        let result = Ok(SvVoteSet {
1235            client_id: in_range(_p.read_int(warn)?, -1, 63)?,
1236            type_: enums::Vote::from_i32(_p.read_int(warn)?)?,
1237            timeout: in_range(_p.read_int(warn)?, 0, 60)?,
1238            description: sanitize(warn, _p.read_string()?)?,
1239            reason: sanitize(warn, _p.read_string()?)?,
1240        });
1241        _p.finish(wrap(warn));
1242        result
1243    }
1244    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1245        assert!(-1 <= self.client_id && self.client_id <= 63);
1246        assert!(0 <= self.timeout && self.timeout <= 60);
1247        sanitize(&mut Panic, self.description).unwrap();
1248        sanitize(&mut Panic, self.reason).unwrap();
1249        _p.write_int(self.client_id)?;
1250        _p.write_int(self.type_.to_i32())?;
1251        _p.write_int(self.timeout)?;
1252        _p.write_string(self.description)?;
1253        _p.write_string(self.reason)?;
1254        Ok(_p.written())
1255    }
1256}
1257impl<'a> fmt::Debug for SvVoteSet<'a> {
1258    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1259        f.debug_struct("SvVoteSet")
1260            .field("client_id", &self.client_id)
1261            .field("type_", &self.type_)
1262            .field("timeout", &self.timeout)
1263            .field("description", &pretty::Bytes::new(&self.description))
1264            .field("reason", &pretty::Bytes::new(&self.reason))
1265            .finish()
1266    }
1267}
1268
1269impl SvVoteStatus {
1270    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvVoteStatus, Error> {
1271        let result = Ok(SvVoteStatus {
1272            yes: in_range(_p.read_int(warn)?, 0, 64)?,
1273            no: in_range(_p.read_int(warn)?, 0, 64)?,
1274            pass: in_range(_p.read_int(warn)?, 0, 64)?,
1275            total: in_range(_p.read_int(warn)?, 0, 64)?,
1276        });
1277        _p.finish(wrap(warn));
1278        result
1279    }
1280    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1281        assert!(0 <= self.yes && self.yes <= 64);
1282        assert!(0 <= self.no && self.no <= 64);
1283        assert!(0 <= self.pass && self.pass <= 64);
1284        assert!(0 <= self.total && self.total <= 64);
1285        _p.write_int(self.yes)?;
1286        _p.write_int(self.no)?;
1287        _p.write_int(self.pass)?;
1288        _p.write_int(self.total)?;
1289        Ok(_p.written())
1290    }
1291}
1292impl fmt::Debug for SvVoteStatus {
1293    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1294        f.debug_struct("SvVoteStatus")
1295            .field("yes", &self.yes)
1296            .field("no", &self.no)
1297            .field("pass", &self.pass)
1298            .field("total", &self.total)
1299            .finish()
1300    }
1301}
1302
1303impl SvServerSettings {
1304    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvServerSettings, Error> {
1305        let result = Ok(SvServerSettings {
1306            kick_vote: to_bool(_p.read_int(warn)?)?,
1307            kick_min: in_range(_p.read_int(warn)?, 0, 64)?,
1308            spec_vote: to_bool(_p.read_int(warn)?)?,
1309            team_lock: to_bool(_p.read_int(warn)?)?,
1310            team_balance: to_bool(_p.read_int(warn)?)?,
1311            player_slots: in_range(_p.read_int(warn)?, 0, 64)?,
1312        });
1313        _p.finish(wrap(warn));
1314        result
1315    }
1316    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1317        assert!(0 <= self.kick_min && self.kick_min <= 64);
1318        assert!(0 <= self.player_slots && self.player_slots <= 64);
1319        _p.write_int(self.kick_vote as i32)?;
1320        _p.write_int(self.kick_min)?;
1321        _p.write_int(self.spec_vote as i32)?;
1322        _p.write_int(self.team_lock as i32)?;
1323        _p.write_int(self.team_balance as i32)?;
1324        _p.write_int(self.player_slots)?;
1325        Ok(_p.written())
1326    }
1327}
1328impl fmt::Debug for SvServerSettings {
1329    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1330        f.debug_struct("SvServerSettings")
1331            .field("kick_vote", &self.kick_vote)
1332            .field("kick_min", &self.kick_min)
1333            .field("spec_vote", &self.spec_vote)
1334            .field("team_lock", &self.team_lock)
1335            .field("team_balance", &self.team_balance)
1336            .field("player_slots", &self.player_slots)
1337            .finish()
1338    }
1339}
1340
1341impl<'a> SvClientInfo<'a> {
1342    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<SvClientInfo<'a>, Error> {
1343        let result = Ok(SvClientInfo {
1344            client_id: in_range(_p.read_int(warn)?, 0, 63)?,
1345            local: to_bool(_p.read_int(warn)?)?,
1346            team: enums::Team::from_i32(_p.read_int(warn)?)?,
1347            name: sanitize(warn, _p.read_string()?)?,
1348            clan: sanitize(warn, _p.read_string()?)?,
1349            country: _p.read_int(warn)?,
1350            skin_part_names: [
1351                sanitize(warn, _p.read_string()?)?,
1352                sanitize(warn, _p.read_string()?)?,
1353                sanitize(warn, _p.read_string()?)?,
1354                sanitize(warn, _p.read_string()?)?,
1355                sanitize(warn, _p.read_string()?)?,
1356                sanitize(warn, _p.read_string()?)?,
1357            ],
1358            use_custom_colors: [
1359                to_bool(_p.read_int(warn)?)?,
1360                to_bool(_p.read_int(warn)?)?,
1361                to_bool(_p.read_int(warn)?)?,
1362                to_bool(_p.read_int(warn)?)?,
1363                to_bool(_p.read_int(warn)?)?,
1364                to_bool(_p.read_int(warn)?)?,
1365            ],
1366            skin_part_colors: [
1367                _p.read_int(warn)?,
1368                _p.read_int(warn)?,
1369                _p.read_int(warn)?,
1370                _p.read_int(warn)?,
1371                _p.read_int(warn)?,
1372                _p.read_int(warn)?,
1373            ],
1374            silent: to_bool(_p.read_int(warn)?)?,
1375        });
1376        _p.finish(wrap(warn));
1377        result
1378    }
1379    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1380        assert!(0 <= self.client_id && self.client_id <= 63);
1381        sanitize(&mut Panic, self.name).unwrap();
1382        sanitize(&mut Panic, self.clan).unwrap();
1383        for &e in &self.skin_part_names {
1384            sanitize(&mut Panic, e).unwrap();
1385        }
1386        _p.write_int(self.client_id)?;
1387        _p.write_int(self.local as i32)?;
1388        _p.write_int(self.team.to_i32())?;
1389        _p.write_string(self.name)?;
1390        _p.write_string(self.clan)?;
1391        _p.write_int(self.country)?;
1392        for &e in &self.skin_part_names {
1393            _p.write_string(e)?;
1394        }
1395        for &e in &self.use_custom_colors {
1396            _p.write_int(e as i32)?;
1397        }
1398        for &e in &self.skin_part_colors {
1399            _p.write_int(e)?;
1400        }
1401        _p.write_int(self.silent as i32)?;
1402        Ok(_p.written())
1403    }
1404}
1405impl<'a> fmt::Debug for SvClientInfo<'a> {
1406    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1407        f.debug_struct("SvClientInfo")
1408            .field("client_id", &self.client_id)
1409            .field("local", &self.local)
1410            .field("team", &self.team)
1411            .field("name", &pretty::Bytes::new(&self.name))
1412            .field("clan", &pretty::Bytes::new(&self.clan))
1413            .field("country", &self.country)
1414            .field("skin_part_names", &DebugSlice::new(&self.skin_part_names, |e| pretty::Bytes::new(&e)))
1415            .field("use_custom_colors", &self.use_custom_colors)
1416            .field("skin_part_colors", &self.skin_part_colors)
1417            .field("silent", &self.silent)
1418            .finish()
1419    }
1420}
1421
1422impl SvGameInfo {
1423    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvGameInfo, Error> {
1424        let result = Ok(SvGameInfo {
1425            game_flags: _p.read_int(warn)?,
1426            score_limit: positive(_p.read_int(warn)?)?,
1427            time_limit: positive(_p.read_int(warn)?)?,
1428            match_num: positive(_p.read_int(warn)?)?,
1429            match_current: positive(_p.read_int(warn)?)?,
1430        });
1431        _p.finish(wrap(warn));
1432        result
1433    }
1434    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1435        assert!(self.score_limit >= 0);
1436        assert!(self.time_limit >= 0);
1437        assert!(self.match_num >= 0);
1438        assert!(self.match_current >= 0);
1439        _p.write_int(self.game_flags)?;
1440        _p.write_int(self.score_limit)?;
1441        _p.write_int(self.time_limit)?;
1442        _p.write_int(self.match_num)?;
1443        _p.write_int(self.match_current)?;
1444        Ok(_p.written())
1445    }
1446}
1447impl fmt::Debug for SvGameInfo {
1448    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1449        f.debug_struct("SvGameInfo")
1450            .field("game_flags", &self.game_flags)
1451            .field("score_limit", &self.score_limit)
1452            .field("time_limit", &self.time_limit)
1453            .field("match_num", &self.match_num)
1454            .field("match_current", &self.match_current)
1455            .finish()
1456    }
1457}
1458
1459impl<'a> SvClientDrop<'a> {
1460    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<SvClientDrop<'a>, Error> {
1461        let result = Ok(SvClientDrop {
1462            client_id: in_range(_p.read_int(warn)?, 0, 63)?,
1463            reason: sanitize(warn, _p.read_string()?)?,
1464            silent: to_bool(_p.read_int(warn)?)?,
1465        });
1466        _p.finish(wrap(warn));
1467        result
1468    }
1469    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1470        assert!(0 <= self.client_id && self.client_id <= 63);
1471        sanitize(&mut Panic, self.reason).unwrap();
1472        _p.write_int(self.client_id)?;
1473        _p.write_string(self.reason)?;
1474        _p.write_int(self.silent as i32)?;
1475        Ok(_p.written())
1476    }
1477}
1478impl<'a> fmt::Debug for SvClientDrop<'a> {
1479    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1480        f.debug_struct("SvClientDrop")
1481            .field("client_id", &self.client_id)
1482            .field("reason", &pretty::Bytes::new(&self.reason))
1483            .field("silent", &self.silent)
1484            .finish()
1485    }
1486}
1487
1488impl SvGameMsg {
1489    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvGameMsg, Error> {
1490        let result = Ok(SvGameMsg);
1491        _p.finish(wrap(warn));
1492        result
1493    }
1494    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1495        Ok(_p.written())
1496    }
1497}
1498impl fmt::Debug for SvGameMsg {
1499    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1500        f.debug_struct("SvGameMsg")
1501            .finish()
1502    }
1503}
1504
1505impl<'a> DeClientEnter<'a> {
1506    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<DeClientEnter<'a>, Error> {
1507        let result = Ok(DeClientEnter {
1508            name: sanitize(warn, _p.read_string()?)?,
1509            client_id: in_range(_p.read_int(warn)?, -1, 63)?,
1510            team: enums::Team::from_i32(_p.read_int(warn)?)?,
1511        });
1512        _p.finish(wrap(warn));
1513        result
1514    }
1515    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1516        sanitize(&mut Panic, self.name).unwrap();
1517        assert!(-1 <= self.client_id && self.client_id <= 63);
1518        _p.write_string(self.name)?;
1519        _p.write_int(self.client_id)?;
1520        _p.write_int(self.team.to_i32())?;
1521        Ok(_p.written())
1522    }
1523}
1524impl<'a> fmt::Debug for DeClientEnter<'a> {
1525    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1526        f.debug_struct("DeClientEnter")
1527            .field("name", &pretty::Bytes::new(&self.name))
1528            .field("client_id", &self.client_id)
1529            .field("team", &self.team)
1530            .finish()
1531    }
1532}
1533
1534impl<'a> DeClientLeave<'a> {
1535    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<DeClientLeave<'a>, Error> {
1536        let result = Ok(DeClientLeave {
1537            name: sanitize(warn, _p.read_string()?)?,
1538            client_id: in_range(_p.read_int(warn)?, -1, 63)?,
1539            reason: sanitize(warn, _p.read_string()?)?,
1540        });
1541        _p.finish(wrap(warn));
1542        result
1543    }
1544    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1545        sanitize(&mut Panic, self.name).unwrap();
1546        assert!(-1 <= self.client_id && self.client_id <= 63);
1547        sanitize(&mut Panic, self.reason).unwrap();
1548        _p.write_string(self.name)?;
1549        _p.write_int(self.client_id)?;
1550        _p.write_string(self.reason)?;
1551        Ok(_p.written())
1552    }
1553}
1554impl<'a> fmt::Debug for DeClientLeave<'a> {
1555    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1556        f.debug_struct("DeClientLeave")
1557            .field("name", &pretty::Bytes::new(&self.name))
1558            .field("client_id", &self.client_id)
1559            .field("reason", &pretty::Bytes::new(&self.reason))
1560            .finish()
1561    }
1562}
1563
1564impl<'a> ClSay<'a> {
1565    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<ClSay<'a>, Error> {
1566        let result = Ok(ClSay {
1567            mode: enums::Chat::from_i32(_p.read_int(warn)?)?,
1568            target: in_range(_p.read_int(warn)?, -1, 63)?,
1569            message: sanitize(warn, _p.read_string()?)?,
1570        });
1571        _p.finish(wrap(warn));
1572        result
1573    }
1574    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1575        assert!(-1 <= self.target && self.target <= 63);
1576        sanitize(&mut Panic, self.message).unwrap();
1577        _p.write_int(self.mode.to_i32())?;
1578        _p.write_int(self.target)?;
1579        _p.write_string(self.message)?;
1580        Ok(_p.written())
1581    }
1582}
1583impl<'a> fmt::Debug for ClSay<'a> {
1584    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1585        f.debug_struct("ClSay")
1586            .field("mode", &self.mode)
1587            .field("target", &self.target)
1588            .field("message", &pretty::Bytes::new(&self.message))
1589            .finish()
1590    }
1591}
1592
1593impl ClSetTeam {
1594    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<ClSetTeam, Error> {
1595        let result = Ok(ClSetTeam {
1596            team: enums::Team::from_i32(_p.read_int(warn)?)?,
1597        });
1598        _p.finish(wrap(warn));
1599        result
1600    }
1601    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1602        _p.write_int(self.team.to_i32())?;
1603        Ok(_p.written())
1604    }
1605}
1606impl fmt::Debug for ClSetTeam {
1607    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1608        f.debug_struct("ClSetTeam")
1609            .field("team", &self.team)
1610            .finish()
1611    }
1612}
1613
1614impl ClSetSpectatorMode {
1615    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<ClSetSpectatorMode, Error> {
1616        let result = Ok(ClSetSpectatorMode {
1617            spec_mode: enums::Spec::from_i32(_p.read_int(warn)?)?,
1618            spectator_id: in_range(_p.read_int(warn)?, -1, 63)?,
1619        });
1620        _p.finish(wrap(warn));
1621        result
1622    }
1623    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1624        assert!(-1 <= self.spectator_id && self.spectator_id <= 63);
1625        _p.write_int(self.spec_mode.to_i32())?;
1626        _p.write_int(self.spectator_id)?;
1627        Ok(_p.written())
1628    }
1629}
1630impl fmt::Debug for ClSetSpectatorMode {
1631    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1632        f.debug_struct("ClSetSpectatorMode")
1633            .field("spec_mode", &self.spec_mode)
1634            .field("spectator_id", &self.spectator_id)
1635            .finish()
1636    }
1637}
1638
1639impl<'a> ClStartInfo<'a> {
1640    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<ClStartInfo<'a>, Error> {
1641        let result = Ok(ClStartInfo {
1642            name: sanitize(warn, _p.read_string()?)?,
1643            clan: sanitize(warn, _p.read_string()?)?,
1644            country: _p.read_int(warn)?,
1645            skin_part_names: [
1646                sanitize(warn, _p.read_string()?)?,
1647                sanitize(warn, _p.read_string()?)?,
1648                sanitize(warn, _p.read_string()?)?,
1649                sanitize(warn, _p.read_string()?)?,
1650                sanitize(warn, _p.read_string()?)?,
1651                sanitize(warn, _p.read_string()?)?,
1652            ],
1653            use_custom_colors: [
1654                to_bool(_p.read_int(warn)?)?,
1655                to_bool(_p.read_int(warn)?)?,
1656                to_bool(_p.read_int(warn)?)?,
1657                to_bool(_p.read_int(warn)?)?,
1658                to_bool(_p.read_int(warn)?)?,
1659                to_bool(_p.read_int(warn)?)?,
1660            ],
1661            skin_part_colors: [
1662                _p.read_int(warn)?,
1663                _p.read_int(warn)?,
1664                _p.read_int(warn)?,
1665                _p.read_int(warn)?,
1666                _p.read_int(warn)?,
1667                _p.read_int(warn)?,
1668            ],
1669        });
1670        _p.finish(wrap(warn));
1671        result
1672    }
1673    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1674        sanitize(&mut Panic, self.name).unwrap();
1675        sanitize(&mut Panic, self.clan).unwrap();
1676        for &e in &self.skin_part_names {
1677            sanitize(&mut Panic, e).unwrap();
1678        }
1679        _p.write_string(self.name)?;
1680        _p.write_string(self.clan)?;
1681        _p.write_int(self.country)?;
1682        for &e in &self.skin_part_names {
1683            _p.write_string(e)?;
1684        }
1685        for &e in &self.use_custom_colors {
1686            _p.write_int(e as i32)?;
1687        }
1688        for &e in &self.skin_part_colors {
1689            _p.write_int(e)?;
1690        }
1691        Ok(_p.written())
1692    }
1693}
1694impl<'a> fmt::Debug for ClStartInfo<'a> {
1695    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1696        f.debug_struct("ClStartInfo")
1697            .field("name", &pretty::Bytes::new(&self.name))
1698            .field("clan", &pretty::Bytes::new(&self.clan))
1699            .field("country", &self.country)
1700            .field("skin_part_names", &DebugSlice::new(&self.skin_part_names, |e| pretty::Bytes::new(&e)))
1701            .field("use_custom_colors", &self.use_custom_colors)
1702            .field("skin_part_colors", &self.skin_part_colors)
1703            .finish()
1704    }
1705}
1706
1707impl ClKill {
1708    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<ClKill, Error> {
1709        let result = Ok(ClKill);
1710        _p.finish(wrap(warn));
1711        result
1712    }
1713    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1714        Ok(_p.written())
1715    }
1716}
1717impl fmt::Debug for ClKill {
1718    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1719        f.debug_struct("ClKill")
1720            .finish()
1721    }
1722}
1723
1724impl ClReadyChange {
1725    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<ClReadyChange, Error> {
1726        let result = Ok(ClReadyChange);
1727        _p.finish(wrap(warn));
1728        result
1729    }
1730    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1731        Ok(_p.written())
1732    }
1733}
1734impl fmt::Debug for ClReadyChange {
1735    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1736        f.debug_struct("ClReadyChange")
1737            .finish()
1738    }
1739}
1740
1741impl ClEmoticon {
1742    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<ClEmoticon, Error> {
1743        let result = Ok(ClEmoticon {
1744            emoticon: enums::Emoticon::from_i32(_p.read_int(warn)?)?,
1745        });
1746        _p.finish(wrap(warn));
1747        result
1748    }
1749    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1750        _p.write_int(self.emoticon.to_i32())?;
1751        Ok(_p.written())
1752    }
1753}
1754impl fmt::Debug for ClEmoticon {
1755    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1756        f.debug_struct("ClEmoticon")
1757            .field("emoticon", &self.emoticon)
1758            .finish()
1759    }
1760}
1761
1762impl ClVote {
1763    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<ClVote, Error> {
1764        let result = Ok(ClVote {
1765            vote: in_range(_p.read_int(warn)?, -1, 1)?,
1766        });
1767        _p.finish(wrap(warn));
1768        result
1769    }
1770    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1771        assert!(-1 <= self.vote && self.vote <= 1);
1772        _p.write_int(self.vote)?;
1773        Ok(_p.written())
1774    }
1775}
1776impl fmt::Debug for ClVote {
1777    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1778        f.debug_struct("ClVote")
1779            .field("vote", &self.vote)
1780            .finish()
1781    }
1782}
1783
1784impl<'a> ClCallVote<'a> {
1785    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<ClCallVote<'a>, Error> {
1786        let result = Ok(ClCallVote {
1787            type_: sanitize(warn, _p.read_string()?)?,
1788            value: sanitize(warn, _p.read_string()?)?,
1789            reason: sanitize(warn, _p.read_string()?)?,
1790            force: to_bool(_p.read_int(warn)?)?,
1791        });
1792        _p.finish(wrap(warn));
1793        result
1794    }
1795    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1796        sanitize(&mut Panic, self.type_).unwrap();
1797        sanitize(&mut Panic, self.value).unwrap();
1798        sanitize(&mut Panic, self.reason).unwrap();
1799        _p.write_string(self.type_)?;
1800        _p.write_string(self.value)?;
1801        _p.write_string(self.reason)?;
1802        _p.write_int(self.force as i32)?;
1803        Ok(_p.written())
1804    }
1805}
1806impl<'a> fmt::Debug for ClCallVote<'a> {
1807    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1808        f.debug_struct("ClCallVote")
1809            .field("type_", &pretty::Bytes::new(&self.type_))
1810            .field("value", &pretty::Bytes::new(&self.value))
1811            .field("reason", &pretty::Bytes::new(&self.reason))
1812            .field("force", &self.force)
1813            .finish()
1814    }
1815}
1816
1817impl<'a> SvSkinChange<'a> {
1818    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<SvSkinChange<'a>, Error> {
1819        let result = Ok(SvSkinChange {
1820            client_id: in_range(_p.read_int(warn)?, 0, 63)?,
1821            skin_part_names: [
1822                sanitize(warn, _p.read_string()?)?,
1823                sanitize(warn, _p.read_string()?)?,
1824                sanitize(warn, _p.read_string()?)?,
1825                sanitize(warn, _p.read_string()?)?,
1826                sanitize(warn, _p.read_string()?)?,
1827                sanitize(warn, _p.read_string()?)?,
1828            ],
1829            use_custom_colors: [
1830                to_bool(_p.read_int(warn)?)?,
1831                to_bool(_p.read_int(warn)?)?,
1832                to_bool(_p.read_int(warn)?)?,
1833                to_bool(_p.read_int(warn)?)?,
1834                to_bool(_p.read_int(warn)?)?,
1835                to_bool(_p.read_int(warn)?)?,
1836            ],
1837            skin_part_colors: [
1838                _p.read_int(warn)?,
1839                _p.read_int(warn)?,
1840                _p.read_int(warn)?,
1841                _p.read_int(warn)?,
1842                _p.read_int(warn)?,
1843                _p.read_int(warn)?,
1844            ],
1845        });
1846        _p.finish(wrap(warn));
1847        result
1848    }
1849    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1850        assert!(0 <= self.client_id && self.client_id <= 63);
1851        for &e in &self.skin_part_names {
1852            sanitize(&mut Panic, e).unwrap();
1853        }
1854        _p.write_int(self.client_id)?;
1855        for &e in &self.skin_part_names {
1856            _p.write_string(e)?;
1857        }
1858        for &e in &self.use_custom_colors {
1859            _p.write_int(e as i32)?;
1860        }
1861        for &e in &self.skin_part_colors {
1862            _p.write_int(e)?;
1863        }
1864        Ok(_p.written())
1865    }
1866}
1867impl<'a> fmt::Debug for SvSkinChange<'a> {
1868    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1869        f.debug_struct("SvSkinChange")
1870            .field("client_id", &self.client_id)
1871            .field("skin_part_names", &DebugSlice::new(&self.skin_part_names, |e| pretty::Bytes::new(&e)))
1872            .field("use_custom_colors", &self.use_custom_colors)
1873            .field("skin_part_colors", &self.skin_part_colors)
1874            .finish()
1875    }
1876}
1877
1878impl<'a> ClSkinChange<'a> {
1879    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<ClSkinChange<'a>, Error> {
1880        let result = Ok(ClSkinChange {
1881            skin_part_names: [
1882                sanitize(warn, _p.read_string()?)?,
1883                sanitize(warn, _p.read_string()?)?,
1884                sanitize(warn, _p.read_string()?)?,
1885                sanitize(warn, _p.read_string()?)?,
1886                sanitize(warn, _p.read_string()?)?,
1887                sanitize(warn, _p.read_string()?)?,
1888            ],
1889            use_custom_colors: [
1890                to_bool(_p.read_int(warn)?)?,
1891                to_bool(_p.read_int(warn)?)?,
1892                to_bool(_p.read_int(warn)?)?,
1893                to_bool(_p.read_int(warn)?)?,
1894                to_bool(_p.read_int(warn)?)?,
1895                to_bool(_p.read_int(warn)?)?,
1896            ],
1897            skin_part_colors: [
1898                _p.read_int(warn)?,
1899                _p.read_int(warn)?,
1900                _p.read_int(warn)?,
1901                _p.read_int(warn)?,
1902                _p.read_int(warn)?,
1903                _p.read_int(warn)?,
1904            ],
1905        });
1906        _p.finish(wrap(warn));
1907        result
1908    }
1909    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1910        for &e in &self.skin_part_names {
1911            sanitize(&mut Panic, e).unwrap();
1912        }
1913        for &e in &self.skin_part_names {
1914            _p.write_string(e)?;
1915        }
1916        for &e in &self.use_custom_colors {
1917            _p.write_int(e as i32)?;
1918        }
1919        for &e in &self.skin_part_colors {
1920            _p.write_int(e)?;
1921        }
1922        Ok(_p.written())
1923    }
1924}
1925impl<'a> fmt::Debug for ClSkinChange<'a> {
1926    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1927        f.debug_struct("ClSkinChange")
1928            .field("skin_part_names", &DebugSlice::new(&self.skin_part_names, |e| pretty::Bytes::new(&e)))
1929            .field("use_custom_colors", &self.use_custom_colors)
1930            .field("skin_part_colors", &self.skin_part_colors)
1931            .finish()
1932    }
1933}
1934
1935impl SvRaceFinish {
1936    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvRaceFinish, Error> {
1937        let result = Ok(SvRaceFinish {
1938            client_id: in_range(_p.read_int(warn)?, 0, 63)?,
1939            time: at_least(_p.read_int(warn)?, -1)?,
1940            diff: _p.read_int(warn)?,
1941            record_personal: to_bool(_p.read_int(warn)?)?,
1942            record_server: to_bool(_p.read_int(warn)?)?,
1943        });
1944        _p.finish(wrap(warn));
1945        result
1946    }
1947    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1948        assert!(0 <= self.client_id && self.client_id <= 63);
1949        assert!(self.time >= -1);
1950        _p.write_int(self.client_id)?;
1951        _p.write_int(self.time)?;
1952        _p.write_int(self.diff)?;
1953        _p.write_int(self.record_personal as i32)?;
1954        _p.write_int(self.record_server as i32)?;
1955        Ok(_p.written())
1956    }
1957}
1958impl fmt::Debug for SvRaceFinish {
1959    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1960        f.debug_struct("SvRaceFinish")
1961            .field("client_id", &self.client_id)
1962            .field("time", &self.time)
1963            .field("diff", &self.diff)
1964            .field("record_personal", &self.record_personal)
1965            .field("record_server", &self.record_server)
1966            .finish()
1967    }
1968}
1969
1970impl SvCheckpoint {
1971    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvCheckpoint, Error> {
1972        let result = Ok(SvCheckpoint {
1973            diff: _p.read_int(warn)?,
1974        });
1975        _p.finish(wrap(warn));
1976        result
1977    }
1978    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
1979        _p.write_int(self.diff)?;
1980        Ok(_p.written())
1981    }
1982}
1983impl fmt::Debug for SvCheckpoint {
1984    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1985        f.debug_struct("SvCheckpoint")
1986            .field("diff", &self.diff)
1987            .finish()
1988    }
1989}
1990
1991impl<'a> SvCommandInfo<'a> {
1992    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<SvCommandInfo<'a>, Error> {
1993        let result = Ok(SvCommandInfo {
1994            name: sanitize(warn, _p.read_string()?)?,
1995            args_format: sanitize(warn, _p.read_string()?)?,
1996            help_text: sanitize(warn, _p.read_string()?)?,
1997        });
1998        _p.finish(wrap(warn));
1999        result
2000    }
2001    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
2002        sanitize(&mut Panic, self.name).unwrap();
2003        sanitize(&mut Panic, self.args_format).unwrap();
2004        sanitize(&mut Panic, self.help_text).unwrap();
2005        _p.write_string(self.name)?;
2006        _p.write_string(self.args_format)?;
2007        _p.write_string(self.help_text)?;
2008        Ok(_p.written())
2009    }
2010}
2011impl<'a> fmt::Debug for SvCommandInfo<'a> {
2012    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2013        f.debug_struct("SvCommandInfo")
2014            .field("name", &pretty::Bytes::new(&self.name))
2015            .field("args_format", &pretty::Bytes::new(&self.args_format))
2016            .field("help_text", &pretty::Bytes::new(&self.help_text))
2017            .finish()
2018    }
2019}
2020
2021impl<'a> SvCommandInfoRemove<'a> {
2022    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<SvCommandInfoRemove<'a>, Error> {
2023        let result = Ok(SvCommandInfoRemove {
2024            name: sanitize(warn, _p.read_string()?)?,
2025        });
2026        _p.finish(wrap(warn));
2027        result
2028    }
2029    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
2030        sanitize(&mut Panic, self.name).unwrap();
2031        _p.write_string(self.name)?;
2032        Ok(_p.written())
2033    }
2034}
2035impl<'a> fmt::Debug for SvCommandInfoRemove<'a> {
2036    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2037        f.debug_struct("SvCommandInfoRemove")
2038            .field("name", &pretty::Bytes::new(&self.name))
2039            .finish()
2040    }
2041}
2042
2043impl<'a> ClCommand<'a> {
2044    pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker<'a>) -> Result<ClCommand<'a>, Error> {
2045        let result = Ok(ClCommand {
2046            name: sanitize(warn, _p.read_string()?)?,
2047            arguments: sanitize(warn, _p.read_string()?)?,
2048        });
2049        _p.finish(wrap(warn));
2050        result
2051    }
2052    pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
2053        sanitize(&mut Panic, self.name).unwrap();
2054        sanitize(&mut Panic, self.arguments).unwrap();
2055        _p.write_string(self.name)?;
2056        _p.write_string(self.arguments)?;
2057        Ok(_p.written())
2058    }
2059}
2060impl<'a> fmt::Debug for ClCommand<'a> {
2061    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2062        f.debug_struct("ClCommand")
2063            .field("name", &pretty::Bytes::new(&self.name))
2064            .field("arguments", &pretty::Bytes::new(&self.arguments))
2065            .finish()
2066    }
2067}
2068