void CZone::LoadZoneWeather() { static const int8* Query = "SELECT " "weather.none," "weather.sunshine," "weather.clouds," "weather.fog," "weather.hot_spell," "weather.heat_wave," "weather.rain," "weather.squall," "weather.dust_storm," "weather.sand_storm," "weather.wind," "weather.gales," "weather.snow," "weather.blizzards," "weather.thunder," "weather.thunder_storms," "weather.auroras," "weather.stellar_glares," "weather.gloom," "weather.darkness " "FROM zone_weather as weather " "WHERE zoneid = %u " "LIMIT 1"; if (Sql_Query(SqlHandle, Query, m_zoneID) != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS) { uint16 Frequency = 0; for (uint8 weather = 0; weather < MAX_WEATHER_ID; ++weather) { m_WeatherFrequency[weather] = (uint8)Sql_GetIntData(SqlHandle,weather); if (m_WeatherFrequency[weather] == 100) { m_IsWeatherStatic = true; SetWeather((WEATHER)weather); } Frequency += m_WeatherFrequency[weather]; } if (Frequency != 100) { //ShowWarning(CL_YELLOW"Total Weather Frequency is %u for zone %u\n" CL_RESET, Frequency, m_zoneID); } } else { memset(&m_WeatherFrequency, 0, sizeof(m_WeatherFrequency)); ShowFatalError(CL_RED"CZone::LoadZoneWeather: Cannot load zone weather (%u)\n" CL_RESET, m_zoneID); } }
/************************************************************** 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; }
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); std::vector<CStatusEffect*> PEffectList; 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)); PEffectList.push_back(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()); } } } for (auto&& PStatusEffect : PEffectList) { AddStatusEffect(PStatusEffect); } m_POwner->UpdateHealth(); // после загрузки эффектов пересчитываем максимальное количество HP/MP }
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); } }
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); }
static 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", mail_db, 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 ) break; // Check for online players if( (character = (struct online_char_data *)idb_get(online_char_db, mails[i].account_id)) && character->server >= 0 ) map_fd = 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; }
int mail_fromsql(uint32 char_id, struct mail_data* md) { int i; char *data; memset(md, 0, sizeof(struct mail_data)); md->amount = 0; md->full = false; // First we prefill the msg ids if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id` FROM `%s` WHERE `dest_id`='%d' AND `status` < 3 ORDER BY `id` LIMIT %d", schema_config.mail_db, char_id, MAIL_MAX_INBOX + 1) ){ Sql_ShowDebug(sql_handle); return 0; } md->full = (Sql_NumRows(sql_handle) > MAIL_MAX_INBOX); for( i = 0; i < MAIL_MAX_INBOX && SQL_SUCCESS == Sql_NextRow(sql_handle); i++ ){ Sql_GetData(sql_handle, 0, &data, NULL); md->msg[i].id = atoi(data); } md->amount = i; Sql_FreeResult(sql_handle); // Now we load them for( i = 0; i < md->amount; i++ ){ if( !mail_loadmessage( md->msg[i].id, &md->msg[i] ) ){ return 0; } } md->unchecked = 0; md->unread = 0; for (i = 0; i < md->amount; i++) { struct mail_message *msg = &md->msg[i]; if( msg->status == MAIL_NEW ) { if ( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", schema_config.mail_db, MAIL_UNREAD, msg->id) ) Sql_ShowDebug(sql_handle); msg->status = MAIL_UNREAD; md->unchecked++; } else if ( msg->status == MAIL_UNREAD ) md->unread++; } ShowInfo("mail load complete from DB - id: %d (total: %d)\n", char_id, md->amount); return 1; }
std::list<SearchEntity*> CDataLoader::GetPartyList(uint16 PartyID, uint16 AllianceID) { std::list<SearchEntity*> PartyList; const char* Query = "SELECT charid, partyid, charname, pos_zone, nation, rank_sandoria, rank_bastok, rank_windurst, race, nameflags, mjob, sjob, mlvl, slvl " "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 IF (allianceid <> 0, allianceid IN (SELECT allianceid FROM accounts_parties WHERE charid = %u) , partyid = %u) " "ORDER BY charname ASC " "LIMIT 18"; int32 ret = Sql_Query(SqlHandle, Query, (!AllianceID ? PartyID : AllianceID), (!PartyID ? AllianceID : PartyID)); 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); 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; PartyList.push_back(PPlayer); } } return PartyList; }
void CMobEntity::SetNewSkin(uint8 skinid) { const int8* Query = "SELECT skin_model FROM mob_change_skin WHERE skinid = %u"; int32 ret = Sql_Query(SqlHandle, Query, skinid); if(ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS) { memcpy(&look,Sql_GetData(SqlHandle,0),23); m_NewSkin = true; m_SkinID = skinid; } }
/** * Map-serv requesting to send the list of sc_data the player has saved * @author [Skotlex] * @param fd: wich fd to parse from * @return : 0 not enough data received, 1 success */ int chmapif_parse_askscdata(int fd){ if (RFIFOREST(fd) < 10) return 0; { #ifdef ENABLE_SC_SAVING int aid, cid; aid = RFIFOL(fd,2); cid = RFIFOL(fd,6); if( SQL_ERROR == Sql_Query(sql_handle, "SELECT type, tick, val1, val2, val3, val4 from `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", schema_config.scdata_db, aid, cid) ) { Sql_ShowDebug(sql_handle); return 1; } if( Sql_NumRows(sql_handle) > 0 ) { struct status_change_data scdata; int count; char* data; WFIFOHEAD(fd,14+50*sizeof(struct status_change_data)); WFIFOW(fd,0) = 0x2b1d; WFIFOL(fd,4) = aid; WFIFOL(fd,8) = cid; for( count = 0; count < 50 && SQL_SUCCESS == Sql_NextRow(sql_handle); ++count ) { Sql_GetData(sql_handle, 0, &data, NULL); scdata.type = atoi(data); Sql_GetData(sql_handle, 1, &data, NULL); scdata.tick = atoi(data); Sql_GetData(sql_handle, 2, &data, NULL); scdata.val1 = atoi(data); Sql_GetData(sql_handle, 3, &data, NULL); scdata.val2 = atoi(data); Sql_GetData(sql_handle, 4, &data, NULL); scdata.val3 = atoi(data); Sql_GetData(sql_handle, 5, &data, NULL); scdata.val4 = atoi(data); memcpy(WFIFOP(fd, 14+count*sizeof(struct status_change_data)), &scdata, sizeof(struct status_change_data)); } if (count >= 50) ShowWarning("Too many status changes for %d:%d, some of them were not loaded.\n", aid, cid); if (count > 0) { WFIFOW(fd,2) = 14 + count*sizeof(struct status_change_data); WFIFOW(fd,12) = count; WFIFOSET(fd,WFIFOW(fd,2)); } } Sql_FreeResult(sql_handle); #endif RFIFOSKIP(fd, 10); } return 1; }
void Sql_HerculesUpdateCheck(Sql* self) { char line[22];// "yyyy-mm-dd--hh-mm" (17) + ".sql" (4) + 1 FILE* ifp;/* index fp */ unsigned int performed = 0; if( !( ifp = fopen("sql-files/upgrades/index.txt", "r") ) ) { ShowError("SQL upgrade index was not found!\n"); return; } while(fgets(line, sizeof(line), ifp)) { char path[41];// "sql-files/upgrades/" (19) + "yyyy-mm-dd--hh-mm" (17) + ".sql" (4) + 1 char timestamp[11];// "1360186680" (10) + 1 FILE* ufp;/* upgrade fp */ if( line[0] == '\n' || ( line[0] == '/' && line[1] == '/' ) )/* skip \n and "//" comments */ continue; sprintf(path,"sql-files/upgrades/%s",line); if( !( ufp = fopen(path, "r") ) ) { ShowError("SQL upgrade file %s was not found!\n",path); continue; } if( fgetc(ufp) != '#' ) continue; fseek (ufp,1,SEEK_SET);/* woo. skip the # */ if( fgets(timestamp,sizeof(timestamp),ufp) ) { unsigned int timestampui = atol(timestamp); if( SQL_ERROR == SQL->Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) ) Sql_ShowDebug(self); if( Sql_NumRows(self) != 1 ) { ShowSQL("'"CL_WHITE"%s"CL_RESET"' wasn't applied to the database\n",path); performed++; } } fclose(ufp); } fclose(ifp); if( performed ) { ShowSQL("If you did apply these updates or would like to be skip, insert a new entry in your sql_updates table with the timestamp of each file\n"); } }
uint8 getMaxLootGroups(CInstance* instance){ const int8* fmtQuery = "SELECT MAX(lootGroupId) \ FROM bcnm_loot \ JOIN bcnm_info ON bcnm_info.LootDropId = bcnm_loot.LootDropId \ WHERE bcnm_info.LootDropId = %u LIMIT 1"; int32 ret = Sql_Query(SqlHandle, fmtQuery, instance->getLootId()); if (ret == SQL_ERROR || Sql_NumRows(SqlHandle) == 0 || Sql_NextRow(SqlHandle) != SQL_SUCCESS){ ShowError("SQL error occured \n"); return 0; } else { return (uint8)Sql_GetUIntData(SqlHandle,0); } }
//Account Creation void Packet0x02(session_data_t* session, CPlayer* player, int8* data) { char* query = "SELECT id, handle FROM accounts WHERE handle LIKE '%s';"; char handle[11]; memset(handle, 0, sizeof handle); memcpy(handle, data + 0x02, 10); char pass[17]; memset(pass, 0, sizeof pass); memcpy(pass, data + 0x0C, 16); char escapedHandle[(sizeof handle) * 2 + 1]; char escapedPass[(sizeof pass) * 2 + 1]; Sql_EscapeStringLen(SqlHandle, escapedHandle, handle, sizeof handle); Sql_EscapeStringLen(SqlHandle, escapedPass, pass, sizeof pass); int ret = Sql_Query(SqlHandle, query, escapedHandle); //TODO: validate name/pass if (ret != SQL_ERROR) { if (Sql_NumRows(SqlHandle) == 0) { query = "INSERT INTO accounts (handle, password) VALUES('%s', PASSWORD('%s'));"; ret = Sql_Query(SqlHandle, query, escapedHandle, escapedPass); if (ret != SQL_ERROR && Sql_AffectedRows(SqlHandle) == 1) { session->PPlayer->pushPacket(new CAccountCreatePacket(CREATE_SUCCESS)); ShowDebug("Account %s has been created\n", handle); } else { session->PPlayer->pushPacket(new CAccountCreatePacket(CREATE_UNDEF)); } } else { session->PPlayer->pushPacket(new CAccountCreatePacket(CREATE_NAME_TAKEN)); } } else { session->PPlayer->pushPacket(new CAccountCreatePacket(CREATE_UNDEF)); } }
//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; }
uint16 getRollsPerGroup(CInstance* instance, uint8 groupID){ const int8* fmtQuery = "SELECT SUM(CASE \ WHEN LootDropID = %u \ AND lootGroupId = %u \ THEN rolls \ ELSE 0 END) \ FROM bcnm_loot;"; int32 ret = Sql_Query(SqlHandle, fmtQuery, instance->getLootId(), groupID); if (ret == SQL_ERROR || Sql_NumRows(SqlHandle) == 0 || Sql_NextRow(SqlHandle) != SQL_SUCCESS){ ShowError("SQL error occured \n"); return 0; } else { return (uint16)Sql_GetUIntData(SqlHandle,0); } }
void CMeritPoints::LoadMeritPoints(uint32 charid) { const int8* Query = "SELECT merits FROM chars WHERE charid = %u"; if (Sql_Query(SqlHandle, Query, charid) != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS) { size_t length = 0; int8* points = 0; Sql_GetData(SqlHandle, 0, &points, &length); if (length == MERITS_COUNT) { 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 = points[i]; merits[i].next = upgrade[merits[i].upgradeid][merits[i].count]; } return; } else if(length == 0) { //merits were not set to zero on char creation for this character, set them now SaveMeritPoints(charid,true); return; } } ShowError(CL_RED"MeritSystem: can't load merits for charid %u" CL_RESET, charid); }
bool Sql_GetAutoCommit(Sql_t* self) { if( self ) { int32 ret = Sql_Query(self, "SELECT @@autocommit;"); if( ret != SQL_ERROR && Sql_NumRows(self) > 0 && Sql_NextRow(self) == SQL_SUCCESS ) { return (Sql_GetUIntData(self, 0) == 1); } } ShowFatalError("Sql_GetAutoCommit: SQL_ERROR\n"); return false; }
void LoadPet(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; } //TODO: move this out of modifying the global pet list else if (PetID==PETID_WYVERN) { petType = PETTYPE_WYVERN; const int8* Query = "SELECT\ pet_name.name,\ char_pet.wyvernid\ FROM pet_name, char_pet\ WHERE pet_name.id = char_pet.wyvernid AND \ char_pet.charid = %u"; if ( Sql_Query(SqlHandle, Query, 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)); } } } }
//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; }
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; }
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; } } }
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); } }
// 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 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; } } }
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; } }