Пример #1
0
  TEST(Session, ClientsServers)
  {
    Timer::GetInstance().UseVirtualTime();
    ConnectionManager::UseTimer = false;
    OverlayNetwork net = ConstructOverlay(10, 20);
    VerifyStoppedNetwork(net);
    StartNetwork(net);
    VerifyNetwork(net);

    Sessions sessions = BuildSessions(net);
    qDebug() << "Starting sessions...";
    StartSessions(sessions);
    StartRound(sessions);
    SendTest(sessions);
    SendTest(sessions);
    DisconnectServer(sessions, true);
    SendTest(sessions);
    DisconnectServer(sessions, false);
    SendTest(sessions);
    SendTest(sessions);
    StopSessions(sessions);

    StopNetwork(sessions.network);
    VerifyStoppedNetwork(sessions.network);
    ConnectionManager::UseTimer = true;
  }
Пример #2
0
void CDDom::Process( void )
{
	if( GetRunTime() == RUN_CLOSED )
		return;

	if( GetRunTime() == RUN_COOLDOWN )
	{
		if( m_dwRoundTime != 0 && m_dwRoundTime < GetTickCount() )
		{
			m_dwRoundTime = 0;
			StartRound();
		}
	}
	else if( GetRunTime() == RUN_FIGHT )
	{
		if( GetTime() > 0 )
		{
			DecreaseTime();
		}
		else
		{
			const DDOM_TEAM tA = m_Base[BASE_A].GetTouchTeam();
			const DDOM_TEAM tB = m_Base[BASE_B].GetTouchTeam();
			if( tA != MAX_TEAM && tB != MAX_TEAM )
			{
				if( tA == tB )
				{
					Capped( tA ); //ATTENTION
					ResetCapTeam(); 
				} 
			}	
		}
	}
}
Пример #3
0
//-----------------------------------------------------------------------------
// Purpose: Start a battle. Spawn all the players, and begin the countdown.
//-----------------------------------------------------------------------------
void CDiscArena::StartBattle( void )
{
	m_iCurrRound = 0;
	m_iTeamOneScore = m_iTeamTwoScore = 0;

	// First, set all players in this arena to "didn't play"
	for ( int i = 1; i <= gpGlobals->maxClients; i++ )
	{
		CBasePlayer *pPlayer = (CBasePlayer *)UTIL_PlayerByIndex( i );

		if (pPlayer && (pPlayer->m_pCurrentArena == this) && pPlayer->m_bHasDisconnected != TRUE )
			pPlayer->m_iLastGameResult = GAME_DIDNTPLAY;
	}

	// Get the players in the battle
	for ( i = 0; i < (m_iPlayersPerTeam * 2); i++ )
	{
		CBasePlayer *pCurr;

		// Check to see if this slot's already full
		if ( m_hCombatants[ i ] )
		{
			pCurr = (CBasePlayer*)(CBaseEntity*)m_hCombatants[ i ];
		}
		else
		{
			// Pop a new player from the queue
			pCurr = GetNextPlayer();
			if (!pCurr)
			{
				// Couldnt get enough players. Reset.
				Reset();
				return;
			}
		}

		// Set her team number
		if ( i < m_iPlayersPerTeam )
			pCurr->pev->team = 1;
		else
			pCurr->pev->team = 2;
		pCurr->pev->iuser4 = pCurr->pev->team;

		char sz[128];
		sprintf(sz, "Arena %d", pev->groupinfo );
		MESSAGE_BEGIN( MSG_ALL, gmsgTeamInfo );
			WRITE_BYTE( pCurr->entindex() );
			WRITE_STRING( sz );
		MESSAGE_END();

		// Add her to the list of combatants
		m_hCombatants[ i ] = pCurr;
		
		// Force her to update her clientinfo, so her colors match her team
		ClientUserInfoChanged( pCurr->edict(), g_engfuncs.pfnGetInfoKeyBuffer( pCurr->edict() ) );
	}

	// Start the first round
	StartRound();
}
Пример #4
0
//-----------------------------------------------------------------------------
// Purpose: Show who won, and then restart the round
//-----------------------------------------------------------------------------
void CDiscArena::FinishedThink( void )
{
	m_iSecondsTillStart--;

	if (m_iSecondsTillStart)
	{
		pev->nextthink = gpGlobals->time + 1.0;
	}
	else
	{
		SetThink( NULL );

		// Tell the clients to remove the "Won" window
		for ( int i = 1; i <= gpGlobals->maxClients; i++ )
		{
			CBasePlayer *pPlayer = (CBasePlayer *)UTIL_PlayerByIndex( i );

			if (pPlayer && (pPlayer->pev->groupinfo & pev->groupinfo) && pPlayer->m_bHasDisconnected != TRUE)
			{
				MESSAGE_BEGIN( MSG_ONE, gmsgEndRnd, NULL, pPlayer->edict() );
					WRITE_BYTE( m_iCurrRound );
					WRITE_BYTE( 0 );
					WRITE_BYTE( 0 );
				MESSAGE_END();
			}
		}

		// Round is over. See if the match is over too.
		if ( m_iTeamOneScore >= m_iMaxRounds || m_iTeamTwoScore >= m_iMaxRounds )
		{
			// Remove the losers from the combatants list
			for (int i = 0; i < (m_iPlayersPerTeam * 2); i++)
			{
				CBasePlayer *pPlayer = (CBasePlayer*)(CBaseEntity*)m_hCombatants[i];
				if (!pPlayer)
					continue;
				if ( pPlayer->pev->team == m_iWinningTeam )
				{
					pPlayer->m_iDeaths += 1;
					pPlayer->m_iLastGameResult = GAME_WON;
					continue;
				}

				pPlayer->m_iLastGameResult = GAME_LOST;
				m_hCombatants[i] = NULL;
			}

			// Then start the next Battle
			PostBattle();
		}
		else
		{
			// Start the next round
			StartRound();
		}
	}
}
Пример #5
0
  void DisconnectServer(Sessions &sessions, bool hard)
  {
    qDebug() << "Disconnecting server" << hard;

    int server_count = sessions.servers.count();
    CryptoRandom rand;
    int idx = rand.GetInt(0, server_count);
    OverlayPointer op_disc = sessions.network.first[idx];

    if(hard) {
      op_disc->Stop();
      sessions.servers[idx]->Stop();
      // This will need to be adjusted if we support offline servers
      Time::GetInstance().IncrementVirtualClock(60000);
      Timer::GetInstance().VirtualRun();

      OverlayPointer op(new Overlay(op_disc->GetId(),
            op_disc->GetLocalEndpoints(),
            op_disc->GetRemoteEndpoints(),
            op_disc->GetServerIds()));
      op->SetSharedPointer(op);
      sessions.network.first[idx] = op;
      ServerPointer ss = MakeSession<ServerSession>(
            op, sessions.private_keys[op->GetId().ToString()],
            sessions.keys, sessions.create_round);
      sessions.servers[idx] = ss;
      ss->SetSink(sessions.sink_multiplexers[idx].data());

      op->Start();
      ss->Start();
    } else {
      // 1 for the node itself and 1 for at least another peer
      int disc_count = qMax(2, rand.GetInt(0, server_count));
      QHash<int, bool> disced;
      disced[idx] = true;
      while(disced.size() < disc_count) {
        int to_disc = rand.GetInt(0, server_count);
        if(disced.contains(to_disc)) {
          continue;
        }
        disced[to_disc] = true;
        Id remote = sessions.network.first[to_disc]->GetId();
        op_disc->GetConnectionTable().GetConnection(remote)->Disconnect();
      }
    }

    qDebug() << "Disconnecting done";
    StartRound(sessions);
    qDebug() << "Round started after disconnection";
  }
void ATacticalOpsGameModeBase::InitGameState  ()
{
	Super::InitGameState();

	AMyGameStateBase *TOGameState = Cast<AMyGameStateBase>(GameState);
	if (TOGameState)
	{
		TOGameState->TimeRemaining = GameTime;
		TOGameState->RoundTimeRemaining = PreRoundTime;
	
		//Scores et nombre de round à 0
		TOGameState->ResetScores();
		StartRound();

	}
}
void ATacticalOpsGameModeBase::OnRoundTimeExpired()
{
	switch (RoundState)
	{
	case (ERoundStateEnum::PreRound):
		StartRound();
		break;

	case (ERoundStateEnum::InProgress):
		RoundTimeExpired();
		break;

	case (ERoundStateEnum::RoundEnd):
		NextRound();
		break;
	}

}
Пример #8
0
void IGameController::Tick()
{
	// do warmup
	if(m_Warmup)
	{
		m_Warmup--;
		if(!m_Warmup)
			StartRound();
	}

	if(m_GameOverTick != -1)
	{
		// game over.. wait for restart
		if(Server()->Tick() > m_GameOverTick+Server()->TickSpeed()*10)
		{
			CycleMap();
			StartRound();
			m_RoundCount++;
		}
	}

	// do team-balancing
	if (IsTeamplay() && m_UnbalancedTick != -1 && Server()->Tick() > m_UnbalancedTick+g_Config.m_SvTeambalanceTime*Server()->TickSpeed()*60)
	{
		GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", "Balancing teams");

		int aT[2] = {0,0};
		float aTScore[2] = {0,0};
		float aPScore[MAX_CLIENTS] = {0.0f};
		for(int i = 0; i < MAX_CLIENTS; i++)
		{
			if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
			{
				aT[GameServer()->m_apPlayers[i]->GetTeam()]++;
				aPScore[i] = GameServer()->m_apPlayers[i]->m_Score*Server()->TickSpeed()*60.0f/
					(Server()->Tick()-GameServer()->m_apPlayers[i]->m_ScoreStartTick);
				aTScore[GameServer()->m_apPlayers[i]->GetTeam()] += aPScore[i];
			}
		}

		// are teams unbalanced?
		if(absolute(aT[0]-aT[1]) >= 2)
		{
			int M = (aT[0] > aT[1]) ? 0 : 1;
			int NumBalance = absolute(aT[0]-aT[1]) / 2;

			do
			{
				CPlayer *pP = 0;
				float PD = aTScore[M];
				for(int i = 0; i < MAX_CLIENTS; i++)
				{
					if(!GameServer()->m_apPlayers[i] || !CanBeMovedOnBalance(i))
						continue;
					// remember the player who would cause lowest score-difference
					if(GameServer()->m_apPlayers[i]->GetTeam() == M && (!pP || absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i])) < PD))
					{
						pP = GameServer()->m_apPlayers[i];
						PD = absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i]));
					}
				}

				// move the player to the other team
				int Temp = pP->m_LastActionTick;
				pP->SetTeam(M^1);
				pP->m_LastActionTick = Temp;

				pP->Respawn();
				pP->m_ForceBalanced = true;
			} while (--NumBalance);

			m_ForceBalanced = true;
		}
		m_UnbalancedTick = -1;
	}

	// check for inactive players
	if(g_Config.m_SvInactiveKickTime > 0)
	{
		for(int i = 0; i < MAX_CLIENTS; ++i)
		{
			if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && !Server()->IsAuthed(i))
			{
				if(Server()->Tick() > GameServer()->m_apPlayers[i]->m_LastActionTick+g_Config.m_SvInactiveKickTime*Server()->TickSpeed()*60)
				{
					switch(g_Config.m_SvInactiveKick)
					{
					case 0:
						{
							// move player to spectator
							GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
						}
						break;
					case 1:
						{
							// move player to spectator if the reserved slots aren't filled yet, kick him otherwise
							int Spectators = 0;
							for(int j = 0; j < MAX_CLIENTS; ++j)
								if(GameServer()->m_apPlayers[j] && GameServer()->m_apPlayers[j]->GetTeam() == TEAM_SPECTATORS)
									++Spectators;
							if(Spectators >= g_Config.m_SvSpectatorSlots)
								Server()->Kick(i, "Kicked for inactivity");
							else
								GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
						}
						break;
					case 2:
						{
							// kick the player
							Server()->Kick(i, "Kicked for inactivity");
						}
					}
				}
			}
		}
	}

	// first condition is because player score gets reset pretty late. second is to not get two votes, if both sv_endvote_* are set.
	// third is to only cause the vote in the last round
	if (m_RoundStartTick != Server()->Tick() && *g_Config.m_SvMaprotation && !m_AutoVoteCaused && m_RoundCount >= g_Config.m_SvRoundsPerMap - 1)
	{
		if (g_Config.m_SvEndvoteTime > 0 && g_Config.m_SvTimelimit > 0 && g_Config.m_SvEndvoteTime < g_Config.m_SvTimelimit*60
				&& Server()->Tick() - m_RoundStartTick >= (g_Config.m_SvTimelimit*60 - g_Config.m_SvEndvoteTime) * Server()->TickSpeed())
		{
				AutoVote(); //time
		}
		else if (g_Config.m_SvEndvoteScore > 0 && g_Config.m_SvScorelimit > 0 && g_Config.m_SvEndvoteScore < g_Config.m_SvScorelimit)
		{
			int Max = 0;
			if (m_GameFlags & GAMEFLAG_TEAMS)
				Max = m_aTeamscore[m_aTeamscore[TEAM_RED] > m_aTeamscore[TEAM_BLUE] ? TEAM_RED : TEAM_BLUE];
			else
				for(int i = 0; i < MAX_CLIENTS; ++i)
					if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->m_Score > Max)
						Max = GameServer()->m_apPlayers[i]->m_Score;

			if (Max + g_Config.m_SvEndvoteScore >= g_Config.m_SvScorelimit)
				AutoVote(); //score
		}
	}
}
Пример #9
0
void IGameController::Tick()
{
	for (int i=0; i < MAX_CLIENTS; i++){
		if (GameServer()->m_apPlayers[i]){
			char Bufs[256];str_format(Bufs, sizeof(Bufs), "Team %d", GameServer()->m_apPlayers[i]->m_Team2);
			GameServer()->Server()->SetClientClan(i, Bufs);
			GameServer()->m_apPlayers[i]->m_Score = GameServer()->m_apPlayers[i]->m_Money;
			char aBuf[256];
			str_format(aBuf, sizeof(aBuf), "Your Money : %d\nYour Team : %d", GameServer()->m_apPlayers[i]->m_Money, GameServer()->m_apPlayers[i]->m_Team2);
			GameServer()->SendBroadcast(aBuf, i);
		}
	}
	
	// do warmup
	if(m_Warmup)
	{
		m_Warmup--;
		if(!m_Warmup)
			StartRound();
	}

	if(m_GameOverTick != -1)
	{
		// game over.. wait for restart
		if(Server()->Tick() > m_GameOverTick+Server()->TickSpeed()*10)
		{
			//CycleMap();
			StartRound();
			m_RoundCount++;
		}
	}

	/*
	// game is Paused
	if(GameServer()->m_World.m_Paused)
		++m_RoundStartTick;

	// do team-balancing
	if(IsTeamplay() && m_UnbalancedTick != -1 && Server()->Tick() > m_UnbalancedTick+g_Config.m_SvTeambalanceTime*Server()->TickSpeed()*60)
	{
		GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", "Balancing teams");

		int aT[2] = {0,0};
		float aTScore[2] = {0,0};
		float aPScore[MAX_CLIENTS] = {0.0f};
		for(int i = 0; i < MAX_CLIENTS; i++)
		{
			if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
			{
				aT[GameServer()->m_apPlayers[i]->GetTeam()]++;
				aPScore[i] = GameServer()->m_apPlayers[i]->m_Score*Server()->TickSpeed()*60.0f/
					(Server()->Tick()-GameServer()->m_apPlayers[i]->m_ScoreStartTick);
				aTScore[GameServer()->m_apPlayers[i]->GetTeam()] += aPScore[i];
			}
		}

		// are teams unbalanced?
		if(absolute(aT[0]-aT[1]) >= 2)
		{
			int M = (aT[0] > aT[1]) ? 0 : 1;
			int NumBalance = absolute(aT[0]-aT[1]) / 2;

			do
			{
				CPlayer *pP = 0;
				float PD = aTScore[M];
				for(int i = 0; i < MAX_CLIENTS; i++)
				{
					if(!GameServer()->m_apPlayers[i] || !CanBeMovedOnBalance(i))
						continue;
					// remember the player who would cause lowest score-difference
					if(GameServer()->m_apPlayers[i]->GetTeam() == M && (!pP || absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i])) < PD))
					{
						pP = GameServer()->m_apPlayers[i];
						PD = absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i]));
					}
				}

				// move the player to the other team
				int Temp = pP->m_LastActionTick;
				pP->SetTeam(M^1);
				pP->m_LastActionTick = Temp;

				pP->Respawn();
				pP->m_ForceBalanced = true;
			} while (--NumBalance);

			m_ForceBalanced = true;
		}
		m_UnbalancedTick = -1;
	}
	*/
	// check for inactive players
	if(g_Config.m_SvInactiveKickTime > 0)
	{
		for(int i = 0; i < MAX_CLIENTS; ++i)
		{
		#ifdef CONF_DEBUG
			if(g_Config.m_DbgDummies)
			{
				if(i >= MAX_CLIENTS-g_Config.m_DbgDummies)
					break;
			}
		#endif
			if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && !Server()->IsAuthed(i))
			{
				if(Server()->Tick() > GameServer()->m_apPlayers[i]->m_LastActionTick+g_Config.m_SvInactiveKickTime*Server()->TickSpeed()*60)
				{
					switch(g_Config.m_SvInactiveKick)
					{
					case 0:
						{
							// move player to spectator
							GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
						}
						break;
					case 1:
						{
							// move player to spectator if the reserved slots aren't filled yet, kick him otherwise
							int Spectators = 0;
							for(int j = 0; j < MAX_CLIENTS; ++j)
								if(GameServer()->m_apPlayers[j] && GameServer()->m_apPlayers[j]->GetTeam() == TEAM_SPECTATORS)
									++Spectators;
							if(Spectators >= g_Config.m_SvSpectatorSlots)
								Server()->Kick(i, "Kicked for inactivity");
							else
								GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
						}
						break;
					case 2:
						{
							// kick the player
							Server()->Kick(i, "Kicked for inactivity");
						}
					}
				}
			}
		}
	}

	//DoWincheck();
	
	// logout inactive players
	if(g_Config.m_SvInactiveLogoutTime > 0)
	{
		for(int i = 0; i < MAX_CLIENTS; ++i)
		{
			if(GameServer()->m_apPlayers[i] && (Server()->IsAuthed(i) || GameServer()->m_apPlayers[i]->m_IsLoggedIn))
			{
				if(Server()->Tick() > GameServer()->m_apPlayers[i]->m_LastActionTick+g_Config.m_SvInactiveLogoutTime*Server()->TickSpeed()*60)
				{
					//Logout player from rcon and member tile (copy of "ConLogOut")
//					GameServer()->m_apPlayers[i]->m_Authed = IConsole::CONSOLELEVEL_USER;
//					Server()->SetRconLevel(i, IConsole::CONSOLELEVEL_USER);
//					if (g_Config.m_SvRconScore)
//						GameServer()->m_apPlayers[i]->m_Score = 0;
//					GameServer()->m_apPlayers[i]->m_IsMember = false;
//					GameServer()->m_apPlayers[i]->m_IsLoggedIn = false;
//					//Set player as acted (to prevent instant inactive kick)
//					GameServer()->m_apPlayers[i]->m_LastActionTick = Server()->Tick();
				}
			}
		}
	}

	//DoWincheck();
}
Пример #10
0
void IGameController::Tick()
{
	// do warmup
	if(m_Warmup)
	{
		m_Warmup--;
		if(!m_Warmup)
			StartRound();
	}

	if(m_GameOverTick != -1)
	{
		// game over.. wait for restart
		if(Server()->Tick() > m_GameOverTick+Server()->TickSpeed()*10)
		{
			CycleMap();
			StartRound();
			m_RoundCount++;
		}
	}

	// game is Paused
	if(GameServer()->m_World.m_Paused)
		++m_RoundStartTick;

	// do team-balancing
	if(IsTeamplay() && m_UnbalancedTick != -1 && Server()->Tick() > m_UnbalancedTick+g_Config.m_SvTeambalanceTime*Server()->TickSpeed()*60)
	{
		GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", "Balancing teams");

		int aT[2] = {0,0};
		float aTScore[2] = {0,0};
		float aPScore[MAX_CLIENTS] = {0.0f};
		for(int i = 0; i < MAX_CLIENTS; i++)
		{
			if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
			{
				aT[GameServer()->m_apPlayers[i]->GetTeam()]++;
				aPScore[i] = GameServer()->m_apPlayers[i]->m_Score*Server()->TickSpeed()*60.0f/
					(Server()->Tick()-GameServer()->m_apPlayers[i]->m_ScoreStartTick);
				aTScore[GameServer()->m_apPlayers[i]->GetTeam()] += aPScore[i];
			}
		}

		// are teams unbalanced?
		if(absolute(aT[0]-aT[1]) >= 2)
		{
			int M = (aT[0] > aT[1]) ? 0 : 1;
			int NumBalance = absolute(aT[0]-aT[1]) / 2;

			do
			{
				CPlayer *pP = 0;
				float PD = aTScore[M];
				for(int i = 0; i < MAX_CLIENTS; i++)
				{
					if(!GameServer()->m_apPlayers[i] || !CanBeMovedOnBalance(i))
						continue;
					// remember the player who would cause lowest score-difference
					if(GameServer()->m_apPlayers[i]->GetTeam() == M && (!pP || absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i])) < PD))
					{
						pP = GameServer()->m_apPlayers[i];
						PD = absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i]));
					}
				}

				// move the player to the other team
				int Temp = pP->m_LastActionTick;
				pP->SetTeam(M^1);
				pP->m_LastActionTick = Temp;

				pP->Respawn();
				pP->m_ForceBalanced = true;
			} while (--NumBalance);

			m_ForceBalanced = true;
		}
		m_UnbalancedTick = -1;
	}

	// check for inactive players
	if(g_Config.m_SvInactiveKickTime > 0)
	{
		// dont kick bots
		for(int i = 0; i < FIRST_BOT_ID; ++i)
		{
		#ifdef CONF_DEBUG
			if(g_Config.m_DbgDummies)
			{
				if(i >= MAX_CLIENTS-g_Config.m_DbgDummies)
					break;
			}
		#endif
			if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && !Server()->IsAuthed(i))
			{
				if(Server()->Tick() > GameServer()->m_apPlayers[i]->m_LastActionTick+g_Config.m_SvInactiveKickTime*Server()->TickSpeed()*60)
				{
					switch(g_Config.m_SvInactiveKick)
					{
					case 0:
						{
							// move player to spectator
							GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
						}
						break;
					case 1:
						{
							// move player to spectator if the reserved slots aren't filled yet, kick him otherwise
							int Spectators = 0;
							for(int j = 0; j < FIRST_BOT_ID; ++j)
								if(GameServer()->m_apPlayers[j] && GameServer()->m_apPlayers[j]->GetTeam() == TEAM_SPECTATORS)
									++Spectators;
							if(Spectators >= g_Config.m_SvSpectatorSlots)
								Server()->Kick(i, "Kicked for inactivity");
							else
								GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
						}
						break;
					case 2:
						{
							// kick the player
							Server()->Kick(i, "Kicked for inactivity");
						}
					}
				}
			}
		}
	}

	DoWincheck();
}
Пример #11
0
void IGameController::Tick()
{
	// handle game states
	if(m_GameState != IGS_GAME_RUNNING)
	{
		if(m_GameStateTimer > 0)
			--m_GameStateTimer;

		if(m_GameStateTimer == 0)
		{
			// timer fires
			switch(m_GameState)
			{
			case IGS_WARMUP_USER:
				// end warmup
				SetGameState(IGS_WARMUP_USER, 0);
				break;
			case IGS_START_COUNTDOWN:
				// unpause the game
				SetGameState(IGS_GAME_RUNNING);
				break;
			case IGS_GAME_PAUSED:
				// end pause
				SetGameState(IGS_GAME_PAUSED, 0);
				break;
			case IGS_END_ROUND:
				// check if the match is over otherwise start next round
				DoWincheckMatch();
				if(m_GameState != IGS_END_MATCH)
					StartRound();
				break;
			case IGS_END_MATCH:
				// start next match
				CycleMap();
				StartMatch();
				m_MatchCount++;
				break;
			case IGS_WARMUP_GAME:
			case IGS_GAME_RUNNING:
				// not effected
				break;
			}
		}
		else
		{
			// timer still running
			switch(m_GameState)
 			{
			case IGS_WARMUP_USER:
				// check if player ready mode was disabled and it waits that all players are ready -> end warmup
				if(!g_Config.m_SvPlayerReadyMode && m_GameStateTimer == TIMER_INFINITE)
					SetGameState(IGS_WARMUP_USER, 0);
				break;
			case IGS_START_COUNTDOWN:
			case IGS_GAME_PAUSED:
				// freeze the game
				++m_GameStartTick;
				break;
			case IGS_WARMUP_GAME:
			case IGS_GAME_RUNNING:
			case IGS_END_MATCH:
			case IGS_END_ROUND:
				// not effected
				break;
 			}
		}
	}

	// do team-balancing (skip this in survival, done there when a round starts)
	if(IsTeamplay() && !(m_GameFlags&GAMEFLAG_SURVIVAL))
	{
		switch(m_UnbalancedTick)
		{
		case TBALANCE_CHECK:
			CheckTeamBalance();
			break;
		case TBALANCE_OK:
			break;
		default:
			if(Server()->Tick() > m_UnbalancedTick+g_Config.m_SvTeambalanceTime*Server()->TickSpeed()*60)
				DoTeamBalance();
		}
	}

	// check for inactive players
	DoActivityCheck();

	// win check
	if((m_GameState == IGS_GAME_RUNNING || m_GameState == IGS_GAME_PAUSED) && !GameServer()->m_World.m_ResetRequested)
	{
		if(m_GameFlags&GAMEFLAG_SURVIVAL)
			DoWincheckRound();
		else
			DoWincheckMatch();
	}
}
Пример #12
0
  void TestRoundBad(CreateRound good_cr, CreateRound bad_cr,
      const BadGuyCB &callback, bool client, bool will_finish)
  {
    int servers = 3, clients = 10;
    ConnectionManager::UseTimer = false;
    Timer::GetInstance().UseVirtualTime();
    OverlayNetwork net = ConstructOverlay(servers, clients);
    VerifyStoppedNetwork(net);
    StartNetwork(net);
    VerifyNetwork(net);

    Sessions sessions = BuildSessions(net, good_cr);
    // Find a bad guy and replace him...
    int badguy = Random::GetInstance().GetInt(0, clients);
    Id badid = net.second[badguy]->GetId();

    if(!client) {
      badguy = Random::GetInstance().GetInt(0, servers);
      badid = net.first[badguy]->GetId();
    }

    qDebug() << "Bad guy at" << badguy << badid;
    QSharedPointer<AsymmetricKey> key =
      sessions.private_keys[badid.ToString()];

    if(client) {
      ClientPointer cs = MakeSession<ClientSession>(
          net.second[badguy], key, sessions.keys, bad_cr);
      cs->SetSink(sessions.sink_multiplexers[servers + badguy].data());
      sessions.clients[badguy] = cs;
    } else {
      ServerPointer ss = MakeSession<ServerSession>(
          net.first[badguy], key, sessions.keys, bad_cr);
      ss->SetSink(sessions.sink_multiplexers[badguy].data());
      sessions.servers[badguy] = ss;
    }

    // Find a sender != badguy
    int sender = Random::GetInstance().GetInt(0, clients);
    if(client) {
      while(sender == badguy) {
        sender = Random::GetInstance().GetInt(0, clients);
      }
    }
    QByteArray msg(64, 0);
    CryptoRandom().GenerateBlock(msg);
    sessions.clients[sender]->Send(msg);

    qDebug() << "Starting sessions...";
    StartSessions(sessions);
    StartRound(sessions);

    QSharedPointer<Round> bad_round;
    if(client) {
      bad_round = sessions.clients[badguy]->GetRound();
    } else {
      bad_round = sessions.servers[badguy]->GetRound();
    }

    SignalCounter sc;
    for(int idx = 0; idx < servers; idx++) {
      QObject::connect(sessions.servers[idx].data(),
          SIGNAL(RoundFinished(const QSharedPointer<Anonymity::Round> &)),
          &sc, SLOT(Counter()));
    }

    for(int idx = 0; idx < clients; idx++) {
      QObject::connect(sessions.clients[idx].data(),
          SIGNAL(RoundFinished(const QSharedPointer<Anonymity::Round> &)),
          &sc, SLOT(Counter()));
    }

    RunUntil(sc, clients + servers);
    if(will_finish) {
      ASSERT_EQ(sc.GetCount(), clients + servers);
      ASSERT_EQ(bad_round->GetBadMembers().size(), 1);
      ASSERT_EQ(badid, bad_round->GetBadMembers()[0]);
    }

    if(!callback(bad_round.data())) {
      std::cout << "RoundTest_BadGuy was never triggered, "
        "consider rerunning." << std::endl;
    }

    StopNetwork(sessions.network);
    VerifyStoppedNetwork(sessions.network);
    ConnectionManager::UseTimer = true;
  }
Пример #13
0
void IGameController::Tick()
{
	// do warmup
	if(m_Warmup)
	{
		m_Warmup--;
		if(!m_Warmup)
			StartRound();
	}
	
	if(m_GameOverTick != -1)
	{
		// game over.. wait for restart
		if(Server()->Tick() > m_GameOverTick+Server()->TickSpeed()*10)
		{
			CycleMap();
			StartRound();
			m_RoundCount++;
		}
	}
	
	// do team-balancing
	if (IsTeamplay() && m_UnbalancedTick != -1 && Server()->Tick() > m_UnbalancedTick+g_Config.m_SvTeambalanceTime*Server()->TickSpeed()*60)
	{
		dbg_msg("game", "Balancing teams");
		
		int aT[2] = {0,0};
		float aTScore[2] = {0,0};
		float aPScore[MAX_CLIENTS] = {0.0f};
		for(int i = 0; i < MAX_CLIENTS; i++)
		{
			if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != -1)
			{
				aT[GameServer()->m_apPlayers[i]->GetTeam()]++;
				aPScore[i] = GameServer()->m_apPlayers[i]->m_Score*Server()->TickSpeed()*60.0f/
					(Server()->Tick()-GameServer()->m_apPlayers[i]->m_ScoreStartTick);
				aTScore[GameServer()->m_apPlayers[i]->GetTeam()] += aPScore[i];
			}
		}
		
		// are teams unbalanced?
		if(absolute(aT[0]-aT[1]) >= 2)
		{
			int M = (aT[0] > aT[1]) ? 0 : 1;
			int NumBalance = absolute(aT[0]-aT[1]) / 2;
			
			do
			{
				CPlayer *pP = 0;
				int PD = aTScore[M];
				for(int i = 0; i < MAX_CLIENTS; i++)
				{
					if(!GameServer()->m_apPlayers[i] || !CanBeMovedOnBalance(i))
						continue;
					// remember the player who would cause lowest score-difference
					if(GameServer()->m_apPlayers[i]->GetTeam() == M && (!pP || absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i])) < PD))
					{
						pP = GameServer()->m_apPlayers[i];
						PD = absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i]));
					}
				}
				
				// move the player to the other team
				pP->SetTeam(M^1);
				
				pP->Respawn();
				pP->m_ForceBalanced = true;
			} while (--NumBalance);
			
			m_ForceBalanced = true;
		}
		m_UnbalancedTick = -1;
	}
	
	// update browse info
	int Prog = -1;
	if(g_Config.m_SvTimelimit > 0)
		Prog = max(Prog, (Server()->Tick()-m_RoundStartTick) * 100 / (g_Config.m_SvTimelimit*Server()->TickSpeed()*60));

	if(g_Config.m_SvScorelimit)
	{
		if(IsTeamplay())
		{
			Prog = max(Prog, (m_aTeamscore[0]*100)/g_Config.m_SvScorelimit);
			Prog = max(Prog, (m_aTeamscore[1]*100)/g_Config.m_SvScorelimit);
		}
		else
		{
			for(int i = 0; i < MAX_CLIENTS; i++)
			{
				if(GameServer()->m_apPlayers[i])
					Prog = max(Prog, (GameServer()->m_apPlayers[i]->m_Score*100)/g_Config.m_SvScorelimit);
			}
		}
	}

	if(m_Warmup)
		Prog = -1;
		
	Server()->SetBrowseInfo(m_pGameType, Prog);
}
Пример #14
0
void IGameController::Tick()
{
	// do warmup
	if(m_Warmup)
	{
		m_Warmup--;
		if(!m_Warmup)
		{	
			if(IsTeamplay())
			{
				m_aTeamscore[TEAM_RED] = 0;
				m_aTeamscore[TEAM_BLUE] = 0;
			}
			IGameController::PostReset(true);
			StartRound();
		}
	}

	if(m_GameOverTick != -1)
	{
		// game over.. wait for restart
		if(Server()->Tick() > m_GameOverTick+Server()->TickSpeed()*3)
		{
			CycleMap();
			StartRound();
			m_RoundCount++;
		}
	}

	// game is Paused
	if(GameServer()->m_World.m_Paused)
		++m_RoundStartTick;


	// check for inactive players
	if(g_Config.m_SvInactiveKickTime > 0)
	{
		for(int i = 0; i < MAX_CLIENTS; ++i)
		{
		#ifdef CONF_DEBUG
			if(g_Config.m_DbgDummies)
			{
				if(i >= MAX_CLIENTS-g_Config.m_DbgDummies)
					break;
			}
		#endif
			if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && !Server()->IsAuthed(i))
			{
				if(Server()->Tick() > GameServer()->m_apPlayers[i]->m_LastActionTick+g_Config.m_SvInactiveKickTime*Server()->TickSpeed()*60)
				{
					switch(g_Config.m_SvInactiveKick)
					{
					case 0:
						{
							// move player to spectator
							GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
						}
						break;
					case 1:
						{
							// move player to spectator if the reserved slots aren't filled yet, kick him otherwise
							int Spectators = 0;
							for(int j = 0; j < MAX_CLIENTS; ++j)
								if(GameServer()->m_apPlayers[j] && GameServer()->m_apPlayers[j]->GetTeam() == TEAM_SPECTATORS)
									++Spectators;
							if(Spectators >= g_Config.m_SvSpectatorSlots)
								Server()->Kick(i, "Kicked for inactivity");
							else
								GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
						}
						break;
					case 2:
						{
							// kick the player
							Server()->Kick(i, "Kicked for inactivity");
						}
					}
				}
			}
		}
	}
	
	DoWincheck();
}
Пример #15
0
void StrandOfTheAncient::OnStart(){

	m_started = true;

	StartRound();
}