示例#1
0
void Battle::StartHostedBattle()
{
	if ( UserExists( GetMe().GetNick() ) )
	{
		if ( IsFounderMe() )
		{
			if ( sett().GetBattleLastAutoControlState() )
			{
				FixTeamIDs( (IBattle::BalanceType)sett().GetFixIDMethod(), sett().GetFixIDClans(), sett().GetFixIDStrongClans(), sett().GetFixIDGrouping() );
				Autobalance( (IBattle::BalanceType)sett().GetBalanceMethod(), sett().GetBalanceClans(), sett().GetBalanceStrongClans(), sett().GetBalanceGrouping() );
				FixColours();
			}
			if ( IsProxy() )
			{
				if ( UserExists( GetProxy()) && !GetUser(GetProxy()).Status().in_game )
				{
					// DON'T set m_generating_script here, it will trick the script generating code to think we're the host
					wxString hostscript = spring().WriteScriptTxt( *this );
					try
					{
						wxString path = TowxString(SlPaths::GetDataDir()) + _T("relayhost_script.txt");
						if ( !wxFile::Access( path, wxFile::write ) ) {
								wxLogError( _T("Access denied to script.txt.") );
						}

						wxFile f( path, wxFile::write );
						f.Write( hostscript );
						f.Close();

					} catch (...) {}
					m_serv.SendScriptToProxy( hostscript );
				}
			}
			if( GetAutoLockOnStart() )
			{
				SetIsLocked( true );
				SendHostInfo( IBattle::HI_Locked );
			}
			sett().SetLastHostMap(TowxString(GetServer().GetCurrentBattle()->GetHostMapName()));
			sett().SaveSettings();
			if ( !IsProxy() ) GetServer().StartHostedBattle();
			else if ( UserExists( GetProxy() ) && GetUser(GetProxy()).Status().in_game ) // relayhost is already ingame, let's try to join it
			{
				StartSpring();
			}
		}
	}
}
示例#2
0
void Battle::StartHostedBattle()
{
	if ( UserExists( GetMe().GetNick() ) )
	{
		if ( IsFounderMe() )
		{
			if ( sett().GetBattleLastAutoControlState() )
			{
				FixTeamIDs( (IBattle::BalanceType)sett().GetFixIDMethod(), sett().GetFixIDClans(), sett().GetFixIDStrongClans(), sett().GetFixIDGrouping() );
				Autobalance( (IBattle::BalanceType)sett().GetBalanceMethod(), sett().GetBalanceClans(), sett().GetBalanceStrongClans(), sett().GetBalanceGrouping() );
				FixColours();
			}
			if ( IsProxy() )
			{
				wxString hostscript = spring().WriteScriptTxt( *this );
				try
				{
					wxString path = sett().GetCurrentUsedDataDir() + wxFileName::GetPathSeparator() + _T("relayhost_script.txt");
					if ( !wxFile::Access( path, wxFile::write ) ) {
							wxLogError( _T("Access denied to script.txt.") );
					}

					wxFile f( path, wxFile::write );
					f.Write( hostscript );
					f.Close();

				} catch (...) {}
				m_serv.SendScriptToProxy( hostscript );
			}
			if( IsFounderMe() && GetAutoLockOnStart() )
			{
				SetIsLocked( true );
				SendHostInfo( IBattle::HI_Locked );
			}
			sett().SetLastHostMap( GetServer().GetCurrentBattle()->GetHostMapName() );
			sett().SaveSettings();
			if ( !IsProxy() ) GetServer().StartHostedBattle();
		}
	}
}