<commit_before>/*
 * Illarionserver - server for the game Illarion
 * Copyright 2011 Illarion e.V.
 *
 * This file is part of Illarionserver.
 *
 * Illarionserver  is  free  software:  you can redistribute it and/or modify it
 * under the terms of the  GNU Affero General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * Illarionserver is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY;  without  even  the  implied  warranty  of  MERCHANTABILITY  or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along with
 * Illarionserver. If not, see <http://www.gnu.org/licenses/>.
 */

#include "World.hpp"

#include "Config.hpp"
#include "Logger.hpp"
#include "LongTimeAction.hpp"
#include "Monster.hpp"
#include "NPC.hpp"
#include "Player.hpp"
#include "PlayerManager.hpp"
#include "Random.hpp"
#include "TableStructs.hpp"
#include "WaypointList.hpp"
#include "data/Data.hpp"
#include "data/MonsterTable.hpp"
#include "data/NPCTable.hpp"
#include "data/ScheduledScriptsTable.hpp"
#include "data/SkillTable.hpp"
#include "data/TilesTable.hpp"
#include "data/WeaponObjectTable.hpp"
#include "db/Result.hpp"
#include "db/SelectQuery.hpp"
#include "netinterface/BasicCommand.hpp"
#include "netinterface/NetInterface.hpp"
#include "netinterface/protocol/ServerCommands.hpp"
#include "script/LuaNPCScript.hpp"
#include "script/server.hpp"
#include "tuningConstants.hpp"

#include <algorithm>
#include <cmath>
#include <iterator>
#include <memory>
#include <regex>

extern ScheduledScriptsTable *scheduledScripts;
extern MonsterTable *monsterDescriptions;

World *World::_self;

auto World::create() -> World * {
    if ((_self) == nullptr) {
        _self = new World();
        // init spawnlocations...
        _self->initRespawns();
        // initialise list of GM Commands
        _self->InitGMCommands();
        // initialise list of Player Commands
        _self->InitPlayerCommands();
        _self->monitoringClientList = std::make_unique<MonitoringClients>();
    }

    return _self;
}

auto World::get() -> World * {
    if ((_self) == nullptr) {
        throw std::runtime_error("world was not created");
    }

    return _self;
}

World::World() {
    lastTurnIGDay = getTime("day");

    startTime = std::chrono::steady_clock::now();

    scriptDir = Config::instance().datadir() + std::string(SCRIPTSDIR);
}

void World::turntheworld() {
    auto now = std::chrono::steady_clock::now();
    using std::chrono::duration_cast;
    using std::chrono::milliseconds;
    auto elapsed = duration_cast<milliseconds>(now - startTime).count();

    ap = static_cast<int>(elapsed / MIN_AP_UPDATE - usedAP);

    if (ap > 0) {
        usedAP += ap;

        checkPlayers();
        checkMonsters();
        checkNPC();
    }
}

void World::checkPlayers() {
    time_t now = 0;
    time(&now);
    bool savedOnePlayer = false;

    std::vector<Player *> lostPlayers;

    Players.for_each([now, &savedOnePlayer, &lostPlayers, this](Player *playerPointer) {
        Player &player = *playerPointer;<commit_msg>Disable player auto save until moved to another thread<commit_after>/*
 * Illarionserver - server for the game Illarion
 * Copyright 2011 Illarion e.V.
 *
 * This file is part of Illarionserver.
 *
 * Illarionserver  is  free  software:  you can redistribute it and/or modify it
 * under the terms of the  GNU Affero General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * Illarionserver is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY;  without  even  the  implied  warranty  of  MERCHANTABILITY  or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along with
 * Illarionserver. If not, see <http://www.gnu.org/licenses/>.
 */

#include "World.hpp"

#include "Config.hpp"
#include "Logger.hpp"
#include "LongTimeAction.hpp"
#include "Monster.hpp"
#include "NPC.hpp"
#include "Player.hpp"
#include "PlayerManager.hpp"
#include "Random.hpp"
#include "TableStructs.hpp"
#include "WaypointList.hpp"
#include "data/Data.hpp"
#include "data/MonsterTable.hpp"
#include "data/NPCTable.hpp"
#include "data/ScheduledScriptsTable.hpp"
#include "data/SkillTable.hpp"
#include "data/TilesTable.hpp"
#include "data/WeaponObjectTable.hpp"
#include "db/Result.hpp"
#include "db/SelectQuery.hpp"
#include "netinterface/BasicCommand.hpp"
#include "netinterface/NetInterface.hpp"
#include "netinterface/protocol/ServerCommands.hpp"
#include "script/LuaNPCScript.hpp"
#include "script/server.hpp"
#include "tuningConstants.hpp"

#include <algorithm>
#include <cmath>
#include <iterator>
#include <memory>
#include <regex>

extern ScheduledScriptsTable *scheduledScripts;
extern MonsterTable *monsterDescriptions;

World *World::_self;

auto World::create() -> World * {
    if ((_self) == nullptr) {
        _self = new World();
        // init spawnlocations...
        _self->initRespawns();
        // initialise list of GM Commands
        _self->InitGMCommands();
        // initialise list of Player Commands
        _self->InitPlayerCommands();
        _self->monitoringClientList = std::make_unique<MonitoringClients>();
    }

    return _self;
}

auto World::get() -> World * {
    if ((_self) == nullptr) {
        throw std::runtime_error("world was not created");
    }

    return _self;
}

World::World() {
    lastTurnIGDay = getTime("day");

    startTime = std::chrono::steady_clock::now();

    scriptDir = Config::instance().datadir() + std::string(SCRIPTSDIR);
}

void World::turntheworld() {
    auto now = std::chrono::steady_clock::now();
    using std::chrono::duration_cast;
    using std::chrono::milliseconds;
    auto elapsed = duration_cast<milliseconds>(now - startTime).count();

    ap = static_cast<int>(elapsed / MIN_AP_UPDATE - usedAP);

    if (ap > 0) {
        usedAP += ap;

        checkPlayers();
        checkMonsters();
        checkNPC();
    }
}

void World::checkPlayers() {
    time_t now = 0;
    time(&now);
    bool savedOnePlayer = true; // disable auto save until it can be moved into player save thread

    std::vector<Player *> lostPlayers;

    Players.for_each([now, &savedOnePlayer, &lostPlayers, this](Player *playerPointer) {
        Player &player = *playerPointer;
{'fraction_non_alphanumeric': 0.12316981132075472, 'fraction_numerical': 0.0021132075471698114, 'mean_word_length': 3.8864306784660765, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2041266', 'n_tokens_mistral': 2084, 'n_tokens_neox': 2040, 'n_words': 577}