Esempio n. 1
0
/*==========================================
 * キャラIDからクエストデータを取得
 *------------------------------------------
 */
const struct quest *questdb_sql_load(int char_id)
{
	bool result = false;
	struct quest *q = (struct quest *)numdb_search(quest_db, char_id);

	if(q && q->char_id == char_id) {
		// 既にキャッシュが存在する
		return q;
	}
	if(q == NULL) {
		q = (struct quest *)aMalloc(sizeof(struct quest));
		numdb_insert(quest_db, char_id, q);
	}
	memset(q, 0, sizeof(struct quest));

	q->char_id = char_id;

	result = sqldbs_query(&mysql_handle,
		"SELECT `account_id`,`nameid`,`state`,`limit`,`mobid1`,`mobmax1`,`mobcnt1`,`mobid2`,`mobmax2`,`mobcnt2`,`mobid3`,`mobmax3`,`mobcnt3` "
		"FROM `" QUEST_TABLE "` WHERE `char_id`='%d'", char_id
	);
	if(result == false) {
		q->char_id = -1;
		return NULL;
	}

	if(sqldbs_num_rows(&mysql_handle) > 0) {
		int i;
		char **sql_row;

		for(i = 0; (sql_row = sqldbs_fetch(&mysql_handle)) && i < MAX_QUESTLIST; i++) {
			if(q->account_id == 0) {
				q->account_id = atoi(sql_row[0]);
			}
			q->data[i].nameid     = atoi(sql_row[1]);
			q->data[i].state      = (char)atoi(sql_row[2]);
			q->data[i].limit      = (unsigned int)atoi(sql_row[3]);
			q->data[i].mob[0].id  = (short)atoi(sql_row[4]);
			q->data[i].mob[0].max = (short)atoi(sql_row[5]);
			q->data[i].mob[0].cnt = (short)atoi(sql_row[6]);
			q->data[i].mob[1].id  = (short)atoi(sql_row[7]);
			q->data[i].mob[1].max = (short)atoi(sql_row[8]);
			q->data[i].mob[1].cnt = (short)atoi(sql_row[9]);
			q->data[i].mob[2].id  = (short)atoi(sql_row[10]);
			q->data[i].mob[2].max = (short)atoi(sql_row[11]);
			q->data[i].mob[2].cnt = (short)atoi(sql_row[12]);
		}
		q->count = (i < MAX_QUESTLIST)? i: MAX_QUESTLIST;
	} else {
		// 見つからなくても正常
		q = NULL;
	}
	sqldbs_free_result(&mysql_handle);

	return q;
}
Esempio n. 2
0
/*==========================================
 * 傭兵IDから傭兵データをロード
 *------------------------------------------
 */
const struct mmo_mercstatus* mercdb_sql_load(int merc_id)
{
	char **sql_row;
	struct mmo_mercstatus *p = (struct mmo_mercstatus *)numdb_search(merc_db, merc_id);

	if(p && p->merc_id == merc_id) {
		return p;
	}
	if(p == NULL) {
		p = (struct mmo_mercstatus *)aMalloc(sizeof(struct mmo_mercstatus));
		numdb_insert(merc_db, merc_id, p);
	}
	memset(p, 0, sizeof(struct mmo_mercstatus));

	if( sqldbs_query(&mysql_handle, "SELECT `class`,`account_id`,`char_id`,`hp`,`sp`,`kill_count`,`limit` FROM `" MERC_TABLE "` WHERE `merc_id`='%d'", merc_id) == false )
	{
		p->merc_id = -1;
		return NULL;
	}

	if((sql_row = sqldbs_fetch(&mysql_handle)) != NULL) {
		p->merc_id    = merc_id;
		p->class_     = atoi(sql_row[0]);
		p->account_id = atoi(sql_row[1]);
		p->char_id    = atoi(sql_row[2]);
		p->hp         = atoi(sql_row[3]);
		p->sp         = atoi(sql_row[4]);
		p->kill_count = atoi(sql_row[5]);
		p->limit      = (unsigned int)atoi(sql_row[6]);
	} else {
		p->merc_id = -1;
		p = NULL;
	}
	sqldbs_free_result(&mysql_handle);

	return p;
}
Esempio n. 3
0
/*==========================================
 * ホムIDからホムデータのロード
 *------------------------------------------
 */
const struct mmo_homunstatus* homundb_sql_load(int homun_id)
{
	int i;
	char **sql_row;
	bool result = false;
	struct mmo_homunstatus *p = (struct mmo_homunstatus *)numdb_search(homun_db, homun_id);

	if(p && p->homun_id == homun_id) {
		return p;
	}
	if(p == NULL) {
		p = (struct mmo_homunstatus *)aMalloc(sizeof(struct mmo_homunstatus));
		numdb_insert(homun_db, homun_id, p);
	}
	memset(p, 0, sizeof(struct mmo_homunstatus));

	result = sqldbs_query(&mysql_handle,
		"SELECT `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` "
		"FROM `" HOMUN_TABLE "` WHERE `homun_id`='%d'",
		homun_id
	);
	if(result == false) {
		p->homun_id = -1;
		return NULL;
	}

	if((sql_row = sqldbs_fetch(&mysql_handle)) != NULL) {
		p->homun_id     = homun_id;
		p->class_       = atoi(sql_row[0]);
		strncpy(p->name, sql_row[1], 24);
		p->name[23] = '\0';	// force \0 terminal
		p->account_id   = atoi(sql_row[2]);
		p->char_id      = atoi(sql_row[3]);
		p->base_level   = atoi(sql_row[4]);
		p->base_exp     = atoi(sql_row[5]);
		p->max_hp       = atoi(sql_row[6]);
		p->hp           = atoi(sql_row[7]);
		p->max_sp       = atoi(sql_row[8]);
		p->sp           = atoi(sql_row[9]);
		p->str          = atoi(sql_row[10]);
		p->agi          = atoi(sql_row[11]);
		p->vit          = atoi(sql_row[12]);
		p->int_         = atoi(sql_row[13]);
		p->dex          = atoi(sql_row[14]);
		p->luk          = atoi(sql_row[15]);
		p->f_str        = atoi(sql_row[16]);
		p->f_agi        = atoi(sql_row[17]);
		p->f_vit        = atoi(sql_row[18]);
		p->f_int        = atoi(sql_row[19]);
		p->f_dex        = atoi(sql_row[20]);
		p->f_luk        = atoi(sql_row[21]);
		p->status_point = atoi(sql_row[22]);
		p->skill_point  = atoi(sql_row[23]);
		p->equip        = atoi(sql_row[24]);
		p->intimate     = atoi(sql_row[25]);
		p->hungry       = atoi(sql_row[26]);
		p->rename_flag  = atoi(sql_row[27]);
		p->incubate     = atoi(sql_row[28]);
	} else {
		p->homun_id = -1;
		sqldbs_free_result(&mysql_handle);
		return NULL;
	}
	sqldbs_free_result(&mysql_handle);

	result = sqldbs_query(&mysql_handle, "SELECT `id`,`lv` FROM `" HOMUN_SKILL_TABLE "` WHERE `homun_id`='%d'", homun_id);
	if(result == false) {
		p->homun_id = -1;
		return NULL;
	}

	for(i = 0; (sql_row = sqldbs_fetch(&mysql_handle)) && i < MAX_HOMSKILL; i++) {
		int id = atoi(sql_row[0]);
		if(id < HOM_SKILLID || id >= MAX_HOM_SKILLID) {
			// DB操作して変なスキルを覚えさせられる可能性があるのでチェック
			printf("homundb_sql_load: invaild skill id: %d\n", id);
		} else {
			p->skill[id-HOM_SKILLID].id = id;
			p->skill[id-HOM_SKILLID].lv = atoi(sql_row[1]);
		}
	}
	sqldbs_free_result(&mysql_handle);

	p->option = 0;
	if(p->hungry < 0)
		p->hungry = 0;
	else if(p->hungry > 100)
		p->hungry = 100;
	if(p->intimate < 0)
		p->intimate = 0;
	else if(p->intimate > 100000)
		p->intimate = 100000;

	return p;
}