예제 #1
0
bool IBattle::LoadOptionsPreset( const std::string& name )
{
	const std::string preset = FixPresetName(name);
	if (preset.empty()) return false; //preset not found
	m_preset = preset;

	for ( unsigned int i = 0; i < LSL::OptionsWrapper::LastOption; i++) {
		std::map<wxString,wxString> options = sett().GetHostingPreset( TowxString(m_preset), i );
		if ( (LSL::OptionsWrapper::GameOption)i != LSL::OptionsWrapper::PrivateOptions ) {
			for ( std::map<wxString,wxString>::const_iterator itor = options.begin(); itor != options.end(); ++itor ) {
				wxLogWarning( itor->first + _T(" ::: ") + itor->second );
				CustomBattleOptions().setSingleOption( STD_STRING(itor->first),
								       STD_STRING(itor->second),
								       (LSL::OptionsWrapper::GameOption)i );
			}
		} else {
			if ( !options[_T("mapname")].IsEmpty() ) {
				if (LSL::usync().MapExists(STD_STRING(options[_T("mapname")]))) {
					SetLocalMap( STD_STRING(options[_T("mapname")]) );
					SendHostInfo( HI_Map );
				} else if ( !ui().OnPresetRequiringMap( options[_T("mapname")] ) ) {
					//user didn't want to download the missing map, so set to empty to not have it tried to be loaded again
					options[_T("mapname")] = wxEmptyString;
					sett().SetHostingPreset( TowxString(m_preset), i, options );
				}
			}

			for( unsigned int j = 0; j <= GetLastRectIdx(); ++j ) {
				if ( GetStartRect( j ).IsOk() )
					RemoveStartRect(j); // remove all rects that might come from map presets
			}
			SendHostInfo( IBattle::HI_StartRects );

			unsigned int rectcount = s2l( options[_T("numrects")] );
			for ( unsigned int loadrect = 0; loadrect < rectcount; loadrect++) {
				int ally = s2l(options[_T("rect_") + TowxString(loadrect) + _T("_ally")]);
				if ( ally == 0 ) continue;
				AddStartRect( ally - 1, s2l(options[_T("rect_") + TowxString(loadrect) + _T("_left")]), s2l(options[_T("rect_") + TowxString(loadrect) + _T("_top")]), s2l(options[_T("rect_") + TowxString(loadrect) + _T("_right")]), s2l(options[_T("rect_") + TowxString(loadrect) + _T("_bottom")]) );
			}
			SendHostInfo( HI_StartRects );

			wxStringTokenizer tkr( options[_T("restrictions")], _T('\t') );
			m_restricted_units.clear();
			while( tkr.HasMoreTokens() ) {
				wxString unitinfo = tkr.GetNextToken();
				RestrictUnit( STD_STRING(unitinfo.BeforeLast(_T('='))), s2l( unitinfo.AfterLast(_T('=')) ) );
			}
			SendHostInfo( HI_Restrictions );
			Update( wxFormat( _T("%d_restrictions") ) % LSL::OptionsWrapper::PrivateOptions );

		}
	}
	SendHostInfo( HI_Send_All_opts );
	ui().ReloadPresetList();
	return true;
}
예제 #2
0
파일: battle.cpp 프로젝트: tvo/springlobby
void Battle::LoadMapDefaults( const wxString& mapname )
{
	CustomBattleOptions().setSingleOption( _T("startpostype"), sett().GetMapLastStartPosType( mapname ), OptionsWrapper::EngineOption );
	SendHostInfo( wxString::Format( _T("%d_startpostype"), OptionsWrapper::EngineOption ) );

	for( unsigned int i = 0; i <= GetLastRectIdx(); ++i ) if ( GetStartRect( i ).IsOk() ) RemoveStartRect(i); // remove all rects
	SendHostInfo( IBattle::HI_StartRects );

	std::vector<Settings::SettStartBox> savedrects = sett().GetMapLastRectPreset( mapname );
	for ( std::vector<Settings::SettStartBox>::iterator itor = savedrects.begin(); itor != savedrects.end(); itor++ )
	{
		AddStartRect( itor->ally, itor->topx, itor->topy, itor->bottomx, itor->bottomy );
	}
	SendHostInfo( IBattle::HI_StartRects );
}
예제 #3
0
void IBattle::ForceSpectator( User& user, bool spectator )
{
	if ( IsFounderMe() || user.BattleStatus().IsBot() ) {
		UserBattleStatus& status = user.BattleStatus();

		if ( !status.spectator ) { // leaving spectator status
			PlayerJoinedTeam( status.team );
			PlayerJoinedAlly( status.ally );
			if ( status.ready && !status.IsBot() ) m_players_ready++;
		}

		if (spectator) { // entering spectator status
			PlayerLeftTeam( status.team );
			PlayerLeftAlly( status.ally );
			if ( status.ready && !status.IsBot() ) m_players_ready--;
		}

		if ( IsFounderMe() ) {
			if ( status.spectator != spectator ) {
				if ( spectator ) {
					m_opts.spectators++;
				} else {
					m_opts.spectators--;
				}
				SendHostInfo( HI_Spectators );
			}
		}
		user.BattleStatus().spectator = spectator;
	}
}
예제 #4
0
void IBattle::OnUserRemoved( User& user )
{
	UserBattleStatus& bs = user.BattleStatus();
	if ( !bs.spectator ) {
		PlayerLeftTeam( bs.team );
		PlayerLeftAlly( bs.ally );
	}
	if ( !bs.spectator && !bs.IsBot() ) {
		if ( bs.ready ) m_players_ready--;
		if ( bs.sync ) m_players_sync--;
		if ( bs.ready && bs.sync ) m_players_ok--;
	}
	if ( IsFounderMe() && bs.spectator ) {
		m_opts.spectators--;
		SendHostInfo( HI_Spectators );
	}
	if ( &user == &GetMe() ) {
		OnSelfLeftBattle();
	}
	UserList::RemoveUser( user.GetNick() );
	if ( !bs.IsBot() )
		user.SetBattle( 0 );
	else {
		UserVecIter itor = m_internal_bot_list.find( user.GetNick());
		if ( itor != m_internal_bot_list.end() ) {
			m_internal_bot_list.erase( itor );
		}
	}
}
예제 #5
0
void SinglePlayerBattle::SendHostInfo( HostInfo update )
{
  if ( (update & HI_StartType) != 0 ) m_sptab.UpdateMinimap();
  if ( (update & HI_Restrictions) != 0 ) m_sptab.ReloadRestrictions();
  if ( (update & HI_Map_Changed) != 0 )
  {
	LoadMap();
    m_sptab.ReloadMapOptContrls();
	Update(  wxFormat(_T("%d_%s") ) % LSL::OptionsWrapper::PrivateOptions % _T("mapname") );
  }
  if ( (update & HI_Mod_Changed) != 0 )
  {
    RemoveUnfittingBots();
	LoadMod();
    wxString presetname = sett().GetModDefaultPresetName( GetHostModName() );
    if ( !presetname.IsEmpty() )
    {
      LoadOptionsPreset( presetname );
      SendHostInfo( HI_Send_All_opts );
    }
    m_sptab.ReloadModOptContrls();
	Update(  wxFormat(_T("%d_%s") ) % LSL::OptionsWrapper::PrivateOptions % _T("modname") );
  }
  if ( (update & HI_Send_All_opts) != 0 )
  {
    for ( int i = 0; i < (int)LSL::OptionsWrapper::LastOption; i++)
    {
      for (const auto pair : CustomBattleOptions().getOptionsMap( (LSL::OptionsWrapper::GameOption)i))
      {
        Update(  wxFormat(_T("%d_%s") ) % i % pair.first );
      }
    }
  }
}
void SinglePlayerBattle::SendHostInfo( HostInfo update )
{
  if ( (update & HI_StartType) != 0 ) m_sptab.UpdateMinimap();
  if ( (update & HI_Restrictions) != 0 ) m_sptab.ReloadRestrictions();
  if ( (update & HI_Map_Changed) != 0 )
  {
	LoadMap();
    m_sptab.ReloadMapOptContrls();
	Update(  wxFormat(_T("%d_%s") ) % OptionsWrapper::PrivateOptions % _T("mapname") );
  }
  if ( (update & HI_Mod_Changed) != 0 )
  {
    RemoveUnfittingBots();
	LoadMod();
    wxString presetname = sett().GetModDefaultPresetName( GetHostModName() );
    if ( !presetname.IsEmpty() )
    {
      LoadOptionsPreset( presetname );
      SendHostInfo( HI_Send_All_opts );
    }
    m_sptab.ReloadModOptContrls();
	Update(  wxFormat(_T("%d_%s") ) % OptionsWrapper::PrivateOptions % _T("modname") );
  }
  if ( (update & HI_Send_All_opts) != 0 )
  {
    for ( int i = 0; i < (int)OptionsWrapper::LastOption; i++)
    {
      const std::map<wxString,wxString>& options = CustomBattleOptions().getOptionsMap( (OptionsWrapper::GameOption)i );
      for ( std::map<wxString,wxString>::const_iterator itor = options.begin(); itor != options.end(); ++itor )
      {
		Update(  wxFormat(_T("%d_%s") ) % i % itor->first );
      }
    }
  }
}
예제 #7
0
void IBattle::OnUserBattleStatusUpdated( User &user, UserBattleStatus status )
{

    UserBattleStatus previousstatus = user.BattleStatus();

    user.UpdateBattleStatus( status );
	unsigned int oldspeccount = m_opts.spectators;
	m_opts.spectators = 0;
	m_players_sync = 0;
	m_players_ready = 0;
	m_players_ok = 0;
	m_teams_sizes.clear();
	m_ally_sizes.clear();
	for ( unsigned int i = 0; i < GetNumUsers(); i++ )
	{
		User& loopuser = GetUser( i );
		UserBattleStatus& loopstatus = loopuser.BattleStatus();
		if ( loopstatus.spectator ) m_opts.spectators++;
		if ( !loopstatus.IsBot() )
		{
			if ( !loopstatus.spectator )
			{
				if ( loopstatus.ready && loopstatus.spectator ) m_players_ready++;
				if ( loopstatus.sync ) m_players_sync++;
				if ( loopstatus.ready && loopstatus.sync ) m_players_ok++;
				PlayerJoinedTeam( loopstatus.team );
				PlayerJoinedAlly( loopstatus.ally );
			}
		}
	}
	if ( oldspeccount != m_opts.spectators  )
	{
		if ( IsFounderMe() ) SendHostInfo( HI_Spectators );
	}
	if ( !status.IsBot() )
	{
		if ( ( status.ready && status.sync ) || status.spectator )
		{
			std::map<wxString, time_t>::iterator itor = m_ready_up_map.find( user.GetNick() );
			if ( itor != m_ready_up_map.end() )
			{
				m_ready_up_map.erase( itor );
			}
		}
		if ( ( !status.ready || !status.sync ) && !status.spectator )
		{
			std::map<wxString, time_t>::iterator itor = m_ready_up_map.find( user.GetNick() );
			if ( itor == m_ready_up_map.end() )
			{
				m_ready_up_map[user.GetNick()] = time(0);
			}
		}
	}
}
예제 #8
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();
			}
		}
	}
}
void SinglePlayerBattle::SendHostInfo(HostInfo update)
{
	if ((update & HI_StartType) != 0)
		m_sptab.UpdateMinimap();
	if ((update & HI_Restrictions) != 0)
		m_sptab.ReloadRestrictions();
	if ((update & HI_Map_Changed) != 0) {
		LoadMap();
		m_sptab.ReloadMapOptContrls();
	}
	if ((update & HI_Game_Changed) != 0) {
		RemoveUnfittingBots();
		LoadGame();
		wxString presetname = sett().GetModDefaultPresetName(TowxString(GetHostGameName()));
		if (!presetname.IsEmpty()) {
			LoadOptionsPreset(STD_STRING(presetname));
			SendHostInfo(HI_Send_All_opts);
		}
		m_sptab.ReloadModOptContrls();
	}
}
예제 #10
0
파일: battle.cpp 프로젝트: tvo/springlobby
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();
		}
	}
}