Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infection rewrite #150

Merged
merged 3 commits into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/engine/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ class IServer : public IInterface

/* INFECTION MODIFICATION START ***************************************/
virtual int IsClientInfectedBefore(int ClientID) = 0;
virtual void InfecteClient(int ClientID) = 0;
virtual void InfectClient(int ClientID) = 0;
virtual void UnInfectClient(int ClientID) = 0;

virtual int GetClientNbRound(int ClientID) = 0;

Expand Down Expand Up @@ -354,10 +355,6 @@ class IServer : public IInterface

virtual int* GetIdMap(int ClientID) = 0;
virtual void SetCustClt(int ClientID) = 0;
// InfClassR spectators vector
std::vector<int> spectators_id;

virtual int GetActivePlayerCount() = 0;
};

class IGameServer : public IInterface
Expand All @@ -384,6 +381,7 @@ class IGameServer : public IInterface

virtual bool IsClientReady(int ClientID) = 0;
virtual bool IsClientPlayer(int ClientID) = 0;
virtual int GetActivePlayerCount() = 0;

virtual const char *GameType() = 0;
virtual const char *Version() = 0;
Expand Down
64 changes: 25 additions & 39 deletions src/engine/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <engine/masterserver.h>
#include <engine/server.h>
#include <engine/storage.h>

#include <engine/shared/compression.h>
#include <engine/shared/config.h>
#include <engine/shared/datafile.h>
Expand Down Expand Up @@ -336,9 +335,6 @@ void CServer::CClient::Reset(bool ResetScore)
if(ResetScore)
{
m_NbRound = 0;
m_WaitingTime = 0;
m_WasInfected = 0;

m_UserID = -1;
#ifdef CONF_SQL
m_UserLevel = SQL_USERLEVEL_NORMAL;
Expand Down Expand Up @@ -2866,28 +2862,34 @@ int CServer::IsClientInfectedBefore(int ClientID)
return m_aClients[ClientID].m_WasInfected;
}

void CServer::InfecteClient(int ClientID)
void CServer::InfectClient(int ClientID)
{
m_aClients[ClientID].m_WasInfected = 1;
bool NonInfectedFound = false;
for(int i=0; i<MAX_CLIENTS; i++)
{
if(m_aClients[i].m_State == CServer::CClient::STATE_INGAME && m_aClients[i].m_WasInfected == 0)
{
NonInfectedFound = true;
break;
}
}

if(!NonInfectedFound)
{
for(int i=0; i<MAX_CLIENTS; i++)
{
m_aClients[i].m_WasInfected = 0;
}
}
// bool NonInfectedFound = false;
// for(int i=0; i<MAX_CLIENTS; i++)
// {
// if(m_aClients[i].m_State == CServer::CClient::STATE_INGAME && m_aClients[i].m_WasInfected == 0)
// {
// NonInfectedFound = true;
// break;
// }
// }
//
// if(!NonInfectedFound)
// {
// for(int i=0; i<MAX_CLIENTS; i++)
// {
// m_aClients[i].m_WasInfected = 0;
// }
// }
}

void CServer::UnInfectClient(int ClientID)
{
m_aClients[ClientID].m_WasInfected = 0;
}


int CServer::GetClientAntiPing(int ClientID)
{
return m_aClients[ClientID].m_AntiPing;
Expand Down Expand Up @@ -4386,22 +4388,6 @@ IServer::CClientSession* CServer::GetClientSession(int ClientID)
return &m_aClients[ClientID].m_Session;
}

// returns how many players are currently playing and not spectating
int CServer::GetActivePlayerCount()
{
int PlayerCount = 0;
auto& vec = spectators_id;
for(int i=0; i<MAX_CLIENTS; i++)
{
if(m_aClients[i].m_State == CClient::STATE_INGAME)
{
if (std::find(vec.begin(), vec.end(), i) == vec.end())
PlayerCount++;
}
}
return PlayerCount;
}

void CServer::AddAccusation(int From, int To, const char* pReason)
{
if(From < 0 || From >= MAX_CLIENTS || To < 0 || To >= MAX_CLIENTS)
Expand Down Expand Up @@ -4547,7 +4533,7 @@ IServer::CMapVote* CServer::GetMapVote()
if (m_MapVotesCounter <= 0)
return 0;

float PlayerCount = GetActivePlayerCount();
float PlayerCount = GameServer()->GetActivePlayerCount();

int HighestNum = -1;
int HighestNumIndex = -1;
Expand Down
6 changes: 2 additions & 4 deletions src/engine/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ class CServer : public IServer

public:
virtual int IsClientInfectedBefore(int ClientID);
virtual void InfecteClient(int ClientID);
virtual void InfectClient(int ClientID);
virtual void UnInfectClient(int ClientID);

virtual int GetClientAntiPing(int ClientID);
virtual void SetClientAntiPing(int ClientID, int Value);
Expand Down Expand Up @@ -412,9 +413,6 @@ class CServer : public IServer
virtual void ResetMapVotes();
virtual IServer::CMapVote* GetMapVote();
virtual int GetMinPlayersForMap(const char* pMapName);

virtual int GetActivePlayerCount();

virtual int GetTimeShiftUnit() const { return m_TimeShiftUnit; } //In ms
/* INFECTION MODIFICATION END *****************************************/

Expand Down
4 changes: 2 additions & 2 deletions src/game/server/entities/hero-flag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void CHeroFlag::FindPosition()
void CHeroFlag::SetCoolDown()
{
// Set cooldown for next flag depending on how many players are online
int PlayerCount = Server()->GetActivePlayerCount();
int PlayerCount = GameServer()->GetActivePlayerCount();
if (PlayerCount <= 1)
{
// only 1 player on, let him find as many flags as he wants
Expand All @@ -70,7 +70,7 @@ void CHeroFlag::GiveGift(CCharacter* pHero)

if (g_Config.m_InfTurretEnable)
{
if (Server()->GetActivePlayerCount() > 2)
if (GameServer()->GetActivePlayerCount() > 2)
{
if (pHero->m_TurretCount == 0)
pHero->GiveWeapon(WEAPON_HAMMER, -1);
Expand Down
Loading