//------------------------------------------------------------------------------------------------------------------ Response Response::htmlResponse(const std::string& _fileName, unsigned _code) { // Open file File* pageFile = File::openExisting(_fileName); if(pageFile) { Response r(_code, shortDesc(_code)); pageFile->readAll(); r.setBody(pageFile->bufferAsText()); r.headers()["Content-type"] = "text/html"; return r; } else return response404(); }
void Forge::NameWeapon(CHAR_DATA & ch, const char * argument) { // Check for name effect AFFECT_DATA * paf(FindNameEffect(ch)); if (paf == NULL) { send_to_char("You have no weapon waiting to receive a Name.\n", &ch); return; } // Verify the object OBJ_DATA * obj(FindNameableObject(ch, *paf)); affect_remove(&ch, paf); if (obj == NULL) { send_to_char("You are no longer carrying the weapon you empowered to receive a Name.\n", &ch); return; } // Object exists and is carried by the char, so name it according to the argument act("You pass your hand over $p, willing the Name into it.", &ch, obj, NULL, TO_CHAR); act("$n passes $s hand over $p, murmuring softly.", &ch, obj, NULL, TO_ROOM); // Echo about the naming std::ostringstream mess; mess << "A deep rush of power sweeps over $p as it claims the Name \"" << argument << "\"!"; act(mess.str().c_str(), &ch, &obj, NULL, TO_ALL); // Add the name to the short desc std::string shortDesc(obj->short_descr); shortDesc += ", \""; shortDesc += argument; shortDesc += '"'; SetBasicDescs(*obj, shortDesc.c_str(), true); // Create lore static char *his_her [] = { "its", "his", "her" }; const char * ch_name(IS_NPC(&ch) ? ch.short_descr : ch.name); std::ostringstream lore; lore << "Forged by the " << race_table[ch.race].name << " smith " << ch_name; lore << ", this mighty " << flag_string(weapon_class, obj->value[0]) << " was given its Name by the same."; lore << "Imbuing it with " << his_her[ch.sex] << " own power, " << ch_name << " marked \"" << argument; lore << "\" as an extension of " << his_her[ch.sex] << " very being."; copy_string(obj->lore, lore.str().c_str()); obj->lore = format_string(obj->lore); }
void Drakes::AdjustDrake(CHAR_DATA & ch, CHAR_DATA & drake, int stoneType, const Info & info, int level, Age age) { // Set the appropriate strings const char * stoneName(material_table[stoneType].name); std::string shortDesc(BuildShortDesc(stoneName, age)); std::string longDesc(shortDesc + " is here.\n"); longDesc[0] = UPPER(longDesc[0]); setName(drake, shortDesc.c_str()); copy_string(drake.short_descr, shortDesc.c_str()); copy_string(drake.long_descr, longDesc.c_str()); copy_string(drake.description, BuildDescription(ch, stoneName, age).c_str()); // Seed any random values with ch's id srand(ch.id + 12345); // Adjust damage type and damverb drake.dam_type = info.damageType; const char * damverb("strike"); switch (info.damageType) { case DAM_BASH: switch ((rand() + stoneType) % 3) { case 0: damverb = "slam"; break; case 1: damverb = "smash"; break; case 2: damverb = "crush"; break; } break; case DAM_SLASH: switch ((rand() + stoneType) % 3) { case 0: damverb = "slice"; break; case 1: damverb = "claw"; break; case 2: damverb = "talon"; break; } break; case DAM_PIERCE: switch ((rand() + stoneType) % 2) { case 0: damverb = "bite"; break; case 1: damverb = "strike"; break; } break; } copy_string(drake.dam_verb, damverb); // Perform basic adjustments drake.level = UMAX(1, level + age); drake.damroll = (level / 10) + (age * 4); drake.hitroll = (level * 2) / 3; drake.damage[0] = (level * 2) / 3; drake.damage[1] = 4; drake.damage[2] = drake.damroll; drake.max_hit = dice(level * 4, 19) + 400 + (age * 100); // Adjust for damage and hp mods drake.damage[0] = (drake.damage[0] * (100 + info.damageMod)) / 100; drake.max_hit = (drake.max_hit * (100 + info.hpMod)) / 100; // Adjust stats for (size_t i(0); i < MAX_STATS; ++i) { drake.perm_stat[i] = 18 + age; drake.mod_stat[i] = 18 + age; drake.max_stat[i] = 18 + age; } // Fill in resistances for (size_t i(0); i < info.resistances.size(); ++i) drake.resist[info.resistances[i].type] = info.resistances[i].modBase + (age * info.resistances[i].modStep); // Restore random seed srand(time(0)); // Determine duration until next age level up int duration((age + 1) * 260); if (age == Ancient) duration = -1; else duration = (duration * (100 + info.maturationMod)) / 100; // Mark the drake's stone type and age in the modifier and level fields AFFECT_DATA af = {0}; af.where = TO_AFFECTS; af.type = gsn_wakenedstone; af.modifier = stoneType; af.level = age; af.duration = duration; affect_to_char(&drake, &af); // Adjust the drake's level for overwhelm drake.level += SpecialCount(drake, Overwhelm); }
int main(int argc, char* argv[]) { // NOTE: MacOs X has a lower rlimit for opened file descriptor than Linux (256 // in Snow Leopard vs 512 in SLC5). This is a problem for some of the workflows // that open many small root datafiles. Notice that this is safe to do also // for Linux, but we agreed not to change the behavior there for the moment. // Also the limits imposed by ulimit are not affected and still apply, if // there. #ifdef __APPLE__ struct rlimit limits; getrlimit(RLIMIT_NOFILE, &limits); limits.rlim_cur = (OPEN_MAX < limits.rlim_max) ? OPEN_MAX : limits.rlim_max; setrlimit(RLIMIT_NOFILE, &limits); #endif // We must initialize the plug-in manager first try { edmplugin::PluginManager::configure(edmplugin::standard::config()); } catch(const std::exception& e) { std::cerr << e.what() << std::endl; return 1; } // Decide whether to use the multi-thread or single-thread message logger // (Just walk the command-line arguments, since the boost parser will // be run below and can lead to error messages which should be sent via // the message logger) bool multiThreadML = false; for (int i=0; i<argc; ++i) { if ( (std::strncmp (argv[i],"-t", 20) == 0) || (std::strncmp (argv[i],"--multithreadML", 20) == 0) ) { multiThreadML = true; break; } } // TEMPORARY -- REMOVE AT ONCE!!!!! // if ( multiThreadML ) std::cerr << "\n\n multiThreadML \n\n"; // Load the message service plug-in boost::shared_ptr<edm::Presence> theMessageServicePresence; if (multiThreadML) { try { theMessageServicePresence = boost::shared_ptr<edm::Presence>(edm::PresenceFactory::get()-> makePresence("MessageServicePresence").release()); } catch(cms::Exception& e) { std::cerr << e.what() << std::endl; return 1; } } else { try { theMessageServicePresence = boost::shared_ptr<edm::Presence>(edm::PresenceFactory::get()-> makePresence("SingleThreadMSPresence").release()); } catch(cms::Exception& e) { std::cerr << e.what() << std::endl; return 1; } } // // Specify default services to be enabled with their default parameters. // // The parameters for these can be overridden from the configuration files. std::vector<std::string> defaultServices; defaultServices.reserve(6); defaultServices.push_back("MessageLogger"); defaultServices.push_back("InitRootHandlers"); #ifdef linux defaultServices.push_back("EnableFloatingPointExceptions"); #endif defaultServices.push_back("UnixSignalService"); defaultServices.push_back("AdaptorConfig"); defaultServices.push_back("SiteLocalConfigService"); // These cannot be overridden from the configuration files. // An exception will be thrown if any of these is specified there. std::vector<std::string> forcedServices; forcedServices.reserve(1); forcedServices.push_back("JobReportService"); std::string descString(argv[0]); descString += " [options] [--"; descString += kParameterSetOpt; descString += "] config_file \nAllowed options"; boost::program_options::options_description desc(descString); desc.add_options() (kHelpCommandOpt, "produce help message") (kParameterSetCommandOpt, boost::program_options::value<std::string>(), "configuration file") (kJobreportCommandOpt, boost::program_options::value<std::string>(), "file name to use for a job report file: default extension is .xml") (kEnableJobreportCommandOpt, "enable job report files (if any) specified in configuration file") (kJobModeCommandOpt, boost::program_options::value<std::string>(), "Job Mode for MessageLogger defaults - default mode is grid") (kMultiThreadMessageLoggerOpt, "MessageLogger handles multiple threads - default is single-thread") (kStrictOpt, "strict parsing"); // anything at the end will be ignored, and sent to python boost::program_options::positional_options_description p; p.add(kParameterSetOpt, 1).add(kPythonOpt, -1); // This --fwk option is not used anymore, but I'm leaving it around as // it might be useful again in the future for code development // purposes. We originally used it when implementing the boost // state machine code. boost::program_options::options_description hidden("hidden options"); hidden.add_options()("fwk", "For use only by Framework Developers") (kPythonOpt, boost::program_options::value< std::vector<std::string> >(), "options at the end to be passed to python"); boost::program_options::options_description all_options("All Options"); all_options.add(desc).add(hidden); boost::program_options::variables_map vm; try { store(boost::program_options::command_line_parser(argc,argv).options(all_options).positional(p).run(),vm); notify(vm); } catch(boost::program_options::error const& iException) { edm::LogError("FwkJob") << "Exception from command line processing: " << iException.what(); edm::LogSystem("CommandLineProcessing") << "Exception from command line processing: " << iException.what() << "\n"; return 7000; } if(vm.count(kHelpOpt)) { std::cout << desc <<std::endl; if(!vm.count(kParameterSetOpt)) edm::HaltMessageLogging(); return 0; } if(!vm.count(kParameterSetOpt)) { std::string shortDesc("ConfigFileNotFound"); std::ostringstream longDesc; longDesc << "cmsRun: No configuration file given.\n" << "For usage and an options list, please do '" << argv[0] << " --" << kHelpOpt << "'."; int exitCode = 7001; edm::LogAbsolute(shortDesc) << longDesc.str() << "\n"; edm::HaltMessageLogging(); return exitCode; } #ifdef CHANGED_FROM if(!vm.count(kParameterSetOpt)) { std::string shortDesc("ConfigFileNotFound"); std::ostringstream longDesc; longDesc << "No configuration file given \n" <<" please do '" << argv[0] << " --" << kHelpOpt << "'."; int exitCode = 7001; jobRep->reportError(shortDesc, longDesc.str(), exitCode); edm::LogSystem(shortDesc) << longDesc.str() << "\n"; return exitCode; } #endif // // Decide whether to enable creation of job report xml file // We do this first so any errors will be reported // std::string jobReportFile; if (vm.count("jobreport")) { jobReportFile = vm["jobreport"].as<std::string>(); } else if (vm.count("enablejobreport")) { jobReportFile = "FrameworkJobReport.xml"; } std::auto_ptr<std::ofstream> jobReportStreamPtr = std::auto_ptr<std::ofstream>(jobReportFile.empty() ? 0 : new std::ofstream(jobReportFile.c_str())); // // Make JobReport Service up front // //NOTE: JobReport must have a lifetime shorter than jobReportStreamPtr so that when the JobReport destructor // is called jobReportStreamPtr is still valid std::auto_ptr<edm::JobReport> jobRepPtr(new edm::JobReport(jobReportStreamPtr.get())); boost::shared_ptr<edm::serviceregistry::ServiceWrapper<edm::JobReport> > jobRep( new edm::serviceregistry::ServiceWrapper<edm::JobReport>(jobRepPtr) ); edm::ServiceToken jobReportToken = edm::ServiceRegistry::createContaining(jobRep); std::string fileName(vm[kParameterSetOpt].as<std::string>()); boost::shared_ptr<edm::ProcessDesc> processDesc; try { processDesc = edm::readConfig(fileName, argc, argv); } catch(cms::Exception& iException) { std::string shortDesc("ConfigFileReadError"); std::ostringstream longDesc; longDesc << "Problem with configuration file " << fileName << "\n" << iException.what(); int exitCode = 7002; jobRep->get().reportError(shortDesc, longDesc.str(), exitCode); edm::LogSystem(shortDesc) << longDesc.str() << "\n"; return exitCode; } processDesc->addServices(defaultServices, forcedServices); // // Decide what mode of hardcoded MessageLogger defaults to use // if (vm.count("mode")) { std::string jobMode = vm["mode"].as<std::string>(); edm::MessageDrop::instance()->jobMode = jobMode; } if(vm.count(kStrictOpt)) { //edm::setStrictParsing(true); edm::LogSystem("CommandLineProcessing") << "Strict configuration processing is now done from python"; } // Now create and configure the services // EventProcessorWithSentry proc; int rc = -1; // we should never return this value! try { std::auto_ptr<edm::EventProcessor> procP(new edm::EventProcessor(processDesc, jobReportToken, edm::serviceregistry::kTokenOverrides)); EventProcessorWithSentry procTmp(procP); proc = procTmp; proc->beginJob(); if(!proc->forkProcess(jobReportFile)) { return 0; } proc.on(); bool onlineStateTransitions = false; proc->runToCompletion(onlineStateTransitions); proc.off(); proc->endJob(); rc = 0; // Disable Root Error Handler so we do not throw because of ROOT errors. edm::ServiceToken token = proc->getToken(); edm::ServiceRegistry::Operate operate(token); edm::Service<edm::RootHandlers> rootHandler; rootHandler->disableErrorHandler(); } catch (edm::Exception& e) { rc = e.returnCode(); edm::printCmsException(e, kProgramName, &(jobRep->get()), rc); } catch (cms::Exception& e) { rc = 8001; edm::printCmsException(e, kProgramName, &(jobRep->get()), rc); } catch(std::bad_alloc& bda) { rc = 8004; edm::printBadAllocException(kProgramName, &(jobRep->get()), rc); } catch (std::exception& e) { rc = 8002; edm::printStdException(e, kProgramName, &(jobRep->get()), rc); } catch (...) { rc = 8003; edm::printUnknownException(kProgramName, &(jobRep->get()), rc); } // Disable Root Error Handler again, just in case an exception // caused the above disabling of the handler to be bypassed. SetErrorHandler(DefaultErrorHandler); return rc; }
//------------------------------------------------------------------------------------------------------------------ Response Response::jsonResponse(const Json& _payload, unsigned _code) { Response r(_code, shortDesc(_code)); r.setBody(_payload.serialize()); r.headers()["Content-type"] = "application/json"; return r; }
//------------------------------------------------------------------------------------------------------------------ Response Response::response404(const std::string& _customMessage) { Response r(404, shortDesc(404)); r.setBody(_customMessage); return r; }
//------------------------------------------------------------------------------------------------------------------ Response Response::response200(const std::string& _customMessage) { Response r(200, shortDesc(200)); r.setBody(_customMessage); return r; }