// 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'", schema_config.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; }
void SpawnPet(CBattleEntity* PMaster, uint32 PetID, bool spawningFromZone) { DSP_DEBUG_BREAK_IF(PetID >= g_PPetList.size()); if(PMaster->GetMJob()!=JOB_DRG && PetID == PETID_WYVERN) { return; } Pet_t* PPetData = g_PPetList.at(PetID); if (PMaster->objtype == TYPE_PC) ((CCharEntity*)PMaster)->petZoningInfo.petID = PetID; PETTYPE petType = PETTYPE_JUG_PET; if (PetID <= PETID_CAIT_SITH) { petType = PETTYPE_AVATAR; } else if (PetID==PETID_WYVERN) { petType = PETTYPE_WYVERN; const int8* Query = "SELECT\ pet_name.name,\ char_pet_name.wyvernid\ FROM pet_name, char_pet_name\ WHERE pet_name.id = char_pet_name.wyvernid\ AND char_pet_name.charid = %u"; if ( Sql_Query(SqlHandle, Query, ((CCharEntity*)PMaster)->id) != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while (Sql_NextRow(SqlHandle) == SQL_SUCCESS) { uint16 wyvernid = (uint16)Sql_GetIntData(SqlHandle, 1); if (wyvernid != 0) { g_PPetList.at(PetID)->name.clear(); g_PPetList.at(PetID)->name.insert(0, Sql_GetData(SqlHandle, 0)); } } } }
int inter_pet_fromsql(int pet_id, struct s_pet* p) { char* data; size_t len; #ifdef NOISY ShowInfo("Loading pet (%d)...\n",pet_id); #endif memset(p, 0, sizeof(struct s_pet)); //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`) if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate` FROM `%s` WHERE `pet_id`='%d'", schema_config.pet_db, pet_id) ) { Sql_ShowDebug(sql_handle); return 0; } if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) { p->pet_id = pet_id; Sql_GetData(sql_handle, 1, &data, NULL); p->class_ = atoi(data); Sql_GetData(sql_handle, 2, &data, &len); memcpy(p->name, data, zmin(len, NAME_LENGTH)); Sql_GetData(sql_handle, 3, &data, NULL); p->account_id = atoi(data); Sql_GetData(sql_handle, 4, &data, NULL); p->char_id = atoi(data); Sql_GetData(sql_handle, 5, &data, NULL); p->level = atoi(data); Sql_GetData(sql_handle, 6, &data, NULL); p->egg_id = atoi(data); Sql_GetData(sql_handle, 7, &data, NULL); p->equip = atoi(data); Sql_GetData(sql_handle, 8, &data, NULL); p->intimate = atoi(data); Sql_GetData(sql_handle, 9, &data, NULL); p->hungry = atoi(data); Sql_GetData(sql_handle, 10, &data, NULL); p->rename_flag = atoi(data); Sql_GetData(sql_handle, 11, &data, NULL); p->incubate = atoi(data); Sql_FreeResult(sql_handle); p->hungry = cap_value(p->hungry, 0, 100); p->intimate = cap_value(p->intimate, 0, 1000); if( charserv_config.save_log ) ShowInfo("Pet loaded (%d - %s).\n", pet_id, p->name); } return 0; }
/** * Get the number of failed login attempts by the ip in the last minutes. * @param ip: ip to search attempt from * @param minutes: intervall to search * @return number of failed attempts */ unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes) { unsigned long failures = 0; if( !enabled ) return 0; if( SQL_ERROR == Sql_Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `ip` = '%s' AND `rcode` = '1' AND `time` > NOW() - INTERVAL %d MINUTE", log_login_db, ip2str(ip,NULL), minutes) )// how many times failed account? in one ip. Sql_ShowDebug(sql_handle); if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) { char* data; Sql_GetData(sql_handle, 0, &data, NULL); failures = strtoul(data, NULL, 10); Sql_FreeResult(sql_handle); } return failures; }
bool spawnSecondPartDynamis(CBattlefield* battlefield) { DSP_DEBUG_BREAK_IF(battlefield == nullptr); //get ids from DB const int8* fmtQuery = "SELECT monsterId \ FROM bcnm_battlefield \ WHERE bcnmId = %u AND battlefieldNumber = 2"; int32 ret = Sql_Query(SqlHandle, fmtQuery, battlefield->getID()); if (ret == SQL_ERROR || Sql_NumRows(SqlHandle) == 0) { ShowError("spawnSecondPartDynamis : SQL error - Cannot find any monster IDs for Dynamis %i \n", battlefield->getID(), battlefield->getBattlefieldNumber()); } else { while (Sql_NextRow(SqlHandle) == SQL_SUCCESS) { uint32 mobid = Sql_GetUIntData(SqlHandle, 0); CMobEntity* PMob = (CMobEntity*)zoneutils::GetEntity(mobid, TYPE_MOB); if (PMob != nullptr) { if (!PMob->PAI->IsSpawned()) { PMob->Spawn(); PMob->m_battlefieldID = battlefield->getBattlefieldNumber(); ShowDebug("Spawned %s (%u) id %i inst %i \n", PMob->GetName(), PMob->id, battlefield->getID(), battlefield->getBattlefieldNumber()); battlefield->addEnemy(PMob, CONDITION_SPAWNED_AT_START & CONDITION_WIN_REQUIREMENT); } else { ShowDebug(CL_CYAN"spawnSecondPartDynamis: <%s> (%u) is already spawned\n" CL_RESET, PMob->GetName(), PMob->id); } } else { ShowDebug("spawnSecondPartDynamis: mob %u not found\n", mobid); } } return true; } return false; }
/************************************************************** Called by ALL BCNMs to check winning conditions every tick. This is usually when all the monsters are defeated but can be other things (e.g. mob below X% HP, successful Steal, etc) ***************************************************************/ bool meetsWinningConditions(CBattlefield* battlefield, time_point tick) { if (battlefield->won()) return true; //handle odd cases e.g. stop fight @ x% HP //handle Maat fights if (battlefield->locked && (battlefield->m_RuleMask & RULES_MAAT)) { // survive for 5 mins if (battlefield->getPlayerMainJob() == JOB_WHM && (tick - battlefield->fightTick) > 5min) return true; if (battlefield->isEnemyBelowHPP(10)) return true; if (battlefield->getPlayerMainJob() == JOB_THF && battlefield->m_EnemyList.at(0)->m_ItemStolen) //thf can win by stealing from maat only if maat not previously defeated { const int8* fmtQuery = "SELECT value FROM char_vars WHERE charid = %u AND varname = '%s' LIMIT 1;"; int32 ret = Sql_Query(SqlHandle, fmtQuery, battlefield->m_PlayerList.at(0)->id, "maatDefeated"); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) == 0) return true; else if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS) { int16 value = (int16)Sql_GetIntData(SqlHandle, 0); if (value <= 0) return true; } } } // savage if (battlefield->getID() == 961 && battlefield->isEnemyBelowHPP(30)) { return true; } //generic cases, kill all mobs if (battlefield->allEnemiesDefeated()) { return true; } return false; }
//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)); } }
bool spawnSecondPartDynamis(CInstance* instance){ DSP_DEBUG_BREAK_IF(instance==NULL); //get ids from DB const int8* fmtQuery = "SELECT monsterId \ FROM bcnm_instance \ WHERE bcnmId = %u AND instanceNumber = 2"; int32 ret = Sql_Query(SqlHandle, fmtQuery, instance->getID()); if (ret == SQL_ERROR || Sql_NumRows(SqlHandle) == 0) { ShowError("spawnSecondPartDynamis : SQL error - Cannot find any monster IDs for Dynamis %i \n", instance->getID(), instance->getInstanceNumber()); } else{ while(Sql_NextRow(SqlHandle) == SQL_SUCCESS){ uint32 mobid = Sql_GetUIntData(SqlHandle,0); CMobEntity* PMob = (CMobEntity*)zoneutils::GetEntity(mobid, TYPE_MOB); if (PMob != NULL) { if (PMob->PBattleAI->GetCurrentAction() == ACTION_NONE || PMob->PBattleAI->GetCurrentAction() == ACTION_SPAWN) { PMob->PBattleAI->SetLastActionTime(0); PMob->PBattleAI->SetCurrentAction(ACTION_SPAWN); PMob->m_instanceID = instance->getInstanceNumber(); ShowDebug("Spawned %s (%u) id %i inst %i \n",PMob->GetName(),PMob->id,instance->getID(),instance->getInstanceNumber()); instance->addEnemy(PMob, CONDITION_SPAWNED_AT_START & CONDITION_WIN_REQUIREMENT); } else { ShowDebug(CL_CYAN"spawnSecondPartDynamis: <%s> (%u) is alredy spawned\n" CL_RESET, PMob->GetName(), PMob->id); } } else { ShowDebug("spawnSecondPartDynamis: mob %u not found\n", mobid); } } return true; } return false; }
// 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; }
/*====================================== * item_db table reading *======================================*/ static int itemdb_read_sqldb(void) { const char* item_db_name[] = { item_db_db, item_db2_db }; int fi; for( fi = 0; fi < ARRAYLENGTH(item_db_name); ++fi ) { uint32 lines = 0, count = 0; // retrieve all rows from the item database if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", item_db_name[fi]) ) { Sql_ShowDebug(mmysql_handle); continue; } // process rows one by one while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) ) {// wrap the result into a TXT-compatible format char* str[22]; char* dummy = ""; int i; ++lines; for( i = 0; i < 22; ++i ) { Sql_GetData(mmysql_handle, i, &str[i], NULL); if( str[i] == NULL ) str[i] = dummy; // get rid of NULL columns } if (!itemdb_parse_dbrow(str, item_db_name[fi], lines, SCRIPT_IGNORE_EXTERNAL_BRACKETS)) continue; ++count; } // free the query result Sql_FreeResult(mmysql_handle); ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, item_db_name[fi]); } return 0; }
bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele) { char *data; memset(ele, 0, sizeof(struct s_elemental)); ele->elemental_id = ele_id; ele->char_id = char_id; if(SQL_ERROR == Sql_Query(sql_handle, "SELECT `class`, `mode`, `hp`, `sp`, `max_hp`, `max_sp`, `atk1`, `atk2`, `matk`, `aspd`," "`def`, `mdef`, `flee`, `hit`, `life_time` FROM `%s` WHERE `ele_id` = '%d' AND `char_id` = '%d'", elemental_db, ele_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); ele->class_ = atoi(data); Sql_GetData(sql_handle, 1, &data, NULL); ele->mode = atoi(data); Sql_GetData(sql_handle, 2, &data, NULL); ele->hp = atoi(data); Sql_GetData(sql_handle, 3, &data, NULL); ele->sp = atoi(data); Sql_GetData(sql_handle, 4, &data, NULL); ele->max_hp = atoi(data); Sql_GetData(sql_handle, 5, &data, NULL); ele->max_sp = atoi(data); Sql_GetData(sql_handle, 6, &data, NULL); ele->atk = atoi(data); Sql_GetData(sql_handle, 7, &data, NULL); ele->atk2 = atoi(data); Sql_GetData(sql_handle, 8, &data, NULL); ele->matk = atoi(data); Sql_GetData(sql_handle, 9, &data, NULL); ele->amotion = atoi(data); Sql_GetData(sql_handle, 10, &data, NULL); ele->def = atoi(data); Sql_GetData(sql_handle, 11, &data, NULL); ele->mdef = atoi(data); Sql_GetData(sql_handle, 12, &data, NULL); ele->flee = atoi(data); Sql_GetData(sql_handle, 13, &data, NULL); ele->hit = atoi(data); Sql_GetData(sql_handle, 14, &data, NULL); ele->life_time = atoi(data); Sql_FreeResult(sql_handle); if(save_log) ShowInfo(read_message("Source.char.elemental_load"), ele->elemental_id, ele->char_id); return true; }
void CParty::RemovePartyLeader(CBattleEntity* PEntity) { DSP_DEBUG_BREAK_IF(members.empty()); int ret = Sql_Query(SqlHandle, "SELECT charname FROM accounts_sessions JOIN chars ON accounts_sessions.charid = chars.charid \ JOIN accounts_parties ON accounts_parties.charid = chars.charid WHERE partyid = %u AND NOT partyflag & %d \ ORDER BY timestamp ASC LIMIT 1;", m_PartyID, PARTY_LEADER); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS) { SetLeader(Sql_GetData(SqlHandle, 0)); } if (m_PLeader == PEntity) { DisbandParty(); } else { RemoveMember(PEntity); } }
void CMobEntity::SetMainSkin(uint32 mobid) { if(m_NewSkin) { const int8* Query = "SELECT modelid \ FROM mob_spawn_points, mob_groups, mob_pools \ WHERE mob_spawn_points.mobid = %u \ AND mob_groups.groupid = mob_spawn_points.groupid \ AND mob_groups.poolid = mob_pools.poolid"; int32 ret = Sql_Query(SqlHandle, Query, mobid); if(ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS) { memcpy(&look,Sql_GetData(SqlHandle,0),23); m_NewSkin = false; m_SkinID = 0; } } }
CCurrencyPacket2::CCurrencyPacket2(CCharEntity* PChar) { this->type = 0x18; this->size = 0x25; const char* query = "SELECT bayld, kinetic_unit, imprimaturs, obsidian_fragment, lebondopt_wing, \ pulchridopt_wing, mweya_plasm FROM char_points WHERE charid = %d"; int ret = Sql_Query(SqlHandle, query, PChar->id); if (ret != SQL_ERROR && Sql_NextRow(SqlHandle) == SQL_SUCCESS) { WBUFL(data, (0x04)-4) = Sql_GetIntData(SqlHandle, 0); WBUFW(data, (0x08)-4) = Sql_GetUIntData(SqlHandle, 1); WBUFB(data, (0x0A)-4) = Sql_GetUIntData(SqlHandle, 2); WBUFL(data, (0x0C)-4) = Sql_GetIntData(SqlHandle, 3); WBUFW(data, (0x10)-4) = Sql_GetUIntData(SqlHandle, 4); WBUFW(data, (0x12)-4) = Sql_GetUIntData(SqlHandle, 5); WBUFL(data, (0x14)-4) = Sql_GetIntData(SqlHandle, 6); } }
// Check to see if there is a list for the zone if one exists return the ListID int GridList(CCharEntity* PChar) { float POSX = PChar->loc.p.x; float POSY = PChar->loc.p.y; float POSZ = PChar->loc.p.z; int GRIDPOSX = (POSX + POSY) / 30; int GRIDPOSY = (POSZ + POSY) / 30; const int8* Query = "SELECT ListID, x, y \ FROM fishing_grid \ WHERE zone = %u \ ORDER BY zone ASC"; int32 ret = Sql_Query(SqlHandle, Query, PChar->getZone()); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while (Sql_NextRow(SqlHandle) == SQL_SUCCESS) { int32 GX = Sql_GetIntData(SqlHandle, 1); int32 GY = Sql_GetIntData(SqlHandle, 2); if (GX == GRIDPOSX && GY == GRIDPOSY) { return Sql_GetIntData(SqlHandle, 0); } if (GX == -99 && GY == -99) { if (GRIDPOSX != -99 && GRIDPOSY != -99) { return Sql_GetIntData(SqlHandle, 0); } } } } return 0; }
void CDataLoader::ExpireAHItems() { Sql_t* sqlH2 = Sql_Malloc(); Sql_Connect(sqlH2, search_config.mysql_login.c_str(), search_config.mysql_password.c_str(), search_config.mysql_host.c_str(), search_config.mysql_port, search_config.mysql_database.c_str()); std::string qStr = "SELECT T0.id,T0.itemid,T1.stacksize, T0.stack, T0.seller FROM auction_house T0 INNER JOIN item_basic T1 ON \ T0.itemid = T1.itemid WHERE datediff(now(),from_unixtime(date)) >=%u AND buyer_name IS NULL;"; int32 ret = Sql_Query(SqlHandle, qStr.c_str(), search_config.expire_days); int64 expiredAuctions = Sql_NumRows(SqlHandle); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while (Sql_NextRow(SqlHandle) == SQL_SUCCESS) { std::string qStr2; // iterate through the expired auctions and return them to the seller uint32 saleID = (uint32)Sql_GetUIntData(SqlHandle, 0); uint32 itemID = (uint32)Sql_GetUIntData(SqlHandle, 1); uint8 itemStack = (uint8)Sql_GetUIntData(SqlHandle, 2); uint8 ahStack = (uint8)Sql_GetUIntData(SqlHandle, 3); uint32 seller = (uint32)Sql_GetUIntData(SqlHandle, 4); ret = Sql_Query(sqlH2, "INSERT INTO delivery_box (charid, charname, box, itemid, itemsubid, quantity, senderid, sender) VALUES " "(%u, (select charname from chars where charid=%u), 1, %u, 0, %u, 0, 'AH-Jeuno');", seller, seller, itemID, ahStack == 1 ? itemStack : 1 ); // ShowMessage(cC2, seller, seller, itemID); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { // delete the item from the auction house Sql_Query(sqlH2, "DELETE FROM auction_house WHERE id= %u", saleID); } } } else if (ret == SQL_ERROR) { // ShowMessage(CL_RED"SQL ERROR: %s\n\n" CL_RESET, SQL_ERROR); } ShowMessage("Sent %u expired auction house items back to sellers\n", expiredAuctions); Sql_Free(sqlH2); }
void CMeritPoints::LoadMeritPoints(uint32 charid) { uint8 catNumber = 0; for (uint16 i = 0; i < MERITS_COUNT; ++i) { if ((catNumber < 51 && i == meritNameSpace::groupOffset[catNumber]) || (catNumber > 25 && catNumber < 31)) { if (catNumber > 25 && catNumber < 31) // point these to valid merits to prevent crash Categories[catNumber] = &merits[163]; else Categories[catNumber] = &merits[i]; catNumber++; } merits[i].count = 0; merits[i].next = upgrade[merits[i].upgradeid][merits[i].count]; } if (Sql_Query(SqlHandle, "SELECT meritid, upgrades FROM char_merit WHERE charid = %u", charid) != SQL_ERROR) { for (uint16 j = 0; j < Sql_NumRows(SqlHandle); j++) { if (Sql_NextRow(SqlHandle) == SQL_SUCCESS) { uint32 meritID = Sql_GetUIntData(SqlHandle, 0); uint32 upgrades = Sql_GetUIntData(SqlHandle, 1); for (uint16 i = 0; i < MERITS_COUNT; i++) { if (merits[i].id == meritID) { merits[i].count = upgrades; merits[i].next = upgrade[merits[i].upgradeid][merits[i].count]; } } } } } }
std::vector<CParty::partyInfo_t> CParty::GetPartyInfo() { std::vector<CParty::partyInfo_t> memberinfo; int ret = Sql_Query(SqlHandle, "SELECT chars.charid, partyid, allianceid, charname, partyflag, pos_zone, pos_prevzone FROM accounts_parties \ LEFT JOIN chars ON accounts_parties.charid = chars.charid WHERE \ (allianceid <> 0 AND allianceid = %d) OR partyid = %d ORDER BY partyflag & %u, timestamp;", m_PAlliance ? m_PAlliance->m_AllianceID : 0, m_PartyID, PARTY_SECOND | PARTY_THIRD); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while (Sql_NextRow(SqlHandle) == SQL_SUCCESS) { memberinfo.push_back({Sql_GetUIntData(SqlHandle,0), Sql_GetUIntData(SqlHandle, 1), Sql_GetUIntData(SqlHandle, 2), std::string((const char*)Sql_GetData(SqlHandle, 3)), static_cast<uint16>(Sql_GetUIntData(SqlHandle, 4)), static_cast<uint16>(Sql_GetUIntData(SqlHandle, 5)), static_cast<uint16>(Sql_GetUIntData(SqlHandle, 6))}); } } return memberinfo; }
/************************************************************************ * * * ????????? ??????? ????????? * * * ************************************************************************/ void CStatusEffectContainer::LoadStatusEffects() { DSP_DEBUG_BREAK_IF(m_POwner->objtype != TYPE_PC); const int8* Query = "SELECT " "effectid," "icon," "power," "tick," "duration," "subid," "subpower," "tier " "FROM char_effects " "WHERE charid = %u;"; int32 ret = Sql_Query(SqlHandle, Query, m_POwner->id); if( ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while(Sql_NextRow(SqlHandle) == SQL_SUCCESS) { CStatusEffect* PStatusEffect = new CStatusEffect( (EFFECT)Sql_GetUIntData(SqlHandle,0), (uint16)Sql_GetUIntData(SqlHandle,1), (uint16)Sql_GetUIntData(SqlHandle,2), (uint32)Sql_GetUIntData(SqlHandle,3), (uint32)Sql_GetUIntData(SqlHandle,4), (uint16)Sql_GetUIntData(SqlHandle,5), (uint16)Sql_GetUIntData(SqlHandle,6), (uint16)Sql_GetUIntData(SqlHandle,7)); AddStatusEffect(PStatusEffect); // load shadows left if(PStatusEffect->GetStatusID() == EFFECT_COPY_IMAGE){ m_POwner->setModifier(MOD_UTSUSEMI, PStatusEffect->GetPower()); } else if(PStatusEffect->GetStatusID() == EFFECT_BLINK){ m_POwner->setModifier(MOD_BLINK, PStatusEffect->GetPower()); } } } m_POwner->UpdateHealth(); // ????? ???????? ???????? ????????????? ???????????? ?????????? HP/MP }
void LoadUnlockableWeaponList() { PROFILE_FUNC(); int32 ret = Sql_Query(SqlHandle, "SELECT itemid, points FROM item_weapon_unlocked WHERE Id < %u;", MAX_UNLOCKABLE_WEAPONS); if( ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { uint16 index = 0; while(Sql_NextRow(SqlHandle) == SQL_SUCCESS) { UnlockedWeapons_t UnlockedWeapon = {0}; UnlockedWeapon.itemid = Sql_GetUIntData(SqlHandle,0); UnlockedWeapon.required = Sql_GetUIntData(SqlHandle,1); g_pWeaponUnlockable[index] = UnlockedWeapon; index++; } } }
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)); PLinkshell->setMessage(Sql_GetData(SqlHandle,4)); PLinkshell->setMessageTime(Sql_GetUIntData(SqlHandle,5)); LinkshellList[PLinkshell->getID()] = PLinkshell; } } }
bool mapif_elemental_load (int ele_id, int char_id, struct s_elemental *ele) { char *data; memset (ele, 0, sizeof (struct s_elemental)); ele->elemental_id = ele_id; ele->char_id = char_id; if (SQL_ERROR == Sql_Query (sql_handle, "SELECT `class`, `mode`, `hp`, `sp`, `max_hp`, `max_sp`, `str`, `agi`, `vit`, `int`, `dex`," "`luk`, `life_time` FROM `elemental` WHERE `ele_id` = '%d' AND `char_id` = '%d'", ele_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); ele->class_ = atoi (data); Sql_GetData (sql_handle, 1, &data, NULL); ele->mode = atoi (data); Sql_GetData (sql_handle, 2, &data, NULL); ele->hp = atoi (data); Sql_GetData (sql_handle, 3, &data, NULL); ele->sp = atoi (data); Sql_GetData (sql_handle, 4, &data, NULL); ele->max_hp = atoi (data); Sql_GetData (sql_handle, 5, &data, NULL); ele->max_sp = atoi (data); Sql_GetData (sql_handle, 6, &data, NULL); ele->str = atoi (data); Sql_GetData (sql_handle, 7, &data, NULL); ele->agi = atoi (data); Sql_GetData (sql_handle, 8, &data, NULL); ele->vit = atoi (data); Sql_GetData (sql_handle, 9, &data, NULL); ele->int_ = atoi (data); Sql_GetData (sql_handle, 10, &data, NULL); ele->dex = atoi (data); Sql_GetData (sql_handle, 11, &data, NULL); ele->luk = atoi (data); Sql_GetData (sql_handle, 12, &data, NULL); ele->life_time = atoi (data); Sql_FreeResult (sql_handle); if (save_log) ShowInfo ("Elemental carregado (%d - %d).\n", ele->elemental_id, ele->char_id); return true; }
CSynthSuggestionPacket::CSynthSuggestionPacket(uint32 synthID) { this->type = 0x31; this->size = 0x1A; const int8* fmtQuery = "SELECT KeyItem, Wood, Smith, Gold, Cloth, Leather, Bone, Alchemy, Cook, Crystal, \ Result, Ingredient1, Ingredient2, Ingredient3, Ingredient4, Ingredient5, Ingredient6, Ingredient7, Ingredient8 \ FROM synth_recipes \ WHERE ID = %u \ LIMIT 1"; int32 ret = Sql_Query( SqlHandle, fmtQuery, synthID); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS) { WBUFW(data,(0x04)) = Sql_GetUIntData(SqlHandle,10); //words 0x06, 0x08, 0x0A are subcraft number WBUFW(data,(0x0C)) = Sql_GetUIntData(SqlHandle,9); WBUFW(data,(0x0E)) = Sql_GetUIntData(SqlHandle,0); WBUFW(data,(0x10)) = Sql_GetUIntData(SqlHandle,11); WBUFW(data,(0x12)) = Sql_GetUIntData(SqlHandle,12); WBUFW(data,(0x14)) = Sql_GetUIntData(SqlHandle,13); WBUFW(data,(0x16)) = Sql_GetUIntData(SqlHandle,14); WBUFW(data,(0x18)) = Sql_GetUIntData(SqlHandle,15); WBUFW(data,(0x1A)) = Sql_GetUIntData(SqlHandle,16); WBUFW(data,(0x1C)) = Sql_GetUIntData(SqlHandle,17); WBUFW(data,(0x1E)) = Sql_GetUIntData(SqlHandle,18); //TODO: words 0x20 through 0x2E are the quantity per material WBUFW(data,(0x30)) = 0x01; } }
// make sure you can catch a fish with the current bait equipped bool BaitCheck(uint16 BaitID, uint32 FishID) { DSP_DEBUG_BREAK_IF(BaitID == NULL); DSP_DEBUG_BREAK_IF(FishID == NULL); const int8* Query = "SELECT baitid, fishid,rare \ FROM fishing_bait \ WHERE baitid = %u \ ORDER BY baitid ASC"; int32 ret = Sql_Query(SqlHandle, Query, BaitID); //ShowDebug(CL_CYAN"BaitID Record's found: %u \n" CL_RESET, Sql_NumRows(SqlHandle)); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while (Sql_NextRow(SqlHandle) == SQL_SUCCESS) { uint32 ent = Sql_GetIntData(SqlHandle, 1); uint32 rare = Sql_GetIntData(SqlHandle, 2); if (ent == FishID) { // rare chance 20% if (rare = 1 && rand()% 100 <= 20) { return false; } else { return true; } } } } return false; }
void LoadSetSpells(CCharEntity* PChar) { if (PChar->GetMJob() == JOB_BLU || PChar->GetSJob() == JOB_BLU) { const char* 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; char* blue_spells = nullptr; 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(static_cast<SpellID>(PChar->m_SetBlueSpells[slot] + 0x200)); if (PSpell == nullptr) { PChar->m_SetBlueSpells[slot] = 0; } else { PChar->addModifiers(&PSpell->modList); } } } ValidateBlueSpells(PChar); } }
/*************************************************************** Spawns treasure chest/armory crate, what ever on winning bcnm ****************************************************************/ bool spawnTreasureForBcnm(CBattlefield* battlefield) { DSP_DEBUG_BREAK_IF(battlefield == nullptr); //get ids from DB const int8* fmtQuery = "SELECT npcId \ FROM bcnm_treasure_chests \ WHERE bcnmId = %u AND battlefieldNumber = %u"; int32 ret = Sql_Query(SqlHandle, fmtQuery, battlefield->getID(), battlefield->getBattlefieldNumber()); if (ret == SQL_ERROR || Sql_NumRows(SqlHandle) == 0) { ShowError("spawnTreasureForBcnm : SQL error - Cannot find any npc IDs for BCNMID %i Battlefield %i \n", battlefield->getID(), battlefield->getBattlefieldNumber()); } else { while (Sql_NextRow(SqlHandle) == SQL_SUCCESS) { uint32 npcid = Sql_GetUIntData(SqlHandle, 0); CBaseEntity* PNpc = (CBaseEntity*)zoneutils::GetEntity(npcid, TYPE_NPC); if (PNpc != nullptr) { PNpc->status = STATUS_NORMAL; PNpc->animation = 0; PNpc->loc.zone->PushPacket(PNpc, CHAR_INRANGE, new CEntityUpdatePacket(PNpc, ENTITY_SPAWN, UPDATE_ALL_MOB)); battlefield->addNpc(PNpc); ShowDebug(CL_CYAN"Spawned %s id %i inst %i \n", PNpc->status, PNpc->id, battlefield->getBattlefieldNumber()); } else { ShowDebug(CL_CYAN"spawnTreasureForBcnm: <%s> is already spawned\n" CL_RESET, PNpc->GetName()); } } return true; } return false; }
std::vector<ahItem*> CDataLoader::GetAHItemsToCategory(uint8 AHCategoryID, int8* OrderByString) { ShowDebug("try find category %u\n", AHCategoryID); std::vector<ahItem*> ItemList; const char* fmtQuery = "SELECT item_basic.itemid, item_basic.stackSize, COUNT(*)-SUM(stack), SUM(stack) " "FROM item_basic " "LEFT JOIN auction_house ON item_basic.itemId = auction_house.itemid AND auction_house.buyer_name IS NULL " "LEFT JOIN item_armor ON item_basic.itemid = item_armor.itemid " "LEFT JOIN item_weapon ON item_basic.itemid = item_weapon.itemid " "WHERE aH = %u " "GROUP BY item_basic.itemid " "%s"; int32 ret = Sql_Query(SqlHandle, fmtQuery, AHCategoryID, OrderByString); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while (Sql_NextRow(SqlHandle) == SQL_SUCCESS) { ahItem* PAHItem = new ahItem; PAHItem->ItemID = Sql_GetIntData(SqlHandle, 0); PAHItem->SinglAmount = Sql_GetIntData(SqlHandle, 2); PAHItem->StackAmount = Sql_GetIntData(SqlHandle, 3); if (Sql_GetIntData(SqlHandle, 1) == 1) { PAHItem->StackAmount = -1; } ItemList.push_back(PAHItem); } } return ItemList; }
void LoadConquestSystem() { int8 regNum = 0; const int8* Query = "SELECT region_id, region_control, sandoria_influence, bastok_influence, windurst_influence, beastmen_influence, graphics_arrows FROM conquest_system"; int32 ret = Sql_Query(SqlHandle, Query); if( ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while(Sql_NextRow(SqlHandle) == SQL_SUCCESS) { g_Conquest[regNum][0] = (uint32)Sql_GetIntData(SqlHandle,0); // Region ID g_Conquest[regNum][1] = (uint32)Sql_GetIntData(SqlHandle,1); // Region Control g_Conquest[regNum][2] = (uint32)Sql_GetIntData(SqlHandle,2); // Influence of sandoria g_Conquest[regNum][3] = (uint32)Sql_GetIntData(SqlHandle,3); // Influence of bastok g_Conquest[regNum][4] = (uint32)Sql_GetIntData(SqlHandle,4); // Influence of windurst g_Conquest[regNum][5] = (uint32)Sql_GetIntData(SqlHandle,5); // Influence of beastmen g_Conquest[regNum][6] = (uint32)Sql_GetIntData(SqlHandle,6); // Number for graphics with arrows regNum++; } } }
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 ); }
void CZone::LoadZoneLines() { static const int8 fmtQuery[] = "SELECT zoneline, tozone, tox, toy, toz, rotation FROM zonelines WHERE fromzone = %u"; int32 ret = Sql_Query(SqlHandle, fmtQuery, m_zoneID); if( ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while(Sql_NextRow(SqlHandle) == SQL_SUCCESS) { zoneLine_t* zl = new zoneLine_t; zl->m_zoneLineID = (uint32)Sql_GetIntData(SqlHandle,0); zl->m_toZone = (uint16)Sql_GetIntData(SqlHandle,1); zl->m_toPos.x = Sql_GetFloatData(SqlHandle,2); zl->m_toPos.y = Sql_GetFloatData(SqlHandle,3); zl->m_toPos.z = Sql_GetFloatData(SqlHandle,4); zl->m_toPos.rotation = (uint8)Sql_GetIntData(SqlHandle,5); m_zoneLineList.push_back(zl); } } }