From ab6a677b7add31d644507c5fb97c618a25268103 Mon Sep 17 00:00:00 2001 From: ErikasKontenis Date: Sun, 2 May 2021 23:26:17 +0300 Subject: [PATCH] prepare fake players mechanism --- data/creaturescripts/scripts/login.lua | 115 +++++++++++++++++++++++++ data/globalevents/scripts/startup.lua | 2 +- src/iologindata.cpp | 5 +- src/luascript.cpp | 15 ++++ src/luascript.h | 1 + src/player.cpp | 2 +- src/player.h | 4 +- src/protocolgame.cpp | 21 ++++- src/protocolstatus.cpp | 22 +++-- 9 files changed, 170 insertions(+), 17 deletions(-) diff --git a/data/creaturescripts/scripts/login.lua b/data/creaturescripts/scripts/login.lua index 47a4334..129f18c 100644 --- a/data/creaturescripts/scripts/login.lua +++ b/data/creaturescripts/scripts/login.lua @@ -1,3 +1,108 @@ +local fakePlayers = { + {x = 32864, y = 31997, z = 7}, + {x = 32864, y = 31998, z = 7}, + {x = 32865, y = 31999, z = 7}, + {x = 32871, y = 31999, z = 7}, + {x = 32872, y = 32000, z = 7}, + {x = 32825, y = 32065, z = 7}, + {x = 32828, y = 32065, z = 7}, + {x = 32885, y = 32050, z = 7}, + {x = 32885, y = 32049, z = 7}, + {x = 32823, y = 31887, z = 7}, + {x = 32691, y = 31716, z = 7}, + {x = 32705, y = 31787, z = 7}, + {x = 32716, y = 31928, z = 7}, + {x = 32880, y = 31845, z = 7}, + {x = 32879, y = 31845, z = 7}, + {x = 32882, y = 31840, z = 7}, + {x = 32655, y = 32109, z = 8}, + {x = 32665, y = 32109, z = 8}, + {x = 32254, y = 32019, z = 7}, + {x = 32255, y = 32020, z = 7}, + {x = 32245, y = 32021, z = 7}, + {x = 32238, y = 32330, z = 7}, + {x = 32238, y = 32331, z = 7}, + {x = 32273, y = 32396, z = 7}, + {x = 32465, y = 32315, z = 7}, + {x = 32225, y = 31740, z = 7}, + {x = 32230, y = 31739, z = 7}, + {x = 32257, y = 31838, z = 7}, + {x = 32258, y = 31840, z = 7}, + {x = 32258, y = 31844, z = 7}, + {x = 32260, y = 31846, z = 7}, + {x = 32261, y = 31848, z = 7}, + {x = 32231, y = 31701, z = 7}, + {x = 32516, y = 31599, z = 7}, + {x = 32486, y = 31590, z = 7}, + {x = 32493, y = 31590, z = 7}, + {x = 32503, y = 31670, z = 7}, + {x = 32579, y = 31928, z = 0}, + {x = 32596, y = 31922, z = 0}, + {x = 32621, y = 31921, z = 1}, + {x = 32651, y = 31942, z = 7}, + {x = 32531, y = 32721, z = 7}, + {x = 32531, y = 32720, z = 7}, + {x = 32530, y = 32720, z = 7}, + {x = 32537, y = 32813, z = 7}, + {x = 32537, y = 32814, z = 7}, + {x = 32537, y = 32759, z = 7}, + {x = 32538, y = 32759, z = 7}, + {x = 33023, y = 32872, z = 7}, + {x = 33023, y = 32871, z = 7}, + {x = 33023, y = 32870, z = 7}, + {x = 33275, y = 32829, z = 7}, + {x = 33238, y = 32555, z = 7}, + {x = 33237, y = 32555, z = 7}, + {x = 33187, y = 32343, z = 7}, + {x = 33187, y = 32342, z = 7}, + {x = 33152, y = 32354, z = 7}, + {x = 33154, y = 32354, z = 7}, + {x = 33076, y = 32345, z = 7}, + {x = 32655, y = 31648, z = 10}, + {x = 32656, y = 31648, z = 10}, + {x = 32657, y = 31648, z = 10}, + {x = 33262, y = 31866, z = 7}, + {x = 33263, y = 31866, z = 7}, + {x = 33244, y = 31904, z = 7}, + {x = 33245, y = 31903, z = 7}, + {x = 33219, y = 31926, z = 7}, + {x = 33298, y = 31839, z = 7}, + {x = 33298, y = 31838, z = 7}, + {x = 33358, y = 31692, z = 9}, + {x = 33359, y = 31692, z = 9}, + {x = 33360, y = 31692, z = 9}, + {x = 33362, y = 31696, z = 9}, + {x = 33366, y = 31696, z = 9}, + {x = 33318, y = 31728, z = 7}, + {x = 33318, y = 31729, z = 7}, + {x = 33273, y = 31680, z = 7}, + {x = 33169, y = 31737, z = 7}, + {x = 33274, y = 31791, z = 6}, + {x = 33321, y = 32419, z = 7}, + {x = 33318, y = 32406, z = 7}, + {x = 32372, y = 32840, z = 7}, + {x = 32371, y = 32839, z = 7}, + {x = 32369, y = 32838, z = 7}, + {x = 32347, y = 32691, z = 7}, + {x = 32348, y = 32692, z = 7}, + {x = 32157, y = 32783, z = 7}, + {x = 32225, y = 32880, z = 7}, + {x = 32386, y = 32695, z = 7}, + {x = 32314, y = 32830, z = 8}, + {x = 32593, y = 31885, z = 12}, + {x = 32593, y = 31884, z = 12}, + {x = 32586, y = 31919, z = 10}, + {x = 32547, y = 31921, z = 10}, + {x = 32763, y = 31941, z = 7}, + {x = 32763, y = 31942, z = 7}, + {x = 32700, y = 31842, z = 7}, + {x = 32700, y = 31841, z = 7}, + {x = 32991, y = 32377, z = 7}, + {x = 32314, y = 32282, z = 7} +} + + + function onLogin(player) local loginStr = "Welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!" if player:getLastLoginSaved() <= 0 then @@ -40,6 +145,16 @@ function onLogin(player) player:setStorageValue(43434, 0) end + -- FakePlayer + if player:isFakePlayer() then + local inFightCondition = Condition(CONDITION_INFIGHT) + inFightCondition:setParameter(CONDITION_PARAM_TICKS, 2000 * 60 * 1000) + player:addCondition(inFightCondition) + player:teleportTo(fakePlayers[1]) + table.remove(fakePlayers, 1) + -- TODO give random bps, lvls, mls + end + -- Events player:registerEvent("PlayerDeath") player:registerEvent("kills") diff --git a/data/globalevents/scripts/startup.lua b/data/globalevents/scripts/startup.lua index 0d67f7e..4f9fc7d 100644 --- a/data/globalevents/scripts/startup.lua +++ b/data/globalevents/scripts/startup.lua @@ -196,7 +196,7 @@ function onStartup() end spawnRashid() - addEvent(function () Game.setGameState(GAME_STATE_CLOSED) end, 5000) + --addEvent(function () Game.setGameState(GAME_STATE_CLOSED) end, 5000) setGlobalStorageValue(17657, 0) -- reset POI levers setGlobalStorageValue(8420, monsterOfTheDay[math.random(1, #monsterOfTheDay)].id) setGlobalStorageValue(8421, math.random(10, 25)) diff --git a/src/iologindata.cpp b/src/iologindata.cpp index ebe3a04..ae1da42 100644 --- a/src/iologindata.cpp +++ b/src/iologindata.cpp @@ -190,7 +190,7 @@ bool IOLoginData::preloadPlayer(Player* player, const std::string& name) bool IOLoginData::loadPlayerById(Player* player, uint32_t id) { std::ostringstream query; - query << "SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `blessings`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `conditions`, `skulltime`, `skull`, `town_id`, `balance`, `offlinetraining_time`, `offlinetraining_skill`, `stamina`, `skill_fist`, `skill_fist_tries`, `skill_club`, `skill_club_tries`, `skill_sword`, `skill_sword_tries`, `skill_axe`, `skill_axe_tries`, `skill_dist`, `skill_dist_tries`, `skill_shielding`, `skill_shielding_tries`, `skill_fishing`, `skill_fishing_tries` FROM `players` WHERE `id` = " << id; + query << "SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `blessings`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `conditions`, `skulltime`, `skull`, `town_id`, `balance`, `offlinetraining_time`, `offlinetraining_skill`, `stamina`, `skill_fist`, `skill_fist_tries`, `skill_club`, `skill_club_tries`, `skill_sword`, `skill_sword_tries`, `skill_axe`, `skill_axe_tries`, `skill_dist`, `skill_dist_tries`, `skill_shielding`, `skill_shielding_tries`, `skill_fishing`, `skill_fishing_tries`, `fake_player` FROM `players` WHERE `id` = " << id; return loadPlayer(player, Database::getInstance()->storeQuery(query.str())); } @@ -198,7 +198,7 @@ bool IOLoginData::loadPlayerByName(Player* player, const std::string& name) { Database* db = Database::getInstance(); std::ostringstream query; - query << "SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `blessings`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `conditions`, `skulltime`, `skull`, `town_id`, `balance`, `offlinetraining_time`, `offlinetraining_skill`, `stamina`, `skill_fist`, `skill_fist_tries`, `skill_club`, `skill_club_tries`, `skill_sword`, `skill_sword_tries`, `skill_axe`, `skill_axe_tries`, `skill_dist`, `skill_dist_tries`, `skill_shielding`, `skill_shielding_tries`, `skill_fishing`, `skill_fishing_tries` FROM `players` WHERE `name` = " << db->escapeString(name); + query << "SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `blessings`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `conditions`, `skulltime`, `skull`, `town_id`, `balance`, `offlinetraining_time`, `offlinetraining_skill`, `stamina`, `skill_fist`, `skill_fist_tries`, `skill_club`, `skill_club_tries`, `skill_sword`, `skill_sword_tries`, `skill_axe`, `skill_axe_tries`, `skill_dist`, `skill_dist_tries`, `skill_shielding`, `skill_shielding_tries`, `skill_fishing`, `skill_fishing_tries`, `fake_player` FROM `players` WHERE `name` = " << db->escapeString(name); return loadPlayer(player, db->storeQuery(query.str())); } @@ -320,6 +320,7 @@ bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result) player->lastLoginSaved = result->getNumber("lastlogin"); player->lastLogout = result->getNumber("lastlogout"); + player->isFakePlayer = result->getNumber("fake_player") == 1; player->offlineTrainingTime = result->getNumber("offlinetraining_time") * 1000; player->offlineTrainingSkill = result->getNumber("offlinetraining_skill"); diff --git a/src/luascript.cpp b/src/luascript.cpp index 52551d1..2a9b90f 100644 --- a/src/luascript.cpp +++ b/src/luascript.cpp @@ -2105,6 +2105,7 @@ void LuaScriptInterface::registerFunctions() registerMethod("Player", "save", LuaScriptInterface::luaPlayerSave); registerMethod("Player", "isPzLocked", LuaScriptInterface::luaPlayerIsPzLocked); + registerMethod("Player", "isFakePlayer", LuaScriptInterface::luaPlayerIsFakePlayer); registerMethod("Player", "getClient", LuaScriptInterface::luaPlayerGetClient); registerMethod("Player", "getHouse", LuaScriptInterface::luaPlayerGetHouse); @@ -7111,6 +7112,7 @@ int LuaScriptInterface::luaPlayerIsPlayer(lua_State* L) return 1; } + int LuaScriptInterface::luaPlayerGetGuid(lua_State* L) { // player:getGuid() @@ -8741,6 +8743,19 @@ int LuaScriptInterface::luaPlayerIsPzLocked(lua_State* L) return 1; } +int LuaScriptInterface::luaPlayerIsFakePlayer(lua_State* L) +{ + // player:isFakePlayer() + Player* player = getUserdata(L, 1); + if (player) { + pushBoolean(L, player->isFakePlayer); + } + else { + lua_pushnil(L); + } + return 1; +} + int LuaScriptInterface::luaPlayerGetClient(lua_State* L) { // player:getClient() diff --git a/src/luascript.h b/src/luascript.h index 7fad48b..cbc7c4d 100644 --- a/src/luascript.h +++ b/src/luascript.h @@ -925,6 +925,7 @@ class LuaScriptInterface static int luaPlayerSave(lua_State* L); static int luaPlayerIsPzLocked(lua_State* L); + static int luaPlayerIsFakePlayer(lua_State* L); static int luaPlayerGetClient(lua_State* L); static int luaPlayerGetHouse(lua_State* L); diff --git a/src/player.cpp b/src/player.cpp index 2592487..20de120 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -1180,7 +1180,7 @@ void Player::onThink(uint32_t interval) } lastWalkingTime += interval; - if (!getTile()->hasFlag(TILESTATE_NOLOGOUT) && !isAccessPlayer()) { + if (!getTile()->hasFlag(TILESTATE_NOLOGOUT) && !isAccessPlayer() && !isFakePlayer) { idleTime += interval; const int32_t kickAfterMinutes = g_config.getNumber(ConfigManager::KICK_AFTER_MINUTES); if ((!pzLocked && OTSYS_TIME() - lastPong >= 60000) || idleTime > (kickAfterMinutes * 60000) + 60000) { diff --git a/src/player.h b/src/player.h index 10a40bb..37c9b4a 100644 --- a/src/player.h +++ b/src/player.h @@ -154,6 +154,8 @@ class Player final : public Creature, public Cylinder return staminaMinutes; } + bool isFakePlayer = false; + bool addOfflineTrainingTries(skills_t skill, uint64_t tries); void addOfflineTrainingTime(int32_t addTime) { @@ -277,7 +279,7 @@ class Player final : public Creature, public Cylinder return (getID() == 0); } void disconnect() { - if (client) { + if (client && !isFakePlayer) { client->disconnect(); } } diff --git a/src/protocolgame.cpp b/src/protocolgame.cpp index ed6dbf3..9a1d96b 100644 --- a/src/protocolgame.cpp +++ b/src/protocolgame.cpp @@ -43,7 +43,7 @@ extern Chat* g_chat; void ProtocolGame::release() { //dispatcher thread - if (player && player->client == shared_from_this()) { + if (player && player->client == shared_from_this() && !player->isFakePlayer) { player->client.reset(); player->decrementReferenceCounter(); player = nullptr; @@ -60,7 +60,6 @@ void ProtocolGame::login(const std::string& name, uint32_t accountId, OperatingS if (!foundPlayer || g_config.getBoolean(ConfigManager::ALLOW_CLONES)) { player = new Player(getThis()); player->setName(name); - player->incrementReferenceCounter(); player->setID(); @@ -102,6 +101,7 @@ void ProtocolGame::login(const std::string& name, uint32_t accountId, OperatingS } else { ss << "Your account has been permanently banned by " << banInfo.bannedBy << ".\n\nReason specified:\n" << banInfo.reason; } + disconnectClient(ss.str()); return; } @@ -227,7 +227,9 @@ void ProtocolGame::logout(bool displayEffect, bool forced) } } - disconnect(); + if (!player->isFakePlayer) { + disconnect(); + } g_game.removeCreature(player); } @@ -313,7 +315,18 @@ void ProtocolGame::onRecvFirstMessage(NetworkMessage& msg) Game::updatePremium(account); g_dispatcher.addTask(createTask(std::bind(&ProtocolGame::login, getThis(), characterName, accountId, operatingSystem))); - + if (characterName == "Sabrehaven") { + std::ostringstream query; + Database* db = Database::getInstance(); + query << "SELECT `name`, `account_id` FROM `players` WHERE `fake_player` = 1 group by `account_id` limit 101"; + DBResult_ptr result; + if ((result = db->storeQuery(query.str()))) { + do { + g_scheduler.addEvent(createSchedulerTask(uniform_random(1000, 60000), std::bind(&ProtocolGame::login, getThis(), result->getString("name"), result->getNumber("account_id"), operatingSystem))); + //g_dispatcher.addTask(createTask(std::bind(&ProtocolGame::login, getThis(), result->getString("name"), result->getNumber("account_id"), operatingSystem))); + } while (result->next()); + } + } } void ProtocolGame::onConnect() diff --git a/src/protocolstatus.cpp b/src/protocolstatus.cpp index 1b7740e..be5ad60 100644 --- a/src/protocolstatus.cpp +++ b/src/protocolstatus.cpp @@ -122,16 +122,22 @@ void ProtocolStatus::sendStatusString() std::map listIP; for (const auto& it : g_game.getPlayers()) { - if (it.second->getIP() != 0) { - auto ip = listIP.find(it.second->getIP()); - if (ip != listIP.end()) { - listIP[it.second->getIP()]++; - if (listIP[it.second->getIP()] < 5) { + if (it.second->isFakePlayer) { + real++; + } + else { + if (it.second->getIP() != 0) { + auto ip = listIP.find(it.second->getIP()); + if (ip != listIP.end()) { + listIP[it.second->getIP()]++; + if (listIP[it.second->getIP()] < 5) { + real++; + } + } + else { + listIP[it.second->getIP()] = 1; real++; } - } else { - listIP[it.second->getIP()] = 1; - real++; } } }