Ejemplo n.º 1
0
/*==========================================
 * セーブ
 *------------------------------------------
 */
bool mercdb_sql_save(struct mmo_mercstatus *p2)
{
	char sep = ' ';
	char tmp_sql[65536];
	char *p = tmp_sql;
	const struct mmo_mercstatus *p1;
	bool result = false;

	nullpo_retr(false, p2);

	p1 = mercdb_sql_load(p2->merc_id);
	if(p1 == NULL)
		return false;

	strcpy(p, "UPDATE `" MERC_TABLE "` SET");
	p += strlen(p);

	UPDATE_NUM(class_     ,"class");
	UPDATE_NUM(account_id ,"account_id");
	UPDATE_NUM(char_id    ,"char_id");
	UPDATE_NUM(hp         ,"hp");
	UPDATE_NUM(sp         ,"sp");
	UPDATE_NUM(kill_count ,"kill_count");
	UPDATE_UNUM(limit     ,"limit");

	if( sqldbs_transaction_start(&mysql_handle) == false )
		return false;

	// try
	do {
		if(sep == ',') {
			sprintf(p, " WHERE `merc_id` = '%d'",p2->merc_id);
			if( sqldbs_simplequery(&mysql_handle, tmp_sql) == false )
				break;
		}

		// success
		result = true;

		{
			// cache copy
			struct mmo_mercstatus *p3 = (struct mmo_mercstatus *)numdb_search(merc_db, p2->merc_id);
			if(p3)
				memcpy(p3, p2, sizeof(struct mmo_mercstatus));
		}
	} while(0);

	sqldbs_transaction_end(&mysql_handle, result);

	return result;
}
Ejemplo n.º 2
0
/*==========================================
 * セーブ
 *------------------------------------------
 */
bool homundb_sql_save(struct mmo_homunstatus *p2)
{
	const struct mmo_homunstatus *p1;
	char buf[64], tmp_sql[65536];
	char sep = ' ';
	char *p = tmp_sql;
	bool result = false;

	nullpo_retr(false, p2);

	p1 = homundb_sql_load(p2->homun_id);
	if(p1 == NULL)
		return 0;

	strcpy(p, "UPDATE `" HOMUN_TABLE "` SET");
	p += strlen(p);

	UPDATE_NUM(class_      ,"class");
	UPDATE_STR(name        ,"name");
	UPDATE_NUM(account_id  ,"account_id");
	UPDATE_NUM(char_id     ,"char_id");
	UPDATE_NUM(base_level  ,"base_level");
	UPDATE_NUM(base_exp    ,"base_exp");
	UPDATE_NUM(max_hp      ,"max_hp");
	UPDATE_NUM(hp          ,"hp");
	UPDATE_NUM(max_sp      ,"max_sp");
	UPDATE_NUM(sp          ,"sp");
	UPDATE_NUM(str         ,"str");
	UPDATE_NUM(agi         ,"agi");
	UPDATE_NUM(vit         ,"vit");
	UPDATE_NUM(int_        ,"int");
	UPDATE_NUM(dex         ,"dex");
	UPDATE_NUM(luk         ,"luk");
	UPDATE_NUM(f_str       ,"f_str");
	UPDATE_NUM(f_agi       ,"f_agi");
	UPDATE_NUM(f_vit       ,"f_vit");
	UPDATE_NUM(f_int       ,"f_int");
	UPDATE_NUM(f_dex       ,"f_dex");
	UPDATE_NUM(f_luk       ,"f_luk");
	UPDATE_NUM(status_point,"status_point");
	UPDATE_NUM(skill_point ,"skill_point");
	UPDATE_NUM(equip       ,"equip");
	UPDATE_NUM(intimate    ,"intimate");
	UPDATE_NUM(hungry      ,"hungry");
	UPDATE_NUM(rename_flag ,"rename_flag");
	UPDATE_NUM(incubate    ,"incubate");

	if( sqldbs_transaction_start(&mysql_handle) == false )
		return false;

	// try
	do {
		if(sep == ',') {
			sprintf(p, " WHERE `homun_id` = '%d'", p2->homun_id);
			if( sqldbs_simplequery(&mysql_handle, tmp_sql) == false )
				break;
		}

		if(memcmp(p1->skill, p2->skill, sizeof(p1->skill)) ) {
			int i;

			if( sqldbs_query(&mysql_handle, "DELETE FROM `" HOMUN_SKILL_TABLE "` WHERE `homun_id`='%d'", p2->homun_id) == false )
				break;

			for(i = 0; i < MAX_HOMSKILL; i++) {
				if(p2->skill[i].id && p2->skill[i].flag != 1) {
					int lv = (p2->skill[i].flag == 0)? p2->skill[i].lv: p2->skill[i].flag - 2;
					if( sqldbs_query(&mysql_handle,
						"INSERT INTO `" HOMUN_SKILL_TABLE "` (`homun_id`,`id`,`lv`) VALUES ('%d','%d','%d')",
						p2->homun_id, p2->skill[i].id, lv
					) == false )
						break;
				}
			}
			if(i != MAX_HOMSKILL)
				break;
		}

		// success
		result = true;

		{
			// cache copy
			struct mmo_homunstatus *p3 = (struct mmo_homunstatus *)numdb_search(homun_db, p2->homun_id);
			if(p3)
				memcpy(p3, p2, sizeof(struct mmo_homunstatus));
		}
	} while(0);

	sqldbs_transaction_end(&mysql_handle, result);

	return result;
}