Esempio n. 1
0
MarketOfferEx IOMarket::getOfferById(uint32_t id)
{
	Database* db = Database::getInstance();
	DBQuery query;
	query << "SELECT `id`, `sale`, `itemtype`, `amount`, `created`, `price`, `player_id`, `anonymous` FROM `market_offers` WHERE `id` = " << id 
		<< " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << ";";

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

	MarketOfferEx offer;
	offer.type = (MarketAction_t)result->getDataInt("sale");
	offer.amount = result->getDataInt("amount");
	offer.counter = result->getDataInt("id") & 0xFFFF;
	offer.timestamp = result->getDataInt("created");
	offer.price = result->getDataInt("price");
	offer.itemId = result->getDataInt("itemtype");

	int32_t playerId = result->getDataInt("player_id");
	offer.playerId = playerId;
	if(!result->getDataInt("anonymous"))
	{
		IOLoginData::getInstance()->getNameByGuid(playerId, offer.playerName);
		if(offer.playerName.empty())
			offer.playerName = "Anonymous";
	}
	else
		offer.playerName = "Anonymous";

	result->free();
	return offer;
}
Esempio n. 2
0
bool IOGuild::joinGuild(Player* player, uint32_t guildId)
{
	Database* db = Database::getInstance();
	DBQuery query;
	DBResult* result;

	query << "SELECT `name` FROM `guild_ranks` WHERE `guild_id` = " << guildId << " AND `level` = 1";
	if(!(result = db->storeQuery(query.str())))
		return false;

	const std::string rankName = result->getDataString("name");

	query.str("");
	db->freeResult(result);
	query << "SELECT `name` as `guildname` FROM `guilds` WHERE `id` = " << guildId;
	if(!(result = db->storeQuery(query.str())))
		return false;

	const std::string guildName = result->getDataString("guildname");

	query.str("");
	db->freeResult(result);
	query << "SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " << guildId << " AND `level` = 1";
	if(!(result = db->storeQuery(query.str())))
		return false;

	player->setGuildName(guildName);
	player->setGuildId(guildId);
	player->setGuildLevel(GUILDLEVEL_MEMBER);
	player->setGuildRank(rankName);
	player->invitedToGuildsList.clear();
	db->freeResult(result);
	return true;
}
Esempio n. 3
0
bool IOGuild::canLeaveWar(uint32_t guildId)
{
	if(!isInWar(guildId))
		return true;

	Database* db = Database::getInstance();

	DBQuery query;
	DBResult* result;
	bool returnVal = true;

	query << "SELECT `started` FROM `guild_wars` WHERE `guild1` = " << guildId << " AND `ended` = 0 AND `status` = 1;";
	if((result = db->storeQuery(query.str())))
	{
		do {
			if((result->getDataLong("started") + (86400 * 4)) >= time(NULL))
				returnVal = false;
		} while (result->next());
		db->freeResult(result);
	}

	query.str("");
	query << "SELECT `started` FROM `guild_wars` WHERE `guild2` = " << guildId << " AND `ended` = 0 AND `status` = 1;";
	if((result = db->storeQuery(query.str())))
	{
		do {
			if((result->getDataLong("started") + (86400 * 4)) >= time(NULL))
				returnVal = false;
		} while (result->next());
		db->freeResult(result);
	}
	return returnVal;
}
Esempio n. 4
0
bool Database::connect()
{
	// connection handle initialization
	m_handle = mysql_init(nullptr);
	if (!m_handle) {
		std::cout << std::endl << "Failed to initialize MySQL connection handle." << std::endl;
		return false;
	}

	// automatic reconnect
	my_bool reconnect = true;
	mysql_options(m_handle, MYSQL_OPT_RECONNECT, &reconnect);

	// connects to database
	if (!mysql_real_connect(m_handle, g_config.getString(ConfigManager::MYSQL_HOST).c_str(), g_config.getString(ConfigManager::MYSQL_USER).c_str(), g_config.getString(ConfigManager::MYSQL_PASS).c_str(), g_config.getString(ConfigManager::MYSQL_DB).c_str(), g_config.getNumber(ConfigManager::SQL_PORT), nullptr, 0)) {
		std::cout << std::endl << "MySQL Error Message: " << mysql_error(m_handle) << std::endl;
		return false;
	}

	m_connected = true;

	DBResult* result = storeQuery("SHOW variables LIKE 'max_allowed_packet'");
	if (result) {
		int32_t max_query = result->getDataInt("Value");
		freeResult(result);

		if (max_query < 16777216) {
			std::cout << std::endl << "[Warning] max_allowed_packet might too low for house item storage" << std::endl;
			std::cout << "Use the following query to raise max_allow_packet: ";
			std::cout << "SET GLOBAL max_allowed_packet = 16777216";
		}
	}
	return true;
}
Esempio n. 5
0
bool IOBan::isAccountBanned(uint32_t accountId, BanInfo& banInfo)
{
	Database* db = Database::getInstance();

	std::ostringstream query;
	query << "SELECT `reason`, `expires_at`, `banned_at`, `banned_by`, (SELECT `name` FROM `players` WHERE `id` = `banned_by`) AS `name` FROM `account_bans` WHERE `account_id` = " << accountId;

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

	int64_t expiresAt = result->getNumber<int64_t>("expires_at");
	if (expiresAt != 0 && time(nullptr) > expiresAt) {
		// Move the ban to history if it has expired
		query.str("");
		query << "INSERT INTO `account_ban_history` (`account_id`, `reason`, `banned_at`, `expired_at`, `banned_by`) VALUES (" << accountId << ',' << db->escapeString(result->getDataString("reason")) << ',' << result->getDataInt("banned_at") << ',' << expiresAt << ',' << result->getDataInt("banned_by") << ')';
		db->executeQuery(query.str());

		query.str("");
		query << "DELETE FROM `account_bans` WHERE `account_id` = " << accountId;
		db->executeQuery(query.str());

		db->freeResult(result);
		return false;
	}

	banInfo.expiresAt = expiresAt;
	banInfo.reason = result->getDataString("reason");
	banInfo.bannedBy = result->getDataString("name");
	db->freeResult(result);
	return true;
}
Esempio n. 6
0
bool IOBan::isIpBanned(uint32_t clientip, BanInfo& banInfo)
{
	if (clientip == 0) {
		return false;
	}

	Database* db = Database::getInstance();

	std::ostringstream query;
	query << "SELECT `reason`, `expires_at`, (SELECT `name` FROM `players` WHERE `id` = `banned_by`) AS `name` FROM `ip_bans` WHERE `ip` = " << clientip;

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

	int64_t expiresAt = result->getNumber<int64_t>("expires_at");
	if (expiresAt != 0 && time(nullptr) > expiresAt) {
		query << "DELETE FROM `ip_bans` WHERE `ip` = " << clientip;
		db->executeQuery(query.str());

		db->freeResult(result);
		return false;
	}

	banInfo.expiresAt = expiresAt;
	banInfo.reason = result->getDataString("reason");
	banInfo.bannedBy = result->getDataString("name");
	db->freeResult(result);
	return true;
}
Esempio n. 7
0
void *API_resultOK(UINT64 affected, UINT64 insertId, int serverStatus,
                   const char *message, size_t len, void *opt)
{
    DBResult *res = new DBResult(affected, insertId);
    res->Ref();
    return res;
}
Esempio n. 8
0
void IOMarket::updateStatistics()
{
	Database* db = Database::getInstance();
	DBQuery query;
	query << "SELECT `sale`, `itemtype`, COUNT(`price`) AS `num`, MIN(`price`) AS `min`, MAX(`price`) AS `max`, SUM(`price`) AS `sum` FROM `market_history` WHERE `state` = "
		<< OFFERSTATE_ACCEPTED << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " GROUP BY `itemtype`, `sale`;";

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

	do
	{
		MarketStatistics* statistics;
		if(result->getDataInt("sale") == MARKETACTION_BUY)
			statistics = &purchaseStatistics[result->getDataInt("itemtype")];
		else
			statistics = &saleStatistics[result->getDataInt("itemtype")];

		statistics->numTransactions = result->getDataInt("num");
		statistics->lowestPrice = result->getDataInt("min");
		statistics->totalPrice = result->getDataLong("sum");
		statistics->highestPrice = result->getDataInt("max");
	}
	while(result->next());
	result->free();
}
bool IOLoginData::getGuidByNameEx(uint32_t& guid, bool& specialVip, std::string& name)
{
	Database* db = Database::getInstance();

	std::ostringstream query;
	query << "SELECT `name`, `id`, `group_id`, `account_id` FROM `players` WHERE `name` = " << db->escapeString(name);

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

	name = result->getDataString("name");
	guid = result->getDataInt("id");
	Group* group = g_game.getGroup(result->getDataInt("group_id"));
	db->freeResult(result);

	uint64_t flags;
	if (group) {
		flags = group->flags;
	} else {
		flags = 0;
	}

	specialVip = (0 != (flags & ((uint64_t)1 << PlayerFlag_SpecialVIP)));
	return true;
}
Esempio n. 10
0
bool IOMapSerialize::loadHouseInfo()
{
	Database* db = Database::getInstance();

	DBResult* result = db->storeQuery("SELECT `id`, `owner`, `paid`, `warnings` FROM `houses`");
	if (!result) {
		return false;
	}

	do {
		House* house = Houses::getInstance().getHouse(result->getDataInt("id"));
		if (house) {
			house->setOwner(result->getDataInt("owner"), false);
			house->setPaidUntil(result->getDataInt("paid"));
			house->setPayRentWarnings(result->getDataInt("warnings"));
		}
	} while (result->next());
	db->freeResult(result);

	result = db->storeQuery("SELECT `house_id`, `listid`, `list` FROM `house_lists`");
	if (result) {
		do {
			House* house = Houses::getInstance().getHouse(result->getDataInt("house_id"));
			if (house) {
				house->setAccessList(result->getDataInt("listid"), result->getDataString("list"));
			}
		} while (result->next());
		db->freeResult(result);
	}
	return true;
}
Esempio n. 11
0
bool IOGuild::changeRank(uint32_t guild, const std::string& oldName, const std::string& newName)
{
	Database* db = Database::getInstance();
	DBResult* result;

	DBQuery query;
	query << "SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " << guild << " AND `name` " << db->getStringComparer() << db->escapeString(oldName) << " LIMIT 1";
	if(!(result = db->storeQuery(query.str())))
		return false;

	const uint32_t id = result->getDataInt("id");
	result->free();

	query.str("");
	query << "UPDATE `guild_ranks` SET `name` = " << db->escapeString(newName) << " WHERE `id` = " << id << db->getUpdateLimiter();
	if(!db->query(query.str()))
		return false;

	for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)
	{
		if(it->second->getRankId() == id)
			it->second->setRankName(newName);
	}

	return true;
}
Esempio n. 12
0
bool IOGuild::joinGuild(Player* player, uint32_t guildId)
{
	Database* db = Database::getInstance();

	DBQuery query;
	DBResult* result;

	query << "SELECT `id`, `name` FROM `guild_ranks` WHERE `guild_id` = " << guildId << " AND `level` = 1 LIMIT 1";
	if(!(result = db->storeQuery(query.str())))
		return false;

	query.str("");

	player->setGuildRank(result->getDataString("name"));
	player->setGuildId(guildId);
	query << "UPDATE `players` SET `rank_id` = " << result->getDataInt("id") << " WHERE `id` = " << player->getGUID() << db->getUpdateLimiter();
	if(!db->executeQuery(query.str()))
		return false;

	query.str("");

	player->setGuildName(getGuildNameById(guildId));
	query << "SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " << guildId << " AND `level` = 1 LIMIT 1;";
	if(!(result = db->storeQuery(query.str())))
		return false;

	player->setGuildLevel(GUILDLEVEL_MEMBER);
	player->invitedToGuildsList.clear();
	return true;
}
Esempio n. 13
0
GuildWarList IOGuild::getWarList(uint32_t guildId)
{
	GuildWarList guildWarList;

	Database* db = Database::getInstance();

	DBQuery query;
	DBResult* result;
	query << "SELECT `guild1` FROM `guild_wars` WHERE `guild2` = " << guildId << " AND `ended` = 0 AND `status` = 1;";
	if((result = db->storeQuery(query.str())))
	{
		do {
			guildWarList.push_back(result->getDataInt("guild1"));
		} while (result->next());
		db->freeResult(result);
	}

	query.str("");
	query << "SELECT `guild2` FROM `guild_wars` WHERE `guild1` = " << guildId << " AND `ended` = 0 AND `status` = 1;";
	if((result = db->storeQuery(query.str())))
	{
		do {
			guildWarList.push_back(result->getDataInt("guild2"));
		} while (result->next());
		db->freeResult(result);
	}
	return guildWarList;
}
Esempio n. 14
0
bool BanManager::isPlayerBanished(const uint32_t& playerId) const
{
	Database* db = Database::instance();
	DBQuery query;
	query <<
	      "SELECT "
	      "COUNT(*) AS `count` "
	      "FROM "
	      "`bans` "
	      "WHERE "
	      "`type` = " << BAN_PLAYER << " AND "
	      "`value` = " << playerId << " AND "
	      "`active` = 1 AND "
	      "(`expires` >= " << std::time(NULL) << " OR `expires` <= 0)";
	DBResult* result;

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

	int t = result->getDataInt("count");
	db->freeResult(result);
	return t > 0;
}
Esempio n. 15
0
bool IOLoginData::getGuidByName(uint32_t& guid, std::string& name)
{
	GuidCacheMap::const_iterator it = guidCacheMap.find(name);

	if (it != guidCacheMap.end()) {
		name = it->first;
		guid = it->second;
		return true;
	}

	Database* db = Database::getInstance();

	std::ostringstream query;
	query << "SELECT `id`, `name` FROM `players` WHERE `name` = " << db->escapeString(name);

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

	name = result->getDataString("name");
	guid = result->getDataInt("id");
	db->freeResult(result);

	guidCacheMap[name] = guid;
	return true;
}
Esempio n. 16
0
bool IOLoginData::getNameByGuid(uint32_t guid, std::string& name)
{
	NameCacheMap::const_iterator it = nameCacheMap.find(guid);

	if (it != nameCacheMap.end()) {
		name = it->second;
		return true;
	}

	std::ostringstream query;
	query << "SELECT `name` FROM `players` WHERE `id` = " << guid;

	Database* db = Database::getInstance();

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

	name = result->getDataString("name");
	db->freeResult(result);

	nameCacheMap[guid] = name;
	return true;
}
Esempio n. 17
0
bool DatabaseManager::optimizeTables()
{
	Database* db = Database::getInstance();
	std::ostringstream query;

	query << "SELECT `TABLE_NAME` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = " << db->escapeString(g_config.getString(ConfigManager::MYSQL_DB)) << " AND `DATA_FREE` > 0";
	DBResult* result = db->storeQuery(query.str());
	if (!result) {
		return false;
	}

	do {
		std::string tableName = result->getDataString("TABLE_NAME");
		std::cout << "> Optimizing table " << tableName << "..." << std::flush;

		query.str("");
		query << "OPTIMIZE TABLE `" << tableName << '`';

		if (db->executeQuery(query.str())) {
			std::cout << " [success]" << std::endl;
		} else {
			std::cout << " [failed]" << std::endl;
		}
	} while (result->next());
	db->freeResult(result);
	return true;
}
Esempio n. 18
0
bool BanManager::isIpBanished(uint32_t clientip, uint32_t mask /*= 0xFFFFFFFF*/) const
{
	if(clientip == 0) return false;
	Database* db = Database::instance();

	DBQuery query;
	query <<
		"SELECT "
			"COUNT(*) AS `count` "
		"FROM "
			"`bans` "
		"WHERE "
			"`type` = " << BAN_IPADDRESS << " AND "
			"((" << clientip << " & " << mask << " & `param`) = (`value` & `param` & " << mask << ")) AND "
			"`active` = 1 AND "
			"(`expires` >= " << std::time(NULL) << " OR `expires` <= 0)";

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

	int t = result->getDataInt("count");
	db->freeResult(result);
	return t > 0;
}
Esempio n. 19
0
int API_resultRowEnd(void *result, void *opt)
{
    DBResult *res = (DBResult *) result;
    mysql *db = (mysql *) opt;

    res->endRow();

    return 1;
}
Esempio n. 20
0
MarketOfferList IOMarket::getActiveOffers(MarketAction_t action, uint16_t itemId)
{
	Database* db = Database::getInstance();
	DBQuery query;
	query << "SELECT `id`, `player_id`, `amount`, `price`, `created`, `anonymous` FROM `market_offers` WHERE `sale` = "
		<< action << " AND `itemtype` = " << itemId << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << ";";

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

	MarketOfferList offerList;
	do
	{
		MarketOffer offer;
		offer.amount = result->getDataInt("amount");
		offer.price = result->getDataInt("price");
		offer.timestamp = result->getDataInt("created") + g_config.getNumber(ConfigManager::MARKET_OFFER_DURATION);
		offer.counter = result->getDataInt("id") & 0xFFFF;

		if(!result->getDataInt("anonymous"))
		{
			IOLoginData::getInstance()->getNameByGuid(result->getDataInt("player_id"), offer.playerName);
			if(offer.playerName.empty())
				offer.playerName = "Anonymous";
		}
		else
			offer.playerName = "Anonymous";

		offerList.push_back(offer);
	}
	while(result->next());
	result->free();
	return offerList;
}
Esempio n. 21
0
MarketOfferEx IOMarket::getOfferById(uint32_t id)
{
	MarketOfferEx offer;
	std::ostringstream query;
	query << "SELECT `id`, `sale`, `itemtype`, `amount`, `created`, `price`, `player_id`, `anonymous` FROM `market_offers` WHERE `id` = " << id;
	Database* db = Database::getInstance();

	DBResult* result = db->storeQuery(query.str());
	if (result) {
		offer.type = (MarketAction_t)result->getDataInt("sale");
		offer.amount = result->getDataInt("amount");
		offer.counter = result->getDataInt("id") & 0xFFFF;
		offer.timestamp = result->getDataInt("created");
		offer.price = result->getDataInt("price");
		offer.itemId = result->getDataInt("itemtype");

		int32_t playerId = result->getDataInt("player_id");
		offer.playerId = playerId;

		if (result->getDataInt("anonymous") == 0) {
			IOLoginData::getInstance()->getNameByGuid(playerId, offer.playerName);

			if (offer.playerName.empty()) {
				offer.playerName = "Anonymous";
			}
		} else {
			offer.playerName = "Anonymous";
		}

		db->freeResult(result);
	}

	return offer;
}
Esempio n. 22
0
DatabaseMySQL::DatabaseMySQL() :
	m_timeoutTask(0)
{
	m_connected = false;
	if(!mysql_init(&m_handle))
	{
		std::clog << std::endl << "Failed to initialize MySQL connection handler." << std::endl;
		return;
	}

	uint32_t timeout = g_config.getNumber(ConfigManager::MYSQL_READ_TIMEOUT);
	if(timeout)
		mysql_options(&m_handle, MYSQL_OPT_READ_TIMEOUT, (const char*)&timeout);

	timeout = g_config.getNumber(ConfigManager::MYSQL_WRITE_TIMEOUT);
	if(timeout)
		mysql_options(&m_handle, MYSQL_OPT_WRITE_TIMEOUT, (const char*)&timeout);

	my_bool reconnect = true;
	mysql_options(&m_handle, MYSQL_OPT_RECONNECT, &reconnect);
	if(!mysql_real_connect(&m_handle, g_config.getString(ConfigManager::SQL_HOST).c_str(), g_config.getString(
		ConfigManager::SQL_USER).c_str(), g_config.getString(ConfigManager::SQL_PASS).c_str(), g_config.getString(
		ConfigManager::SQL_DB).c_str(), g_config.getNumber(ConfigManager::SQL_PORT), NULL, 0))
	{
		std::clog << "Failed connecting to database - MYSQL ERROR: " << mysql_error(&m_handle) << " (" << mysql_errno(&m_handle) << ")" << std::endl;
		return;
	}

	m_connected = true;
	if(mysql_get_client_version() <= 50019)
		//MySQL servers <= 5.0.19 have a bug where MYSQL_OPT_RECONNECT option is reset by mysql_real_connect calls.
		//Read this http://dev.mysql.com/doc/refman/5.0/en/mysql-options.html for more information.
		std::clog << std::endl << "> WARNING: Outdated MySQL server detected, consider upgrading to a newer version." << std::endl;

	timeout = g_config.getNumber(ConfigManager::SQL_KEEPALIVE) * 1000;
	if(timeout)
		m_timeoutTask = Scheduler::getInstance().addEvent(createSchedulerTask(timeout,
			boost::bind(&DatabaseMySQL::keepAlive, this)));

	if(!g_config.getBool(ConfigManager::HOUSE_STORAGE))
		return;

	//we cannot lock mutex here :)
	DBResult* result = storeQuery("SHOW variables LIKE 'max_allowed_packet';");
	if(!result)
		return;

	if(result->getDataLong("Value") < 16776192)
		std::clog << std::endl << "> WARNING: max_allowed_packet might be set too low for binary map storage." << std::endl
			<< "Use the following query to raise max_allow_packet: SET GLOBAL max_allowed_packet = 16776192;" << std::endl;

	result->free();
}
Esempio n. 23
0
DatabaseMySQL::DatabaseMySQL()
{
	m_connected = false;

	// connection handle initialization
	if(!mysql_init(&m_handle))
	{
		std::cout << std::endl << "Failed to initialize MySQL connection handle." << std::endl;
		return;
	}

	// automatic reconnect
	my_bool reconnect = true;
	mysql_options(&m_handle, MYSQL_OPT_RECONNECT, &reconnect);

	// connects to database
	if(!mysql_real_connect(&m_handle, g_config.getString(ConfigManager::MYSQL_HOST).c_str(), g_config.getString(ConfigManager::MYSQL_USER).c_str(), g_config.getString(ConfigManager::MYSQL_PASS).c_str(), g_config.getString(ConfigManager::MYSQL_DB).c_str(), g_config.getNumber(ConfigManager::SQL_PORT), NULL, 0))
	{
		std::cout << "Failed to connect to database. MYSQL ERROR: " << mysql_error(&m_handle) << std::endl;
		return;
	}

	if(MYSQL_VERSION_ID < 50019)
	{
		//mySQL servers < 5.0.19 has a bug where MYSQL_OPT_RECONNECT is (incorrectly) reset by mysql_real_connect calls
		//See http://dev.mysql.com/doc/refman/5.0/en/mysql-options.html for more information.
		mysql_options(&m_handle, MYSQL_OPT_RECONNECT, &reconnect);
		std::cout << std::endl << "[Warning] Outdated mySQL server detected. Consider upgrading to a newer version." << std::endl;
	}

	m_connected = true;

	if(g_config.getString(ConfigManager::MAP_STORAGE_TYPE) == "binary")
	{
		DBQuery query;
		query << "SHOW variables LIKE 'max_allowed_packet';";

		DBResult* result;
		if((result = storeQuery(query.str())))
		{
			int32_t max_query = result->getDataInt("Value");
			freeResult(result);

			if(max_query < 16777216)
			{
				std::cout << std::endl << "[Warning] max_allowed_packet might be set too low for binary map storage." << std::endl;
				std::cout << "Use the following query to raise max_allow_packet: ";
				std::cout << "SET GLOBAL max_allowed_packet = 16777216;";
			}
		}
	}
}
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);
}
Esempio n. 25
0
bool DatabaseManager::getDatabaseConfig(const std::string& config, std::string& value)
{
	Database* db = Database::getInstance();
	DBQuery query;
	query << "SELECT `value` FROM `server_config` WHERE `config` = " << db->escapeString(config) << ";";
	DBResult* result = db->storeQuery(query.str());
	if(!result)
		return false;

	value = result->getDataString("value");
	db->freeResult(result);
	return true;
}
Esempio n. 26
0
bool IOGuild::guildExists(uint32_t guild)
{
	Database* db = Database::getInstance();
	DBResult* result;

	DBQuery query;
	query << "SELECT `id` FROM `guilds` WHERE `id` = " << guild << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " LIMIT 1";
	if(!(result = db->storeQuery(query.str())))
		return false;

	result->free();
	return true;
}
Esempio n. 27
0
bool IOGuild::isInvited(uint32_t guild, uint32_t guid)
{
	Database* db = Database::getInstance();
	DBResult* result;

	DBQuery query;
	query << "SELECT `guild_id` FROM `guild_invites` WHERE `player_id` = " << guid << " AND `guild_id`= " << guild << " LIMIT 1";
	if(!(result = db->storeQuery(query.str())))
		return false;

	result->free();
	return true;
}
Esempio n. 28
0
bool IOPlayer::getGuildIdByName(uint32_t &guildId, const std::string& guildName)
{
	Database* db = Database::instance();
	DBResult* result;
	DBQuery query;

	if(!(result = db->storeQuery("SELECT `id` FROM `guilds` WHERE `name` = " + db->escapeString(guildName))))
		return false;

	guildId = result->getDataInt("id");
	db->freeResult(result);
	return true;
}
Esempio n. 29
0
bool House::isBidded() const
{
	Database* db = Database::getInstance();
	DBResult* result;

	DBQuery query;
	query << "SELECT `house_id` FROM `house_auctions` WHERE `house_id` = " << id << " LIMIT 1";
	if(!(result = db->storeQuery(query.str())))
		return false;

	result->free();
	return true;
}
Esempio n. 30
0
uint32_t IOPlayer::getLastIP(std::string name) const
{
	Database* db = Database::instance();
	DBResult* result;
	DBQuery query;

	if(!(result = db->storeQuery("SELECT `lastip` FROM `players` WHERE `name`= " + db->escapeString(name))))
		return 0;

	uint32_t lastip = result->getDataInt("lastip");
	db->freeResult(result);
	return lastip;
}