コード例 #1
0
PlayerHandler::const_iterator NczPlayerManager::GetPlayerHandlerByName ( const char * playerName ) const
{
	const char * tName;

	for( PlayerHandler::const_iterator it ( PlayerHandler::begin () ); it != PlayerHandler::end (); ++it )
	{
		if( it )
		{
			tName = it->GetName ();
			if( strcmp ( tName, playerName ) ) return it;
		}
	}

	return PlayerHandler::end ();
}
コード例 #2
0
void NczPlayerManager::FireGameEvent ( SourceSdk::IGameEvent* ev )
/*
player_death
player_team
player_spawn
player_connect
player_disconnect
round_freeze_end
round_end
bot_takeover
*/
{
	const char* event_name ( ev->GetName () + 6 );
	const int maxcl ( m_max_index );

	if( *event_name == 'e' ) // round_end
	{
		DebugMessage("event round_end");
		for( int x ( 1 ); x <= maxcl; ++x )
		{
			PlayerHandler::const_iterator ph ( x );
			if( ph == SlotStatus::PLAYER_IN_TESTS )
			{
				ph.GetHandler()->status = SlotStatus::PLAYER_CONNECTED;
				ph.GetHandler()->in_tests_time = std::numeric_limits<float>::max ();
				DebugMessage(Helpers::format("Players %s : Status changed from PLAYER_IN_TESTS to PLAYER_CONNECTED", ph->GetName()));
			}
			/*else if( ph == SlotStatus::PLAYER_IN_TESTS_TAKEOVER )
			{
				ph->GetTakeover ()->StopBotTakeover ();
				ph->StopBotTakeover ();
				ph.GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
				ph.GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
			}*/
		}

		ProcessFilter::HumanAtLeastConnected filter_class;
		if( GetPlayerCount ( &filter_class ) == 0 ) AutoTVRecord::GetInstance ()->StopRecord ();

		BaseSystem::ManageSystems ();
		Logger::GetInstance ()->Flush ();

		return;
	}
	/*else*/ if( *event_name == 'f' ) // round_freeze_end = round_start
	{
		DebugMessage("event round_freeze_end");
		for( int x ( 1 ); x <= maxcl; ++x )
		{
			PlayerHandler& ph ( FullHandlersList[ x ] );
			if( ph.status == SlotStatus::INVALID ) continue;
			if( ph.status >= SlotStatus::PLAYER_CONNECTED )
			{
				ph.status = SlotStatus::PLAYER_CONNECTED;
				SourceSdk::IPlayerInfo * const pinfo ( ph.playerClass->GetPlayerInfo () );
				if( pinfo )
				{
					if( pinfo->GetTeamIndex () > 1 )
					{
						DebugMessage(Helpers::format("Players %s : Will enter in status PLAYER_IN_TESTS in 1 second", ph.playerClass->GetName()));
						ph.in_tests_time = Plat_FloatTime () + 1.0f;
					}
					else
					{
						ph.in_tests_time = std::numeric_limits<float>::max ();
					}
				}
			}
		}

		BaseSystem::ManageSystems ();
		return;
	}

	PlayerHandler::const_iterator ph ( GetPlayerHandlerByUserId ( ev->GetInt ( "userid" ) ) );

	if( *event_name == 'k' ) // bot_takeover
	{
		DebugMessage(Helpers::format("event bot_takeover : %s -> %s", ph->GetName (), GetPlayerHandlerByUserId ( ev->GetInt ( "botid" ) )->GetName ()));
		//PlayerHandler::const_iterator bh1 ( GetPlayerHandlerByUserId ( ev->GetInt ( "botid" ) ) );
		//PlayerHandler::const_iterator bh2 ( GetPlayerHandlerByUserId (  ) );
		//DebugMessage ( Helpers::format ( "Player %s taking control of bot %s or bot %d", ph->GetName (), bh1->GetName (), ev->GetInt ( "index" ) ));

		//ph->EnterBotTakeover ( ev->GetInt ( "index" ) );
		//bh2->EnterBotTakeover ( ph.GetIndex () );

		//ph.GetHandler ()->status = SlotStatus::PLAYER_IN_TESTS_TAKEOVER;
		//ph.GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();

		return;
	}

	++event_name;

	if( *event_name == 'c' ) // player_connect
	{
		if( ev->GetBool ( "bot" ) == false )
		{
			if( SourceSdk::InterfacesProxy::m_game == SourceSdk::CounterStrikeGlobalOffensive )
			{
				SourceSdk::IGameEvent_csgo* rev ( reinterpret_cast< SourceSdk::IGameEvent_csgo* >( ev ) );
				Logger::GetInstance ()->Msg<MSG_LOG> ( Helpers::format ( "Player connect : %s [%s]", rev->GetString ( "name", "unknown-name" ), rev->GetString ( "networkid", "unknown-networkid" ) ) );
			}
			else
			{
				Logger::GetInstance ()->Msg<MSG_LOG> ( Helpers::format ( "Player connect : %s [%s - %s]", ev->GetString ( "name", "unknown-name" ), ev->GetString ( "networkid", "unknown-networkid" ), ev->GetString ( "address", "unknown-address" ) ) );
			}
		}

		return;
	}
	if( *(event_name + 1) == 'i' ) // player_disconnect
	{
		if( ev->GetBool ( "bot" ) == false )
		{
			if( SourceSdk::InterfacesProxy::m_game == SourceSdk::CounterStrikeGlobalOffensive )
			{
				SourceSdk::IGameEvent_csgo* rev ( reinterpret_cast< SourceSdk::IGameEvent_csgo* >( ev ) );
				if( !rev->IsEmpty ( "name" ) )
				{
					Logger::GetInstance ()->Msg<MSG_LOG> ( Helpers::format ( "Player disconnect : %s [%s] -> Reason : %s", rev->GetString ( "name", "unknown-name" ), rev->GetString ( "networkid", "unknown-networkid" ), rev->GetString ( "reason", "unknown-reason" ) ) );
				}
			}
			else
			{
				Logger::GetInstance ()->Msg<MSG_LOG> ( Helpers::format ( "Player disconnect : %s [%s - %s] -> Reason : %s", ev->GetString ( "name", "unknown-name" ), ev->GetString ( "networkid", "unknown-networkid" ), ev->GetString ( "address", "unknown-address" ), ev->GetString ( "reason", "unknown-reason" ) ) );
			}
		}

		return;
	}
	if( *event_name == 's' ) // player_spawn(ed)
	{
		DebugMessage(Helpers::format("event player_spawn : %s", ph->GetName()));
		if( ph > SlotStatus::BOT )
		{
			SourceSdk::IPlayerInfo * const pinfo ( ph->GetPlayerInfo () );
			if( pinfo )
			{
				if( pinfo->GetTeamIndex () > 1 )
				{
					DebugMessage(Helpers::format("Players %s : Will enter in status PLAYER_IN_TESTS in 3 seconds", ph->GetName()));
					ph.GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
					ph.GetHandler ()->in_tests_time = Plat_FloatTime () + 3.0f;
				}
				else
				{
					DebugMessage(Helpers::format("Players %s : Status forced to PLAYER_CONNECTED", ph->GetName()));
					ph.GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
					ph.GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
				}
			}
		}
		else if( ph == SlotStatus::BOT )
		{
			/*if( ph->IsControllingBot () )
			{
				ph->GetTakeover ()->StopBotTakeover (); // release link from player to bot
				ph->GetTakeover ().GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
				ph->GetTakeover ().GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
				ph->StopBotTakeover (); // release link from bot to player
			}*/
		}
		BaseSystem::ManageSystems ();
		return;
	}
	if( *event_name == 't' ) // player_team
	{
		DebugMessage("event player_team");
		if( ph > SlotStatus::BOT )
		{
			if( ev->GetInt ( "teamid" ) > 1 )
			{
				DebugMessage(Helpers::format("Players %s : Will enter in status PLAYER_IN_TESTS in 3 seconds", ph->GetName()));
				ph.GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
				ph.GetHandler ()->in_tests_time = Plat_FloatTime () + 3.0f;
			}
			else
			{
				DebugMessage(Helpers::format("Players %s : Status forced to PLAYER_CONNECTED", ph->GetName()));
				ph.GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
				ph.GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
			}
		}
		else if( ph == SlotStatus::BOT )
		{
			/*if( ph->IsControllingBot () )
			{
				ph->GetTakeover ()->StopBotTakeover (); // release link from player to bot
				ph->GetTakeover ().GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
				ph->GetTakeover ().GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
				ph->StopBotTakeover (); // release link from bot to player
			}*/
		}
		BaseSystem::ManageSystems ();
		return;
	}
	//else // player_death
	//{

	DebugMessage(Helpers::format("event player_death : %s", ph->GetName()));
	if( ph == SlotStatus::BOT )
	{
		/*if( ph->IsControllingBot () ) // is bot controlled
		{
			ph->GetTakeover ()->StopBotTakeover (); // release link from player to bot
			ph->GetTakeover ().GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
			ph->GetTakeover ().GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
			ph->StopBotTakeover (); // release link from bot to player
		}*/
	}
	if( ph </*=*/ SlotStatus::PLAYER_CONNECTED ) /// fixed :  https://github.com/L-EARN/NoCheatZ-4/issues/79#issuecomment-240174457
		return;
	DebugMessage(Helpers::format("Players %s : Status forced to PLAYER_CONNECTED", ph->GetName()));
	ph.GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
	ph.GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
	BaseSystem::ManageSystems ();
	//}
}