int main() { size_t i = 0; while (cin.good()) { WorldStatusUpdate world; readProtoFromStream(world, cin); cerr << "Tick: " << i << endl; cerr << "Proto content with DebugString" << endl; cerr << world.DebugString() << endl; Commands commands; Commands::Command* command = commands.add_commands(); command->set_commandtype(Commands::TRAIN); Commands::Train* train = command->mutable_traincommand(); train->set_withwhat("Champion"); train->set_what(Commands::WORKER); writeProtoOnStream(commands, cout); ++i; } return 0; }
static int _handle_options(int argc, char **argv) { int i; while(argc > 0) { const char *cmd = argv[0]; for (i = 0; i < ARRAY_SIZE(commands); i++) { Commands *c = commands + i; if (strcmp(c->cmd, cmd)) continue; if (c->fn) c->fn(argc, argv); } argv++; argc--; } return 0; }
void CommandMgr::ClearCommands() { while (!commandTable.empty()) { Commands::iterator itr = commandTable.begin(); delete itr->second; commandTable.erase(itr); } }
~Rule() { delete filter_; typedef Commands::const_iterator It; for (It i = cmds_->begin(); i != cmds_->end(); ++i) { delete *i; } delete cmds_; }
int main() { Commands Input; Input.Input(); ParseText(); return 0; }
void Cmd_struct::match() { int choice = -1; // first four letters are commands string substring = this->command.substr(0,4); string file = ""; Commands commands; // get the commands from textResources\\basicCommands.txt vector<string> command_codes = commands.getCodes(); // Iterate over all basic commands for (int i = 0; i < command_codes.size(); i++) { if (substring == command_codes[i]) { choice = i; } } if(choice == 3 || choice == 6) { // If we search there is a search query file = this->command.substr(5, this->command.length() - 5); } FunctionHandler fh; switch (choice) { case 0: this->test(); break; case 1: this->shutdown(); break; case 2: this->chrom(); break; case 3: this->playMedia(file); break; case 4: fh.executeBatch("ccleaner.bat"); break; case 5: fh.executeBatch("startuTorrent.bat"); break; case 6: this->closeProgram(file); break; default: this->error(); break; } }
boost::any execute(const command& c) const { Commands::const_iterator it = commands.find(c.name); if (it != commands.end()) { return (it->second.func)->execute(c); } else { return boost::any();//return std::string("unknown command"); } }
Shrinkable<Commands<Cmd>> generateCommands(const Random &random, int size) const { return shrinkable::map(generateSequence(random, size), [](const CommandSequence &sequence) { Commands<Cmd> cmds; const auto &entries = sequence.entries; cmds.reserve(entries.size()); std::transform(begin(entries), end(entries), std::back_inserter(cmds), [](const CommandEntry &entry) { return entry.shrinkable.value(); }); return cmds; }); }
int main(int argc, char *argv[]) { MythFileRecorderCommandLineParser cmdline; if (!cmdline.Parse(argc, argv)) { cmdline.PrintHelp(); return GENERIC_EXIT_INVALID_CMDLINE; } if (cmdline.toBool("showhelp")) { cmdline.PrintHelp(); return GENERIC_EXIT_OK; } if (cmdline.toBool("showversion")) { cmdline.PrintVersion(); return GENERIC_EXIT_OK; } bool loopinput = !cmdline.toBool("noloop"); int data_rate = cmdline.toInt("data_rate"); QCoreApplication a(argc, argv); QCoreApplication::setApplicationName("mythfilerecorder"); int retval; if ((retval = cmdline.ConfigureLogging()) != GENERIC_EXIT_OK) return retval; QString filename = ""; if (!cmdline.toString("infile").isEmpty()) filename = cmdline.toString("infile"); else if (cmdline.GetArgs().size() >= 1) filename = cmdline.GetArgs()[0]; Commands recorder; recorder.Run(filename, data_rate, loopinput); return GENERIC_EXIT_OK; }
int NpcScriptInterface::luaActionSayCommand(lua_State* L) { //commandSay(words) std::string msg(popString(L)); ScriptEnviroment* env = getScriptEnv(); Npc* mynpc = env->getNpc(); if(mynpc) if(commands.exeCommand(mynpc, msg)) return 0; }
void VDDialogEditAccelerators::RefilterCommands(const char *pattern) { mFilteredCommands.clear(); LBClear(IDC_AVAILCOMMANDS); Commands::const_iterator it(mAllCommands.begin()), itEnd(mAllCommands.end()); for(; it != itEnd; ++it) { const VDAccelToCommandEntry& ent = **it; if (VDFileWildMatch(pattern, ent.mpName)) { const VDStringW s(VDTextAToW(ent.mpName)); mFilteredCommands.push_back(&ent); LBAddString(IDC_AVAILCOMMANDS, s.c_str()); } } LBSetSelectedIndex(IDC_AVAILCOMMANDS, 0); }
Commands prepareCommands() { Commands commands; commands.push_back(Command {"set-led-state", "Set led state", {"on", "off"}}); commands.push_back(Command {"get-led-state", "Get led state", {}}); commands.push_back(Command {"set-led-color", "Set led color (red, green or blue)", {"red", "green", "blue"}}); commands.push_back(Command {"get-led-color", "Get led color", {}}); commands.push_back(Command {"set-led-rate", "Set led rate (0..5 Hz)", {"0", "1", "2", "3", "4", "5"}}); commands.push_back(Command {"get-led-rate", "Get led rate", {}}); return commands; }
/** The command handler functions. */ bool cmdGetItem( Command& command ) { const QueueGetItemPacket* packet = command.get< QueueGetItemPacket >(); Commands commands; queue.tryPop( packet->itemsRequested, commands ); for( CommandsCIter i = commands.begin(); i != commands.end(); ++i ) { Command* item = *i; ObjectPacket* reply = item->getModifiable< ObjectPacket >(); reply->instanceID = packet->slaveInstanceID; command.getNode()->send( *reply ); item->release(); } if( packet->itemsRequested > commands.size( )) { QueueEmptyPacket reply( packet ); command.getNode()->send( reply ); } return true; }
pair<int,int> getAction(const Commands& commands) { while ( true ) { displayMenu(commands); int choice = getNumber(0,commands.size()); int subChoice = 0; if (choice == 0) return make_pair(-1,0); if (!commands[choice-1].params.empty()) { displaySubMenu(commands[choice-1].params); subChoice = getNumber(0,commands[choice-1].params.size()); if (subChoice == 0) continue; } return make_pair(choice-1, subChoice-1); } }
void ScreenOptionsMaster::Init() { vector<RString> asLineNames; split( LINE_NAMES, ",", asLineNames ); if( asLineNames.empty() ) { LuaHelpers::ReportScriptErrorFmt("\"%s:LineNames\" is empty.", m_sName.c_str()); } if( FORCE_ALL_PLAYERS ) { FOREACH_PlayerNumber( pn ) GAMESTATE->JoinPlayer( pn ); } if( NAVIGATION_MODE == "toggle" ) SetNavigation( PREFSMAN->m_iArcadeOptionsNavigation? NAV_TOGGLE_THREE_KEY:NAV_TOGGLE_FIVE_KEY ); else if( NAVIGATION_MODE == "menu" ) SetNavigation( NAV_THREE_KEY_MENU ); SetInputMode( StringToInputMode(INPUT_MODE) ); // Call this after enabling players, if any. ScreenOptions::Init(); vector<OptionRowHandler*> OptionRowHandlers; for( unsigned i = 0; i < asLineNames.size(); ++i ) { RString sLineName = asLineNames[i]; RString sRowCommands = LINE(sLineName); Commands cmds; ParseCommands( sRowCommands, cmds, false ); OptionRowHandler *pHand = OptionRowHandlerUtil::Make( cmds ); if( pHand == NULL ) { LuaHelpers::ReportScriptErrorFmt("Invalid OptionRowHandler \"%s\" in \"%s:Line:%s\".", cmds.GetOriginalCommandString().c_str(), m_sName.c_str(), sLineName.c_str()); } else { OptionRowHandlers.push_back( pHand ); } } InitMenu( OptionRowHandlers ); }
void VDDialogEditAccelerators::OnItemSelectionChanged(VDUIProxyListView *source, int index) { if (index < 0 || mbBlockCommandUpdate) return; const BoundCommand& bcmd = *mBoundCommands[index]; if (mpHotKeyControl) mpHotKeyControl->SetAccelerator(bcmd.mAccel); uint32 n = mFilteredCommands.size(); int cmdSelIndex = -1; for(uint32 i=0; i<n; ++i) { const VDAccelToCommandEntry& cent = *mFilteredCommands[i]; if (!_stricmp(cent.mpName, bcmd.mpCommand)) { cmdSelIndex = i; break; } } LBSetSelectedIndex(IDC_AVAILCOMMANDS, cmdSelIndex); }
virtual void preRun() override { Fields::login = commands.login() + " " + getUdpString(); this->write({{ Fields::login }}); }
const Command& GlobalCommands_find( const char* command ){ Commands::iterator i = g_commands.find( command ); ASSERT_MESSAGE( i != g_commands.end(), "failed to lookup command " << makeQuoted( command ) ); return ( *i ).second; }
void GlobalCommands_insert( const char* name, const Callback& callback, const Accelerator& accelerator ){ bool added = g_commands.insert( Commands::value_type( name, Command( callback, GlobalShortcuts_insert( name, accelerator ) ) ) ).second; ASSERT_MESSAGE( added, "command already registered: " << makeQuoted( name ) ); }
void undo() { for(Commands::const_reverse_iterator i = cmds.rbegin(); i != cmds.rend(); ++i) (*i)->undo(); }
void redo() { for(Commands::const_iterator i = cmds.begin(); i != cmds.end(); ++i) (*i)->redo(); }
void add(CommandHandle cmd) { cmds.push_back(cmd); }
//to be inserted in main int main() { string commLine; Commands * c = new Commands(); while(1) //wamt jos tp lee[ going because exit will end it here or in functions { prompt(); //prints [USERNAME]@[HOSTNAME]$ getline(cin, commLine); size_t foundTest = commLine.find("test"); //this will check "test" in the string size_t foundFirstBracket = commLine.find("["); //this will check "[" in the string size_t foundSecBracket = commLine.find("]"); // this will check "]" in the string // check if the string has "test" or "[]" in the string if(foundTest != string::npos || (foundFirstBracket != string::npos && foundSecBracket != string:: npos)) { c->testP(commLine); } else if(commLine == "exit") //EXIT program if user types "exit" { exit(0); } else { c->commandP(commLine); } } // Commands * c = new Commands(); // string commLine; // vector <string> com; // vector <bool> returnv; // while(1) // { // prompt(); // getline(cin, commLine); // while(commLine != "") //while not empty string // { // int endP = commLine.find(")"); // if (commLine.find(")") != string::npos) // { // if (endP > commLine.find("||") && endP > commLine.find("&&") && endP > commLine.find(";")) // { // if (commLine.find("(") != string::npos) // { // int beginP = commLine.find("("); // com.push_back(commLine.substr(beginP, endP)); //so that it gets rid of the parentheses // commLine.erase(beginP, endP); //erase that second from the string // } // else // { // perror("Invalid command."); // } // } // else // { // int beginP = commLine.find("("); // if (beginP != string::npos) // { // int findAND = commLine.find("&"); // int findOR = commLine.find("|"); // int findSEMI = commLine.find(";"); // if (findAND != string::npos && findAND - 3 <= 0) // { // com.push_back("&&"); // commLine.erase(0, 2); // } // else if (findOR != string::npos && findOR - 3 <= 0) // { // com.push_back("||"); // commLine.erase(0, 2); // } // else if (findSEMI != string::npos && findSEMI - 3 <= 0) // { // com.push_back(";"); // commLine.erase(0, 2); // } // com.push_back(commLine.substr(0, beginP - 1)); // commLine.erase(0, beginP - 1); // } // else // { // perror("Invalid command"); // } // } // } // else // { // size_t foundTest = commLine.find("test"); //this will check "test" in the string // size_t foundFirstBracket = commLine.find("["); //this will check "[" in the string // size_t foundSecBracket = commLine.find("]"); // this will check "]" in the string // // check if the string has "test" or "[]" in the string // if(foundTest != string::npos || (foundFirstBracket != string::npos && foundSecBracket != string:: npos)) // { // c->testP(commLine); // commLine.erase(0, commLine.size() - 1); // } // else if(commLine == "exit") //EXIT program if user types "exit" // { // exit(0); // } // else // { // c->commandP(commLine); // commLine.erase(0, commLine.size() - 1); // } // //okay so pretty much, this else is just to run it like normal // //so using the old main, i'm just commenting it out for testing // } // } // for (int i = 0; i < com.size(); ++i) // { // if (com.at(i) == "&&" || com.at(i) == ";") // { // if(i > 0) // { // size_t foundTest = commLine.find("test"); //this will check "test" in the string // size_t foundFirstBracket = commLine.find("["); //this will check "[" in the string // size_t foundSecBracket = commLine.find("]"); // this will check "]" in the string // if(foundTest != string::npos || (foundFirstBracket != string::npos && foundSecBracket != string:: npos)) // { // ++i; // returnv.push_back(c->testP(com.at(i))); //assuming it returns a bool // } // else if(commLine == "exit") //EXIT program if user types "exit" // { // exit(0); // } // else // { // ++i; // //returnv.push_back(c->commandP(com.at(i))); //assuming it returns a bool // } // } // else // { // perror("Invaid command."); //I'm not sure if thats the right error for this // //its for having a connector with nothing infront of it // } // } // else if(com.at(i) == "||") // { // if(i > 0 && returnv.at(i - 1) == false) // { // size_t foundTest = commLine.find("test"); //this will check "test" in the string // size_t foundFirstBracket = commLine.find("["); //this will check "[" in the string // size_t foundSecBracket = commLine.find("]"); // this will check "]" in the string // if(foundTest != string::npos || (foundFirstBracket != string::npos && foundSecBracket != string:: npos)) // { // ++i; // returnv.push_back(c->testP(com.at(i))); // } // else if(commLine == "exit") //EXIT program if user types "exit" // { // exit(0); // } // else // { // ++i; // //returnv.push_back(c->commandP(com.at(i))); // } // } // else // { // perror("Invaid command."); //I'm not sure if thats the right error for this // //its for having a connector with nothing infront of it // } // } // else // { // size_t foundTest = commLine.find("test"); //this will check "test" in the string // size_t foundFirstBracket = commLine.find("["); //this will check "[" in the string // size_t foundSecBracket = commLine.find("]"); // this will check "]" in the string // if(foundTest != string::npos || (foundFirstBracket != string::npos && foundSecBracket != string:: npos)) // { // returnv.push_back(c->testP(com.at(i))); // } // else if(commLine == "exit") //EXIT program if user types "exit" // { // exit(0); // } // else // { // //returnv.push_back(c->commandP(com.at(i))); // } // } // } // } // return 0; }
void populateCommands() { { CommandDescriptor command("ls","list entries in current folder","ls"); g_availableCommands.push_back(command); } { CommandDescriptor command("pwd","display current working dir","pwd"); g_availableCommands.push_back(command); } { CommandDescriptor command("mkdir","create folder","mkdir <folderName>"); g_availableCommands.push_back(command); } { CommandDescriptor command("push","change to folder","push <folderName>"); g_availableCommands.push_back(command); } { CommandDescriptor command("pop","change to previous folder","pop"); g_availableCommands.push_back(command); } { CommandDescriptor command("cd","change to folder","cd <folderName>"); g_availableCommands.push_back(command); } { CommandDescriptor command("rm","remove entry","rm <entryName>"); g_availableCommands.push_back(command); } { CommandDescriptor command("add","add a file or folder to current working dir","add <file:///path/to/thing>"); g_availableCommands.push_back(command); } { CommandDescriptor command("extract","extract a file or folder","extract <entryName> <file:///place/to/extract>"); g_availableCommands.push_back(command); } { CommandDescriptor command("help","list available commands","help"); g_availableCommands.push_back(command); } { CommandDescriptor command("quit","exit the shell","quit"); g_availableCommands.push_back(command); } { CommandDescriptor command("exit","exit the shell","exit"); g_availableCommands.push_back(command); } }
void OptionsList::Load( RString sType, PlayerNumber pn ) { TOP_MENU.Load( sType, "TopMenu" ); m_pn = pn; m_bStartIsDown = false; m_Codes.Load( sType ); m_Cursor.Load( THEME->GetPathG(sType, "cursor") ); m_Cursor->SetName( "Cursor" ); ActorUtil::LoadAllCommands( *m_Cursor, sType ); this->AddChild( m_Cursor ); vector<RString> asDirectLines; split( DIRECT_LINES, ",", asDirectLines, true ); FOREACH( RString, asDirectLines, s ) m_setDirectRows.insert( *s ); vector<RString> setToLoad; split( TOP_MENUS, ",", setToLoad ); m_setTopMenus.insert( setToLoad.begin(), setToLoad.end() ); while( !setToLoad.empty() ) { RString sLineName = *setToLoad.begin(); setToLoad.erase( setToLoad.begin() ); if( m_Rows.find(sLineName) != m_Rows.end() ) continue; RString sRowCommands = LINE(sLineName); Commands cmds; ParseCommands( sRowCommands, cmds, false ); OptionRowHandler *pHand = OptionRowHandlerUtil::Make( cmds ); if( pHand == NULL ) { LuaHelpers::ReportScriptErrorFmt("Invalid OptionRowHandler '%s' in %s::Line%s", cmds.GetOriginalCommandString().c_str(), m_sName.c_str(), sLineName.c_str()); continue; } m_Rows[sLineName] = pHand; m_asLoadedRows.push_back( sLineName ); for( size_t i = 0; i < pHand->m_Def.m_vsChoices.size(); ++i ) { RString sScreen = pHand->GetScreen(i); if( !sScreen.empty() ) setToLoad.push_back( sScreen ); } } for( int i = 0; i < 2; ++i ) { m_Row[i].SetName( "OptionsList" ); m_Row[i].Load( this, "OptionsList" ); ActorUtil::LoadAllCommands( m_Row[i], sType ); this->AddChild( &m_Row[i] ); } this->PlayCommand( "TweenOff" ); this->FinishTweening(); }
void mainLoader(int argc, char* argv[], ServiceManager* services) { //dispatcher thread g_game.setGameState(GAME_STATE_STARTUP); srand((unsigned int)OTSYS_TIME()); #ifdef WIN32 SetConsoleTitle(STATUS_SERVER_NAME); #endif std::cout << STATUS_SERVER_NAME << " - Version " << STATUS_SERVER_VERSION << std::endl; std::cout << "Compilied on " << __DATE__ << " " << __TIME__ << " for arch "; #if defined(__amd64__) || defined(_M_X64) std::cout << "x64" << std::endl; #elif defined(__i386__) || defined(_M_IX86) || defined(_X86_) std::cout << "x86" << std::endl; #else std::cout << "unk" << std::endl; #endif std::cout << std::endl; std::cout << "A server developed by " << STATUS_SERVER_DEVELOPERS << std::endl; std::cout << "Visit our forum for updates, support, and resources: http://otland.net/." << std::endl; std::cout << std::endl; // read global config std::cout << ">> Loading config" << std::endl; if (!g_config.loadFile("config.lua")) { startupErrorMessage("Unable to load config.lua!"); return; } #ifdef WIN32 std::string defaultPriority = asLowerCaseString(g_config.getString(ConfigManager::DEFAULT_PRIORITY)); if (defaultPriority == "realtime") { SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); } else if (defaultPriority == "high") { SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); } else if (defaultPriority == "higher") { SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); } std::ostringstream mutexName; mutexName << "forgottenserver_" << g_config.getNumber(ConfigManager::LOGIN_PORT); CreateMutex(NULL, FALSE, mutexName.str().c_str()); if (GetLastError() == ERROR_ALREADY_EXISTS) { startupErrorMessage("Another instance of The Forgotten Server is already running with the same login port, please shut it down first or change ports for this one."); return; } #endif //set RSA key const char* p("14299623962416399520070177382898895550795403345466153217470516082934737582776038882967213386204600674145392845853859217990626450972452084065728686565928113"); const char* q("7630979195970404721891201847792002125535401292779123937207447574596692788513647179235335529307251350570728407373705564708871762033017096809910315212884101"); const char* d("46730330223584118622160180015036832148732986808519344675210555262940258739805766860224610646919605860206328024326703361630109888417839241959507572247284807035235569619173792292786907845791904955103601652822519121908367187885509270025388641700821735345222087940578381210879116823013776808975766851829020659073"); g_RSA.setKey(p, q, d); std::cout << ">> Establishing database connection..." << std::flush; Database* db = Database::getInstance(); if (!db->connect()) { startupErrorMessage("Failed to connect to database."); return; } std::cout << " MySQL " << db->getClientVersion() << std::endl; // run database manager std::cout << ">> Running database manager" << std::endl; DatabaseManager* dbManager = DatabaseManager::getInstance(); if (!dbManager->isDatabaseSetup()) { startupErrorMessage("The database you have specified in config.lua is empty, please import the schema to the database."); return; } for (uint32_t version = dbManager->updateDatabase(); version != 0; version = dbManager->updateDatabase()) { std::cout << "> Database has been updated to version " << version << "." << std::endl; } dbManager->checkTriggers(); dbManager->checkEncryption(); if (g_config.getBoolean(ConfigManager::OPTIMIZE_DATABASE) && !dbManager->optimizeTables()) { std::cout << "> No tables were optimized." << std::endl; } //load vocations std::cout << ">> Loading vocations" << std::endl; if (!g_vocations.loadFromXml()) { startupErrorMessage("Unable to load vocations!"); return; } //load commands std::cout << ">> Loading commands" << std::endl; if (!commands.loadFromXml()) { startupErrorMessage("Unable to load commands!"); return; } // load item data std::cout << ">> Loading items" << std::endl; if (Item::items.loadFromOtb("data/items/items.otb")) { startupErrorMessage("Unable to load items (OTB)!"); return; } if (!Item::items.loadFromXml()) { startupErrorMessage("Unable to load items (XML)!"); return; } std::cout << ">> Loading script systems" << std::endl; if (!ScriptingManager::getInstance()->loadScriptSystems()) { startupErrorMessage("Failed to load script systems"); return; } std::cout << ">> Loading monsters" << std::endl; if (!g_monsters.loadFromXml()) { startupErrorMessage("Unable to load monsters!"); return; } std::cout << ">> Loading outfits" << std::endl; Outfits* outfits = Outfits::getInstance(); if (!outfits->loadFromXml()) { startupErrorMessage("Unable to load outfits!"); return; } g_adminConfig = new AdminProtocolConfig(); std::cout << ">> Loading admin protocol config" << std::endl; if (!g_adminConfig->loadXMLConfig()) { startupErrorMessage("Unable to load admin protocol config!"); return; } std::cout << ">> Loading experience stages" << std::endl; if (!g_game.loadExperienceStages()) { startupErrorMessage("Unable to load experience stages!"); return; } std::string passwordType = asLowerCaseString(g_config.getString(ConfigManager::PASSWORDTYPE)); if (passwordType == "md5") { g_config.setNumber(ConfigManager::PASSWORD_TYPE, PASSWORD_TYPE_MD5); std::cout << ">> Using MD5 passwords" << std::endl; } else if (passwordType == "sha1") { g_config.setNumber(ConfigManager::PASSWORD_TYPE, PASSWORD_TYPE_SHA1); std::cout << ">> Using SHA1 passwords" << std::endl; } else { g_config.setNumber(ConfigManager::PASSWORD_TYPE, PASSWORD_TYPE_PLAIN); std::cout << ">> Using plaintext passwords" << std::endl; } std::cout << ">> Checking world type... " << std::flush; std::string worldType = asLowerCaseString(g_config.getString(ConfigManager::WORLD_TYPE)); if (worldType == "pvp") { g_game.setWorldType(WORLD_TYPE_PVP); } else if (worldType == "no-pvp") { g_game.setWorldType(WORLD_TYPE_NO_PVP); } else if (worldType == "pvp-enforced") { g_game.setWorldType(WORLD_TYPE_PVP_ENFORCED); } else { std::cout << std::endl; std::ostringstream ss; ss << "> ERROR: Unknown world type: " << g_config.getString(ConfigManager::WORLD_TYPE) << ", valid world types are: pvp, no-pvp and pvp-enforced."; startupErrorMessage(ss.str()); return; } std::cout << asUpperCaseString(worldType) << std::endl; std::cout << ">> Loading map" << std::endl; if (!g_game.loadMap(g_config.getString(ConfigManager::MAP_NAME))) { startupErrorMessage("Failed to load map"); return; } std::cout << ">> Initializing gamestate" << std::endl; g_game.setGameState(GAME_STATE_INIT); // Tibia protocols services->add<ProtocolGame>(g_config.getNumber(ConfigManager::GAME_PORT)); services->add<ProtocolLogin>(g_config.getNumber(ConfigManager::LOGIN_PORT)); // OT protocols services->add<ProtocolAdmin>(g_config.getNumber(ConfigManager::ADMIN_PORT)); services->add<ProtocolStatus>(g_config.getNumber(ConfigManager::STATUS_PORT)); // Legacy protocols services->add<ProtocolOldLogin>(g_config.getNumber(ConfigManager::LOGIN_PORT)); services->add<ProtocolOldGame>(g_config.getNumber(ConfigManager::LOGIN_PORT)); int32_t autoSaveEachMinutes = g_config.getNumber(ConfigManager::AUTO_SAVE_EACH_MINUTES); if (autoSaveEachMinutes > 0) { g_scheduler.addEvent(createSchedulerTask(autoSaveEachMinutes * 1000 * 60, boost::bind(&Game::autoSave, &g_game))); } if (g_config.getBoolean(ConfigManager::SERVERSAVE_ENABLED)) { int32_t serverSaveHour = g_config.getNumber(ConfigManager::SERVERSAVE_H); if (serverSaveHour >= 0 && serverSaveHour <= 24) { time_t timeNow = time(NULL); tm* timeinfo = localtime(&timeNow); if (serverSaveHour == 0) { serverSaveHour = 23; } else { serverSaveHour--; } timeinfo->tm_hour = serverSaveHour; timeinfo->tm_min = 55; timeinfo->tm_sec = 0; time_t difference = (time_t)difftime(mktime(timeinfo), timeNow); if (difference < 0) { difference += 86400; } g_scheduler.addEvent(createSchedulerTask(difference * 1000, boost::bind(&Game::prepareServerSave, &g_game))); } } Houses::getInstance().payHouses(); IOLoginData::getInstance()->updateHouseOwners(); g_npcs.reload(); if (g_config.getBoolean(ConfigManager::MARKET_ENABLED)) { g_game.checkExpiredMarketOffers(); IOMarket::getInstance()->updateStatistics(); } std::cout << ">> Loaded all modules, server starting up..." << std::endl; std::pair<uint32_t, uint32_t> IpNetMask; IpNetMask.first = inet_addr("127.0.0.1"); IpNetMask.second = 0xFFFFFFFF; serverIPs.push_back(IpNetMask); char szHostName[128]; if (gethostname(szHostName, 128) == 0) { hostent* he = gethostbyname(szHostName); if (he) { unsigned char** addr = (unsigned char**)he->h_addr_list; while (addr[0] != NULL) { IpNetMask.first = *(uint32_t*)(*addr); IpNetMask.second = 0xFFFFFFFF; serverIPs.push_back(IpNetMask); addr++; } } } std::string ip = g_config.getString(ConfigManager::IP); uint32_t resolvedIp = inet_addr(ip.c_str()); if (resolvedIp == INADDR_NONE) { struct hostent* he = gethostbyname(ip.c_str()); if (!he) { std::ostringstream ss; ss << "ERROR: Cannot resolve " << ip << "!" << std::endl; startupErrorMessage(ss.str()); return; } resolvedIp = *(uint32_t*)he->h_addr; } IpNetMask.first = resolvedIp; IpNetMask.second = 0; serverIPs.push_back(IpNetMask); #if !defined(WIN32) && !defined(__ROOT_PERMISSION__) if (getuid() == 0 || geteuid() == 0) { std::cout << "> WARNING: " << STATUS_SERVER_NAME << " has been executed as root user, it is recommended to execute is as a normal user." << std::endl; } #endif g_game.start(services); g_game.setGameState(GAME_STATE_NORMAL); g_loaderSignal.notify_all(); }
void mainLoader(int argc, char* argv[], ServiceManager* services) { //dispatcher thread g_game.setGameState(GAME_STATE_STARTUP); srand((unsigned int)OTSYS_TIME()); #ifdef _WIN32 SetConsoleTitle(STATUS_SERVER_NAME); #endif std::cout << STATUS_SERVER_NAME << " - Version " << STATUS_SERVER_VERSION << std::endl; std::cout << "Compilied on " << __DATE__ << ' ' << __TIME__ << " for arch "; #if defined(__amd64__) || defined(_M_X64) std::cout << "x64" << std::endl; #elif defined(__i386__) || defined(_M_IX86) || defined(_X86_) std::cout << "x86" << std::endl; #elif defined(__arm__) std::cout << "ARM" << std::endl; #elif defined(__mips__) std::cout << "MIPS" << std::endl; #else std::cout << "unk" << std::endl; #endif std::cout << std::endl; std::cout << "A server developed by " << STATUS_SERVER_DEVELOPERS << std::endl; std::cout << "Visit our forum for updates, support, and resources: http://otland.net/." << std::endl; std::cout << std::endl; // read global config std::cout << ">> Loading config" << std::endl; if (!g_config.load()) { startupErrorMessage("Unable to load config.lua!"); return; } #ifdef _WIN32 std::string defaultPriority = asLowerCaseString(g_config.getString(ConfigManager::DEFAULT_PRIORITY)); if (defaultPriority == "realtime") { SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); } else if (defaultPriority == "high") { SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); } else if (defaultPriority == "higher") { SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); } #endif //set RSA key const char* p("14299623962416399520070177382898895550795403345466153217470516082934737582776038882967213386204600674145392845853859217990626450972452084065728686565928113"); const char* q("7630979195970404721891201847792002125535401292779123937207447574596692788513647179235335529307251350570728407373705564708871762033017096809910315212884101"); g_RSA.setKey(p, q); std::cout << ">> Establishing database connection..." << std::flush; Database* db = Database::getInstance(); if (!db->connect()) { startupErrorMessage("Failed to connect to database."); return; } std::cout << " MySQL " << Database::getClientVersion() << std::endl; // run database manager std::cout << ">> Running database manager" << std::endl; if (!DatabaseManager::isDatabaseSetup()) { startupErrorMessage("The database you have specified in config.lua is empty, please import the schema.sql to your database."); return; } DatabaseManager::updateDatabase(); if (g_config.getBoolean(ConfigManager::OPTIMIZE_DATABASE) && !DatabaseManager::optimizeTables()) { std::cout << "> No tables were optimized." << std::endl; } //load vocations std::cout << ">> Loading vocations" << std::endl; if (!g_vocations.loadFromXml()) { startupErrorMessage("Unable to load vocations!"); return; } //load commands std::cout << ">> Loading commands" << std::endl; if (!g_commands.loadFromXml()) { startupErrorMessage("Unable to load commands!"); return; } // load item data std::cout << ">> Loading items" << std::endl; if (Item::items.loadFromOtb("data/items/items.otb")) { startupErrorMessage("Unable to load items (OTB)!"); return; } if (!Item::items.loadFromXml()) { startupErrorMessage("Unable to load items (XML)!"); return; } std::cout << ">> Loading script systems" << std::endl; if (!ScriptingManager::getInstance()->loadScriptSystems()) { startupErrorMessage("Failed to load script systems"); return; } std::cout << ">> Loading monsters" << std::endl; if (!g_monsters.loadFromXml()) { startupErrorMessage("Unable to load monsters!"); return; } std::cout << ">> Loading outfits" << std::endl; Outfits* outfits = Outfits::getInstance(); if (!outfits->loadFromXml()) { startupErrorMessage("Unable to load outfits!"); return; } g_adminConfig = new AdminProtocolConfig(); std::cout << ">> Loading admin protocol config" << std::endl; if (!g_adminConfig->loadXMLConfig()) { startupErrorMessage("Unable to load admin protocol config!"); return; } std::cout << ">> Loading experience stages" << std::endl; if (!g_game.loadExperienceStages()) { startupErrorMessage("Unable to load experience stages!"); return; } std::cout << ">> Checking world type... " << std::flush; std::string worldType = asLowerCaseString(g_config.getString(ConfigManager::WORLD_TYPE)); if (worldType == "pvp") { g_game.setWorldType(WORLD_TYPE_PVP); } else if (worldType == "no-pvp") { g_game.setWorldType(WORLD_TYPE_NO_PVP); } else if (worldType == "pvp-enforced") { g_game.setWorldType(WORLD_TYPE_PVP_ENFORCED); } else { std::cout << std::endl; std::ostringstream ss; ss << "> ERROR: Unknown world type: " << g_config.getString(ConfigManager::WORLD_TYPE) << ", valid world types are: pvp, no-pvp and pvp-enforced."; startupErrorMessage(ss.str()); return; } std::cout << asUpperCaseString(worldType) << std::endl; std::cout << ">> Loading map" << std::endl; if (!g_game.loadMainMap(g_config.getString(ConfigManager::MAP_NAME))) { startupErrorMessage("Failed to load map"); return; } std::cout << ">> Initializing gamestate" << std::endl; g_game.setGameState(GAME_STATE_INIT); // Game client protocols services->add<ProtocolGame>(g_config.getNumber(ConfigManager::GAME_PORT)); services->add<ProtocolLogin>(g_config.getNumber(ConfigManager::LOGIN_PORT)); // OT protocols services->add<ProtocolAdmin>(g_config.getNumber(ConfigManager::ADMIN_PORT)); services->add<ProtocolStatus>(g_config.getNumber(ConfigManager::STATUS_PORT)); // Legacy protocols services->add<ProtocolOldLogin>(g_config.getNumber(ConfigManager::LOGIN_PORT)); services->add<ProtocolOldGame>(g_config.getNumber(ConfigManager::LOGIN_PORT)); Houses::getInstance().payHouses(); g_game.checkExpiredMarketOffers(); IOMarket::getInstance()->updateStatistics(); std::cout << ">> Loaded all modules, server starting up..." << std::endl; #ifndef WIN32 if (getuid() == 0 || geteuid() == 0) { std::cout << "> Warning: " << STATUS_SERVER_NAME << " has been executed as root user, please consider running it as a normal user." << std::endl; } #endif g_game.start(services); g_game.setGameState(GAME_STATE_NORMAL); g_loaderSignal.notify_all(); }
bool VDDialogEditAccelerators::OnCommand(uint32 id, uint32 extcode) { if (id == IDC_FILTER) { if (extcode == EN_CHANGE) { VDStringA s("*"); s += VDTextWToA(GetControlValueString(id)).c_str(); s += '*'; RefilterCommands(s.c_str()); return true; } } else if (id == IDC_ADD) { VDUIAccelerator accel; int selIdx = LBGetSelectedIndex(IDC_AVAILCOMMANDS); if ((size_t)selIdx < mFilteredCommands.size()) { const VDAccelToCommandEntry *ace = mFilteredCommands[selIdx]; if (mpHotKeyControl) { mpHotKeyControl->GetAccelerator(accel); // Look for a conflicting command. for(BoundCommands::iterator it(mBoundCommands.begin()), itEnd(mBoundCommands.end()); it != itEnd; ++it) { BoundCommand *obc = *it; if (obc->mAccel == accel) { VDStringW keyName; VDUIGetAcceleratorString(accel, keyName); VDStringA msg; msg.sprintf("The key %ls is already bound to %hs. Rebind it to %hs?", keyName.c_str(), obc->mpCommand, ace->mpName); if (IDOK != MessageBox(mhdlg, msg.c_str(), g_szWarning, MB_OKCANCEL | MB_ICONEXCLAMATION)) return true; mBoundCommands.erase(it); obc->Release(); } } vdrefptr<BoundCommand> bc(new_nothrow BoundCommand); if (bc) { bc->mpCommand = ace->mpName; bc->mCommandId = ace->mId; bc->mAccel = accel; mBoundCommands.push_back(bc.release()); RefreshBoundList(); } } } return true; } else if (id == IDC_REMOVE) { int selIdx = mListViewBoundCommands.GetSelectedIndex(); if ((unsigned)selIdx < mBoundCommands.size()) { BoundCommand *bc = mBoundCommands[selIdx]; mBoundCommands.erase(mBoundCommands.begin() + selIdx); bc->Release(); RefreshBoundList(); } return true; } else if (id == IDC_RESET) { if (IDOK == MessageBox(mhdlg, "Really reset?", g_szWarning, MB_OKCANCEL | MB_ICONEXCLAMATION)) LoadTable(mBoundCommandsDefault); return true; } return false; }
void mainLoader(int argc, char* argv[], ServiceManager* services) { //dispatcher thread g_game.setGameState(GAME_STATE_STARTUP); srand((unsigned int)OTSYS_TIME()); #ifdef _WIN32 SetConsoleTitle(STATUS_SERVER_NAME); #endif std::cout << STATUS_SERVER_NAME << " - Version " << STATUS_SERVER_VERSION << std::endl; std::cout << "Compilied on " << __DATE__ << ' ' << __TIME__ << " for arch "; #if defined(__amd64__) || defined(_M_X64) std::cout << "x64" << std::endl; #elif defined(__i386__) || defined(_M_IX86) || defined(_X86_) std::cout << "x86" << std::endl; #elif defined(__arm__) std::cout << "ARM" << std::endl; #elif defined(__mips__) std::cout << "MIPS" << std::endl; #else std::cout << "unk" << std::endl; #endif std::cout << std::endl; std::cout << "A server developed by " << STATUS_SERVER_DEVELOPERS << std::endl; std::cout << "Visit our forum for updates, support, and resources: http://otland.net/." << std::endl; std::cout << std::endl; // read global config std::cout << ">> Loading config" << std::endl; if (!g_config.load()) { startupErrorMessage("Unable to load config.lua!"); return; } #ifdef _WIN32 std::string defaultPriority = asLowerCaseString(g_config.getString(ConfigManager::DEFAULT_PRIORITY)); if (defaultPriority == "realtime") { SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); } else if (defaultPriority == "high") { SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); } else if (defaultPriority == "higher") { SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); } std::ostringstream mutexName; mutexName << "forgottenserver_" << g_config.getNumber(ConfigManager::LOGIN_PORT); CreateMutex(nullptr, FALSE, mutexName.str().c_str()); if (GetLastError() == ERROR_ALREADY_EXISTS) { startupErrorMessage("Another instance of The Forgotten Server is already running with the same login port, please shut it down first or change ports for this one."); return; } #endif //set RSA key const char* p("14299623962416399520070177382898895550795403345466153217470516082934737582776038882967213386204600674145392845853859217990626450972452084065728686565928113"); const char* q("7630979195970404721891201847792002125535401292779123937207447574596692788513647179235335529307251350570728407373705564708871762033017096809910315212884101"); g_RSA.setKey(p, q); std::cout << ">> Establishing database connection..." << std::flush; Database* db = Database::getInstance(); if (!db->connect()) { startupErrorMessage("Failed to connect to database."); return; } std::cout << " MySQL " << Database::getClientVersion() << std::endl; // run database manager std::cout << ">> Running database manager" << std::endl; if (!DatabaseManager::isDatabaseSetup()) { startupErrorMessage("The database you have specified in config.lua is empty, please import the schema.sql to your database."); return; } DatabaseManager::updateDatabase(); DatabaseManager::checkEncryption(); if (g_config.getBoolean(ConfigManager::OPTIMIZE_DATABASE) && !DatabaseManager::optimizeTables()) { std::cout << "> No tables were optimized." << std::endl; } //load vocations std::cout << ">> Loading vocations" << std::endl; if (!g_vocations.loadFromXml()) { startupErrorMessage("Unable to load vocations!"); return; } //load commands std::cout << ">> Loading commands" << std::endl; if (!g_commands.loadFromXml()) { startupErrorMessage("Unable to load commands!"); return; } // load item data std::cout << ">> Loading items" << std::endl; if (Item::items.loadFromOtb("data/items/items.otb")) { startupErrorMessage("Unable to load items (OTB)!"); return; } if (!Item::items.loadFromXml()) { startupErrorMessage("Unable to load items (XML)!"); return; } std::cout << ">> Loading script systems" << std::endl; if (!ScriptingManager::getInstance()->loadScriptSystems()) { startupErrorMessage("Failed to load script systems"); return; } std::cout << ">> Loading monsters" << std::endl; if (!g_monsters.loadFromXml()) { startupErrorMessage("Unable to load monsters!"); return; } std::cout << ">> Loading outfits" << std::endl; Outfits* outfits = Outfits::getInstance(); if (!outfits->loadFromXml()) { startupErrorMessage("Unable to load outfits!"); return; } g_adminConfig = new AdminProtocolConfig(); std::cout << ">> Loading admin protocol config" << std::endl; if (!g_adminConfig->loadXMLConfig()) { startupErrorMessage("Unable to load admin protocol config!"); return; } std::cout << ">> Loading experience stages" << std::endl; if (!g_game.loadExperienceStages()) { startupErrorMessage("Unable to load experience stages!"); return; } std::string passwordType = asLowerCaseString(g_config.getString(ConfigManager::PASSWORDTYPE)); if (passwordType == "sha1") { g_config.setNumber(ConfigManager::PASSWORD_TYPE, PASSWORD_TYPE_SHA1); std::cout << ">> Using SHA1 passwords" << std::endl; } else { g_config.setNumber(ConfigManager::PASSWORD_TYPE, PASSWORD_TYPE_PLAIN); std::cout << ">> Using plaintext passwords" << std::endl; } std::cout << ">> Checking world type... " << std::flush; std::string worldType = asLowerCaseString(g_config.getString(ConfigManager::WORLD_TYPE)); if (worldType == "pvp") { g_game.setWorldType(WORLD_TYPE_PVP); } else if (worldType == "no-pvp") { g_game.setWorldType(WORLD_TYPE_NO_PVP); } else if (worldType == "pvp-enforced") { g_game.setWorldType(WORLD_TYPE_PVP_ENFORCED); } else { std::cout << std::endl; std::ostringstream ss; ss << "> ERROR: Unknown world type: " << g_config.getString(ConfigManager::WORLD_TYPE) << ", valid world types are: pvp, no-pvp and pvp-enforced."; startupErrorMessage(ss.str()); return; } std::cout << asUpperCaseString(worldType) << std::endl; std::cout << ">> Loading map" << std::endl; if (!g_game.loadMainMap(g_config.getString(ConfigManager::MAP_NAME))) { startupErrorMessage("Failed to load map"); return; } std::cout << ">> Initializing gamestate" << std::endl; g_game.setGameState(GAME_STATE_INIT); // Tibia protocols services->add<ProtocolGame>(g_config.getNumber(ConfigManager::GAME_PORT)); services->add<ProtocolLogin>(g_config.getNumber(ConfigManager::LOGIN_PORT)); // OT protocols services->add<ProtocolAdmin>(g_config.getNumber(ConfigManager::ADMIN_PORT)); services->add<ProtocolStatus>(g_config.getNumber(ConfigManager::STATUS_PORT)); // Legacy protocols services->add<ProtocolOldLogin>(g_config.getNumber(ConfigManager::LOGIN_PORT)); services->add<ProtocolOldGame>(g_config.getNumber(ConfigManager::LOGIN_PORT)); int32_t autoSaveEachMinutes = g_config.getNumber(ConfigManager::AUTO_SAVE_EACH_MINUTES); if (autoSaveEachMinutes > 0) { g_scheduler->addEvent(createSchedulerTask(autoSaveEachMinutes * 1000 * 60, std::bind(&Game::autoSave, &g_game))); } if (g_config.getBoolean(ConfigManager::SERVERSAVE_ENABLED)) { int32_t serverSaveHour = g_config.getNumber(ConfigManager::SERVERSAVE_H); if (serverSaveHour >= 0 && serverSaveHour <= 24) { time_t timeNow = time(nullptr); tm* timeinfo = localtime(&timeNow); if (serverSaveHour == 0) { serverSaveHour = 23; } else { serverSaveHour--; } timeinfo->tm_hour = serverSaveHour; timeinfo->tm_min = 55; timeinfo->tm_sec = 0; double difference = difftime(mktime(timeinfo), timeNow); if (difference < 0) { difference += 86400; } g_scheduler->addEvent(createSchedulerTask(difference * 1000, std::bind(&Game::prepareServerSave, &g_game))); } } Houses::getInstance().payHouses(); IOLoginData::updateHouseOwners(); g_game.checkExpiredMarketOffers(); IOMarket::getInstance()->updateStatistics(); std::cout << ">> Loaded all modules, server starting up..." << std::endl; #if !defined(WIN32) && !defined(__ROOT_PERMISSION__) if (getuid() == 0 || geteuid() == 0) { std::cout << "> WARNING: " << STATUS_SERVER_NAME << " has been executed as root user, it is recommended to execute is as a normal user." << std::endl; } #endif g_game.start(services); g_game.setGameState(GAME_STATE_NORMAL); g_loaderSignal.notify_all(); }