当前位置: 首页>>代码示例>>C++>>正文


C++ IBattle::GetHostIp方法代码示例

本文整理汇总了C++中IBattle::GetHostIp方法的典型用法代码示例。如果您正苦于以下问题:C++ IBattle::GetHostIp方法的具体用法?C++ IBattle::GetHostIp怎么用?C++ IBattle::GetHostIp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IBattle的用法示例。


在下文中一共展示了IBattle::GetHostIp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WriteScriptTxt

wxString Spring::WriteScriptTxt( IBattle& battle ) const
{
    wxLogMessage(_T("0 WriteScriptTxt called "));

    wxString ret;

    TDFWriter tdf(ret);

    // Start generating the script.
    tdf.EnterSection( _T("GAME") );

		tdf.Append( _T("HostIP"), battle.GetHostIp() );
			if ( battle.IsFounderMe() )
			{
					if ( battle.GetNatType() == NAT_Hole_punching ) tdf.Append( _T("HostPort"), battle.GetMyInternalUdpSourcePort() );
					else tdf.Append(_T("HostPort"), battle.GetHostPort() );
			}
			else
			{
					tdf.Append( _T("HostPort"), battle.GetHostPort() );
					if ( battle.GetNatType() == NAT_Hole_punching )
					{
						tdf.Append( _T("SourcePort"), battle.GetMyInternalUdpSourcePort() );
					}
					else if ( sett().GetClientPort() != 0)
					{
						tdf.Append( _T("SourcePort"), sett().GetClientPort() ); /// this allows to play with broken router by setting SourcePort to some forwarded port.
					}
			}
			tdf.Append( _T("IsHost"), battle.IsFounderMe() );

			tdf.Append(_T("MyPlayerName"), battle.GetMe().GetNick() );

			if ( !battle.IsFounderMe() )
			{
					tdf.LeaveSection();
					return ret;
			}

			/**********************************************************************************
																		Host-only section
			**********************************************************************************/

			tdf.AppendLineBreak();

			tdf.Append(_T("ModHash"), battle.LoadMod().hash );
			tdf.Append(_T("MapHash"), battle.LoadMap().hash );

			tdf.Append( _T("Mapname"), battle.GetHostMapName() );
			tdf.Append( _T("GameType"), battle.GetHostModName() );

			tdf.AppendLineBreak();

			switch ( battle.GetBattleType() )
			{
				case BT_Played: break;
				case BT_Replay:
				{
					wxString path = battle.GetPlayBackFilePath();
					if ( path.Find(_T("/")) != wxNOT_FOUND ) path.BeforeLast(_T('/'));
					tdf.Append( _T("DemoFile"), path );
					tdf.AppendLineBreak();
					break;
				}
				case BT_Savegame:
				{
					wxString path = battle.GetPlayBackFilePath();
					if ( path.Find(_T("/")) != wxNOT_FOUND ) path.BeforeLast(_T('/'));
					tdf.Append( _T("Savefile"), path );
					tdf.AppendLineBreak();
					break;
				}
				default:
                    wxLogDebugFunc( _T("") ); break;
			}

			long startpostype;
			battle.CustomBattleOptions().getSingleValue( _T("startpostype"), OptionsWrapper::EngineOption ).ToLong( &startpostype );

			std::vector<StartPos> remap_positions;
			if ( battle.IsProxy() && ( startpostype != IBattle::ST_Pick ) && ( startpostype != IBattle::ST_Choose ) )
			{
				std::set<int> parsedteams;
				unsigned int NumUsers = battle.GetNumUsers();
				unsigned int NumTeams = 0;
				for ( unsigned int i = 0; i < NumUsers; i++ )
				{
						User& usr = battle.GetUser( i );
						UserBattleStatus& status = usr.BattleStatus();
						if ( status.spectator ) continue;
						if ( parsedteams.find( status.team ) != parsedteams.end() ) continue; // skip duplicates
						parsedteams.insert( status.team );
						NumTeams++;
				}

				MapInfo infos = battle.LoadMap().info;
				unsigned int nummapstartpositions = infos.positions.size();
				unsigned int copysize = std::min( nummapstartpositions, NumTeams );
				remap_positions = std::vector<StartPos> ( infos.positions.begin(), infos.positions.begin() + copysize ); // only add the first x positions

//.........这里部分代码省略.........
开发者ID:tvo,项目名称:springlobby,代码行数:101,代码来源:spring.cpp

示例2: WriteScriptTxt

wxString Spring::WriteScriptTxt( IBattle& battle ) const
{
	wxLogMessage(_T("0 WriteScriptTxt called "));

	std::stringstream ret;

	LSL::TDF::TDFWriter tdf(ret);

	// Start generating the script.
	tdf.EnterSection("GAME");

	if ( battle.IsFounderMe() ) {
		tdf.Append("HostIP", ""); //Listen on all addresses for connections when hosting
		if ( battle.GetNatType() == NAT_Hole_punching ) tdf.Append("HostPort", battle.GetMyInternalUdpSourcePort() );
		else tdf.Append("HostPort", battle.GetHostPort() );
	} else {
		tdf.Append("HostIP", battle.GetHostIp() );
		tdf.Append("HostPort", battle.GetHostPort() );
		if ( battle.GetNatType() == NAT_Hole_punching ) {
			tdf.Append("SourcePort", battle.GetMyInternalUdpSourcePort() );
		} else if ( sett().GetClientPort() != 0) {
			tdf.Append("SourcePort", sett().GetClientPort() ); /// this allows to play with broken router by setting SourcePort to some forwarded port.
		}
	}
	tdf.Append("IsHost", battle.IsFounderMe() );

	User& me = battle.GetMe();
	tdf.Append("MyPlayerName", me.GetNick());

	if ( !me.BattleStatus().scriptPassword.empty() ) {
		tdf.Append("MyPasswd", me.BattleStatus().scriptPassword);
	}

	if ( !battle.IsFounderMe() ) {
		tdf.LeaveSection();
		return TowxString(ret.str());
	}

	/**********************************************************************************
																Host-only section
	**********************************************************************************/

	tdf.AppendLineBreak();

	tdf.Append("ModHash", battle.LoadMod().hash);
	tdf.Append("MapHash", battle.LoadMap().hash);

	tdf.Append("Mapname", battle.GetHostMapName());
	tdf.Append("GameType", battle.GetHostModName());

	tdf.AppendLineBreak();

	switch ( battle.GetBattleType() ) {
	case BT_Played:
		break;
	case BT_Replay: {
		wxString path = TowxString(battle.GetPlayBackFilePath());
		if ( path.Find(_T("/")) != wxNOT_FOUND ) path.BeforeLast(_T('/'));
		tdf.Append("DemoFile", STD_STRING(path));
		tdf.AppendLineBreak();
		break;
	}
	case BT_Savegame: {
		wxString path = TowxString(battle.GetPlayBackFilePath());
		if ( path.Find(_T("/")) != wxNOT_FOUND ) path.BeforeLast(_T('/'));
		tdf.Append("Savefile", STD_STRING(path));
		tdf.AppendLineBreak();
		break;
	}
	default:
		slLogDebugFunc("");
		break;
	}

	const long startpostype = LSL::Util::FromString<long>(
					  battle.CustomBattleOptions().getSingleValue("startpostype", LSL::Enum::EngineOption ));

	std::vector<LSL::StartPos> remap_positions;
	if ( battle.IsProxy() && ( startpostype != IBattle::ST_Pick ) && ( startpostype != IBattle::ST_Choose ) ) {
		std::set<int> parsedteams;
		unsigned int NumUsers = battle.GetNumUsers();
		unsigned int NumTeams = 0;
		for ( unsigned int i = 0; i < NumUsers; i++ ) {
			User& usr = battle.GetUser( i );
			UserBattleStatus& status = usr.BattleStatus();
			if ( status.spectator ) continue;
			if ( parsedteams.find( status.team ) != parsedteams.end() ) continue; // skip duplicates
			parsedteams.insert( status.team );
			NumTeams++;
		}

		LSL::MapInfo infos = battle.LoadMap().info;
		unsigned int nummapstartpositions = infos.positions.size();
		unsigned int copysize = std::min( nummapstartpositions, NumTeams );
		remap_positions = std::vector<LSL::StartPos> ( infos.positions.begin(), infos.positions.begin() + copysize ); // only add the first x positions

		if ( startpostype == IBattle::ST_Random ) {
			std::random_shuffle( remap_positions.begin(), remap_positions.end() ); // shuffle the positions
		}

//.........这里部分代码省略.........
开发者ID:jgleesawn,项目名称:springlobby,代码行数:101,代码来源:spring.cpp


注:本文中的IBattle::GetHostIp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。