mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-14 03:58:18 +00:00
Move and extend GetClientVersion
to remove many version.h
includes
The `CServer::GetClientVersion` method needs the `version.h` include, so it's moved from the header to the source file, so the include can be removed from the header. The `GetClientVersion` method is often called with the same `Client != SERVER_DEMO_CLIENT ? GetClientVersion(Client) : CLIENT_VERSIONNR` expression, which also needs the `version.h` include. This expression is moved inside the method, so the include can be removed from all the server entities' and player code. The `CGameContext::GetClientVersion` method is made a delegate to reduce duplicate code. The includes of the server entities are also organized further.
This commit is contained in:
parent
e5e26097bb
commit
9a012312b8
|
@ -14,7 +14,6 @@
|
||||||
#include <game/generated/protocol.h>
|
#include <game/generated/protocol.h>
|
||||||
#include <game/generated/protocol7.h>
|
#include <game/generated/protocol7.h>
|
||||||
#include <game/generated/protocolglue.h>
|
#include <game/generated/protocolglue.h>
|
||||||
#include <game/version.h>
|
|
||||||
|
|
||||||
struct CAntibotRoundData;
|
struct CAntibotRoundData;
|
||||||
|
|
||||||
|
@ -61,6 +60,7 @@ public:
|
||||||
virtual void SetClientDDNetVersion(int ClientID, int DDNetVersion) = 0;
|
virtual void SetClientDDNetVersion(int ClientID, int DDNetVersion) = 0;
|
||||||
virtual void GetClientAddr(int ClientID, char *pAddrStr, int Size) const = 0;
|
virtual void GetClientAddr(int ClientID, char *pAddrStr, int Size) const = 0;
|
||||||
|
|
||||||
|
virtual int GetClientVersion(int ClientID) const = 0;
|
||||||
virtual int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) = 0;
|
virtual int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) = 0;
|
||||||
|
|
||||||
template<class T, typename std::enable_if<!protocol7::is_sixup<T>::value, int>::type = 0>
|
template<class T, typename std::enable_if<!protocol7::is_sixup<T>::value, int>::type = 0>
|
||||||
|
@ -157,19 +157,11 @@ public:
|
||||||
return SendMsg(&Packer, Flags, ClientID);
|
return SendMsg(&Packer, Flags, ClientID);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetClientVersion(int ClientID) const
|
|
||||||
{
|
|
||||||
CClientInfo Info;
|
|
||||||
GetClientInfo(ClientID, &Info);
|
|
||||||
return Info.m_DDNetVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Translate(int &Target, int Client)
|
bool Translate(int &Target, int Client)
|
||||||
{
|
{
|
||||||
if(IsSixup(Client))
|
if(IsSixup(Client))
|
||||||
return true;
|
return true;
|
||||||
int ClientVersion = Client != SERVER_DEMO_CLIENT ? GetClientVersion(Client) : CLIENT_VERSIONNR;
|
if(GetClientVersion(Client) >= VERSION_DDNET_OLD)
|
||||||
if(ClientVersion >= VERSION_DDNET_OLD)
|
|
||||||
return true;
|
return true;
|
||||||
int *pMap = GetIdMap(Client);
|
int *pMap = GetIdMap(Client);
|
||||||
bool Found = false;
|
bool Found = false;
|
||||||
|
@ -189,8 +181,7 @@ public:
|
||||||
{
|
{
|
||||||
if(IsSixup(Client))
|
if(IsSixup(Client))
|
||||||
return true;
|
return true;
|
||||||
int ClientVersion = Client != SERVER_DEMO_CLIENT ? GetClientVersion(Client) : CLIENT_VERSIONNR;
|
if(GetClientVersion(Client) >= VERSION_DDNET_OLD)
|
||||||
if(ClientVersion >= VERSION_DDNET_OLD)
|
|
||||||
return true;
|
return true;
|
||||||
Target = clamp(Target, 0, VANILLA_MAX_CLIENTS - 1);
|
Target = clamp(Target, 0, VANILLA_MAX_CLIENTS - 1);
|
||||||
int *pMap = GetIdMap(Client);
|
int *pMap = GetIdMap(Client);
|
||||||
|
|
|
@ -779,6 +779,17 @@ int CServer::DistinctClientCount() const
|
||||||
return ClientCount;
|
return ClientCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CServer::GetClientVersion(int ClientID) const
|
||||||
|
{
|
||||||
|
// Assume latest client version for server demos
|
||||||
|
if(ClientID == SERVER_DEMO_CLIENT)
|
||||||
|
return CLIENT_VERSIONNR;
|
||||||
|
|
||||||
|
CClientInfo Info;
|
||||||
|
GetClientInfo(ClientID, &Info);
|
||||||
|
return Info.m_DDNetVersion;
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool RepackMsg(const CMsgPacker *pMsg, CPacker &Packer, bool Sixup)
|
static inline bool RepackMsg(const CMsgPacker *pMsg, CPacker &Packer, bool Sixup)
|
||||||
{
|
{
|
||||||
int MsgId = pMsg->m_MsgID;
|
int MsgId = pMsg->m_MsgID;
|
||||||
|
|
|
@ -313,6 +313,7 @@ public:
|
||||||
int ClientCount() const override;
|
int ClientCount() const override;
|
||||||
int DistinctClientCount() const override;
|
int DistinctClientCount() const override;
|
||||||
|
|
||||||
|
int GetClientVersion(int ClientID) const override;
|
||||||
int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) override;
|
int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) override;
|
||||||
|
|
||||||
void DoSnapshot();
|
void DoSnapshot();
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||||
#include <antibot/antibot_data.h>
|
|
||||||
|
|
||||||
#include <engine/antibot.h>
|
|
||||||
|
|
||||||
#include <engine/shared/config.h>
|
|
||||||
#include <game/generated/server_data.h>
|
|
||||||
#include <game/mapitems.h>
|
|
||||||
#include <game/server/gamecontext.h>
|
|
||||||
#include <game/server/gamecontroller.h>
|
|
||||||
#include <game/server/player.h>
|
|
||||||
|
|
||||||
#include "character.h"
|
#include "character.h"
|
||||||
#include "game/generated/protocol.h"
|
|
||||||
#include "laser.h"
|
#include "laser.h"
|
||||||
#include "projectile.h"
|
#include "projectile.h"
|
||||||
|
|
||||||
|
#include <antibot/antibot_data.h>
|
||||||
|
|
||||||
|
#include <engine/antibot.h>
|
||||||
|
#include <engine/shared/config.h>
|
||||||
|
|
||||||
|
#include <game/generated/protocol.h>
|
||||||
|
#include <game/generated/server_data.h>
|
||||||
|
#include <game/mapitems.h>
|
||||||
|
|
||||||
|
#include <game/server/gamecontext.h>
|
||||||
|
#include <game/server/gamecontroller.h>
|
||||||
|
#include <game/server/player.h>
|
||||||
#include <game/server/score.h>
|
#include <game/server/score.h>
|
||||||
#include <game/server/teams.h>
|
#include <game/server/teams.h>
|
||||||
|
|
||||||
|
@ -948,9 +948,7 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon)
|
||||||
//TODO: Move the emote stuff to a function
|
//TODO: Move the emote stuff to a function
|
||||||
void CCharacter::SnapCharacter(int SnappingClient, int ID)
|
void CCharacter::SnapCharacter(int SnappingClient, int ID)
|
||||||
{
|
{
|
||||||
int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ?
|
int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient);
|
||||||
GameServer()->GetClientVersion(SnappingClient) :
|
|
||||||
CLIENT_VERSIONNR;
|
|
||||||
CCharacterCore *pCore;
|
CCharacterCore *pCore;
|
||||||
int Tick, Emote = m_EmoteType, Weapon = m_Core.m_ActiveWeapon, AmmoCount = 0,
|
int Tick, Emote = m_EmoteType, Weapon = m_Core.m_ActiveWeapon, AmmoCount = 0,
|
||||||
Health = 0, Armor = 0;
|
Health = 0, Armor = 0;
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include <game/generated/protocol.h>
|
#include <game/generated/protocol.h>
|
||||||
#include <game/mapitems.h>
|
#include <game/mapitems.h>
|
||||||
#include <game/teamscore.h>
|
#include <game/teamscore.h>
|
||||||
#include <game/version.h>
|
|
||||||
|
|
||||||
#include <game/server/gamecontext.h>
|
#include <game/server/gamecontext.h>
|
||||||
#include <game/server/player.h>
|
#include <game/server/player.h>
|
||||||
|
@ -55,7 +54,7 @@ void CDoor::Snap(int SnappingClient)
|
||||||
pObj->m_X = (int)m_Pos.x;
|
pObj->m_X = (int)m_Pos.x;
|
||||||
pObj->m_Y = (int)m_Pos.y;
|
pObj->m_Y = (int)m_Pos.y;
|
||||||
|
|
||||||
int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ? GameServer()->GetClientVersion(SnappingClient) : CLIENT_VERSIONNR;
|
int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient);
|
||||||
|
|
||||||
CNetObj_EntityEx *pEntData = 0;
|
CNetObj_EntityEx *pEntData = 0;
|
||||||
if(SnappingClientVersion >= VERSION_DDNET_SWITCH)
|
if(SnappingClientVersion >= VERSION_DDNET_SWITCH)
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#include <game/generated/protocol.h>
|
#include <game/generated/protocol.h>
|
||||||
#include <game/mapitems.h>
|
#include <game/mapitems.h>
|
||||||
#include <game/version.h>
|
|
||||||
|
|
||||||
#include <game/server/gamecontext.h>
|
#include <game/server/gamecontext.h>
|
||||||
#include <game/server/player.h>
|
#include <game/server/player.h>
|
||||||
|
@ -185,9 +184,7 @@ void CDragger::Snap(int SnappingClient)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ?
|
int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient);
|
||||||
GameServer()->GetClientVersion(SnappingClient) :
|
|
||||||
CLIENT_VERSIONNR;
|
|
||||||
|
|
||||||
CNetObj_EntityEx *pEntData = 0;
|
CNetObj_EntityEx *pEntData = 0;
|
||||||
if(SnappingClientVersion >= VERSION_DDNET_SWITCH)
|
if(SnappingClientVersion >= VERSION_DDNET_SWITCH)
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#include <game/generated/protocol.h>
|
#include <game/generated/protocol.h>
|
||||||
#include <game/mapitems.h>
|
#include <game/mapitems.h>
|
||||||
#include <game/version.h>
|
|
||||||
|
|
||||||
#include <game/server/gamecontext.h>
|
#include <game/server/gamecontext.h>
|
||||||
#include <game/server/player.h>
|
#include <game/server/player.h>
|
||||||
|
@ -148,9 +147,7 @@ void CGun::Snap(int SnappingClient)
|
||||||
if(NetworkClipped(SnappingClient))
|
if(NetworkClipped(SnappingClient))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ?
|
int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient);
|
||||||
GameServer()->GetClientVersion(SnappingClient) :
|
|
||||||
CLIENT_VERSIONNR;
|
|
||||||
|
|
||||||
CNetObj_EntityEx *pEntData = 0;
|
CNetObj_EntityEx *pEntData = 0;
|
||||||
if(SnappingClientVersion >= VERSION_DDNET_SWITCH)
|
if(SnappingClientVersion >= VERSION_DDNET_SWITCH)
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include <game/generated/protocol.h>
|
#include <game/generated/protocol.h>
|
||||||
#include <game/mapitems.h>
|
#include <game/mapitems.h>
|
||||||
#include <game/teamscore.h>
|
#include <game/teamscore.h>
|
||||||
#include <game/version.h>
|
|
||||||
|
|
||||||
#include <game/server/gamecontext.h>
|
#include <game/server/gamecontext.h>
|
||||||
#include <game/server/player.h>
|
#include <game/server/player.h>
|
||||||
|
@ -106,7 +105,7 @@ void CLight::Snap(int SnappingClient)
|
||||||
if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient, m_To))
|
if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient, m_To))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ? GameServer()->GetClientVersion(SnappingClient) : CLIENT_VERSIONNR;
|
int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient);
|
||||||
|
|
||||||
CNetObj_EntityEx *pEntData = 0;
|
CNetObj_EntityEx *pEntData = 0;
|
||||||
if(SnappingClientVersion >= VERSION_DDNET_SWITCH && (m_Layer == LAYER_SWITCH || length(m_Core) > 0))
|
if(SnappingClientVersion >= VERSION_DDNET_SWITCH && (m_Layer == LAYER_SWITCH || length(m_Core) > 0))
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include <game/generated/protocol.h>
|
#include <game/generated/protocol.h>
|
||||||
#include <game/mapitems.h>
|
#include <game/mapitems.h>
|
||||||
#include <game/teamscore.h>
|
#include <game/teamscore.h>
|
||||||
#include <game/version.h>
|
|
||||||
|
|
||||||
#include <game/server/gamecontext.h>
|
#include <game/server/gamecontext.h>
|
||||||
#include <game/server/player.h>
|
#include <game/server/player.h>
|
||||||
|
@ -174,7 +173,7 @@ void CPickup::Snap(int SnappingClient)
|
||||||
if(SnappingClient != SERVER_DEMO_CLIENT && (GameServer()->m_apPlayers[SnappingClient]->GetTeam() == TEAM_SPECTATORS || GameServer()->m_apPlayers[SnappingClient]->IsPaused()) && GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID != SPEC_FREEVIEW)
|
if(SnappingClient != SERVER_DEMO_CLIENT && (GameServer()->m_apPlayers[SnappingClient]->GetTeam() == TEAM_SPECTATORS || GameServer()->m_apPlayers[SnappingClient]->IsPaused()) && GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID != SPEC_FREEVIEW)
|
||||||
pChar = GameServer()->GetPlayerChar(GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID);
|
pChar = GameServer()->GetPlayerChar(GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID);
|
||||||
|
|
||||||
int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ? GameServer()->GetClientVersion(SnappingClient) : CLIENT_VERSIONNR;
|
int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient);
|
||||||
|
|
||||||
CNetObj_EntityEx *pEntData = 0;
|
CNetObj_EntityEx *pEntData = 0;
|
||||||
if(SnappingClientVersion >= VERSION_DDNET_SWITCH && (m_Layer == LAYER_SWITCH || length(m_Core) > 0))
|
if(SnappingClientVersion >= VERSION_DDNET_SWITCH && (m_Layer == LAYER_SWITCH || length(m_Core) > 0))
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
#include <game/generated/protocol.h>
|
#include <game/generated/protocol.h>
|
||||||
#include <game/mapitems.h>
|
#include <game/mapitems.h>
|
||||||
#include <game/version.h>
|
|
||||||
|
|
||||||
#include <game/server/gamecontext.h>
|
#include <game/server/gamecontext.h>
|
||||||
#include <game/server/gamemodes/DDRace.h>
|
#include <game/server/gamemodes/DDRace.h>
|
||||||
|
@ -317,7 +316,7 @@ void CProjectile::Snap(int SnappingClient)
|
||||||
pEntData->m_EntityClass = ENTITYCLASS_PROJECTILE;
|
pEntData->m_EntityClass = ENTITYCLASS_PROJECTILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ? GameServer()->GetClientVersion(SnappingClient) : CLIENT_VERSIONNR;
|
int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient);
|
||||||
if(SnappingClientVersion < VERSION_DDNET_SWITCH)
|
if(SnappingClientVersion < VERSION_DDNET_SWITCH)
|
||||||
{
|
{
|
||||||
CCharacter *pSnapChar = GameServer()->GetPlayerChar(SnappingClient);
|
CCharacter *pSnapChar = GameServer()->GetPlayerChar(SnappingClient);
|
||||||
|
|
|
@ -4119,9 +4119,7 @@ void CGameContext::List(int ClientID, const char *pFilter)
|
||||||
|
|
||||||
int CGameContext::GetClientVersion(int ClientID) const
|
int CGameContext::GetClientVersion(int ClientID) const
|
||||||
{
|
{
|
||||||
IServer::CClientInfo Info = {0};
|
return Server()->GetClientVersion(ClientID);
|
||||||
Server()->GetClientInfo(ClientID, &Info);
|
|
||||||
return Info.m_DDNetVersion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t CGameContext::ClientsMaskExcludeClientVersionAndHigher(int Version)
|
int64_t CGameContext::ClientsMaskExcludeClientVersionAndHigher(int Version)
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include <engine/shared/config.h>
|
|
||||||
|
|
||||||
#include <engine/antibot.h>
|
|
||||||
#include <engine/server.h>
|
|
||||||
|
|
||||||
#include "base/system.h"
|
|
||||||
#include "entities/character.h"
|
#include "entities/character.h"
|
||||||
#include "gamecontext.h"
|
#include "gamecontext.h"
|
||||||
#include "gamecontroller.h"
|
#include "gamecontroller.h"
|
||||||
#include "score.h"
|
#include "score.h"
|
||||||
|
|
||||||
|
#include <base/system.h>
|
||||||
|
|
||||||
|
#include <engine/antibot.h>
|
||||||
|
#include <engine/server.h>
|
||||||
|
#include <engine/shared/config.h>
|
||||||
|
|
||||||
#include <game/gamecore.h>
|
#include <game/gamecore.h>
|
||||||
#include <game/teamscore.h>
|
#include <game/teamscore.h>
|
||||||
#include <game/version.h>
|
|
||||||
|
|
||||||
MACRO_ALLOC_POOL_ID_IMPL(CPlayer, MAX_CLIENTS)
|
MACRO_ALLOC_POOL_ID_IMPL(CPlayer, MAX_CLIENTS)
|
||||||
|
|
||||||
|
@ -336,7 +335,7 @@ void CPlayer::Snap(int SnappingClient)
|
||||||
pClientInfo->m_ColorBody = m_TeeInfos.m_ColorBody;
|
pClientInfo->m_ColorBody = m_TeeInfos.m_ColorBody;
|
||||||
pClientInfo->m_ColorFeet = m_TeeInfos.m_ColorFeet;
|
pClientInfo->m_ColorFeet = m_TeeInfos.m_ColorFeet;
|
||||||
|
|
||||||
int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ? GameServer()->GetClientVersion(SnappingClient) : CLIENT_VERSIONNR;
|
int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient);
|
||||||
int Latency = SnappingClient == SERVER_DEMO_CLIENT ? m_Latency.m_Min : GameServer()->m_apPlayers[SnappingClient]->m_aCurLatency[m_ClientID];
|
int Latency = SnappingClient == SERVER_DEMO_CLIENT ? m_Latency.m_Min : GameServer()->m_apPlayers[SnappingClient]->m_aCurLatency[m_ClientID];
|
||||||
int Score = abs(m_Score) * -1;
|
int Score = abs(m_Score) * -1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue