本文整理汇总了C++中PreparedQueryResult::NextRow方法的典型用法代码示例。如果您正苦于以下问题:C++ PreparedQueryResult::NextRow方法的具体用法?C++ PreparedQueryResult::NextRow怎么用?C++ PreparedQueryResult::NextRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PreparedQueryResult
的用法示例。
在下文中一共展示了PreparedQueryResult::NextRow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleTurnInPetitionOpcode
//.........这里部分代码省略.........
name = fields[1].GetString();
type = fields[2].GetUInt8();
}
else
{
sLog->outError(LOG_FILTER_NETWORKIO, "Player %s (guid: %u) tried to turn in petition (guid: %u) that is not present in the database", _player->GetName(), _player->GetGUIDLow(), GUID_LOPART(petitionGuid));
return;
}
// Only the petition owner can turn in the petition
if (_player->GetGUIDLow() != ownerguidlo)
return;
// Check if player is already in a guild
if (_player->GetGuildId())
{
data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4);
data.WriteBits(PETITION_TURN_ALREADY_IN_GUILD, 4);
data.FlushBits();
SendPacket(&data);
return;
}
// Check if guild name is already taken
if (sGuildMgr->GetGuildByName(name))
{
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_EXISTS_S, name);
return;
}
// Get petition signatures from db
uint8 signatures;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PETITION_SIGNATURE);
stmt->setUInt32(0, GUID_LOPART(petitionGuid));
result = CharacterDatabase.Query(stmt);
if (result)
signatures = uint8(result->GetRowCount());
else
signatures = 0;
uint32 requiredSignatures;
requiredSignatures = sWorld->getIntConfig(CONFIG_MIN_PETITION_SIGNS);
// Notify player if signatures are missing
if (signatures < requiredSignatures)
{
data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4);
data.WriteBits(PETITION_TURN_NEED_MORE_SIGNATURES, 4);
data.FlushBits();
SendPacket(&data);
return;
}
// Proceed with guild/arena team creation
// Delete charter item
_player->DestroyItem(item->GetBagSlot(), item->GetSlot(), true);
// Create guild
Guild* guild = new Guild;
if (!guild->Create(_player, name))
{
delete guild;
return;
}
// Register guild and add guild master
sGuildMgr->AddGuild(guild);
// Add members from signatures
for (uint8 i = 0; i < signatures; ++i)
{
Field* fields = result->Fetch();
guild->AddMember(MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER));
result->NextRow();
}
SQLTransaction trans = CharacterDatabase.BeginTransaction();
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_PETITION_BY_GUID);
stmt->setUInt32(0, GUID_LOPART(petitionGuid));
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_PETITION_SIGNATURE_BY_GUID);
stmt->setUInt32(0, GUID_LOPART(petitionGuid));
trans->Append(stmt);
CharacterDatabase.CommitTransaction(trans);
// created
sLog->outDebug(LOG_FILTER_NETWORKIO, "TURN IN PETITION GUID %u", GUID_LOPART(petitionGuid));
data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4);
data.WriteBits(PETITION_TURN_OK, 4);
data.FlushBits();
SendPacket(&data);
}
示例2: LoadGuildRewards
void GuildMgr::LoadGuildRewards()
{
uint32 oldMSTime = getMSTime();
// 0 1 2 3
QueryResult result = WorldDatabase.Query("SELECT ItemID, MinGuildRep, RaceMask, Cost FROM guild_rewards");
if (!result)
{
TC_LOG_ERROR("server.loading", ">> Loaded 0 guild reward definitions. DB table `guild_rewards` is empty.");
return;
}
uint32 count = 0;
do
{
GuildReward reward;
Field* fields = result->Fetch();
reward.ItemID = fields[0].GetUInt32();
reward.MinGuildRep = fields[1].GetUInt8();
reward.RaceMask = fields[2].GetInt32();
reward.Cost = fields[3].GetUInt64();
if (!sObjectMgr->GetItemTemplate(reward.ItemID))
{
TC_LOG_ERROR("server.loading", "Guild rewards constains not existing item entry %u", reward.ItemID);
continue;
}
if (reward.MinGuildRep >= MAX_REPUTATION_RANK)
{
TC_LOG_ERROR("server.loading", "Guild rewards contains wrong reputation standing %u, max is %u", uint32(reward.MinGuildRep), MAX_REPUTATION_RANK - 1);
continue;
}
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GUILD_REWARDS_REQ_ACHIEVEMENTS);
stmt->setUInt32(0, reward.ItemID);
PreparedQueryResult reqAchievementResult = WorldDatabase.Query(stmt);
if (reqAchievementResult)
{
do
{
fields = reqAchievementResult->Fetch();
uint32 requiredAchievementId = fields[0].GetUInt32();
if (!sAchievementMgr->GetAchievement(requiredAchievementId))
{
TC_LOG_ERROR("server.loading", "Guild rewards constains not existing achievement entry %u", requiredAchievementId);
continue;
}
reward.AchievementsRequired.push_back(requiredAchievementId);
} while (reqAchievementResult->NextRow());
}
GuildRewards.push_back(reward);
++count;
} while (result->NextRow());
TC_LOG_INFO("server.loading", ">> Loaded %u guild reward definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
示例3: HandleOfferPetitionOpcode
//.........这里部分代码省略.........
recvData >> junk; // this is not petition type!
recvData >> petitionguid; // petition guid
recvData >> plguid; // player guid
player = ObjectAccessor::FindPlayer(plguid);
if (!player)
return;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PETITION_TYPE);
stmt->setUInt32(0, GUID_LOPART(petitionguid));
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (!result)
return;
Field* fields = result->Fetch();
type = fields[0].GetUInt8();
TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "OFFER PETITION: type %u, GUID1 %u, to player id: %u", type, GUID_LOPART(petitionguid), GUID_LOPART(plguid));
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeam() != player->GetTeam())
{
if (type != GUILD_CHARTER_TYPE)
SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", "", ERR_ARENA_TEAM_NOT_ALLIED);
else
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NOT_ALLIED);
return;
}
if (type != GUILD_CHARTER_TYPE)
{
if (player->getLevel() < sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
{
// player is too low level to join an arena team
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, player->GetName().c_str(), "", ERR_ARENA_TEAM_TARGET_TOO_LOW_S);
return;
}
uint8 slot = ArenaTeam::GetSlotByType(type);
if (slot >= MAX_ARENA_SLOT)
return;
if (player->GetArenaTeamId(slot))
{
// player is already in an arena team
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, player->GetName().c_str(), "", ERR_ALREADY_IN_ARENA_TEAM_S);
return;
}
if (player->GetArenaTeamIdInvited())
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", _player->GetName().c_str(), ERR_ALREADY_INVITED_TO_ARENA_TEAM_S);
return;
}
}
else
{
if (player->GetGuildId())
{
Guild::SendCommandResult(this, GUILD_COMMAND_INVITE, ERR_ALREADY_IN_GUILD_S, _player->GetName());
return;
}
if (player->GetGuildIdInvited())
{
Guild::SendCommandResult(this, GUILD_COMMAND_INVITE, ERR_ALREADY_INVITED_TO_GUILD_S, _player->GetName());
return;
}
}
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PETITION_SIGNATURE);
stmt->setUInt32(0, GUID_LOPART(petitionguid));
result = CharacterDatabase.Query(stmt);
// result == NULL also correct charter without signs
if (result)
signs = uint8(result->GetRowCount());
WorldPacket data(SMSG_PETITION_SHOW_SIGNATURES, (8+8+4+signs+signs*12));
data << uint64(petitionguid); // petition guid
data << uint64(_player->GetGUID()); // owner guid
data << uint32(GUID_LOPART(petitionguid)); // guild guid
data << uint8(signs); // sign's count
for (uint8 i = 1; i <= signs; ++i)
{
Field* fields2 = result->Fetch();
data << uint64(MAKE_NEW_GUID(fields2[0].GetUInt32(), 0, HIGHGUID_PLAYER)); // Player GUID
data << uint32(0); // there 0 ...
result->NextRow();
}
player->GetSession()->SendPacket(&data);
}
示例4: tempObj
void PoolGroup<Quest>::SpawnObject(ActivePoolData& spawns, uint32 limit, uint32 triggerFrom)
{
TC_LOG_DEBUG("pool", "PoolGroup<Quest>: Spawning pool %u", poolId);
// load state from db
if (!triggerFrom)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_POOL_QUEST_SAVE);
stmt->setUInt32(0, poolId);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
{
do
{
uint32 questId = result->Fetch()[0].GetUInt32();
spawns.ActivateObject<Quest>(questId, poolId);
PoolObject tempObj(questId, 0.0f);
Spawn1Object(&tempObj);
--limit;
} while (result->NextRow() && limit);
return;
}
}
ActivePoolObjects currentQuests = spawns.GetActiveQuests();
ActivePoolObjects newQuests;
// always try to select different quests
for (PoolObjectList::iterator itr = EqualChanced.begin(); itr != EqualChanced.end(); ++itr)
{
if (spawns.IsActiveObject<Quest>(itr->guid))
continue;
newQuests.insert(itr->guid);
}
// clear the pool
DespawnObject(spawns);
// recycle minimal amount of quests if possible count is lower than limit
if (limit > newQuests.size() && !currentQuests.empty())
{
do
{
uint32 questId = Trinity::Containers::SelectRandomContainerElement(currentQuests);
newQuests.insert(questId);
currentQuests.erase(questId);
} while (newQuests.size() < limit && !currentQuests.empty()); // failsafe
}
if (newQuests.empty())
return;
// activate <limit> random quests
do
{
uint32 questId = Trinity::Containers::SelectRandomContainerElement(newQuests);
spawns.ActivateObject<Quest>(questId, poolId);
PoolObject tempObj(questId, 0.0f);
Spawn1Object(&tempObj);
newQuests.erase(questId);
--limit;
} while (limit && !newQuests.empty());
// if we are here it means the pool is initialized at startup and did not have previous saved state
if (!triggerFrom)
sPoolMgr->SaveQuestsToDB();
}
示例5: DeleteExpiredAuctionsAtStartup
void AuctionHouseMgr::DeleteExpiredAuctionsAtStartup()
{
// Deletes expired auctions. Should be called at server start before loading auctions.
// DO NOT USE after auctions are already loaded since this deletes from the DB
// and assumes the auctions HAVE NOT been loaded into a list or AuctionEntryMap yet
uint32 oldMSTime = getMSTime();
uint32 expirecount = 0;
time_t curTime = sWorld->GetGameTime();
// Query the DB to see if there are any expired auctions
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_EXPIRED_AUCTIONS);
stmt->setUInt32(0, (uint32)curTime+60);
PreparedQueryResult expAuctions = CharacterDatabase.Query(stmt);
if (!expAuctions)
{
TC_LOG_INFO("server.loading", ">> No expired auctions to delete");
return;
}
do
{
Field* fields = expAuctions->Fetch();
AuctionEntry* auction = new AuctionEntry();
// Can't use LoadFromDB() because it assumes the auction map is loaded
if (!auction->LoadFromFieldList(fields))
{
// For some reason the record in the DB is broken (possibly corrupt
// faction info). Delete the object and move on.
delete auction;
continue;
}
SQLTransaction trans = CharacterDatabase.BeginTransaction();
if (auction->bidder==0)
{
// Cancel the auction, there was no bidder
sAuctionMgr->SendAuctionExpiredMail(auction, trans);
}
else
{
// Send the item to the winner and money to seller
sAuctionMgr->SendAuctionSuccessfulMail(auction, trans);
sAuctionMgr->SendAuctionWonMail(auction, trans);
}
// Call the appropriate AuctionHouseObject script
// ** Do we need to do this while core is still loading? **
sScriptMgr->OnAuctionExpire(GetAuctionsMap(auction->factionTemplateId), auction);
// Delete the auction from the DB
auction->DeleteFromDB(trans);
CharacterDatabase.CommitTransaction(trans);
// Release memory
delete auction;
++expirecount;
}
while (expAuctions->NextRow());
TC_LOG_INFO("server.loading", ">> Deleted %u expired auctions in %u ms", expirecount, GetMSTimeDiffToNow(oldMSTime));
}
示例6: HandleBanListHelper
static bool HandleBanListHelper(PreparedQueryResult result, ChatHandler* handler)
{
handler->PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
// Chat short output
if (handler->GetSession())
{
do
{
Field* fields = result->Fetch();
uint32 accountid = fields[0].GetUInt32();
QueryResult banResult = LoginDatabase.PQuery("SELECT account.username FROM account, account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id", accountid);
if (banResult)
{
Field* fields2 = banResult->Fetch();
handler->PSendSysMessage("%s", fields2[0].GetCString());
}
}
while (result->NextRow());
}
// Console wide output
else
{
handler->SendSysMessage(LANG_BANLIST_ACCOUNTS);
handler->SendSysMessage(" ===============================================================================");
handler->SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
do
{
handler->SendSysMessage("-------------------------------------------------------------------------------");
Field* fields = result->Fetch();
uint32 accountId = fields[0].GetUInt32();
std::string accountName;
// "account" case, name can be get in same query
if (result->GetFieldCount() > 1)
accountName = fields[1].GetString();
// "character" case, name need extract from another DB
else
AccountMgr::GetName(accountId, accountName);
// No SQL injection. id is uint32.
QueryResult banInfo = LoginDatabase.PQuery("SELECT bandate, unbandate, bannedby, banreason FROM account_banned WHERE id = %u ORDER BY unbandate", accountId);
if (banInfo)
{
Field* fields2 = banInfo->Fetch();
do
{
time_t timeBan = time_t(fields2[0].GetUInt32());
tm tmBan;
localtime_r(&timeBan, &tmBan);
if (fields2[0].GetUInt32() == fields2[1].GetUInt32())
{
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
accountName.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
fields2[2].GetCString(), fields2[3].GetCString());
}
else
{
time_t timeUnban = time_t(fields2[1].GetUInt32());
tm tmUnban;
localtime_r(&timeUnban, &tmUnban);
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
accountName.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
fields2[2].GetCString(), fields2[3].GetCString());
}
}
while (banInfo->NextRow());
}
}
while (result->NextRow());
handler->SendSysMessage(" ===============================================================================");
}
return true;
}
示例7: HandleBanListIPCommand
static bool HandleBanListIPCommand(ChatHandler* handler, char const* args)
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS);
LoginDatabase.Execute(stmt);
char* filterStr = strtok((char*)args, " ");
std::string filter = filterStr ? filterStr : "";
LoginDatabase.EscapeString(filter);
PreparedQueryResult result;
if (filter.empty())
{
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_ALL);
result = LoginDatabase.Query(stmt);
}
else
{
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_BY_IP);
stmt->setString(0, filter);
result = LoginDatabase.Query(stmt);
}
if (!result)
{
handler->PSendSysMessage(LANG_BANLIST_NOIP);
return true;
}
handler->PSendSysMessage(LANG_BANLIST_MATCHINGIP);
// Chat short output
if (handler->GetSession())
{
do
{
Field* fields = result->Fetch();
handler->PSendSysMessage("%s", fields[0].GetCString());
}
while (result->NextRow());
}
// Console wide output
else
{
handler->SendSysMessage(LANG_BANLIST_IPS);
handler->SendSysMessage(" ===============================================================================");
handler->SendSysMessage(LANG_BANLIST_IPS_HEADER);
do
{
handler->SendSysMessage("-------------------------------------------------------------------------------");
Field* fields = result->Fetch();
time_t timeBan = time_t(fields[1].GetUInt32());
tm tmBan;
localtime_r(&timeBan, &tmBan);
if (fields[1].GetUInt32() == fields[2].GetUInt32())
{
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
fields[0].GetCString(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
fields[3].GetCString(), fields[4].GetCString());
}
else
{
time_t timeUnban = time_t(fields[2].GetUInt32());
tm tmUnban;
localtime_r(&timeUnban, &tmUnban);
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
fields[0].GetCString(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
fields[3].GetCString(), fields[4].GetCString());
}
}
while (result->NextRow());
handler->SendSysMessage(" ===============================================================================");
}
return true;
}
示例8: HandleListItemCommand
static bool HandleListItemCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* id = handler->extractKeyFromLink((char*)args, "Hitem");
if (!id)
return false;
uint32 itemId = atol(id);
if (!itemId)
{
handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
handler->SetSentErrorMessage(true);
return false;
}
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemId);
if (!itemTemplate)
{
handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
handler->SetSentErrorMessage(true);
return false;
}
char* countStr = strtok(NULL, " ");
uint32 count = countStr ? atol(countStr) : 10;
if (count == 0)
return false;
PreparedQueryResult result;
// inventory case
uint32 inventoryCount = 0;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_INVENTORY_COUNT_ITEM);
stmt->setUInt32(0, itemId);
result = CharacterDatabase.Query(stmt);
if (result)
inventoryCount = (*result)[0].GetUInt64();
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_INVENTORY_ITEM_BY_ENTRY);
stmt->setUInt32(0, itemId);
stmt->setUInt32(1, count);
result = CharacterDatabase.Query(stmt);
if (result)
{
do
{
Field* fields = result->Fetch();
uint32 itemGuid = fields[0].GetUInt32();
uint32 itemBag = fields[1].GetUInt32();
uint8 itemSlot = fields[2].GetUInt8();
uint32 ownerGuid = fields[3].GetUInt32();
uint32 ownerAccountId = fields[4].GetUInt32();
std::string ownerName = fields[5].GetString();
char const* itemPos = 0;
if (Player::IsEquipmentPos(itemBag, itemSlot))
itemPos = "[equipped]";
else if (Player::IsInventoryPos(itemBag, itemSlot))
itemPos = "[in inventory]";
else if (Player::IsBankPos(itemBag, itemSlot))
itemPos = "[in bank]";
else
itemPos = "";
handler->PSendSysMessage(LANG_ITEMLIST_SLOT, itemGuid, ownerName.c_str(), ownerGuid, ownerAccountId, itemPos);
}
while (result->NextRow());
uint32 resultCount = uint32(result->GetRowCount());
if (count > resultCount)
count -= resultCount;
else if (count)
count = 0;
}
// mail case
uint32 mailCount = 0;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL_COUNT_ITEM);
stmt->setUInt32(0, itemId);
result = CharacterDatabase.Query(stmt);
if (result)
mailCount = (*result)[0].GetUInt64();
if (count > 0)
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL_ITEMS_BY_ENTRY);
stmt->setUInt32(0, itemId);
stmt->setUInt32(1, count);
result = CharacterDatabase.Query(stmt);
}
else
//.........这里部分代码省略.........
示例9: LoadQuestPools
void PoolMgr::LoadQuestPools()
{
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_LOAD_QUEST_POOLS);
PreparedQueryResult result = WorldDatabase.Query(stmt);
mQuestSearchMap.clear();
mPoolQuestGroups.resize(max_pool_id + 1);
uint32 count = 0;
if (!result)
{
sLog.outString();
sLog.outString(">> Loaded 0 quests in pools");
return;
}
PooledQuestRelationBounds creBounds;
PooledQuestRelationBounds goBounds;
enum eQuestTypes
{
QUEST_NONE = 0,
QUEST_DAILY = 1,
QUEST_WEEKLY = 2
};
std::map<uint32, int32> poolTypeMap;
do
{
Field* fields = result->Fetch();
uint32 entry = fields[0].GetUInt32();
uint32 pool_id = fields[1].GetUInt32();
Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
if (!pQuest)
{
sLog.outErrorDb("`pool_quest` has a non existing quest template (Entry: %u) defined for pool id (%u), skipped.", entry, pool_id);
continue;
}
if (pool_id > max_pool_id)
{
sLog.outErrorDb("`pool_quest` pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.",pool_id);
continue;
}
if (!pQuest->IsDailyOrWeekly())
{
sLog.outErrorDb("`pool_quest` has an quest (%u) which is not daily or weekly in pool id (%u), use ExclusiveGroup instead, skipped.", entry, pool_id);
continue;
}
if (poolTypeMap[pool_id] == QUEST_NONE)
poolTypeMap[pool_id] = pQuest->IsDaily() ? QUEST_DAILY : QUEST_WEEKLY;
int32 currType = pQuest->IsDaily() ? QUEST_DAILY : QUEST_WEEKLY;
if (poolTypeMap[pool_id] != currType)
{
sLog.outErrorDb("`pool_quest` quest %u is %s but pool (%u) is specified for %s, mixing not allowed, skipped.", entry, currType == QUEST_DAILY ? "QUEST_DAILY" : "QUEST_WEEKLY", pool_id, poolTypeMap[pool_id] == QUEST_DAILY ? "QUEST_DAILY" : "QUEST_WEEKLY");
continue;
}
creBounds = mQuestCreatureRelation.equal_range(entry);
goBounds = mQuestGORelation.equal_range(entry);
if (creBounds.first == creBounds.second && goBounds.first == goBounds.second)
{
sLog.outErrorDb("`pool_quest` lists entry (%u) as member of pool (%u) but is not started anywhere, skipped.", entry, pool_id);
continue;
}
PoolTemplateData *pPoolTemplate = &mPoolTemplate[pool_id];
++count;
PoolObject plObject = PoolObject(entry, 0.0f);
PoolGroup<Quest>& questgroup = mPoolQuestGroups[pool_id];
questgroup.SetPoolId(pool_id);
questgroup.AddEntry(plObject, pPoolTemplate->MaxLimit);
SearchPair p(entry, pool_id);
mQuestSearchMap.insert(p);
}
while (result->NextRow());
sLog.outString();
sLog.outString(">> Loaded %u quests in pools", count);
}
示例10: LoadFromDB
void AchievementMgr::LoadFromDB(PreparedQueryResult achievementResult, PreparedQueryResult criteriaResult)
{
if (achievementResult)
{
do
{
Field* fields = achievementResult->Fetch();
uint32 achievementid = fields[0].GetUInt16();
// must not happen: cleanup at server startup in sAchievementMgr->LoadCompletedAchievements()
AchievementEntry const* achievement = sAchievementStore.LookupEntry(achievementid);
if (!achievement)
continue;
if (achievement->flags & ACHIEVEMENT_FLAG_GUILD_ACHIEVEMENT)
continue;
CompletedAchievementData& ca = m_completedAchievements[achievementid];
ca.date = time_t(fields[1].GetUInt32());
ca.changed = false;
m_achievementPoints += achievement->points;
// title achievement rewards are retroactive
if (AchievementReward const* reward = sAchievementMgr->GetAchievementReward(achievement))
if (uint32 titleId = reward->titleId[GetPlayer()->GetTeam() == ALLIANCE ? 0 : 1])
if (CharTitlesEntry const* titleEntry = sCharTitlesStore.LookupEntry(titleId))
if (!GetPlayer()->HasTitle(titleEntry))
GetPlayer()->SetTitle(titleEntry);
} while (achievementResult->NextRow());
}
if (criteriaResult)
{
do
{
Field* fields = criteriaResult->Fetch();
uint32 id = fields[0].GetUInt16();
uint32 counter = fields[1].GetUInt32();
time_t date = time_t(fields[2].GetUInt32());
AchievementCriteriaEntry const* criteria = sAchievementCriteriaStore.LookupEntry(id);
if (!criteria)
{
// we will remove not existed criteria for all characters
sLog->outError("Non-existing achievement criteria %u data removed from table `character_achievement_progress`.", id);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_INVALID_ACHIEV_PROGRESS_CRITERIA);
stmt->setUInt16(0, uint16(id));
CharacterDatabase.Execute(stmt);
continue;
}
if (criteria->timeLimit && time_t(date + criteria->timeLimit) < time(NULL))
continue;
CriteriaProgress& progress = m_criteriaProgress[id];
progress.counter = counter;
progress.date = date;
progress.changed = false;
} while (criteriaResult->NextRow());
}
}
示例11: HandleListMailCommand
// handle list mail command
static bool HandleListMailCommand(ChatHandler* handler, char const* args)
{
Player* target;
ObjectGuid targetGuid;
std::string targetName;
PreparedStatement* stmt = NULL;
if (!*args)
return false;
ObjectGuid parseGUID = ObjectGuid::Create<HighGuid::Player>(strtoull(args, nullptr, 10));
if (ObjectMgr::GetPlayerNameByGUID(parseGUID, targetName))
{
target = ObjectAccessor::FindPlayer(parseGUID);
targetGuid = parseGUID;
}
else if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
return false;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL_LIST_COUNT);
stmt->setUInt64(0, targetGuid.GetCounter());
PreparedQueryResult queryResult = CharacterDatabase.Query(stmt);
if (queryResult)
{
Field* fields = queryResult->Fetch();
uint32 countMail = fields[0].GetUInt64();
std::string nameLink = handler->playerLink(targetName);
handler->PSendSysMessage(LANG_LIST_MAIL_HEADER, countMail, nameLink.c_str(), targetGuid.ToString().c_str());
handler->PSendSysMessage(LANG_ACCOUNT_LIST_BAR);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL_LIST_INFO);
stmt->setUInt64(0, targetGuid.GetCounter());
queryResult = CharacterDatabase.Query(stmt);
if (queryResult)
{
do
{
Field* queryFields = queryResult->Fetch();
uint32 messageId = queryFields[0].GetUInt32();
ObjectGuid::LowType senderId = queryFields[1].GetUInt64();
std::string sender = queryFields[2].GetString();
ObjectGuid::LowType receiverId = queryFields[3].GetUInt64();
std::string receiver = queryFields[4].GetString();
std::string subject = queryFields[5].GetString();
uint64 deliverTime = queryFields[6].GetUInt32();
uint64 expireTime = queryFields[7].GetUInt32();
uint32 money = queryFields[8].GetUInt32();
uint8 hasItem = queryFields[9].GetUInt8();
uint32 gold = money / GOLD;
uint32 silv = (money % GOLD) / SILVER;
uint32 copp = (money % GOLD) % SILVER;
std::string receiverStr = handler->playerLink(receiver);
std::string senderStr = handler->playerLink(sender);
handler->PSendSysMessage(LANG_LIST_MAIL_INFO_1, messageId, subject.c_str(), gold, silv, copp);
handler->PSendSysMessage(LANG_LIST_MAIL_INFO_2, senderStr.c_str(), senderId, receiverStr.c_str(), receiverId);
handler->PSendSysMessage(LANG_LIST_MAIL_INFO_3, TimeToTimestampStr(deliverTime).c_str(), TimeToTimestampStr(expireTime).c_str());
if (hasItem == 1)
{
QueryResult result2;
result2 = CharacterDatabase.PQuery("SELECT item_guid FROM mail_items WHERE mail_id = '%u'", messageId);
if (result2)
{
do
{
uint32 item_guid = (*result2)[0].GetUInt32();
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL_LIST_ITEMS);
stmt->setUInt64(0, item_guid);
PreparedQueryResult result3 = CharacterDatabase.Query(stmt);
if (result3)
{
do
{
Field* fields3 = result3->Fetch();
uint32 item_entry = fields3[0].GetUInt32();
uint32 item_count = fields3[1].GetUInt32();
QueryResult result4;
result4 = WorldDatabase.PQuery("SELECT name, quality FROM item_template WHERE entry = '%u'", item_entry);
Field* fields1 = result4->Fetch();
std::string item_name = fields1[0].GetString();
int item_quality = fields1[1].GetUInt8();
if (handler->GetSession())
{
uint32 color = ItemQualityColors[item_quality];
std::ostringstream itemStr;
itemStr << "|c" << std::hex << color << "|Hitem:" << item_entry << ":0:0:0:0:0:0:0:0:0|h[" << item_name << "]|h|r";
handler->PSendSysMessage(LANG_LIST_MAIL_INFO_ITEM, itemStr.str().c_str(), item_entry, item_guid, item_count);
}
else
handler->PSendSysMessage(LANG_LIST_MAIL_INFO_ITEM, item_name.c_str(), item_entry, item_guid, item_count);
}
while (result3->NextRow());
}
}
while (result2->NextRow());
}
//.........这里部分代码省略.........
示例12: UpdateAccountAccess
void AccountMgr::UpdateAccountAccess(RBACData* rbac, uint32 accountId, uint8 securityLevel, int32 realmId)
{
int32 serverRealmId = realmId != -1 ? realmId : ConfigMgr::GetIntDefault("RealmID", 0);
bool needDelete = false;
if (!rbac)
{
needDelete = true;
rbac = new RBACData(accountId, "", serverRealmId);
rbac->LoadFromDB();
}
// Get max security level and realm (checking current realm and -1)
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_ACCESS_BY_ID);
stmt->setUInt32(0, accountId);
stmt->setInt32(1, serverRealmId);
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (result)
{
do
{
Field* field = result->Fetch();
uint8 secLevel = field[0].GetUInt8();
int32 realmId = field[1].GetUInt32();
RBACGroupContainer const& groupsToRemove = _defaultSecGroups[secLevel];
for (RBACGroupContainer::const_iterator it = groupsToRemove.begin(); it != groupsToRemove.end(); ++it)
rbac->RemoveGroup(*it, realmId);
}
while (result->NextRow());
}
// Add new groups depending on the new security Level
RBACGroupContainer const& groupsToAdd = _defaultSecGroups[securityLevel];
for (RBACGroupContainer::const_iterator it = groupsToAdd.begin(); it != groupsToAdd.end(); ++it)
rbac->AddGroup(*it, realmId);
if (needDelete)
delete rbac;
// Delete old security level from DB
if (realmId == -1)
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS);
stmt->setUInt32(0, accountId);
LoginDatabase.Execute(stmt);
}
else
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM);
stmt->setUInt32(0, accountId);
stmt->setUInt32(1, realmId);
LoginDatabase.Execute(stmt);
}
// Add new security level
if (securityLevel)
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_ACCESS);
stmt->setUInt32(0, accountId);
stmt->setUInt8(1, securityLevel);
stmt->setInt32(2, realmId);
LoginDatabase.Execute(stmt);
}
}
示例13: strlen
void DB2DatabaseLoader::LoadStrings(const char* format, uint32 preparedStatement, uint32 locale, char**& indexTable, std::list<char*>& stringPool)
{
PreparedStatement* stmt = HotfixDatabase.GetPreparedStatement(preparedStatement);
stmt->setString(0, localeNames[locale]);
PreparedQueryResult result = HotfixDatabase.Query(stmt);
if (!result)
return;
size_t stringFields = DB2FileLoader::GetFormatStringFieldCount(format);
if (result->GetFieldCount() != stringFields + 1 /*ID*/)
return;
uint32 const fieldCount = strlen(format);
int32 indexField;
uint32 recordSize = DB2FileLoader::GetFormatRecordSize(format, &indexField);
ASSERT(indexField >= 0, "DB2Storage must be indexed to load localized strings");
do
{
Field* fields = result->Fetch();
uint32 offset = 0;
uint32 stringFieldNumInRecord = 0;
uint32 indexValue = fields[0].GetUInt32();
// Attempt to overwrite existing data
if (char* dataValue = indexTable[indexValue])
{
for (uint32 x = 0; x < fieldCount; x++)
{
switch (format[x])
{
case FT_FLOAT:
case FT_IND:
case FT_INT:
offset += 4;
break;
case FT_BYTE:
offset += 1;
break;
case FT_STRING:
{
// fill only not filled entries
LocalizedString* db2str = *(LocalizedString**)(&dataValue[offset]);
if (db2str->Str[locale] == nullStr)
if (char* str = AddLocaleString(db2str, locale, fields[1 + stringFieldNumInRecord].GetString()))
stringPool.push_back(str);
++stringFieldNumInRecord;
offset += sizeof(char*);
break;
}
}
}
ASSERT(offset == recordSize);
}
else
TC_LOG_ERROR("sql.sql", "Hotfix locale table for storage %s references row that does not exist %u!", _storageName.c_str(), indexValue);
} while (result->NextRow());
return;
}
示例14: HandleWpModifyCommand
static bool HandleWpModifyCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
// first arg: add del text emote spell waittime move
char* show_str = strtok((char*)args, " ");
if (!show_str)
{
return false;
}
std::string show = show_str;
// Check
// Remember: "show" must also be the name of a column!
if ((show != "delay") && (show != "action") && (show != "action_chance")
&& (show != "move_type") && (show != "del") && (show != "move")
)
{
return false;
}
// Next arg is: <PATHID> <WPNUM> <ARGUMENT>
char* arg_str = NULL;
// Did user provide a GUID
// or did the user select a creature?
// -> variable lowguid is filled with the GUID of the NPC
uint32 pathid = 0;
uint32 point = 0;
uint32 wpGuid = 0;
Creature* target = handler->getSelectedCreature();
PreparedStatement* stmt = NULL;
if (!target || target->GetEntry() != VISUAL_WAYPOINT)
{
handler->SendSysMessage("|cffff33ffERROR: You must select a waypoint.|r");
return false;
}
// The visual waypoint
wpGuid = target->GetGUID().GetCounter();
// User did select a visual waypoint?
// Check the creature
stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_BY_WPGUID);
stmt->setUInt32(0, wpGuid);
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (!result)
{
handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH, target->GetGUID().GetCounter());
// Select waypoint number from database
// Since we compare float values, we have to deal with
// some difficulties.
// Here we search for all waypoints that only differ in one from 1 thousand
// (0.001) - There is no other way to compare C++ floats with mySQL floats
// See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
std::string maxDiff = "0.01";
stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_BY_POS);
stmt->setFloat(0, target->GetPositionX());
stmt->setString(1, maxDiff);
stmt->setFloat(2, target->GetPositionY());
stmt->setString(3, maxDiff);
stmt->setFloat(4, target->GetPositionZ());
stmt->setString(5, maxDiff);
PreparedQueryResult queryResult = WorldDatabase.Query(stmt);
if (!queryResult)
{
handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, wpGuid);
return true;
}
}
do
{
Field* fields = result->Fetch();
pathid = fields[0].GetUInt32();
point = fields[1].GetUInt32();
}
while (result->NextRow());
// We have the waypoint number and the GUID of the "master npc"
// Text is enclosed in "<>", all other arguments not
arg_str = strtok((char*)NULL, " ");
// Check for argument
if (show != "del" && show != "move" && arg_str == NULL)
{
handler->PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, show_str);
return false;
}
if (show == "del")
{
handler->PSendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid);
//.........这里部分代码省略.........
示例15: sizeof
//.........这里部分代码省略.........
// Attempt to overwrite existing data
char* dataValue = indexTable[indexValue];
if (!dataValue)
{
newIndexes[newRecords] = indexValue;
dataValue = &tempDataTable[newRecords++ * recordSize];
}
uint32 f = 0;
if (!_loadInfo->Meta->HasIndexFieldInData())
{
*((uint32*)(&dataValue[offset])) = indexValue;
offset += 4;
++f;
}
for (uint32 x = 0; x < _loadInfo->Meta->FieldCount; ++x)
{
for (uint32 z = 0; z < _loadInfo->Meta->ArraySizes[x]; ++z)
{
switch (_loadInfo->TypesString[f])
{
case FT_FLOAT:
*((float*)(&dataValue[offset])) = fields[f].GetFloat();
offset += 4;
break;
case FT_INT:
*((int32*)(&dataValue[offset])) = fields[f].GetInt32();
offset += 4;
break;
case FT_BYTE:
*((int8*)(&dataValue[offset])) = fields[f].GetInt8();
offset += 1;
break;
case FT_SHORT:
*((int16*)(&dataValue[offset])) = fields[f].GetInt16();
offset += 2;
break;
case FT_STRING:
{
LocalizedString** slot = (LocalizedString**)(&dataValue[offset]);
*slot = (LocalizedString*)(&stringHolders[stringHoldersRecordPoolSize * rec + stringFieldOffset]);
ASSERT(*slot);
// Value in database in main table field must be for enUS locale
if (char* str = AddString(&(*slot)->Str[LOCALE_enUS], fields[f].GetString()))
stringPool.push_back(str);
stringFieldOffset += sizeof(LocalizedString);
offset += sizeof(char*);
break;
}
case FT_STRING_NOT_LOCALIZED:
{
char const** slot = (char const**)(&dataValue[offset]);
*slot = (char*)(&stringHolders[stringHoldersRecordPoolSize * rec + stringFieldOffset]);
ASSERT(*slot);
// Value in database in main table field must be for enUS locale
if (char* str = AddString(slot, fields[f].GetString()))
stringPool.push_back(str);
stringFieldOffset += sizeof(char*);
offset += sizeof(char*);
break;
}
default:
ASSERT(false, "Unknown format character '%c' found in %s meta", _loadInfo->Meta->Types[x], _storageName.c_str());
break;
}
++f;
}
}
ASSERT(offset == recordSize);
++rec;
} while (result->NextRow());
if (!newRecords)
{
delete[] tempDataTable;
delete[] newIndexes;
return nullptr;
}
// Compact new data table to only contain new records not previously loaded from file
char* dataTable = new char[newRecords * recordSize];
memcpy(dataTable, tempDataTable, newRecords * recordSize);
// insert new records to index table
for (uint32 i = 0; i < newRecords; ++i)
indexTable[newIndexes[i]] = &dataTable[i * recordSize];
delete[] tempDataTable;
delete[] newIndexes;
records = indexTableSize;
return dataTable;
}