Exemplo n.º 1
0
    Status storeMongoDumpOptions(const moe::Environment& params,
                                 const std::vector<std::string>& args) {
        Status ret = storeGeneralToolOptions(params, args);
        if (!ret.isOK()) {
            return ret;
        }

        mongoDumpGlobalParams.repair = hasParam("repair");
        if (mongoDumpGlobalParams.repair){
            if (!hasParam("dbpath")) {
                return Status(ErrorCodes::BadValue, "repair mode only works with --dbpath");
            }

            if (!hasParam("db")) {
                return Status(ErrorCodes::BadValue,
                              "repair mode only works on 1 db at a time right now");
            }
        }
        mongoDumpGlobalParams.query = getParam("query");
        mongoDumpGlobalParams.useOplog = hasParam("oplog");
        if (mongoDumpGlobalParams.useOplog) {
            if (hasParam("query") || hasParam("db") || hasParam("collection")) {
                return Status(ErrorCodes::BadValue, "oplog mode is only supported on full dumps");
            }
        }
        mongoDumpGlobalParams.outputFile = getParam("out");
        mongoDumpGlobalParams.snapShotQuery = false;
        if (!hasParam("query") && !hasParam("dbpath") && !hasParam("forceTableScan")) {
            mongoDumpGlobalParams.snapShotQuery = true;
        }

        // Make the default db "" if it was not explicitly set
        if (!params.count("db")) {
            toolGlobalParams.db = "";
        }

        if (mongoDumpGlobalParams.outputFile == "-") {
            // write output to standard error to avoid mangling output
            // must happen early to avoid sending junk to stdout
            toolGlobalParams.canUseStdout = false;
        }

        return Status::OK();
    }
Exemplo n.º 2
0
int Scenario::loadMapBuf(string mapn) {
    mapname=mapn;
    ifstream mapfile;
    string tmpline;
    string loadfile=config.datadir+mapname;

    mapfile.open(loadfile.c_str());
    if (mapfile) {
        cout << "Loading new map: " << loadfile << endl;
    } else {
        cout << "Map loading failed: " << loadfile << " not found!\n";
        return 2;
    }

    mapbuf.clear();

    /* We parse the parameters to add a name if it was missing
       This whole file reading looks much more complicated because
       of this (otherwise there would only be mapbuf.push_back(tmpline) */
    string cname;
    Uint16 x,y;
    ParameterMap parameters;
    bool header=true;
    std::map<string,Uint16> namecount;
    while (getline(mapfile,tmpline)) {
        if (header) {
            mapbuf.push_back(tmpline);
            std::istringstream tmpstream(tmpline);
            tmpstream >> cname;
            if (cname[0]=='#') {
                if (cname=="#ENDHEADER") header=false;
                continue;
            }
        } else {
            cname.erase();
            x=y=0;
            std::istringstream tmpstream(tmpline);
            tmpstream >> cname >> x >> y;

            if (cname.empty() || cname[0]=='#') {
                mapbuf.push_back(tmpline);
                continue;
            } else {
                namecount[cname]++;
            }

            string parameterlist((istreambuf_iterator<char>(tmpstream)), istreambuf_iterator<char>());
            parameters=getParameters(parameterlist);
            if (!hasParam(parameters,"name")) {
                if (parameters.empty()) tmpline+=" name="+cname+itos(namecount[cname]);
                else tmpline+=", name="+cname+itos(namecount[cname]);
            }
            mapbuf.push_back(tmpline);
        }
    }
Exemplo n.º 3
0
Object* ObjectsPool::addObjectbyName(const string& obj, Sint16 x, Sint16 y, const ParameterMap& objparam, bool outside) {
    ParameterMap parameters;
    if (hasParam(objparam,"file")) {
        parameters=getFileParameters(objparam.find("file")->second);
        ParameterMap::const_iterator it=objparam.begin();
        while (it!=objparam.end()) {
            if (it->first!="file") parameters[it->first]=it->second;
            ++it;
        }
    } else {
        parameters=objparam;
    }
    //Set names...
    if (!hasParam(parameters,"name")) parameters["name"]=getNextObjectName(obj);

    if      (obj=="Wall")           return (addObject(new Wall(x,y,parameters), outside));
    else if (obj=="Exit")           return (addObject(new Exit(x,y,parameters), outside));
    else if (obj=="Water")          return (addObject(new Water(x,y,parameters), outside));
    else if (obj=="Teleporter")     return (addObject(new Teleporter(x,y,parameters), outside));
    else if (obj=="Wind")           return (addObject(new Wind(x,y,parameters), outside));
    else if (obj=="Geyser")         return (addObject(new Geyser(x,y,parameters), outside));
    else if (obj=="Trigger")        return (addObject(new Trigger(x,y,parameters), outside));
    else if (obj=="Door")           return (addObject(new Door(x,y,parameters), outside));
    else if (obj=="Spike")          return (addObject(new Spike(x,y,parameters), outside));
    else if (obj=="Heart")          return (addObject(new Heart(x,y,parameters), outside));
    else if (obj=="Key")            return (addObject(new Key(x,y,parameters), outside));
    else if (obj=="Bomb")           return (addObject(new Bomb(x,y,parameters), outside));
    else if (obj=="TriggeredBomb")  return (addObject(new TriggeredBomb(x,y,parameters), outside));
    else if (obj=="DeadPlayer")     return (addObject(new DeadPlayer(x,y,parameters), outside));
    else if (obj=="Erik")           return (addObject(new Erik(x,y,parameters), outside));
    else if (obj=="Olaf")           return (addObject(new Olaf(x,y,parameters), outside));
    else if (obj=="Baleog")         return (addObject(new Baleog(x,y,parameters), outside));
    else if (obj=="Fang")           return (addObject(new Fang(x,y,parameters), outside));  
    else if (obj=="Scorch")         return (addObject(new Scorch(x,y,parameters), outside));
    else if (obj=="Plant")          return (addObject(new Plant(x,y,parameters), outside));
    else if (obj=="Zombie")         return (addObject(new Zombie(x,y,parameters), outside));
    else {
        cout << "Object " << obj << " unknown, skipping...\n";
        return NULL;
    }
}
Exemplo n.º 4
0
    Status storeMongoExportOptions(const moe::Environment& params,
                                   const std::vector<std::string>& args) {
        Status ret = storeGeneralToolOptions(params, args);
        if (!ret.isOK()) {
            return ret;
        }

        ret = storeFieldOptions(params, args);
        if (!ret.isOK()) {
            return ret;
        }

        mongoExportGlobalParams.outputFile = getParam("out");
        mongoExportGlobalParams.outputFileSpecified = hasParam("out");
        mongoExportGlobalParams.csv = hasParam("csv");
        mongoExportGlobalParams.jsonArray = hasParam("jsonArray");
        mongoExportGlobalParams.query = getParam("query", "");
        mongoExportGlobalParams.snapShotQuery = false;
        if (!hasParam("query") && !hasParam("dbpath") && !hasParam("forceTableScan")) {
            mongoExportGlobalParams.snapShotQuery = true;
        }
        mongoExportGlobalParams.slaveOk = toolsParsedOptions["slaveOk"].as<bool>();
        mongoExportGlobalParams.limit = getParam("limit", 0);
        mongoExportGlobalParams.skip = getParam("skip", 0);

        return Status::OK();
    }
Exemplo n.º 5
0
    Status storeMongoStatOptions(const moe::Environment& params,
                                 const std::vector<std::string>& args) {
        Status ret = storeGeneralToolOptions(params, args);
        if (!ret.isOK()) {
            return ret;
        }

        if (hasParam("http")) {
            mongoStatGlobalParams.http = true;
            toolGlobalParams.noconnection = true;
        }

        if (hasParam("host") && getParam("host").find(',') != string::npos) {
            toolGlobalParams.noconnection = true;
            mongoStatGlobalParams.many = true;
        }

        if (hasParam("discover")) {
            mongoStatGlobalParams.discover = true;
            mongoStatGlobalParams.many = true;
        }

        mongoStatGlobalParams.showHeaders = !hasParam("noheaders");
        mongoStatGlobalParams.rowCount = getParam("rowcount", 0);
        mongoStatGlobalParams.sleep = getParam("sleep", 1);
        mongoStatGlobalParams.allFields = hasParam("all");

        // Make the default db "admin" if it was not explicitly set
        if (!toolsParsedOptions.count("db")) {
            toolGlobalParams.db = "admin";
        }

        // Make the default db "admin" if it was not explicitly set
        if (!toolsParsedOptions.count("db")) {
            toolGlobalParams.db = "admin";
        }

        return Status::OK();
    }
Exemplo n.º 6
0
        int runNormal() {
            bool showHeaders = ! hasParam( "noheaders" );
            int rowCount = getParam( "rowcount" , 0 );
            int rowNum = 0;

            auth();

            BSONObj prev = stats();
            if ( prev.isEmpty() )
                return -1;

            int maxLockedDbWidth = 0;

            while ( rowCount == 0 || rowNum < rowCount ) {
                sleepsecs((int)ceil(_statUtil.getSeconds()));
                BSONObj now;
                try {
                    now = stats();
                }
                catch ( std::exception& e ) {
                    cout << "can't get data: " << e.what() << endl;
                    continue;
                }

                if ( now.isEmpty() )
                    return -2;

                try {

                    BSONObj out = _statUtil.doRow( prev , now );

                    // adjust width up as longer 'locked db' values appear
                    setMaxLockedDbWidth( &out, &maxLockedDbWidth ); 
                    if ( showHeaders && rowNum % 10 == 0 ) {
                        printHeaders( out );
                    }

                    printData( out , out );

                }
                catch ( AssertionException& e ) {
                    cout << "\nerror: " << e.what() << "\n"
                         << now
                         << endl;
                }

                prev = now;
                rowNum++;
            }
            return 0;
        }
Exemplo n.º 7
0
    Status storeBSONToolOptions(const moe::Environment& params,
                                const std::vector<std::string>& args) {

        bsonToolGlobalParams.objcheck = true;

        if (hasParam("objcheck") && hasParam("noobjcheck")) {
            return Status(ErrorCodes::BadValue, "can't have both --objcheck and --noobjcheck");
        }

        if (hasParam("objcheck")) {
            bsonToolGlobalParams.objcheck = true;
        }
        else if (hasParam("noobjcheck")) {
            bsonToolGlobalParams.objcheck = false;
        }

        if (hasParam("filter")) {
            bsonToolGlobalParams.hasFilter = true;
            bsonToolGlobalParams.filter = getParam("filter");
        }

        return Status::OK();
    }
    Status storeMongoFilesOptions(const moe::Environment& params,
                                  const std::vector<std::string>& args) {
        Status ret = storeGeneralToolOptions(params, args);
        if (!ret.isOK()) {
            return ret;
        }

        mongoFilesGlobalParams.command = getParam("command");
        mongoFilesGlobalParams.gridFSFilename = getParam("file");
        mongoFilesGlobalParams.localFile = getParam("local", mongoFilesGlobalParams.gridFSFilename);
        mongoFilesGlobalParams.contentType = getParam("type", "");
        mongoFilesGlobalParams.replace = hasParam("replace");

        return Status::OK();
    }
Exemplo n.º 9
0
    bool Tool::isMaster() {
        if ( hasParam("dbpath") ) {
            return true;
        }

        BSONObj info;
        bool isMaster;
        bool ok = conn().isMaster(isMaster, &info);

        if (ok && !isMaster) {
            cerr << "ERROR: trying to write to non-master " << conn().toString() << endl;
            cerr << "isMaster info: " << info << endl;
            return false;
        }

        return true;
    }
Exemplo n.º 10
0
    Status storeMongoTopOptions(const moe::Environment& params,
                                const std::vector<std::string>& args) {
        Status ret = storeGeneralToolOptions(params, args);
        if (!ret.isOK()) {
            return ret;
        }

        mongoTopGlobalParams.sleep = getParam("sleep", 1);
        mongoTopGlobalParams.useLocks = hasParam("locks");

        // Make the default db "admin" if it was not explicitly set
        if (!params.count("db")) {
            toolGlobalParams.db = "admin";
        }

        return Status::OK();
    }
Exemplo n.º 11
0
    Status storeMongoOplogOptions(const moe::Environment& params,
                                  const std::vector<std::string>& args) {
        Status ret = storeGeneralToolOptions(params, args);
        if (!ret.isOK()) {
            return ret;
        }

        if (!hasParam("from")) {
            return Status(ErrorCodes::BadValue, "need to specify --from");
        }
        else {
            mongoOplogGlobalParams.from = getParam("from");
        }

        mongoOplogGlobalParams.seconds = getParam("seconds", 86400);
        mongoOplogGlobalParams.ns = getParam("oplogns");

        return Status::OK();
    }
Exemplo n.º 12
0
    Status storeMongoImportOptions(const moe::Environment& params,
                                   const std::vector<std::string>& args) {
        Status ret = storeGeneralToolOptions(params, args);
        if (!ret.isOK()) {
            return ret;
        }

        ret = storeFieldOptions(params, args);
        if (!ret.isOK()) {
            return ret;
        }

        mongoImportGlobalParams.filename = getParam("file");
        mongoImportGlobalParams.drop = hasParam("drop");
        mongoImportGlobalParams.ignoreBlanks = hasParam("ignoreBlanks");

        if (hasParam("upsert") || hasParam("upsertFields")) {
            mongoImportGlobalParams.upsert = true;

            string uf = getParam("upsertFields");
            if (uf.empty()) {
                mongoImportGlobalParams.upsertFields.push_back("_id");
            }
            else {
                StringSplitter(uf.c_str(), ",").split(mongoImportGlobalParams.upsertFields);
            }
        }
        else {
            mongoImportGlobalParams.upsert = false;
        }

        mongoImportGlobalParams.doimport = !hasParam("noimport");
        mongoImportGlobalParams.type = getParam("type", "json");
        mongoImportGlobalParams.jsonArray = hasParam("jsonArray");
        mongoImportGlobalParams.headerLine = hasParam("headerline");
        mongoImportGlobalParams.stopOnError = hasParam("stopOnError");

        return Status::OK();
    }
Exemplo n.º 13
0
void OMLItem::_extractCheckClosed(const std::wstring& text, std::wstring::size_type posClose)
{
	// Se il tag [img] non ha il parametro 'src', mi aspetto una chiusura, poich il suo body sar il parametro 'src'.
	if( ( (m_tagName == _S("img")) && (hasParam(_S("src"))) ) ||
		(m_tagName == _S("br")) ||
		(m_tagName == _S("hr")) )
	{
		m_directClose = true;
	}
	else
	{
		// Alcuni tag non sono chiudibili direttamente.
		// Copre anche l'eccezione (Issue:10)
		if( (m_tagName == _S("url")) )
		{			
			m_directClose = false;
		}
		else
		{
			m_directClose = ( (posClose>0) && (text[posClose-1] == chForwardSlash) );
		}
	}
}
Exemplo n.º 14
0
Monster::Monster(Sint16 xcord, Sint16 ycord, const ParameterMap& param):
  Character(xcord,ycord,param),
  Dai(0),
  Dattack(0) {
    state=STATE_FALL;
    otype|=OTYPE_MONSTER;
    enemy_types|=OTYPE_PLAYER;
    dense_types|=OTYPE_PLAYER;

    /* Parameters */
    if (hasParam(parameters,"anim_left")) anim_left=loadAnimation(getParameters(parameters["anim_left"],':'));
      else anim_left.reset(new EmptyAnimation(&anim_right));
    if (hasParam(parameters,"anim_right")) anim_right=loadAnimation(getParameters(parameters["anim_right"],':'));
      else anim_right.reset(new EmptyAnimation(&anim_orig));
    if (!hasParam(parameters,"maxhealth")) maxhealth=1;
    if (!hasParam(parameters,"health")) health=min(1,(int)maxhealth);
    if (!hasParam(parameters,"maxspeedx")) maxspeedx=50;
    if (!hasParam(parameters,"maxspeedy")) maxspeedy=0;
    if (hasParam(parameters,"audio_hit")) au_hit=scenario->sndcache->loadWAV(parameters["audio_hit"]);
      else au_hit=scenario->sndcache->loadWAV("monhit.wav");

    animation.reset(new EmptyAnimation((state&STATE_LEFT) ? &anim_left : &anim_right));
}
Exemplo n.º 15
0
Erik::Erik(Sint16 xcord, Sint16 ycord, const ParameterMap& param):
  Player(xcord,ycord,param),
  jump(V_JUMP),
  jump2(V_JUMP2) {
    weapon=Weapon(-1,W_PRESSURE,WS_PRESSURE);

    /* Parameters */
    if (hasParam(parameters,"anim_erik_jump_left"))          anim_erik_jump_left=loadAnimation(getParameters(parameters["anim_erik_jump_left"],':'));
    if (hasParam(parameters,"anim_erik_jump_right"))         anim_erik_jump_right=loadAnimation(getParameters(parameters["anim_erik_jump_right"],':'));
    if (hasParam(parameters,"anim_erik_jump2_left"))         anim_erik_jump2_left=loadAnimation(getParameters(parameters["anim_erik_jump2_left"],':'));
    if (hasParam(parameters,"anim_erik_jump2_right"))        anim_erik_jump2_right=loadAnimation(getParameters(parameters["anim_erik_jump2_right"],':'));
    if (hasParam(parameters,"anim_erik_start_run_left"))     anim_erik_start_run_left=loadAnimation(getParameters(parameters["anim_erik_start_run_left"],':'));
    if (hasParam(parameters,"anim_erik_start_run_right"))    anim_erik_start_run_right=loadAnimation(getParameters(parameters["anim_erik_start_run_right"],':'));
    if (hasParam(parameters,"anim_erik_run_left"))           anim_erik_run_left=loadAnimation(getParameters(parameters["anim_erik_run_left"],':'));
    if (hasParam(parameters,"anim_erik_run_right"))          anim_erik_run_right=loadAnimation(getParameters(parameters["anim_erik_run_right"],':'));
    if (hasParam(parameters,"anim_erik_swim_left"))          anim_erik_swim_left=loadAnimation(getParameters(parameters["anim_erik_swim_left"],':'));
    if (hasParam(parameters,"anim_erik_swim_right"))         anim_erik_swim_right=loadAnimation(getParameters(parameters["anim_erik_swim_right"],':'));
    if (hasParam(parameters,"anim_erik_swim_up_left"))       anim_erik_swim_up_left=loadAnimation(getParameters(parameters["anim_erik_swim_up_left"],':'));
    if (hasParam(parameters,"anim_erik_swim_up_right"))      anim_erik_swim_up_right=loadAnimation(getParameters(parameters["anim_erik_swim_up_right"],':'));
    if (hasParam(parameters,"anim_erik_hit_water_left"))     anim_erik_hit_water_left=loadAnimation(getParameters(parameters["anim_erik_hit_water_left"],':'));
    if (hasParam(parameters,"anim_erik_hit_water_right"))    anim_erik_hit_water_right=loadAnimation(getParameters(parameters["anim_erik_hit_water_right"],':'));

    if (!hasParam(parameters,"audio_hit")) au_hit=scenario->sndcache->loadWAV("erikhit.wav");

    if (hasParam(parameters,"audio_jump")) au_jump=scenario->sndcache->loadWAV(parameters["audio_jump"]);
      else au_jump=scenario->sndcache->loadWAV("rboots.wav");
    if (hasParam(parameters,"audio_run")) au_jump=scenario->sndcache->loadWAV(parameters["audio_run"]);
      else au_run=NULL;
}
Exemplo n.º 16
0
        int runMany() {
            StateMap threads;

            {
                string orig = getParam( "host" );
                bool showPorts = false;
                if ( orig == "" )
                    orig = "localhost";

                if ( orig.find( ":" ) != string::npos || hasParam( "port" ) )
                    showPorts = true;

                StringSplitter ss( orig.c_str() , "," );
                while ( ss.more() ) {
                    string host = ss.next();
                    if ( showPorts && host.find( ":" ) == string::npos) {
                        // port supplied, but not for this host.  use default.
                        if ( hasParam( "port" ) )
                            host += ":" + _params["port"].as<string>();
                        else
                            host += ":27017";
                    }
                    _add( threads , host );
                }
            }

            sleepsecs(1);

            int row = 0;
            bool discover = hasParam( "discover" );
            int maxLockedDbWidth = 0;

            while ( 1 ) {
                sleepsecs( (int)ceil(_statUtil.getSeconds()) );

                // collect data
                vector<Row> rows;
                for ( map<string,shared_ptr<ServerState> >::iterator i=threads.begin(); i!=threads.end(); ++i ) {
                    scoped_lock lk( i->second->lock );

                    if ( i->second->error.size() ) {
                        rows.push_back( Row( i->first , i->second->error ) );
                    }
                    else if ( i->second->prev.isEmpty() || i->second->now.isEmpty() ) {
                        rows.push_back( Row( i->first ) );
                    }
                    else {
                        BSONObj out = _statUtil.doRow( i->second->prev , i->second->now );
                        rows.push_back( Row( i->first , out ) );
                    }

                    if ( discover && ! i->second->now.isEmpty() ) {
                        if ( _discover( threads , i->first , i->second ) )
                            break;
                    }
                }

                // compute some stats
                unsigned longestHost = 0;
                BSONObj biggest;
                for ( unsigned i=0; i<rows.size(); i++ ) {
                    if ( rows[i].host.size() > longestHost )
                        longestHost = rows[i].host.size();
                    if ( rows[i].data.nFields() > biggest.nFields() )
                        biggest = rows[i].data;

                    // adjust width up as longer 'locked db' values appear
                    setMaxLockedDbWidth( &rows[i].data, &maxLockedDbWidth ); 
                }

                {
                    // check for any headers not in biggest

                    // TODO: we put any new headers at end,
                    //       ideally we would interleave

                    set<string> seen;

                    BSONObjBuilder b;

                    {
                        // iterate biggest
                        BSONObjIterator i( biggest );
                        while ( i.more() ) {
                            BSONElement e = i.next();
                            seen.insert( e.fieldName() );
                            b.append( e );
                        }
                    }

                    // now do the rest
                    for ( unsigned j=0; j<rows.size(); j++ ) {
                        BSONObjIterator i( rows[j].data );
                        while ( i.more() ) {
                            BSONElement e = i.next();
                            if ( seen.count( e.fieldName() ) )
                                continue;
                            seen.insert( e.fieldName() );
                            b.append( e );
                        }

                    }

                    biggest = b.obj();

                }

                // display data

                cout << endl;

                //    header
                if ( row++ % 5 == 0 && ! biggest.isEmpty() ) {
                    cout << setw( longestHost ) << "" << "\t";
                    printHeaders( biggest );
                }

                //    rows
                for ( unsigned i=0; i<rows.size(); i++ ) {
                    cout << setw( longestHost ) << rows[i].host << "\t";
                    if ( rows[i].err.size() )
                        cout << rows[i].err << endl;
                    else if ( rows[i].data.isEmpty() )
                        cout << "no data" << endl;
                    else
                        printData( rows[i].data , biggest );
                }

            }

            return 0;
        }
Exemplo n.º 17
0
    int Tool::main( int argc , char ** argv ) {
        static StaticObserver staticObserver;

        cmdLine.prealloc = false;

        // The default value may vary depending on compile options, but for tools
        // we want durability to be disabled.
        cmdLine.dur = false;

#if( BOOST_VERSION >= 104500 )
    boost::filesystem::path::default_name_check( boost::filesystem2::no_check );
#else
    boost::filesystem::path::default_name_check( boost::filesystem::no_check );
#endif

        _name = argv[0];

        /* using the same style as db.cpp */
        int command_line_style = (((po::command_line_style::unix_style ^
                                    po::command_line_style::allow_guessing) |
                                   po::command_line_style::allow_long_disguise) ^
                                  po::command_line_style::allow_sticky);
        try {
            po::options_description all_options("all options");
            all_options.add(*_options).add(*_hidden_options);

            po::store( po::command_line_parser( argc , argv ).
                       options(all_options).
                       positional( _positonalOptions ).
                       style(command_line_style).run() , _params );

            po::notify( _params );
        }
        catch (po::error &e) {
            cerr << "ERROR: " << e.what() << endl << endl;
            printHelp(cerr);
            ::_exit(EXIT_BADOPTIONS);
        }

        // hide password from ps output
        for (int i=0; i < (argc-1); ++i) {
            if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "--password")) {
                char* arg = argv[i+1];
                while (*arg) {
                    *arg++ = 'x';
                }
            }
        }

        if ( _params.count( "help" ) ) {
            printHelp(cout);
            ::_exit(0);
        }

        if ( _params.count( "version" ) ) {
            printVersion(cout);
            ::_exit(0);
        }

        if ( _params.count( "verbose" ) ) {
            logLevel = 1;
        }

        for (string s = "vv"; s.length() <= 10; s.append("v")) {
            if (_params.count(s)) {
                logLevel = s.length();
            }
        }


#ifdef MONGO_SSL
        if (_params.count("ssl")) {
            mongo::cmdLine.sslOnNormalPorts = true;
        }
#endif

        preSetup();

        bool useDirectClient = hasParam( "dbpath" );

        if ( ! useDirectClient ) {
            _host = "127.0.0.1";
            if ( _params.count( "host" ) )
                _host = _params["host"].as<string>();

            if ( _params.count( "port" ) )
                _host += ':' + _params["port"].as<string>();

            if ( _noconnection ) {
                // do nothing
            }
            else {
                string errmsg;

                ConnectionString cs = ConnectionString::parse( _host , errmsg );
                if ( ! cs.isValid() ) {
                    cerr << "invalid hostname [" << _host << "] " << errmsg << endl;
                    ::_exit(-1);
                }

                _conn = cs.connect( errmsg );
                if ( ! _conn ) {
                    cerr << "couldn't connect to [" << _host << "] " << errmsg << endl;
                    ::_exit(-1);
                }

                (_usesstdout ? cout : cerr ) << "connected to: " << _host << endl;
            }

        }
        else {
            if ( _params.count( "directoryperdb" ) ) {
                directoryperdb = true;
            }
            verify( lastError.get( true ) );

            if (_params.count("journal")){
                cmdLine.dur = true;
            }

            Client::initThread("tools");
            _conn = new DBDirectClient();
            _host = "DIRECT";
            static string myDbpath = getParam( "dbpath" );
            dbpath = myDbpath.c_str();
            try {
                acquirePathLock();
            }
            catch ( DBException& ) {
                cerr << endl << "If you are running a mongod on the same "
                     "path you should connect to that instead of direct data "
                     "file access" << endl << endl;
                dbexit( EXIT_CLEAN );
                ::_exit(-1);
            }

            FileAllocator::get()->start();

            dur::startup();
        }

        if ( _params.count( "db" ) )
            _db = _params["db"].as<string>();

        if ( _params.count( "collection" ) )
            _coll = _params["collection"].as<string>();

        if ( _params.count( "username" ) )
            _username = _params["username"].as<string>();

        if ( _params.count( "password" )
                && ( _password.empty() ) ) {
            _password = askPassword();
        }

        if (_params.count("ipv6"))
            enableIPv6();

        int ret = -1;
        try {
            ret = run();
        }
        catch ( DBException& e ) {
            cerr << "assertion: " << e.toString() << endl;
            ret = -1;
        }
	catch(const boost::filesystem::filesystem_error &fse) {
	    /*
	      https://jira.mongodb.org/browse/SERVER-2904

	      Simple tools that don't access the database, such as
	      bsondump, aren't throwing DBExceptions, but are throwing
	      boost exceptions.

	      The currently available set of error codes don't seem to match
	      boost documentation.  boost::filesystem::not_found_error
	      (from http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/exception.htm)
	      doesn't seem to exist in our headers.  Also, fse.code() isn't
	      boost::system::errc::no_such_file_or_directory when this
	      happens, as you would expect.  And, determined from
	      experimentation that the command-line argument gets turned into
	      "\\?" instead of "/?" !!!
	     */
#if defined(_WIN32)
	    if (/*(fse.code() == boost::system::errc::no_such_file_or_directory) &&*/
		(fse.path1() == "\\?"))
		printHelp(cerr);
	    else
#endif // _WIN32
		cerr << "error: " << fse.what() << endl;

	    ret = -1;
	}

        if ( currentClient.get() )
            currentClient.get()->shutdown();

        if ( useDirectClient )
            dbexit( EXIT_CLEAN );
        ::_exit(ret);
    }
Exemplo n.º 18
0
    int Tool::main( int argc , char ** argv ){
        static StaticObserver staticObserver;
        
        cmdLine.prealloc = false;

        boost::filesystem::path::default_name_check( boost::filesystem::no_check );

        _name = argv[0];

        /* using the same style as db.cpp */
        int command_line_style = (((po::command_line_style::unix_style ^
                                    po::command_line_style::allow_guessing) |
                                   po::command_line_style::allow_long_disguise) ^
                                  po::command_line_style::allow_sticky);
        try {
            po::options_description all_options("all options");
            all_options.add(*_options).add(*_hidden_options);

            po::store( po::command_line_parser( argc , argv ).
                       options(all_options).
                       positional( _positonalOptions ).
                       style(command_line_style).run() , _params );

            po::notify( _params );
        } catch (po::error &e) {
            cerr << "ERROR: " << e.what() << endl << endl;
            printHelp(cerr);
            return EXIT_BADOPTIONS;
        }

        // hide password from ps output
        for (int i=0; i < (argc-1); ++i){
            if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "--password")){
                char* arg = argv[i+1];
                while (*arg){
                    *arg++ = 'x';
                }
            }
        }

        if ( _params.count( "help" ) ){
            printHelp(cout);
            return 0;
        }

        if ( _params.count( "verbose" ) ) {
            logLevel = 1;
        }

        for (string s = "vv"; s.length() <= 10; s.append("v")) {
            if (_params.count(s)) {
                logLevel = s.length();
            }
        }
        
        preSetup();

        bool useDirectClient = hasParam( "dbpath" );
        
        if ( ! useDirectClient ) {
            _host = "127.0.0.1";
            if ( _params.count( "host" ) )
                _host = _params["host"].as<string>();

            if ( _params.count( "port" ) )
                _host += ':' + _params["port"].as<string>();
            
            if ( _noconnection ){
                // do nothing
            }
            else if ( _host.find( "," ) == string::npos ){
                DBClientConnection * c = new DBClientConnection( _autoreconnect );
                _conn = c;

                string errmsg;
                if ( ! c->connect( _host , errmsg ) ){
                    cerr << "couldn't connect to [" << _host << "] " << errmsg << endl;
                    return -1;
                }
            }
            else {
                log(1) << "using pairing" << endl;
                DBClientPaired * c = new DBClientPaired();
                _paired = true;
                _conn = c;

                if ( ! c->connect( _host ) ){
                    cerr << "couldn't connect to paired server: " << _host << endl;
                    return -1;
                }
            }
            
            (_usesstdout ? cout : cerr ) << "connected to: " << _host << endl;
        }
        else {
            if ( _params.count( "directoryperdb" ) ) {
                directoryperdb = true;
            }
            assert( lastError.get( true ) );
            Client::initThread("tools");
            _conn = new DBDirectClient();
            _host = "DIRECT";
            static string myDbpath = getParam( "dbpath" );
            dbpath = myDbpath.c_str();
            try {
                acquirePathLock();
            }
            catch ( DBException& e ){
                cerr << endl << "If you are running a mongod on the same "
                    "path you should connect to that instead of direct data "
                    "file access" << endl << endl;
                dbexit( EXIT_CLEAN );
                return -1;
            }

            theFileAllocator().start();
        }

        if ( _params.count( "db" ) )
            _db = _params["db"].as<string>();

        if ( _params.count( "collection" ) )
            _coll = _params["collection"].as<string>();

        if ( _params.count( "username" ) )
            _username = _params["username"].as<string>();

        if ( _params.count( "password" )
             && ( _password.empty() ) ) {
            _password = askPassword();
        }

        if (_params.count("ipv6"))
            enableIPv6();

        int ret = -1;
        try {
            ret = run();
        }
        catch ( DBException& e ){
            cerr << "assertion: " << e.toString() << endl;
            ret = -1;
        }
    
        if ( currentClient.get() )
            currentClient->shutdown();

        if ( useDirectClient )
            dbexit( EXIT_CLEAN );
        return ret;
    }
Exemplo n.º 19
0
 bool useLocks() {
     return hasParam( "locks" );
 }
Exemplo n.º 20
0
EmptyAnimationPtr Object::loadAnimation(const ParameterMap& parameters) {
    double scale_factor=1;
    BasePointType bp_type=BP_MD;
    Uint16 animation_type=ATYPE_LOOP;
    double fps=0;
    AllignType allign_type=AT_MD;
    
    if (hasParam(parameters,"scale")) {
        if (parameters.find("scale")->second == "lvl") scale_factor=config.lvlscale;
        else scale_factor=atof(parameters.find("scale")->second.c_str());
    }
    if (hasParam(parameters,"bp_type")) {
        if        (parameters.find("bp_type")->second.find("hleft")   !=string::npos) {
            if      (parameters.find("bp_type")->second.find("vup")     !=string::npos) bp_type=BP_LU;
            else if (parameters.find("bp_type")->second.find("vmiddle") !=string::npos) bp_type=BP_LM;
            else if (parameters.find("bp_type")->second.find("vdown")   !=string::npos) bp_type=BP_LD;
        } else if (parameters.find("bp_type")->second.find("hmiddle") !=string::npos) {
            if      (parameters.find("bp_type")->second.find("vup")     !=string::npos) bp_type=BP_MU;
            else if (parameters.find("bp_type")->second.find("vmiddle") !=string::npos) bp_type=BP_MM;
            else if (parameters.find("bp_type")->second.find("vdown")   !=string::npos) bp_type=BP_MD;
        } else if (parameters.find("bp_type")->second.find("hright")  !=string::npos) {
            if      (parameters.find("bp_type")->second.find("vup")     !=string::npos) bp_type=BP_RU;
            else if (parameters.find("bp_type")->second.find("vmiddle") !=string::npos) bp_type=BP_RM;
            else if (parameters.find("bp_type")->second.find("vdown")   !=string::npos) bp_type=BP_RD;
        }
    }
    if (hasParam(parameters,"type")) {
        animation_type=NOTHING;
        if (parameters.find("type")->second.find("once")    !=string::npos)  animation_type|=ATYPE_ONCE;
        if (parameters.find("type")->second.find("loop")    !=string::npos)  animation_type|=ATYPE_LOOP;
        if (parameters.find("type")->second.find("swing")   !=string::npos)  animation_type|=ATYPE_SWING;
        if (parameters.find("type")->second.find("step")    !=string::npos)  animation_type|=ATYPE_STEP;
        if (parameters.find("type")->second.find("reverse") !=string::npos)  animation_type<<=1;

        if (animation_type==NOTHING)                                         animation_type=ATYPE_LOOP;
        if (parameters.find("type")->second.find("switch")  !=string::npos)  animation_type|=ATYPE_ST_SWITCH;
    }
    if (hasParam(parameters,"fps")) fps=atof(parameters.find("fps")->second.c_str());
    if (hasParam(parameters,"allign_type")) {
        if        (parameters.find("allign_type")->second.find("hleft")   !=string::npos) {
            if      (parameters.find("allign_type")->second.find("vup")     !=string::npos) allign_type=AT_LU;
            else if (parameters.find("allign_type")->second.find("vmiddle") !=string::npos) allign_type=AT_LM;
            else if (parameters.find("allign_type")->second.find("vdown")   !=string::npos) allign_type=AT_LD;
        } else if (parameters.find("allign_type")->second.find("hmiddle") !=string::npos) {
            if      (parameters.find("allign_type")->second.find("vup")     !=string::npos) allign_type=AT_MU;
            else if (parameters.find("allign_type")->second.find("vmiddle") !=string::npos) allign_type=AT_MM;
            else if (parameters.find("allign_type")->second.find("vdown")   !=string::npos) allign_type=AT_MD;
        } else if (parameters.find("allign_type")->second.find("hright")  !=string::npos) {
            if      (parameters.find("allign_type")->second.find("vup")     !=string::npos) allign_type=AT_RU;
            else if (parameters.find("allign_type")->second.find("vmiddle") !=string::npos) allign_type=AT_RM;
            else if (parameters.find("allign_type")->second.find("vdown")   !=string::npos) allign_type=AT_RD;
        }
    }

    /* Use animation name */
    if (hasParam(parameters,"name")) {
        string anim_name=parameters.find("name")->second;
        return loadAnimation(anim_name,scale_factor,bp_type,animation_type,fps,allign_type);

    /* Use a base image */
    } else if (hasParam(parameters,"image")) {
        string image_name=parameters.find("image")->second;
        Uint16 frames=1;
        Uint16 start_pos=0;
        if (hasParam(parameters,"frames")) frames=atoi(parameters.find("frames")->second.c_str());
        if (hasParam(parameters,"start_pos")) start_pos=atoi(parameters.find("start_pos")->second.c_str());

        /* threat as horizontal animation (constant width, height) with <image_hor_frames> frames */
        if (hasParam(parameters,"image_hor_frames")) {
            Uint16 image_hor_frames=atoi(parameters.find("image_hor_frames")->second.c_str());
            return loadAnimation(scenario->imgcache->loadImage(image_hor_frames,image_name,scale_factor),frames,bp_type,animation_type,fps,start_pos,allign_type);

        /* threat as horizontal animation (constant width, height) with width <image_hor_width> and an optional shift */
        } else if (hasParam(parameters,"image_hor_width")) {
            Uint16 image_hor_width=atoi(parameters.find("image_hor_width")->second.c_str());
            Uint16 image_hor_shift=0;
            if (hasParam(parameters,"image_hor_shift")) image_hor_shift=atoi(parameters.find("image_hor_shift")->second.c_str());
            return loadAnimation(scenario->imgcache->loadImage(image_hor_width,image_hor_shift,image_name,scale_factor),frames,bp_type,animation_type,fps,start_pos,allign_type);

        /* threat as constant width/height animation based on a base rectangle */
        } else if (hasParam(parameters,"image_rect")) {
            ParameterMap rect_param=getParameters(parameters.find("image_rect")->second,';');
            SDL_Rect rect;
            rect.x=rect.y=0;
            rect.w=rect.h=10;
            if (hasParam(rect_param,"x")) rect.x=atoi(rect_param.find("x")->second.c_str());
            if (hasParam(rect_param,"y")) rect.y=atoi(rect_param.find("y")->second.c_str());
            if (hasParam(rect_param,"w")) rect.w=atoi(rect_param.find("w")->second.c_str());
            if (hasParam(rect_param,"h")) rect.h=atoi(rect_param.find("h")->second.c_str());
            return loadAnimation(scenario->imgcache->loadImage(rect,image_name,scale_factor),frames,bp_type,animation_type,fps,start_pos,allign_type);

        /* get informations from an image description file */
        } else {
            string image_desc=image_name+".dsc";
            if (hasParam(parameters,"image_desc")) image_desc=parameters.find("image_desc")->second;
            return loadAnimation(scenario->imgcache->loadImage(image_name,scale_factor,image_desc),frames,bp_type,animation_type,fps,start_pos,allign_type);
        }

    /* no suitable animation found */
    } else {
        cout << "Invalid animation parameters!" << endl;
        return EmptyAnimationPtr(new EmptyAnimation());
    }
}
Exemplo n.º 21
0
bool OsirisLink::isValid() const
{
	bool valid = true;
	
	if(getParam("type") == OS_OSIRISLINK_TYPE_PORTAL)
	{
		if(hasParam("portal") == false)
			return false;
		
		PortalID portal = static_cast<String>(getParam("portal")).to_ascii();
		if(portal.validate(false) == false)
			return false;

#ifdef OS_OSIRIS_VERSION_RAZOR
		if(hasParam("pov") == false)
			return false;

		PovID pov = static_cast<String>(getParam("pov")).to_ascii();
		if(pov.empty())
			return false;		
#endif
	}
	else if(getParam("type") == OS_OSIRISLINK_TYPE_ISIS)
	{
		if(hasParam("portal") == false)
			return false;
		
		PortalID portal = static_cast<String>(getParam("portal")).to_ascii();
		if(portal.validate(false) == false)
			return false;

#ifdef OS_OSIRIS_VERSION_RAZOR
		if(hasParam("pov") == false)
			return false;

		PovID pov = static_cast<String>(getParam("pov")).to_ascii();
		if(pov.empty())
			return false;		
#endif

		if(hasParam("name") == false)
			return false;		

		if(hasParam("url") == false)
			return false;

		// TODO: check if is a url.
	}
	else if(getParam("type") == OS_OSIRISLINK_TYPE_FILE)
	{
		if(hasParam("id") == false)
			return false;		

		EntityID id = static_cast<String>(getParam("id")).to_ascii();
		if(id.empty())
			return false;
				
		if(hasParam("portal"))
		{
			PortalID portal = static_cast<String>(getParam("portal")).to_ascii();
			if(portal.validate(false) == false)
				return false;
		}

#ifdef OS_OSIRIS_VERSION_RAZOR
		if(hasParam("pov"))
		{
			PovID pov = static_cast<String>(getParam("pov")).to_ascii();
			if(pov.empty())
				return false;		
		}
#endif	
	}
	else if(getParam("type") == OS_OSIRISLINK_TYPE_URL)
	{
		if(hasParam("url") == false)
			return false;		

		// TODO: check if is a url	
	}
	else if(getParam("type") == OS_OSIRISLINK_TYPE_RES)
	{
		if(hasParam("path") == false)
			return false;

		// We don't check if is a path.
	}
	else
		return false;

	return true;
}
Exemplo n.º 22
0
std::string OsirisLink::generate() const
{	
#ifdef OS_OSIRIS_VERSION_RAZOR
	bool newFormat = true;
#else
	bool newFormat = false;
#endif

	if(isValid() == false)
		return "";

	if(hasParam("type") == false)
		return "";

	if(newFormat)
	{
		std::string out = "";

		for(OsirisLinkParams::const_iterator i = m_params.begin(); i != m_params.end(); ++i)
		{
			std::string key = i->first;
			std::wstring value = i->second;

			if(key != "type") // Type forced below, simply to ensure it's the first.
			{
				if(value != _W(""))
				{
					out += "&" + key + "=" + HttpParser::urlEncodeW(value);
				}
			}
		}
		return "osiris:?type=" + HttpParser::urlEncodeW(getParam("type")) + out;
	}
	else
	{
		if(getParam("type") == OS_OSIRISLINK_TYPE_PORTAL)
		{
			if(hasParam("portal") == false)
				return "";

			std::string out = "osiris://|portal|"  + HttpParser::urlEncodeW(getParam("portal")) + "|";			
			if(hasParam("name"))
				out += "name=" + HttpParser::urlEncodeW(getParam("name")) + "|";
			if(hasParam("description"))
				out += "description=" + HttpParser::urlEncodeW(getParam("description")) +  "|";
			if(hasParam("user"))
				out += "user="******"010000002") + getParam("pov")) + "|";
			return out;
		}
		else if(getParam("type") == OS_OSIRISLINK_TYPE_ISIS)
		{
			if(hasParam("portal") == false)
				return "";

			std::string out = "osiris://|isis|"  + HttpParser::urlEncodeW(getParam("portal")) + "|";			
			
			if(hasParam("name"))
				out += "name=" + HttpParser::urlEncodeW(getParam("name")) + "|";
			if(hasParam("url"))
				out += "url=" + HttpParser::urlEncodeW(getParam("url")) +  "|";			
			return out;
		}
		else if(getParam("type") == OS_OSIRISLINK_TYPE_FILE)
		{
			std::string out = "osiris://|file|"  + HttpParser::urlEncodeW(getParam("id")) + "|";			
			return out;
		}
		else if(getParam("type") == OS_OSIRISLINK_TYPE_URL)
		{
			std::wstring url = getParam("url");
			StringVector array1;
			utils::split(url, _S("?"), array1);

			std::wstring params = _W("");
			if(array1.size()>=2)
			{
				url = array1[0].to_wide();
				params = array1[1].to_wide();
			}

			if(hasParam("portal"))
			{
				if(params.empty() == false)
					params += _W("&");
				params += _W("portal=") + getParam("portal");
			}
			
			/*
			std::string out = "osiris://|url|"  + HttpParser::urlEncodeW(url) + "|";			
			if(params != _W(""))
				out += HttpParser::urlEncodeW(params) + "|";			
			*/
			std::string out = "osiris://|url|"  + utils::wtoa(url) + "|";			
			if(params != _W(""))
				out += utils::wtoa(params) + "|";			
			return out;
		}
		else if(getParam("type") == OS_OSIRISLINK_TYPE_RES)
		{
			std::string out = "osiris://|skin|"  + HttpParser::urlEncodeW(getParam("path")) + "|";			
			return out;
		}
		else
		{
			return "";
		}
	}	
}
Exemplo n.º 23
0
    Status storeGeneralToolOptions(const moe::Environment& params,
                                   const std::vector<std::string>& args) {

        toolGlobalParams.name = args[0];

        storageGlobalParams.prealloc = false;

        // The default value may vary depending on compile options, but for tools
        // we want durability to be disabled.
        storageGlobalParams.dur = false;

        // Set authentication parameters
        if (params.count("authenticationDatabase")) {
            toolGlobalParams.authenticationDatabase =
                params["authenticationDatabase"].as<string>();
        }

        if (params.count("authenticationMechanism")) {
            toolGlobalParams.authenticationMechanism =
                params["authenticationMechanism"].as<string>();
        }

        if (params.count("verbose")) {
            logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(1));
        }

        for (string s = "vv"; s.length() <= 12; s.append("v")) {
            if (params.count(s)) {
                logger::globalLogDomain()->setMinimumLoggedSeverity(
                        logger::LogSeverity::Debug(s.length()));
            }
        }

        toolGlobalParams.quiet = params.count("quiet");

#ifdef MONGO_SSL
        Status ret = storeSSLClientOptions(params);
        if (!ret.isOK()) {
            return ret;
        }
#endif

        if (args.empty()) {
            return Status(ErrorCodes::InternalError, "Cannot get binary name: argv array is empty");
        }

        // setup binary name
        toolGlobalParams.name = args[0];
        size_t i = toolGlobalParams.name.rfind('/');
        if (i != string::npos) {
            toolGlobalParams.name = toolGlobalParams.name.substr(i + 1);
        }
        toolGlobalParams.db = "test";
        toolGlobalParams.coll = "";
        toolGlobalParams.noconnection = false;

        if (params.count("db"))
            toolGlobalParams.db = params["db"].as<string>();

        if (params.count("collection"))
            toolGlobalParams.coll = params["collection"].as<string>();

        if (params.count("username"))
            toolGlobalParams.username = params["username"].as<string>();

        if (params.count("password")) {
            toolGlobalParams.password = params["password"].as<string>();
            if (toolGlobalParams.password.empty()) {
                toolGlobalParams.password = askPassword();
            }
        }

        if (params.count("ipv6")) {
            enableIPv6();
        }

        toolGlobalParams.dbpath = getParam("dbpath");
        toolGlobalParams.useDirectClient = hasParam("dbpath");
        if (toolGlobalParams.useDirectClient && params.count("journal")) {
            storageGlobalParams.dur = true;
        }

        if (!toolGlobalParams.useDirectClient) {
            toolGlobalParams.connectionString = "127.0.0.1";
            if (params.count("host")) {
                toolGlobalParams.hostSet = true;
                toolGlobalParams.host = params["host"].as<string>();
                toolGlobalParams.connectionString = params["host"].as<string>();
            }

            if (params.count("port")) {
                toolGlobalParams.portSet = true;
                toolGlobalParams.port = params["port"].as<string>();
                toolGlobalParams.connectionString += ':' + params["port"].as<string>();
            }
        }
        else {
            if (params.count("directoryperdb")) {
                storageGlobalParams.directoryperdb = true;
            }

            toolGlobalParams.connectionString = "DIRECT";
        }

        return Status::OK();
    }