From 279722706352825f29fcc4e52c8a58bc9715d032 Mon Sep 17 00:00:00 2001 From: eeeee Date: Mon, 5 Jun 2017 22:31:56 -0700 Subject: [PATCH] also remove references to CGameContext from CServer --- src/engine/client/client.cpp | 1 + src/engine/server.h | 3 ++ src/engine/server/server.cpp | 26 ++++------ src/engine/shared/snapshot.h | 1 + src/game/client/components/items.cpp | 2 +- src/game/client/gameclient.cpp | 1 + src/game/extrainfo.cpp | 72 ++++++++++++++++++++++++++++ src/game/extrainfo.h | 13 +++++ src/game/gamecore.cpp | 65 ------------------------- src/game/gamecore.h | 5 -- src/game/server/ddracechat.cpp | 2 + src/game/server/gamecontext.cpp | 13 +++++ src/game/server/gamecontext.h | 3 ++ 13 files changed, 120 insertions(+), 87 deletions(-) create mode 100644 src/game/extrainfo.cpp create mode 100644 src/game/extrainfo.h diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 635f636aa..ef0e2b687 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -52,6 +52,7 @@ #include #include +#include #include #include diff --git a/src/engine/server.h b/src/engine/server.h index 1784e6de3..0f6d4a894 100644 --- a/src/engine/server.h +++ b/src/engine/server.h @@ -215,6 +215,9 @@ public: // DDRace virtual void OnSetAuthed(int ClientID, int Level) = 0; + virtual int GetClientVersion(int ClientID) = 0; + virtual void SetClientVersion(int ClientID, int Version) = 0; + virtual bool PlayerExists(int ClientID) = 0; }; extern IGameServer *CreateGameServer(); diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index e39d8bf86..c00298f03 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include "register.h" #include "server.h" @@ -500,9 +500,7 @@ int CServer::GetClientInfo(int ClientID, CClientInfo *pInfo) { pInfo->m_pName = m_aClients[ClientID].m_aName; pInfo->m_Latency = m_aClients[ClientID].m_Latency; - CGameContext *GameServer = (CGameContext *) m_pGameServer; - if (GameServer->m_apPlayers[ClientID]) - pInfo->m_ClientVersion = GameServer->m_apPlayers[ClientID]->m_ClientVersion; + pInfo->m_ClientVersion = GameServer()->GetClientVersion(ClientID); return 1; } return 0; @@ -1170,14 +1168,13 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) } if(Unpacker.Error() == 0 && !str_comp(pCmd, "crashmeplx")) { - CGameContext *GameServer = (CGameContext *) m_pGameServer; - if (GameServer->m_apPlayers[ClientID] && GameServer->m_apPlayers[ClientID]->m_ClientVersion < VERSION_DDNET_OLD) - GameServer->m_apPlayers[ClientID]->m_ClientVersion = VERSION_DDNET_OLD; + int version = GameServer()->GetClientVersion(ClientID); + if (GameServer()->PlayerExists(ClientID) && version < VERSION_DDNET_OLD) + GameServer()->SetClientVersion(ClientID, VERSION_DDNET_OLD); } else if((pPacket->m_Flags&NET_CHUNKFLAG_VITAL) != 0 && Unpacker.Error() == 0 && m_aClients[ClientID].m_Authed) { - CGameContext *GameServer = (CGameContext *) m_pGameServer; - if (GameServer->m_apPlayers[ClientID]) + if (GameServer()->PlayerExists(ClientID)) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "ClientID=%d rcon='%s'", ClientID, pCmd); @@ -2023,10 +2020,10 @@ void CServer::ConStatus(IConsole::IResult *pResult, void *pUser) if(CanSeeAddress) str_format(aBuf, sizeof(aBuf), "id=%d addr=%s name='%s' score=%d client=%d secure=%s %s", i, aAddrStr, - pThis->m_aClients[i].m_aName, pThis->m_aClients[i].m_Score, ((CGameContext *)(pThis->GameServer()))->m_apPlayers[i]->m_ClientVersion, pThis->m_NetServer.HasSecurityToken(i) ? "yes":"no", aAuthStr); + pThis->m_aClients[i].m_aName, pThis->m_aClients[i].m_Score, pThis->GameServer()->GetClientVersion(i), pThis->m_NetServer.HasSecurityToken(i) ? "yes" : "no", aAuthStr); else str_format(aBuf, sizeof(aBuf), "id=%d name='%s' score=%d client=%d secure=%s %s", i, - pThis->m_aClients[i].m_aName, pThis->m_aClients[i].m_Score, ((CGameContext *)(pThis->GameServer()))->m_apPlayers[i]->m_ClientVersion, pThis->m_NetServer.HasSecurityToken(i) ? "yes" : "no", aAuthStr); + pThis->m_aClients[i].m_aName, pThis->m_aClients[i].m_Score, pThis->GameServer()->GetClientVersion(i), pThis->m_NetServer.HasSecurityToken(i) ? "yes" : "no", aAuthStr); } else { @@ -2068,10 +2065,10 @@ void CServer::ConDnsblStatus(IConsole::IResult *pResult, void *pUser) if (CanSeeAddress) str_format(aBuf, sizeof(aBuf), "id=%d addr=%s name='%s' score=%d client=%d secure=%s %s", i, aAddrStr, - pThis->m_aClients[i].m_aName, pThis->m_aClients[i].m_Score, ((CGameContext *)(pThis->GameServer()))->m_apPlayers[i]->m_ClientVersion, pThis->m_NetServer.HasSecurityToken(i) ? "yes":"no", aAuthStr); + pThis->m_aClients[i].m_aName, pThis->m_aClients[i].m_Score, pThis->GameServer()->GetClientVersion(i), pThis->m_NetServer.HasSecurityToken(i) ? "yes" : "no", aAuthStr); else str_format(aBuf, sizeof(aBuf), "id=%d name='%s' score=%d client=%d secure=%s %s", i, - pThis->m_aClients[i].m_aName, pThis->m_aClients[i].m_Score, ((CGameContext *)(pThis->GameServer()))->m_apPlayers[i]->m_ClientVersion, pThis->m_NetServer.HasSecurityToken(i) ? "yes" : "no", aAuthStr); + pThis->m_aClients[i].m_aName, pThis->m_aClients[i].m_Score, pThis->GameServer()->GetClientVersion(i), pThis->m_NetServer.HasSecurityToken(i) ? "yes" : "no", aAuthStr); } else { @@ -2837,10 +2834,7 @@ bool CServer::SetTimedOut(int ClientID, int OrigID) { { return false; } - CGameContext *GameServer = (CGameContext *) m_pGameServer; DelClientCallback(OrigID, "Timeout Protection used", this); m_aClients[ClientID].m_Authed = IServer::AUTHED_NO; - if (GameServer->m_apPlayers[ClientID]->GetCharacter()) - GameServer->SendTuningParams(ClientID, GameServer->m_apPlayers[ClientID]->GetCharacter()->m_TuneZone); return true; } diff --git a/src/engine/shared/snapshot.h b/src/engine/shared/snapshot.h index eb85c4c9f..c46a491e8 100644 --- a/src/engine/shared/snapshot.h +++ b/src/engine/shared/snapshot.h @@ -45,6 +45,7 @@ public: int Crc(); void DebugDump(); + static void RemoveExtraInfo(unsigned char *pData); }; diff --git a/src/game/client/components/items.cpp b/src/game/client/components/items.cpp index 4d2a4b789..f5b0fb7fa 100644 --- a/src/game/client/components/items.cpp +++ b/src/game/client/components/items.cpp @@ -6,7 +6,7 @@ #include #include -#include // get_angle +#include #include #include #include diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index a2bcf2b88..67be0a482 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include "render.h" diff --git a/src/game/extrainfo.cpp b/src/game/extrainfo.cpp new file mode 100644 index 000000000..d47879b4c --- /dev/null +++ b/src/game/extrainfo.cpp @@ -0,0 +1,72 @@ +/* (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 "extrainfo.h" + +bool UseExtraInfo(const CNetObj_Projectile *pProj) +{ + bool ExtraInfoFlag = ((abs(pProj->m_VelY) & (1<<9)) != 0); + return ExtraInfoFlag; +} + +void ExtractInfo(const CNetObj_Projectile *pProj, vec2 *StartPos, vec2 *StartVel, bool IsDDNet) +{ + if(!UseExtraInfo(pProj) || !IsDDNet) + { + StartPos->x = pProj->m_X; + StartPos->y = pProj->m_Y; + StartVel->x = pProj->m_VelX/100.0f; + StartVel->y = pProj->m_VelY/100.0f; + } + else + { + StartPos->x = pProj->m_X/100.0f; + StartPos->y = pProj->m_Y/100.0f; + float Angle = pProj->m_VelX/1000000.0f; + StartVel->x = sin(-Angle); + StartVel->y = cos(-Angle); + } +} + +void ExtractExtraInfo(const CNetObj_Projectile *pProj, int *Owner, bool *Explosive, int *Bouncing, bool *Freeze) +{ + int Data = pProj->m_VelY; + if(Owner) + { + *Owner = Data & 255; + if((Data>>8) & 1) + *Owner = -(*Owner); + } + if(Bouncing) + *Bouncing = (Data>>10) & 3; + if(Explosive) + *Explosive = (Data>>12) & 1; + if(Freeze) + *Freeze = (Data>>13) & 1; +} + +void SnapshotRemoveExtraInfo(unsigned char *pData) +{ + CSnapshot *pSnap = (CSnapshot*) pData; + for(int Index = 0; Index < pSnap->NumItems(); Index++) + { + CSnapshotItem *pItem = pSnap->GetItem(Index); + if(pItem->Type() == NETOBJTYPE_PROJECTILE) + { + CNetObj_Projectile *pProj = (CNetObj_Projectile*) ((void*)pItem->Data()); + if(UseExtraInfo(pProj)) + { + vec2 Pos; + vec2 Vel; + ExtractInfo(pProj, &Pos, &Vel, 1); + pProj->m_X = Pos.x; + pProj->m_Y = Pos.y; + pProj->m_VelX = (int)(Vel.x*100.0f); + pProj->m_VelY = (int)(Vel.y*100.0f); + } + } + } +} diff --git a/src/game/extrainfo.h b/src/game/extrainfo.h new file mode 100644 index 000000000..503da7aee --- /dev/null +++ b/src/game/extrainfo.h @@ -0,0 +1,13 @@ +/* (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. */ +#ifndef GAME_EXTRAINFO_H +#define GAME_EXTRAINFO_H + +#include + +bool UseExtraInfo(const CNetObj_Projectile *pProj); +void ExtractInfo(const CNetObj_Projectile *pProj, vec2 *StartPos, vec2 *StartVel, bool IsDDNet); +void ExtractExtraInfo(const CNetObj_Projectile *pProj, int *Owner, bool *Explosive, int *Bouncing, bool *Freeze); +void SnapshotRemoveExtraInfo(unsigned char *pData); + +#endif diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index 4666d0e95..12ef3c73e 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -722,68 +722,3 @@ void CCharacterCore::ApplyForce(vec2 Force) LimitForce(&Temp); m_Vel = Temp; } - -bool UseExtraInfo(const CNetObj_Projectile *pProj) -{ - bool ExtraInfoFlag = ((abs(pProj->m_VelY) & (1<<9)) != 0); - return ExtraInfoFlag; -} - -void ExtractInfo(const CNetObj_Projectile *pProj, vec2 *StartPos, vec2 *StartVel, bool IsDDNet) -{ - if(!UseExtraInfo(pProj) || !IsDDNet) - { - StartPos->x = pProj->m_X; - StartPos->y = pProj->m_Y; - StartVel->x = pProj->m_VelX/100.0f; - StartVel->y = pProj->m_VelY/100.0f; - } - else - { - StartPos->x = pProj->m_X/100.0f; - StartPos->y = pProj->m_Y/100.0f; - float Angle = pProj->m_VelX/1000000.0f; - StartVel->x = sin(-Angle); - StartVel->y = cos(-Angle); - } -} - -void ExtractExtraInfo(const CNetObj_Projectile *pProj, int *Owner, bool *Explosive, int *Bouncing, bool *Freeze) -{ - int Data = pProj->m_VelY; - if(Owner) - { - *Owner = Data & 255; - if((Data>>8) & 1) - *Owner = -(*Owner); - } - if(Bouncing) - *Bouncing = (Data>>10) & 3; - if(Explosive) - *Explosive = (Data>>12) & 1; - if(Freeze) - *Freeze = (Data>>13) & 1; -} - -void SnapshotRemoveExtraInfo(unsigned char *pData) -{ - CSnapshot *pSnap = (CSnapshot*) pData; - for(int Index = 0; Index < pSnap->NumItems(); Index++) - { - CSnapshotItem *pItem = pSnap->GetItem(Index); - if(pItem->Type() == NETOBJTYPE_PROJECTILE) - { - CNetObj_Projectile *pProj = (CNetObj_Projectile*) ((void*)pItem->Data()); - if(UseExtraInfo(pProj)) - { - vec2 Pos; - vec2 Vel; - ExtractInfo(pProj, &Pos, &Vel, 1); - pProj->m_X = Pos.x; - pProj->m_Y = Pos.y; - pProj->m_VelX = (int)(Vel.x*100.0f); - pProj->m_VelY = (int)(Vel.y*100.0f); - } - } - } -} diff --git a/src/game/gamecore.h b/src/game/gamecore.h index e997d2b10..bbd10a0bf 100644 --- a/src/game/gamecore.h +++ b/src/game/gamecore.h @@ -296,9 +296,4 @@ inline CInputCount CountInput(int Prev, int Cur) return c; } -bool UseExtraInfo(const CNetObj_Projectile *pProj); -void ExtractInfo(const CNetObj_Projectile *pProj, vec2 *StartPos, vec2 *StartVel, bool IsDDNet); -void ExtractExtraInfo(const CNetObj_Projectile *pProj, int *Owner, bool *Explosive, int *Bouncing, bool *Freeze); -void SnapshotRemoveExtraInfo(unsigned char *pData); - #endif diff --git a/src/game/server/ddracechat.cpp b/src/game/server/ddracechat.cpp index 83cd41b5a..ba8827574 100644 --- a/src/game/server/ddracechat.cpp +++ b/src/game/server/ddracechat.cpp @@ -539,6 +539,8 @@ void CGameContext::ConTimeout(IConsole::IResult *pResult, void *pUserData) if (!pSelf->m_apPlayers[i]) continue; if (str_comp(pSelf->m_apPlayers[i]->m_TimeoutCode, pResult->GetString(0))) continue; if (pSelf->Server()->SetTimedOut(i, pResult->m_ClientID)) { + if (pSelf->m_apPlayers[i]->GetCharacter()) + pSelf->SendTuningParams(i, pSelf->m_apPlayers[i]->GetCharacter()->m_TuneZone); return; } } diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 7e20f060d..4bae6d2de 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -3240,3 +3240,16 @@ void CGameContext::List(int ClientID, const char *pFilter) str_format(aBuf, sizeof(aBuf), "%d players online", Total); SendChatTarget(ClientID, aBuf); } + +int CGameContext::GetClientVersion(int ClientID) { + return m_apPlayers[ClientID] + ? m_apPlayers[ClientID]->m_ClientVersion + : 0; +} + +void CGameContext::SetClientVersion(int ClientID, int Version) { + if (!m_apPlayers[ClientID]) { + return; + } + m_apPlayers[ClientID]->m_ClientVersion = Version; +} diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index c120ffd74..ccf081e81 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -226,6 +226,9 @@ public: // Describes the time when the first player joined the server. int64 m_NonEmptySince; int64 m_LastMapVote; + int GetClientVersion(int ClientID); + void SetClientVersion(int ClientID, int Version); + bool PlayerExists(int ClientID) { return m_apPlayers[ClientID]; }; private: