author | unC0Rr |
Fri, 16 Nov 2018 16:32:51 +0100 | |
changeset 14214 | 77b95406631e |
parent 14211 | 0f7b92397b9e |
child 14254 | 9f4d75fa4a2c |
permissions | -rw-r--r-- |
14209 | 1 |
#[derive(Debug, PartialEq)] |
2 |
pub enum KeystrokeAction { |
|
3 |
Press, |
|
4 |
Release, |
|
5 |
} |
|
6 |
||
7 |
#[derive(Debug, PartialEq)] |
|
8 |
pub enum SyncedEngineMessage { |
|
9 |
Left(KeystrokeAction), |
|
10 |
Right(KeystrokeAction), |
|
11 |
Up(KeystrokeAction), |
|
12 |
Down(KeystrokeAction), |
|
13 |
Precise(KeystrokeAction), |
|
14 |
Attack(KeystrokeAction), |
|
15 |
NextTurn, |
|
16 |
Switch, |
|
17 |
Timer(u8), |
|
18 |
Slot(u8), |
|
19 |
SetWeapon(u8), |
|
20 |
Put(i32, i32), |
|
14211 | 21 |
CursorMove(i32, i32), |
14209 | 22 |
HighJump, |
14211 | 23 |
LongJump, |
14209 | 24 |
Skip, |
25 |
TeamControlGained(String), |
|
26 |
TeamControlLost(String), |
|
14210 | 27 |
TimeWrap, |
14214
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
28 |
Taunt(u8), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
29 |
HogSay(String), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
30 |
Heartbeat, |
14209 | 31 |
} |
32 |
||
33 |
#[derive(Debug, PartialEq)] |
|
34 |
pub enum UnsyncedEngineMessage { |
|
14214
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
35 |
TeamControlGained(String), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
36 |
TeamControlLost(String), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
37 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
38 |
|
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
39 |
#[derive(Debug, PartialEq)] |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
40 |
pub enum UnorderedEngineMessage { |
14209 | 41 |
Ping, |
42 |
Pong, |
|
14214
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
43 |
ChatMessage(String), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
44 |
TeamMessage(String), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
45 |
Error(String), |
14209 | 46 |
Warning(String), |
47 |
StopSyncing, |
|
48 |
GameOver, |
|
49 |
GameInterrupted, |
|
50 |
GameSetupChecksum(String), |
|
14214
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
51 |
PauseToggled, |
14209 | 52 |
} |
53 |
#[derive(Debug, PartialEq)] |
|
54 |
pub enum ConfigEngineMessage { |
|
14214
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
55 |
GameType(u8), |
14209 | 56 |
ConfigRequest, |
57 |
SetAmmo(String), |
|
58 |
SetScript(String), |
|
59 |
SetScriptParam(String), |
|
60 |
Spectate, |
|
61 |
TeamLocality(bool), |
|
62 |
SetMap(String), |
|
63 |
SetTheme(String), |
|
64 |
SetSeed(String), |
|
65 |
SetTemplateFilter(String), |
|
66 |
SetMapGenerator(String), |
|
67 |
SetFeatureSize(u8), |
|
68 |
SetDelay(u32), |
|
69 |
SetReadyDelay(u32), |
|
70 |
SetCratesFrequency(u8), |
|
71 |
SetHealthCrateProbability(u8), |
|
72 |
SetHealthCratesNumber(u8), |
|
73 |
SetRoundsTilSuddenDeath(u8), |
|
74 |
SetSuddenDeathWaterRiseSpeed(u8), |
|
75 |
SetSuddenDeathHealthDecreaseRate(u8), |
|
76 |
SetDamageMultiplier(u32), |
|
77 |
SetRopeLength(u32), |
|
78 |
SetGetawayTime(u32), |
|
79 |
SetDudMinesPercent(u8), |
|
80 |
SetMinesNumber(u32), |
|
81 |
SetAirMinesNumber(u32), |
|
82 |
SetBarrelsNumber(u32), |
|
83 |
SetTurnTime(u32), |
|
84 |
SetMinesTime(u32), |
|
85 |
SetWorldEdge(u8), |
|
86 |
Draw, |
|
87 |
// TODO |
|
88 |
SetVoicePack(String), |
|
89 |
AddHedgehog(String, u8, u32), |
|
90 |
AddTeam(String, u8), |
|
91 |
SetHedgehogCoordinates(i32, i32), |
|
92 |
SetFort(String), |
|
93 |
SetGrave(String), |
|
94 |
SetHat(String), |
|
95 |
SetFlag(String), |
|
96 |
SetOwner(String), |
|
97 |
SetOneClanMode(bool), |
|
98 |
SetMultishootMode(bool), |
|
99 |
SetSolidLand(bool), |
|
100 |
SetBorders(bool), |
|
101 |
SetDivideTeams(bool), |
|
102 |
SetLowGravity(bool), |
|
103 |
SetLaserSight(bool), |
|
104 |
SetInvulnerability(bool), |
|
105 |
SetHealthReset(bool), |
|
106 |
SetVampiric(bool), |
|
107 |
SetKarma(bool), |
|
108 |
SetArtilleryMode(bool), |
|
109 |
SetHedgehogSwitch(bool), |
|
110 |
SetRandomOrder(bool), |
|
111 |
SetKingMode(bool), |
|
112 |
SetPlaceHedgehog(bool), |
|
113 |
SetSharedAmmo(bool), |
|
114 |
SetGirdersEnabled(bool), |
|
115 |
SetLandObjectsEnabled(bool), |
|
116 |
SetAISurvivalMode(bool), |
|
117 |
SetInfiniteAttack(bool), |
|
118 |
SetResetWeapons(bool), |
|
119 |
SetAmmoPerHedgehog(bool), |
|
120 |
SetWindMode(u8), |
|
121 |
SetTagTeam(bool), |
|
122 |
SetBottomBorder(bool), |
|
123 |
SetShoppaBorder(bool), |
|
124 |
} |
|
125 |
||
126 |
#[derive(Debug, PartialEq)] |
|
127 |
pub enum EngineMessage { |
|
128 |
Unknown, |
|
129 |
Empty, |
|
14214
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
130 |
Synced(SyncedEngineMessage, u32), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
131 |
Unsynced(UnsyncedEngineMessage), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
132 |
Unordered(UnorderedEngineMessage), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
133 |
Config(ConfigEngineMessage), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
134 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
135 |
|
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
136 |
macro_rules! em { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
137 |
[$msg: expr] => { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
138 |
vec![($msg) as u8] |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
139 |
}; |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
140 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
141 |
|
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
142 |
macro_rules! ems { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
143 |
[$msg: expr, $param: expr] => { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
144 |
{ |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
145 |
let mut v = vec![($msg) as u8]; |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
146 |
v.extend(String::into_bytes($param.to_string()).iter()); |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
147 |
v |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
148 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
149 |
}; |
14209 | 150 |
} |
151 |
||
14214
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
152 |
impl SyncedEngineMessage { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
153 |
fn to_bytes(&self) -> Vec<u8> { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
154 |
use self::KeystrokeAction::*; |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
155 |
use self::SyncedEngineMessage::*; |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
156 |
match self { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
157 |
Left(Press) => em!['L'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
158 |
Left(Release) => em!['l'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
159 |
Right(Press) => em!['R'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
160 |
Right(Release) => em!['r'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
161 |
Up(Press) => em!['U'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
162 |
Up(Release) => em!['u'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
163 |
Down(Press) => em!['D'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
164 |
Down(Release) => em!['d'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
165 |
Precise(Press) => em!['Z'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
166 |
Precise(Release) => em!['z'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
167 |
Attack(Press) => em!['A'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
168 |
Attack(Release) => em!['a'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
169 |
NextTurn => em!['N'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
170 |
Switch => em!['S'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
171 |
Timer(t) => vec!['0' as u8 + t], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
172 |
Slot(s) => vec!['~' as u8, *s], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
173 |
SetWeapon(s) => vec!['~' as u8, *s], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
174 |
Put(x, y) => unimplemented!(), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
175 |
CursorMove(x, y) => unimplemented!(), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
176 |
HighJump => em!['J'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
177 |
LongJump => em!['j'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
178 |
Skip => em![','], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
179 |
TeamControlGained(str) => ems!['g', str], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
180 |
TeamControlLost(str) => ems!['f', str], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
181 |
Taunt(s) => vec!['t' as u8, *s], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
182 |
HogSay(str) => ems!['h', str], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
183 |
Heartbeat => em!['+'], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
184 |
TimeWrap => unreachable!(), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
185 |
} |
14209 | 186 |
} |
14214
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
187 |
} |
14209 | 188 |
|
14214
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
189 |
impl UnsyncedEngineMessage { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
190 |
fn to_bytes(&self) -> Vec<u8> { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
191 |
use self::UnsyncedEngineMessage::*; |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
192 |
match self { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
193 |
TeamControlGained(str) => ems!['G', str], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
194 |
TeamControlLost(str) => ems!['F', str], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
195 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
196 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
197 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
198 |
|
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
199 |
impl UnorderedEngineMessage { |
14209 | 200 |
fn to_bytes(&self) -> Vec<u8> { |
201 |
unimplemented!() |
|
202 |
} |
|
203 |
} |
|
14214
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
204 |
|
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
205 |
impl ConfigEngineMessage { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
206 |
fn to_bytes(&self) -> Vec<u8> { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
207 |
unimplemented!() |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
208 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
209 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
210 |
|
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
211 |
impl EngineMessage { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
212 |
pub const MAX_LEN: u16 = 49215; |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
213 |
|
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
214 |
fn to_unwrapped(&self) -> Vec<u8> { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
215 |
use self::EngineMessage::*; |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
216 |
match self { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
217 |
Unknown => unreachable!("you're not supposed to construct such messages"), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
218 |
Empty => unreachable!("you're not supposed to construct such messages"), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
219 |
Synced(SyncedEngineMessage::TimeWrap, _) => vec!['#' as u8, 0xff, 0xff], |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
220 |
Synced(msg, timestamp) => { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
221 |
let mut v = msg.to_bytes(); |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
222 |
v.push((*timestamp / 256) as u8); |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
223 |
v.push(*timestamp as u8); |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
224 |
|
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
225 |
v |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
226 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
227 |
Unsynced(msg) => msg.to_bytes(), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
228 |
Unordered(msg) => msg.to_bytes(), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
229 |
Config(msg) => msg.to_bytes(), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
230 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
231 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
232 |
|
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
233 |
pub fn to_bytes(&self) -> Vec<u8> { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
234 |
let mut unwrapped = self.to_unwrapped(); |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
235 |
let mut size = unwrapped.len(); |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
236 |
|
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
237 |
if size > EngineMessage::MAX_LEN as usize - 2 { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
238 |
size = EngineMessage::MAX_LEN as usize - 2; |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
239 |
unwrapped.truncate(size); |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
240 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
241 |
|
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
242 |
if size < 64 { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
243 |
unwrapped.insert(0, size as u8); |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
244 |
} else { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
245 |
size -= 64; |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
246 |
unwrapped.insert(0, (size / 256 + 64) as u8); |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
247 |
unwrapped.insert(1, size as u8); |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
248 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
249 |
|
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
250 |
unwrapped |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
251 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
252 |
} |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
253 |
|
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
254 |
#[test] |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
255 |
fn message_contruction() { |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
256 |
assert_eq!( |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
257 |
EngineMessage::Synced(SyncedEngineMessage::TimeWrap, 0).to_bytes(), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
258 |
vec![3, '#' as u8, 255, 255] |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
259 |
); |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
260 |
assert_eq!( |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
261 |
EngineMessage::Synced(SyncedEngineMessage::NextTurn, 258).to_bytes(), |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
262 |
vec![3, 'N' as u8, 1, 2] |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
263 |
); |
77b95406631e
Implement more of parsing, start implementation of engine messages rendering
unC0Rr
parents:
14211
diff
changeset
|
264 |
} |