void PushButton::setupUI(const VariantMap &ui) { Widget::setupUI( ui ); __D_REF(_d,PushButton) Variant tmp; tmp = ui.get( "bgtype" ); if( tmp.isValid() ) { BackgroundStyleHelper helper; setBackgroundStyle( helper.findType( tmp.toString() ) ); } setIsPushButton( (bool)ui.get( "pushbutton" ) ); _d.text.offset = ui.get( "textOffset" ); _d.text.offset = ui.get( "text.offset", _d.text.offset ); setEnabled( (bool)ui.get( "enabled", true ) ); Variant vFont = ui.get( "font" ); if( vFont.isValid() ) { setFont( Font::create( vFont.toString() ) ); } VariantList vlist = ui.get( "normal" ).toList(); if( !vlist.empty() ) setPicture( vlist.get( 0 ).toString(), vlist.get( 1 ).toInt(), stNormal ); vlist = ui.get( "hovered" ).toList(); if( !vlist.empty() ) setPicture( vlist.get( 0 ).toString(), vlist.get( 1 ).toInt(), stHovered ); vlist = ui.get( "pressed" ).toList(); if( !vlist.empty() ) setPicture( vlist.get( 0 ).toString(), vlist.get( 1 ).toInt(), stPressed ); vlist = ui.get( "disabled" ).toList(); if( !vlist.empty() ) setPicture( vlist.get( 0 ).toString(), vlist.get( 1 ).toInt(), stDisabled ); }
void Factory::load( const VariantMap& stream) { WorkingBuilding::load( stream ); _d->goodStore.load( stream.get( "goodStore" ).toMap() ); _d->progress = (float)stream.get( "progress" ); // approximation _d->productionRate = (float)stream.get( "productionRate" ); }
static size_t onWrite(char *ptr, size_t size, size_t nmemb, void *userdata) { WebRequestInternalState *is_(reinterpret_cast<WebRequestInternalState*>(userdata)); is_->state = HTTP_OPEN; if (is_->isAborted) { is_->state = HTTP_CLOSED; // This should probably be CURL_WRITEFUNC_ABORT, but that doesn't // exist. It probably would be the same numeric value, if it did. // The docs say that it just has to be a number of bytes that is // not "size * nmemb" to abort. return CURL_READFUNC_ABORT; } // Find the size in bytes. size_t real_size(size * nmemb); // Write the date into the download buffer queue. Serializer* download(dynamic_cast<Serializer*>(is_->download.Get())); download->Write(ptr, (unsigned int)real_size); // Emit a "download_chunk" event. VariantMap eventData; eventData.Insert(MakePair(StringHash("download"), Variant(is_->download))); eventData.Insert(MakePair(StringHash("size"), Variant((unsigned int)real_size))); is_->es.SendEvent("download_chunk", eventData); return real_size; }
bool OMap::load(const std::string& filename, Game& game) { _d->restartFile = filename; VariantMap vm; if( vfs::Path( filename ).isMyExtension( ".zmap" ) ) { Logger::error( "OMap not loading citymap from zip" ); return false; } else { vm = config::load( filename ); } _d->climate = vm.get( "climate" ).toInt(); _d->loadCity( vm, game.city() ); _d->initCameraStartPos(vm, game.city() ); game.city()->setOption( PlayerCity::adviserEnabled, 1 ); game.empire()->setCitiesAvailable( true ); return true; }
void StartMenu::Impl::showLanguageOptions() { Widget* parent = game->gui()->rootWidget(); Size windowSize( 512, 384 ); Label* frame = new Label( parent, Rect( Point(), windowSize ), "", false, gui::Label::bgWhiteFrame ); ListBox* lbx = new ListBox( frame, Rect( 0, 0, 1, 1 ), -1, true, true ); PushButton* btn = new PushButton( frame, Rect( 0, 0, 1, 1), _("##apply##") ); WidgetEscapeCloser::insertTo( frame ); frame->setCenter( parent->center() ); lbx->setFocus(); lbx->setGeometry( RectF( 0.05, 0.05, 0.95, 0.85 ) ); btn->setGeometry( RectF( 0.1, 0.88, 0.9, 0.95 ) ); VariantMap languages = config::load( SETTINGS_RC_PATH( langModel ) ); std::string currentLang = SETTINGS_VALUE( language ).toString(); int currentIndex = -1; foreach( it, languages ) { lbx->addItem( it->first ); std::string ext = it->second.toMap().get( literals::ext ).toString(); if( ext == currentLang ) currentIndex = std::distance( languages.begin(), it ); }
int OMap::climateType(const std::string& filename) { VariantMap vm = config::load( filename ); _d->climate = vm.get( "climate" ).toInt(); return _d->climate; }
void ChangeEmpireOptions::_exec(Game& game, unsigned int) { VariantMap emOpts = _vars.get( literals::empire ).toMap(); VariantMap advOptions = _vars.get( literals::adviser ).toMap(); if( !emOpts.empty() ) { world::EmpirePtr empire = game.empire(); unsigned int lastWorkerSalary = empire->workerSalary(); empire->load( emOpts ); if( empire->workerSalary() != lastWorkerSalary ) { bool raiseSalary = empire->workerSalary() - lastWorkerSalary; GameEventPtr e = ShowInfobox::create( "##rome##", raiseSalary ? "##rome_raises_wages##" : "##rome_lowers_wages##"); e->dispatch(); } } Variant adv_enabled = advOptions.get( literals::enabled ); if( adv_enabled.isValid() ) { game.city()->setOption( PlayerCity::adviserEnabled, adv_enabled ); } }
void ServiceBuilding::load( const VariantMap& stream ) { WorkingBuilding::load( stream ); _d->serviceTimer = (int)stream.get( "timer" ); _d->serviceDelay = (int)stream.get( "delay" ); _d->serviceRange = (int)stream.get( "range" ); }
virtual void sendStartupArguments(pid_t pid, FileDescriptor &fd) { VariantMap options = agentsOptions; options.set("logging_agent_address", wo->loggingAgentAddress); options.set("logging_agent_password", wo->loggingAgentPassword); options.set("logging_agent_admin_address", wo->loggingAgentAdminAddress); options.writeToFd(fd); }
void RandomFire::load(const VariantMap& stream) { VariantList vl = stream.get( lc_population ).toList(); _d->minPopulation = vl.get( 0, 0 ).toInt(); _d->maxPopulation = vl.get( 1, 999999 ).toInt(); _d->strong = stream.get( lc_strong, 10 ); }
void LandOverlay::load( const VariantMap& stream ) { _name = stream.get( "name" ).toString(); _d->buildingType = (BuildingType)stream.get( "buildingType" ).toInt(); _picture = &Picture::load( stream.get( "picture" ).toString() + ".png" ); _size = stream.get( "size" ).toInt(); _isDeleted = stream.get( "isDeleted" ).toBool(); }
virtual void sendStartupArguments(pid_t pid, FileDescriptor &fd) { VariantMap options = agentsOptions; options.set("request_socket_password", Base64::encode(requestSocketPassword)). set("message_socket_password", Base64::encode(messageSocketPassword)). set("logging_agent_address", loggingAgentAddress). set("logging_agent_password", loggingAgentPassword); options.writeToFd(fd); }
void Peace::load(const VariantMap& stream) { VARIANT_LOAD_ANY_D( _d, peaceYears, stream ) VARIANT_LOAD_ANY_D( _d, someCriminalSeen, stream ) _d->protestorOrMugglerSeen = stream.get( lc_protestorOrMugglerSeen ); _d->rioterSeen = stream.get( lc_rioterSeen ); _d->value = stream.get( lc_value ); _d->significantBuildingsDestroyed = stream.get( lc_significantBuildingsDestroyed ); }
static void installAbortHandler() { VariantMap options; options.set("passenger_root", resourceLocator->getRoot()); initializeAgentOptions("CxxTestMain", options); installAgentAbortHandler(); }
virtual void reportAgentsInformation(VariantMap &report) { const VariantMap &options = *agentsOptions; report.set("ust_router_address", options.get("ust_router_address")); report.set("ust_router_password", options.get("ust_router_password")); // For backward compatibilty: report.set("logging_agent_address", options.get("ust_router_address")); report.set("logging_agent_password", options.get("ust_router_password")); }
void set( Senate::Status status, const VariantMap& stream ) { if( stream.empty() ) return; Picture pic( stream.get( "rc"), stream.get( "index") ); Point offset = stream.get( "offset" ); set( status, pic, offset ); }
void Dispatcher::load( const vfs::Path& filename, const std::string& section) { VariantMap vm = config::load( filename ); if( !section.empty() ) vm = vm.get( section ).toMap(); load( vm ); }
void ShowAdvisorWindow::load(const VariantMap &stream) { GameEvent::load( stream ); _show = stream.get( "show" ); Variant adv = stream.get( "advisor" ); if( adv.type() == Variant::String ) { _advisor = advisor::fromString( adv.toString() ); } else { _advisor = (advisor::Type)adv.toInt(); } }
void TileOverlay::load( const VariantMap& stream ) { _d->name = stream.get( "name" ).toString(); _d->size = stream.get( "size", Size(1) ).toSize(); //_d->overlayType = (LandOverlayType)stream.get( "overlayType" ).toInt(); _d->picture = Picture::load( stream.get( "picture" ).toString() + ".png" ); _d->picture.setOffset( stream.get( "pictureOffset" ).toPoint() ); _d->isDeleted = stream.get( "isDeleted", false ).toBool(); }
virtual void reportAgentsInformation(VariantMap &report) { const VariantMap &options = *agentsOptions; vector<string> addresses = options.getStrSet("core_addresses"); report.set("core_address", addresses.front()); report.set("core_password", options.get("core_password")); // For backwards compatibility: report.set("server_address", addresses.front()); report.set("server_password", options.get("core_password")); }
void ConnectionSettings::operator<<(const VariantMap &value) { for (auto it = value.begin(); it != value.end(); ++it) { std::string key = it->first; Variant value = it->second; // Set the key-value pair set(key, value); } }
void Soldier::load(const VariantMap& stream) { Walker::load( stream ); __D_IMPL(d,Soldier) d->action = (Soldier::SldrAction)stream.get( lc_sldAction ).toInt(); d->strikeForce = stream.get( lc_strikeForce ); d->resistance = stream.get( lc_resistance ); d->attackDistance = stream.get( lc_attackDistance ).toUInt(); VARIANT_LOAD_ANY_D( d, morale, stream ) }
void House::load( const VariantMap& stream ) { Building::load( stream ); _d->picIdOffset = stream.get( "picIdOffset" ).toInt(); _d->houseId = stream.get( "houseId" ).toInt(); _d->houseLevel = stream.get( "houseLevel" ).toInt(); _d->houseLevelSpec = HouseSpecHelper::getInstance().getHouseLevelSpec(_d->houseLevel); _d->nextHouseLevelSpec = _d->houseLevelSpec.next(); _d->desirability = stream.get( "desirability" ).toInt(); _d->currentHabitants = stream.get( "currentHubitants" ).toInt(); _d->maxHabitants = stream.get( "maxHubitants" ).toInt(); _d->freeWorkersCount = stream.get( "freeWorkersCount" ).toInt(); _d->goodStore.load( stream.get( "goodstore" ).toMap() ); VariantList vl_services = stream.get( "services" ).toList(); for( VariantList::iterator it = vl_services.begin(); it != vl_services.end(); it++ ) { ServiceType type = ServiceType( (*it).toInt() ); it++; int serviceValue = (*it).toInt(); _d->serviceAccessMap[ type ] = serviceValue; } Building::build( getTilePos() ); _update(); }
bool Serializer::WriteVariantMap(const VariantMap& value) { bool success = true; success &= WriteVLE(value.Size()); for (VariantMap::ConstIterator i = value.Begin(); i != value.End(); ++i) { WriteStringHash(i->first_); WriteVariant(i->second_); } return success; }
void CityIndebt::load(const VariantMap& stream) { GameEvent::load( stream ); VARIANT_LOAD_ANY_D( _d, state, stream ) VARIANT_LOAD_ANY_D( _d, isDeleted, stream ) _d->emperorMoney << stream.get( "emperorMoney" ).toList(); _d->text = stream.get( "text" ).toStringArray(); _d->title = stream.get( "title" ).toStringArray(); _d->video = stream.get( "video" ).toStringArray(); }
static RomeDivinityPtr create( const VariantMap& vm ) { RomeDivinityBase* divn = new RomeDivinityBase(); divn->_name = vm.get( "name" ).toString(); divn->_service = (ServiceType)vm.get( "service" ).toInt(); divn->_pic = Picture::load( vm.get( "image" ).toString() ); RomeDivinityPtr ret( divn ); ret->drop(); return ret; }
void Soldier::initialize(const VariantMap &options) { Human::initialize( options ); setResistance( options.get( "resistance", 1.f ) ); setStrike( options.get( "strike", 3.f ) ); Variant ad = options.get( "attackDistance" ); if( ad.isValid() ) { setAttackDistance( math::clamp( ad.toUInt(), 1u, 99u ) ); } }
static void initializeWorkingObjects(WorkingObjectsPtr &wo, ServerInstanceDirToucherPtr &serverInstanceDirToucher) { TRACE_POINT(); wo = make_shared<WorkingObjects>(); wo->resourceLocator = make_shared<ResourceLocator>(agentsOptions.get("passenger_root")); UPDATE_TRACE_POINT(); // Must not used make_shared() here because Watchdog.cpp // deletes the raw pointer in cleanupAgentsInBackground(). if (agentsOptions.get("server_instance_dir", false).empty()) { /* We embed the super structure version in the server instance directory name * because it's possible to upgrade Phusion Passenger without changing the * web server's PID. This way each incompatible upgrade will use its own * server instance directory. */ string path = tempDir + "/passenger." + toString(SERVER_INSTANCE_DIR_STRUCTURE_MAJOR_VERSION) + "." + toString(SERVER_INSTANCE_DIR_STRUCTURE_MINOR_VERSION) + "." + toString<unsigned long long>(agentsOptions.getPid("web_server_pid")); wo->serverInstanceDir.reset(new ServerInstanceDir(path)); } else { wo->serverInstanceDir.reset(new ServerInstanceDir(agentsOptions.get("server_instance_dir"))); agentsOptions.set("server_instance_dir", wo->serverInstanceDir->getPath()); } wo->generation = wo->serverInstanceDir->newGeneration(userSwitching, defaultUser, defaultGroup, webServerWorkerUid, webServerWorkerGid); agentsOptions.set("server_instance_dir", wo->serverInstanceDir->getPath()); agentsOptions.setInt("generation_number", wo->generation->getNumber()); UPDATE_TRACE_POINT(); serverInstanceDirToucher = make_shared<ServerInstanceDirToucher>(wo); UPDATE_TRACE_POINT(); lookupDefaultUidGid(wo->defaultUid, wo->defaultGid); UPDATE_TRACE_POINT(); wo->loggingAgentAddress = "unix:" + wo->generation->getPath() + "/logging"; wo->loggingAgentPassword = wo->randomGenerator.generateAsciiString(64); wo->loggingAgentAdminAddress = "unix:" + wo->generation->getPath() + "/logging_admin"; UPDATE_TRACE_POINT(); wo->adminToolStatusPassword = wo->randomGenerator.generateAsciiString(MESSAGE_SERVER_MAX_PASSWORD_SIZE); wo->adminToolManipulationPassword = wo->randomGenerator.generateAsciiString(MESSAGE_SERVER_MAX_PASSWORD_SIZE); agentsOptions.set("admin_tool_status_password", wo->adminToolStatusPassword); agentsOptions.set("admin_tool_manipulation_password", wo->adminToolManipulationPassword); if (geteuid() == 0 && !userSwitching) { createFile(wo->generation->getPath() + "/passenger-status-password.txt", wo->adminToolStatusPassword, S_IRUSR, wo->defaultUid, wo->defaultGid); createFile(wo->generation->getPath() + "/admin-manipulation-password.txt", wo->adminToolManipulationPassword, S_IRUSR, wo->defaultUid, wo->defaultGid); } else { createFile(wo->generation->getPath() + "/passenger-status-password.txt", wo->adminToolStatusPassword, S_IRUSR | S_IWUSR); createFile(wo->generation->getPath() + "/admin-manipulation-password.txt", wo->adminToolManipulationPassword, S_IRUSR | S_IWUSR); } }
static size_t onRead(char *buffer, size_t size, size_t nitems, void *instream) { WebRequestInternalState *is_(reinterpret_cast<WebRequestInternalState*>(instream)); is_->state = HTTP_OPEN; if (is_->isAborted) { is_->state = HTTP_CLOSED; return CURL_READFUNC_ABORT; } // Find the size in bytes. size_t real_size(size * nitems); // Read as much as we can from the upload buffer queue. Deserializer* upload(dynamic_cast<Deserializer*>(is_->upload.Get())); size_t size_queued(upload->GetSize()); size_t size_left(real_size); if ((size_left > 0) && (size_queued > 0)) { size_t read_size(std::min(size_queued, size_left)); upload->Read(buffer, (unsigned int)read_size); size_left -= read_size; } // If we still have bytes to fill, then emit a "upload_chunk" event. if (size_left > 0) { VariantMap eventData; eventData.Insert(MakePair(StringHash("upload"), Variant(is_->upload))); eventData.Insert(MakePair(StringHash("size"), Variant((unsigned int)size_left))); is_->es.SendEvent("upload_chunk", eventData); } // Read as much as we can from the upload buffer queue (again). size_queued = upload->GetSize(); size_left = real_size; if ((size_left > 0) && (size_queued > 0)) { size_t read_size(std::min(size_queued, size_left)); upload->Read(buffer, (unsigned int)read_size); size_left -= read_size; } // If we still have bytes to fill, then something went wrong, so we should abort. if (size_left > 0) { is_->isAborted = true; return CURL_READFUNC_ABORT; } return real_size; }
void FishingBoat::load( const VariantMap& stream ) { Ship::load( stream ); _d->destination = stream.get( "destination" ); _d->stock.load( stream.get( "stock" ).toList() ); _d->mode = (State)stream.get( "mode", (int)wait ).toInt(); _d->base = ptr_cast<CoastalFactory>(_city()->getOverlay( (TilePos)stream.get( "base" ) ) ); if( _d->base.isValid() ) { _d->base->assignBoat( this ); } }