Ejemplo n.º 1
0
void RoItemDB::init(short max_id)
{
	if (_inited)
		return;

	_inited = true;
	_max_id = max_id;
	_items = new RoDBItem[_max_id];
	
	// Do it for ourself.
	string sql = "SELECT `id`,`name_english`,`type`,`price_buy`,`price_sell`,`weight`,`attack`,`defence`,`range`,`slots`,`equip_jobs`,`equip_upper`,`equip_genders`,`equip_locations`,`weapon_level`,`equip_level`,`refineable`,`view` FROM `%s`";
	QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(),
			RO_ITEM_DB_TB);
	if (!res)
	{
		LogError("RO_ITEM_DB", "Empty item db");
		return;
	}
	size_t count = res->get_row_size();
	size_t i = 0;
	for (; i < count; ++i)
	{
		Field* f = res->fetch();
		if (!fetch_item(f))
			break;
		res->next();
	}
	LogSuccess("RO_ITEM_DB", "%d items has been loaded!!", i);
	res->Delete();
	return;
}
Ejemplo n.º 2
0
bool RoSql::load_hotkey(int char_id, std::vector<RoCharHotKey>& keys)
{
	keys.clear();

	string sql = "SELECT `hotkey`, `type`, `itemskill_id`, `skill_lvl` FROM `%s` WHERE `char_id`=%d LIMIT %d";
	QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(), RO_HOTKEY_TB, char_id, MaxHotKeyCount);

	if (res == NULL)
		return true;;

	size_t count = res->get_row_size();
	for (size_t n = 0; n < count; ++n)
	{
		Field* f = res->fetch();
		RoCharHotKey key;
		key._id = f[0].get<int>();
		key._type = f[1].get<uint16>();
		key._lvl = f[2].get<uint16>();

		keys.push_back(key);
		res->next();
	}
	res->Delete();

	return true;
}
Ejemplo n.º 3
0
bool RoSql::load_friends(int char_id, std::vector<RoCharFriendInfo>& friends)
{
	friends.clear();

	string sql = "SELECT c.`account_id`, c.`char_id`, c.`name` FROM `%s` c LEFT JOIN `%s` f ON f.`friend_account` = c.`account_id` AND f.`friend_id` = c.`char_id` WHERE f.`char_id`=%d LIMIT %d";
	QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(), RO_CHAR_TB, RO_FRIEND_TB, char_id, MaxFriendCount);

	if (res == NULL)
		return true;

	size_t count = res->get_row_size();
	for (size_t n = 0; n < count; ++n)
	{
		Field* f = res->fetch();
		RoCharFriendInfo fr;
		fr._account_id = f[0].get<int>();
		fr._char_id = f[1].get<int>();
		fr._name = f[2].get<string>();
		fr._nick_name = f[2].get<string>();

		friends.push_back(fr);
		res->next();
	}
	res->Delete();
	return true;
}
Ejemplo n.º 4
0
bool RoSql::load_skill(int char_id, std::vector<RoCharSkillInfo>& skills)
{
	skills.clear();

	string sql = "SELECT `id`, `lv` FROM `%s` WHERE `char_id`=%d LIMIT %d";
	QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(), RO_SKILL_TB, char_id, MaxSkillCount);

	if (res == NULL)
		return true;

	size_t count = res->get_row_size();
	for (size_t n = 0; n < count; ++n)
	{
		Field* f = res->fetch();
		RoCharSkillInfo skill;
		skill._id = f[0].get<int>();
		skill._lvl = f[1].get<int>();
		skill._flag = f[2].get<int>();

		skills.push_back(skill);
		res->next();
	}
	res->Delete();

	return true;
}
Ejemplo n.º 5
0
bool RoSql::load_cart(int char_id, std::vector<RoCharItem>& cart_items)
{
	cart_items.clear();

	string sql = "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`";
	for (int i = 0; i <MaxSlotCount; ++i)
		sql += ", `card" + conversion_cast<string>(i) + "`";
	sql += " FROM `%s` WHERE `char_id`=%d LIMIT %d";
	QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(), RO_CART_TB, char_id, MaxCartCount);

	if (res == NULL)
		return true;

	size_t count = res->get_row_size();
	for (size_t n = 0; n < count; ++n)
	{
		Field* f = res->fetch();
		RoCharItem info;
		info._id = f[0].get<int>();
		info._type = f[1].get<short>();
		info._amount = f[2].get<short>();
		info._equip = f[3].get<uint16>();
		info._identify = f[4].get<char>();
		info._refine = f[5].get<char>();
		info._attrs = f[6].get<char>();
		info._expire_time = f[7].get<unsigned int>();
		cart_items.push_back(info);
		res->next();
	}
	res->Delete();

	return true;
}
Ejemplo n.º 6
0
size_t RoSql::load_chars(int account_id, RoCharInfoBase*& result)
{
	std::string sql = "SELECT `char_id`,`char_num`,`name`,`class`,`base_level`,`job_level`,`base_exp`,`job_exp`,`zeny`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`max_hp`,`hp`,`max_sp`,`sp`,`status_point`,`skill_point`,`option`,`karma`,`manner`,`hair`,`hair_color`,`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom` FROM `%s` WHERE `account_id`='%d'";
	QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(),
			RO_CHAR_TB, account_id);
	if (!res)
		return 0;

	size_t count = res->get_row_size();
	if (count == 0)
	{
		res->Delete();
		return 0;
	}
	result = new RoCharInfoBase[count];

	size_t i = 0;
	for (; i < count; ++i)
	{
		Field* f = res->fetch();
		if (!f)
			break;
		RoCharInfoBase* info =result + i;
		info->_account_id = account_id;
		if (!fetch_chars_info(f, *info))
			break;
		res->next();
	}
	res->Delete();
	return i;
}