Пример #1
0
int32_t WeaponMelee::getElementDamage(const Player* player, const Item* item) const
{
	int32_t attackSkill = player->getWeaponSkill(item);
	int32_t attackValue = std::max<int32_t>(0, elementDamage);
	float attackFactor = player->getAttackFactor();

	int32_t maxValue = Weapons::getMaxWeaponDamage(player->getLevel(), attackSkill, attackValue, attackFactor);
	if (uniform_random(1, 100) <= g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE)) {
		maxValue *= 2;
	}

	maxValue = int32_t(maxValue * player->getVocation()->meleeDamageMultiplier);
	return -normal_random(0, maxValue);
}
Пример #2
0
void IOMarket::moveOfferToHistory(uint32_t offerId, MarketOfferState_t state)
{
	Database* db = Database::getInstance();
	DBQuery query;
	query << "SELECT `player_id`, `sale`, `itemtype`, `amount`, `price`, `created` FROM `market_offers` WHERE `id` = " << offerId << " AND `world_id` = " 
		<< g_config.getNumber(ConfigManager::WORLD_ID) << ";";

	DBResult* result;
	if(!(result = db->storeQuery(query.str())))
		return;

	query.str("");
	query << "DELETE FROM `market_offers` WHERE `id` = " << offerId << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << ";";
	if(!db->query(query.str()))
	{
		result->free();
		return;
	}

	appendHistory(result->getDataInt("player_id"), (MarketAction_t)result->getDataInt("sale"), result->getDataInt("itemtype"), result->getDataInt("amount"),
		result->getDataInt("price"), result->getDataInt("created") + g_config.getNumber(ConfigManager::MARKET_OFFER_DURATION), state);
	result->free();
}
void ProtocolLogin::getCharacterList(const std::string& accountName, const std::string& password)
{
	Account account;
	if (!IOLoginData::loginserverAuthentication(accountName, password, account)) {
		disconnectClient("Account name or password is not correct.");
		return;
	}

	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if (output) {
		//Update premium days
		Game::updatePremium(account);

		//Add MOTD
		output->addByte(0x14);

		std::ostringstream ss;
		ss << g_game.getMotdNum() << "\n" << g_config.getString(ConfigManager::MOTD);
		output->addString(ss.str());

		//Add char list
		output->addByte(0x64);

		output->addByte(1); // number of worlds

		output->addByte(0); // world id
		output->addString(g_config.getString(ConfigManager::SERVER_NAME));
		output->addString(g_config.getString(ConfigManager::IP));
		output->add<uint16_t>(g_config.getNumber(ConfigManager::GAME_PORT));
		output->addByte(0);

		uint8_t size = std::min<size_t>(std::numeric_limits<uint8_t>::max(), account.characters.size());
		output->addByte(size);
		for (uint8_t i = 0; i < size; i++) {
			output->addByte(0);
			output->addString(account.characters[i]);
		}

		//Add premium days
		if (g_config.getBoolean(ConfigManager::FREE_PREMIUM)) {
			output->add<uint16_t>(0xFFFF);    //client displays free premium
		} else {
			output->add<uint16_t>(account.premiumDays);
		}

		OutputMessagePool::getInstance()->send(output);
	}

	getConnection()->close();
}
Пример #4
0
void Commands::buyHouse(Player* player, const std::string& cmd, const std::string& param)
{
	if (!player->isPremium()) {
		player->sendCancelMessage(RET_YOUNEEDPREMIUMACCOUNT);
		return;
	}

	Position pos = player->getPosition();
	pos = getNextPosition(player->direction, pos);

	Tile* tile = g_game.getTile(pos.x, pos.y, pos.z);

	if (!tile) {
		player->sendCancel("You have to be looking at the door of the house you would like to buy.");
		return;
	}

	HouseTile* houseTile = dynamic_cast<HouseTile*>(tile);
	if (!houseTile) {
		player->sendCancel("You have to be looking at the door of the house you would like to buy.");
		return;
	}

	House* house = houseTile->getHouse();
	if (!house || !house->getDoorByPosition(pos)) {
		player->sendCancel("You have to be looking at the door of the house you would like to buy.");
		return;
	}

	if (house->getHouseOwner()) {
		player->sendCancel("This house alreadly has an owner.");
		return;
	}

	for (const auto& it : Houses::getInstance().getHouses()) {
		if (it.second->getHouseOwner() == player->guid) {
			player->sendCancel("You are already the owner of a house.");
			return;
		}
	}

	uint64_t price = house->getHouseTiles().size() * g_config.getNumber(ConfigManager::HOUSE_PRICE);
	if (!g_game.removeMoney(player, price)) {
		player->sendCancel("You do not have enough money.");
		return;
	}

	house->setHouseOwner(player->guid);
	player->sendTextMessage(MSG_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in the bank.");
}
Пример #5
0
void MagicField::onStepInField(Creature* creature, bool purposeful/* = true*/)
{
	if(!creature)
		return;

	if(isUnstepable() || isBlocking(creature))
	{
		if(!creature->isGhost())
			g_game.internalRemoveItem(creature, this, 1);

		return;
	}

	if(!purposeful || !creature->isAttackable())
		return;

	const ItemType& it = items[id];
	if(!it.condition)
		return;

	uint32_t ownerId = getOwner();
	Tile* tile = getTile();

	Condition* condition = it.condition->clone();
	if(ownerId && !tile->hasFlag(TILESTATE_HARDCOREZONE))
	{
		if(Creature* owner = g_game.getCreatureByID(ownerId))
		{
			Player* ownerPlayer = owner->getPlayer();
			if(!ownerPlayer && owner->isPlayerSummon())
				ownerPlayer = owner->getPlayerMaster();

			bool harmful = true;
			if((g_game.getWorldType() == WORLDTYPE_OPTIONAL || tile->hasFlag(TILESTATE_OPTIONALZONE)) && ownerPlayer)
				harmful = false;
			else if(Player* player = creature->getPlayer())
			{
				if(ownerPlayer && Combat::isProtected(ownerPlayer, player))
					harmful = false;
			}

			if(!harmful || (OTSYS_TIME() - createTime) <= (uint32_t)g_config.getNumber(
				ConfigManager::FIELD_OWNERSHIP) || creature->hasBeenAttacked(ownerId))
				condition->setParam(CONDITIONPARAM_OWNER, ownerId);
		}
	}

	creature->addCondition(condition);
}
Пример #6
0
void Creature::onDeath()
{
	bool lastHitUnjustified = false;
	bool mostDamageUnjustified = false;
	Creature* _lastHitCreature = g_game.getCreatureByID(lastHitCreature);
	Creature* lastHitCreatureMaster;
	if (_lastHitCreature) {
		lastHitUnjustified = _lastHitCreature->onKilledCreature(this);
		lastHitCreatureMaster = _lastHitCreature->getMaster();
	} else {
		lastHitCreatureMaster = nullptr;
	}

	Creature* mostDamageCreature = nullptr;

	const int64_t timeNow = OTSYS_TIME();
	const uint32_t inFightTicks = g_config.getNumber(ConfigManager::PZ_LOCKED);
	int32_t mostDamage = 0;
	for (const auto& it : damageMap) {
		if (Creature* attacker = g_game.getCreatureByID(it.first)) {
			CountBlock_t cb = it.second;
			if ((cb.total > mostDamage && (timeNow - cb.ticks <= inFightTicks))) {
				mostDamage = cb.total;
				mostDamageCreature = attacker;
			}
			attacker->onAttackedCreatureKilled(this);
		}
	}

	if (mostDamageCreature) {
		if (mostDamageCreature != _lastHitCreature && mostDamageCreature != lastHitCreatureMaster) {
			Creature* mostDamageCreatureMaster = mostDamageCreature->getMaster();
			if (_lastHitCreature != mostDamageCreatureMaster && (lastHitCreatureMaster == nullptr || mostDamageCreatureMaster != lastHitCreatureMaster)) {
				mostDamageUnjustified = mostDamageCreature->onKilledCreature(this, false);
			}
		}
	}

	bool droppedCorpse = dropCorpse(_lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified);
	death(_lastHitCreature);

	if (master) {
		master->removeSummon(this);
	}

	if (droppedCorpse) {
		g_game.removeCreature(this, false);
	}
}
Пример #7
0
void Connection::parseHeader(const boost::system::error_code& error)
{
	m_connectionLock.lock();
	m_readTimer.cancel();

	int32_t size = m_msg.decodeHeader();
	if (error || size <= 0 || size >= NETWORKMESSAGE_MAXSIZE - 16) {
		handleReadError(error);
	}

	if (m_connectionState != CONNECTION_STATE_OPEN || m_readError) {
		closeConnection();
		m_connectionLock.unlock();
		return;
	}

	uint32_t timePassed = std::max<uint32_t>(1, (time(nullptr) - m_timeConnected) + 1);
	if ((++m_packetsSent / timePassed) > (uint32_t)g_config.getNumber(ConfigManager::MAX_PACKETS_PER_SECOND)) {
		std::cout << convertIPToString(getIP()) << " disconnected for exceeding packet per second limit." << std::endl;
		closeConnection();
		m_connectionLock.unlock();
		return;
	}

	if (timePassed > 2) {
		m_timeConnected = time(nullptr);
		m_packetsSent = 0;
	}

	try {
		m_readTimer.expires_from_now(boost::posix_time::seconds(Connection::read_timeout));
		m_readTimer.async_wait( std::bind(&Connection::handleReadTimeout, std::weak_ptr<Connection>(shared_from_this()),
		                                    std::placeholders::_1));

		// Read packet content
		m_msg.setMessageLength(size + NetworkMessage::header_length);
		boost::asio::async_read(getHandle(), boost::asio::buffer(m_msg.getBodyBuffer(), size),
		                        std::bind(&Connection::parsePacket, shared_from_this(), std::placeholders::_1));
	} catch (boost::system::system_error& e) {
		if (m_logError) {
			std::cout << "[Network error - Connection::parseHeader] " << e.what() << std::endl;
			m_logError = false;
		}

		closeConnection();
	}

	m_connectionLock.unlock();
}
Пример #8
0
bool IOPlayer::getAccountByName(std::string& account, const std::string& player_name)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;
	DBQuery query;

	query << "SELECT `a`.`name` FROM `players` p LEFT JOIN `accounts` a ON `p`.`account_id` = `a`.`id` "
		"WHERE `p`.`world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `p`.`name` = " << db->escapeString(player_name);

	if(!(result = db->storeQuery(query)))
		return false;

	account = result->getDataString("name");
	return true;
}
Пример #9
0
int32_t IOMarket::getPlayerOfferCount(uint32_t playerId)
{
	Database* db = Database::getInstance();
	DBQuery query;
	query << "SELECT COUNT(*) AS `count` FROM `market_offers` WHERE `player_id` = " << playerId << " AND `world_id` = " 
		<< g_config.getNumber(ConfigManager::WORLD_ID) << ";";

	DBResult* result;
	if(!(result = db->storeQuery(query.str())))
		return -1;

	int32_t tmp = result->getDataInt("count");
	result->free();
	return tmp;
}
Пример #10
0
void Party::shareExperience(uint64_t experience, bool fromMonster)
{
	double member_factor = g_config.getNumber(ConfigManager::PARTY_MEMBER_EXP_BONUS);
	double xpgained = experience / (memberList.size() + 1) + experience * (member_factor / 100.);

	if(xpgained < 0)
		return;
	uint64_t shareExp = (uint64_t)std::ceil(xpgained);
	
	for(PlayerVector::iterator it = memberList.begin(); it != memberList.end(); ++it){
		(*it)->onGainSharedExperience(shareExp, fromMonster);
	}

	getLeader()->onGainSharedExperience(shareExp, fromMonster);
}
Пример #11
0
bool Monster::inDespawnRange(const Position& pos)
{
	if(spawn && !mType->isLureable){
		if(g_config.getNumber(ConfigManager::DEFAULT_DESPAWNRADIUS) == 0){
			return false;
		}

		if(!Spawns::getInstance()->isInZone(masterPos, g_config.getNumber(ConfigManager::DEFAULT_DESPAWNRADIUS), pos)){
			return true;
		}

		if(g_config.getNumber(ConfigManager::DEFAULT_DESPAWNRANGE) == 0){
			return false;
		}

		if(std::abs(pos.z - masterPos.z) > g_config.getNumber(ConfigManager::DEFAULT_DESPAWNRANGE)){
			return true;
		}

		return false;
	}

	return false;
}
Пример #12
0
void DatabaseMySQL::keepAlive()
{
	int32_t timeout = g_config.getNumber(ConfigManager::SQL_KEEPALIVE) * 1000;
	if(!timeout)
		return;

	if(OTSYS_TIME() > (m_use + timeout))
	{
		if(mysql_ping(&m_handle))
			m_connected = false;
	}

	Scheduler::getInstance().addEvent(createSchedulerTask(timeout,
		boost::bind(&DatabaseMySQL::keepAlive, this)));
}
Пример #13
0
DeathList Creature::getKillers()
{
	DeathList list;
	Creature* lhc = NULL;
	if(!(lhc = g_game.getCreatureByID(lastHitCreature)))
		list.push_back(DeathEntry(getCombatName(lastDamageSource), 0));
	else
		list.push_back(DeathEntry(lhc, 0));

	int32_t requiredTime = g_config.getNumber(ConfigManager::DEATHLIST_REQUIRED_TIME);
	int64_t now = OTSYS_TIME();

	CountBlock_t cb;
	for(CountMap::const_iterator it = damageMap.begin(); it != damageMap.end(); ++it)
	{
		cb = it->second;
		if((now - cb.ticks) > requiredTime)
			continue;

		Creature* mdc = g_game.getCreatureByID(it->first);
		if(!mdc || mdc == lhc || (lhc && (mdc->getMaster() == lhc || lhc->getMaster() == mdc)))
			continue;

		bool deny = false;
		for(DeathList::iterator fit = list.begin(); fit != list.end(); ++fit)
		{
			if(fit->isNameKill())
				continue;

			Creature* tmp = fit->getKillerCreature();
			if(!(mdc->getName() == tmp->getName() && mdc->getMaster() == tmp->getMaster()) &&
				(!mdc->getMaster() || (mdc->getMaster() != tmp && mdc->getMaster() != tmp->getMaster()))
				&& (mdc->getSummonCount() <= 0 || tmp->getMaster() != mdc))
				continue;

			deny = true;
			break;
		}

		if(!deny)
			list.push_back(DeathEntry(mdc, cb.total));
	}

	if(list.size() > 1)
		std::sort(list.begin() + 1, list.end(), DeathLessThan());

	return list;
}
Пример #14
0
bool Actions::useItem(Player* player, const Position& pos, uint8_t index, Item* item, bool isHotkey)
{
	player->setNextAction(OTSYS_TIME() + g_config.getNumber(ConfigManager::ACTIONS_DELAY_INTERVAL));
	player->stopWalk();

	if (isHotkey) {
		showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), -1));
	}

	ReturnValue ret = internalUseItem(player, pos, index, item, isHotkey);
	if (ret != RETURNVALUE_NOERROR) {
		player->sendCancelMessage(ret);
		return false;
	}
	return true;
}
Пример #15
0
void Combat::postCombatEffects(Creature* caster, const Position& pos, const CombatParams& params)
{
	if(caster){
		if(params.distanceEffect != NM_ME_NONE)
			addDistanceEffect(caster, caster->getPosition(), pos, params.distanceEffect);

		Player* p_caster = NULL;
		if(caster->getPlayer())
			p_caster = caster->getPlayer();
		else if(caster->isPlayerSummon())
			p_caster = caster->getPlayerMaster();

		if(p_caster && !p_caster->hasFlag(PlayerFlag_NotGainInFight) && params.isAggressive)
			p_caster->addInFightTicks(g_config.getNumber(ConfigManager::IN_FIGHT_DURATION), params.pzBlock);
	}
}
Пример #16
0
bool IOPlayer::getLastIP(uint32_t& ip, uint32_t guid)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;

	DBQuery query;
	query <<
		"SELECT `lastip` "
		"FROM `players` "
		"WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `id` = " << guid << ";";
	if(!(result = db->storeQuery(query)))
		return false;

	ip = result->getDataInt("lastip");
	return true;
}
Пример #17
0
bool IOPlayer::getAccountByName(uint32_t& account, const std::string& name)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;
	DBQuery query;

	query <<
		"SELECT `account_id` "
		"FROM `players` "
		"WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `name` = " << db->escapeString(name);
	if(!(result = db->storeQuery(query)))
		return false;

	account = result->getDataInt("account_id");
	return true;
}
Пример #18
0
bool IOPlayer::getDefaultTown(std::string& name, uint32_t& depotId)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;
	DBQuery query;

	query <<
		"SELECT `town_id` "
		"FROM `players` "
		"WHERE `players`.`world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `name`= " << db->escapeString(name);
	if(!(result = db->storeQuery(query)))
		return false;

	depotId = result->getDataInt("town_id");
	return true;
}
Пример #19
0
uint32_t IOMarket::getOfferIdByCounter(uint32_t timestamp, uint16_t counter)
{
	const int32_t created = timestamp - g_config.getNumber(ConfigManager::MARKET_OFFER_DURATION);

	std::ostringstream query;
	query << "SELECT `id` FROM `market_offers` WHERE `created` = " << created << " AND (`id` & 65535) = " << counter << " LIMIT 1";
	Database* db = Database::getInstance();

	DBResult* result = db->storeQuery(query.str());
	if (result) {
		uint32_t offerId = result->getDataInt("id");
		db->freeResult(result);
		return offerId;
	}

	return 0;
}
Пример #20
0
bool IOPlayer::hasFlag(PlayerFlags flag, uint32_t guid)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;

	DBQuery query;
	query <<
		"SELECT `groups`.`flags` AS `flags` "
		"FROM `players` "
		"LEFT JOIN `groups` ON `groups`.`id` = `players`.`group_id` "
		"WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `players`.`id` = " << guid;
	if(!(result = db->storeQuery(query)))
		return false;

	uint64_t flags = result->getDataLong("flags");
	return (flags & (1ull << flag)) != 0;
}
Пример #21
0
bool IOPlayer::getGuidByNameEx(uint32_t& guid, bool& specialVip, const std::string& player_name)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;
	DBQuery query;

	query <<
		"SELECT `players`.`name`, `players`.`id`, `groups`.`flags` AS `flags` "
		"FROM `players` LEFT JOIN `groups` ON `groups`.`id` = `players`.`group_id` "
		"WHERE `players`.`world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `players`.`name`= " << db->escapeString(player_name);
	if(!(result = db->storeQuery(query.str())))
		return false;

	guid = result->getDataInt("id");
	specialVip = (result->getDataLong("flags") & (1ull << PlayerFlag_SpecialVIP)) != 0;
	return true;
}
Пример #22
0
int32_t WeaponMelee::getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage /*= false*/) const
{
	int32_t attackSkill = player->getWeaponSkill(item);
	int32_t attackValue = std::max<int32_t>(0, item->getAttack());
	float attackFactor = player->getAttackFactor();

	int32_t maxValue = Weapons::getMaxWeaponDamage(player->getLevel(), attackSkill, attackValue, attackFactor);
	if(random_range(1, 100) <= g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE))
		maxValue <<= 1;

	maxValue = int32_t(maxValue * player->getVocation()->meleeDamageMultipler);

	if(maxDamage)
		return -maxValue;

	return -random_range(0, maxValue, DISTRO_NORMAL);
}
Пример #23
0
bool IOPlayer::getGuildIdByName(uint32_t& guildId, const std::string& guildName)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;
	DBQuery query;

	query <<
		"SELECT `guilds`.`id` "
		"FROM `guilds` "
		"LEFT JOIN `players` ON `players`.`id` = `guilds`.`owner_id` "
		"WHERE `players`.`world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `guilds`.`name` = " << db->escapeString(guildName);
	if(!(result = db->storeQuery(query)))
		return false;

	guildId = result->getDataInt("id");
	return true;
}
Пример #24
0
bool Combat::isProtected(const Player* attacker, const Player* target)
{
	uint32_t protectionLevel = g_config.getNumber(ConfigManager::PROTECTION_LEVEL);
	if (target->getLevel() < protectionLevel || attacker->getLevel() < protectionLevel) {
		return true;
	}

	if (attacker->getVocationId() == VOCATION_NONE || target->getVocationId() == VOCATION_NONE) {
		return true;
	}

	if (attacker->getSkull() == SKULL_BLACK && attacker->getSkullClient(target) == SKULL_NONE) {
		return true;
	}

	return false;
}
Пример #25
0
void Commands::playerKills(Player* player, const std::string& cmd, const std::string& param)
{
	int32_t fragTime = g_config.getNumber(ConfigManager::FRAG_TIME);

	if (player->skullTicks && fragTime > 0) {
		int32_t frags = (int32_t)ceil(player->skullTicks / (double)fragTime);
		int32_t remainingTime = (player->skullTicks % fragTime) / 1000;
		int32_t hours = remainingTime / 3600;
		int32_t minutes = (remainingTime % 3600) / 60;

		std::ostringstream ss;
		ss << "You have " << frags << " unjustified kill" << (frags > 1 ? "s" : "") << ". The amount of unjustified kills will decrease after: " << hours << " hour" << (hours != 1 ? "s" : "") << " and " << minutes << " minute" << (minutes != 1 ? "s" : "") << ".";
		player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, ss.str());
	} else {
		player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "You do not have any unjustified frag.");
	}
}
Пример #26
0
void DatabaseManager::checkEncryption()
{
	int32_t currentValue = g_config.getNumber(ConfigManager::PASSWORD_TYPE);
	int32_t oldValue = 0;

	if (getDatabaseConfig("encryption", oldValue)) {
		if (currentValue == oldValue) {
			return;
		}

		if (oldValue != PASSWORD_TYPE_PLAIN) {
			std::string oldName;

			if (oldValue == PASSWORD_TYPE_MD5) {
				oldName = "md5";
			} else if (oldValue == PASSWORD_TYPE_SHA1) {
				oldName = "sha1";
			} else {
				oldName = "plain";
			}

			g_config.setNumber(ConfigManager::PASSWORD_TYPE, oldValue);
			std::cout << "> WARNING: Unsupported password hashing switch! Change back passwordType in config.lua to \"" << oldName << "\"!" << std::endl;
			return;
		}

		switch (currentValue) {
			case PASSWORD_TYPE_MD5: {
				Database::getInstance()->executeQuery("UPDATE `accounts` SET `password` = MD5(`password`)");
				std::cout << "> Password type has been updated to MD5." << std::endl;
				break;
			}

			case PASSWORD_TYPE_SHA1: {
				Database::getInstance()->executeQuery("UPDATE `accounts` SET `password` = SHA1(`password`)");
				std::cout << "> Password type has been updated to SHA1." << std::endl;
				break;
			}

			default:
				break;
		}
	}

	registerDatabaseConfig("encryption", currentValue);
}
Пример #27
0
void House::updateDoorDescription()
{
	std::ostringstream ss;
	if(houseOwner != 0)
		ss << "It belongs to house '" << houseName << "'. " << houseOwnerName << " owns this house.";
	else
	{
		int32_t housePrice = 0;
		for(HouseTileList::iterator it = getHouseTileBegin(), end = getHouseTileEnd(); it != end; ++it)
			housePrice += g_config.getNumber(ConfigManager::HOUSE_PRICE);

		ss << "It belongs to house '" << houseName << "'. Nobody owns this house. It costs " << housePrice << " gold coins.";
	}

	HouseDoorList::iterator it;
	for(it = doorList.begin(); it != doorList.end(); ++it)
		(*it)->setSpecialDescription(ss.str());
}
Пример #28
0
bool IOMapSerialize::saveHouseItems(Database* db, House* house)
{
	std::string config = asLowerCaseString(g_config.getString(ConfigManager::HOUSE_STORAGE));
	if(config == "binary-tilebased")
	{
		DBQuery query;
		query << "DELETE FROM `tile_store` WHERE `house_id` = " << house->getId()
			<< " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
		if(!db->query(query.str()))
			return false;

		DBInsert stmt(db);
		stmt.setQuery("INSERT INTO `tile_store` (`house_id`, `world_id`, `data`) VALUES ");
		return saveHouseBinaryTileBased(db, stmt, house) && stmt.execute();
	}
	else if(config == "binary")
	{
		DBQuery query;
		query << "DELETE FROM `house_data` WHERE `house_id` = "<< house->getId()
			<< " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
		if(!db->query(query.str()))
			return false;

		DBInsert stmt(db);
		stmt.setQuery("INSERT INTO `house_data` (`house_id`, `world_id`, `data`) VALUES ");
		return saveHouseBinary(db, stmt, house) && stmt.execute();
	}

	DBQuery query;
	query << "DELETE FROM `tile_items` WHERE `tile_id` IN (SELECT `id` FROM `tiles` WHERE `house_id` = "
		<< house->getId() << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID)
		<< ") AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
	if(!db->query(query.str()))
		return false;

	query.str("");
	query << "DELETE FROM `tiles` WHERE `house_id` = " << house->getId()
		<< " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
	if(!db->query(query.str()))
		return false;

	query.str("");
	query << "SELECT `id` FROM `tiles` WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " ORDER BY `id` DESC LIMIT 1;";

	DBResult* result;
	if(!(result = db->storeQuery(query.str())))
		return false;

	uint32_t tileId = result->getDataInt("id") + 1;
	result->free();
	return saveHouseRelational(db, house, tileId);
}
Пример #29
0
void House::updateDoorDescription() const
{
	std::ostringstream ss;
	if (owner != 0) {
		ss << "It belongs to house '" << houseName << "'. " << ownerName << " owns this house.";
	} else {
		ss << "It belongs to house '" << houseName << "'. Nobody owns this house.";

		const int32_t housePrice = g_config.getNumber(ConfigManager::HOUSE_PRICE);
		if (housePrice != -1) {
			ss << " It costs " << (houseTiles.size() * housePrice) << " gold coins.";
		}
	}

	for (const auto& it : doorList) {
		it->setSpecialDescription(ss.str());
	}
}
Пример #30
0
void ProtocolStatus::onRecvFirstMessage(NetworkMessage& msg)
{
	uint32_t ip = getIP();
	if (ip != 0x0100007F) {
		std::string ipStr = convertIPToString(ip);
		if (ipStr != g_config.getString(ConfigManager::IP)) {
			std::map<uint32_t, int64_t>::const_iterator it = ipConnectMap.find(ip);
			if (it != ipConnectMap.end()) {
				if (OTSYS_TIME() < (it->second + g_config.getNumber(ConfigManager::STATUSQUERY_TIMEOUT))) {
					getConnection()->close();
					return;
				}
			}
		}
	}

	ipConnectMap[ip] = OTSYS_TIME();

	switch (msg.getByte()) {
		//XML info protocol
		case 0xFF: {
			if (msg.getString(4) == "info") {
				g_dispatcher.addTask(createTask(std::bind(&ProtocolStatus::sendStatusString, this)));
				return;
			}
			break;
		}

		//Another ServerInfo protocol
		case 0x01: {
			uint16_t requestedInfo = msg.get<uint16_t>(); // only a Byte is necessary, though we could add new info here
			std::string characterName;
			if (requestedInfo & REQUEST_PLAYER_STATUS_INFO) {
				characterName = msg.getString();
			}
			g_dispatcher.addTask(createTask(std::bind(&ProtocolStatus::sendInfo, this, requestedInfo, characterName)));
			return;
		}

		default:
			break;
	}
	getConnection()->close();
}