コード例 #1
0
ファイル: rosql.cpp プロジェクト: srdgame/srdgame
bool RoSql::load_account(int id, UserInfoEx<RoUser>& info)
{
	// TODO: Specify the columns. "SELECT `account_id`,`userid`,`user_pass`,`sex`,`email`,`level`,`state`,`unban_time`,`expiration_time`,`logincount`,`lastlogin`,`last_ip` FROM `%s` WHERE `account_id` = %d",
	//
	std::string sql = "SELECT * FROM `%s` WHERE `account_id`= '%s'";

	QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(),
		RO_ACCOUNT_TB, MAKE_STRING(id));
	if (res->get_row_size() != 1)
	{
		res->Delete();
		_LogDebug_(LN, "No account with id : %d ", id);
		return false;
	}
	Field* field = res->fetch();
	if (field)
	{
		if (res->get_field_size() != 12)
		{
			LogError(LN, "Incorrect result has been queried out!!!!!!!!!!");
			res->Delete();
			return false;
		}
		fetch_account_info(field, info);
	}
	res->Delete();
	return true;
}
コード例 #2
0
ファイル: roitemdb.cpp プロジェクト: srdgame/srdgame
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;
}
コード例 #3
0
ファイル: rosql.cpp プロジェクト: srdgame/srdgame
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;
}
コード例 #4
0
ファイル: rosql.cpp プロジェクト: srdgame/srdgame
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;
}
コード例 #5
0
ファイル: rosql.cpp プロジェクト: srdgame/srdgame
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;
}
コード例 #6
0
ファイル: rosql.cpp プロジェクト: srdgame/srdgame
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;
}
コード例 #7
0
ファイル: rosql.cpp プロジェクト: srdgame/srdgame
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;
}
コード例 #8
0
ファイル: rosql.cpp プロジェクト: srdgame/srdgame
int RoSql::get_max_char_id()
{
	std::string sql = "SELECT MAX(`char_id`)+1 FROM `%s`";

	QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(),
			RO_CHAR_TB);
	if (res == NULL)
	{
		_LogDebug_(LN, "NO result when select max char_id");
		return 1000;
	}
	
	Field* f = res->fetch();
	if (f == NULL)
	{
		res->Delete();
		return 1000;
	}

	int max = f[0].get<int>();
	if (max < 1000)
		max = 1000;
	_LogDebug_(LN, "Max char_id is %d", max);
	res->Delete();
	return max;

}
コード例 #9
0
ファイル: rosql.cpp プロジェクト: srdgame/srdgame
bool RoSql::load_account(const char* name, UserInfoEx<RoUser>& info)
{
	_LogDebug_(LN, "Starting to select from DB...................");
	std::string sql = "SELECT `account_id` FROM `%s` WHERE `userid`= %s '%s'";

	QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(),
		RO_ACCOUNT_TB, "BINARY", name);
	if (!res || res->get_row_size() != 1)
	{
		if (res)
			res->Delete();
		_LogDebug_(LN, "No account with name : %s ", name);
		return false;
	}
	Field* field = res->fetch();
	if (field)
	{
		long id = field->get<long>();
		bool result =  load_account(id, info);
		res->Delete();
		return result;
	}
	res->Delete();
	return false;
}
コード例 #10
0
ファイル: rosql.cpp プロジェクト: srdgame/srdgame
int RoSql::get_max_id()
{
	std::string sql = "SELECT MAX(`account_id`)+1 FROM `%s`";

	QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(),
			RO_ACCOUNT_TB);
	if (res == NULL)
	{
		return 1000;
	}
	
	Field* f = res->fetch();
	if (f == NULL)
	{
		res->Delete();
		return 1000;
	}

	int max = f[0].get<int>();
	res->Delete();
	return max;
}
コード例 #11
0
ファイル: rosql.cpp プロジェクト: srdgame/srdgame
bool RoSql::load_char(int char_id, RoCharInfo& info, bool load_everything)
{
	info._id = char_id;
	std::string sql = "SELECT `account_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`,`party_id`,`guild_id`,`pet_id`,`homun_id`,`hair`,`hair_color`,`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`,`last_map`,`last_x`,`last_y`,`save_map`,`save_x`,`save_y`,`partner_id`,`father`,`mother`,`child`,`fame` FROM `%s` WHERE `char_id`=%d LIMIT 1";
	QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(),
			RO_CHAR_TB, char_id);
	if (!res)
	{
		//_LogDebug_("RO_SQL", "Failed to query!!!!!!!!!!!!!");
		return false;
	}

	size_t count = res->get_row_size();
	if (count != 1)
	{
		//_LogDebug_("RO_SQL", "count is not one, means no invald data");
		res->Delete();
		return false;
	}
	Field * f = res->fetch();
	if (!f)
	{
		//_LogDebug_("RO_SQL", "No data fields~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
		res->Delete();
		return false;
	}
	fetch_char_info(f, info);
	res->Delete();
	if (!load_everything)
	{
		return true;
	}

	// Or we will load other stuff
	// Load memory data.
	
	// load items.
	if (!load_items(char_id, info._items))
		return false;

	// Load cart
	if (!load_cart(char_id, info._carts))
		return false;

	// load storage
	
	// load skill
	if (!load_skill(char_id, info._skills))
		return false;

	// load friends
	if (!load_friends(char_id, info._friends))
		return false;

	// load hotkey
	if (!load_hotkey(char_id, info._hotkeys))
		return false;

	// We are ok here.
	return true;
}