diff --git a/src/engine/server.h b/src/engine/server.h index e20b6d3b5..fa823079f 100644 --- a/src/engine/server.h +++ b/src/engine/server.h @@ -14,7 +14,6 @@ #include #include #include -#include struct CAntibotRoundData; @@ -61,6 +60,7 @@ public: virtual void SetClientDDNetVersion(int ClientID, int DDNetVersion) = 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; template::value, int>::type = 0> @@ -157,19 +157,11 @@ public: 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) { if(IsSixup(Client)) return true; - int ClientVersion = Client != SERVER_DEMO_CLIENT ? GetClientVersion(Client) : CLIENT_VERSIONNR; - if(ClientVersion >= VERSION_DDNET_OLD) + if(GetClientVersion(Client) >= VERSION_DDNET_OLD) return true; int *pMap = GetIdMap(Client); bool Found = false; @@ -189,8 +181,7 @@ public: { if(IsSixup(Client)) return true; - int ClientVersion = Client != SERVER_DEMO_CLIENT ? GetClientVersion(Client) : CLIENT_VERSIONNR; - if(ClientVersion >= VERSION_DDNET_OLD) + if(GetClientVersion(Client) >= VERSION_DDNET_OLD) return true; Target = clamp(Target, 0, VANILLA_MAX_CLIENTS - 1); int *pMap = GetIdMap(Client); diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 8d40ae657..596670ae5 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -779,6 +779,17 @@ int CServer::DistinctClientCount() const 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) { int MsgId = pMsg->m_MsgID; diff --git a/src/engine/server/server.h b/src/engine/server/server.h index 55949b956..e6f972747 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -313,6 +313,7 @@ public: int ClientCount() const override; int DistinctClientCount() const override; + int GetClientVersion(int ClientID) const override; int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) override; void DoSnapshot(); diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 507bd1c63..9b98e36c1 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -1,21 +1,21 @@ /* (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. */ -#include - -#include - -#include -#include -#include -#include -#include -#include - #include "character.h" -#include "game/generated/protocol.h" #include "laser.h" #include "projectile.h" +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include #include #include @@ -948,9 +948,7 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon) //TODO: Move the emote stuff to a function void CCharacter::SnapCharacter(int SnappingClient, int ID) { - int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ? - GameServer()->GetClientVersion(SnappingClient) : - CLIENT_VERSIONNR; + int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient); CCharacterCore *pCore; int Tick, Emote = m_EmoteType, Weapon = m_Core.m_ActiveWeapon, AmmoCount = 0, Health = 0, Armor = 0; diff --git a/src/game/server/entities/door.cpp b/src/game/server/entities/door.cpp index ea13f365e..0926562e7 100644 --- a/src/game/server/entities/door.cpp +++ b/src/game/server/entities/door.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -55,7 +54,7 @@ void CDoor::Snap(int SnappingClient) pObj->m_X = (int)m_Pos.x; 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; if(SnappingClientVersion >= VERSION_DDNET_SWITCH) diff --git a/src/game/server/entities/dragger.cpp b/src/game/server/entities/dragger.cpp index 60374dd8e..1836028a3 100644 --- a/src/game/server/entities/dragger.cpp +++ b/src/game/server/entities/dragger.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include @@ -185,9 +184,7 @@ void CDragger::Snap(int SnappingClient) } } - int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ? - GameServer()->GetClientVersion(SnappingClient) : - CLIENT_VERSIONNR; + int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient); CNetObj_EntityEx *pEntData = 0; if(SnappingClientVersion >= VERSION_DDNET_SWITCH) diff --git a/src/game/server/entities/gun.cpp b/src/game/server/entities/gun.cpp index 023a67fe1..5c997bffd 100644 --- a/src/game/server/entities/gun.cpp +++ b/src/game/server/entities/gun.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include @@ -148,9 +147,7 @@ void CGun::Snap(int SnappingClient) if(NetworkClipped(SnappingClient)) return; - int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ? - GameServer()->GetClientVersion(SnappingClient) : - CLIENT_VERSIONNR; + int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient); CNetObj_EntityEx *pEntData = 0; if(SnappingClientVersion >= VERSION_DDNET_SWITCH) diff --git a/src/game/server/entities/light.cpp b/src/game/server/entities/light.cpp index f414ea69f..82df42455 100644 --- a/src/game/server/entities/light.cpp +++ b/src/game/server/entities/light.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include @@ -106,7 +105,7 @@ void CLight::Snap(int SnappingClient) if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient, m_To)) return; - int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ? GameServer()->GetClientVersion(SnappingClient) : CLIENT_VERSIONNR; + int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient); CNetObj_EntityEx *pEntData = 0; if(SnappingClientVersion >= VERSION_DDNET_SWITCH && (m_Layer == LAYER_SWITCH || length(m_Core) > 0)) diff --git a/src/game/server/entities/pickup.cpp b/src/game/server/entities/pickup.cpp index 246734794..06b49e176 100644 --- a/src/game/server/entities/pickup.cpp +++ b/src/game/server/entities/pickup.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include @@ -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) 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; if(SnappingClientVersion >= VERSION_DDNET_SWITCH && (m_Layer == LAYER_SWITCH || length(m_Core) > 0)) diff --git a/src/game/server/entities/projectile.cpp b/src/game/server/entities/projectile.cpp index 99ea45596..c44d77381 100644 --- a/src/game/server/entities/projectile.cpp +++ b/src/game/server/entities/projectile.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -317,7 +316,7 @@ void CProjectile::Snap(int SnappingClient) 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) { CCharacter *pSnapChar = GameServer()->GetPlayerChar(SnappingClient); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index abc49223e..0963e3482 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -4119,9 +4119,7 @@ void CGameContext::List(int ClientID, const char *pFilter) int CGameContext::GetClientVersion(int ClientID) const { - IServer::CClientInfo Info = {0}; - Server()->GetClientInfo(ClientID, &Info); - return Info.m_DDNetVersion; + return Server()->GetClientVersion(ClientID); } int64_t CGameContext::ClientsMaskExcludeClientVersionAndHigher(int Version) diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 3a7864602..1bf96e9fd 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -1,20 +1,19 @@ /* (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. */ #include "player.h" -#include - -#include -#include - -#include "base/system.h" #include "entities/character.h" #include "gamecontext.h" #include "gamecontroller.h" #include "score.h" +#include + +#include +#include +#include + #include #include -#include 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_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 Score = abs(m_Score) * -1;