mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
also remove references to CGameContext from CServer
This commit is contained in:
parent
9b6699d3b8
commit
2797227063
|
@ -52,6 +52,7 @@
|
|||
#include <engine/shared/fifo.h>
|
||||
#include <engine/shared/uuid_manager.h>
|
||||
|
||||
#include <game/extrainfo.h>
|
||||
#include <game/version.h>
|
||||
|
||||
#include <mastersrv/mastersrv.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();
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <engine/shared/linereader.h>
|
||||
#include <game/server/gamecontext.h>
|
||||
#include <game/extrainfo.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
|
||||
int Crc();
|
||||
void DebugDump();
|
||||
static void RemoveExtraInfo(unsigned char *pData);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <game/generated/client_data.h>
|
||||
#include <engine/shared/config.h>
|
||||
|
||||
#include <game/gamecore.h> // get_angle
|
||||
#include <game/extrainfo.h>
|
||||
#include <game/client/gameclient.h>
|
||||
#include <game/client/ui.h>
|
||||
#include <game/client/render.h>
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <base/math.h>
|
||||
#include <base/vmath.h>
|
||||
|
||||
#include <game/extrainfo.h>
|
||||
#include <game/localization.h>
|
||||
#include <game/version.h>
|
||||
#include "render.h"
|
||||
|
|
72
src/game/extrainfo.cpp
Normal file
72
src/game/extrainfo.cpp
Normal file
|
@ -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 <engine/shared/snapshot.h>
|
||||
#include <game/generated/protocol.h>
|
||||
#include <base/math.h>
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
src/game/extrainfo.h
Normal file
13
src/game/extrainfo.h
Normal file
|
@ -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 <base/vmath.h>
|
||||
|
||||
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
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
Loading…
Reference in a new issue