Exemple #1
0
/// Modifies the value of a string variable.
bool mapreg_setregstr(int uid, const char* str)
{
	int num = (uid & 0x00ffffff);
	int i   = (uid & 0xff000000) >> 24;
	const char* name = get_str(num);
	
	if( str == NULL || *str == 0 )
	{
		if(name[1] != '@') {
			if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) )
				Sql_ShowDebug(mmysql_handle);
		}
		idb_remove(mapregstr_db,uid);
	}
	else
	{
		if (idb_put(mapregstr_db,uid, aStrdup(str)))
			mapreg_dirty = true;
		else if(name[1] != '@') { //put returned null, so we must insert.
			// Someone is causing a database size infinite increase here without name[1] != '@' [Lance]
			char tmp_str[32*2+1];
			char tmp_str2[255*2+1];
			Sql_EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32));
			Sql_EscapeStringLen(mmysql_handle, tmp_str2, str, strnlen(str, 255));
			if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%s')", mapreg_table, tmp_str, i, tmp_str2) )
				Sql_ShowDebug(mmysql_handle);
		}
	}

	return true;
}
Exemple #2
0
void log_woe_kill(struct map_session_data* ssd, struct map_session_data* tsd, uint16 skill_id)
{
	char esc_sname[NAME_LENGTH*2+1];
	char esc_tname[NAME_LENGTH*2+1];

	Sql_EscapeStringLen(mmysql_handle, esc_sname, ssd->status.name, strnlen(ssd->status.name, NAME_LENGTH));
	Sql_EscapeStringLen(mmysql_handle, esc_tname, tsd->status.name, strnlen(tsd->status.name, NAME_LENGTH));

	if( SQL_ERROR == Sql_Query(mmysql_handle,LOG_QUERY " INTO `char_woe_log` (`time`,`killer`,`killer_id`,`killed`,`killed_id`,`map`,`skill`) VALUES (NOW(), '%s', '%d', '%s', '%d', '%s', '%d')", esc_sname, ssd->status.char_id, esc_tname, tsd->status.char_id, map[tsd->bl.m].name, skill_id) )
		Sql_ShowDebug(mmysql_handle);

	return;
}
Exemple #3
0
int log_bg_kill(struct map_session_data *ssd, struct map_session_data *tsd, int skill)
{
	char esc_sname[NAME_LENGTH*2+1];
	char esc_tname[NAME_LENGTH*2+1];

	Sql_EscapeStringLen(mmysql_handle, esc_sname, ssd->status.name, strnlen(ssd->status.name, NAME_LENGTH));
	Sql_EscapeStringLen(mmysql_handle, esc_tname, tsd->status.name, strnlen(tsd->status.name, NAME_LENGTH));

	if( SQL_ERROR == Sql_Query(mmysql_handle,"INSERT DELAYED INTO `char_bg_log` (`time`,`killer`,`killer_id`,`killed`,`killed_id`,`map`,`skill`) VALUES (NOW(), '%s', '%d', '%s', '%d', '%s', '%d')", esc_sname, ssd->status.char_id, esc_tname, tsd->status.char_id, map[tsd->bl.m].name, skill) )
		Sql_ShowDebug(mmysql_handle);

	return 0;
}
	//Account Creation
	void Packet0x02(session_data_t* session, CPlayer* player, int8* data)
	{
		char* query = "SELECT id, handle FROM accounts WHERE handle LIKE '%s';";

		char handle[11];
		memset(handle, 0, sizeof handle);
		memcpy(handle, data + 0x02, 10);
		char pass[17];
		memset(pass, 0, sizeof pass);
		memcpy(pass, data + 0x0C, 16);

		char escapedHandle[(sizeof handle) * 2 + 1];
		char escapedPass[(sizeof pass) * 2 + 1];

		Sql_EscapeStringLen(SqlHandle, escapedHandle, handle, sizeof handle);
		Sql_EscapeStringLen(SqlHandle, escapedPass, pass, sizeof pass);

		int ret = Sql_Query(SqlHandle, query, escapedHandle);

		//TODO: validate name/pass
		if (ret != SQL_ERROR)
		{
			if (Sql_NumRows(SqlHandle) == 0)
			{
				query = "INSERT INTO accounts (handle, password) VALUES('%s', PASSWORD('%s'));";

				ret = Sql_Query(SqlHandle, query, escapedHandle, escapedPass);

				if (ret != SQL_ERROR && Sql_AffectedRows(SqlHandle) == 1)
				{
					session->PPlayer->pushPacket(new CAccountCreatePacket(CREATE_SUCCESS));
					ShowDebug("Account %s has been created\n", handle);
				}
				else
				{
					session->PPlayer->pushPacket(new CAccountCreatePacket(CREATE_UNDEF));
				}
			}
			else
			{
				session->PPlayer->pushPacket(new CAccountCreatePacket(CREATE_NAME_TAKEN));
			}
		}
		else
		{
			session->PPlayer->pushPacket(new CAccountCreatePacket(CREATE_UNDEF));
		}
	}
Exemple #5
0
static void mapif_parse_Mail_send(int fd)
{
	struct mail_message msg;
	char esc_name[NAME_LENGTH*2+1];
	int account_id = 0;

	if(RFIFOW(fd,2) != 8 + sizeof(struct mail_message))
		return;

	account_id = RFIFOL(fd,4);
	memcpy(&msg, RFIFOP(fd,8), sizeof(struct mail_message));

	// Try to find the Dest Char by Name
	Sql_EscapeStringLen(sql_handle, esc_name, msg.dest_name, strnlen(msg.dest_name, NAME_LENGTH));
	if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`, `char_id` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) )
		Sql_ShowDebug(sql_handle);
	else
	if ( SQL_SUCCESS == Sql_NextRow(sql_handle) )
	{
		char *data;
		Sql_GetData(sql_handle, 0, &data, NULL);
		if (atoi(data) != account_id)
		{ // Cannot send mail to char in the same account
			Sql_GetData(sql_handle, 1, &data, NULL);
			msg.dest_id = atoi(data);
		}
	}
	Sql_FreeResult(sql_handle);
	msg.status = MAIL_NEW;

	if( msg.dest_id > 0 )
		msg.id = mail_savemessage(&msg);

	mapif_Mail_send(fd, &msg);
}
Exemple #6
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;
}
Exemple #7
0
void mapif_parse_Mail_send(int fd)
{
	struct mail_message msg;
	char esc_name[NAME_LENGTH*2+1];
	char *data;
	size_t len;

	if(RFIFOW(fd,2) != 8 + sizeof(struct mail_message))
		return;

	memcpy(&msg, RFIFOP(fd,8), sizeof(struct mail_message));

	if( msg.dest_id != 0 ){
		if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`, `name` FROM `%s` WHERE `char_id` = '%u'", schema_config.char_db, msg.dest_id) ){
			Sql_ShowDebug(sql_handle);
			return;
		}
		
		msg.dest_id = 0;
		msg.dest_name[0] = '\0';

		if( SQL_SUCCESS == Sql_NextRow(sql_handle) ){
			Sql_GetData(sql_handle, 0, &data, NULL);
			msg.dest_id = atoi(data);
			Sql_GetData(sql_handle, 1, &data, &len);
			safestrncpy(msg.dest_name, data, NAME_LENGTH);
		}

		Sql_FreeResult(sql_handle);
	}

	// Try to find the Dest Char by Name
	Sql_EscapeStringLen(sql_handle, esc_name, msg.dest_name, strnlen(msg.dest_name, NAME_LENGTH));
	if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`, `char_id` FROM `%s` WHERE `name` = '%s'", schema_config.char_db, esc_name) ){
		Sql_ShowDebug(sql_handle);
	}else if ( SQL_SUCCESS == Sql_NextRow(sql_handle) ){
#if PACKETVER < 20150513
		uint32 account_id = RFIFOL(fd,4);

		Sql_GetData(sql_handle, 0, &data, NULL);
		if (atoi(data) != account_id)
		{ // Cannot send mail to char in the same account
			Sql_GetData(sql_handle, 1, &data, NULL);
			msg.dest_id = atoi(data);
		}
#else
		// In RODEX you can even send mails to yourself
		Sql_GetData(sql_handle, 1, &data, NULL);
		msg.dest_id = atoi(data);
#endif
	}
	Sql_FreeResult(sql_handle);
	msg.status = MAIL_NEW;

	if( msg.dest_id > 0 )
		msg.id = mail_savemessage(&msg);

	mapif_Mail_send(fd, &msg); // notify sender
	mapif_Mail_new(&msg); // notify recipient
}
Exemple #8
0
/// Modifies the value of an integer variable.
bool mapreg_setreg(int uid, int val) {
	struct mapreg_save *m;
	int num = (uid & 0x00ffffff);
	int i   = (uid & 0xff000000) >> 24;
	const char* name = get_str(num);

	if( val != 0 ) {
		if( (m = idb_get(mapreg_db,uid)) ) {
			m->u.i = val;
			if(name[1] != '@') {
				m->save = true;
				mapreg_i_dirty = true;
			}
		} else {
			m = ers_alloc(mapreg_ers, struct mapreg_save);

			m->u.i = val;
			m->uid = uid;
			m->save = false;

			if(name[1] != '@') {// write new variable to database
				char tmp_str[32*2+1];
				Sql_EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32));
				if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%d')", mapreg_table, tmp_str, i, val) )
					Sql_ShowDebug(mmysql_handle);
			}
			idb_put(mapreg_db, uid, m);
		}
	} else { // val == 0
		if( (m = idb_get(mapreg_db,uid)) ) {
Exemple #9
0
/**
 * Modifies the value of an integer variable.
 *
 * @param uid: variable's unique identifier
 * @param val new value
 * @return: true value was successfully set
 */
bool mapreg_setreg(int64 uid, int val)
{
	struct mapreg_save *m;
	int num = script_getvarid(uid);
	unsigned int i = script_getvaridx(uid);
	const char* name = get_str(num);

	if (val != 0) {
		if ((m = i64db_get(regs.vars, uid))) {
			m->u.i = val;
			if (name[1] != '@') {
				m->save = true;
				mapreg_dirty = true;
			}
		} else {
			if (i)
				script_array_update(&regs, uid, false);

			m = ers_alloc(mapreg_ers, struct mapreg_save);

			m->u.i = val;
			m->uid = uid;
			m->save = false;
			m->is_string = false;

			if (name[1] != '@' && !skip_insert) {// write new variable to database
				char tmp_str[32 * 2 + 1];
				Sql_EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32));
				if (SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%d')", mapreg_table, tmp_str, i, val))
					Sql_ShowDebug(mmysql_handle);
			}
			i64db_put(regs.vars, uid, m);
		}
	} else { // val == 0
		if (i)
Exemple #10
0
/// Modifies the value of an integer variable.
bool mapreg_setreg(int uid, int val)
{
	int num = (uid & 0x00ffffff);
	int i   = (uid & 0xff000000) >> 24;
	const char* name = get_str(num);

	if( val != 0 )
	{
		if( idb_put(mapreg_db,uid,(void*)(intptr_t)val) )
			mapreg_dirty = true; // already exists, delay write
		else if(name[1] != '@')
		{// write new wariable to database
			char tmp_str[32*2+1];
			Sql_EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32));
			if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%d')", mapreg_table, tmp_str, i, val) )
				Sql_ShowDebug(mmysql_handle);
		}
	}
	else // val == 0
	{
		idb_remove(mapreg_db,uid);

		if( name[1] != '@' )
		{// Remove from database because it is unused.
			if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) )
				Sql_ShowDebug(mmysql_handle);
		}
	}

	return true;
}
Exemple #11
0
/// Modifies the value of an integer variable.
bool mapreg_setreg(int uid, int val)
{
	int num = (uid & 0x00ffffff);
	int i   = (uid & 0xff000000) >> 24;
	const char* name = get_str(num);
	struct region_data* rd;

	if( !stricmp(name,"$Region") && i > 0 && i < SCRIPT_MAX_ARRAYSIZE && (rd = region_search(i)) != NULL )
		region_set_guild(i,val);

	if( val != 0 )
	{
		if( idb_iput(mapreg_db,uid,val) )
			mapreg_dirty = true; // already exists, delay write
		else if(name[1] != '@')
		{// write new variable to database
			char tmp_str[32*2+1];
			Sql_EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32));
			if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%d')", mapreg_table, tmp_str, i, val) )
				Sql_ShowDebug(mmysql_handle);
		}
	}
	else // val == 0
	{
		idb_remove(mapreg_db,uid);

		if( name[1] != '@' )
		{// Remove from database because it is unused.
			if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) )
				Sql_ShowDebug(mmysql_handle);
		}
	}

	return true;
}
Exemple #12
0
/**
 * Records an event in the login log.
 * @param ip:
 * @param username:
 * @param rcode:
 * @param message:
 */
void login_log(uint32 ip, const char* username, int rcode, const char* message) {
	char esc_username[NAME_LENGTH*2+1];
	char esc_message[255*2+1];
	int retcode;

	if( !enabled )
		return;

	Sql_EscapeStringLen(sql_handle, esc_username, username, strnlen(username, NAME_LENGTH));
	Sql_EscapeStringLen(sql_handle, esc_message, message, strnlen(message, 255));

	retcode = Sql_Query(sql_handle,
		"INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%s', '%s', '%d', '%s')",
		log_login_db, ip2str(ip,NULL), esc_username, rcode, esc_message);

	if( retcode != SQL_SUCCESS )
		Sql_ShowDebug(sql_handle);
}
Exemple #13
0
	//Login Status
	void Packet0x01(session_data_t* session, CPlayer* player, int8* data)
	{
		char* query = "SELECT id, handle, wins, losses FROM accounts WHERE handle = '%s' AND password = PASSWORD('%s');";

		char handle[11];
		memset(handle, 0, sizeof handle);
		memcpy(handle, data + 0x02, 10);
		char pass[17];
		memset(pass, 0, sizeof pass);
		memcpy(pass, data + 0x0C, 16);

		char escapedHandle[(sizeof handle) * 2 + 1];
		char escapedPass[(sizeof pass) * 2 + 1];

		Sql_EscapeStringLen(SqlHandle, escapedHandle, handle, sizeof handle);
		Sql_EscapeStringLen(SqlHandle, escapedPass, pass, sizeof pass);

		int ret = Sql_Query(SqlHandle, query, escapedHandle, escapedPass);

		if (ret != SQL_ERROR)
		{
			if (Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS)
			{
				//fill in account specific stuff (wins/losses/etc)
				delete session->PPlayer;
				session->PPlayer = new CPlayer(Sql_GetUIntData(SqlHandle, 0));
				session->PPlayer->SetName(handle);
				session->PPlayer->SetWins(Sql_GetUIntData(SqlHandle, 2));
				session->PPlayer->SetLosses(Sql_GetUIntData(SqlHandle, 3));
				session->PPlayer->pushPacket(new CLoginPacket(session->PPlayer, LOGIN_SUCCESS));
				session->PPlayer->pushPacket(new CLobbyListPacket());
				ShowDebug("Player %s has logged in\n", session->PPlayer->GetName());
			}
			else
			{
				session->PPlayer->pushPacket(new CLoginPacket(session->PPlayer, LOGIN_INVALID_CRED));
			}
		}
		else
		{
			session->PPlayer->pushPacket(new CLoginPacket(session->PPlayer, LOGIN_UNDEF));
		}
	}
Exemple #14
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;
}
Exemple #15
0
int log_pick_pc(struct map_session_data *sd, const char *type, int nameid, int amount, struct item *itm, uint64 serial)
{
	nullpo_ret(sd);

	if (!should_log_item(log_config.filter, nameid, amount))
		return 0; //we skip logging this item set - it doesn't meet our logging conditions [Lupus]

#ifndef TXT_ONLY
	if( log_config.sql_logs )
	{
		char esc_name[NAME_LENGTH*2+1];
		Sql_EscapeStringLen(logmysql_handle, esc_name, sd->status.name, strnlen(sd->status.name, NAME_LENGTH));

		if( itm == NULL ) { //We log common item
			if (SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`time`, `account_id`, `char_id`, `name`, `type`, `nameid`, `amount`, `map`, `serial`) VALUES (NOW(), '%d', '%d', '%s', '%s', '%d', '%d', '%s', '%u')",
				log_config.log_pick_db, sd->status.account_id, sd->status.char_id, esc_name, type, nameid, amount, mapindex_id2name(sd->mapindex), serial) )
			{
				Sql_ShowDebug(logmysql_handle);
				return 0;
			}
		} else { //We log Extended item
			if (SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`time`, `account_id`, `char_id`, `name`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `serial`) VALUES (NOW(), '%d', '%d', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%u')",
				log_config.log_pick_db, sd->status.account_id, sd->status.char_id, esc_name, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapindex_id2name(sd->mapindex), serial) )
			{
				Sql_ShowDebug(logmysql_handle);
				return 0;
			}
		}
	}
	else
#endif
	{
		FILE* logfp;

		if((logfp = fopen(log_config.log_pick, "a+")) == NULL)
			return 0;
		time(&curtime);
		strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));

		if( itm == NULL ) { //We log common item
			fprintf(logfp,"%s - %d\t%s\t%d,%d,%s\n", timestring, sd->status.char_id, type, nameid, amount, mapindex_id2name(sd->mapindex));
		} else { //We log Extended item
			fprintf(logfp,"%s - %d\t%s\t%d,%d,%d,%d,%d,%d,%d,%s\n", timestring, sd->status.char_id, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapindex_id2name(sd->mapindex));
		}
		fclose(logfp);
	}
	
	return 1; //Logged
}
Exemple #16
0
/**
 * Save interlog into sql (arglist version)
 * @see inter_log
 */
int inter_vlog(char* fmt, va_list ap) {
	char str[255];
	char esc_str[sizeof(str)*2+1];// escaped str
	va_list apcopy;

	va_copy(apcopy, ap);
	vsnprintf(str, sizeof(str), fmt, apcopy);
	va_end(apcopy);

	Sql_EscapeStringLen(sql_handle, esc_str, str, strnlen(str, sizeof(str)));
	if(SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`time`, `log`) VALUES (NOW(),  '%s')", interlog_db, esc_str))
		Sql_ShowDebug(sql_handle);

	return 0;
}
Exemple #17
0
// Search for the party according to its name
struct party_data *search_partyname(char *str) {
	char esc_name[NAME_LENGTH*2+1];
	char *data;
	struct party_data *p = NULL;

	Sql_EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH));
	if(SQL_ERROR == Sql_Query(sql_handle, "SELECT `party_id` FROM `%s` WHERE `name`='%s'", party_db, esc_name))
		Sql_ShowDebug(sql_handle);
	else if(SQL_SUCCESS == Sql_NextRow(sql_handle)) {
		Sql_GetData(sql_handle, 0, &data, NULL);
		p = inter_party_fromsql(atoi(data));
	}
	Sql_FreeResult(sql_handle);

	return p;
}
Exemple #18
0
void SaveSetSpells(CCharEntity* PChar)
{
    if (PChar->GetMJob() == JOB_BLU || PChar->GetSJob() == JOB_BLU)
    {
	    const int8* Query =
            "UPDATE chars SET "
              "set_blue_spells = '%s' "
            "WHERE charid = %u;";

	    int8 spells[sizeof(PChar->m_SetBlueSpells)*2+1];
	    Sql_EscapeStringLen(SqlHandle,spells,(const int8*)PChar->m_SetBlueSpells,sizeof(PChar->m_SetBlueSpells));

	    Sql_Query(SqlHandle,Query,
            spells,
            PChar->id);
    }
}
Exemple #19
0
/// Saves permanent variables to database
static void script_save_mapreg(void)
{
	DBIterator* iter;
	DBData *data;
	DBKey key;

	iter = db_iterator(mapreg_db);
	for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) )
	{
		int num = (key.i & 0x00ffffff);
		int i   = (key.i & 0xff000000) >> 24;
		const char* name = get_str(num);

		if( name[1] == '@' )
			continue;

		if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d'", mapreg_table, db_data2i(data), name, i) )
			Sql_ShowDebug(mmysql_handle);
	}
	dbi_destroy(iter);

	iter = db_iterator(mapregstr_db);
	for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) )
	{
		int num = (key.i & 0x00ffffff);
		int i   = (key.i & 0xff000000) >> 24;
		const char* name = get_str(num);
		char tmp_str2[2*255+1];

		if( name[1] == '@' )
			continue;

		Sql_EscapeStringLen(mmysql_handle, tmp_str2, db_data2ptr(data), safestrnlen(db_data2ptr(data), 255));
		if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%d'", mapreg_table, tmp_str2, name, i) )
			Sql_ShowDebug(mmysql_handle);
	}
	dbi_destroy(iter);

	mapreg_dirty = false;
}
Exemple #20
0
void mapif_parse_Mail_receiver_check( int fd ){
	char name[NAME_LENGTH], esc_name[NAME_LENGTH * 2 + 1];
	uint32 char_id = 0;
	uint16 class_ = 0, base_level = 0;

	safestrncpy( name, RFIFOCP(fd, 6), NAME_LENGTH );

	// Try to find the Dest Char by Name
	Sql_EscapeStringLen( sql_handle, esc_name, name, strnlen( name, NAME_LENGTH ) );

	if( SQL_ERROR == Sql_Query( sql_handle, "SELECT `char_id`,`class`,`base_level` FROM `%s` WHERE `name` = '%s'", schema_config.char_db, esc_name ) ){
		Sql_ShowDebug(sql_handle);
	}else if( SQL_SUCCESS == Sql_NextRow(sql_handle) ){
		char *data;

		Sql_GetData(sql_handle, 0, &data, NULL); char_id = atoi(data);
		Sql_GetData(sql_handle, 1, &data, NULL); class_ = atoi(data);
		Sql_GetData(sql_handle, 2, &data, NULL); base_level = atoi(data);
	}

	Sql_FreeResult(sql_handle);
	mapif_Mail_receiver_send( fd, RFIFOL(fd, 2), char_id, class_, base_level, name );
}
Exemple #21
0
void CMeritPoints::SaveMeritPoints(uint32 charid, bool resetingMerits)
{
	const int8* Query =  "UPDATE chars SET merits = '%s' WHERE charid = %u";

	int8 points[MERITS_COUNT*2+1];
    int8 MeritCounts[MERITS_COUNT];

    for (uint16 i = 0; i < MERITS_COUNT; ++i)
    {
		if (resetingMerits)
			MeritCounts[i] = 0;
		else
			MeritCounts[i] = merits[i].count;
    }

	Sql_EscapeStringLen(SqlHandle, points, (const int8*)MeritCounts, MERITS_COUNT);

	Sql_Query(SqlHandle, Query, points, charid);


	// reload merit points if they were reset
	if (resetingMerits)
		LoadMeritPoints(charid);
}
Exemple #22
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;
}
Exemple #23
0
// Wisp/page request to send
int mapif_parse_WisRequest(int fd)
{
	struct WisData *wd;
	static int wisid = 0;
	char name[NAME_LENGTH];
	char esc_name[NAME_LENGTH*2+1];// escaped name
	char *data;
	size_t len;


	if(fd <= 0) {
		return 0;   // check if we have a valid fd
	}

	if(RFIFOW(fd,2)-52 >= sizeof(wd->msg)) {
		ShowWarning(read_message("Source.char.inter_parsewisrequest_s1"));
		return 0;
	} else if(RFIFOW(fd,2)-52 <= 0) {  // normaly, impossible, but who knows...
		ShowError(read_message("Source.char.inter_parsewisrequest_s2"));
		return 0;
	}

	safestrncpy(name, (char *)RFIFOP(fd,28), NAME_LENGTH); //Received name may be too large and not contain \0! [Skotlex]

	Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH));
	if(SQL_ERROR == Sql_Query(sql_handle, "SELECT `name` FROM `%s` WHERE `name`='%s'", char_db, esc_name))
		Sql_ShowDebug(sql_handle);

	// search if character exists before to ask all map-servers
	if(SQL_SUCCESS != Sql_NextRow(sql_handle)) {
		unsigned char buf[27];
		WBUFW(buf, 0) = 0x3802;
		memcpy(WBUFP(buf, 2), RFIFOP(fd, 4), NAME_LENGTH);
		WBUFB(buf,26) = 1; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
		mapif_send(fd, buf, 27);
	} else {
		// Character exists. So, ask all map-servers
		// to be sure of the correct name, rewrite it
		Sql_GetData(sql_handle, 0, &data, &len);
		memset(name, 0, NAME_LENGTH);
		memcpy(name, data, min(len, NAME_LENGTH));
		// if source is destination, don't ask other servers.
		if(strncmp((const char *)RFIFOP(fd,4), name, NAME_LENGTH) == 0) {
			uint8 buf[27];
			WBUFW(buf, 0) = 0x3802;
			memcpy(WBUFP(buf, 2), RFIFOP(fd, 4), NAME_LENGTH);
			WBUFB(buf,26) = 1; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
			mapif_send(fd, buf, 27);
		} else {

			CREATE(wd, struct WisData, 1);

			// Whether the failure of previous wisp/page transmission (timeout)
			check_ttl_wisdata();

			wd->id = ++wisid;
			wd->fd = fd;
			wd->len= RFIFOW(fd,2)-52;
			memcpy(wd->src, RFIFOP(fd, 4), NAME_LENGTH);
			memcpy(wd->dst, RFIFOP(fd,28), NAME_LENGTH);
			memcpy(wd->msg, RFIFOP(fd,52), wd->len);
			wd->tick = gettick();
			idb_put(wis_db, wd->id, wd);
			mapif_wis_message(wd);
		}
	}

	Sql_FreeResult(sql_handle);
	return 0;
}
Exemple #24
0
/// logs item transactions (generic)
void log_pick(struct block_list* bl, int16 m, e_log_pick_type type, int amount, struct item* itm)
{
	const char* mapname;
	int id = 0, account_id = 0;
	char esc_name[NAME_LENGTH*2+1] = "";
	nullpo_retv(itm);

	if( ( log_config.enable_logs&type ) == 0 )
	{// disabled
		return;
	}

	if( !should_log_item(itm->nameid, amount, itm->refine) )
		return; //we skip logging this item set - it doesn't meet our logging conditions [Lupus]

	//either PLAYER or MOB (here we get map name and objects ID)
	if( bl == NULL )
	{
		ShowError("log_pick: bl == NULL\n");
	}
	else switch( bl->type )
	{
		case BL_PC:
			id = ((TBL_PC*)bl)->status.char_id;
			account_id = ((TBL_PC*)bl)->status.account_id;
			Sql_EscapeStringLen(logmysql_handle, esc_name, ((TBL_PC*)bl)->status.name, NAME_LENGTH);
			break;
		case BL_MOB:
			id = ((TBL_MOB*)bl)->mob_id;
			account_id = 0;
			Sql_EscapeStringLen(logmysql_handle, esc_name, ((TBL_MOB*)bl)->name, NAME_LENGTH);
			break;
		default:
			ShowDebug("log_pick: Unhandled bl type %d.\n", bl->type);
	}

	mapname = map[bl->m].name;

	if( log_config.sql_logs )
	{
#ifdef BETA_THREAD_TEST
		char entry[512];
		int e_length = 0;
		e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`time`, `account_id`, `char_id`, `name`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`, `bound`) VALUES (NOW(), '%d', '%d', '%s', '%c', '%hu', '%d', '%d', '%hu', '%hu', '%hu', '%hu', '%s', '%"PRIu64"', '%d')",
				log_config.log_pick, account_id, id, esc_name, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname, itm->unique_id, itm->bound);
		queryThread_log(entry,e_length);
#else
		if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `account_id`, `char_id`, `name`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`, `bound`) VALUES (NOW(), '%d', '%d', '%s', '%c', '%hu', '%d', '%d', '%hu', '%hu', '%hu', '%hu', '%s', '%"PRIu64"', '%d')",
			log_config.log_pick, account_id, id, esc_name, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname, itm->unique_id, itm->bound) )
		{
			Sql_ShowDebug(logmysql_handle);
			return;
		}
#endif
	}
	else
	{
		char timestring[255];
		time_t curtime;
		FILE* logfp;

		if( ( logfp = fopen(log_config.log_pick, "a") ) == NULL )
			return;
		time(&curtime);
		strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
		fprintf(logfp,"%s - %d\t%c\t%hu,%d,%d,%hu,%hu,%hu,%hu,%s,'%"PRIu64"',%d\n", timestring, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname, itm->unique_id, itm->bound);
		fclose(logfp);
	}
}
Exemple #25
0
size_t Sql_EscapeString(Sql_t* self, char *out_to, const char *from)
{
	return Sql_EscapeStringLen(self,out_to,from,strlen(from));
}
Exemple #26
0
int32 doSynthResult(CCharEntity* PChar)
{
	uint8 m_synthResult = PChar->CraftContainer->getQuantity(0);

	if (m_synthResult == SYNTHESIS_FAIL)
	{
		doSynthFail(PChar);
	}else{
		uint16 itemID   = PChar->CraftContainer->getItemID(10 + m_synthResult);
		uint8  quantity = PChar->CraftContainer->getInvSlotID(10 + m_synthResult); // к сожалению поле quantity занято

		uint8 invSlotID   = 0;
		uint8 nextSlotID  = 0;
		uint8 removeCount = 0;

		invSlotID = PChar->CraftContainer->getInvSlotID(1);

		for(uint8 slotID = 1; slotID <= 8; ++slotID)
		{
			nextSlotID = (slotID != 8 ? PChar->CraftContainer->getInvSlotID(slotID+1) : 0);
			removeCount++;

			if (invSlotID != nextSlotID)
			{
				if (invSlotID != 0xFF)
				{
					#ifdef _DSP_SYNTH_DEBUG_MESSAGES_
					ShowDebug(CL_CYAN"Removing quantity %u from inventory slot %u\n" CL_RESET,removeCount,invSlotID);
					#endif
					PChar->getStorage(LOC_INVENTORY)->GetItem(invSlotID)->setSubType(ITEM_UNLOCKED);
					charutils::UpdateItem(PChar, LOC_INVENTORY, invSlotID, -(int32)removeCount);
				}
				invSlotID   = nextSlotID;
				nextSlotID  = 0;
				removeCount = 0;
			}
		}

        // TODO: перейти на новую функцию AddItem, чтобы не обновлять signature ручками

		invSlotID = charutils::AddItem(PChar, LOC_INVENTORY, itemID, quantity);

		CItem* PItem = PChar->getStorage(LOC_INVENTORY)->GetItem(invSlotID);

		if (PItem != NULL)
		{
			if ((PItem->getFlag() & ITEM_FLAG_INSCRIBABLE) && (PChar->CraftContainer->getItemID(0) > 0x1080))
			{
                int8 encodedSignature [12];
				PItem->setSignature(EncodeStringSignature((int8*)PChar->name.c_str(), encodedSignature));

                int8 signature_esc[31]; //max charname: 15 chars * 2 + 1
				Sql_EscapeStringLen(SqlHandle,signature_esc,PChar->name.c_str(),strlen(PChar->name.c_str()));

				int8 fmtQuery[] = "UPDATE char_inventory SET signature = '%s' WHERE charid = %u AND location = 0 AND slot = %u;\0";

				Sql_Query(SqlHandle,fmtQuery,signature_esc,PChar->id, invSlotID);
			}
			PChar->pushPacket(new CInventoryItemPacket(PItem, LOC_INVENTORY, invSlotID));
		}

		PChar->pushPacket(new CInventoryFinishPacket());
        if(PChar->loc.zone->GetID() != 255 && PChar->loc.zone->GetID() != 0)
        {
			PChar->loc.zone->PushPacket(PChar, CHAR_INRANGE, new CSynthResultMessagePacket(PChar, SYNTH_SUCCESS, itemID, quantity));
			PChar->pushPacket(new CSynthMessagePacket(PChar, SYNTH_SUCCESS, itemID, quantity));
        }
        else
        {
            PChar->pushPacket(new CSynthMessagePacket(PChar, SYNTH_SUCCESS, itemID, quantity));
        }
	}

	doSynthSkillUp(PChar);

	return 0;
}
Exemple #27
0
/// logs item transactions
void log_pick(struct block_list* bl, e_log_pick_type type, int nameid, int amount, struct item* itm)
{
	const char* mapname;
	int id = 0, account_id = 0;
	char esc_name[NAME_LENGTH*2+1] = "";

	if( ( log_config.enable_logs&type ) == 0 )
	{// disabled
		return;
	}

	if( !should_log_item(nameid, amount, itm ? itm->refine : 0) )
		return; //we skip logging this item set - it doesn't meet our logging conditions [Lupus]

	//either PLAYER or MOB (here we get map name and objects ID)
	if( bl == NULL )
	{
		ShowError("log_pick: bl == NULL\n");
	}
	else switch( bl->type )
	{
		case BL_PC:
			id = ((TBL_PC*)bl)->status.char_id;
			account_id = ((TBL_PC*)bl)->status.account_id;
			Sql_EscapeStringLen(logmysql_handle, esc_name, ((TBL_PC*)bl)->status.name, NAME_LENGTH);
			break;
		case BL_MOB:
			id = ((TBL_MOB*)bl)->class_;
			account_id = 0;
			Sql_EscapeStringLen(logmysql_handle, esc_name, ((TBL_MOB*)bl)->name, NAME_LENGTH);
			break;
		default:
			ShowDebug("log_pick: Unhandled bl type %d.\n", bl->type);
	}

	mapname = map[bl->m].name;

#ifndef TXT_ONLY
	if( log_config.sql_logs )
	{
		if( itm == NULL )
		{//We log common item
			if (type == LOG_TYPE_NPC && amount < 0) {
				if( SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`char_id`, `nameid`, `amount`) VALUES ('%d', '%d', '%d')",
					"sell_log", id, nameid, (amount*-1)) )
				{
					Sql_ShowDebug(logmysql_handle);
				}
			}
			if( SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`time`, `account_id`, `char_id`, `name`, `type`, `nameid`, `amount`, `map`) VALUES (NOW(), '%d', '%d', '%s', '%c', '%d', '%d', '%s')",
				log_config.log_pick, account_id, id, esc_name, log_picktype2char(type), nameid, amount, mapname) )
			{
				Sql_ShowDebug(logmysql_handle);
				return;
			}
		}
		else
		{//We log Extended item
			if (type == LOG_TYPE_NPC && amount < 0) {
				if( SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`char_id`, `nameid`, `amount`, `attribute`, `refine`, `card0`, `card1`, `card2`, `card3`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
					"sell_log", id, nameid, (amount*-1), itm->attribute, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3]) )
				{
					Sql_ShowDebug(logmysql_handle);
				}
			}			
			if( SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`time`, `account_id`, `char_id`, `name`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `serial`) VALUES (NOW(), '%d', '%d', '%s', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%u')",
				log_config.log_pick, account_id, id, esc_name, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname, itm->serial) )
			{
				Sql_ShowDebug(logmysql_handle);
				return;
			}
		}
	}
	else
#endif
	{
		char timestring[255];
		time_t curtime;
		FILE* logfp;

		if( ( logfp = fopen(log_config.log_pick, "a") ) == NULL )
			return;
		time(&curtime);
		strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));

		if( itm == NULL )
		{//We log common item
			fprintf(logfp,"%s - %d\t%c\t%d,%d,%s\n", timestring, id, log_picktype2char(type), nameid, amount, mapname);
		}
		else
		{//We log Extended item
			fprintf(logfp,"%s - %d\t%c\t%d,%d,%d,%d,%d,%d,%d,%s\n", timestring, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname);
		}
		fclose(logfp);
	}
}
Exemple #28
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;
}