Example #1
0
/*==========================================
 * 傭兵作成
 *------------------------------------------
 */
bool mercdb_sql_new(struct mmo_mercstatus *p)
{
	bool result;
	struct mmo_mercstatus *p2;

	nullpo_retr(false, p);

	result = sqldbs_query(&mysql_handle,
		"INSERT INTO `" MERC_TABLE "` (`class`,`account_id`,`char_id`,`hp`,`sp`,`kill_count`,`limit`) "
		"VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%u')",
		p->class_, p->account_id, p->char_id, p->hp, p->sp, p->kill_count, p->limit
	);
	if(result == false) {
		p->merc_id = -1;
		return false;
	}

	p->merc_id = (int)sqldbs_insert_id(&mysql_handle);

	p2 = (struct mmo_mercstatus*)aMalloc(sizeof(struct mmo_mercstatus));
	memcpy(p2, p, sizeof(struct mmo_mercstatus));
	numdb_insert(merc_db, p->merc_id, p2);

	return true;
}
Example #2
0
/*==========================================
 * ホム作成
 *------------------------------------------
 */
bool homundb_sql_new(struct mmo_homunstatus *p)
{
	bool result = false;

	nullpo_retr(false, p);

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

	// try
	do {
		int i;
		char t_name[64];

		if( sqldbs_query(&mysql_handle,
			"INSERT INTO `" HOMUN_TABLE "` (`class`,`name`,`account_id`,`char_id`,`base_level`,`base_exp`,"
			"`max_hp`,`hp`,`max_sp`,`sp`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,"
			"`f_str`,`f_agi`,`f_vit`,`f_int`,`f_dex`,`f_luk`,"
			"`status_point`,`skill_point`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`) "
			"VALUES ('%d', '%s', '%d', '%d',"
			"'%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d',"
			"'%d', '%d', '%d', '%d', '%d', '%d',"
			"'%d', '%d', '%d', '%d', '%d', '%d', '%d')",
			p->class_, strecpy(t_name, p->name), p->account_id, p->char_id, p->base_level,
			p->base_exp, p->max_hp, p->hp, p->max_sp, p->sp, p->str, p->agi, p->vit, p->int_, p->dex, p->luk,
			p->f_str, p->f_agi, p->f_vit, p->f_int, p->f_dex, p->f_luk,
			p->status_point, p->skill_point, p->equip, p->intimate,
			p->hungry, p->rename_flag, p->incubate
		) == false ) {
			p->homun_id = -1;
			break;
		}

		p->homun_id = (int)sqldbs_insert_id(&mysql_handle);

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

		// success
		result = true;

		{
			// cache copy
			struct mmo_homunstatus *p2 = (struct mmo_homunstatus*)aMalloc(sizeof(struct mmo_homunstatus));
			memcpy(p2, p, sizeof(struct mmo_homunstatus));
			numdb_insert(homun_db, p->homun_id, p2);
		}
	} while(0);

	sqldbs_transaction_end(&mysql_handle, result);

	return true;
}