void ScheduledScriptsTable::reload() {
#ifdef DataConnect_DEBUG
    std::cout << "ScheduledScriptsTable: reload" << std::endl;
#endif

    try {
        Database::SelectQuery query;
        query.addColumn("scheduledscripts", "sc_scriptname");
        query.addColumn("scheduledscripts", "sc_mincycletime");
        query.addColumn("scheduledscripts", "sc_maxcycletime");
        query.addColumn("scheduledscripts", "sc_functionname");
        query.addServerTable("scheduledscripts");

        Database::Result results = query.execute();

        if (!results.empty()) {
            clearOldTable();
            ScriptData tmpRecord;

            for (Database::ResultConstIterator itr = results.begin();
                 itr != results.end(); ++itr) {
                tmpRecord.minCycleTime = (uint32_t)((*itr)["sc_mincycletime"].as<uint32_t>());
                tmpRecord.maxCycleTime = (uint32_t)((*itr)["sc_maxcycletime"].as<uint32_t>());
                tmpRecord.nextCycleTime = 0;

                if (!((*itr)["sc_scriptname"].is_null()) && !((*itr)["sc_functionname"].is_null())) {
                    tmpRecord.functionName = ((*itr)["sc_functionname"].as<std::string>());
                    tmpRecord.scriptName = ((*itr)["sc_scriptname"].as<std::string>());

                    try {
                        boost::shared_ptr<LuaScheduledScript> tmpScript(new LuaScheduledScript(tmpRecord.scriptName));
                        tmpRecord.scriptptr = tmpScript;
                        addData(tmpRecord);
                    } catch (ScriptException &e) {
                        Logger::writeError("scripts", "Error while loading scheduled script: " + tmpRecord.scriptName + ":\n" + e.what() + "\n");
                    }
                }
            }
        }

        m_dataOk = true;
    } catch (std::exception &e) {
        std::cerr << "exception: " << e.what() << std::endl;
        m_dataOk = false;
    }
}
Пример #2
0
// Itemdefinitionen laden
void loadData() {
    bool ok = true;

    Skills = new SkillTable();

    if (!Skills->dataOK()) {
        ok = false;
    }

    Quests = new QuestTable();

    if (!Quests->isDataOK()) {
        ok = false;
    }

    scriptVariables = new ScriptVariablesTable();

    if (!scriptVariables->isDataOk()) {
        ok = false;
    }

    RaceSizes = new RaceSizeTable();

    if (!RaceSizes->isDataOk()) {
        ok = false;
    }

    NaturalArmors = new NaturalArmorTable();

    if (!NaturalArmors->isDataOk()) {
        ok = false;
    }

    MonsterAttacks = new MonsterAttackTable();

    if (!MonsterAttacks->isDataOk()) {
        ok = false;
    }

    CommonItems = new CommonObjectTable();

    if (!CommonItems->dataOK()) {
        ok = false;
    }

    ItemNames = new NamesObjectTable();

    if (!ItemNames->dataOK()) {
        ok = false;
    }

    WeaponItems = new WeaponObjectTable();

    if (!WeaponItems->dataOK()) {
        ok = false;
    }

    ArmorItems = new ArmorObjectTable();

    if (!ArmorItems->dataOK()) {
        ok = false;
    }

    ContainerItems = new ContainerObjectTable();

    if (!ContainerItems->dataOK()) {
        ok = false;
    }

    TilesModItems = new TilesModificatorTable();

    if (!TilesModItems->dataOK()) {
        ok = false;
    }

    Tiles = new TilesTable();

    if (!Tiles->dataOK()) {
        ok = false;
    }

    Spells = new SpellTable();

    if (!Spells->isDataOK()) {
        ok = false;
    }

    ScheduledScripts = new ScheduledScriptsTable();
    scheduledScripts = ScheduledScripts;

    if (!ScheduledScripts->dataOK()) {
        ok = false;
    }

    Triggers = new TriggerTable();

    if (!Triggers->isDataOK()) {
        ok = false;
    }

    MonsterDescriptions = new MonsterTable();

    if (!MonsterDescriptions->dataOK()) {
        ok=false;
    }

    LongTimeEffects = new LongTimeEffectTable();

    if (!LongTimeEffects->dataOK()) {
        ok = false;
    }

    erasedcontainers = new std::vector<int>;

    contpos= new std::vector<position>;

    try {
        boost::shared_ptr<LuaWeaponScript> tmpScript(new LuaWeaponScript("server.standardfighting"));
        standardFightingScript = tmpScript;
    } catch (ScriptException &e) {
        Logger::writeError("scripts", "Error while loading script: server.standardfighting:\n" + std::string(e.what()) + "\n");
    }

    try {
        boost::shared_ptr<LuaLookAtPlayerScript>tmpScript(new LuaLookAtPlayerScript("server.playerlookat"));
        lookAtPlayerScript = tmpScript;
    } catch (ScriptException &e) {
        Logger::writeError("scripts", "Error while loading script: server.playerlookat:\n" + std::string(e.what()) + "\n");
    }

    try {
        boost::shared_ptr<LuaLookAtItemScript>tmpScript(new LuaLookAtItemScript("server.itemlookat"));
        lookAtItemScript = tmpScript;
    } catch (ScriptException &e) {
        Logger::writeError("scripts", "Error while loading script: server.itemlookat:\n" + std::string(e.what()) + "\n");
    }

    try {
        boost::shared_ptr<LuaPlayerDeathScript>tmpScript(new LuaPlayerDeathScript("server.playerdeath"));
        playerDeathScript = tmpScript;
    } catch (ScriptException &e) {
        Logger::writeError("scripts", "Error while loading script: server.playerdeath:\n" + std::string(e.what()) + "\n");
    }

    try {
        boost::shared_ptr<LuaDepotScript>tmpScript(new LuaDepotScript("server.depot"));
        depotScript = tmpScript;
    } catch (ScriptException &e) {
        Logger::writeError("scripts", "Error while loading script: server.depot:\n" + std::string(e.what()) + "\n");
    }

    try {
        boost::shared_ptr<LuaLoginScript>tmpScript(new LuaLoginScript("server.login"));
        loginScript = tmpScript;
    } catch (ScriptException &e) {
        Logger::writeError("scripts", "Error while loading script: server.login:\n" + std::string(e.what()) + "\n");
    }

    try {
        boost::shared_ptr<LuaLogoutScript>tmpScript(new LuaLogoutScript("server.logout"));
        logoutScript = tmpScript;
    } catch (ScriptException &e) {
        Logger::writeError("scripts", "Error while loading script: server.logout:\n" + std::string(e.what()) + "\n");
    }

    try {
        boost::shared_ptr<LuaLearnScript>tmpScript(new LuaLearnScript("server.learn"));
        learnScript = tmpScript;
    } catch (ScriptException &e) {
        Logger::writeError("scripts", "Error while loading script: server.learn:\n" + std::string(e.what()) + "\n");
    }


    if (!ok) {
        std::cerr << "could not load tables from database!" << std::endl;
    }
}
Пример #3
0
void WeaponObjectTable::reload() {
#ifdef DataConnect_DEBUG
    std::cout << "WeaponObjectTable: reload" << std::endl;
#endif

    try {
        Database::SelectQuery query;
        query.addColumn("weapon", "wp_itemid");
        query.addColumn("weapon", "wp_attack");
        query.addColumn("weapon", "wp_defence");
        query.addColumn("weapon", "wp_accuracy");
        query.addColumn("weapon", "wp_range");
        query.addColumn("weapon", "wp_weapontype");
        query.addColumn("weapon", "wp_ammunitiontype");
        query.addColumn("weapon", "wp_actionpoints");
        query.addColumn("weapon", "wp_magicdisturbance");
        query.addColumn("weapon", "wp_poison");
        query.addColumn("weapon", "wp_fightingscript");
        query.addServerTable("weapon");

        Database::Result results = query.execute();

        if (!results.empty()) {
            clearOldTable();
            WeaponStruct temprecord;
            std::string scriptname;
            TYPE_OF_ITEM_ID weaponId;

            for (Database::ResultConstIterator itr = results.begin();
                 itr != results.end(); ++itr) {
                weaponId = (*itr)["wp_itemid"].as<TYPE_OF_ITEM_ID>();
                temprecord.Attack = (TYPE_OF_ATTACK)((*itr)["wp_attack"].as<uint16_t>());
                temprecord.Defence = (TYPE_OF_DEFENCE)((*itr)["wp_defence"].as<uint16_t>());
                temprecord.Accuracy = (TYPE_OF_ACCURACY)((*itr)["wp_accuracy"].as<uint16_t>());
                temprecord.Range = (TYPE_OF_RANGE)((*itr)["wp_range"].as<uint16_t>());
                temprecord.WeaponType = (TYPE_OF_WEAPONTYPE)((*itr)["wp_weapontype"].as<uint16_t>());
                temprecord.AmmunitionType = (TYPE_OF_AMMUNITIONTYPE)((*itr)["wp_ammunitiontype"].as<uint16_t>());
                temprecord.ActionPoints = (TYPE_OF_ACTIONPOINTS)((*itr)["wp_actionpoints"].as<uint16_t>());
                temprecord.MagicDisturbance = (TYPE_OF_MAGICDISTURBANCE)((*itr)["wp_magicdisturbance"].as<uint16_t>());
                temprecord.PoisonStrength = (TYPE_OF_POISONSTRENGTH)((*itr)["wp_poison"].as<uint16_t>());

                if (!(*itr)["wp_fightingscript"].is_null()) {
                    scriptname = (*itr)["wp_fightingscript"].as<std::string>();

                    if (!scriptname.empty()) {
                        try {
                            boost::shared_ptr<LuaWeaponScript> tmpScript(new LuaWeaponScript(scriptname));
                            temprecord.script = tmpScript;
                        } catch (ScriptException &e) {
                            Logger::writeError("scripts", "Error while loading weapon script: " + scriptname + ":\n" + e.what() + "\n");
                        }
                    }
                }

                m_table[weaponId] = temprecord;
            }

            m_dataOK = true;
        } else {
            m_dataOK = false;
        }


#ifdef DataConnect_DEBUG
        std::cout << "loaded " << rows << " rows into WeaponObjectTable" << std::endl;
#endif

    } catch (...) {
        m_dataOK = false;
    }

}
Пример #4
0
//! Die Hauptfunktion zum Testen //
int main(int argc, char *argv[]) {

    int res;
    rlimit rlp;
    res = getrlimit(RLIMIT_CORE, &rlp);
    std::cout<<"max core size: "<<rlp.rlim_cur<<std::endl;
    std::cout<<"current core size: "<<rlp.rlim_max<<std::endl;
    rlp.rlim_cur = 20000;
    res = getrlimit(RLIMIT_CORE, &rlp);

    if (res < 0) {
        std::cout<<"err: "<<errno<<std::endl;
        perror("setrlimit: RLIMIT_CORE");
        exit(-2);
    }

    importmaps = false;
    //di::postgres::enable_trace_query = true;
    // get more info for unspecified exceptions
    std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
    // save starting time
    time_t starttime;
    time(&starttime);

    std::stringstream ss;
    ss << starttime;
    configOptions["starttime"] = ss.str();
    //Initialize Logging Options
    InitLogOptions();

    Logger::writeMessage("basic", "\nStarte Illarion !");

    // initialize randomizer
    initRandom();

    // initialize signalhandlers
    if (! init_sighandlers()) {
        return 1;
    }

    // deactivate savethread
    // unsigned long int thisonlinetime = 0;

    checkArguments(argc, argv);


    // set up logfiles etc. and check if everything works
    if (! setup_files()) {
        return 1;
    }

    Logger::writeMessage("basic", "main: server requires clientversion: " + configOptions["clientversion"], false);
    Logger::writeMessage("basic", "main: listen port: " + configOptions["port"], false);
    Logger::writeMessage("basic", "main: data directory: " + configOptions["datadir"], false);

    // initialise DB Manager
    Database::ConnectionManager::Login login;
    Database::ConnectionManager::Server server;
    login.database = configOptions["postgres_db"];
    login.user = configOptions["postgres_user"];
    login.password = configOptions["postgres_pwd"];
    server.host = configOptions["postgres_host"];
    server.port = configOptions["postgres_port"];
    Database::ConnectionManager::getInstance().setupManager(login, server);
    Database::SchemaHelper::setSchemata(configOptions["postgres_schema_server"],
                                        configOptions["postgres_schema_account"]);

    //Welt anlegen
    World *world = World::create(configOptions["datadir"] , starttime);

    //Laden der Daten fr die Welt (Items, Scripte, Tabellen etc.)
    loadData();

    if (!importmaps) {
        world->Load("Illarion");
    } else {
        configOptions["disable_login"] = "******";
        world->load_from_editor(configOptions["datadir"] + std::string("map/import/oberwelt_0"));
    }

    std::cout<<"Creation the PlayerManager"<<std::endl;
    PlayerManager::get()->activate();
    std::cout<<"PlayerManager activated"<<std::endl;
    PlayerManager::TPLAYERVECTOR &newplayers = PlayerManager::get()->getLogInPlayers();
    timespec stime;
    stime.tv_sec = 0;
    stime.tv_nsec = 25000000;    //25ms
    //NPC's erschaffen
    world->initNPC();

    //run both reload scripts to initialize semi-dynamic data
    try {
        boost::shared_ptr<LuaReloadScript> tmpScript(new LuaReloadScript("server.reload_defs"));

        if (!tmpScript->onReload()) {
            std::cerr << "server.reload_defs.onReload returned false" << std::endl;
        }
    } catch (ScriptException &e) {
        std::cerr << "reload_defs: " << e.what() << std::endl;
    }

    try {
        boost::shared_ptr<LuaReloadScript> tmpScript(new LuaReloadScript("server.reload_tables"));

        if (!tmpScript->onReload()) {
            std::cerr << "server.reload_tables.onReload returned false" << std::endl;
        };
    } catch (ScriptException &e) {
        std::cerr << "reload_tables: " << e.what() << std::endl;
    }

    Logger::writeMessage("basic","Scheduler wird Initialisiert \n",false);
    //Scheduler Initialisieren
    world->initScheduler();

    int new_players_processed;

    running = true;
    // die OnlinePlayer-Liste aktualisieren (-> auf 0)
    world->saveAllPlayerNamesToFile(configOptions["datadir"] + std::string(ONLINEPLFILE));

    while (running) {
        // Ausgaben auf std::cout in die Datei schreiben
        std::cout.flush();
        // make sure we don't block the server with processing new players...
        new_players_processed = 0;

        // process new players from connection thread
        while (!newplayers.empty() && new_players_processed < MAXPLAYERSPROCESSED) {

            new_players_processed++;
            Player *newPlayer = newplayers.non_block_pop_front();

            if (newPlayer) {
                login_save(newPlayer);

                if (newPlayer->isMonitoringClient()) {
                    world->monitoringClientList->clientConnect(newPlayer);
                } else {
                    try {
                        std::cout<<"login sucessully from: "<<newPlayer->name<<" "<<newPlayer->id<<std::endl;
                        world->Players.push_back(newPlayer);
                        newPlayer->login();

                        try {
                            std::cout<<"calling onlogin"<<std::endl;
                            loginScript->onLogin(newPlayer);
                        } catch (ScriptException &e) {
                            std::cerr<<"Login Script: Failed to load scripts/login.lua !"<<std::endl;
                        }

                        world->updatePlayerList();
                    } catch (Player::LogoutException &e) {
                        std::cout<<"got logout Exception during login!"<<std::endl;
                        boost::shared_ptr<BasicServerCommand> cmd(new LogOutTC(e.getReason()));
                        newPlayer->Connection->shutdownSend(cmd);
                        //newPlayer->Connection->closeConnection();
                        PlayerManager::get()->getLogOutPlayers().non_block_push_back(newPlayer);
                    }
                }
            } else {
                std::cout<<"try to get new player but was NULL!"<<std::endl;
            }

        } // get new players

        // Eingaben der Player abarbeiten und die Karte altern
        world->turntheworld();
        nanosleep(&stime, NULL);
    }


    Logger::writeMessage("basic","Beende Illarion!");

    std::cout<<"Server Shutdown:"<<std::endl;

    scriptVariables->save();
    std::cout<<"Scriptvariables saved!"<<std::endl;
    world->forceLogoutOfAllPlayers();

    //saving all players which where forced logged out.
    PlayerManager::get()->saveAll();

    world->takeMonsterAndNPCFromMap();


    Logger::writeMessage("basic","Statistik aktualisieren");
    Logger::writeMessage("basic","OnlinePlayer-Liste aktualisieren (-> auf 0)");
    world->saveAllPlayerNamesToFile(configOptions["datadir"] + std::string(ONLINEPLFILE));
    Logger::writeMessage("basic","Karten speichern");
    world->Save("Illarion");
    Logger::writeMessage("basic","InitialConnection beenden");
    Logger::writeMessage("basic", "Die in loadItems(..) angelegten Tabellen loeschen");
    delete CommonItems;
    CommonItems = NULL;
    delete ItemNames;
    ItemNames = NULL;
    delete WeaponItems;
    WeaponItems = NULL;
    delete ArmorItems;
    ArmorItems = NULL;
    delete ContainerItems;
    ContainerItems = NULL;
    delete TilesModItems;
    TilesModItems = NULL;
    delete Tiles;
    Tiles = NULL;
    delete world;
    world = NULL;

    reset_sighandlers();

    time(&starttime);
    Logger::writeMessage("basic","main: Ende ");

    return EXIT_SUCCESS;
}
Пример #5
0
	void XML::getOpArgs(const node_ptr script, block_ptr curBlock) {
		std::vector<std::string> args;
		std::vector<block_ptr> blockArgs;
		std::string opStr;
		int i(0);
		
		node_ptr tmpScript(script);
		
		if (std::strcmp(tmpScript->name(), "block") == 0 ||
			std::strcmp(tmpScript->name(), "list") == 0) {
			if (tmpScript->first_attribute("s")) {
				curBlock->setOpcode(tmpScript->first_attribute("s")->value());
			} else if (tmpScript->first_attribute("var")) {
				curBlock->setOpcode("readVariable");
				opStr = tmpScript->first_attribute("var")->value();
			} else if (tmpScript->first_attribute("point")) {
				curBlock->setOpcode("readPoint");
				opStr = tmpScript->first_attribute("point")->value();
			} else if (tmpScript->first_attribute("schedule")) {
				curBlock->setOpcode("reportGetSched");
				opStr = tmpScript->first_attribute("schedule")->value();
			}
			
			if (!opStr.empty()) {
				args.push_back(opStr);
			}
			
			const node_ptr first(tmpScript->first_node(), null_deleter());
			for (node_ptr child(first);
				 child;
				 child.reset(child->next_sibling(), null_deleter())) {
				if (std::strcmp(child->name(), "block") == 0 ||
					std::strcmp(child->name(), "script") == 0 ||
					std::strcmp(child->name(), "list") == 0) {
					block_ptr b(new blocks::Block);
					getOpArgs(child, b);
					if (b->opcode() == "nested") {
						curBlock->addNestedStart(b->nestedBlocks()[0]);
					} else if (b->opcode().empty()) {
						blockArgs = b->blockArgs();
					} else {
						opStr = "block:" + std::to_string(i++);
						blockArgs.push_back(b);
					}
				} else if (std::strcmp(child->name(), "l") == 0) {
					if (child->first_node() != 0) {
						opStr = child->value();
					} else {
						opStr = child->first_node("option")->value();
					}
				}
				
				if (!opStr.empty()) {
					args.push_back(opStr);
				}
			}
		} else if (std::strcmp(tmpScript->name(), "script") == 0) {
			curBlock->setOpcode("nested");
			node_ptr child(tmpScript->first_node(), null_deleter());
			curBlock->addNestedStart(getChildren(child, true));
		}
		
		if (args.size() > 0) curBlock->setArgs(args);
		if (blockArgs.size() > 0) curBlock->setBlockArgs(blockArgs);
	}