std::vector<ahHistory*> CDataLoader::GetAHItemHystory(uint16 ItemID, bool stack) { std::vector<ahHistory*> HistoryList; const char* fmtQuery = "SELECT sale, sell_date, seller_name, buyer_name " "FROM auction_house " "WHERE itemid = %u AND stack = %u AND buyer_name IS NOT NULL " "ORDER BY sell_date DESC " "LIMIT 10"; int32 ret = Sql_Query(SqlHandle, fmtQuery, ItemID, stack); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while (Sql_NextRow(SqlHandle) == SQL_SUCCESS) { ahHistory* PAHHistory = new ahHistory; PAHHistory->Price = Sql_GetUIntData(SqlHandle, 0); PAHHistory->Data = Sql_GetUIntData(SqlHandle, 1); snprintf((char*)PAHHistory->Name1, 15, "%s", Sql_GetData(SqlHandle, 2)); snprintf((char*)PAHHistory->Name2, 15, "%s", Sql_GetData(SqlHandle, 3)); HistoryList.push_back(PAHHistory); } std::reverse(HistoryList.begin(), HistoryList.end()); } return HistoryList; }
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 }
bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc) { char* data; memset(merc, 0, sizeof(struct s_mercenary)); merc->mercenary_id = merc_id; merc->char_id = char_id; if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `class`, `hp`, `sp`, `kill_counter`, `life_time` FROM `%s` WHERE `mer_id` = '%d' AND `char_id` = '%d'", mercenary_db, merc_id, char_id) ) { Sql_ShowDebug(sql_handle); return false; } if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) { Sql_FreeResult(sql_handle); return false; } Sql_GetData(sql_handle, 0, &data, NULL); merc->class_ = atoi(data); Sql_GetData(sql_handle, 1, &data, NULL); merc->hp = atoi(data); Sql_GetData(sql_handle, 2, &data, NULL); merc->sp = atoi(data); Sql_GetData(sql_handle, 3, &data, NULL); merc->kill_count = atoi(data); Sql_GetData(sql_handle, 4, &data, NULL); merc->life_time = atoi(data); Sql_FreeResult(sql_handle); if( save_log ) ShowInfo("Assitentes carregados (%d - %d).\n", merc->mercenary_id, merc->char_id); return true; }
/*========================================== * [Zephyrus] Serial Database *------------------------------------------*/ static int itemdb_load_serials(void) { int nameid, count = 0; struct item_data *id; unsigned int serial; char *data; if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `nameid`, `serial` FROM `item_serials`") ) { Sql_ShowDebug(mmysql_handle); return 0; } while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) ) { Sql_GetData(mmysql_handle, 0, &data, NULL); nameid = atoi(data); Sql_GetData(mmysql_handle, 1, &data, NULL); serial = atol(data); if( (id = itemdb_exists(nameid)) == NULL ) continue; id->last_serial = serial; ++count; } // free the query result Sql_FreeResult(mmysql_handle); ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"item_serials"CL_RESET"'.\n", count); return 0; }
/*************************************************************** Loads the given battlefield from the database and returns a new Battlefield object. ****************************************************************/ CBattlefield* loadBattlefield(CBattlefieldHandler* hand, uint16 bcnmid, BATTLEFIELDTYPE type) { const char* fmtQuery = "SELECT name, bcnmId, fastestName, fastestTime, timeLimit, levelCap, lootDropId, rules, partySize, zoneId, fastestPartySize, isMission \ FROM bcnm_info \ WHERE bcnmId = %u"; int32 ret = Sql_Query(SqlHandle, fmtQuery, bcnmid); if (ret == SQL_ERROR || Sql_NumRows(SqlHandle) == 0 || Sql_NextRow(SqlHandle) != SQL_SUCCESS) { ShowError("Cannot load battlefield BCNM:%i \n", bcnmid); } else { CBattlefield* PBattlefield = new CBattlefield(hand, Sql_GetUIntData(SqlHandle, 1), type); char* tmpName = nullptr; Sql_GetData(SqlHandle, 0, &tmpName, nullptr); PBattlefield->setBcnmName((int8*)tmpName); PBattlefield->setTimeLimit(std::chrono::seconds(Sql_GetUIntData(SqlHandle, 4))); PBattlefield->setLevelCap(Sql_GetUIntData(SqlHandle, 5)); PBattlefield->setLootId(Sql_GetUIntData(SqlHandle, 6)); PBattlefield->setMaxParticipants(Sql_GetUIntData(SqlHandle, 8)); PBattlefield->setZoneId(Sql_GetUIntData(SqlHandle, 9)); PBattlefield->m_RuleMask = (uint16)Sql_GetUIntData(SqlHandle, 7); PBattlefield->m_isMission = (uint8)Sql_GetUIntData(SqlHandle, 11); PBattlefield->setRecord((const char*)Sql_GetData(SqlHandle, 2), (uint8)Sql_GetUIntData(SqlHandle, 10), std::chrono::seconds((uint32)Sql_GetUIntData(SqlHandle, 3))); return PBattlefield; } return nullptr; }
void LoadLinkshellList() { int32 ret = Sql_Query(SqlHandle, "SELECT linkshellid, color, name, poster, message, messagetime FROM linkshells"); if( ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while(Sql_NextRow(SqlHandle) == SQL_SUCCESS) { CLinkshell* PLinkshell = new CLinkshell(Sql_GetUIntData(SqlHandle,0)); PLinkshell->setColor(Sql_GetIntData(SqlHandle,1)); int8 EncodedName[16]; EncodeStringLinkshell(Sql_GetData(SqlHandle,2), EncodedName); PLinkshell->setName(EncodedName); PLinkshell->setPoster(Sql_GetData(SqlHandle,3)); int8* linkshellMessage = Sql_GetData(SqlHandle, 4); if (linkshellMessage != nullptr) PLinkshell->setMessage(linkshellMessage); else PLinkshell->setMessage(""); PLinkshell->setMessageTime(Sql_GetUIntData(SqlHandle,5)); LinkshellList[PLinkshell->getID()] = PLinkshell; } } }
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); }
int mail_timer_sub( int limit, enum mail_inbox_type type ){ struct{ int mail_id; int char_id; int account_id; }mails[MAIL_MAX_INBOX]; int i, map_fd; char* data; struct online_char_data* character; if( limit <= 0 ){ return 0; } memset(mails, 0, sizeof(mails)); if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id`,`char_id`,`account_id` FROM `%s` `m` INNER JOIN `%s` `c` ON `c`.`char_id`=`m`.`dest_id` WHERE `type` = '%d' AND `time` <= UNIX_TIMESTAMP( NOW() - INTERVAL %d DAY ) ORDER BY `id` LIMIT %d", schema_config.mail_db, schema_config.char_db, type, limit, MAIL_MAX_INBOX + 1) ){ Sql_ShowDebug(sql_handle); return 0; } if( Sql_NumRows(sql_handle) <= 0 ){ return 0; } for( i = 0; i < MAIL_MAX_INBOX && SQL_SUCCESS == Sql_NextRow(sql_handle); i++ ){ Sql_GetData(sql_handle, 0, &data, NULL); mails[i].mail_id = atoi(data); Sql_GetData(sql_handle, 1, &data, NULL); mails[i].char_id = atoi(data); Sql_GetData(sql_handle, 2, &data, NULL); mails[i].account_id = atoi(data); } Sql_FreeResult(sql_handle); for( i = 0; i < MAIL_MAX_INBOX; i++ ){ if( mails[i].mail_id == 0 ){ break; } // Check for online players if( ( character = (struct online_char_data*)idb_get(char_get_onlinedb(), mails[i].account_id) ) != NULL && character->server >= 0 ){ map_fd = map_server[character->server].fd; }else{ map_fd = 0; } if( type == MAIL_INBOX_NORMAL ){ mapif_Mail_return( 0, mails[i].char_id, mails[i].mail_id ); mapif_Mail_delete( map_fd, mails[i].char_id, mails[i].mail_id, true ); }else if( type == MAIL_INBOX_RETURNED ){ mapif_Mail_delete( map_fd, mails[i].char_id, mails[i].mail_id, false ); }else{ // Should not happen continue; } } return 0; }
void CZone::LoadZoneSettings() { static const int8* Query = "SELECT " "zone.name," "zone.zoneip," "zone.zoneport," "zone.music_day," "zone.music_night," "zone.battlesolo," "zone.battlemulti," "zone.tax," "zone.misc," "zone.navmesh," "zone.zonetype," "bcnm.name " "FROM zone_settings AS zone " "LEFT JOIN bcnm_info AS bcnm " "USING (zoneid) " "WHERE zoneid = %u " "LIMIT 1"; if (Sql_Query(SqlHandle, Query, m_zoneID) != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS) { m_zoneName.insert(0, Sql_GetData(SqlHandle,0)); m_zoneIP = inet_addr(Sql_GetData(SqlHandle,1)); m_zonePort = (uint16)Sql_GetUIntData(SqlHandle,2); m_zoneMusic.m_songDay = (uint8)Sql_GetUIntData(SqlHandle, 3); // background music (day) m_zoneMusic.m_songNight = (uint8)Sql_GetUIntData(SqlHandle, 4); // background music (night) m_zoneMusic.m_bSongS = (uint8)Sql_GetUIntData(SqlHandle,5); // solo battle music m_zoneMusic.m_bSongM = (uint8)Sql_GetUIntData(SqlHandle,6); // party battle music m_tax = (uint16)(Sql_GetFloatData(SqlHandle,7) * 100); // tax for bazaar m_miscMask = (uint16)Sql_GetUIntData(SqlHandle,8); m_useNavMesh = (bool)Sql_GetIntData(SqlHandle,9); m_zoneType = (ZONETYPE)Sql_GetUIntData(SqlHandle, 10); if (Sql_GetData(SqlHandle,11) != nullptr) // сейчас нельзя использовать bcnmid, т.к. они начинаются с нуля { m_BattlefieldHandler = new CBattlefieldHandler(m_zoneID); } if (m_miscMask & MISC_TREASURE) { m_TreasurePool = new CTreasurePool(TREASUREPOOL_ZONE); } } else { ShowFatalError(CL_RED"CZone::LoadZoneSettings: Cannot load zone settings (%u)\n" CL_RESET, m_zoneID); } }
// Load account_reg from sql (type=2) int inter_accreg_fromsql (int account_id, int char_id, struct accreg *reg, int type) { struct global_reg *r; char *data; size_t len; int i; 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 if (SQL_ERROR == Sql_Query (sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id)) Sql_ShowDebug (sql_handle); break; case 2: //account reg if (SQL_ERROR == Sql_Query (sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=2 AND `account_id`='%d'", reg_db, account_id)) Sql_ShowDebug (sql_handle); break; case 1: //account2 reg ShowError ("inter_accreg_fromsql: char-server não deveria manusear registros de valor tipo 1 (##). Isto é trabalho do login-server!\n"); return 0; default: ShowError ("inter_accreg_fromsql: Tipo inválido: %d\n", type); return 0; } for (i = 0; i < MAX_REG_NUM && SQL_SUCCESS == Sql_NextRow (sql_handle); ++i) { r = ®->reg[i]; // str Sql_GetData (sql_handle, 0, &data, &len); memcpy (r->str, data, min (len, sizeof (r->str))); // value Sql_GetData (sql_handle, 1, &data, &len); memcpy (r->value, data, min (len, sizeof (r->value))); } reg->reg_num = i; Sql_FreeResult (sql_handle); return 1; }
/// Load guild_storage data to mem int storage_fromsql(int account_id, struct storage_data* p) { StringBuf buf; struct item* item; char* data; int i; int j; memset(p, 0, sizeof(struct storage_data)); //clean up memory p->storage_amount = 0; // storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`} StringBuf_Init(&buf); StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`"); for( j = 0; j < MAX_SLOTS; ++j ) StringBuf_Printf(&buf, ",`card%d`", j); StringBuf_Printf(&buf, " FROM `%s` WHERE `account_id`='%d' ORDER BY `nameid`", storage_db, account_id); if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) ) Sql_ShowDebug(sql_handle); StringBuf_Destroy(&buf); for( i = 0; i < MAX_STORAGE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) { item = &p->items[i]; Sql_GetData(sql_handle, 0, &data, NULL); item->id = atoi(data); Sql_GetData(sql_handle, 1, &data, NULL); item->nameid = atoi(data); Sql_GetData(sql_handle, 2, &data, NULL); item->amount = atoi(data); Sql_GetData(sql_handle, 3, &data, NULL); item->equip = atoi(data); Sql_GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data); Sql_GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data); Sql_GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data); Sql_GetData(sql_handle, 7, &data, NULL); item->expire_time = (unsigned int)atoi(data); for( j = 0; j < MAX_SLOTS; ++j ) { Sql_GetData(sql_handle, 8+j, &data, NULL); item->card[j] = atoi(data); } } p->storage_amount = i; Sql_FreeResult(sql_handle); ShowInfo("storage load complete from DB - id: %d (total: %d)\n", account_id, p->storage_amount); return 1; }
void CInstance::LoadInstance() { static const int8* Query = "SELECT " "instance_name, " "time_limit, " "entrance_zone, " "start_x, " "start_y, " "start_z, " "start_rot " "FROM instance_list " "WHERE instanceid = %u " "LIMIT 1"; if (Sql_Query(SqlHandle, Query, m_instanceid) != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS) { m_instanceName.insert(0, Sql_GetData(SqlHandle, 0)); m_timeLimit = Sql_GetUIntData(SqlHandle, 1); m_entrance = Sql_GetUIntData(SqlHandle, 2); m_entryloc.x = Sql_GetFloatData(SqlHandle, 3); m_entryloc.y = Sql_GetFloatData(SqlHandle, 4); m_entryloc.z = Sql_GetFloatData(SqlHandle, 5); m_entryloc.rotation = Sql_GetUIntData(SqlHandle, 6); } else { ShowFatalError(CL_RED"CZone::LoadInstance: Cannot load instance %u\n" CL_RESET, m_instanceid); } }
void LoadEffectsParameters() { for (uint16 i = 0; i < MAX_EFFECTID; ++i) { EffectsParams[i].Flag = 0; } int32 ret = Sql_Query(SqlHandle, "SELECT id, name, flags, type, negative_id, overwrite, block_id, remove_id, element, min_duration FROM status_effects WHERE id < %u", MAX_EFFECTID); if( ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while(Sql_NextRow(SqlHandle) == SQL_SUCCESS) { uint16 EffectID = (uint16)Sql_GetIntData(SqlHandle,0); EffectsParams[EffectID].Name = Sql_GetData(SqlHandle,1); EffectsParams[EffectID].Flag = Sql_GetIntData(SqlHandle,2); EffectsParams[EffectID].Type = Sql_GetIntData(SqlHandle,3); EffectsParams[EffectID].NegativeId = (EFFECT)Sql_GetIntData(SqlHandle,4); EffectsParams[EffectID].Overwrite = (EFFECTOVERWRITE)Sql_GetIntData(SqlHandle,5); EffectsParams[EffectID].BlockId = (EFFECT)Sql_GetIntData(SqlHandle,6); EffectsParams[EffectID].RemoveId = (EFFECT)Sql_GetIntData(SqlHandle,7); EffectsParams[EffectID].Element = Sql_GetIntData(SqlHandle,8); // convert from second to millisecond EffectsParams[EffectID].MinDuration = Sql_GetIntData(SqlHandle,9) * 1000; } } }
/** * Retrieve data from db and store it in the provided data structure. * Doesn't actually retrieve data yet: escapes and checks userid, then transforms it to accid for fetching. * Filled data structure is done by delegation to account_db_sql_load_num. * @param self: pointer to db * @param acc: pointer of mmo_account to fill * @param userid: name of user account * @return true if successful, false if something has failed */ static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, const char* userid) { AccountDB_SQL* db = (AccountDB_SQL*)self; Sql* sql_handle = db->accounts; char esc_userid[2*NAME_LENGTH+1]; uint32 account_id; char* data; Sql_EscapeString(sql_handle, esc_userid, userid); // get the list of account IDs for this user ID if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `userid`= %s '%s'", db->account_db, (db->case_sensitive ? "BINARY" : ""), esc_userid) ) { Sql_ShowDebug(sql_handle); return false; } if( Sql_NumRows(sql_handle) > 1 ) {// serious problem - duplicit account ShowError("account_db_sql_load_str: multiple accounts found when retrieving data for account '%s'!\n", userid); Sql_FreeResult(sql_handle); return false; } if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) {// no such entry Sql_FreeResult(sql_handle); return false; } Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); return account_db_sql_load_num(self, acc, account_id); }
void LoadSetSpells(CCharEntity* PChar) { if (PChar->GetMJob() == JOB_BLU || PChar->GetSJob() == JOB_BLU) { const int8* Query = "SELECT set_blue_spells FROM " "chars WHERE charid = %u;"; int32 ret = Sql_Query(SqlHandle,Query,PChar->id); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS) { size_t length = 0; int8* blue_spells = NULL; Sql_GetData(SqlHandle,0,&blue_spells,&length); memcpy(PChar->m_SetBlueSpells, blue_spells, (length > sizeof(PChar->m_SetBlueSpells) ? sizeof(PChar->m_SetBlueSpells) : length)); } for (int slot = 0; slot < 20; slot++) { if (PChar->m_SetBlueSpells[slot] != 0) { CBlueSpell* PSpell = (CBlueSpell*)spell::GetSpell(PChar->m_SetBlueSpells[slot] + 0x200); PChar->addModifiers(&PSpell->modList); } } ValidateBlueSpells(PChar); } }
/*************************************************************** Loads the given instance from the database and returns a new Instance object. ****************************************************************/ CInstance* loadInstance(CInstanceHandler* hand, uint16 bcnmid, INSTANCETYPE type){ const int8* fmtQuery = "SELECT name, bcnmId, fastestName, fastestTime, timeLimit, levelCap, lootDropId, rules, partySize, zoneId \ FROM bcnm_info \ WHERE bcnmId = %u"; int32 ret = Sql_Query(SqlHandle, fmtQuery, bcnmid); if (ret == SQL_ERROR || Sql_NumRows(SqlHandle) == 0 || Sql_NextRow(SqlHandle) != SQL_SUCCESS) { ShowError("Cannot load instance BCNM:%i \n",bcnmid); } else { CInstance* PInstance = new CInstance(hand,Sql_GetUIntData(SqlHandle,1), type); int8* tmpName; Sql_GetData(SqlHandle,0,&tmpName,NULL); PInstance->setBcnmName(tmpName); PInstance->setTimeLimit(Sql_GetUIntData(SqlHandle,4)); PInstance->setLevelCap(Sql_GetUIntData(SqlHandle,5)); PInstance->setLootId(Sql_GetUIntData(SqlHandle,6)); PInstance->setMaxParticipants(Sql_GetUIntData(SqlHandle,8)); PInstance->setZoneId(Sql_GetUIntData(SqlHandle,9)); PInstance->m_RuleMask = (uint16)Sql_GetUIntData(SqlHandle,7); return PInstance; } return NULL; }
/** * Fetches the next account in the database. * @param self: pointer to db iterator * @param acc: pointer of mmo_account to fill * @return true if next account found and filled, false if something has failed */ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account* acc) { AccountDBIterator_SQL* iter = (AccountDBIterator_SQL*)self; AccountDB_SQL* db = (AccountDB_SQL*)iter->db; Sql* sql_handle = db->accounts; char* data; // get next account ID if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `account_id` > '%d' ORDER BY `account_id` ASC LIMIT 1", db->account_db, iter->last_account_id) ) { Sql_ShowDebug(sql_handle); return false; } if( SQL_SUCCESS == Sql_NextRow(sql_handle) && SQL_SUCCESS == Sql_GetData(sql_handle, 0, &data, NULL) && data != NULL ) {// get account data uint32 account_id; account_id = atoi(data); if( mmo_auth_fromsql(db, acc, account_id) ) { iter->last_account_id = account_id; Sql_FreeResult(sql_handle); return true; } } Sql_FreeResult(sql_handle); return false; }
// check ip against active bans list bool ipban_check(uint32 ip) { uint8* p = (uint8*)&ip; char* data = NULL; int matches; if( !login_config.ipban ) return false;// ipban disabled if( SQL_ERROR == Sql_Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `rtime` > NOW() AND (`list` = '%u.*.*.*' OR `list` = '%u.%u.*.*' OR `list` = '%u.%u.%u.*' OR `list` = '%u.%u.%u.%u')", ipban_table, p[3], p[3], p[2], p[3], p[2], p[1], p[3], p[2], p[1], p[0]) ) { Sql_ShowDebug(sql_handle); // close connection because we can't verify their connectivity. return true; } if( SQL_ERROR == Sql_NextRow(sql_handle) ) return true;// Shouldn't happen, but just in case... Sql_GetData(sql_handle, 0, &data, NULL); matches = atoi(data); Sql_FreeResult(sql_handle); return( matches > 0 ); }
void SendBlacklist(CCharEntity* PChar) { std::vector< std::pair< uint32, string_t > > blacklist; // Obtain this users blacklist info.. const int8* sql = "SELECT c.charid, c.charname FROM char_blacklist AS b INNER JOIN chars AS c ON b.charid_target = c.charid WHERE charid_owner = %u;"; if (Sql_Query(SqlHandle, sql, PChar->id) == SQL_ERROR || Sql_NumRows(SqlHandle) == 0) { PChar->pushPacket(new CStopDownloadingPacket(PChar, blacklist)); return; } // Loop and build blacklist.. int currentCount = 0; while (Sql_NextRow(SqlHandle) == SQL_SUCCESS) { uint32 accid_target = Sql_GetUIntData(SqlHandle, 0); string_t targetName = string_t(Sql_GetData(SqlHandle, 1)); blacklist.push_back(std::make_pair(accid_target, targetName)); currentCount++; if (currentCount >= 12) { PChar->pushPacket(new CStopDownloadingPacket(PChar, blacklist)); blacklist.clear(); currentCount = 0; } } // Push remaining entries.. if (blacklist.size() != 0) PChar->pushPacket(new CStopDownloadingPacket(PChar, blacklist)); }
int32 Sql_GetColumnNames(Sql_t* self, const char* table, char* out_buf, size_t buf_len, char sep) { char* data; size_t len; size_t off = 0; if( self == NULL || SQL_ERROR == Sql_Query(self, "EXPLAIN `%s`", table) ) return SQL_ERROR; out_buf[off] = '\0'; while( SQL_SUCCESS == Sql_NextRow(self) && SQL_SUCCESS == Sql_GetData(self, 0, &data, &len) ) { len = strnlen(data, len); if( off + len + 2 > buf_len ) { ShowDebug("Sql_GetColumns: output buffer is too small\n"); *out_buf = '\0'; return SQL_ERROR; } memcpy(out_buf+off, data, len); off += len; out_buf[off++] = sep; } out_buf[off] = '\0'; Sql_FreeResult(self); return SQL_SUCCESS; }
/// Load guild_storage data to mem int guild_storage_fromsql(int guild_id, struct guild_storage *p) { StringBuf buf; int i, j; 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`} StringBuf_Init(&buf); StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`bound`,`unique_id`"); for( j = 0; j < MAX_SLOTS; ++j ) StringBuf_Printf(&buf, ",`card%d`", j); StringBuf_Printf(&buf, " FROM `%s` WHERE `guild_id`='%d' ORDER BY `nameid`", guild_storage_db, guild_id); if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) ) Sql_ShowDebug(sql_handle); StringBuf_Destroy(&buf); for( i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) { struct item *item; char *data; item = &p->items[i]; Sql_GetData(sql_handle, 0, &data, NULL); item->id = atoi(data); Sql_GetData(sql_handle, 1, &data, NULL); item->nameid = atoi(data); Sql_GetData(sql_handle, 2, &data, NULL); item->amount = atoi(data); Sql_GetData(sql_handle, 3, &data, NULL); item->equip = atoi(data); Sql_GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data); Sql_GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data); Sql_GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data); Sql_GetData(sql_handle, 7, &data, NULL); item->bound = atoi(data); Sql_GetData(sql_handle, 8, &data, NULL); item->unique_id = strtoull(data, NULL, 10); item->expire_time = 0; for( j = 0; j < MAX_SLOTS; ++j ) { Sql_GetData(sql_handle, 9 + j, &data, NULL); item->card[j] = atoi(data); } } p->storage_amount = i; Sql_FreeResult(sql_handle); ShowInfo("guild storage load complete from DB - id: %d (total: %d)\n", guild_id, p->storage_amount); return 0; }
std::list<SearchEntity*> CDataLoader::GetLinkshellList(uint32 LinkshellID) { std::list<SearchEntity*> LinkshellList; const char* fmtQuery = "SELECT charid, partyid, charname, pos_zone, nation, rank_sandoria, rank_bastok, rank_windurst, race, nameflags, mjob, sjob, " "mlvl, slvl, linkshellid1, linkshellid2, " "linkshellrank1, linkshellrank2 " "FROM accounts_sessions " "LEFT JOIN accounts_parties USING (charid) " "LEFT JOIN chars USING (charid) " "LEFT JOIN char_look USING (charid) " "LEFT JOIN char_stats USING (charid) " "LEFT JOIN char_profile USING(charid) " "WHERE linkshellid1 = %u OR linkshellid2 = %u " "ORDER BY charname ASC " "LIMIT 18"; int32 ret = Sql_Query(SqlHandle, fmtQuery, LinkshellID, LinkshellID); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while (Sql_NextRow(SqlHandle) == SQL_SUCCESS) { SearchEntity* PPlayer = new SearchEntity; memset(PPlayer, 0, sizeof(SearchEntity)); memcpy(PPlayer->name, Sql_GetData(SqlHandle, 2), 15); PPlayer->id = (uint32)Sql_GetUIntData(SqlHandle, 0); PPlayer->zone = (uint16)Sql_GetIntData(SqlHandle, 3); PPlayer->nation = (uint8)Sql_GetIntData(SqlHandle, 4); PPlayer->mjob = (uint8)Sql_GetIntData(SqlHandle, 10); PPlayer->sjob = (uint8)Sql_GetIntData(SqlHandle, 11); PPlayer->mlvl = (uint8)Sql_GetIntData(SqlHandle, 12); PPlayer->slvl = (uint8)Sql_GetIntData(SqlHandle, 13); PPlayer->race = (uint8)Sql_GetIntData(SqlHandle, 8); PPlayer->rank = (uint8)Sql_GetIntData(SqlHandle, 5 + PPlayer->nation); PPlayer->linkshellid1 = Sql_GetIntData(SqlHandle, 14); PPlayer->linkshellid2 = Sql_GetIntData(SqlHandle, 15); PPlayer->linkshellrank1 = Sql_GetIntData(SqlHandle, 16); PPlayer->linkshellrank2 = Sql_GetIntData(SqlHandle, 17); uint32 partyid = (uint32)Sql_GetUIntData(SqlHandle, 1); uint32 nameflag = (uint32)Sql_GetUIntData(SqlHandle, 9); if (partyid == PPlayer->id) PPlayer->flags1 |= 0x0008; if (nameflag & FLAG_AWAY) PPlayer->flags1 |= 0x0100; if (nameflag & FLAG_DC) PPlayer->flags1 |= 0x0800; if (partyid != 0) PPlayer->flags1 |= 0x2000; if (nameflag & FLAG_ANON) PPlayer->flags1 |= 0x4000; if (nameflag & FLAG_INVITE) PPlayer->flags1 |= 0x8000; PPlayer->flags2 = PPlayer->flags1; LinkshellList.push_back(PPlayer); } } return LinkshellList; }
//Request skillcooldown data 0x2b0a int chmapif_parse_req_skillcooldown(int fd){ if (RFIFOREST(fd) < 10) return 0; else { int aid, cid; aid = RFIFOL(fd,2); cid = RFIFOL(fd,6); RFIFOSKIP(fd, 10); if( SQL_ERROR == Sql_Query(sql_handle, "SELECT skill, tick FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", schema_config.skillcooldown_db, aid, cid) ) { Sql_ShowDebug(sql_handle); return 1; } if( Sql_NumRows(sql_handle) > 0 ) { int count; char* data; struct skill_cooldown_data scd; WFIFOHEAD(fd,14 + MAX_SKILLCOOLDOWN * sizeof(struct skill_cooldown_data)); WFIFOW(fd,0) = 0x2b0b; WFIFOL(fd,4) = aid; WFIFOL(fd,8) = cid; for( count = 0; count < MAX_SKILLCOOLDOWN && SQL_SUCCESS == Sql_NextRow(sql_handle); ++count ) { Sql_GetData(sql_handle, 0, &data, NULL); scd.skill_id = atoi(data); Sql_GetData(sql_handle, 1, &data, NULL); scd.tick = atoi(data); memcpy(WFIFOP(fd,14+count*sizeof(struct skill_cooldown_data)), &scd, sizeof(struct skill_cooldown_data)); } if( count >= MAX_SKILLCOOLDOWN ) ShowWarning("Too many skillcooldowns for %d:%d, some of them were not loaded.\n", aid, cid); if( count > 0 ) { WFIFOW(fd,2) = 14 + count * sizeof(struct skill_cooldown_data); WFIFOW(fd,12) = count; WFIFOSET(fd,WFIFOW(fd,2)); //Clear the data once loaded. if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", schema_config.skillcooldown_db, aid, cid) ) Sql_ShowDebug(sql_handle); } } Sql_FreeResult(sql_handle); } return 1; }
bool mercenary_owner_fromsql(int char_id, struct mmo_charstatus *status) { char* data; if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith` FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) ) { Sql_ShowDebug(sql_handle); return false; } if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) { Sql_FreeResult(sql_handle); return false; } Sql_GetData(sql_handle, 0, &data, NULL); status->mer_id = atoi(data); Sql_GetData(sql_handle, 1, &data, NULL); status->arch_calls = atoi(data); Sql_GetData(sql_handle, 2, &data, NULL); status->arch_faith = atoi(data); Sql_GetData(sql_handle, 3, &data, NULL); status->spear_calls = atoi(data); Sql_GetData(sql_handle, 4, &data, NULL); status->spear_faith = atoi(data); Sql_GetData(sql_handle, 5, &data, NULL); status->sword_calls = atoi(data); Sql_GetData(sql_handle, 6, &data, NULL); status->sword_faith = atoi(data); Sql_FreeResult(sql_handle); return true; }
int read_elemental_skilldb(void) { struct s_elemental_db *db; int i, j = 0, k = 0, class_, skill_id, skill_lv, skillmode; if(SQL_ERROR == Sql_Query(dbmysql_handle, "SELECT * FROM `%s`", get_database_name(37))) { Sql_ShowDebug(dbmysql_handle); return -1; } while(SQL_SUCCESS == Sql_NextRow(dbmysql_handle)) { char *row[4]; k++; for(i = 0; i != 4; ++i) Sql_GetData(dbmysql_handle, i, &row[i], NULL); class_ = atoi(row[0]); ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, class_ == elemental_db[i].class_); if(i == MAX_ELEMENTAL_CLASS) { ShowError("read_elemental_skilldb : Classe n?o encontrada em elemental_db para a entrada de habilidade, ROW %d.\n", k); continue; } skill_id = atoi(row[1]); if(skill_id < EL_SKILLBASE || skill_id >= EL_SKILLBASE + MAX_ELEMENTALSKILL) { ShowError("read_elemental_skilldb : Habilidade fora do alcance, ROW %d.\n", k); continue; } db = &elemental_db[i]; skill_lv = atoi(row[2]); skillmode = atoi(row[3]); if(skillmode < EL_SKILLMODE_PASIVE || skillmode > EL_SKILLMODE_AGGRESSIVE) { ShowError("read_elemental_skilldb : Skillmode fora da faixa, ROW %d.\n",k); continue; } ARR_FIND(0, MAX_ELESKILLTREE, i, db->skill[i].id == 0 || db->skill[i].id == skill_id); if(i == MAX_ELESKILLTREE) { ShowWarning("Não foi possível carregar habilidade %d em Elemental %d's árvore. O número máximo de capacidade por elementar foi atingido.\n", skill_id, class_); continue; } db->skill[i].id = skill_id; db->skill[i].lv = skill_lv; db->skill[i].mode = skillmode; j++; } ShowSQL("Leitura de '"CL_WHITE"%lu"CL_RESET"' entradas na tabela '"CL_WHITE"%s"CL_RESET"'.\n", j, get_database_name(37)); Sql_FreeResult(dbmysql_handle); return 0; }
/* [Dekamaster/Nightroad] */ void mapif_parse_accinfo(int fd) { int u_fd = RFIFOL(fd,2), aid = RFIFOL(fd,6), castergroup = RFIFOL(fd,10); char query[NAME_LENGTH], query_esq[NAME_LENGTH*2+1]; int account_id; char *data; safestrncpy(query, (char *) RFIFOP(fd,14), NAME_LENGTH); Sql_EscapeString(sql_handle, query_esq, query); account_id = atoi(query); if(account_id < START_ACCOUNT_NUM) { // is string if(SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `%s` WHERE `name` LIKE '%s' LIMIT 10", char_db, query_esq) || Sql_NumRows(sql_handle) == 0) { if(Sql_NumRows(sql_handle) == 0) { inter_msg_to_fd(fd, u_fd, aid, read_message("Source.char.inter_parse_accinfo_s1"), query); } else { Sql_ShowDebug(sql_handle); inter_msg_to_fd(fd, u_fd, aid, read_message("Source.char.inter_parse_accinfo_s2")); } Sql_FreeResult(sql_handle); return; } else { if(Sql_NumRows(sql_handle) == 1) { //we found a perfect match Sql_NextRow(sql_handle); Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); Sql_FreeResult(sql_handle); } else {// more than one, listing... [Dekamaster/Nightroad] inter_msg_to_fd(fd, u_fd, aid, read_message("Source.char.inter_parse_accinfo_s3"), (int)Sql_NumRows(sql_handle)); while (SQL_SUCCESS == Sql_NextRow(sql_handle)) { int class_; short base_level, job_level, online; char name[NAME_LENGTH]; Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); Sql_GetData(sql_handle, 2, &data, NULL); class_ = atoi(data); Sql_GetData(sql_handle, 3, &data, NULL); base_level = atoi(data); Sql_GetData(sql_handle, 4, &data, NULL); job_level = atoi(data); Sql_GetData(sql_handle, 5, &data, NULL); online = atoi(data); inter_msg_to_fd(fd, u_fd, aid, read_message("Source.char.inter_parse_accinfo_s4"), account_id, name, job_name(class_), base_level, job_level, online?"Online":"Offline"); } Sql_FreeResult(sql_handle); return; } } } /* it will only get here if we have a single match */ /* and we will send packet with account id to login server asking for account info */ if(account_id) { mapif_on_parse_accinfo(account_id, u_fd, aid, castergroup, fd); } return; }
int inter_party_CharOnline (int char_id, int party_id) { struct party_data *p; int i; if (party_id == -1) { // Get party_id from the database char *data; if (SQL_ERROR == Sql_Query (sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", char_db, char_id)) { Sql_ShowDebug (sql_handle); return 0; } if (SQL_SUCCESS != Sql_NextRow (sql_handle)) return 0; //Eh? No party? Sql_GetData (sql_handle, 0, &data, NULL); party_id = atoi (data); Sql_FreeResult (sql_handle); } if (party_id == 0) return 0; //No party... p = inter_party_fromsql (party_id); if (!p) { ShowError ("Character %d's party %d not found!\n", char_id, party_id); return 0; } //Set member online for (i = 0; i < MAX_PARTY; i++) { if (p->party.member[i].char_id == char_id) { if (!p->party.member[i].online) { p->party.member[i].online = 1; p->party.count++; if (p->party.member[i].lv < p->min_lv || p->party.member[i].lv > p->max_lv) int_party_check_lv (p); } break; } } return 1; }
// Load account_reg from sql (type=2) int inter_accreg_fromsql(uint32 account_id,uint32 char_id, struct accreg *reg, int type) { char* data; size_t len; int i; 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 if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=3 AND `char_id`='%d'", schema_config.reg_db, char_id) ) Sql_ShowDebug(sql_handle); break; case 2: //account reg if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=2 AND `account_id`='%d'", schema_config.reg_db, account_id) ) Sql_ShowDebug(sql_handle); 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; default: ShowError("inter_accreg_fromsql: Invalid type %d\n", type); return 0; } for( i = 0; i < MAX_REG_NUM && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) { struct global_reg* r = ®->reg[i]; // str Sql_GetData(sql_handle, 0, &data, &len); memcpy(r->str, data, min(len, sizeof(r->str))); // value Sql_GetData(sql_handle, 1, &data, &len); memcpy(r->value, data, min(len, sizeof(r->value))); } reg->reg_num = i; Sql_FreeResult(sql_handle); return 1; }
void mapif_parse_accinfo2(bool success, int map_fd, int u_fd, int u_aid, int account_id, const char *userid, const char *user_pass, const char *email, const char *last_ip, const char *lastlogin, const char *pin_code, const char *birthdate, int group_id, int logincount, int state) { if (map_fd <= 0 || !session_isActive(map_fd)) return; // check if we have a valid fd if(!success) { inter_msg_to_fd(map_fd, u_fd, u_aid, "No account with ID '%d' was found.", account_id); return; } inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s7"), account_id); inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s8"), userid, group_id, state); if(user_pass && *user_pass != '\0') { /* password is only received if your gm level is greater than the one you're searching for */ if(pin_code && *pin_code != '\0') inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s17"), user_pass, pin_code); else inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s9"), user_pass); } inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s10"), email, birthdate); inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s11"), last_ip, geoip_getcountry(str2ip(last_ip))); inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s12"), logincount, lastlogin); inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s13")); if(SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` " "FROM `%s` WHERE `account_id` = '%d' ORDER BY `char_num` LIMIT %d", char_db, account_id, MAX_CHARS) || Sql_NumRows(sql_handle) == 0) { if(Sql_NumRows(sql_handle) == 0) { inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s14")); } else { inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s15")); Sql_ShowDebug(sql_handle); } } else { while(SQL_SUCCESS == Sql_NextRow(sql_handle)) { char *data; int char_id, class_; short char_num, base_level, job_level, online; char name[NAME_LENGTH]; Sql_GetData(sql_handle, 0, &data, NULL); char_id = atoi(data); Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); Sql_GetData(sql_handle, 2, &data, NULL); char_num = atoi(data); Sql_GetData(sql_handle, 3, &data, NULL); class_ = atoi(data); Sql_GetData(sql_handle, 4, &data, NULL); base_level = atoi(data); Sql_GetData(sql_handle, 5, &data, NULL); job_level = atoi(data); Sql_GetData(sql_handle, 6, &data, NULL); online = atoi(data); inter_msg_to_fd(map_fd, u_fd, u_aid, read_message("Source.char.inter_parse_accinfo_s16"), char_num, char_id, name, job_name(class_), base_level, job_level, online?"On":"Off"); } } Sql_FreeResult(sql_handle); return; }
/** * Receive a account_info request from map-serv * @author : [Dekamaster/Nightroad] * @param fd : map-serv link */ void mapif_parse_accinfo(int fd) { int u_fd = RFIFOL(fd,2), u_aid = RFIFOL(fd,6), u_group = RFIFOL(fd,10); char type= RFIFOB(fd,14); char query[NAME_LENGTH], query_esq[NAME_LENGTH*2+1]; uint32 account_id = 0; char *data; safestrncpy(query, RFIFOCP(fd,15), NAME_LENGTH); Sql_EscapeString(sql_handle, query_esq, query); account_id = atoi(query); if (account_id < START_ACCOUNT_NUM) { // is string if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `%s` WHERE `name` LIKE '%s' LIMIT 10", schema_config.char_db, query_esq) || Sql_NumRows(sql_handle) == 0 ) { if( Sql_NumRows(sql_handle) == 0 ) { inter_to_fd(fd, u_fd, u_aid, (char *)msg_txt(212) ,query); } else { Sql_ShowDebug(sql_handle); inter_to_fd(fd, u_fd, u_aid, (char *)msg_txt(213)); } Sql_FreeResult(sql_handle); return; } else { if( Sql_NumRows(sql_handle) == 1 ) {//we found a perfect match Sql_NextRow(sql_handle); Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); Sql_FreeResult(sql_handle); } else {// more than one, listing... [Dekamaster/Nightroad] inter_to_fd(fd, u_fd, u_aid, (char *)msg_txt(214),(int)Sql_NumRows(sql_handle)); while ( SQL_SUCCESS == Sql_NextRow(sql_handle) ) { int class_; short base_level, job_level, online; char name[NAME_LENGTH]; Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); Sql_GetData(sql_handle, 2, &data, NULL); class_ = atoi(data); Sql_GetData(sql_handle, 3, &data, NULL); base_level = atoi(data); Sql_GetData(sql_handle, 4, &data, NULL); job_level = atoi(data); Sql_GetData(sql_handle, 5, &data, NULL); online = atoi(data); inter_to_fd(fd, u_fd, u_aid, (char *)msg_txt(215), account_id, name, job_name(class_), base_level, job_level, online?"Online":"Offline"); } Sql_FreeResult(sql_handle); return; } } } /* it will only get here if we have a single match then ask login-server to fetch the `login` record */ if (!account_id || chlogif_req_accinfo(fd, u_fd, u_aid, u_group, account_id, type) != 1) { inter_to_fd(fd, u_fd, u_aid, (char *)msg_txt(213)); } return; }