Пример #1
0
//function which updates the playerlist.
void World::updatePlayerList() {
    using namespace Database;
    std::cout<<"Updateplayerlist start"<<std::endl;

    PConnection connection = ConnectionManager::getInstance().getConnection();

    try {
        connection->beginTransaction();

        DeleteQuery delQuery(connection);
        delQuery.setServerTable("onlineplayer");
        delQuery.execute();

        if (!Players.empty()) {
            InsertQuery insQuery(connection);
            insQuery.setServerTable("onlineplayer");
            const InsertQuery::columnIndex column = insQuery.addColumn("on_playerid");

            PLAYERVECTOR::iterator plIterator;

            for (plIterator = Players.begin(); plIterator != Players.end(); ++plIterator) {
                insQuery.addValue<TYPE_OF_CHARACTER_ID>(column, (*plIterator)->id);
            }

            insQuery.execute();
        }

        connection->commitTransaction();
    } catch (std::exception &e) {
        std::cerr<<"caught exception during online player save: "<<e.what()<<std::endl;
        connection->rollbackTransaction();
    }

    std::cout<<"updateplayerlist end"<<std::endl;
}
Пример #2
0
//function which updates the playerlist.
void World::updatePlayerList() {
    using namespace Database;

    PConnection connection = ConnectionManager::getInstance().getConnection();

    try {
        connection->beginTransaction();

        DeleteQuery delQuery(connection);
        delQuery.setServerTable("onlineplayer");
        delQuery.execute();

        if (!Players.empty()) {
            InsertQuery insQuery(connection);
            insQuery.setServerTable("onlineplayer");
            const InsertQuery::columnIndex column = insQuery.addColumn("on_playerid");

            Players.for_each([&](Player *player) {
                insQuery.addValue<TYPE_OF_CHARACTER_ID>(column, player->getId());
            });

            insQuery.execute();
        }

        connection->commitTransaction();
    } catch (std::exception &e) {
        Logger::error(LogFacility::World) << "Exception during saving online player list: " << e.what() << Log::end;
        connection->rollbackTransaction();
    }
}
Пример #3
0
bool LongTimeEffect::save(uint32_t playerid, int32_t currentTime) {
    using namespace Database;
    PConnection connection = ConnectionManager::getInstance().getConnection();

    try {
        connection->beginTransaction();

        {
            InsertQuery insQuery(connection);
            insQuery.setServerTable("playerlteffects");
            const InsertQuery::columnIndex userColumn = insQuery.addColumn("plte_playerid");
            const InsertQuery::columnIndex effectColumn = insQuery.addColumn("plte_effectid");
            const InsertQuery::columnIndex nextCalledColumn = insQuery.addColumn("plte_nextcalled");
            const InsertQuery::columnIndex numberCalledColumn = insQuery.addColumn("plte_numbercalled");
            insQuery.addValue(userColumn, playerid);
            insQuery.addValue(effectColumn, effectId);
            insQuery.addValue(nextCalledColumn, executionTime - currentTime);
            insQuery.addValue(numberCalledColumn, numberOfCalls);
            insQuery.execute();
        }

        {
            InsertQuery insQuery(connection);
            insQuery.setServerTable("playerlteffectvalues");
            const InsertQuery::columnIndex userColumn = insQuery.addColumn("pev_playerid");
            const InsertQuery::columnIndex effectColumn = insQuery.addColumn("pev_effectid");
            const InsertQuery::columnIndex nameColumn = insQuery.addColumn("pev_name");
            const InsertQuery::columnIndex valueColumn = insQuery.addColumn("pev_value");

            for (const auto &value : values) {
                insQuery.addValue(nameColumn, value.first);
                insQuery.addValue(valueColumn, value.second);
                insQuery.addValue(userColumn, playerid);
                insQuery.addValue(effectColumn, effectId);
            }

            insQuery.execute();
        }

        connection->commitTransaction();
        return true;
    } catch (std::exception &e) {
        Logger::error(LogFacility::Other) << "Exception while saving long time effects: " << e.what() << Log::end;
        connection->rollbackTransaction();
        return false;
    }

    return true;
}