mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
cleaned up types within network data
This commit is contained in:
parent
719867271f
commit
a55a7dfef0
|
@ -127,6 +127,7 @@ class CNetObjHandler
|
|||
char m_aMsgData[1024];
|
||||
int m_NumObjCorrections;
|
||||
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 int ms_aObjSizes[];
|
||||
|
@ -176,6 +177,7 @@ if gen_network_source:
|
|||
lines += ['']
|
||||
|
||||
lines += ['static const int max_int = 0x7fffffff;']
|
||||
lines += ['']
|
||||
|
||||
lines += ['int CNetObjHandler::ClampInt(const char *pErrorMsg, int Value, int Min, int Max)']
|
||||
lines += ['{']
|
||||
|
@ -183,6 +185,14 @@ if gen_network_source:
|
|||
lines += ['\tif(Value > Max) { m_pObjCorrectedOn = pErrorMsg; m_NumObjCorrections++; return Max; }']
|
||||
lines += ['\treturn Value;']
|
||||
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 += ['\t"invalid",']
|
||||
|
|
|
@ -320,6 +320,24 @@ class NetIntRange(NetIntAny):
|
|||
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)]
|
||||
|
||||
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):
|
||||
def __init__(self, name):
|
||||
NetIntRange.__init__(self,name,0,1)
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
from datatypes import *
|
||||
|
||||
Emotes = ["NORMAL", "PAIN", "HAPPY", "SURPRISE", "ANGRY", "BLINK"]
|
||||
PlayerFlags = ["CHATTING", "SCOREBOARD", "READY", "DEAD", "WATCHING"]
|
||||
GameFlags = ["TEAMS", "FLAGS", "SURVIVAL"]
|
||||
GameStateFlags = ["WARMUP", "SUDDENDEATH", "ROUNDOVER", "GAMEOVER", "PAUSED", "STARTCOUNTDOWN"]
|
||||
Pickups = Enum("PICKUP", ["HEALTH", "ARMOR", "GRENADE", "SHOTGUN", "LASER", "NINJA"])
|
||||
Emotes = Enum("EMOTE", ["NORMAL", "PAIN", "HAPPY", "SURPRISE", "ANGRY", "BLINK"])
|
||||
Emoticons = Enum("EMOTICON", ["OOP", "EXCLAMATION", "HEARTS", "DROP", "DOTDOT", "MUSIC", "SORRY", "GHOST", "SUSHI", "SPLATTEE", "DEVILTEE", "ZOMG", "ZZZ", "WTF", "EYES", "QUESTION"])
|
||||
|
||||
Emoticons = ["OOP", "EXCLAMATION", "HEARTS", "DROP", "DOTDOT", "MUSIC", "SORRY", "GHOST", "SUSHI", "SPLATTEE", "DEVILTEE", "ZOMG", "ZZZ", "WTF", "EYES", "QUESTION"]
|
||||
|
||||
Pickups = ["HEALTH", "ARMOR", "GRENADE", "SHOTGUN", "LASER", "NINJA"]
|
||||
PlayerFlags = Flags("PLAYERFLAG", ["CHATTING", "SCOREBOARD", "READY", "DEAD", "WATCHING"])
|
||||
GameFlags = Flags("GAMEFLAG", ["TEAMS", "FLAGS", "SURVIVAL"])
|
||||
GameStateFlags = Flags("GAMESTATEFLAG", ["WARMUP", "SUDDENDEATH", "ROUNDOVER", "GAMEOVER", "PAUSED", "STARTCOUNTDOWN"])
|
||||
|
||||
RawHeader = '''
|
||||
|
||||
|
@ -39,31 +38,31 @@ RawSource = '''
|
|||
'''
|
||||
|
||||
Enums = [
|
||||
Enum("EMOTE", Emotes),
|
||||
Enum("PICKUP", Pickups),
|
||||
Enum("EMOTICON", Emoticons)
|
||||
Pickups,
|
||||
Emotes,
|
||||
Emoticons
|
||||
]
|
||||
|
||||
Flags = [
|
||||
Flags("PLAYERFLAG", PlayerFlags),
|
||||
Flags("GAMEFLAG", GameFlags),
|
||||
Flags("GAMESTATEFLAG", GameStateFlags)
|
||||
PlayerFlags,
|
||||
GameFlags,
|
||||
GameStateFlags
|
||||
]
|
||||
|
||||
Objects = [
|
||||
|
||||
NetObject("PlayerInput", [
|
||||
NetIntAny("m_Direction"),
|
||||
NetIntRange("m_Direction", -1, 1),
|
||||
NetIntAny("m_TargetX"),
|
||||
NetIntAny("m_TargetY"),
|
||||
|
||||
NetIntAny("m_Jump"),
|
||||
NetBool("m_Jump"),
|
||||
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_PrevWeapon"),
|
||||
]),
|
||||
|
@ -91,7 +90,7 @@ Objects = [
|
|||
NetIntAny("m_X"),
|
||||
NetIntAny("m_Y"),
|
||||
|
||||
NetIntRange("m_Type", 0, 'max_int'),
|
||||
NetEnum("m_Type", Pickups),
|
||||
]),
|
||||
|
||||
NetObject("Flag", [
|
||||
|
@ -103,7 +102,7 @@ Objects = [
|
|||
|
||||
NetObject("GameData", [
|
||||
NetTick("m_GameStartTick"),
|
||||
NetIntRange("m_GameStateFlags", 0, 256),
|
||||
NetFlag("m_GameStateFlags", GameStateFlags),
|
||||
NetIntRange("m_GameStateTimer", 0, 'max_int'),
|
||||
]),
|
||||
|
||||
|
@ -120,7 +119,7 @@ Objects = [
|
|||
]),
|
||||
|
||||
NetObject("CharacterCore", [
|
||||
NetIntAny("m_Tick"),
|
||||
NetTick("m_Tick"),
|
||||
NetIntAny("m_X"),
|
||||
NetIntAny("m_Y"),
|
||||
NetIntAny("m_VelX"),
|
||||
|
@ -145,12 +144,12 @@ Objects = [
|
|||
NetIntRange("m_Armor", 0, 10),
|
||||
NetIntAny("m_AmmoCount"),
|
||||
NetIntRange("m_Weapon", 0, 'NUM_WEAPONS-1'),
|
||||
NetIntRange("m_Emote", 0, len(Emotes)),
|
||||
NetIntRange("m_AttackTick", 0, 'max_int'),
|
||||
NetEnum("m_Emote", Emotes),
|
||||
NetTick("m_AttackTick"),
|
||||
]),
|
||||
|
||||
NetObject("PlayerInfo", [
|
||||
NetIntRange("m_PlayerFlags", 0, 256),
|
||||
NetFlag("m_PlayerFlags", PlayerFlags),
|
||||
NetIntAny("m_Score"),
|
||||
NetIntAny("m_Latency"),
|
||||
]),
|
||||
|
@ -164,7 +163,7 @@ Objects = [
|
|||
## Demo
|
||||
|
||||
NetObject("De_ClientInfo", [
|
||||
NetIntRange("m_Local", 0, 1),
|
||||
NetBool("m_Local"),
|
||||
NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'),
|
||||
|
||||
NetArray(NetIntAny("m_aName"), 4),
|
||||
|
@ -173,12 +172,12 @@ Objects = [
|
|||
NetIntAny("m_Country"),
|
||||
|
||||
NetArray(NetArray(NetIntAny("m_aaSkinPartNames"), 6), 6),
|
||||
NetArray(NetIntRange("m_aUseCustomColors", 0, 1), 6),
|
||||
NetArray(NetBool("m_aUseCustomColors"), 6),
|
||||
NetArray(NetIntAny("m_aSkinPartColors"), 6),
|
||||
]),
|
||||
|
||||
NetObject("De_GameInfo", [
|
||||
NetIntRange("m_GameFlags", 0, 256),
|
||||
NetFlag("m_GameFlags", GameFlags),
|
||||
|
||||
NetIntRange("m_ScoreLimit", 0, 'max_int'),
|
||||
NetIntRange("m_TimeLimit", 0, 'max_int'),
|
||||
|
@ -237,7 +236,7 @@ Messages = [
|
|||
NetMessage("Sv_Team", [
|
||||
NetIntRange("m_ClientID", -1, 'MAX_CLIENTS-1'),
|
||||
NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'),
|
||||
NetIntRange("m_Silent", 0, 1),
|
||||
NetBool("m_Silent"),
|
||||
]),
|
||||
|
||||
NetMessage("Sv_KillMsg", [
|
||||
|
@ -261,7 +260,7 @@ Messages = [
|
|||
|
||||
NetMessage("Sv_Emoticon", [
|
||||
NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'),
|
||||
NetIntRange("m_Emoticon", 0, 'NUM_EMOTICONS-1'),
|
||||
NetEnum("m_Emoticon", Emoticons),
|
||||
]),
|
||||
|
||||
NetMessage("Sv_VoteClearOptions", [
|
||||
|
@ -299,7 +298,7 @@ Messages = [
|
|||
|
||||
NetMessage("Sv_ClientInfo", [
|
||||
NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'),
|
||||
NetIntRange("m_Local", 0, 1),
|
||||
NetBool("m_Local"),
|
||||
NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'),
|
||||
NetStringStrict("m_pName"),
|
||||
NetStringStrict("m_pClan"),
|
||||
|
@ -310,7 +309,7 @@ Messages = [
|
|||
]),
|
||||
|
||||
NetMessage("Sv_GameInfo", [
|
||||
NetIntRange("m_GameFlags", 0, 256),
|
||||
NetFlag("m_GameFlags", GameFlags),
|
||||
|
||||
NetIntRange("m_ScoreLimit", 0, 'max_int'),
|
||||
NetIntRange("m_TimeLimit", 0, 'max_int'),
|
||||
|
@ -356,7 +355,7 @@ Messages = [
|
|||
NetMessage("Cl_ReadyChange", []),
|
||||
|
||||
NetMessage("Cl_Emoticon", [
|
||||
NetIntRange("m_Emoticon", 0, 'NUM_EMOTICONS-1'),
|
||||
NetEnum("m_Emoticon", Emoticons),
|
||||
]),
|
||||
|
||||
NetMessage("Cl_Vote", [
|
||||
|
|
|
@ -160,8 +160,8 @@ int CControls::SnapInput(int *pData)
|
|||
float t = Client()->LocalTime();
|
||||
mem_zero(&m_InputData, sizeof(m_InputData));
|
||||
|
||||
m_InputData.m_Direction = ((int)t/2)&1;
|
||||
m_InputData.m_Jump = ((int)t);
|
||||
m_InputData.m_Direction = ((int)t/2)%3-1;
|
||||
m_InputData.m_Jump = ((int)t)&1;
|
||||
m_InputData.m_Fire = ((int)(t*10));
|
||||
m_InputData.m_Hook = ((int)(t*2))&1;
|
||||
m_InputData.m_WantedWeapon = ((int)t)%NUM_WEAPONS;
|
||||
|
|
Loading…
Reference in a new issue