Exemple #1
0
bool Spring::Run(const IBattlePtr battle )
{
    BF::path path = sett().GetCurrentUsedDataDir();
    path /= "script.txt";
    try {
        BF::ofstream f( path );
        if ( !f.is_open() ) {
            LslError( "Access denied to script.txt at %s", path.string().c_str() );
        }
        battle->DisableHostStatusInProxyMode( true );
        f << WriteScriptTxt(battle);
        battle->DisableHostStatusInProxyMode( false );
        f.close();
    }
    catch ( std::exception& e ) {
        LslError( "Couldn't write script.txt, exception caught:\n %s", e.what() );
        return false;
    }
    catch (...) {
        LslError( "Couldn't write script.txt" );
        return false;
    }

    std::string cmd;
    //! TODO
//    if ( battle->GetAutoHost().GetEnabled() )
//    {
//        // -m, --minimise          Start minimised
//        // -q [T], --quit=[T]      Quit immediately on game over or after T seconds
//        cmd = "--minimise";
//    }
    cmd += std::string(" \"" + path.string() +  "\"");
    return LaunchSpring( cmd );
}
bool SpringBundle::GetBundleVersion()
{
	if (!version.empty()) //get version only once
		return true;
	if (!Util::FileExists(unitsync)) {
		return false;
	}
	void* temphandle = _LoadLibrary(unitsync);
	if (temphandle == nullptr)
		return false;
	std::string functionname = "GetSpringVersion";
	GetSpringVersionPtr getspringversion = (GetSpringVersionPtr)GetLibFuncPtr(temphandle, functionname);
	if (!getspringversion) {
		_FreeLibrary(temphandle);
		LslError("getspringversion: function not found %s", unitsync.c_str());
		return false;
	}
	functionname = "IsSpringReleaseVersion";
	IsSpringReleaseVersionPtr isspringreleaseversion = (IsSpringReleaseVersionPtr)GetLibFuncPtr(temphandle, functionname);

	functionname = "GetSpringVersionPatchset";
	GetSpringVersionPatchsetPtr getspringversionpatcheset = (GetSpringVersionPatchsetPtr)GetLibFuncPtr(temphandle, functionname);

	version = getspringversion();
	if (isspringreleaseversion && getspringversionpatcheset && isspringreleaseversion()) {
		version += ".";
		version += getspringversionpatcheset();
	}
	_FreeLibrary(temphandle);
	return !version.empty();
}
bool OptionsWrapper::loadOptions(Enum::GameOption modmapFlag, const std::string& name)
{
	unLoadOptions(modmapFlag);
	GameOptions opt;
	switch (modmapFlag) {
		default:
			break;
		case Enum::MapOption:
			try {
				opt = usync().GetMapOptions(name);
			} catch (...) {
				LslError("Could not load map options");
				usync().FetchUnitsyncErrors(name);
				return false;
			}
			break;

		case Enum::ModOption:
			try {
				opt = usync().GetGameOptions(name);
			} catch (...) {
				LslError("Could not load game options");
				usync().FetchUnitsyncErrors(name);
				return false;
			}
			break;

		case Enum::EngineOption: {
			//TODO Fixed,random and so forth are intls
			mmOptionList startpos("Start Position Type", "startpostype", "How players will select where to be spawned in the map\n0: fixed map positions\n1: random map positions\n2: choose in game\n3: choose in the lobby before starting", "0");
			startpos.addItem("0", "Fixed", "Use the start positions defined in the map, the positions will be assigned incrementally from the team with lowest number to highest");
			startpos.addItem("1", "Random", "Use the start positions defined in the map, the positions will be assigned randomly");
			startpos.addItem("2", "Choose in-game", "Players will be able to pick their own starting point right before the game starts, optionally limited by a bounding box defined by the host");
			startpos.addItem("3", "Choose before game", "The host will place each player's start position in the map preview before the game is launched");
			opt.list_map["startpostype"] = startpos;
			break;
		}

		case Enum::PrivateOptions: {
			opt.string_map["restrictions"] = mmOptionString("List of restricted units", "restrictedunits", "Units in this list won't be available in game", "", 0); // tab separated list
			opt.string_map["mapname"] = mmOptionString("Map name", "mapname", "Map name", "", 0);
			break;
		}
	}
	m_opts[modmapFlag] = opt;
	return true;
}
Exemple #4
0
void TDFWriter::Close()
{
    while (m_depth > 0)
        LeaveSection();
    if (m_depth < 0) {
        LslError("error in TDFWriter usage: more LeaveSection() calls than EnterSection(). Please contact springlobby developers");
    }
}
Exemple #5
0
bool Spring::Run(const std::string& script)
{
    BF::path path = sett().GetCurrentUsedDataDir();
    path /= "script.txt";
    std::string cmd = std::string(" \"" + path.string() +  "\"");
    try {
        BF::ofstream f( path );
        if ( !f.is_open() ) {
            LslError( "Access denied to script.txt at %s", path.string().c_str() );
        }
        f << script;
        f.close();
    }
    catch ( std::exception& e ) {
        LslError( "Couldn't write script.txt, exception caught:\n %s", e.what() );
        return false;
    }
    catch (...) {
        LslError( "Couldn't write script.txt" );
        return false;
    }
    return LaunchSpring( cmd );
}
Exemple #6
0
bool Spring::LaunchSpring( const std::string& params  )
{
    if ( m_running )
    {
        LslError( "Spring already running!" );
        return false;
    }
    if ( !Util::FileExists( sett().GetCurrentUsedSpringBinary() ) ) {
        LslError( "spring binary not found at set location: %s", sett().GetCurrentUsedSpringBinary().c_str() );
        return false;
    }

    std::string configfileflags = sett().GetCurrentUsedSpringConfigFilePath();
    if ( !configfileflags.empty() )
    {
        configfileflags = "--config=\"" + configfileflags + "\" ";
    }

    std::string cmd =  "\"" + sett().GetCurrentUsedSpringBinary();
#ifdef __WXMAC__
    wxChar sep = wxFileName::GetPathSeparator();
    if ( sett().GetCurrentUsedSpringBinary().AfterLast('.') == "app" )
        cmd += sep + std::string("Contents") + sep + std::string("MacOS") + sep + std::string("spring"); // append app bundle inner path
#endif
    cmd += "\" " + configfileflags + params;

    LslDebug( "spring call params: %s", cmd.c_str() );
    if ( m_process == 0 )
        m_process = new SpringProcess( *this );
    m_process->Create();
    m_process->SetCommand( cmd );
    m_process->Run();

    m_running = true;
    return true;
}
Exemple #7
0
void* GetLibFuncPtr(void* libhandle, const std::string& name)
{
	if (libhandle == NULL)
		return NULL;

#if defined _WIN32
	void* p = (void*)GetProcAddress((HMODULE)libhandle, name.c_str());
#else  // defined _WIN32
	void* p = dlsym(libhandle, name.c_str());
#endif // else defined _WIN32

	if (p == NULL) {
		LslError("Couldn't load %s from unitsync library", name.c_str());
	}
	return p;
}
Exemple #8
0
void DataList::InsertRenameAt(PNode node, PNode where)
{   // rename if such entry already exists. str contains new name.
    if (!node.Ok())
        return;
    if (!where->list_prev)
        return;

    if (!InsertAt(node, where)) {
        for (int n = 0; n < 10000; ++n) {
            std::ostringstream os;
            os << node->Name() << rename_prefix << n;
            node->name = os.str();
            if (InsertAt(node, where)) {
                return;
            }
        }
        LslError("insertRename: iterated over 10 000 names, way too many");
    }
}
Exemple #9
0
void DataList::InsertRename(PNode node)
{   /// rename if such entry already exists. str contains new name.
    if (!node.Ok())
        return;

    if (!Insert(node)) {
        std::string original_name = node->Name();
        for (int n = 0; n < 10000; ++n) {
            //std::string tmp=str+std::string(rename_prefix);
            std::ostringstream os;
            os << original_name << rename_prefix << n;
            node->name = os.str();
            if (Insert(node)) {
                return;
            }
        }
        LslError("insertRename: iterated over 10 000 names, way too many");
    }
}
Exemple #10
0
void Tokenizer::ReportError(const Token& t, const std::string& err)
{
    LslError("TDF parsing error at (%s), on token \"%s\" : %s", t.pos_string.c_str(), t.value_s.c_str(), err.c_str());
    errors++;
}