Ejemplo n.º 1
0
/*==========================================
 * ホム削除
 *------------------------------------------
 */
bool homundb_sql_delete(int homun_id)
{
	bool result = false;

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

	// try
	do
	{
		// delete homun
		if( sqldbs_query(&mysql_handle, "DELETE FROM `" HOMUN_TABLE "` WHERE `homun_id`='%d'", homun_id) == false )
			break;

		// delete homun skill
		if( sqldbs_query(&mysql_handle, "DELETE FROM `" HOMUN_SKILL_TABLE "` WHERE `homun_id`='%d'", homun_id) == false )
			break;

		// success
		result = true;

		{
			// cache delete
			struct mmo_homunstatus *p = (struct mmo_homunstatus *)numdb_erase(homun_db, homun_id);
			if(p) {
				aFree(p);
			}
		}
	} while(0);

	sqldbs_transaction_end(&mysql_handle, result);

	return result;
}
Ejemplo n.º 2
0
/*==========================================
 * セーブ
 *------------------------------------------
 */
bool questdb_sql_save(struct quest *q2)
{
	const struct quest *q1;
	bool result = false;

	nullpo_retr(false, q2);

	q1 = questdb_sql_load(q2->char_id);

	if(q1 && q1->count <= 0 && q2->count <= 0) {
		// データが共に0個なので何もしない
		return true;
	}

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

	// try
	do {
		int i;

		if(q1 == NULL || q1->count > 0) {
			// データサーバ側にデータがあるときだけ削除クエリを発行
			if( sqldbs_query(&mysql_handle, "DELETE FROM `" QUEST_TABLE "` WHERE `char_id`='%d'", q2->char_id) == false )
				break;
		}

		for(i = 0; i < q2->count; i++) {
			if( sqldbs_query(&mysql_handle,
				"INSERT INTO `" QUEST_TABLE "` (`char_id`, `account_id`, `nameid`, `state`, `limit`, `mobid1`, `mobmax1`, `mobcnt1`, "
				"`mobid2`, `mobmax2`, `mobcnt2`, `mobid3`, `mobmax3`, `mobcnt3`) "
				"VALUES ('%d','%d','%d','%d','%u','%d','%d','%d','%d','%d','%d','%d','%d','%d')",
				q2->char_id, q2->account_id, q2->data[i].nameid, q2->data[i].state, q2->data[i].limit,
				q2->data[i].mob[0].id, q2->data[i].mob[0].max, q2->data[i].mob[0].cnt,
				q2->data[i].mob[1].id, q2->data[i].mob[1].max, q2->data[i].mob[1].cnt,
				q2->data[i].mob[2].id, q2->data[i].mob[2].max, q2->data[i].mob[2].cnt
			) == false )
				break;
		}
		if(i != q2->count)
			break;

		// success
		result = true;

		{
			// cache copy
			struct quest *q3 = (struct quest *)numdb_search(quest_db, q2->char_id);
			if(q3)
				memcpy(q3, q2, sizeof(struct quest));
		}
	} while(0);

	sqldbs_transaction_end(&mysql_handle, result);

	return result;
}
Ejemplo n.º 3
0
// ギルド城データを書き込み
static int guildcastle_tosql(struct guild_castle *gc)
{
	sqldbs_query(&mysql_handle, "DELETE FROM `guild_castle` WHERE `castle_id` = '%d'", gc->castle_id);

	sqldbs_query(&mysql_handle,
		"INSERT INTO `guild_castle` (`castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`, "
		"`visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`) "
		"VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
		gc->castle_id, gc->guild_id, gc->economy, gc->defense, gc->triggerE, gc->triggerD, gc->nextTime, gc->payTime, gc->createTime,
		gc->visibleC, gc->guardian[0].visible, gc->guardian[1].visible, gc->guardian[2].visible, gc->guardian[3].visible, gc->guardian[4].visible, gc->guardian[5].visible, gc->guardian[6].visible, gc->guardian[7].visible
	);

	return 0;
}
Ejemplo n.º 4
0
// ペットデータを書き込み
static int pet_tosql(int pet_id, struct s_pet *p)
{
	char t_name[64];

	sqldbs_query(&mysql_handle, "DELETE FROM `pet` WHERE `pet_id` = '%d'", pet_id);

	sqldbs_query(&mysql_handle,
		"INSERT INTO `pet` (`pet_id`, `class`, `name`, `account_id`, `char_id`, `level`, `egg_id`, `equip`, `intimate`, `hungry`, `rename_flag`, `incubate`) "
		"VALUES ('%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
		p->pet_id, p->class_, strecpy(t_name,p->name), p->account_id, p->char_id, p->level, p->egg_id,
		p->equip, p->intimate, p->hungry, p->rename_flag, p->incubate
	);

	return 0;
}
Ejemplo n.º 5
0
// 友達登録
static int mmo_friend_tosql(int char_id, struct mmo_charstatus *st)
{
	int i;

	sqldbs_query(&mysql_handle, "DELETE FROM `friend` WHERE `char_id`='%d'", char_id);

	for(i=0; i < st->friend_num; i++) {
		sqldbs_query(&mysql_handle,
			"INSERT INTO `friend` (`char_id`, `friend_account`, `friend_id`) VALUES ('%d', '%d', '%d')",
			st->char_id, st->friend_data[i].account_id, st->friend_data[i].char_id
		);
	}

	return 0;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
/*==========================================
 * 傭兵削除
 *------------------------------------------
 */
bool mercdb_sql_delete(int merc_id)
{
	bool result = false;

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

	// try
	do
	{
		// delete merc
		if( sqldbs_query(&mysql_handle, "DELETE FROM `" MERC_TABLE "` WHERE `merc_id`='%d'", merc_id) == false )
			break;

		// success
		result = true;

		{
			// cache delete
			struct mmo_mercstatus *p = (struct mmo_mercstatus *)numdb_erase(merc_db, merc_id);
			if(p) {
				aFree(p);
			}
		}
	} while(0);

	sqldbs_transaction_end(&mysql_handle, result);

	return result;
}
Ejemplo n.º 8
0
// キャラクター永続変数を書き込み
static int mmo_char_reg_tosql(int char_id, int num, struct global_reg *reg)
{
	char buf[256];
	int i;

	sqldbs_query(&mysql_handle, "DELETE FROM `globalreg` WHERE `char_id`='%d'", char_id);

	for(i=0;i<num;i++){
		if(reg[i].str[0] && reg[i].value != 0) {
			sqldbs_query(&mysql_handle,
				"INSERT INTO `globalreg` (`char_id`, `reg`, `value`) VALUES ('%d', '%s', '%d')",
				char_id, strecpy(buf,reg[i].str), reg[i].value
			);
		}
	}

	return 0;
}
Ejemplo n.º 9
0
static int char_sql_saveitem(struct item *item, int max, int id, int tableswitch)
{
	int i;
	const char *tablename;
	const char *selectoption;
	char *p, tmp_sql[65536 * 2];
	char sep = ' ';

	switch (tableswitch) {
	case TABLE_INVENTORY:
		tablename    = "inventory";
		selectoption = "char_id";
		break;
	case TABLE_CART:
		tablename    = "cart_inventory";
		selectoption = "char_id";
		break;
	case TABLE_STORAGE:
		tablename    = "storage";
		selectoption = "account_id";
		break;
	case TABLE_GUILD_STORAGE:
		tablename    = "guild_storage";
		selectoption = "guild_id";
		break;
	default:
		printf("Invalid table name!\n");
		return 1;
	}

	// delete
	sqldbs_query(&mysql_handle, "DELETE FROM `%s` WHERE `%s`='%d'", tablename, selectoption, id);

	p  = tmp_sql;
	p += sprintf(
		p,"INSERT INTO `%s`(`id`, `%s`, `nameid`, `amount`, `equip`, `identify`, `refine`, "
		"`attribute`, `card0`, `card1`, `card2`, `card3`, `limit`, `private`) VALUES",tablename,selectoption
	);

	for(i = 0 ; i < max ; i++) {
		if(item[i].nameid) {
			p += sprintf(
				p,"%c('%u','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%u','%d')",
				sep,item[i].id,id,item[i].nameid,item[i].amount,item[i].equip,item[i].identify,
				item[i].refine,item[i].attribute,item[i].card[0],item[i].card[1],
				item[i].card[2],item[i].card[3],item[i].limit,item[i].private_
			);
			sep = ',';
		}
	}
	if(sep == ',') {
		sqldbs_simplequery(&mysql_handle, tmp_sql);
	}

	return 0;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
0
/*==========================================
 * ログ記録
 *------------------------------------------
 */
int charlog_log_sql(const char *fmt, ...)
{
	char msg[256], buf[512];
	va_list ap;

	va_start(ap, fmt);
	vsnprintf(msg, sizeof(msg), fmt, ap);
	va_end(ap);

	sqldbs_query(&mysql_handle, "INSERT INTO `" CHARLOG_TABLE "` (`time`,`log`) VALUES (NOW(),'%s')", strecpy(buf, msg));

	return 0;
}
Ejemplo n.º 12
0
// パーティデータを書き込み
static int party_tosql(struct party *p)
{
	int i = 0;
	int leader_id = -1;
	char t_name[64];

	for(i = 0; i < MAX_PARTY; i++) {
		if(p->member[i].account_id > 0 && p->member[i].leader) {
			leader_id = p->member[i].account_id;
			break;
		}
	}

	sqldbs_query(&mysql_handle, "DELETE FROM `party` WHERE `party_id`='%d'", p->party_id);

	sqldbs_query(&mysql_handle,
		"INSERT INTO `party`  (`party_id`, `name`, `exp`, `item`, `leader_id`) "
		"VALUES ('%d','%s', '%d', '%d', '%d')",
		p->party_id,strecpy(t_name,p->name), p->exp, p->item, leader_id
	);

	return 0;
}
Ejemplo n.º 13
0
// ホムンクルスデータを書き込み
static int homun_tosql(int homun_id, struct mmo_homunstatus *h)
{
	int i;
	char sep, *p, buf[64];
	char tmp_sql[65536];

	sqldbs_query(&mysql_handle, "DELETE FROM `homunculus` WHERE `homun_id`='%d'", homun_id);

	sqldbs_query(&mysql_handle,
		"INSERT INTO `homunculus` SET `homun_id` = '%d', `class` = '%d', `name` = '%s', `account_id` = '%d', `char_id` = '%d', `base_level` = '%d', `base_exp` = '%d',"
		"`max_hp` = '%d', `hp` = '%d', `max_sp` = '%d', `sp` = '%d', `str` = '%d', `agi` = '%d',`vit` = '%d',`int` = '%d',`dex` = '%d',`luk` = '%d',"
		"`f_str` = '%d', `f_agi` = '%d',`f_vit` = '%d',`f_int` = '%d',`f_dex` = '%d',`f_luk` = '%d',"
		"`status_point` = '%d', `skill_point` = '%d', `equip` = '%d', `intimate` = '%d', `hungry` = '%d', `rename_flag` = '%d', `incubate` = '%d'",
		homun_id, h->class_, strecpy(buf,h->name), h->account_id , h->char_id, h->base_level, h->base_exp,
		h->max_hp, h->hp, h->max_sp, h->sp, h->str, h->agi, h->vit, h->int_, h->dex, h->luk,
		h->f_str, h->f_agi, h->f_vit, h->f_int, h->f_dex, h->f_luk,
		h->status_point, h->skill_point, h->equip, h->intimate, h->hungry, h->rename_flag, h->incubate
	);

	sqldbs_query(&mysql_handle, "DELETE FROM `homunculus_skill` WHERE `homun_id`='%d'", homun_id);

	p  = tmp_sql;
	p += sprintf(tmp_sql, "INSERT INTO `homunculus_skill` (`homun_id`,`id`,`lv`) VALUES");
	sep = ' ';
	for(i=0;i<MAX_HOMSKILL;i++) {
		if(h->skill[i].id && h->skill[i].flag!=1){
			int lv = (h->skill[i].flag==0)? h->skill[i].lv: h->skill[i].flag-2;
			p += sprintf(p,"%c('%d','%d','%d')", sep,homun_id,h->skill[i].id,lv);
			sep = ',';
		}
	}
	if(sep == ',') {
		sqldbs_simplequery(&mysql_handle, tmp_sql);
	}

	return 0;
}
Ejemplo n.º 14
0
/*==========================================
 * クエストデータ削除
 *------------------------------------------
 */
bool questdb_sql_delete(int char_id)
{
	struct quest *q;

	if( sqldbs_query(&mysql_handle, "DELETE FROM `" QUEST_TABLE "` WHERE `char_id`='%d'", char_id) == false )
		return false;

	q = (struct quest *)numdb_search(quest_db, char_id);

	if(q && q->char_id == char_id) {
		numdb_erase(quest_db, char_id);
		aFree(q);
	}
	return true;
}
Ejemplo n.º 15
0
/*==========================================
 * 接続
 *------------------------------------------
 */
bool sqldbs_connect(struct sqldbs_handle *hd, const char *host, const char *user, const char *passwd,
	const char *db, unsigned short port, const char *charset, int keepalive, const char *tag)
{
	if(hd == NULL)
		return false;

	hd->result = NULL;
	hd->transaction_count = 0;
	hd->tag = NULL;

	if(mysql_init(&hd->handle) == NULL) {
		printf("Database Server Out of Memory\n");
		return false;
	}

	printf("Connecting Database Server -> %s@%s:%d/%s", user, host, port, db);
	if(charset && *charset) {
		mysql_options(&hd->handle, MYSQL_SET_CHARSET_NAME, charset);
		printf(" (charset: %s)", charset);
	}
	printf("\n  ... ");

	if(!mysql_real_connect(&hd->handle, host, user, passwd, db, port, NULL, 0)) {
		printf("%s\n", mysql_error(&hd->handle));
		return false;
	}
	printf("connect success!\n");

	if(charset && *charset) {
		sqldbs_query(hd, "SET NAMES %s", charset);
	}

	printf("MySQL Server version %s\n", mysql_get_server_info(&hd->handle));

	if(keepalive > 0) {
		add_timer_func_list(sqldbs_keepalive_timer);
		add_timer_interval(gettick() + keepalive * 1000, sqldbs_keepalive_timer, 0, hd, keepalive * 1000);
		printf("MySQL keepalive timer set: interval = %d (sec)\n", keepalive);
	}

	if(tag)
		hd->tag = (char *)aStrdup(tag);

	return true;
}
Ejemplo n.º 16
0
/*==========================================
 * ギルド倉庫削除
 *------------------------------------------
 */
bool gstoragedb_sql_delete(int guild_id)
{
	const struct guild_storage *s = gstoragedb_sql_load(guild_id);
	bool result = false;

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

	// try
	do
	{
		if(s) {
			int i;
			for(i = 0; i < s->storage_amount; i++) {
				// ペット削除
				if( s->store_item[i].card[0] == (short)0xff00) {
					if( petdb_delete(*((int *)(&s->store_item[i].card[1]))) == false )
						break;
				}
			}
			if(i != s->storage_amount)
				break;
		}

		// delete
		if( sqldbs_query(&mysql_handle, "DELETE FROM `" GUILD_STORAGE_TABLE "` WHERE `guild_id`='%d'", guild_id) == false )
			break;

		// success
		result = true;

		{
			// cache delete
			struct guild_storage *s2 = (struct guild_storage *)numdb_erase(gstorage_db, guild_id);
			if(s2) {
				aFree(s2);
			}
		}
	} while(0);

	sqldbs_transaction_end(&mysql_handle, result);

	return result;
}
Ejemplo n.º 17
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;
}
Ejemplo n.º 18
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;
}
Ejemplo n.º 19
0
// キャラクターデータを書き込み
static int mmo_char_tosql(int char_id, struct mmo_charstatus *st)
{
	char sep = ' ';
	char buf[256];
	char *p, tmp_sql[65536];
	int i;

	sqldbs_query(&mysql_handle, "DELETE FROM `char_data` WHERE `char_id`='%d'", char_id);

	sqldbs_query(&mysql_handle,
		"INSERT INTO `char_data` SET `char_id` = '%d', `account_id` = '%d', `char_num` = '%d', `name` = '%s', `class` = '%d', `base_level` = '%d', `job_level` = '%d',"
		"`base_exp` = '%d', `job_exp` = '%d', `zeny` = '%d',"
		"`max_hp` = '%d', `hp` = '%d', `max_sp` = '%d', `sp` = '%d', `status_point` = '%d', `skill_point` = '%d',"
		"`str` = '%d', `agi` = '%d', `vit` = '%d', `int` = '%d', `dex` = '%d', `luk` = '%d',"
		"`option` = '%u', `karma` = '%d', `manner` = '%d', `die_counter` = '%d', `party_id` = '%d', `guild_id` = '%d', `pet_id` = '%d', `homun_id` = '%d', `merc_id` = '%d', `elem_id` = '%d',"
		"`hair` = '%d', `hair_color` = '%d', `clothes_color` = '%d', `weapon` = '%d', `shield` = '%d', `robe` = '%d', `head_top` = '%d', `head_mid` = '%d', `head_bottom` = '%d',"
		"`last_map` = '%s', `last_x` = '%d', `last_y` = '%d', `save_map` = '%s', `save_x` = '%d', `save_y` = '%d',"
		"`partner_id` = '%d', `parent_id` = '%d', `parent_id2` = '%d', `baby_id` = '%d', `delete_date` = '%d', `refuse_partyinvite` = '%d', `show_equip` = '%d', `font` = '%d'",
		char_id, st->account_id, st->char_num, strecpy(buf,st->name), st->class_ , st->base_level, st->job_level,
		st->base_exp, st->job_exp, st->zeny,
		st->max_hp, st->hp, st->max_sp, st->sp, st->status_point, st->skill_point,
		st->str, st->agi, st->vit, st->int_, st->dex, st->luk,
		st->option, st->karma, st->manner, st->die_counter, st->party_id, st->guild_id, st->pet_id, st->homun_id, st->merc_id, st->elem_id,
		st->hair, st->hair_color, st->clothes_color,
		st->weapon, st->shield, st->robe, st->head_top, st->head_mid, st->head_bottom,
		st->last_point.map, st->last_point.x, st->last_point.y,
		st->save_point.map, st->save_point.x, st->save_point.y,
		st->partner_id, st->parent_id[0], st->parent_id[1], st->baby_id,
		st->delete_date, st->refuse_partyinvite, st->show_equip, st->font
	);

	// memo
	sqldbs_query(&mysql_handle, "DELETE FROM `memo` WHERE `char_id`='%d'", char_id);

	for(i = 0; i < MAX_PORTAL_MEMO; i++) {
		if(st->memo_point[i].map[0]) {
			sqldbs_query(&mysql_handle,
				"INSERT INTO `memo`(`char_id`,`index`,`map`,`x`,`y`) VALUES ('%d', '%d', '%s', '%d', '%d')",
				char_id, i, strecpy(buf,st->memo_point[i].map), st->memo_point[i].x, st->memo_point[i].y
			);
		}
	}

	// inventory
	char_sql_saveitem(st->inventory, MAX_INVENTORY, st->char_id, TABLE_INVENTORY);

	// cart
	char_sql_saveitem(st->cart, MAX_CART, st->char_id, TABLE_CART);

	// skill
	sqldbs_query(&mysql_handle, "DELETE FROM `skill` WHERE `char_id`='%d'", char_id);

	p  = tmp_sql;
	p += sprintf(p,"INSERT INTO `skill` (`char_id`, `id`, `lv`) VALUES");
	sep = ' ';
	for(i=0;i<MAX_PCSKILL;i++){
		int sk_lv = (st->skill[i].flag==0)? st->skill[i].lv: st->skill[i].flag-2;
		if(st->skill[i].id && st->skill[i].flag!=1){
			p += sprintf(p,"%c('%d','%d','%d')", sep, char_id, st->skill[i].id, sk_lv);
			sep = ',';
		}
	}
	if(sep == ',') {
		sqldbs_simplequery(&mysql_handle, tmp_sql);
	}

	// feel_info
	sqldbs_query(&mysql_handle, "DELETE FROM `feel_info` WHERE `char_id`='%d'", char_id);

	for(i = 0; i < 3; i++) {
		if(st->feel_map[i][0]) {
			sqldbs_query(&mysql_handle,
				"INSERT INTO `feel_info`(`char_id`,`map`,`lv`) VALUES ('%d', '%s', '%d')",
				char_id, strecpy(buf,st->feel_map[i]), i
			);
		}
	}

	// hotkey
	sqldbs_query(&mysql_handle, "DELETE FROM `hotkey` WHERE `char_id`='%d'", char_id);

	for(i = 0; i < MAX_HOTKEYS; i++) {
		if(st->hotkey[i].id > 0) {
			sqldbs_query(&mysql_handle,
				"INSERT INTO `hotkey`(`char_id`,`key`,`type`,`id`,`lv`) VALUES ('%d', '%d', '%d', '%d', '%d')",
				char_id, i, st->hotkey[i].type, st->hotkey[i].id, st->hotkey[i].lv
			);
		}
	}

	// mercenary
	sqldbs_query(&mysql_handle, "DELETE FROM `mercenary` WHERE `char_id`='%d'", char_id);

	for(i = 0; i < MAX_MERC_TYPE; i++) {
		if(st->merc_fame[i] > 0 || st->merc_call[i] > 0) {
			sqldbs_query(&mysql_handle,
				"INSERT INTO `mercenary`(`char_id`,`type`,`fame`,`call`) VALUES ('%d', '%d', '%d', '%d')",
				char_id, i, st->merc_fame[i], st->merc_call[i]
			);
		}
	}

	return 0;
}
Ejemplo n.º 20
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;
}
Ejemplo n.º 21
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;
}
Ejemplo n.º 22
0
// ギルドデータを書き込み
static int guild_tosql(struct guild* g)
{
	int  i;
	char buf[256],buf2[256],buf3[256],buf4[256];
	char tmp_sql[65536];
	char *p = tmp_sql;
	char sep;

	// 基本データ
	sqldbs_query(&mysql_handle, "DELETE FROM `guild` WHERE `guild_id`='%d'", g->guild_id);

	p += sprintf(
		tmp_sql,"INSERT INTO `guild` "
		"(`guild_id`, `name`, `master`, `guild_lv`, `connect_member`, `max_member`, `average_lv`, `exp`,"
		"`next_exp`, `skill_point`, `mes1`, `mes2`, `emblem_len`, `emblem_id`, `emblem_data`) "
		"VALUES ('%d', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%s', '%d', '%d', '",
		g->guild_id, strecpy(buf,g->name), strecpy(buf2,g->master),
		g->guild_lv, g->connect_member, g->max_member, g->average_lv, g->exp,
		g->next_exp, g->skill_point, strecpy(buf3,g->mes1), strecpy(buf4,g->mes2), g->emblem_len, g->emblem_id
	);
	for(i=0; i<g->emblem_len; i++) {
		p += sprintf(p,"%02x",(unsigned char)(g->emblem_data[i]));
	}
	p += sprintf(p,"')");

	sqldbs_simplequery(&mysql_handle, tmp_sql);

	// メンバー
	sqldbs_query(&mysql_handle, "DELETE FROM `guild_member` WHERE `guild_id`='%d'", g->guild_id);

	p  = tmp_sql;
	p += sprintf(
		tmp_sql,
		"INSERT INTO `guild_member` (`guild_id`,`account_id`,`char_id`,`hair`,`hair_color`,`gender`,"
		"`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`name`) VALUES"
	);
	sep = ' ';

	for(i=0;i < g->max_member;i++) {
		if (g->member[i].account_id>0){
			struct guild_member *m = &g->member[i];
			p += sprintf(
				p,
				"%c('%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%s')",
				sep,g->guild_id,m->account_id,m->char_id,m->hair,m->hair_color,m->gender,
				m->class_,m->lv,m->exp,m->exp_payper,(int)m->online,m->position,strecpy(buf,m->name)
			);
			sep = ',';
		}
	}
	if(sep == ',') {
		sqldbs_simplequery(&mysql_handle, tmp_sql);
	}

	// 役職
	sqldbs_query(&mysql_handle, "DELETE FROM `guild_position` WHERE `guild_id`='%d'", g->guild_id);

	p  = tmp_sql;
	p += sprintf(
		tmp_sql,
		"INSERT INTO `guild_position` (`guild_id`,`position`,`name`,`mode`,`exp_mode`) VALUES"
	);
	sep = ' ';
	for(i=0;i<MAX_GUILDPOSITION;i++){
		struct guild_position *pos = &g->position[i];
		p += sprintf(
			p,"%c('%d','%d','%s','%d','%d')",
			sep, g->guild_id,i,strecpy(buf,pos->name),pos->mode,pos->exp_mode
		);
		sep = ',';
	}
	if(sep == ',') {
		sqldbs_simplequery(&mysql_handle, tmp_sql);
	}

	// 同盟リスト
	sqldbs_query(&mysql_handle, "DELETE FROM `guild_alliance` WHERE `guild_id`='%d'", g->guild_id);

	p  = tmp_sql;
	p += sprintf(
		tmp_sql,
		"INSERT INTO `guild_alliance` (`guild_id`,`opposition`,`alliance_id`,`name`) VALUES"
	);
	sep = ' ';
	for(i=0;i<MAX_GUILDALLIANCE;i++){
		struct guild_alliance *a = &g->alliance[i];
		if(a->guild_id>0){
			p += sprintf(
				p,
				"%c('%d','%d','%d','%s')",
				sep,g->guild_id,a->opposition,a->guild_id,strecpy(buf,a->name)
			);
			sep = ',';
		}
	}
	if(sep == ',') {
		sqldbs_simplequery(&mysql_handle, tmp_sql);
	}

	// 追放リスト
	sqldbs_query(&mysql_handle, "DELETE FROM `guild_expulsion` WHERE `guild_id`='%d'", g->guild_id);

	p  = tmp_sql;
	p += sprintf(
		tmp_sql,
		"INSERT INTO `guild_expulsion` (`guild_id`,`name`,`mes`,`account_id`) VALUES"
	);
	sep = ' ';
	for(i=0;i<MAX_GUILDEXPLUSION;i++) {
		struct guild_explusion *e = &g->explusion[i];
		if(e->account_id>0) {
			p += sprintf(
				p,"%c('%d','%s','%s','%d')",
				sep,g->guild_id,strecpy(buf,e->name),strecpy(buf2,e->mes),e->account_id
			);
			sep = ',';
		}
	}
	if(sep == ',') {
		sqldbs_simplequery(&mysql_handle, tmp_sql);
	}

	// ギルドスキル
	sqldbs_query(&mysql_handle, "DELETE FROM `guild_skill` WHERE `guild_id`='%d'", g->guild_id);

	p  = tmp_sql;
	p += sprintf(
		tmp_sql,
		"INSERT INTO `guild_skill` (`guild_id`,`id`,`lv`) VALUES"
	);
	sep = ' ';
	for(i=0;i<MAX_GUILDSKILL;i++) {
		if (g->skill[i].id > 0) {
			p += sprintf(
				p,"%c('%d','%d','%d')",
				sep,g->guild_id,g->skill[i].id,g->skill[i].lv
			);
			sep = ',';
		}
	}
	if(sep == ',') {
		sqldbs_simplequery(&mysql_handle, tmp_sql);
	}

	return 0;
}