Ejemplo n.º 1
0
bool mapif_elemental_save(struct s_elemental* ele) {
    bool flag = true;

    if( ele->elemental_id == 0 ) { // Create new DB entry
        if( SQL_ERROR == Sql_Query(sql_handle,
                                   "INSERT INTO `elemental` (`char_id`,`class`,`mode`,`hp`,`sp`,`max_hp`,`max_sp`,`atk1`,`atk2`,`matk`,`aspd`,`def`,`mdef`,`flee`,`hit`,`life_time`)"
                                   "VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%u')",
                                   ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2, ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time) )
        {
            Sql_ShowDebug(sql_handle);
            flag = false;
        }
        else
            ele->elemental_id = (int)Sql_LastInsertId(sql_handle);
    } else if( SQL_ERROR == Sql_Query(sql_handle,
                                      "UPDATE `elemental` SET `char_id` = '%d', `class` = '%d', `mode` = '%d', `hp` = '%d', `sp` = '%d',"
                                      "`max_hp` = '%d', `max_sp` = '%d', `atk1` = '%d', `atk2` = '%d', `matk` = '%d', `aspd` = '%d', `def` = '%d',"
                                      "`mdef` = '%d', `flee` = '%d', `hit` = '%d', `life_time` = '%u' WHERE `ele_id` = '%d'",
                                      ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2,
                                      ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time, ele->elemental_id) )
    {   // Update DB entry
        Sql_ShowDebug(sql_handle);
        flag = false;
    }
    return flag;
}
Ejemplo n.º 2
0
//---------------------------------------------------------
int inter_pet_tosql (int pet_id, struct s_pet *p)
{
	//`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`)
	char esc_name[NAME_LENGTH * 2 + 1]; // escaped pet name
	Sql_EscapeStringLen (sql_handle, esc_name, p->name, strnlen (p->name, NAME_LENGTH));
	p->hungry = cap_value (p->hungry, 0, 100);
	p->intimate = cap_value (p->intimate, 0, 1000);

	if (pet_id == -1) {
		// New pet.
		if (SQL_ERROR == Sql_Query (sql_handle, "INSERT INTO `%s` "
									"(`class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) "
									"VALUES ('%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
									pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id,
									p->equip, p->intimate, p->hungry, p->rename_flag, p->incuvate)) {
			Sql_ShowDebug (sql_handle);
			return 0;
		}

		p->pet_id = (int) Sql_LastInsertId (sql_handle);
	} else {
		// Update pet.
		if (SQL_ERROR == Sql_Query (sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incuvate`='%d' WHERE `pet_id`='%d'",
									pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id,
									p->equip, p->intimate, p->hungry, p->rename_flag, p->incuvate, p->pet_id)) {
			Sql_ShowDebug (sql_handle);
			return 0;
		}
	}

	if (save_log)
		ShowInfo ("Pet salvo %d - %s.\n", pet_id, p->name);

	return 1;
}
Ejemplo n.º 3
0
bool mapif_mercenary_save(struct s_mercenary* merc)
{
	bool flag = true;

	if( merc->mercenary_id == 0 )
	{ // Create new DB entry
		if( SQL_ERROR == Sql_Query(sql_handle,
			"INSERT INTO `%s` (`char_id`,`class`,`hp`,`sp`,`kill_counter`,`life_time`) VALUES ('%d','%d','%d','%d','%u','%u')",
			mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time) )
		{
			Sql_ShowDebug(sql_handle);
			flag = false;
		}
		else
			merc->mercenary_id = (int)Sql_LastInsertId(sql_handle);
	}
	else if( SQL_ERROR == Sql_Query(sql_handle,
		"UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `hp` = '%d', `sp` = '%d', `kill_counter` = '%u', `life_time` = '%u' WHERE `mer_id` = '%d'",
		mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time, merc->mercenary_id) )
	{ // Update DB entry
		Sql_ShowDebug(sql_handle);
		flag = false;
	}

	return flag;
}
Ejemplo n.º 4
0
bool mapif_homunculus_save(struct s_homunculus *hd)
{
	bool flag = true;
	char esc_name[NAME_LENGTH*2+1];

	Sql_EscapeStringLen(sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH));

	if(hd->hom_id == 0) {
		// new homunculus
		if(SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` "
		                          "(`char_id`, `class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`, `rename_flag`, `vaporize`) "
		                          "VALUES ('%d', '%d', '%d', '%s', '%d', '%u', '%u', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
		                          homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk,
		                          hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize)) {
			Sql_ShowDebug(sql_handle);
			flag = false;
		} else {
			hd->hom_id = (int)Sql_LastInsertId(sql_handle);
		}
	} else {
		if(SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_id`='%d', `class`='%d',`prev_class`='%d',`name`='%s',`level`='%d',`exp`='%u',`intimacy`='%u',`hunger`='%d', `str`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%d',`max_hp`='%d',`sp`='%d',`max_sp`='%d',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d' WHERE `homun_id`='%d'",
		                          homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk,
		                          hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->hom_id)) {
			Sql_ShowDebug(sql_handle);
			flag = false;
		} else {
			SqlStmt *stmt;
			int i;

			stmt = SqlStmt_Malloc(sql_handle);
			if (SQL_ERROR == SqlStmt_Prepare(stmt, "REPLACE INTO `%s` (`homun_id`, `id`, `lv`) VALUES (%d, ?, ?)", skill_homunculus_db, hd->hom_id))
				SqlStmt_ShowDebug(stmt);
			for(i = 0; i < MAX_HOMUNSKILL; ++i) {
				if(hd->hskill[i].id > 0 && hd->hskill[i].lv != 0) {
					SqlStmt_BindParam(stmt, 0, SQLDT_USHORT, &hd->hskill[i].id, 0);
					SqlStmt_BindParam(stmt, 1, SQLDT_USHORT, &hd->hskill[i].lv, 0);
					if(SQL_ERROR == SqlStmt_Execute(stmt)) {
						SqlStmt_ShowDebug(stmt);
						SqlStmt_Free(stmt);
						flag = false;
						break;
					}
				}
			}
			SqlStmt_Free(stmt);
		}
	}

	return flag;
}
Ejemplo n.º 5
0
    uint32 RegisterNewLinkshell(const int8* name, uint16 color)
    {
        if (IsValidLinkshellName(name))
        {
		    if (Sql_Query(SqlHandle, "INSERT INTO linkshells (name, color) VALUES ('%s', %u)", name, color) != SQL_ERROR)
            {
                CLinkshell* PLinkshell = new CLinkshell(Sql_LastInsertId(SqlHandle));
			
			    PLinkshell->setColor(color);
                PLinkshell->setName((int8*)name);
                
                LinkshellList[PLinkshell->getID()] = PLinkshell;

                return PLinkshell->getID();
            }
        }
        return 0;
    }
Ejemplo n.º 6
0
// Save party to mysql
int inter_party_tosql(struct party *p, int flag, int index)
{
	// 'party' ('party_id','name','exp','item','leader_id','leader_char')
	char esc_name[NAME_LENGTH*2+1];// escaped party name
	int party_id;

	if( p == NULL || p->party_id == 0 )
		return 0;
	party_id = p->party_id;

#ifdef NOISY
	ShowInfo("Save party request ("CL_BOLD"%d"CL_RESET" - %s).\n", party_id, p->name);
#endif
	Sql_EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH));

#ifndef TXT_SQL_CONVERT
	if( flag & PS_BREAK )
	{// Break the party
		// we'll skip name-checking and just reset everyone with the same party id [celest]
		if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id) )
			Sql_ShowDebug(sql_handle);
		if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `party_id`='%d'", party_db, party_id) )
			Sql_ShowDebug(sql_handle);
		//Remove from memory
		idb_remove(party_db_, party_id);
		return 1;
	}
#endif //TXT_SQL_CONVERT
	if( flag & PS_CREATE )
	{// Create party
#ifndef TXT_SQL_CONVERT
		if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` "
			"(`name`, `exp`, `item`, `leader_id`, `leader_char`) "
			"VALUES ('%s', '%d', '%d', '%d', '%d')",
			party_db, esc_name, p->exp, p->item, p->member[index].account_id, p->member[index].char_id) )
		{
			Sql_ShowDebug(sql_handle);
			return 0;
		}
		party_id = p->party_id = (int)Sql_LastInsertId(sql_handle);
#else
		//During conversion, you want to specify the id, and allow overwriting
		//(in case someone is re-running the process.

		if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` "
			"(`party_id`, `name`, `exp`, `item`, `leader_id`, `leader_char`) "
			"VALUES ('%d', '%s', '%d', '%d', '%d', '%d')",
			party_db, p->party_id, esc_name, p->exp, p->item, p->member[index].account_id, p->member[index].char_id) )
		{
			Sql_ShowDebug(sql_handle);
			return 0;
		}
#endif
	}

#ifndef TXT_SQL_CONVERT
	if( flag & PS_BASIC )
	{// Update party info.
		if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `name`='%s', `exp`='%d', `item`='%d' WHERE `party_id`='%d'",
			party_db, esc_name, p->exp, p->item, party_id) )
			Sql_ShowDebug(sql_handle);
	}

	if( flag & PS_LEADER )
	{// Update leader
		if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s`  SET `leader_id`='%d', `leader_char`='%d' WHERE `party_id`='%d'",
			party_db, p->member[index].account_id, p->member[index].char_id, party_id) )
			Sql_ShowDebug(sql_handle);
	}
	
	if( flag & PS_ADDMEMBER )
	{// Add one party member.
		if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='%d' WHERE `account_id`='%d' AND `char_id`='%d'",
			char_db, party_id, p->member[index].account_id, p->member[index].char_id) )
			Sql_ShowDebug(sql_handle);
	}

	if( flag & PS_DELMEMBER )
	{// Remove one party member.
		if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d' AND `account_id`='%d' AND `char_id`='%d'",
			char_db, party_id, p->member[index].account_id, p->member[index].char_id) )
			Sql_ShowDebug(sql_handle);
	}
#endif //TXT_SQL_CONVERT
	if( save_log )
		ShowInfo("Party Saved (%d - %s)\n", party_id, p->name);
	return 1;
}
Ejemplo n.º 7
0
// Save party to mysql
int inter_party_tosql(struct party *p, int flag, int index)
{
	// 'party' ('party_id','name','exp','item','leader_id','leader_char')
	char esc_name[NAME_LENGTH*2+1];// escaped party name
	int party_id;

	if(p == NULL || p->party_id == 0)
		return 0;
	party_id = p->party_id;

#ifdef NOISY
	ShowInfo(read_message("Source.char.party_tosql_s1"), CL_BOLD, party_id, CL_RESET, p->name);
#endif
	Sql_EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH));

	if(flag & PS_BREAK) {
		// Break the party
		// we'll skip name-checking and just reset everyone with the same party id [celest]
		if(SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id))
			Sql_ShowDebug(sql_handle);
		if(SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `party_id`='%d'", party_db, party_id))
			Sql_ShowDebug(sql_handle);
		//Remove from memory
		idb_remove(party_db_, party_id);
		return 1;
	}

	if(flag & PS_CREATE) {
		// Create party
		if(SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` "
		                          "(`name`, `exp`, `item`, `leader_id`, `leader_char`) "
		                          "VALUES ('%s', '%d', '%d', '%d', '%d')",
		                          party_db, esc_name, p->exp, p->item, p->member[index].account_id, p->member[index].char_id)) {
			Sql_ShowDebug(sql_handle);
			return 0;
		}
		party_id = p->party_id = (int)Sql_LastInsertId(sql_handle);
	}

	if(flag & PS_BASIC) {
		// Update party info.
		if(SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `name`='%s', `exp`='%d', `item`='%d' WHERE `party_id`='%d'",
		                          party_db, esc_name, p->exp, p->item, party_id))
			Sql_ShowDebug(sql_handle);
	}

	if(flag & PS_LEADER) {
		// Update leader
		if(SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s`  SET `leader_id`='%d', `leader_char`='%d' WHERE `party_id`='%d'",
		                          party_db, p->member[index].account_id, p->member[index].char_id, party_id))
			Sql_ShowDebug(sql_handle);
	}

	if(flag & PS_ADDMEMBER) {
		// Add one party member.
		if(SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='%d' WHERE `account_id`='%d' AND `char_id`='%d'",
		                          char_db, party_id, p->member[index].account_id, p->member[index].char_id))
			Sql_ShowDebug(sql_handle);
	}

	if(flag & PS_DELMEMBER) {
		// Remove one party member.
		if(SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d' AND `account_id`='%d' AND `char_id`='%d'",
		                          char_db, party_id, p->member[index].account_id, p->member[index].char_id))
			Sql_ShowDebug(sql_handle);
	}

	if(save_log)
		ShowInfo(read_message("Source.char.party_tosql_s2"), party_id, p->name);
	return 1;
}