mirror of
				https://github.com/ErikasKontenis/SabrehavenServer.git
				synced 2025-10-30 19:56:22 +01:00 
			
		
		
		
	prepare fake players mechanism
This commit is contained in:
		| @@ -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<time_t>("lastlogin"); | ||||
| 	player->lastLogout = result->getNumber<time_t>("lastlogout"); | ||||
| 	player->isFakePlayer = result->getNumber<int32_t>("fake_player") == 1; | ||||
|  | ||||
| 	player->offlineTrainingTime = result->getNumber<int32_t>("offlinetraining_time") * 1000; | ||||
| 	player->offlineTrainingSkill = result->getNumber<int32_t>("offlinetraining_skill"); | ||||
|   | ||||
| @@ -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<Player>(L, 1); | ||||
| 	if (player) { | ||||
| 		pushBoolean(L, player->isFakePlayer); | ||||
| 	} | ||||
| 	else { | ||||
| 		lua_pushnil(L); | ||||
| 	} | ||||
| 	return 1; | ||||
| } | ||||
|  | ||||
| int LuaScriptInterface::luaPlayerGetClient(lua_State* L) | ||||
| { | ||||
| 	// player:getClient() | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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) { | ||||
|   | ||||
| @@ -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(); | ||||
| 			} | ||||
| 		} | ||||
|   | ||||
| @@ -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<uint32_t>("account_id"), operatingSystem))); | ||||
| 				//g_dispatcher.addTask(createTask(std::bind(&ProtocolGame::login, getThis(), result->getString("name"), result->getNumber<uint32_t>("account_id"), operatingSystem))); | ||||
| 			} while (result->next()); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void ProtocolGame::onConnect() | ||||
|   | ||||
| @@ -122,16 +122,22 @@ void ProtocolStatus::sendStatusString() | ||||
| 	std::map<uint32_t, uint32_t> 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++; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 ErikasKontenis
					ErikasKontenis