Address Learath2's comments

This commit is contained in:
heinrich5991 2019-06-14 00:24:50 +02:00
parent 62846821da
commit ca03ab6337
6 changed files with 57 additions and 32 deletions

View file

@ -198,7 +198,7 @@ class Flags:
self.values = values
class NetObject:
def __init__(self, name, variables, ex=None):
def __init__(self, name, variables, ex=None, validate_size=True):
l = name.split(":")
self.name = l[0]
self.base = ""
@ -209,6 +209,7 @@ class NetObject:
self.enum_name = "NETOBJTYPE_%s" % self.name.upper()
self.variables = variables
self.ex = ex
self.validate_size = validate_size
def emit_declaration(self):
if self.base:
lines = ["struct %s : public %s"%(self.struct_name,self.base_struct_name), "{"]
@ -221,10 +222,14 @@ class NetObject:
def emit_validate(self):
lines = ["case %s:" % self.enum_name]
lines += ["{"]
lines += ["\t%s *pObj = (%s *)pData;"%(self.struct_name, self.struct_name)]
lines += ["\tif((int)sizeof(*pObj) > Size) return -1;"]
if self.validate_size:
lines += ["\t%s *pObj = (%s *)pData;"%(self.struct_name, self.struct_name)]
lines += ["\tif((int)sizeof(*pObj) > Size) return -1;"]
prev_len = len(lines)
for v in self.variables:
lines += ["\t"+line for line in v.emit_validate()]
if not self.validate_size and prev_len != len(lines):
raise ValueError("Can't use members that need validation in a struct whose size isn't validated")
lines += ["\treturn 0;"]
lines += ["}"]
return lines
@ -273,8 +278,8 @@ class NetMessage(NetObject):
return lines
class NetObjectEx(NetObject):
def __init__(self, name, ex, variables):
NetObject.__init__(self, name, variables, ex=ex)
def __init__(self, name, ex, variables, validate_size=True):
NetObject.__init__(self, name, variables, ex=ex, validate_size=validate_size)
class NetEventEx(NetEvent):
def __init__(self, name, ex, variables):

View file

@ -5,10 +5,20 @@ PlayerFlags = ["PLAYING", "IN_MENU", "CHATTING", "SCOREBOARD", "AIM"]
GameFlags = ["TEAMS", "FLAGS"]
GameStateFlags = ["GAMEOVER", "SUDDENDEATH", "PAUSED", "RACETIME"]
CharacterFlags = ["SOLO", "JETPACK", "NO_COLLISION", "ENDLESS_HOOK", "ENDLESS_JUMP", "SUPER",
"NO_HAMMER_HIT", "NO_SHOTGUN_HIT", "NO_GRENADE_HIT", "NO_RIFLE_HIT", "NO_HOOK",
"TELEGUN_GUN", "TELEGUN_GRENADE", "TELEGUN_LASER",
"WEAPON_HAMMER", "WEAPON_GUN", "WEAPON_SHOTGUN", "WEAPON_GRENADE", "WEAPON_LASER", "WEAPON_NINJA"]
GameInfoFlags = ["TIMESCORE", "GAMETYPE_RACE", "GAMETYPE_FASTCAP", "GAMETYPE_FNG", "GAMETYPE_DDRACE", "GAMETYPE_DDNET", "GAMETYPE_BLOCK_WORLDS", "GAMETYPE_VANILLA", "GAMETYPE_PLUS", "FLAG_STARTS_RACE", "RACE", "UNLIMITED_AMMO", "DDRACE_RECORD_MESSAGE", "RACE_RECORD_MESSAGE", "ALLOW_EYE_WHEEL", "ALLOW_HOOK_COLL", "ALLOW_ZOOM", "BUG_DDRACE_GHOST", "BUG_DDRACE_INPUT", "BUG_FNG_LASER_RANGE", "BUG_VANILLA_BOUNCE", "PREDICT_FNG", "PREDICT_DDRACE", "PREDICT_DDRACE_TILES", "PREDICT_VANILLA", "ENTITIES_DDNET", "ENTITIES_DDRACE", "ENTITIES_RACE", "ENTITIES_FNG", "ENTITIES_VANILLA"]
"NO_HAMMER_HIT", "NO_SHOTGUN_HIT", "NO_GRENADE_HIT", "NO_RIFLE_HIT", "NO_HOOK",
"TELEGUN_GUN", "TELEGUN_GRENADE", "TELEGUN_LASER",
"WEAPON_HAMMER", "WEAPON_GUN", "WEAPON_SHOTGUN", "WEAPON_GRENADE", "WEAPON_LASER", "WEAPON_NINJA"]
GameInfoFlags = [
"TIMESCORE", "GAMETYPE_RACE", "GAMETYPE_FASTCAP", "GAMETYPE_FNG",
"GAMETYPE_DDRACE", "GAMETYPE_DDNET", "GAMETYPE_BLOCK_WORLDS",
"GAMETYPE_VANILLA", "GAMETYPE_PLUS", "FLAG_STARTS_RACE", "RACE",
"UNLIMITED_AMMO", "DDRACE_RECORD_MESSAGE", "RACE_RECORD_MESSAGE",
"ALLOW_EYE_WHEEL", "ALLOW_HOOK_COLL", "ALLOW_ZOOM", "BUG_DDRACE_GHOST",
"BUG_DDRACE_INPUT", "BUG_FNG_LASER_RANGE", "BUG_VANILLA_BOUNCE",
"PREDICT_FNG", "PREDICT_DDRACE", "PREDICT_DDRACE_TILES", "PREDICT_VANILLA",
"ENTITIES_DDNET", "ENTITIES_DDRACE", "ENTITIES_RACE", "ENTITIES_FNG",
"ENTITIES_VANILLA",
]
Emoticons = ["OOP", "EXCLAMATION", "HEARTS", "DROP", "DOTDOT", "MUSIC", "SORRY", "GHOST", "SUSHI", "SPLATTEE", "DEVILTEE", "ZOMG", "ZZZ", "WTF", "EYES", "QUESTION"]
@ -224,7 +234,7 @@ Objects = [
NetObjectEx("GameInfoEx", "gameinfo@netobj.ddnet.tw", [
NetIntAny("m_Flags"),
NetIntAny("m_Version"),
]),
], validate_size=False),
## Events

View file

@ -740,7 +740,7 @@ void CClient::DisconnectWithReason(const char *pReason)
//
m_RconAuthed[0] = 0;
m_GotServerCapabilities = false;
m_CanReceiveServerCapabilities = true;
m_ServerSentCapabilities = false;
m_UseTempRconCommands = 0;
m_pConsole->DeregisterTempAll();
@ -1572,7 +1572,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
}
else if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && Msg == NETMSG_CAPABILITIES)
{
if(m_GotServerCapabilities)
if(!m_CanReceiveServerCapabilities)
{
return;
}
@ -1583,15 +1583,15 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
return;
}
m_ServerCapabilities = GetServerCapabilities(Version, Flags);
m_GotServerCapabilities = true;
m_CanReceiveServerCapabilities = false;
m_ServerSentCapabilities = true;
}
else if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && Msg == NETMSG_MAP_CHANGE)
{
if(!m_GotServerCapabilities)
if(m_CanReceiveServerCapabilities)
{
m_ServerCapabilities = GetServerCapabilities(0, 0);
m_GotServerCapabilities = true;
m_CanReceiveServerCapabilities = false;
}
bool MapDetailsWerePresent = m_MapDetailsPresent;
m_MapDetailsPresent = false;

View file

@ -197,7 +197,7 @@ class CClient : public IClient, public CDemoPlayer::IListener
std::list<std::shared_ptr<CDemoEdit>> m_EditJobs;
//
bool m_GotServerCapabilities;
bool m_CanReceiveServerCapabilities;
bool m_ServerSentCapabilities;
CServerCapabilities m_ServerCapabilities;

View file

@ -953,28 +953,39 @@ void CGameClient::ProcessEvents()
static CGameInfo GetGameInfo(const CNetObj_GameInfoEx *pInfoEx, int InfoExSize, CServerInfo *pFallbackServerInfo)
{
int Version = -1;
if(InfoExSize >= 4)
{
Version = 0;
}
else if(InfoExSize >= 8)
if(InfoExSize >= 8)
{
Version = pInfoEx->m_Version;
}
else if(InfoExSize >= 4)
{
Version = 0;
}
int Flags = 0;
if(Version >= 0)
{
Flags = pInfoEx->m_Flags;
}
bool Race = IsRace(pFallbackServerInfo);
bool FastCap = IsFastCap(pFallbackServerInfo);
bool FNG = IsFNG(pFallbackServerInfo);
bool DDRace = IsDDRace(pFallbackServerInfo);
bool DDNet = IsDDNet(pFallbackServerInfo);
bool BlockWorlds = IsBlockWorlds(pFallbackServerInfo);
bool Vanilla = IsVanilla(pFallbackServerInfo);
bool Plus = IsPlus(pFallbackServerInfo);
if(Version >= 1)
bool Race;
bool FastCap;
bool FNG;
bool DDRace;
bool DDNet;
bool BlockWorlds;
bool Vanilla;
bool Plus;
if(Version < 1)
{
Race = IsRace(pFallbackServerInfo);
FastCap = IsFastCap(pFallbackServerInfo);
FNG = IsFNG(pFallbackServerInfo);
DDRace = IsDDRace(pFallbackServerInfo);
DDNet = IsDDNet(pFallbackServerInfo);
BlockWorlds = IsBlockWorlds(pFallbackServerInfo);
Vanilla = IsVanilla(pFallbackServerInfo);
Plus = IsPlus(pFallbackServerInfo);
}
else
{
Race = Flags&GAMEINFOFLAG_GAMETYPE_RACE;
FastCap = Flags&GAMEINFOFLAG_GAMETYPE_FASTCAP;
@ -985,6 +996,7 @@ static CGameInfo GetGameInfo(const CNetObj_GameInfoEx *pInfoEx, int InfoExSize,
Vanilla = Flags&GAMEINFOFLAG_GAMETYPE_VANILLA;
Plus = Flags&GAMEINFOFLAG_GAMETYPE_PLUS;
// Ensure invariants upheld by the server info parsing business.
DDRace = DDRace || DDNet;
Race = Race || FastCap || DDRace;
}

View file

@ -224,8 +224,6 @@ public:
//const CNetObj_PlayerInfo *m_paInfoByTeam[MAX_CLIENTS];
const CNetObj_PlayerInfo *m_paInfoByDDTeam[MAX_CLIENTS];
const CNetObj_GameInfoEx *m_pGameInfoEx;
int m_LocalClientID;
int m_NumPlayers;
int m_aTeamSize[2];