int log_pick_pc(struct map_session_data *sd, const char *type, int nameid, int amount, struct item *itm) { FILE *logfp; char *mapname; nullpo_retr(0, sd); //Should we log this item? [Lupus] if (!should_log_item(log_config.filter,nameid, amount)) return 0; //we skip logging this items set - they doesn't met our logging conditions [Lupus] mapname = (char*)mapindex_id2name(sd->mapindex); if(mapname==NULL) mapname=""; #ifndef TXT_ONLY if(log_config.sql_logs > 0) { if (itm==NULL) { //We log common item sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%s')", log_config.log_pick_db, sd->status.char_id, type, nameid, amount, mapname); } else { //We log Extended item sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')", log_config.log_pick_db, sd->status.char_id, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname); } if(mysql_query(&logmysql_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); return 0; } return 1; } #endif 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%s", timestring, sd->status.char_id, type, nameid, amount, mapname, RETCODE); } else { //We log Extended item fprintf(logfp,"%s - %d\t%s\t%d,%d,%d,%d,%d,%d,%d,%s%s", timestring, sd->status.char_id, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname, RETCODE); } fclose(logfp); return 1; //Logged }
/// Executes the prepared statement. int SqlStmt_Execute(SqlStmt* self) { if( self == NULL ) return SQL_ERROR; SqlStmt_FreeResult(self); if( (self->bind_params && mysql_stmt_bind_param(self->stmt, self->params)) || mysql_stmt_execute(self->stmt) ) { ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt)); return SQL_ERROR; } self->bind_columns = false; if( mysql_stmt_store_result(self->stmt) )// store all the data { ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt)); return SQL_ERROR; } return SQL_SUCCESS; }
/// Executes a query. int Sql_QueryV(Sql* self, const char* query, va_list args) { if( self == NULL ) return SQL_ERROR; Sql_FreeResult(self); StringBuf_Clear(&self->buf); StringBuf_Vprintf(&self->buf, query, args); if( mysql_real_query(&self->handle, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_error(&self->handle)); return SQL_ERROR; } self->result = mysql_store_result(&self->handle); if( mysql_errno(&self->handle) != 0 ) { ShowSQL("DB error - %s\n", mysql_error(&self->handle)); return SQL_ERROR; } return SQL_SUCCESS; }
int32 Sql_QueryStr(Sql_t* self, const char* query) { if( self == NULL ) return SQL_ERROR; Sql_FreeResult(self); StringBuf_Clear(&self->buf); StringBuf_AppendStr(&self->buf, query); if( mysql_real_query(&self->handle, StringBuf_Value(&self->buf), (uint32)StringBuf_Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_error(&self->handle)); return SQL_ERROR; } self->result = mysql_store_result(&self->handle); if( mysql_errno(&self->handle) != 0 ) { ShowSQL("DB error - %s\n", mysql_error(&self->handle)); return SQL_ERROR; } return SQL_SUCCESS; }
/// Establishes a connection. int Sql_Connect(Sql* self, const char* user, const char* passwd, const char* host, uint16 port, const char* db) { if( self == NULL ) return SQL_ERROR; StringBuf_Clear(&self->buf); if( !mysql_real_connect(&self->handle, host, user, passwd, db, (unsigned int)port, NULL/*unix_socket*/, 0/*clientflag*/) ) { ShowSQL("%s\n", mysql_error(&self->handle)); return SQL_ERROR; } self->keepalive = Sql_P_Keepalive(self); if( self->keepalive == INVALID_TIMER ) { ShowSQL("Failed to establish keepalive for DB connection!\n"); return SQL_ERROR; } return SQL_SUCCESS; }
int32 Sql_Connect(Sql_t* self, const char* user, const char* passwd, const char* host, uint16 port, const char* db) { if( self == NULL ) return SQL_ERROR; StringBuf_Clear(&self->buf); if( !mysql_real_connect(&self->handle, host, user, passwd, db, (uint32)port, NULL/*unix_socket*/, 0/*clientflag*/) ) { ShowSQL("%s\n", mysql_error(&self->handle)); return SQL_ERROR; } return SQL_SUCCESS; }
/// Executes a query. int Sql_QueryStr(Sql* self, const char* query) { if( self == NULL ) return SQL_ERROR; SQL->FreeResult(self); StrBuf->Clear(&self->buf); StrBuf->AppendStr(&self->buf, query); if( mysql_real_query(&self->handle, StrBuf->Value(&self->buf), (unsigned long)StrBuf->Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_error(&self->handle)); hercules_mysql_error_handler(mysql_errno(&self->handle)); return SQL_ERROR; } self->result = mysql_store_result(&self->handle); if( mysql_errno(&self->handle) != 0 ) { ShowSQL("DB error - %s\n", mysql_error(&self->handle)); hercules_mysql_error_handler(mysql_errno(&self->handle)); return SQL_ERROR; } return SQL_SUCCESS; }
int inter_party_sql_init(){ int i; //memory alloc // ShowDebug("interserver party memory initialize.... (%d byte)\n",sizeof(struct party)); party_pt = (struct party*)aCalloc(sizeof(struct party), 1); sprintf (tmp_sql , "SELECT count(*) FROM `%s`", party_db); if (mysql_query(&mysql_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } sql_res = mysql_store_result(&mysql_handle) ; sql_row = mysql_fetch_row(sql_res); ShowStatus("total party data -> '%s'.......\n",sql_row[0]); i = atoi (sql_row[0]); mysql_free_result(sql_res); if (i > 0) { //set party_newid sprintf (tmp_sql , "SELECT max(`party_id`) FROM `%s`", party_db); if(mysql_query(&mysql_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } sql_res = mysql_store_result(&mysql_handle) ; sql_row = mysql_fetch_row(sql_res); party_newid = atoi (sql_row[0])+1; mysql_free_result(sql_res); } ShowDebug("set party_newid: %d.......\n", party_newid); return 0; }
int mail_check_timer(int tid,unsigned int tick,int id,int data) { if(mail_timer != tid) return 0; sprintf(tmp_sql,"SELECT DISTINCT `to_account_id` FROM `%s` WHERE `read_flag` = '0' AND `check_flag` = '0'", mail_db); if (mysql_query(&mail_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); mail_timer=add_timer(gettick()+MAIL_CHECK_TIME,mail_check_timer,0,0); return 0; } mail_res = mysql_store_result(&mail_handle); if (mail_res) { if (mysql_num_rows(mail_res) == 0) { mysql_free_result(mail_res); mail_timer=add_timer(gettick()+MAIL_CHECK_TIME,mail_check_timer,0,0); return 0; } while ((mail_row = mysql_fetch_row(mail_res))) clif_foreachclient(mail_check_timer_sub, atoi(mail_row[0])); } sprintf(tmp_sql,"UPDATE `%s` SET `check_flag`='1' WHERE `check_flag`= '0' ", mail_db); if(mysql_query(&mail_handle, tmp_sql) ) { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } mail_timer=add_timer(gettick()+MAIL_CHECK_TIME,mail_check_timer,0,0); return 0; }
/// Prepares the statement. int SqlStmt_PrepareStr(SqlStmt* self, const char* query) { if( self == NULL ) return SQL_ERROR; SqlStmt_FreeResult(self); StringBuf_Clear(&self->buf); StringBuf_AppendStr(&self->buf, query); if( mysql_stmt_prepare(self->stmt, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt)); return SQL_ERROR; } self->bind_params = false; return SQL_SUCCESS; }
// Save interlog into sql int inter_log(char *fmt,...) { char str[255]; char temp_str[510]; //Needs be twice as long as str[] //Skotlex va_list ap; va_start(ap,fmt); vsprintf(str,fmt,ap); sprintf(tmp_sql,"INSERT INTO `%s` (`time`, `log`) VALUES (NOW(), '%s')",interlog_db, jstrescapecpy(temp_str,str)); if(mysql_query(&mysql_handle, tmp_sql) ) { ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } va_end(ap); return 0; }
/// Prepares the statement. int SqlStmt_PrepareV(SqlStmt* self, const char* query, va_list args) { if( self == NULL ) return SQL_ERROR; SqlStmt_FreeResult(self); StringBuf_Clear(&self->buf); StringBuf_Vprintf(&self->buf, query, args); if( mysql_stmt_prepare(self->stmt, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt)); hercules_mysql_error_handler(mysql_stmt_errno(self->stmt)); return SQL_ERROR; } self->bind_params = false; return SQL_SUCCESS; }
/// Reports debug information about a truncated column. /// /// @private static void SqlStmt_P_ShowDebugTruncatedColumn(SqlStmt* self, size_t i) { MYSQL_RES* meta; MYSQL_FIELD* field; MYSQL_BIND* column; meta = mysql_stmt_result_metadata(self->stmt); field = mysql_fetch_field_direct(meta, (unsigned int)i); ShowSQL("DB error - data of field '%s' was truncated.\n", field->name); ShowDebug("column - %lu\n", (unsigned long)i); Sql_P_ShowDebugMysqlFieldInfo("data - ", field->type, field->flags&UNSIGNED_FLAG, self->column_lengths[i].length, ""); column = &self->columns[i]; if( column->buffer_type == MYSQL_TYPE_STRING ) Sql_P_ShowDebugMysqlFieldInfo("buffer - ", column->buffer_type, column->is_unsigned, column->buffer_length, "+1(nul-terminator)"); else Sql_P_ShowDebugMysqlFieldInfo("buffer - ", column->buffer_type, column->is_unsigned, column->buffer_length, ""); mysql_free_result(meta); }
/// Prepares the statement. int SqlStmt_PrepareStr(SqlStmt* self, const char* query) { if( self == NULL ) return SQL_ERROR; SQL->StmtFreeResult(self); StrBuf->Clear(&self->buf); StrBuf->AppendStr(&self->buf, query); if( mysql_stmt_prepare(self->stmt, StrBuf->Value(&self->buf), (unsigned long)StrBuf->Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt)); hercules_mysql_error_handler(mysql_stmt_errno(self->stmt)); return SQL_ERROR; } self->bind_params = false; return SQL_SUCCESS; }
// Load guild_storage data to mem int guild_storage_fromsql(int guild_id, struct guild_storage *p) { int i=0,j; struct guild_storage *gs=guild_storage_pt; char * str_p = tmp_sql; p=gs; memset(p,0,sizeof(struct guild_storage)); //clean up memory p->storage_amount = 0; p->guild_id = guild_id; // storage {`guild_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`} str_p += sprintf(str_p,"SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`"); for (j=0; j<MAX_SLOTS; j++) str_p += sprintf(str_p, ", `card%d`", j); str_p += sprintf(str_p," FROM `%s` WHERE `guild_id`='%d' ORDER BY `nameid`", guild_storage_db, guild_id); if(mysql_query(&mysql_handle, tmp_sql) ) { ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } sql_res = mysql_store_result(&mysql_handle) ; if (sql_res) { while((sql_row = mysql_fetch_row(sql_res)) && i < MAX_GUILD_STORAGE) { //start to fetch p->storage_[i].id= atoi(sql_row[0]); p->storage_[i].nameid= atoi(sql_row[1]); p->storage_[i].amount= atoi(sql_row[2]); p->storage_[i].equip= atoi(sql_row[3]); p->storage_[i].identify= atoi(sql_row[4]); p->storage_[i].refine= atoi(sql_row[5]); p->storage_[i].attribute= atoi(sql_row[6]); for (j=0; j<MAX_SLOTS; j++) p->storage_[i].card[j] = atoi(sql_row[7+j]); i++; } p->storage_amount = i; mysql_free_result(sql_res); } ShowInfo ("guild storage load complete from DB - id: %d (total: %d)\n", guild_id, p->storage_amount); return 0; }
// Save/Update Homunculus Skills int mapif_save_homunculus_skills(struct s_homunculus *hd) { int i; for(i=0; i<MAX_HOMUNSKILL; i++) { if(hd->hskill[i].id != 0 && hd->hskill[i].lv != 0 ) { sprintf(tmp_sql,"REPLACE INTO `skill_homunculus` (`homun_id`, `id`, `lv`) VALUES (%d, %d, %d)", hd->hom_id, hd->hskill[i].id, hd->hskill[i].lv); if(mysql_query(&mysql_handle, tmp_sql)){ ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); return 0; } } } return 1; }
int log_chat(char *type, int type_id, int src_charid, int src_accid, char *map, int x, int y, char *dst_charname, char *message) { FILE *logfp; #ifndef TXT_ONLY char t_charname[NAME_LENGTH*2]; char t_msg[CHAT_SIZE*2+1]; //Chat line fully escaped, with an extra space just in case. #endif //Check ON/OFF if(log_config.chat <= 0) return 0; //Deactivated #ifndef TXT_ONLY if(log_config.sql_logs > 0) { if (strlen(message) > CHAT_SIZE) { if (battle_config.error_log) ShowError("log chat: Received message too long from type %d (%d:%d)!\n", type_id, src_accid, src_charid); return 0; } sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`time`, `type`, `type_id`, `src_charid`, `src_accountid`, `src_map`, `src_map_x`, `src_map_y`, `dst_charname`, `message`) VALUES (NOW(), '%s', '%d', '%d', '%d', '%s', '%d', '%d', '%s', '%s')", log_config.log_chat_db, type, type_id, src_charid, src_accid, map, x, y, jstrescapecpy(t_charname, dst_charname), jstrescapecpy(t_msg, message)); if(mysql_query(&logmysql_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); return 0; } return 1; } #endif if((logfp = fopen(log_config.log_chat, "a+")) == NULL) return 0; time(&curtime); strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime)); //DATE - type,type_id,src_charid,src_accountid,src_map,src_x,src_y,dst_charname,message fprintf(logfp, "%s - %s,%d,%d,%d,%s,%d,%d,%s,%s%s", timestring, type, type_id, src_charid, src_accid, map, x, y, dst_charname, message, RETCODE); fclose(logfp); return 1; }
int log_atcommand(struct map_session_data *sd, const char *message) { FILE *logfp; #ifndef TXT_ONLY char t_name[NAME_LENGTH*2]; char t_msg[CHAT_SIZE*2+1]; //These are the contents of an @ call, so there shouldn't be overflow danger here? #endif if(!log_config.enable_logs) return 0; nullpo_retr(0, sd); #ifndef TXT_ONLY if(log_config.sql_logs > 0) { if (strlen(message) > CHAT_SIZE) { if (battle_config.error_log) ShowError("log atcommand: Received message too long from player %s (%d:%d)!\n", sd->status.name, sd->status.account_id, sd->status.char_id); return 0; } sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`atcommand_date`, `account_id`, `char_id`, `char_name`, `map`, `command`) VALUES(NOW(), '%d', '%d', '%s', '%s', '%s') ", log_config.log_gm_db, sd->status.account_id, sd->status.char_id, jstrescapecpy(t_name, sd->status.name), mapindex_id2name(sd->mapindex), jstrescapecpy(t_msg, (char *)message)); if(mysql_query(&logmysql_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); return 0; } return 1; } #endif if((logfp=fopen(log_config.log_gm,"a+")) == NULL) return 0; time(&curtime); strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime)); fprintf(logfp,"%s - %s[%d]: %s%s",timestring,sd->status.name,sd->status.account_id,message,RETCODE); fclose(logfp); return 1; }
int mapif_load_guild_storage(int fd,int account_id,int guild_id) { int guild_exist=1; WFIFOHEAD(fd, sizeof(struct guild_storage)+12); WFIFOW(fd,0)=0x3818; #if 0 // innodb guilds should render this check unnecessary [Aru] // Check if guild exists, I may write a function for this later, coz I use it several times. //printf("- Check if guild %d exists\n",g->guild_id); sprintf(tmp_sql, "SELECT count(*) FROM `%s` WHERE `guild_id`='%d'",guild_db, guild_id); if(mysql_query(&mysql_handle, tmp_sql) ) { ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } sql_res = mysql_store_result(&mysql_handle) ; if (sql_res!=NULL && mysql_num_rows(sql_res)>0) { sql_row = mysql_fetch_row(sql_res); guild_exist = atoi (sql_row[0]); //printf("- Check if guild %d exists : %s\n",g->guild_id,((guild_exist==0)?"No":"Yes")); } mysql_free_result(sql_res) ; //resource free #endif if(guild_exist==1) { guild_storage_fromsql(guild_id,guild_storage_pt); WFIFOW(fd,2)=sizeof(struct guild_storage)+12; WFIFOL(fd,4)=account_id; WFIFOL(fd,8)=guild_id; memcpy(WFIFOP(fd,12),guild_storage_pt,sizeof(struct guild_storage)); } else { WFIFOW(fd,2)=12; WFIFOL(fd,4)=account_id; WFIFOL(fd,8)=0; } WFIFOSET(fd,WFIFOW(fd,2)); return 0; }
int mapif_parse_SaveGuildStorage(int fd) { int guild_exist=1; int guild_id; int len; RFIFOHEAD(fd); guild_id=RFIFOL(fd,8); len=RFIFOW(fd,2); if(sizeof(struct guild_storage)!=len-12) { ShowError("inter storage: data size error %d %d\n",sizeof(struct guild_storage),len-12); } else { #if 0 // Again, innodb key checks make the check pointless // Check if guild exists, I may write a function for this later, coz I use it several times. //printf("- Check if guild %d exists\n",g->guild_id); sprintf(tmp_sql, "SELECT count(*) FROM `%s` WHERE `guild_id`='%d'",guild_db, guild_id); if(mysql_query(&mysql_handle, tmp_sql) ) { ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } sql_res = mysql_store_result(&mysql_handle) ; if (sql_res!=NULL && mysql_num_rows(sql_res)>0) { sql_row = mysql_fetch_row(sql_res); guild_exist = atoi (sql_row[0]); //printf("- Check if guild %d exists : %s\n",g->guild_id,((guild_exist==0)?"No":"Yes")); } mysql_free_result(sql_res) ; //resource free #endif if(guild_exist==1) { memcpy(guild_storage_pt,RFIFOP(fd,12),sizeof(struct guild_storage)); guild_storage_tosql(guild_id,guild_storage_pt); mapif_save_guild_storage_ack(fd,RFIFOL(fd,4),guild_id,0); } else mapif_save_guild_storage_ack(fd,RFIFOL(fd,4),guild_id,1); } return 0; }
int mapif_save_homunculus(int fd, int account_id, struct s_homunculus *hd) { int flag =1; char t_name[NAME_LENGTH*2]; jstrescapecpy(t_name, hd->name); if(hd->hom_id==0) // new homunculus { sprintf(tmp_sql, "INSERT INTO `homunculus` " "(`char_id`, `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', '%s', '%d', '%u', '%u', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", hd->char_id, hd->class_,t_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); } else { sprintf(tmp_sql, "UPDATE `homunculus` SET `char_id`='%d', `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'", hd->char_id, hd->class_,t_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); } if(mysql_query(&mysql_handle, tmp_sql)){ ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); flag = 0; } if(hd->hom_id==0 && flag!=0) hd->hom_id = (int)mysql_insert_id(&mysql_handle); // new homunculus else { flag = mapif_save_homunculus_skills(hd); mapif_saved_homunculus(fd, account_id, flag); } return flag; }
// Load account_reg from sql (type=2) int inter_accreg_fromsql(int account_id,int char_id, struct accreg *reg, int type) { int j=0; if (reg==NULL) return 0; memset(reg, 0, sizeof(struct accreg)); reg->account_id=account_id; reg->char_id=char_id; //`global_reg_value` (`type`, `account_id`, `char_id`, `str`, `value`) switch (type) { case 3: //char reg sprintf (tmp_sql, "SELECT `str`, `value` FROM `%s` WHERE `type`=3 AND `char_id`='%d'",reg_db, reg->char_id); break; case 2: //account reg sprintf (tmp_sql, "SELECT `str`, `value` FROM `%s` WHERE `type`=2 AND `account_id`='%d'",reg_db, reg->account_id); break; case 1: //account2 reg ShowError("inter_accreg_fromsql: Char server shouldn't handle type 1 registry values (##). That is the login server's work!\n"); return 0; } if(mysql_query(&mysql_handle, tmp_sql) ) { ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } sql_res = mysql_store_result(&mysql_handle); if (sql_res) { for(j=0; (sql_row = mysql_fetch_row(sql_res)); j++) { strcpy(reg->reg[j].str, sql_row[0]); strcpy(reg->reg[j].value, sql_row[1]); } mysql_free_result(sql_res); } reg->reg_num=j; return 1; }
int quest_read_db(void) { int QuestLoop, QueryLoop, MaxQuestLoop = 0; if(SQL_ERROR == Sql_Query(dbmysql_handle, "SELECT * FROM `%s`", get_database_name(50))) { Sql_ShowDebug(dbmysql_handle); return -1; } while(SQL_SUCCESS == Sql_NextRow(dbmysql_handle) && MaxQuestLoop < MAX_QUEST_DB) { char *row[9]; for(QueryLoop = 0; QueryLoop < 9; ++QueryLoop) Sql_GetData(dbmysql_handle, QueryLoop, &row[QueryLoop], NULL); memset(&quest_db[MaxQuestLoop], 0, sizeof(quest_db[0])); quest_db[MaxQuestLoop].id = atoi(row[0]); quest_db[MaxQuestLoop].time = atoi(row[1]); for(QuestLoop = 0; QuestLoop < MAX_QUEST_OBJECTIVES; QuestLoop++) { quest_db[MaxQuestLoop].mob[QuestLoop] = atoi(row[2*QuestLoop+2]); quest_db[MaxQuestLoop].count[QuestLoop] = atoi(row[2*QuestLoop+3]); if(!quest_db[MaxQuestLoop].mob[QuestLoop] || !quest_db[MaxQuestLoop].count[QuestLoop]) break; } quest_db[MaxQuestLoop].num_objectives = QuestLoop; MaxQuestLoop++; } ShowSQL("Leitura de '"CL_WHITE"%lu"CL_RESET"' entradas na tabela '"CL_WHITE"%s"CL_RESET"'.\n", MaxQuestLoop, get_database_name(50)); Sql_FreeResult(dbmysql_handle); return 0; }
/*====================================== * SQL *=================================== */ static int itemdb_read_sqldb(void) { unsigned short nameid; struct item_data *id; char script[65535 + 2 + 1]; // Maximum length of MySQL TEXT type (65535) + 2 bytes for curly brackets + 1 byte for terminator char *item_db_name[] = { item_db_db, item_db2_db }; long unsigned int ln = 0; int i; // ---------- for (i = 0; i < 2; i++) { sprintf(tmp_sql, "SELECT * FROM `%s`", item_db_name[i]); // Execute the query; if the query execution succeeded... if (mysql_query(&mmysql_handle, tmp_sql) == 0) { sql_res = mysql_store_result(&mmysql_handle); // If the storage of the query result succeeded... if (sql_res) { // Parse each row in the query result into sql_row while ((sql_row = mysql_fetch_row(sql_res))) { /*Table structure is: 00 id 01 name_english 02 name_japanese 03 type 04 price_buy 05 price_sell 06 weight 07 attack 08 defence 09 range 10 slots 11 equip_jobs 12 equip_upper 13 equip_genders 14 equip_locations 15 weapon_level 16 equip_level 17 refineable 18 view 19 script 20 equip_script 21 unequip_script */ nameid = atoi(sql_row[0]); // If the identifier is not within the valid range, process the next row if (nameid == 0) continue; ln++; // ---------- id = itemdb_load(nameid); strncpy(id->name, sql_row[1], ITEM_NAME_LENGTH-1); strncpy(id->jname, sql_row[2], ITEM_NAME_LENGTH-1); id->type = atoi(sql_row[3]); if (id->type == IT_DELAYCONSUME) { //Items that are consumed upon target confirmation //(yggdrasil leaf, spells & pet lures) [Skotlex] id->type = IT_USABLE; id->flag.delay_consume=1; } else //In case of an itemdb reload and the item type changed. id->flag.delay_consume=0; // If price_buy is not NULL and price_sell is not NULL... if ((sql_row[4] != NULL) && (sql_row[5] != NULL)) { id->value_buy = atoi(sql_row[4]); id->value_sell = atoi(sql_row[5]); } // If price_buy is not NULL and price_sell is NULL... else if ((sql_row[4] != NULL) && (sql_row[5] == NULL)) { id->value_buy = atoi(sql_row[4]); id->value_sell = atoi(sql_row[4]) / 2; } // If price_buy is NULL and price_sell is not NULL... else if ((sql_row[4] == NULL) && (sql_row[5] != NULL)) { id->value_buy = atoi(sql_row[5]) * 2; id->value_sell = atoi(sql_row[5]); } // If price_buy is NULL and price_sell is NULL... if ((sql_row[4] == NULL) && (sql_row[5] == NULL)) { id->value_buy = 0; id->value_sell = 0; } id->weight = atoi(sql_row[6]); id->atk = (sql_row[7] != NULL) ? atoi(sql_row[7]) : 0; id->def = (sql_row[8] != NULL) ? atoi(sql_row[8]) : 0; id->range = (sql_row[9] != NULL) ? atoi(sql_row[9]) : 0; id->slot = (sql_row[10] != NULL) ? atoi(sql_row[10]) : 0; if (id->slot > MAX_SLOTS) { ShowWarning("itemdb_read_sqldb: Item %d (%s) specifies %d slots, but the server only supports up to %d\n", nameid, id->jname, id->slot, MAX_SLOTS); id->slot = MAX_SLOTS; } itemdb_jobid2mapid(id->class_base, (sql_row[11] != NULL) ? (unsigned int)strtoul(sql_row[11], NULL, 0) : 0); id->class_upper= (sql_row[12] != NULL) ? atoi(sql_row[12]) : 0; id->sex = (sql_row[13] != NULL) ? atoi(sql_row[13]) : 0; id->equip = (sql_row[14] != NULL) ? atoi(sql_row[14]) : 0; if (!id->equip && itemdb_isequip2(id)) { ShowWarning("Item %d (%s) is an equipment with no equip-field! Making it an etc item.\n", nameid, id->jname); id->type = 3; } id->wlv = (sql_row[15] != NULL) ? atoi(sql_row[15]) : 0; id->elv = (sql_row[16] != NULL) ? atoi(sql_row[16]) : 0; id->flag.no_refine = (sql_row[17] == NULL || atoi(sql_row[17]) == 1)?0:1; id->look = (sql_row[18] != NULL) ? atoi(sql_row[18]) : 0; id->view_id = 0; id->sex = itemdb_gendercheck(id); //Apply gender filtering. // ---------- if (id->script) script_free_code(id->script); if (sql_row[19] != NULL) { if (sql_row[19][0] == '{') id->script = parse_script(sql_row[19],item_db_name[i], ln, 0); else { sprintf(script, "{%s}", sql_row[19]); id->script = parse_script(script, item_db_name[i], ln, 0); } } else id->script = NULL; if (id->equip_script) script_free_code(id->equip_script); if (sql_row[20] != NULL) { if (sql_row[20][0] == '{') id->equip_script = parse_script(sql_row[20], item_db_name[i], ln, 0); else { sprintf(script, "{%s}", sql_row[20]); id->equip_script = parse_script(script, item_db_name[i], ln, 0); } } else id->equip_script = NULL; if (id->unequip_script) script_free_code(id->unequip_script); if (sql_row[21] != NULL) { if (sql_row[21][0] == '{') id->unequip_script = parse_script(sql_row[21],item_db_name[i], ln, 0); else { sprintf(script, "{%s}", sql_row[21]); id->unequip_script = parse_script(script, item_db_name[i], ln, 0); } } else id->unequip_script = NULL; // ---------- id->flag.available = 1; id->flag.value_notdc = 0; id->flag.value_notoc = 0; } ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, item_db_name[i]); ln = 0; } else { ShowSQL("DB error (%s) - %s\n",item_db_name[i], mysql_error(&mmysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } // Free the query result mysql_free_result(sql_res); } else { ShowSQL("DB error (%s) - %s\n",item_db_name[i], mysql_error(&mmysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } } return 0; }
// Wisp/page request to send int mapif_parse_WisRequest(int fd) { struct WisData* wd; static int wisid = 0; char name[NAME_LENGTH], t_name[NAME_LENGTH*2]; //Needs space to allocate names with escaped chars [Skotlex] if ( fd <= 0 ) {return 0;} // check if we have a valid fd if (RFIFOW(fd,2)-52 >= sizeof(wd->msg)) { ShowWarning("inter: Wis message size too long.\n"); return 0; } else if (RFIFOW(fd,2)-52 <= 0) { // normaly, impossible, but who knows... ShowError("inter: Wis message doesn't exist.\n"); return 0; } memcpy(name, RFIFOP(fd,28), NAME_LENGTH); //Received name may be too large and not contain \0! [Skotlex] name[NAME_LENGTH-1]= '\0'; sprintf (tmp_sql, "SELECT `name` FROM `%s` WHERE `name`='%s'", char_db, jstrescapecpy(t_name, name)); if(mysql_query(&mysql_handle, tmp_sql) ) { ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } sql_res = mysql_store_result(&mysql_handle); // search if character exists before to ask all map-servers if (!(sql_row = mysql_fetch_row(sql_res))) { 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); // Character exists. So, ask all map-servers } else { // to be sure of the correct name, rewrite it memset(name, 0, NAME_LENGTH); strncpy(name, sql_row[0], NAME_LENGTH); // if source is destination, don't ask other servers. if (strcmp((char*)RFIFOP(fd,4),name) == 0) { 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 { 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(); numdb_insert(wis_db, wd->id, wd); mapif_wis_message(wd); } } //Freeing ... O.o if(sql_res){ mysql_free_result(sql_res); } return 0; }
// initialize int inter_init(const char *file) { //int i; ShowInfo ("interserver initialize...\n"); inter_config_read(file); //DB connection initialized mysql_init(&mysql_handle); ShowInfo("Connect Character DB server.... (Character Server)\n"); if(!mysql_real_connect(&mysql_handle, char_server_ip, char_server_id, char_server_pw, char_server_db ,char_server_port, (char *)NULL, 0)) { //pointer check ShowFatalError("%s\n",mysql_error(&mysql_handle)); exit(1); } else if (inter_sql_test()) { ShowStatus("Connect Success! (Character Server)\n"); } if(char_gm_read) { mysql_init(&lmysql_handle); ShowInfo("Connect Character DB server.... (login server)\n"); if(!mysql_real_connect(&lmysql_handle, login_server_ip, login_server_id, login_server_pw, login_server_db ,login_server_port, (char *)NULL, 0)) { //pointer check ShowFatalError("%s\n",mysql_error(&lmysql_handle)); exit(1); } else { ShowStatus ("Connect Success! (Login Server)\n"); } } if(strlen(default_codepage) > 0 ) { sprintf( tmp_sql, "SET NAMES %s", default_codepage ); if (mysql_query(&mysql_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } if(char_gm_read) if (mysql_query(&lmysql_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&lmysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } } wis_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int)); inter_guild_sql_init(); inter_storage_sql_init(); inter_party_sql_init(); inter_pet_sql_init(); inter_accreg_sql_init(); //printf ("interserver timer initializing : %d sec...\n",autosave_interval); //i=add_timer_interval(gettick()+autosave_interval,inter_save_timer,0,0,autosave_interval); if (connection_ping_interval) { add_timer_func_list(inter_sql_ping, "inter_sql_ping"); add_timer_interval(gettick()+connection_ping_interval*60*60*1000, inter_sql_ping, 0, 0, connection_ping_interval*60*60*1000); } return 0; }
int read_elementaldb(void) { struct s_elemental_db *db; struct status_data *status; int count = 0, ele; memset(elemental_db,0,sizeof(elemental_db)); if(SQL_ERROR == Sql_Query(dbmysql_handle, "SELECT * FROM `%s`", get_database_name(36))) { Sql_ShowDebug(dbmysql_handle); return -1; } while(SQL_SUCCESS == Sql_NextRow(dbmysql_handle) && count < MAX_ELEMENTAL_CLASS) { char *row[26]; int i; for(i = 0; i != 26; ++i) Sql_GetData(dbmysql_handle, i, &row[i], NULL); db = &elemental_db[count]; db->class_ = atoi(row[0]); safestrncpy(db->sprite, row[1], NAME_LENGTH); safestrncpy(db->name, row[2], NAME_LENGTH); db->lv = atoi(row[3]); status = &db->status; db->vd.class_ = db->class_; status->max_hp = atoi(row[4]); status->max_sp = atoi(row[5]); status->rhw.range = atoi(row[6]); status->rhw.atk = atoi(row[7]); status->rhw.atk2 = atoi(row[8]); status->def = atoi(row[9]); status->mdef = atoi(row[10]); status->str = atoi(row[11]); status->agi = atoi(row[12]); status->vit = atoi(row[13]); status->int_ = atoi(row[14]); status->dex = atoi(row[15]); status->luk = atoi(row[16]); db->range2 = atoi(row[17]); db->range3 = atoi(row[18]); status->size = atoi(row[19]); status->race = atoi(row[20]); ele = atoi(row[21]); status->def_ele = ele%10; status->ele_lv = ele/20; if(status->def_ele >= ELE_MAX) { ShowWarning("Elemental %d tem o tipo de elemento inválido %d (elemento máximo ? %d)\n", db->class_, status->def_ele, ELE_MAX - 1); status->def_ele = ELE_NEUTRAL; } if(status->ele_lv < 1 || status->ele_lv > 4) { ShowWarning("Elemental %d tem nível de elemento inválido %d (máximo ? 4)\n", db->class_, status->ele_lv); status->ele_lv = 1; } status->aspd_rate = 1000; status->speed = atoi(row[22]); status->adelay = atoi(row[23]); status->amotion = atoi(row[24]); status->dmotion = atoi(row[25]); ++count; } ShowSQL("Leitura de '"CL_WHITE"%lu"CL_RESET"' entradas na tabela '"CL_WHITE"%s"CL_RESET"'.\n", count, get_database_name(36)); Sql_FreeResult(dbmysql_handle); return 0; }
int mail_check(struct map_session_data *sd,int type) { int i = 0, new_ = 0, priority = 0; char message[80]; nullpo_retr (0, sd); sprintf(tmp_sql,"SELECT `message_id`,`to_account_id`,`from_char_name`,`read_flag`,`priority`,`check_flag` " "FROM `%s` WHERE `to_account_id` = \"%d\" ORDER by `message_id`", mail_db, sd->status.account_id); if (mysql_query(&mail_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); return 0; } mail_res = mysql_store_result(&mail_handle); if(mail_res) { if (mysql_num_rows(mail_res) == 0) { //clif_displaymessage(sd->fd,"You have no messages."); clif_displaymessage(sd->fd, msg_txt(516)); mysql_free_result(mail_res); return 0; } while ((mail_row = mysql_fetch_row(mail_res))) { i++; if(!atoi(mail_row[5])) { sprintf(tmp_sql,"UPDATE `%s` SET `check_flag`='1' WHERE `message_id`= \"%d\"", mail_db, atoi(mail_row[0])); if(mysql_query(&mail_handle, tmp_sql) ) { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } } if(!atoi(mail_row[3])) { new_++; if(atoi(mail_row[4])) priority++; if(type==2 || type==3) { if(atoi(mail_row[4])) { snprintf(message, 80, msg_txt(511), i, mail_row[2]); clif_displaymessage(sd->fd, message); } else { //sprintf(message, "%d - From : %s (New)", i, mail_row[2]); snprintf(message, 80, msg_txt(512), i, mail_row[2]); clif_displaymessage(sd->fd, message); } } } else if(type==2){ snprintf(message, 80, msg_txt(513), i, mail_row[2]); clif_displaymessage(sd->fd, message); } } mysql_free_result(mail_res); } else { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); return 0; } if(i>0 && new_>0 && type==1) { //sprintf(message, "You have %d new messages.", new_); sprintf(message, msg_txt(514), new_); clif_displaymessage(sd->fd, jstrescape(message)); } if(i>0 && new_>0 && priority>0 && type==1) { //sprintf(message, "You have %d unread priority messages.", priority); sprintf(message, msg_txt(515), priority); clif_displaymessage(sd->fd, jstrescape(message)); } if(!new_) { //clif_displaymessage(sd->fd, "You have no new messages."); clif_displaymessage(sd->fd, msg_txt(516)); } return 0; }
/// Fetches the next row. int SqlStmt_NextRow(SqlStmt* self) { int err; size_t i; size_t cols; MYSQL_BIND* column; unsigned long length; if( self == NULL ) return SQL_ERROR; // bind columns if( self->bind_columns && mysql_stmt_bind_result(self->stmt, self->columns) ) err = 1;// error binding columns else err = mysql_stmt_fetch(self->stmt);// fetch row // check for errors if( err == MYSQL_NO_DATA ) return SQL_NO_DATA; #if defined(MYSQL_DATA_TRUNCATED) // MySQL 5.0/5.1 defines and returns MYSQL_DATA_TRUNCATED [FlavioJS] if( err == MYSQL_DATA_TRUNCATED ) { my_bool truncated; if( !self->bind_columns ) { ShowSQL("DB error - data truncated (unknown source, columns are not bound)\n"); return SQL_ERROR; } // find truncated column cols = SqlStmt_NumColumns(self); for( i = 0; i < cols; ++i ) { column = &self->columns[i]; column->error = &truncated; mysql_stmt_fetch_column(self->stmt, column, (unsigned int)i, 0); column->error = NULL; if( truncated ) {// report truncated column SqlStmt_P_ShowDebugTruncatedColumn(self, i); return SQL_ERROR; } } ShowSQL("DB error - data truncated (unknown source)\n"); return SQL_ERROR; } #endif if( err ) { ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt)); hercules_mysql_error_handler(mysql_stmt_errno(self->stmt)); return SQL_ERROR; } // propagate column lengths and clear unused parts of string/enum/blob buffers cols = SqlStmt_NumColumns(self); for( i = 0; i < cols; ++i ) { length = self->column_lengths[i].length; column = &self->columns[i]; #if !defined(MYSQL_DATA_TRUNCATED) // MySQL 4.1/(below?) returns success even if data is truncated, so we test truncation manually [FlavioJS] if( column->buffer_length < length ) {// report truncated column if( column->buffer_type == MYSQL_TYPE_STRING || column->buffer_type == MYSQL_TYPE_BLOB ) {// string/enum/blob column SqlStmt_P_ShowDebugTruncatedColumn(self, i); return SQL_ERROR; } // FIXME numeric types and null [FlavioJS] } #endif if( self->column_lengths[i].out_length ) *self->column_lengths[i].out_length = (uint32)length; if( column->buffer_type == MYSQL_TYPE_STRING ) {// clear unused part of the string/enum buffer (and nul-terminate) memset((char*)column->buffer + length, 0, column->buffer_length - length + 1); } else if( column->buffer_type == MYSQL_TYPE_BLOB && length < column->buffer_length ) {// clear unused part of the blob buffer memset((char*)column->buffer + length, 0, column->buffer_length - length); } } return SQL_SUCCESS; }
int mail_send(struct map_session_data *sd, char *name, char *message, int flag) { nullpo_retr (0, sd); if(pc_isGM(sd) < 80 && sd->mail_counter > 0) { //clif_displaymessage(sd->fd,"You must wait 10 minutes before sending another message"); clif_displaymessage(sd->fd,msg_txt(522)); return 0; } if(strcmp(name,"*")==0) { if(pc_isGM(sd) < 80) { //clif_displaymessage(sd->fd, "Access Denied."); clif_displaymessage(sd->fd, msg_txt(523)); return 0; } else sprintf(tmp_sql,"SELECT DISTINCT `account_id` FROM `%s` WHERE `account_id` <> '%d' ORDER BY `account_id`", char_db, sd->status.account_id); } else sprintf(tmp_sql,"SELECT `account_id`,`name` FROM `%s` WHERE `name` = \"%s\"", char_db, jstrescape(name)); if (mysql_query(&mail_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); return 0; } mail_res = mysql_store_result(&mail_handle); if(mail_res) { if (mysql_num_rows(mail_res) == 0) { mysql_free_result(mail_res); //clif_displaymessage(sd->fd,"Character does not exist."); clif_displaymessage(sd->fd,msg_txt(524)); return 0; } while ((mail_row = mysql_fetch_row(mail_res))) { if(strcmp(name,"*")==0) { sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`to_account_id`,`from_account_id`,`from_char_name`,`message`,`priority`)" " VALUES ('%d', '%d', '%s', '%s', '%d')",mail_db, atoi(mail_row[0]), sd->status.account_id, sd->status.name, jstrescape(message), flag); } else { sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`to_account_id`,`to_char_name`,`from_account_id`,`from_char_name`,`message`,`priority`)" " VALUES ('%d', '%s', '%d', '%s', '%s', '%d')",mail_db, atoi(mail_row[0]), mail_row[1], sd->status.account_id, sd->status.name, jstrescape(message), flag); if(pc_isGM(sd) < 80) sd->mail_counter=5; } if(mysql_query(&mail_handle, tmp_sql) ) { mysql_free_result(mail_res); ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); return 0; } } } //clif_displaymessage(sd->fd,"Mail has been sent."); clif_displaymessage(sd->fd,msg_txt(525)); return 0; }