1#include "protocol.h"
2
3#include <base/system.h>
4#include <engine/shared/packer.h>
5#include <engine/shared/protocol.h>
6#include <engine/shared/uuid_manager.h>
7
8#include <game/mapitems_ex.h>
9
10CNetObjHandler::CNetObjHandler()
11{
12 m_pMsgFailedOn = "";
13 m_pObjFailedOn = "";
14 m_pObjCorrectedOn = "";
15 m_NumObjCorrections = 0;
16}
17
18int CNetObjHandler::NumObjCorrections() const { return m_NumObjCorrections; }
19const char *CNetObjHandler::CorrectedObjOn() const { return m_pObjCorrectedOn; }
20const char *CNetObjHandler::FailedObjOn() const { return m_pObjFailedOn; }
21const char *CNetObjHandler::FailedMsgOn() const { return m_pMsgFailedOn; }
22
23static const int max_int = 0x7fffffff;
24static const int min_int = 0x80000000;
25
26int CNetObjHandler::ClampInt(const char *pErrorMsg, int Value, int Min, int Max)
27{
28 if(Value < Min) { m_pObjCorrectedOn = pErrorMsg; m_NumObjCorrections++; return Min; }
29 if(Value > Max) { m_pObjCorrectedOn = pErrorMsg; m_NumObjCorrections++; return Max; }
30 return Value;
31}
32
33const char *CNetObjHandler::ms_apObjNames[] = {
34 "EX/UUID",
35 "PlayerInput",
36 "Projectile",
37 "Laser",
38 "Pickup",
39 "Flag",
40 "GameInfo",
41 "GameData",
42 "CharacterCore",
43 "Character",
44 "PlayerInfo",
45 "ClientInfo",
46 "SpectatorInfo",
47 "Common",
48 "Explosion",
49 "Spawn",
50 "HammerHit",
51 "Death",
52 "SoundGlobal",
53 "SoundWorld",
54 "DamageInd",
55 ""
56};
57
58const char *CNetObjHandler::ms_apExObjNames[] = {
59 "invalid",
60 "MyOwnObject",
61 "DDNetCharacter",
62 "DDNetPlayer",
63 "GameInfoEx",
64 "DDRaceProjectile",
65 "DDNetLaser",
66 "DDNetProjectile",
67 "DDNetPickup",
68 "Finish",
69 "MyOwnEvent",
70 "SpecChar",
71 "SwitchState",
72 "EntityEx",
73 ""
74};
75
76int CNetObjHandler::ms_aObjSizes[] = {
77 0,
78 sizeof(CNetObj_PlayerInput),
79 sizeof(CNetObj_Projectile),
80 sizeof(CNetObj_Laser),
81 sizeof(CNetObj_Pickup),
82 sizeof(CNetObj_Flag),
83 sizeof(CNetObj_GameInfo),
84 sizeof(CNetObj_GameData),
85 sizeof(CNetObj_CharacterCore),
86 sizeof(CNetObj_Character),
87 sizeof(CNetObj_PlayerInfo),
88 sizeof(CNetObj_ClientInfo),
89 sizeof(CNetObj_SpectatorInfo),
90 sizeof(CNetEvent_Common),
91 sizeof(CNetEvent_Explosion),
92 sizeof(CNetEvent_Spawn),
93 sizeof(CNetEvent_HammerHit),
94 sizeof(CNetEvent_Death),
95 sizeof(CNetEvent_SoundGlobal),
96 sizeof(CNetEvent_SoundWorld),
97 sizeof(CNetEvent_DamageInd),
98 0
99};
100
101int CNetObjHandler::ms_aUnpackedObjSizes[] = {
102 16,
103 sizeof(CNetObj_PlayerInput),
104 sizeof(CNetObj_Projectile),
105 sizeof(CNetObj_Laser),
106 sizeof(CNetObj_Pickup),
107 sizeof(CNetObj_Flag),
108 sizeof(CNetObj_GameInfo),
109 sizeof(CNetObj_GameData),
110 sizeof(CNetObj_CharacterCore),
111 sizeof(CNetObj_Character),
112 sizeof(CNetObj_PlayerInfo),
113 sizeof(CNetObj_ClientInfo),
114 sizeof(CNetObj_SpectatorInfo),
115 sizeof(CNetEvent_Common),
116 sizeof(CNetEvent_Explosion),
117 sizeof(CNetEvent_Spawn),
118 sizeof(CNetEvent_HammerHit),
119 sizeof(CNetEvent_Death),
120 sizeof(CNetEvent_SoundGlobal),
121 sizeof(CNetEvent_SoundWorld),
122 sizeof(CNetEvent_DamageInd),
123};
124
125int CNetObjHandler::ms_aUnpackedExObjSizes[] = {
126 0,
127 sizeof(CNetObj_MyOwnObject),
128 sizeof(CNetObj_DDNetCharacter),
129 sizeof(CNetObj_DDNetPlayer),
130 sizeof(CNetObj_GameInfoEx),
131 sizeof(CNetObj_DDRaceProjectile),
132 sizeof(CNetObj_DDNetLaser),
133 sizeof(CNetObj_DDNetProjectile),
134 sizeof(CNetObj_DDNetPickup),
135 sizeof(CNetEvent_Finish),
136 sizeof(CNetObj_MyOwnEvent),
137 sizeof(CNetObj_SpecChar),
138 sizeof(CNetObj_SwitchState),
139 sizeof(CNetObj_EntityEx),
140};
141
142const char *CNetObjHandler::ms_apMsgNames[] = {
143 "invalid",
144 "Sv_Motd",
145 "Sv_Broadcast",
146 "Sv_Chat",
147 "Sv_KillMsg",
148 "Sv_SoundGlobal",
149 "Sv_TuneParams",
150 "Unused",
151 "Sv_ReadyToEnter",
152 "Sv_WeaponPickup",
153 "Sv_Emoticon",
154 "Sv_VoteClearOptions",
155 "Sv_VoteOptionListAdd",
156 "Sv_VoteOptionAdd",
157 "Sv_VoteOptionRemove",
158 "Sv_VoteSet",
159 "Sv_VoteStatus",
160 "Cl_Say",
161 "Cl_SetTeam",
162 "Cl_SetSpectatorMode",
163 "Cl_StartInfo",
164 "Cl_ChangeInfo",
165 "Cl_Kill",
166 "Cl_Emoticon",
167 "Cl_Vote",
168 "Cl_CallVote",
169 "Cl_IsDDNetLegacy",
170 "Sv_DDRaceTimeLegacy",
171 "Sv_RecordLegacy",
172 "Unused2",
173 "Sv_TeamsStateLegacy",
174 "Cl_ShowOthersLegacy",
175 ""
176};
177
178const char *CNetObjHandler::ms_apExMsgNames[] = {
179 "invalid",
180 "Sv_MyOwnMessage",
181 "Cl_ShowDistance",
182 "Cl_ShowOthers",
183 "Sv_TeamsState",
184 "Sv_DDRaceTime",
185 "Sv_Record",
186 "Sv_KillMsgTeam",
187 "Sv_YourVote",
188 "Sv_RaceFinish",
189 "Sv_CommandInfo",
190 "Sv_CommandInfoRemove",
191 "Sv_VoteOptionGroupStart",
192 "Sv_VoteOptionGroupEnd",
193 "Sv_CommandInfoGroupStart",
194 "Sv_CommandInfoGroupEnd",
195 "Sv_ChangeInfoCooldown",
196 ""
197};
198
199const char *CNetObjHandler::GetObjName(int Type) const
200{
201 if(Type >= 0 && Type < NUM_NETOBJTYPES)
202 {
203 return ms_apObjNames[Type];
204 }
205 else if(Type > __NETOBJTYPE_UUID_HELPER && Type < OFFSET_NETMSGTYPE_UUID)
206 {
207 return ms_apExObjNames[Type - __NETOBJTYPE_UUID_HELPER];
208 }
209 return "(out of range)";
210}
211
212int CNetObjHandler::GetObjSize(int Type) const
213{
214 if(Type < 0 || Type >= NUM_NETOBJTYPES) return 0;
215 return ms_aObjSizes[Type];
216}
217
218int CNetObjHandler::GetUnpackedObjSize(int Type) const
219{
220 if(Type >= 0 && Type < NUM_NETOBJTYPES)
221 {
222 return ms_aUnpackedObjSizes[Type];
223 }
224 else if(Type > __NETOBJTYPE_UUID_HELPER && Type < OFFSET_NETMSGTYPE_UUID)
225 {
226 return ms_aUnpackedExObjSizes[Type - __NETOBJTYPE_UUID_HELPER];
227 }
228 return 0;
229}
230
231const char *CNetObjHandler::GetMsgName(int Type) const
232{
233 if(Type >= 0 && Type < NUM_NETMSGTYPES)
234 {
235 return ms_apMsgNames[Type];
236 }
237 else if(Type > __NETMSGTYPE_UUID_HELPER && Type < OFFSET_MAPITEMTYPE_UUID)
238 {
239 return ms_apExMsgNames[Type - __NETMSGTYPE_UUID_HELPER];
240 }
241 return "(out of range)";
242}
243
244void *CNetObjHandler::SecureUnpackObj(int Type, CUnpacker *pUnpacker)
245{
246 m_pObjFailedOn = 0;
247 switch(Type)
248 {
249 case NETOBJTYPE_EX:
250 {
251 const unsigned char *pPtr = pUnpacker->GetRaw(Size: sizeof(CUuid));
252 if(pPtr != 0)
253 {
254 mem_copy(dest: m_aUnpackedData, source: pPtr, size: sizeof(CUuid));
255 }
256 break;
257 }
258
259 case NETOBJTYPE_PLAYERINPUT:
260 {
261 CNetObj_PlayerInput *pData = (CNetObj_PlayerInput *)m_aUnpackedData;
262 pData->m_Direction = pUnpacker->GetUncompressedInt();
263 pData->m_TargetX = pUnpacker->GetUncompressedInt();
264 pData->m_TargetY = pUnpacker->GetUncompressedInt();
265 pData->m_Jump = pUnpacker->GetUncompressedInt();
266 pData->m_Fire = pUnpacker->GetUncompressedInt();
267 pData->m_Hook = pUnpacker->GetUncompressedInt();
268 pData->m_PlayerFlags = pUnpacker->GetUncompressedInt();
269 pData->m_WantedWeapon = pUnpacker->GetUncompressedInt();
270 pData->m_NextWeapon = pUnpacker->GetUncompressedInt();
271 pData->m_PrevWeapon = pUnpacker->GetUncompressedInt();
272 pData->m_PlayerFlags = ClampInt(pErrorMsg: "m_PlayerFlags", Value: pData->m_PlayerFlags, Min: 0, Max: 256);
273 } break;
274
275 case NETOBJTYPE_PROJECTILE:
276 {
277 CNetObj_Projectile *pData = (CNetObj_Projectile *)m_aUnpackedData;
278 pData->m_X = pUnpacker->GetUncompressedInt();
279 pData->m_Y = pUnpacker->GetUncompressedInt();
280 pData->m_VelX = pUnpacker->GetUncompressedInt();
281 pData->m_VelY = pUnpacker->GetUncompressedInt();
282 pData->m_Type = pUnpacker->GetUncompressedInt();
283 pData->m_StartTick = pUnpacker->GetUncompressedInt();
284 pData->m_Type = ClampInt(pErrorMsg: "m_Type", Value: pData->m_Type, Min: 0, Max: NUM_WEAPONS-1);
285 } break;
286
287 case NETOBJTYPE_LASER:
288 {
289 CNetObj_Laser *pData = (CNetObj_Laser *)m_aUnpackedData;
290 pData->m_X = pUnpacker->GetUncompressedInt();
291 pData->m_Y = pUnpacker->GetUncompressedInt();
292 pData->m_FromX = pUnpacker->GetUncompressedInt();
293 pData->m_FromY = pUnpacker->GetUncompressedInt();
294 pData->m_StartTick = pUnpacker->GetUncompressedInt();
295 } break;
296
297 case NETOBJTYPE_PICKUP:
298 {
299 CNetObj_Pickup *pData = (CNetObj_Pickup *)m_aUnpackedData;
300 pData->m_X = pUnpacker->GetUncompressedInt();
301 pData->m_Y = pUnpacker->GetUncompressedInt();
302 pData->m_Type = pUnpacker->GetUncompressedInt();
303 pData->m_Subtype = pUnpacker->GetUncompressedInt();
304 pData->m_Type = ClampInt(pErrorMsg: "m_Type", Value: pData->m_Type, Min: 0, Max: max_int);
305 pData->m_Subtype = ClampInt(pErrorMsg: "m_Subtype", Value: pData->m_Subtype, Min: 0, Max: max_int);
306 } break;
307
308 case NETOBJTYPE_FLAG:
309 {
310 CNetObj_Flag *pData = (CNetObj_Flag *)m_aUnpackedData;
311 pData->m_X = pUnpacker->GetUncompressedInt();
312 pData->m_Y = pUnpacker->GetUncompressedInt();
313 pData->m_Team = pUnpacker->GetUncompressedInt();
314 pData->m_Team = ClampInt(pErrorMsg: "m_Team", Value: pData->m_Team, Min: TEAM_RED, Max: TEAM_BLUE);
315 } break;
316
317 case NETOBJTYPE_GAMEINFO:
318 {
319 CNetObj_GameInfo *pData = (CNetObj_GameInfo *)m_aUnpackedData;
320 pData->m_GameFlags = pUnpacker->GetUncompressedInt();
321 pData->m_GameStateFlags = pUnpacker->GetUncompressedInt();
322 pData->m_RoundStartTick = pUnpacker->GetUncompressedInt();
323 pData->m_WarmupTimer = pUnpacker->GetUncompressedInt();
324 pData->m_ScoreLimit = pUnpacker->GetUncompressedInt();
325 pData->m_TimeLimit = pUnpacker->GetUncompressedInt();
326 pData->m_RoundNum = pUnpacker->GetUncompressedInt();
327 pData->m_RoundCurrent = pUnpacker->GetUncompressedInt();
328 pData->m_GameFlags = ClampInt(pErrorMsg: "m_GameFlags", Value: pData->m_GameFlags, Min: 0, Max: 256);
329 pData->m_GameStateFlags = ClampInt(pErrorMsg: "m_GameStateFlags", Value: pData->m_GameStateFlags, Min: 0, Max: 256);
330 pData->m_WarmupTimer = ClampInt(pErrorMsg: "m_WarmupTimer", Value: pData->m_WarmupTimer, Min: min_int, Max: max_int);
331 pData->m_ScoreLimit = ClampInt(pErrorMsg: "m_ScoreLimit", Value: pData->m_ScoreLimit, Min: 0, Max: max_int);
332 pData->m_TimeLimit = ClampInt(pErrorMsg: "m_TimeLimit", Value: pData->m_TimeLimit, Min: 0, Max: max_int);
333 pData->m_RoundNum = ClampInt(pErrorMsg: "m_RoundNum", Value: pData->m_RoundNum, Min: 0, Max: max_int);
334 pData->m_RoundCurrent = ClampInt(pErrorMsg: "m_RoundCurrent", Value: pData->m_RoundCurrent, Min: 0, Max: max_int);
335 } break;
336
337 case NETOBJTYPE_GAMEDATA:
338 {
339 CNetObj_GameData *pData = (CNetObj_GameData *)m_aUnpackedData;
340 pData->m_TeamscoreRed = pUnpacker->GetUncompressedInt();
341 pData->m_TeamscoreBlue = pUnpacker->GetUncompressedInt();
342 pData->m_FlagCarrierRed = pUnpacker->GetUncompressedInt();
343 pData->m_FlagCarrierBlue = pUnpacker->GetUncompressedInt();
344 pData->m_FlagCarrierRed = ClampInt(pErrorMsg: "m_FlagCarrierRed", Value: pData->m_FlagCarrierRed, Min: FLAG_MISSING, Max: MAX_CLIENTS-1);
345 pData->m_FlagCarrierBlue = ClampInt(pErrorMsg: "m_FlagCarrierBlue", Value: pData->m_FlagCarrierBlue, Min: FLAG_MISSING, Max: MAX_CLIENTS-1);
346 } break;
347
348 case NETOBJTYPE_CHARACTERCORE:
349 {
350 CNetObj_CharacterCore *pData = (CNetObj_CharacterCore *)m_aUnpackedData;
351 pData->m_Tick = pUnpacker->GetUncompressedInt();
352 pData->m_X = pUnpacker->GetUncompressedInt();
353 pData->m_Y = pUnpacker->GetUncompressedInt();
354 pData->m_VelX = pUnpacker->GetUncompressedInt();
355 pData->m_VelY = pUnpacker->GetUncompressedInt();
356 pData->m_Angle = pUnpacker->GetUncompressedInt();
357 pData->m_Direction = pUnpacker->GetUncompressedInt();
358 pData->m_Jumped = pUnpacker->GetUncompressedInt();
359 pData->m_HookedPlayer = pUnpacker->GetUncompressedInt();
360 pData->m_HookState = pUnpacker->GetUncompressedInt();
361 pData->m_HookTick = pUnpacker->GetUncompressedInt();
362 pData->m_HookX = pUnpacker->GetUncompressedInt();
363 pData->m_HookY = pUnpacker->GetUncompressedInt();
364 pData->m_HookDx = pUnpacker->GetUncompressedInt();
365 pData->m_HookDy = pUnpacker->GetUncompressedInt();
366 pData->m_Direction = ClampInt(pErrorMsg: "m_Direction", Value: pData->m_Direction, Min: -1, Max: 1);
367 pData->m_Jumped = ClampInt(pErrorMsg: "m_Jumped", Value: pData->m_Jumped, Min: 0, Max: 3);
368 pData->m_HookedPlayer = ClampInt(pErrorMsg: "m_HookedPlayer", Value: pData->m_HookedPlayer, Min: -1, Max: MAX_CLIENTS-1);
369 pData->m_HookState = ClampInt(pErrorMsg: "m_HookState", Value: pData->m_HookState, Min: -1, Max: 5);
370 } break;
371
372 case NETOBJTYPE_CHARACTER:
373 {
374 CNetObj_Character *pData = (CNetObj_Character *)m_aUnpackedData;
375 pData->m_Tick = pUnpacker->GetUncompressedInt();
376 pData->m_X = pUnpacker->GetUncompressedInt();
377 pData->m_Y = pUnpacker->GetUncompressedInt();
378 pData->m_VelX = pUnpacker->GetUncompressedInt();
379 pData->m_VelY = pUnpacker->GetUncompressedInt();
380 pData->m_Angle = pUnpacker->GetUncompressedInt();
381 pData->m_Direction = pUnpacker->GetUncompressedInt();
382 pData->m_Jumped = pUnpacker->GetUncompressedInt();
383 pData->m_HookedPlayer = pUnpacker->GetUncompressedInt();
384 pData->m_HookState = pUnpacker->GetUncompressedInt();
385 pData->m_HookTick = pUnpacker->GetUncompressedInt();
386 pData->m_HookX = pUnpacker->GetUncompressedInt();
387 pData->m_HookY = pUnpacker->GetUncompressedInt();
388 pData->m_HookDx = pUnpacker->GetUncompressedInt();
389 pData->m_HookDy = pUnpacker->GetUncompressedInt();
390 pData->m_PlayerFlags = pUnpacker->GetUncompressedInt();
391 pData->m_Health = pUnpacker->GetUncompressedInt();
392 pData->m_Armor = pUnpacker->GetUncompressedInt();
393 pData->m_AmmoCount = pUnpacker->GetUncompressedInt();
394 pData->m_Weapon = pUnpacker->GetUncompressedInt();
395 pData->m_Emote = pUnpacker->GetUncompressedInt();
396 pData->m_AttackTick = pUnpacker->GetUncompressedInt();
397 pData->m_Direction = ClampInt(pErrorMsg: "m_Direction", Value: pData->m_Direction, Min: -1, Max: 1);
398 pData->m_Jumped = ClampInt(pErrorMsg: "m_Jumped", Value: pData->m_Jumped, Min: 0, Max: 3);
399 pData->m_HookedPlayer = ClampInt(pErrorMsg: "m_HookedPlayer", Value: pData->m_HookedPlayer, Min: -1, Max: MAX_CLIENTS-1);
400 pData->m_HookState = ClampInt(pErrorMsg: "m_HookState", Value: pData->m_HookState, Min: -1, Max: 5);
401 pData->m_PlayerFlags = ClampInt(pErrorMsg: "m_PlayerFlags", Value: pData->m_PlayerFlags, Min: 0, Max: 256);
402 pData->m_Health = ClampInt(pErrorMsg: "m_Health", Value: pData->m_Health, Min: 0, Max: 10);
403 pData->m_Armor = ClampInt(pErrorMsg: "m_Armor", Value: pData->m_Armor, Min: 0, Max: 10);
404 pData->m_AmmoCount = ClampInt(pErrorMsg: "m_AmmoCount", Value: pData->m_AmmoCount, Min: 0, Max: 10);
405 pData->m_Weapon = ClampInt(pErrorMsg: "m_Weapon", Value: pData->m_Weapon, Min: 0, Max: NUM_WEAPONS-1);
406 pData->m_Emote = ClampInt(pErrorMsg: "m_Emote", Value: pData->m_Emote, Min: 0, Max: 6);
407 pData->m_AttackTick = ClampInt(pErrorMsg: "m_AttackTick", Value: pData->m_AttackTick, Min: 0, Max: max_int);
408 } break;
409
410 case NETOBJTYPE_PLAYERINFO:
411 {
412 CNetObj_PlayerInfo *pData = (CNetObj_PlayerInfo *)m_aUnpackedData;
413 pData->m_Local = pUnpacker->GetUncompressedInt();
414 pData->m_ClientId = pUnpacker->GetUncompressedInt();
415 pData->m_Team = pUnpacker->GetUncompressedInt();
416 pData->m_Score = pUnpacker->GetUncompressedInt();
417 pData->m_Latency = pUnpacker->GetUncompressedInt();
418 pData->m_Local = ClampInt(pErrorMsg: "m_Local", Value: pData->m_Local, Min: 0, Max: 1);
419 pData->m_ClientId = ClampInt(pErrorMsg: "m_ClientId", Value: pData->m_ClientId, Min: 0, Max: MAX_CLIENTS-1);
420 pData->m_Team = ClampInt(pErrorMsg: "m_Team", Value: pData->m_Team, Min: TEAM_SPECTATORS, Max: TEAM_BLUE);
421 } break;
422
423 case NETOBJTYPE_CLIENTINFO:
424 {
425 CNetObj_ClientInfo *pData = (CNetObj_ClientInfo *)m_aUnpackedData;
426 pData->m_Name0 = pUnpacker->GetUncompressedInt();
427 pData->m_Name1 = pUnpacker->GetUncompressedInt();
428 pData->m_Name2 = pUnpacker->GetUncompressedInt();
429 pData->m_Name3 = pUnpacker->GetUncompressedInt();
430 pData->m_Clan0 = pUnpacker->GetUncompressedInt();
431 pData->m_Clan1 = pUnpacker->GetUncompressedInt();
432 pData->m_Clan2 = pUnpacker->GetUncompressedInt();
433 pData->m_Country = pUnpacker->GetUncompressedInt();
434 pData->m_Skin0 = pUnpacker->GetUncompressedInt();
435 pData->m_Skin1 = pUnpacker->GetUncompressedInt();
436 pData->m_Skin2 = pUnpacker->GetUncompressedInt();
437 pData->m_Skin3 = pUnpacker->GetUncompressedInt();
438 pData->m_Skin4 = pUnpacker->GetUncompressedInt();
439 pData->m_Skin5 = pUnpacker->GetUncompressedInt();
440 pData->m_UseCustomColor = pUnpacker->GetUncompressedInt();
441 pData->m_ColorBody = pUnpacker->GetUncompressedInt();
442 pData->m_ColorFeet = pUnpacker->GetUncompressedInt();
443 pData->m_UseCustomColor = ClampInt(pErrorMsg: "m_UseCustomColor", Value: pData->m_UseCustomColor, Min: 0, Max: 1);
444 } break;
445
446 case NETOBJTYPE_SPECTATORINFO:
447 {
448 CNetObj_SpectatorInfo *pData = (CNetObj_SpectatorInfo *)m_aUnpackedData;
449 pData->m_SpectatorId = pUnpacker->GetUncompressedInt();
450 pData->m_X = pUnpacker->GetUncompressedInt();
451 pData->m_Y = pUnpacker->GetUncompressedInt();
452 pData->m_SpectatorId = ClampInt(pErrorMsg: "m_SpectatorId", Value: pData->m_SpectatorId, Min: SPEC_FREEVIEW, Max: MAX_CLIENTS-1);
453 } break;
454
455 case NETOBJTYPE_MYOWNOBJECT:
456 {
457 CNetObj_MyOwnObject *pData = (CNetObj_MyOwnObject *)m_aUnpackedData;
458 pData->m_Test = pUnpacker->GetUncompressedInt();
459 } break;
460
461 case NETOBJTYPE_DDNETCHARACTER:
462 {
463 CNetObj_DDNetCharacter *pData = (CNetObj_DDNetCharacter *)m_aUnpackedData;
464 pData->m_Flags = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
465 pData->m_FreezeEnd = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
466 pData->m_Jumps = pUnpacker->GetUncompressedIntOrDefault(Default: 2);
467 pData->m_TeleCheckpoint = pUnpacker->GetUncompressedIntOrDefault(Default: -1);
468 pData->m_StrongWeakId = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
469 pData->m_JumpedTotal = pUnpacker->GetUncompressedIntOrDefault(Default: -1);
470 pData->m_NinjaActivationTick = pUnpacker->GetUncompressedIntOrDefault(Default: -1);
471 pData->m_FreezeStart = pUnpacker->GetUncompressedIntOrDefault(Default: -1);
472 pData->m_TargetX = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
473 pData->m_TargetY = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
474 pData->m_Jumps = ClampInt(pErrorMsg: "m_Jumps", Value: pData->m_Jumps, Min: -1, Max: 255);
475 pData->m_StrongWeakId = ClampInt(pErrorMsg: "m_StrongWeakId", Value: pData->m_StrongWeakId, Min: 0, Max: MAX_CLIENTS-1);
476 pData->m_JumpedTotal = ClampInt(pErrorMsg: "m_JumpedTotal", Value: pData->m_JumpedTotal, Min: -1, Max: 255);
477 } break;
478
479 case NETOBJTYPE_DDNETPLAYER:
480 {
481 CNetObj_DDNetPlayer *pData = (CNetObj_DDNetPlayer *)m_aUnpackedData;
482 pData->m_Flags = pUnpacker->GetUncompressedInt();
483 pData->m_AuthLevel = pUnpacker->GetUncompressedInt();
484 pData->m_AuthLevel = ClampInt(pErrorMsg: "m_AuthLevel", Value: pData->m_AuthLevel, Min: AUTHED_NO, Max: AUTHED_ADMIN);
485 } break;
486
487 case NETOBJTYPE_GAMEINFOEX:
488 {
489 CNetObj_GameInfoEx *pData = (CNetObj_GameInfoEx *)m_aUnpackedData;
490 pData->m_Flags = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
491 pData->m_Version = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
492 pData->m_Flags2 = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
493 } break;
494
495 case NETOBJTYPE_DDRACEPROJECTILE:
496 {
497 CNetObj_DDRaceProjectile *pData = (CNetObj_DDRaceProjectile *)m_aUnpackedData;
498 pData->m_X = pUnpacker->GetUncompressedInt();
499 pData->m_Y = pUnpacker->GetUncompressedInt();
500 pData->m_Angle = pUnpacker->GetUncompressedInt();
501 pData->m_Data = pUnpacker->GetUncompressedInt();
502 pData->m_Type = pUnpacker->GetUncompressedInt();
503 pData->m_StartTick = pUnpacker->GetUncompressedInt();
504 pData->m_Type = ClampInt(pErrorMsg: "m_Type", Value: pData->m_Type, Min: 0, Max: NUM_WEAPONS-1);
505 } break;
506
507 case NETOBJTYPE_DDNETLASER:
508 {
509 CNetObj_DDNetLaser *pData = (CNetObj_DDNetLaser *)m_aUnpackedData;
510 pData->m_ToX = pUnpacker->GetUncompressedInt();
511 pData->m_ToY = pUnpacker->GetUncompressedInt();
512 pData->m_FromX = pUnpacker->GetUncompressedInt();
513 pData->m_FromY = pUnpacker->GetUncompressedInt();
514 pData->m_StartTick = pUnpacker->GetUncompressedInt();
515 pData->m_Owner = pUnpacker->GetUncompressedInt();
516 pData->m_Type = pUnpacker->GetUncompressedInt();
517 pData->m_SwitchNumber = pUnpacker->GetUncompressedIntOrDefault(Default: -1);
518 pData->m_Subtype = pUnpacker->GetUncompressedIntOrDefault(Default: -1);
519 pData->m_Flags = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
520 pData->m_Owner = ClampInt(pErrorMsg: "m_Owner", Value: pData->m_Owner, Min: -1, Max: MAX_CLIENTS-1);
521 } break;
522
523 case NETOBJTYPE_DDNETPROJECTILE:
524 {
525 CNetObj_DDNetProjectile *pData = (CNetObj_DDNetProjectile *)m_aUnpackedData;
526 pData->m_X = pUnpacker->GetUncompressedInt();
527 pData->m_Y = pUnpacker->GetUncompressedInt();
528 pData->m_VelX = pUnpacker->GetUncompressedInt();
529 pData->m_VelY = pUnpacker->GetUncompressedInt();
530 pData->m_Type = pUnpacker->GetUncompressedInt();
531 pData->m_StartTick = pUnpacker->GetUncompressedInt();
532 pData->m_Owner = pUnpacker->GetUncompressedInt();
533 pData->m_SwitchNumber = pUnpacker->GetUncompressedInt();
534 pData->m_TuneZone = pUnpacker->GetUncompressedInt();
535 pData->m_Flags = pUnpacker->GetUncompressedInt();
536 pData->m_Type = ClampInt(pErrorMsg: "m_Type", Value: pData->m_Type, Min: 0, Max: NUM_WEAPONS-1);
537 pData->m_Owner = ClampInt(pErrorMsg: "m_Owner", Value: pData->m_Owner, Min: -1, Max: MAX_CLIENTS-1);
538 } break;
539
540 case NETOBJTYPE_DDNETPICKUP:
541 {
542 CNetObj_DDNetPickup *pData = (CNetObj_DDNetPickup *)m_aUnpackedData;
543 pData->m_X = pUnpacker->GetUncompressedInt();
544 pData->m_Y = pUnpacker->GetUncompressedInt();
545 pData->m_Type = pUnpacker->GetUncompressedInt();
546 pData->m_Subtype = pUnpacker->GetUncompressedInt();
547 pData->m_SwitchNumber = pUnpacker->GetUncompressedInt();
548 pData->m_Type = ClampInt(pErrorMsg: "m_Type", Value: pData->m_Type, Min: 0, Max: max_int);
549 pData->m_Subtype = ClampInt(pErrorMsg: "m_Subtype", Value: pData->m_Subtype, Min: 0, Max: max_int);
550 } break;
551
552 case NETEVENTTYPE_COMMON:
553 {
554 CNetEvent_Common *pData = (CNetEvent_Common *)m_aUnpackedData;
555 pData->m_X = pUnpacker->GetUncompressedInt();
556 pData->m_Y = pUnpacker->GetUncompressedInt();
557 } break;
558
559 case NETEVENTTYPE_EXPLOSION:
560 {
561 CNetEvent_Explosion *pData = (CNetEvent_Explosion *)m_aUnpackedData;
562 pData->m_X = pUnpacker->GetUncompressedInt();
563 pData->m_Y = pUnpacker->GetUncompressedInt();
564 } break;
565
566 case NETEVENTTYPE_SPAWN:
567 {
568 CNetEvent_Spawn *pData = (CNetEvent_Spawn *)m_aUnpackedData;
569 pData->m_X = pUnpacker->GetUncompressedInt();
570 pData->m_Y = pUnpacker->GetUncompressedInt();
571 } break;
572
573 case NETEVENTTYPE_HAMMERHIT:
574 {
575 CNetEvent_HammerHit *pData = (CNetEvent_HammerHit *)m_aUnpackedData;
576 pData->m_X = pUnpacker->GetUncompressedInt();
577 pData->m_Y = pUnpacker->GetUncompressedInt();
578 } break;
579
580 case NETEVENTTYPE_DEATH:
581 {
582 CNetEvent_Death *pData = (CNetEvent_Death *)m_aUnpackedData;
583 pData->m_X = pUnpacker->GetUncompressedInt();
584 pData->m_Y = pUnpacker->GetUncompressedInt();
585 pData->m_ClientId = pUnpacker->GetUncompressedInt();
586 pData->m_ClientId = ClampInt(pErrorMsg: "m_ClientId", Value: pData->m_ClientId, Min: 0, Max: MAX_CLIENTS-1);
587 } break;
588
589 case NETEVENTTYPE_SOUNDGLOBAL:
590 {
591 CNetEvent_SoundGlobal *pData = (CNetEvent_SoundGlobal *)m_aUnpackedData;
592 pData->m_X = pUnpacker->GetUncompressedInt();
593 pData->m_Y = pUnpacker->GetUncompressedInt();
594 pData->m_SoundId = pUnpacker->GetUncompressedInt();
595 pData->m_SoundId = ClampInt(pErrorMsg: "m_SoundId", Value: pData->m_SoundId, Min: 0, Max: NUM_SOUNDS-1);
596 } break;
597
598 case NETEVENTTYPE_SOUNDWORLD:
599 {
600 CNetEvent_SoundWorld *pData = (CNetEvent_SoundWorld *)m_aUnpackedData;
601 pData->m_X = pUnpacker->GetUncompressedInt();
602 pData->m_Y = pUnpacker->GetUncompressedInt();
603 pData->m_SoundId = pUnpacker->GetUncompressedInt();
604 pData->m_SoundId = ClampInt(pErrorMsg: "m_SoundId", Value: pData->m_SoundId, Min: 0, Max: NUM_SOUNDS-1);
605 } break;
606
607 case NETEVENTTYPE_DAMAGEIND:
608 {
609 CNetEvent_DamageInd *pData = (CNetEvent_DamageInd *)m_aUnpackedData;
610 pData->m_X = pUnpacker->GetUncompressedInt();
611 pData->m_Y = pUnpacker->GetUncompressedInt();
612 pData->m_Angle = pUnpacker->GetUncompressedInt();
613 } break;
614
615 case NETEVENTTYPE_FINISH:
616 {
617 CNetEvent_Finish *pData = (CNetEvent_Finish *)m_aUnpackedData;
618 pData->m_X = pUnpacker->GetUncompressedInt();
619 pData->m_Y = pUnpacker->GetUncompressedInt();
620 } break;
621
622 case NETOBJTYPE_MYOWNEVENT:
623 {
624 CNetObj_MyOwnEvent *pData = (CNetObj_MyOwnEvent *)m_aUnpackedData;
625 pData->m_Test = pUnpacker->GetUncompressedInt();
626 } break;
627
628 case NETOBJTYPE_SPECCHAR:
629 {
630 CNetObj_SpecChar *pData = (CNetObj_SpecChar *)m_aUnpackedData;
631 pData->m_X = pUnpacker->GetUncompressedInt();
632 pData->m_Y = pUnpacker->GetUncompressedInt();
633 } break;
634
635 case NETOBJTYPE_SWITCHSTATE:
636 {
637 CNetObj_SwitchState *pData = (CNetObj_SwitchState *)m_aUnpackedData;
638 pData->m_HighestSwitchNumber = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
639 pData->m_aStatus[0] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
640 pData->m_aStatus[1] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
641 pData->m_aStatus[2] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
642 pData->m_aStatus[3] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
643 pData->m_aStatus[4] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
644 pData->m_aStatus[5] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
645 pData->m_aStatus[6] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
646 pData->m_aStatus[7] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
647 pData->m_aSwitchNumbers[0] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
648 pData->m_aSwitchNumbers[1] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
649 pData->m_aSwitchNumbers[2] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
650 pData->m_aSwitchNumbers[3] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
651 pData->m_aEndTicks[0] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
652 pData->m_aEndTicks[1] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
653 pData->m_aEndTicks[2] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
654 pData->m_aEndTicks[3] = pUnpacker->GetUncompressedIntOrDefault(Default: 0);
655 } break;
656
657 case NETOBJTYPE_ENTITYEX:
658 {
659 CNetObj_EntityEx *pData = (CNetObj_EntityEx *)m_aUnpackedData;
660 pData->m_SwitchNumber = pUnpacker->GetUncompressedInt();
661 pData->m_Layer = pUnpacker->GetUncompressedInt();
662 pData->m_EntityClass = pUnpacker->GetUncompressedInt();
663 } break;
664
665 default:
666 m_pObjFailedOn = "(type out of range)";
667 break;
668 }
669
670 if(pUnpacker->Error())
671 m_pObjFailedOn = "(unpack error)";
672
673 if(m_pObjFailedOn)
674 return 0;
675 m_pObjFailedOn = "";
676 return m_aUnpackedData;
677}
678
679void *CNetObjHandler::SecureUnpackMsg(int Type, CUnpacker *pUnpacker)
680{
681 m_pMsgFailedOn = 0;
682 switch(Type)
683 {
684
685 case NETMSGTYPE_SV_MOTD:
686 {
687 CNetMsg_Sv_Motd *pData = (CNetMsg_Sv_Motd *)m_aUnpackedData;
688 pData->m_pMessage = pUnpacker->GetString();
689 } break;
690
691 case NETMSGTYPE_SV_BROADCAST:
692 {
693 CNetMsg_Sv_Broadcast *pData = (CNetMsg_Sv_Broadcast *)m_aUnpackedData;
694 pData->m_pMessage = pUnpacker->GetString();
695 } break;
696
697 case NETMSGTYPE_SV_CHAT:
698 {
699 CNetMsg_Sv_Chat *pData = (CNetMsg_Sv_Chat *)m_aUnpackedData;
700 pData->m_Team = pUnpacker->GetInt();
701 pData->m_ClientId = pUnpacker->GetInt();
702 pData->m_pMessage = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC);
703 if(pData->m_Team < -2 || pData->m_Team > 3) { m_pMsgFailedOn = "m_Team"; break; }
704 if(pData->m_ClientId < -1 || pData->m_ClientId > MAX_CLIENTS-1) { m_pMsgFailedOn = "m_ClientId"; break; }
705 } break;
706
707 case NETMSGTYPE_SV_KILLMSG:
708 {
709 CNetMsg_Sv_KillMsg *pData = (CNetMsg_Sv_KillMsg *)m_aUnpackedData;
710 pData->m_Killer = pUnpacker->GetInt();
711 pData->m_Victim = pUnpacker->GetInt();
712 pData->m_Weapon = pUnpacker->GetInt();
713 pData->m_ModeSpecial = pUnpacker->GetInt();
714 if(pData->m_Killer < 0 || pData->m_Killer > MAX_CLIENTS-1) { m_pMsgFailedOn = "m_Killer"; break; }
715 if(pData->m_Victim < 0 || pData->m_Victim > MAX_CLIENTS-1) { m_pMsgFailedOn = "m_Victim"; break; }
716 if(pData->m_Weapon < -3 || pData->m_Weapon > NUM_WEAPONS-1) { m_pMsgFailedOn = "m_Weapon"; break; }
717 } break;
718
719 case NETMSGTYPE_SV_SOUNDGLOBAL:
720 {
721 CNetMsg_Sv_SoundGlobal *pData = (CNetMsg_Sv_SoundGlobal *)m_aUnpackedData;
722 pData->m_SoundId = pUnpacker->GetInt();
723 if(pData->m_SoundId < 0 || pData->m_SoundId > NUM_SOUNDS-1) { m_pMsgFailedOn = "m_SoundId"; break; }
724 } break;
725
726 case NETMSGTYPE_SV_TUNEPARAMS:
727 {
728 CNetMsg_Sv_TuneParams *pData = (CNetMsg_Sv_TuneParams *)m_aUnpackedData;
729 (void)pData;
730 } break;
731
732 case NETMSGTYPE_UNUSED:
733 {
734 CNetMsg_Unused *pData = (CNetMsg_Unused *)m_aUnpackedData;
735 (void)pData;
736 } break;
737
738 case NETMSGTYPE_SV_READYTOENTER:
739 {
740 CNetMsg_Sv_ReadyToEnter *pData = (CNetMsg_Sv_ReadyToEnter *)m_aUnpackedData;
741 (void)pData;
742 } break;
743
744 case NETMSGTYPE_SV_WEAPONPICKUP:
745 {
746 CNetMsg_Sv_WeaponPickup *pData = (CNetMsg_Sv_WeaponPickup *)m_aUnpackedData;
747 pData->m_Weapon = pUnpacker->GetInt();
748 if(pData->m_Weapon < 0 || pData->m_Weapon > NUM_WEAPONS-1) { m_pMsgFailedOn = "m_Weapon"; break; }
749 } break;
750
751 case NETMSGTYPE_SV_EMOTICON:
752 {
753 CNetMsg_Sv_Emoticon *pData = (CNetMsg_Sv_Emoticon *)m_aUnpackedData;
754 pData->m_ClientId = pUnpacker->GetInt();
755 pData->m_Emoticon = pUnpacker->GetInt();
756 if(pData->m_ClientId < 0 || pData->m_ClientId > MAX_CLIENTS-1) { m_pMsgFailedOn = "m_ClientId"; break; }
757 if(pData->m_Emoticon < 0 || pData->m_Emoticon > NUM_EMOTICONS-1) { m_pMsgFailedOn = "m_Emoticon"; break; }
758 } break;
759
760 case NETMSGTYPE_SV_VOTECLEAROPTIONS:
761 {
762 CNetMsg_Sv_VoteClearOptions *pData = (CNetMsg_Sv_VoteClearOptions *)m_aUnpackedData;
763 (void)pData;
764 } break;
765
766 case NETMSGTYPE_SV_VOTEOPTIONLISTADD:
767 {
768 CNetMsg_Sv_VoteOptionListAdd *pData = (CNetMsg_Sv_VoteOptionListAdd *)m_aUnpackedData;
769 pData->m_NumOptions = pUnpacker->GetInt();
770 pData->m_pDescription0 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
771 pData->m_pDescription1 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
772 pData->m_pDescription2 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
773 pData->m_pDescription3 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
774 pData->m_pDescription4 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
775 pData->m_pDescription5 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
776 pData->m_pDescription6 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
777 pData->m_pDescription7 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
778 pData->m_pDescription8 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
779 pData->m_pDescription9 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
780 pData->m_pDescription10 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
781 pData->m_pDescription11 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
782 pData->m_pDescription12 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
783 pData->m_pDescription13 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
784 pData->m_pDescription14 = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
785 if(pData->m_NumOptions < 1 || pData->m_NumOptions > 15) { m_pMsgFailedOn = "m_NumOptions"; break; }
786 } break;
787
788 case NETMSGTYPE_SV_VOTEOPTIONADD:
789 {
790 CNetMsg_Sv_VoteOptionAdd *pData = (CNetMsg_Sv_VoteOptionAdd *)m_aUnpackedData;
791 pData->m_pDescription = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
792 } break;
793
794 case NETMSGTYPE_SV_VOTEOPTIONREMOVE:
795 {
796 CNetMsg_Sv_VoteOptionRemove *pData = (CNetMsg_Sv_VoteOptionRemove *)m_aUnpackedData;
797 pData->m_pDescription = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
798 } break;
799
800 case NETMSGTYPE_SV_VOTESET:
801 {
802 CNetMsg_Sv_VoteSet *pData = (CNetMsg_Sv_VoteSet *)m_aUnpackedData;
803 pData->m_Timeout = pUnpacker->GetInt();
804 pData->m_pDescription = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
805 pData->m_pReason = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
806 if(pData->m_Timeout < 0 || pData->m_Timeout > max_int) { m_pMsgFailedOn = "m_Timeout"; break; }
807 } break;
808
809 case NETMSGTYPE_SV_VOTESTATUS:
810 {
811 CNetMsg_Sv_VoteStatus *pData = (CNetMsg_Sv_VoteStatus *)m_aUnpackedData;
812 pData->m_Yes = pUnpacker->GetInt();
813 pData->m_No = pUnpacker->GetInt();
814 pData->m_Pass = pUnpacker->GetInt();
815 pData->m_Total = pUnpacker->GetInt();
816 if(pData->m_Yes < 0 || pData->m_Yes > MAX_CLIENTS) { m_pMsgFailedOn = "m_Yes"; break; }
817 if(pData->m_No < 0 || pData->m_No > MAX_CLIENTS) { m_pMsgFailedOn = "m_No"; break; }
818 if(pData->m_Pass < 0 || pData->m_Pass > MAX_CLIENTS) { m_pMsgFailedOn = "m_Pass"; break; }
819 if(pData->m_Total < 0 || pData->m_Total > MAX_CLIENTS) { m_pMsgFailedOn = "m_Total"; break; }
820 } break;
821
822 case NETMSGTYPE_CL_SAY:
823 {
824 CNetMsg_Cl_Say *pData = (CNetMsg_Cl_Say *)m_aUnpackedData;
825 pData->m_Team = pUnpacker->GetInt();
826 pData->m_pMessage = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC);
827 if(pData->m_Team < 0 || pData->m_Team > 1) { m_pMsgFailedOn = "m_Team"; break; }
828 } break;
829
830 case NETMSGTYPE_CL_SETTEAM:
831 {
832 CNetMsg_Cl_SetTeam *pData = (CNetMsg_Cl_SetTeam *)m_aUnpackedData;
833 pData->m_Team = pUnpacker->GetInt();
834 if(pData->m_Team < TEAM_SPECTATORS || pData->m_Team > TEAM_BLUE) { m_pMsgFailedOn = "m_Team"; break; }
835 } break;
836
837 case NETMSGTYPE_CL_SETSPECTATORMODE:
838 {
839 CNetMsg_Cl_SetSpectatorMode *pData = (CNetMsg_Cl_SetSpectatorMode *)m_aUnpackedData;
840 pData->m_SpectatorId = pUnpacker->GetInt();
841 if(pData->m_SpectatorId < SPEC_FREEVIEW || pData->m_SpectatorId > MAX_CLIENTS-1) { m_pMsgFailedOn = "m_SpectatorId"; break; }
842 } break;
843
844 case NETMSGTYPE_CL_STARTINFO:
845 {
846 CNetMsg_Cl_StartInfo *pData = (CNetMsg_Cl_StartInfo *)m_aUnpackedData;
847 pData->m_pName = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
848 pData->m_pClan = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
849 pData->m_Country = pUnpacker->GetInt();
850 pData->m_pSkin = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
851 pData->m_UseCustomColor = pUnpacker->GetInt();
852 pData->m_ColorBody = pUnpacker->GetInt();
853 pData->m_ColorFeet = pUnpacker->GetInt();
854 if(pData->m_UseCustomColor < 0 || pData->m_UseCustomColor > 1) { m_pMsgFailedOn = "m_UseCustomColor"; break; }
855 } break;
856
857 case NETMSGTYPE_CL_CHANGEINFO:
858 {
859 CNetMsg_Cl_ChangeInfo *pData = (CNetMsg_Cl_ChangeInfo *)m_aUnpackedData;
860 pData->m_pName = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
861 pData->m_pClan = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
862 pData->m_Country = pUnpacker->GetInt();
863 pData->m_pSkin = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
864 pData->m_UseCustomColor = pUnpacker->GetInt();
865 pData->m_ColorBody = pUnpacker->GetInt();
866 pData->m_ColorFeet = pUnpacker->GetInt();
867 if(pData->m_UseCustomColor < 0 || pData->m_UseCustomColor > 1) { m_pMsgFailedOn = "m_UseCustomColor"; break; }
868 } break;
869
870 case NETMSGTYPE_CL_KILL:
871 {
872 CNetMsg_Cl_Kill *pData = (CNetMsg_Cl_Kill *)m_aUnpackedData;
873 (void)pData;
874 } break;
875
876 case NETMSGTYPE_CL_EMOTICON:
877 {
878 CNetMsg_Cl_Emoticon *pData = (CNetMsg_Cl_Emoticon *)m_aUnpackedData;
879 pData->m_Emoticon = pUnpacker->GetInt();
880 if(pData->m_Emoticon < 0 || pData->m_Emoticon > NUM_EMOTICONS-1) { m_pMsgFailedOn = "m_Emoticon"; break; }
881 } break;
882
883 case NETMSGTYPE_CL_VOTE:
884 {
885 CNetMsg_Cl_Vote *pData = (CNetMsg_Cl_Vote *)m_aUnpackedData;
886 pData->m_Vote = pUnpacker->GetInt();
887 if(pData->m_Vote < -1 || pData->m_Vote > 1) { m_pMsgFailedOn = "m_Vote"; break; }
888 } break;
889
890 case NETMSGTYPE_CL_CALLVOTE:
891 {
892 CNetMsg_Cl_CallVote *pData = (CNetMsg_Cl_CallVote *)m_aUnpackedData;
893 pData->m_pType = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
894 pData->m_pValue = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
895 pData->m_pReason = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
896 } break;
897
898 case NETMSGTYPE_CL_ISDDNETLEGACY:
899 {
900 CNetMsg_Cl_IsDDNetLegacy *pData = (CNetMsg_Cl_IsDDNetLegacy *)m_aUnpackedData;
901 (void)pData;
902 } break;
903
904 case NETMSGTYPE_SV_DDRACETIMELEGACY:
905 {
906 CNetMsg_Sv_DDRaceTimeLegacy *pData = (CNetMsg_Sv_DDRaceTimeLegacy *)m_aUnpackedData;
907 pData->m_Time = pUnpacker->GetInt();
908 pData->m_Check = pUnpacker->GetInt();
909 pData->m_Finish = pUnpacker->GetInt();
910 if(pData->m_Finish < 0 || pData->m_Finish > 1) { m_pMsgFailedOn = "m_Finish"; break; }
911 } break;
912
913 case NETMSGTYPE_SV_RECORDLEGACY:
914 {
915 CNetMsg_Sv_RecordLegacy *pData = (CNetMsg_Sv_RecordLegacy *)m_aUnpackedData;
916 pData->m_ServerTimeBest = pUnpacker->GetInt();
917 pData->m_PlayerTimeBest = pUnpacker->GetInt();
918 } break;
919
920 case NETMSGTYPE_UNUSED2:
921 {
922 CNetMsg_Unused2 *pData = (CNetMsg_Unused2 *)m_aUnpackedData;
923 (void)pData;
924 } break;
925
926 case NETMSGTYPE_SV_TEAMSSTATELEGACY:
927 {
928 CNetMsg_Sv_TeamsStateLegacy *pData = (CNetMsg_Sv_TeamsStateLegacy *)m_aUnpackedData;
929 (void)pData;
930 } break;
931
932 case NETMSGTYPE_CL_SHOWOTHERSLEGACY:
933 {
934 CNetMsg_Cl_ShowOthersLegacy *pData = (CNetMsg_Cl_ShowOthersLegacy *)m_aUnpackedData;
935 pData->m_Show = pUnpacker->GetInt();
936 if(pData->m_Show < 0 || pData->m_Show > 1) { m_pMsgFailedOn = "m_Show"; break; }
937 } break;
938
939 case NETMSGTYPE_SV_MYOWNMESSAGE:
940 {
941 CNetMsg_Sv_MyOwnMessage *pData = (CNetMsg_Sv_MyOwnMessage *)m_aUnpackedData;
942 pData->m_Test = pUnpacker->GetInt();
943 } break;
944
945 case NETMSGTYPE_CL_SHOWDISTANCE:
946 {
947 CNetMsg_Cl_ShowDistance *pData = (CNetMsg_Cl_ShowDistance *)m_aUnpackedData;
948 pData->m_X = pUnpacker->GetInt();
949 pData->m_Y = pUnpacker->GetInt();
950 } break;
951
952 case NETMSGTYPE_CL_SHOWOTHERS:
953 {
954 CNetMsg_Cl_ShowOthers *pData = (CNetMsg_Cl_ShowOthers *)m_aUnpackedData;
955 pData->m_Show = pUnpacker->GetInt();
956 if(pData->m_Show < 0 || pData->m_Show > 2) { m_pMsgFailedOn = "m_Show"; break; }
957 } break;
958
959 case NETMSGTYPE_SV_TEAMSSTATE:
960 {
961 CNetMsg_Sv_TeamsState *pData = (CNetMsg_Sv_TeamsState *)m_aUnpackedData;
962 (void)pData;
963 } break;
964
965 case NETMSGTYPE_SV_DDRACETIME:
966 {
967 CNetMsg_Sv_DDRaceTime *pData = (CNetMsg_Sv_DDRaceTime *)m_aUnpackedData;
968 pData->m_Time = pUnpacker->GetInt();
969 pData->m_Check = pUnpacker->GetInt();
970 pData->m_Finish = pUnpacker->GetInt();
971 if(pData->m_Finish < 0 || pData->m_Finish > 1) { m_pMsgFailedOn = "m_Finish"; break; }
972 } break;
973
974 case NETMSGTYPE_SV_RECORD:
975 {
976 CNetMsg_Sv_Record *pData = (CNetMsg_Sv_Record *)m_aUnpackedData;
977 pData->m_ServerTimeBest = pUnpacker->GetInt();
978 pData->m_PlayerTimeBest = pUnpacker->GetInt();
979 } break;
980
981 case NETMSGTYPE_SV_KILLMSGTEAM:
982 {
983 CNetMsg_Sv_KillMsgTeam *pData = (CNetMsg_Sv_KillMsgTeam *)m_aUnpackedData;
984 pData->m_Team = pUnpacker->GetInt();
985 pData->m_First = pUnpacker->GetInt();
986 if(pData->m_Team < 0 || pData->m_Team > MAX_CLIENTS-1) { m_pMsgFailedOn = "m_Team"; break; }
987 if(pData->m_First < -1 || pData->m_First > MAX_CLIENTS-1) { m_pMsgFailedOn = "m_First"; break; }
988 } break;
989
990 case NETMSGTYPE_SV_YOURVOTE:
991 {
992 CNetMsg_Sv_YourVote *pData = (CNetMsg_Sv_YourVote *)m_aUnpackedData;
993 pData->m_Voted = pUnpacker->GetInt();
994 if(pData->m_Voted < -1 || pData->m_Voted > 1) { m_pMsgFailedOn = "m_Voted"; break; }
995 } break;
996
997 case NETMSGTYPE_SV_RACEFINISH:
998 {
999 CNetMsg_Sv_RaceFinish *pData = (CNetMsg_Sv_RaceFinish *)m_aUnpackedData;
1000 pData->m_ClientId = pUnpacker->GetInt();
1001 pData->m_Time = pUnpacker->GetInt();
1002 pData->m_Diff = pUnpacker->GetInt();
1003 pData->m_RecordPersonal = pUnpacker->GetInt();
1004 pData->m_RecordServer = pUnpacker->GetIntOrDefault(Default: 0);
1005 if(pData->m_ClientId < 0 || pData->m_ClientId > MAX_CLIENTS-1) { m_pMsgFailedOn = "m_ClientId"; break; }
1006 if(pData->m_RecordPersonal < 0 || pData->m_RecordPersonal > 1) { m_pMsgFailedOn = "m_RecordPersonal"; break; }
1007 if(pData->m_RecordServer < 0 || pData->m_RecordServer > 1) { m_pMsgFailedOn = "m_RecordServer"; break; }
1008 } break;
1009
1010 case NETMSGTYPE_SV_COMMANDINFO:
1011 {
1012 CNetMsg_Sv_CommandInfo *pData = (CNetMsg_Sv_CommandInfo *)m_aUnpackedData;
1013 pData->m_pName = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
1014 pData->m_pArgsFormat = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
1015 pData->m_pHelpText = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
1016 } break;
1017
1018 case NETMSGTYPE_SV_COMMANDINFOREMOVE:
1019 {
1020 CNetMsg_Sv_CommandInfoRemove *pData = (CNetMsg_Sv_CommandInfoRemove *)m_aUnpackedData;
1021 pData->m_pName = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
1022 } break;
1023
1024 case NETMSGTYPE_SV_VOTEOPTIONGROUPSTART:
1025 {
1026 CNetMsg_Sv_VoteOptionGroupStart *pData = (CNetMsg_Sv_VoteOptionGroupStart *)m_aUnpackedData;
1027 (void)pData;
1028 } break;
1029
1030 case NETMSGTYPE_SV_VOTEOPTIONGROUPEND:
1031 {
1032 CNetMsg_Sv_VoteOptionGroupEnd *pData = (CNetMsg_Sv_VoteOptionGroupEnd *)m_aUnpackedData;
1033 (void)pData;
1034 } break;
1035
1036 case NETMSGTYPE_SV_COMMANDINFOGROUPSTART:
1037 {
1038 CNetMsg_Sv_CommandInfoGroupStart *pData = (CNetMsg_Sv_CommandInfoGroupStart *)m_aUnpackedData;
1039 (void)pData;
1040 } break;
1041
1042 case NETMSGTYPE_SV_COMMANDINFOGROUPEND:
1043 {
1044 CNetMsg_Sv_CommandInfoGroupEnd *pData = (CNetMsg_Sv_CommandInfoGroupEnd *)m_aUnpackedData;
1045 (void)pData;
1046 } break;
1047
1048 case NETMSGTYPE_SV_CHANGEINFOCOOLDOWN:
1049 {
1050 CNetMsg_Sv_ChangeInfoCooldown *pData = (CNetMsg_Sv_ChangeInfoCooldown *)m_aUnpackedData;
1051 pData->m_WaitUntil = pUnpacker->GetInt();
1052 } break;
1053
1054 default:
1055 m_pMsgFailedOn = "(type out of range)";
1056 break;
1057 }
1058
1059 if(pUnpacker->Error())
1060 m_pMsgFailedOn = "(unpack error)";
1061
1062 if(m_pMsgFailedOn)
1063 return 0;
1064 m_pMsgFailedOn = "";
1065 return m_aUnpackedData;
1066}
1067
1068bool CNetObjHandler::TeeHistorianRecordMsg(int Type)
1069{
1070 switch(Type)
1071 {
1072
1073 case NETMSGTYPE_CL_SAY:
1074 case NETMSGTYPE_CL_VOTE:
1075 case NETMSGTYPE_CL_CALLVOTE:
1076 return false;
1077 default:
1078 return true;
1079 }
1080}
1081
1082void RegisterGameUuids(CUuidManager *pManager)
1083{
1084
1085 pManager->RegisterName(Id: NETOBJTYPE_MYOWNOBJECT, pName: "my-own-object@heinrich5991.de");
1086 pManager->RegisterName(Id: NETOBJTYPE_DDNETCHARACTER, pName: "character@netobj.ddnet.tw");
1087 pManager->RegisterName(Id: NETOBJTYPE_DDNETPLAYER, pName: "player@netobj.ddnet.tw");
1088 pManager->RegisterName(Id: NETOBJTYPE_GAMEINFOEX, pName: "gameinfo@netobj.ddnet.tw");
1089 pManager->RegisterName(Id: NETOBJTYPE_DDRACEPROJECTILE, pName: "projectile@netobj.ddnet.tw");
1090 pManager->RegisterName(Id: NETOBJTYPE_DDNETLASER, pName: "laser@netobj.ddnet.tw");
1091 pManager->RegisterName(Id: NETOBJTYPE_DDNETPROJECTILE, pName: "ddnet-projectile@netobj.ddnet.tw");
1092 pManager->RegisterName(Id: NETOBJTYPE_DDNETPICKUP, pName: "pickup@netobj.ddnet.tw");
1093 pManager->RegisterName(Id: NETEVENTTYPE_FINISH, pName: "finish@netevent.ddnet.org");
1094 pManager->RegisterName(Id: NETOBJTYPE_MYOWNEVENT, pName: "my-own-event@heinrich5991.de");
1095 pManager->RegisterName(Id: NETOBJTYPE_SPECCHAR, pName: "spec-char@netobj.ddnet.tw");
1096 pManager->RegisterName(Id: NETOBJTYPE_SWITCHSTATE, pName: "switch-state@netobj.ddnet.tw");
1097 pManager->RegisterName(Id: NETOBJTYPE_ENTITYEX, pName: "entity-ex@netobj.ddnet.tw");
1098 pManager->RegisterName(Id: NETMSGTYPE_SV_MYOWNMESSAGE, pName: "my-own-message@heinrich5991.de");
1099 pManager->RegisterName(Id: NETMSGTYPE_CL_SHOWDISTANCE, pName: "show-distance@netmsg.ddnet.tw");
1100 pManager->RegisterName(Id: NETMSGTYPE_CL_SHOWOTHERS, pName: "showothers@netmsg.ddnet.tw");
1101 pManager->RegisterName(Id: NETMSGTYPE_SV_TEAMSSTATE, pName: "teamsstate@netmsg.ddnet.tw");
1102 pManager->RegisterName(Id: NETMSGTYPE_SV_DDRACETIME, pName: "ddrace-time@netmsg.ddnet.tw");
1103 pManager->RegisterName(Id: NETMSGTYPE_SV_RECORD, pName: "record@netmsg.ddnet.tw");
1104 pManager->RegisterName(Id: NETMSGTYPE_SV_KILLMSGTEAM, pName: "killmsgteam@netmsg.ddnet.tw");
1105 pManager->RegisterName(Id: NETMSGTYPE_SV_YOURVOTE, pName: "yourvote@netmsg.ddnet.org");
1106 pManager->RegisterName(Id: NETMSGTYPE_SV_RACEFINISH, pName: "racefinish@netmsg.ddnet.org");
1107 pManager->RegisterName(Id: NETMSGTYPE_SV_COMMANDINFO, pName: "commandinfo@netmsg.ddnet.org");
1108 pManager->RegisterName(Id: NETMSGTYPE_SV_COMMANDINFOREMOVE, pName: "commandinfo-remove@netmsg.ddnet.org");
1109 pManager->RegisterName(Id: NETMSGTYPE_SV_VOTEOPTIONGROUPSTART, pName: "sv-vote-option-group-start@netmsg.ddnet.org");
1110 pManager->RegisterName(Id: NETMSGTYPE_SV_VOTEOPTIONGROUPEND, pName: "sv-vote-option-group-end@netmsg.ddnet.org");
1111 pManager->RegisterName(Id: NETMSGTYPE_SV_COMMANDINFOGROUPSTART, pName: "sv-commandinfo-group-start@netmsg.ddnet.org");
1112 pManager->RegisterName(Id: NETMSGTYPE_SV_COMMANDINFOGROUPEND, pName: "sv-commandinfo-group-end@netmsg.ddnet.org");
1113 pManager->RegisterName(Id: NETMSGTYPE_SV_CHANGEINFOCOOLDOWN, pName: "change-info-cooldown@netmsg.ddnet.org");
1114
1115 RegisterMapItemTypeUuids(pManager);
1116}
1117
1118