cleaned up types within network data

This commit is contained in:
oy 2012-08-03 18:46:01 +02:00
parent 719867271f
commit a55a7dfef0
4 changed files with 61 additions and 34 deletions

View file

@ -127,6 +127,7 @@ class CNetObjHandler
char m_aMsgData[1024]; char m_aMsgData[1024];
int m_NumObjCorrections; int m_NumObjCorrections;
int ClampInt(const char *pErrorMsg, int Value, int Min, int Max); int ClampInt(const char *pErrorMsg, int Value, int Min, int Max);
int ClampFlag(const char *pErrorMsg, int Value, int Mask);
static const char *ms_apObjNames[]; static const char *ms_apObjNames[];
static int ms_aObjSizes[]; static int ms_aObjSizes[];
@ -176,6 +177,7 @@ if gen_network_source:
lines += [''] lines += ['']
lines += ['static const int max_int = 0x7fffffff;'] lines += ['static const int max_int = 0x7fffffff;']
lines += ['']
lines += ['int CNetObjHandler::ClampInt(const char *pErrorMsg, int Value, int Min, int Max)'] lines += ['int CNetObjHandler::ClampInt(const char *pErrorMsg, int Value, int Min, int Max)']
lines += ['{'] lines += ['{']
@ -183,6 +185,14 @@ if gen_network_source:
lines += ['\tif(Value > Max) { m_pObjCorrectedOn = pErrorMsg; m_NumObjCorrections++; return Max; }'] lines += ['\tif(Value > Max) { m_pObjCorrectedOn = pErrorMsg; m_NumObjCorrections++; return Max; }']
lines += ['\treturn Value;'] lines += ['\treturn Value;']
lines += ['}'] lines += ['}']
lines += ['']
lines += ['int CNetObjHandler::ClampFlag(const char *pErrorMsg, int Value, int Mask)']
lines += ['{']
lines += ['\tif((Value&Mask) != Value) { m_pObjCorrectedOn = pErrorMsg; m_NumObjCorrections++; return (Value&Mask); }']
lines += ['\treturn Value;']
lines += ['}']
lines += ['']
lines += ["const char *CNetObjHandler::ms_apObjNames[] = {"] lines += ["const char *CNetObjHandler::ms_apObjNames[] = {"]
lines += ['\t"invalid",'] lines += ['\t"invalid",']

View file

@ -320,6 +320,24 @@ class NetIntRange(NetIntAny):
def emit_unpack_check(self): def emit_unpack_check(self):
return ["if(pMsg->%s < %s || pMsg->%s > %s) { m_pMsgFailedOn = \"%s\"; break; }" % (self.name, self.min, self.name, self.max, self.name)] return ["if(pMsg->%s < %s || pMsg->%s > %s) { m_pMsgFailedOn = \"%s\"; break; }" % (self.name, self.min, self.name, self.max, self.name)]
class NetEnum(NetIntRange):
def __init__(self, name, enum):
NetIntRange.__init__(self, name, 0, len(enum.values))
class NetFlag(NetIntAny):
def __init__(self, name, flag):
NetIntAny.__init__(self, name)
if len(flag.values) > 0:
self.mask = "%s_%s" % (flag.name, flag.values[0])
for i in flag.values[1:]:
self.mask += "|%s_%s" % (flag.name, i)
else:
self.mask = "0"
def emit_validate(self):
return ["ClampFlag(\"%s\", pObj->%s, %s);"%(self.name, self.name, self.mask)]
def emit_unpack_check(self):
return ["if(pMsg->%s & (%s) != pMsg->%s) { m_pMsgFailedOn = \"%s\"; break; }" % (self.name, self.mask, self.name, self.name)]
class NetBool(NetIntRange): class NetBool(NetIntRange):
def __init__(self, name): def __init__(self, name):
NetIntRange.__init__(self,name,0,1) NetIntRange.__init__(self,name,0,1)

View file

@ -1,13 +1,12 @@
from datatypes import * from datatypes import *
Emotes = ["NORMAL", "PAIN", "HAPPY", "SURPRISE", "ANGRY", "BLINK"] Pickups = Enum("PICKUP", ["HEALTH", "ARMOR", "GRENADE", "SHOTGUN", "LASER", "NINJA"])
PlayerFlags = ["CHATTING", "SCOREBOARD", "READY", "DEAD", "WATCHING"] Emotes = Enum("EMOTE", ["NORMAL", "PAIN", "HAPPY", "SURPRISE", "ANGRY", "BLINK"])
GameFlags = ["TEAMS", "FLAGS", "SURVIVAL"] Emoticons = Enum("EMOTICON", ["OOP", "EXCLAMATION", "HEARTS", "DROP", "DOTDOT", "MUSIC", "SORRY", "GHOST", "SUSHI", "SPLATTEE", "DEVILTEE", "ZOMG", "ZZZ", "WTF", "EYES", "QUESTION"])
GameStateFlags = ["WARMUP", "SUDDENDEATH", "ROUNDOVER", "GAMEOVER", "PAUSED", "STARTCOUNTDOWN"]
Emoticons = ["OOP", "EXCLAMATION", "HEARTS", "DROP", "DOTDOT", "MUSIC", "SORRY", "GHOST", "SUSHI", "SPLATTEE", "DEVILTEE", "ZOMG", "ZZZ", "WTF", "EYES", "QUESTION"] PlayerFlags = Flags("PLAYERFLAG", ["CHATTING", "SCOREBOARD", "READY", "DEAD", "WATCHING"])
GameFlags = Flags("GAMEFLAG", ["TEAMS", "FLAGS", "SURVIVAL"])
Pickups = ["HEALTH", "ARMOR", "GRENADE", "SHOTGUN", "LASER", "NINJA"] GameStateFlags = Flags("GAMESTATEFLAG", ["WARMUP", "SUDDENDEATH", "ROUNDOVER", "GAMEOVER", "PAUSED", "STARTCOUNTDOWN"])
RawHeader = ''' RawHeader = '''
@ -39,31 +38,31 @@ RawSource = '''
''' '''
Enums = [ Enums = [
Enum("EMOTE", Emotes), Pickups,
Enum("PICKUP", Pickups), Emotes,
Enum("EMOTICON", Emoticons) Emoticons
] ]
Flags = [ Flags = [
Flags("PLAYERFLAG", PlayerFlags), PlayerFlags,
Flags("GAMEFLAG", GameFlags), GameFlags,
Flags("GAMESTATEFLAG", GameStateFlags) GameStateFlags
] ]
Objects = [ Objects = [
NetObject("PlayerInput", [ NetObject("PlayerInput", [
NetIntAny("m_Direction"), NetIntRange("m_Direction", -1, 1),
NetIntAny("m_TargetX"), NetIntAny("m_TargetX"),
NetIntAny("m_TargetY"), NetIntAny("m_TargetY"),
NetIntAny("m_Jump"), NetBool("m_Jump"),
NetIntAny("m_Fire"), NetIntAny("m_Fire"),
NetIntAny("m_Hook"), NetBool("m_Hook"),
NetIntRange("m_PlayerFlags", 0, 256), NetFlag("m_PlayerFlags", PlayerFlags),
NetIntAny("m_WantedWeapon"), NetIntRange("m_WantedWeapon", 0, 'NUM_WEAPONS-1'),
NetIntAny("m_NextWeapon"), NetIntAny("m_NextWeapon"),
NetIntAny("m_PrevWeapon"), NetIntAny("m_PrevWeapon"),
]), ]),
@ -91,7 +90,7 @@ Objects = [
NetIntAny("m_X"), NetIntAny("m_X"),
NetIntAny("m_Y"), NetIntAny("m_Y"),
NetIntRange("m_Type", 0, 'max_int'), NetEnum("m_Type", Pickups),
]), ]),
NetObject("Flag", [ NetObject("Flag", [
@ -103,7 +102,7 @@ Objects = [
NetObject("GameData", [ NetObject("GameData", [
NetTick("m_GameStartTick"), NetTick("m_GameStartTick"),
NetIntRange("m_GameStateFlags", 0, 256), NetFlag("m_GameStateFlags", GameStateFlags),
NetIntRange("m_GameStateTimer", 0, 'max_int'), NetIntRange("m_GameStateTimer", 0, 'max_int'),
]), ]),
@ -120,7 +119,7 @@ Objects = [
]), ]),
NetObject("CharacterCore", [ NetObject("CharacterCore", [
NetIntAny("m_Tick"), NetTick("m_Tick"),
NetIntAny("m_X"), NetIntAny("m_X"),
NetIntAny("m_Y"), NetIntAny("m_Y"),
NetIntAny("m_VelX"), NetIntAny("m_VelX"),
@ -145,12 +144,12 @@ Objects = [
NetIntRange("m_Armor", 0, 10), NetIntRange("m_Armor", 0, 10),
NetIntAny("m_AmmoCount"), NetIntAny("m_AmmoCount"),
NetIntRange("m_Weapon", 0, 'NUM_WEAPONS-1'), NetIntRange("m_Weapon", 0, 'NUM_WEAPONS-1'),
NetIntRange("m_Emote", 0, len(Emotes)), NetEnum("m_Emote", Emotes),
NetIntRange("m_AttackTick", 0, 'max_int'), NetTick("m_AttackTick"),
]), ]),
NetObject("PlayerInfo", [ NetObject("PlayerInfo", [
NetIntRange("m_PlayerFlags", 0, 256), NetFlag("m_PlayerFlags", PlayerFlags),
NetIntAny("m_Score"), NetIntAny("m_Score"),
NetIntAny("m_Latency"), NetIntAny("m_Latency"),
]), ]),
@ -164,7 +163,7 @@ Objects = [
## Demo ## Demo
NetObject("De_ClientInfo", [ NetObject("De_ClientInfo", [
NetIntRange("m_Local", 0, 1), NetBool("m_Local"),
NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'), NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'),
NetArray(NetIntAny("m_aName"), 4), NetArray(NetIntAny("m_aName"), 4),
@ -173,12 +172,12 @@ Objects = [
NetIntAny("m_Country"), NetIntAny("m_Country"),
NetArray(NetArray(NetIntAny("m_aaSkinPartNames"), 6), 6), NetArray(NetArray(NetIntAny("m_aaSkinPartNames"), 6), 6),
NetArray(NetIntRange("m_aUseCustomColors", 0, 1), 6), NetArray(NetBool("m_aUseCustomColors"), 6),
NetArray(NetIntAny("m_aSkinPartColors"), 6), NetArray(NetIntAny("m_aSkinPartColors"), 6),
]), ]),
NetObject("De_GameInfo", [ NetObject("De_GameInfo", [
NetIntRange("m_GameFlags", 0, 256), NetFlag("m_GameFlags", GameFlags),
NetIntRange("m_ScoreLimit", 0, 'max_int'), NetIntRange("m_ScoreLimit", 0, 'max_int'),
NetIntRange("m_TimeLimit", 0, 'max_int'), NetIntRange("m_TimeLimit", 0, 'max_int'),
@ -237,7 +236,7 @@ Messages = [
NetMessage("Sv_Team", [ NetMessage("Sv_Team", [
NetIntRange("m_ClientID", -1, 'MAX_CLIENTS-1'), NetIntRange("m_ClientID", -1, 'MAX_CLIENTS-1'),
NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'), NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'),
NetIntRange("m_Silent", 0, 1), NetBool("m_Silent"),
]), ]),
NetMessage("Sv_KillMsg", [ NetMessage("Sv_KillMsg", [
@ -261,7 +260,7 @@ Messages = [
NetMessage("Sv_Emoticon", [ NetMessage("Sv_Emoticon", [
NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'), NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'),
NetIntRange("m_Emoticon", 0, 'NUM_EMOTICONS-1'), NetEnum("m_Emoticon", Emoticons),
]), ]),
NetMessage("Sv_VoteClearOptions", [ NetMessage("Sv_VoteClearOptions", [
@ -299,7 +298,7 @@ Messages = [
NetMessage("Sv_ClientInfo", [ NetMessage("Sv_ClientInfo", [
NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'), NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'),
NetIntRange("m_Local", 0, 1), NetBool("m_Local"),
NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'), NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'),
NetStringStrict("m_pName"), NetStringStrict("m_pName"),
NetStringStrict("m_pClan"), NetStringStrict("m_pClan"),
@ -310,7 +309,7 @@ Messages = [
]), ]),
NetMessage("Sv_GameInfo", [ NetMessage("Sv_GameInfo", [
NetIntRange("m_GameFlags", 0, 256), NetFlag("m_GameFlags", GameFlags),
NetIntRange("m_ScoreLimit", 0, 'max_int'), NetIntRange("m_ScoreLimit", 0, 'max_int'),
NetIntRange("m_TimeLimit", 0, 'max_int'), NetIntRange("m_TimeLimit", 0, 'max_int'),
@ -356,7 +355,7 @@ Messages = [
NetMessage("Cl_ReadyChange", []), NetMessage("Cl_ReadyChange", []),
NetMessage("Cl_Emoticon", [ NetMessage("Cl_Emoticon", [
NetIntRange("m_Emoticon", 0, 'NUM_EMOTICONS-1'), NetEnum("m_Emoticon", Emoticons),
]), ]),
NetMessage("Cl_Vote", [ NetMessage("Cl_Vote", [

View file

@ -160,8 +160,8 @@ int CControls::SnapInput(int *pData)
float t = Client()->LocalTime(); float t = Client()->LocalTime();
mem_zero(&m_InputData, sizeof(m_InputData)); mem_zero(&m_InputData, sizeof(m_InputData));
m_InputData.m_Direction = ((int)t/2)&1; m_InputData.m_Direction = ((int)t/2)%3-1;
m_InputData.m_Jump = ((int)t); m_InputData.m_Jump = ((int)t)&1;
m_InputData.m_Fire = ((int)(t*10)); m_InputData.m_Fire = ((int)(t*10));
m_InputData.m_Hook = ((int)(t*2))&1; m_InputData.m_Hook = ((int)(t*2))&1;
m_InputData.m_WantedWeapon = ((int)t)%NUM_WEAPONS; m_InputData.m_WantedWeapon = ((int)t)%NUM_WEAPONS;