本文整理汇总了C++中SQLTransaction类的典型用法代码示例。如果您正苦于以下问题:C++ SQLTransaction类的具体用法?C++ SQLTransaction怎么用?C++ SQLTransaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SQLTransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TimeStringToSecs
/// Ban an account by player name, duration will be parsed using TimeStringToSecs if it is positive, otherwise permban
BanReturn BanManager::BanAccountByPlayerName(std::string const& CharacterName, std::string const& Duration, std::string const& Reason, std::string const& Author)
{
if (CharacterName.empty() || Duration.empty())
return BAN_SYNTAX_ERROR;
uint32 DurationSecs = TimeStringToSecs(Duration);
uint32 AccountID = sObjectMgr->GetPlayerAccountIdByPlayerName(CharacterName);
if (!AccountID)
return BAN_NOTFOUND;
///- Disconnect all affected players (for IP it can be several)
SQLTransaction trans = LoginDatabase.BeginTransaction();
// pussywizard: check existing ban to prevent overriding by a shorter one! >_>
PreparedStatement* stmtAccountBanned = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED);
stmtAccountBanned->setUInt32(0, AccountID);
PreparedQueryResult banresult = LoginDatabase.Query(stmtAccountBanned);
if (banresult && ((*banresult)[0].GetUInt32() == (*banresult)[1].GetUInt32() || ((*banresult)[1].GetUInt32() > time(nullptr) + DurationSecs && DurationSecs)))
return BAN_LONGER_EXISTS;
// make sure there is only one active ban
PreparedStatement * stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_NOT_BANNED);
stmt->setUInt32(0, AccountID);
trans->Append(stmt);
// No SQL injection with prepared statements
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_BANNED);
stmt->setUInt32(0, AccountID);
stmt->setUInt32(1, DurationSecs);
stmt->setString(2, Author);
stmt->setString(3, Reason);
trans->Append(stmt);
if (WorldSession* session = sWorld->FindSession(AccountID))
if (session->GetPlayerName() != Author)
session->KickPlayer("Ban Account at condition 'FindSession(account)->GetPlayerName() != author'");
if (WorldSession* session = sWorld->FindOfflineSession(AccountID))
if (session->GetPlayerName() != Author)
session->KickPlayer("Ban Account at condition 'FindOfflineSession(account)->GetPlayerName() != author'");
LoginDatabase.CommitTransaction(trans);
if (sWorld->getBoolConfig(CONFIG_SHOW_BAN_IN_WORLD))
{
bool IsPermanetly = true;
if (TimeStringToSecs(Duration) > 0)
IsPermanetly = false;
std::string AccountName;
AccountMgr::GetName(AccountID, AccountName);
if (!IsPermanetly)
sWorld->SendWorldText(LANG_BAN_ACCOUNT_YOUBANNEDMESSAGE_WORLD, Author.c_str(), AccountName.c_str(), secsToTimeString(TimeStringToSecs(Duration), true).c_str(), Reason.c_str());
else
sWorld->SendWorldText(LANG_BAN_ACCOUNT_YOUPERMBANNEDMESSAGE_WORLD, Author.c_str(), AccountName.c_str(), Reason.c_str());
}
return BAN_SUCCESS;
}
示例2: MAKE_NEW_GUID
AccountOpResult AccountMgr::DeleteAccount(uint32 accountId)
{
// Check if accounts exists
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BY_ID);
stmt->setUInt32(0, accountId);
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (!result)
return AOR_NAME_NOT_EXIST;
// Obtain accounts characters
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARS_BY_ACCOUNT_ID);
stmt->setUInt32(0, accountId);
result = CharacterDatabase.Query(stmt);
if (result)
{
do
{
uint32 guidLow = (*result)[0].GetUInt32();
uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
// Kick if player is online
if (Player* p = ObjectAccessor::FindPlayer(guid))
{
WorldSession* s = p->GetSession();
s->KickPlayer(); // mark session to remove at next session list update
s->LogoutPlayer(false); // logout player without waiting next session list update
}
Player::DeleteFromDB(guid, accountId, false); // no need to update realm characters
} while (result->NextRow());
}
// table realm specific but common for all characters of account for realm
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_TUTORIALS);
stmt->setUInt32(0, accountId);
CharacterDatabase.Execute(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ACCOUNT_DATA);
stmt->setUInt32(0, accountId);
CharacterDatabase.Execute(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHARACTER_BAN);
stmt->setUInt32(0, accountId);
CharacterDatabase.Execute(stmt);
SQLTransaction trans = LoginDatabase.BeginTransaction();
stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT);
stmt->setUInt32(0, accountId);
trans->Append(stmt);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS);
stmt->setUInt32(0, accountId);
trans->Append(stmt);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_REALM_CHARACTERS);
stmt->setUInt32(0, accountId);
trans->Append(stmt);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_BANNED);
stmt->setUInt32(0, accountId);
trans->Append(stmt);
LoginDatabase.CommitTransaction(trans);
return AOR_OK;
}
示例3: SaveToDB
void Item::SaveToDB(SQLTransaction& trans)
{
bool isInTransaction = !(trans.null());
if(!isInTransaction)
trans = CharacterDatabase.BeginTransaction();
uint32 guid = GetGUIDLow();
switch(uState)
{
case ITEM_NEW:
case ITEM_CHANGED:
{
uint8 index = 0;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(uState == ITEM_NEW ? CHAR_ADD_ITEM_INSTANCE : CHAR_UPDATE_ITEM_INSTANCE);
stmt->setUInt32( index, GetEntry());
stmt->setUInt32(++index, GUID_LOPART(GetOwnerGUID()));
stmt->setUInt32(++index, GUID_LOPART(GetUInt64Value(ITEM_FIELD_CREATOR)));
stmt->setUInt32(++index, GUID_LOPART(GetUInt64Value(ITEM_FIELD_GIFTCREATOR)));
stmt->setUInt32(++index, GetCount());
stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_DURATION));
std::ostringstream ssSpells;
for(uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
ssSpells << GetSpellCharges(i) << " ";
stmt->setString(++index, ssSpells.str());
stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_FLAGS));
std::ostringstream ssEnchants;
for(uint8 i = 0; i < MAX_ENCHANTMENT_SLOT; ++i)
{
ssEnchants << GetEnchantmentId(EnchantmentSlot(i)) << " ";
ssEnchants << GetEnchantmentDuration(EnchantmentSlot(i)) << " ";
ssEnchants << GetEnchantmentCharges(EnchantmentSlot(i)) << " ";
}
stmt->setString(++index, ssEnchants.str());
stmt->setInt32 (++index, GetItemRandomPropertyId());
stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_DURABILITY));
stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME));
stmt->setString(++index, m_text);
stmt->setUInt32(++index, guid);
trans->Append(stmt);
if((uState == ITEM_CHANGED) && HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED))
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GIFT_OWNER);
stmt->setUInt32(0, GUID_LOPART(GetOwnerGUID()));
stmt->setUInt32(1, guid);
trans->Append(stmt);
}
break;
}
case ITEM_REMOVED:
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_INSTANCE);
stmt->setUInt32(0, guid);
trans->Append(stmt);
if(HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED))
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GIFT);
stmt->setUInt32(0, guid);
trans->Append(stmt);
}
if(!isInTransaction)
CharacterDatabase.CommitTransaction(trans);
delete this;
return;
}
case ITEM_UNCHANGED:
break;
}
SetState(ITEM_UNCHANGED);
if(!isInTransaction)
CharacterDatabase.CommitTransaction(trans);
}
示例4: GUID_LOPART
//.........这里部分代码省略.........
result = CharacterDatabase.Query(stmt);
if (result)
signatures = uint8(result->GetRowCount());
else
signatures = 0;
uint32 requiredSignatures;
if (type == GUILD_CHARTER_TYPE)
requiredSignatures = sWorld->getIntConfig(CONFIG_MIN_PETITION_SIGNS);
else
requiredSignatures = type-1;
// Notify player if signatures are missing
if (signatures < requiredSignatures)
{
data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4);
data << (uint32)PETITION_TURN_NEED_MORE_SIGNATURES;
SendPacket(&data);
return;
}
// Proceed with guild/arena team creation
// Delete charter item
_player->DestroyItem(item->GetBagSlot(), item->GetSlot(), true);
if (type == GUILD_CHARTER_TYPE)
{
// Create guild
Guild* guild = new Guild;
if (!guild->Create(_player, name))
{
delete guild;
return;
}
// Register guild and add guild master
sGuildMgr->AddGuild(guild);
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_COMMAND_SUCCESS, name);
// 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();
}
}
else
{
// Receive the rest of the packet in arena team creation case
uint32 background, icon, iconcolor, border, bordercolor;
recvData >> background >> icon >> iconcolor >> border >> bordercolor;
// Create arena team
ArenaTeam* arenaTeam = new ArenaTeam();
if (!arenaTeam->Create(_player->GetGUID(), type, name, background, icon, iconcolor, border, bordercolor))
{
delete arenaTeam;
return;
}
// Register arena team
sArenaTeamMgr->AddArenaTeam(arenaTeam);
sLog->outDebug(LOG_FILTER_NETWORKIO, "PetitonsHandler: Arena team (guid: %u) added to ObjectMgr", arenaTeam->GetId());
// Add members
for (uint8 i = 0; i < signatures; ++i)
{
Field* fields = result->Fetch();
uint32 memberGUID = fields[0].GetUInt32();
sLog->outDebug(LOG_FILTER_NETWORKIO, "PetitionsHandler: Adding arena team (guid: %u) member %u", arenaTeam->GetId(), memberGUID);
arenaTeam->AddMember(MAKE_NEW_GUID(memberGUID, 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 << (uint32)PETITION_TURN_OK;
SendPacket(&data);
}
示例5: HandleMailReturnToSender
void WorldSession::HandleMailReturnToSender(WorldPacket & recv_data)
{
uint64 mailbox;
uint32 mailId;
recv_data >> mailbox;
recv_data >> mailId;
recv_data.read_skip<uint64>(); // original sender GUID for return to, not used
if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX))
return;
Player* player = _player;
Mail* m = player->GetMail(mailId);
if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL))
{
player->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_ERR_INTERNAL_ERROR);
return;
}
//we can return mail now
//so firstly delete the old one
SQLTransaction trans = CharacterDatabase.BeginTransaction();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_BY_ID);
stmt->setUInt32(0, mailId);
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_ITEM_BY_ID);
stmt->setUInt32(0, mailId);
trans->Append(stmt);
player->RemoveMail(mailId);
// only return mail if the player exists (and delete if not existing)
if (m->messageType == MAIL_NORMAL && m->sender)
{
MailDraft draft(m->subject, m->body);
if (m->mailTemplateId)
draft = MailDraft(m->mailTemplateId, false); // items already included
if (m->HasItems())
{
for (MailItemInfoVec::iterator itr2 = m->items.begin(); itr2 != m->items.end(); ++itr2)
{
Item* item = player->GetMItem(itr2->item_guid);
if (item)
draft.AddItem(item);
else
{
//WTF?
}
player->RemoveMItem(itr2->item_guid);
}
}
draft.AddMoney(m->money).SendReturnToSender(GetAccountId(), m->receiver, m->sender, trans);
}
CharacterDatabase.CommitTransaction(trans);
delete m; //we can deallocate old mail
player->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_OK);
}
示例6: SendPetNameInvalid
void WorldSession::HandlePetRename(WorldPacket & recv_data)
{
sLog->outDetail("HandlePetRename. CMSG_PET_RENAME");
uint64 petguid;
uint8 isdeclined;
std::string name;
DeclinedName declinedname;
recv_data >> petguid;
recv_data >> name;
recv_data >> isdeclined;
Pet* pet = ObjectAccessor::FindPet(petguid);
// check it!
if(!pet || !pet->isPet() || ((Pet*)pet)->getPetType()!= HUNTER_PET ||
!pet->HasByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED) ||
pet->GetOwnerGUID() != _player->GetGUID() || !pet->GetCharmInfo())
return;
PetNameInvalidReason res = ObjectMgr::CheckPetName(name);
if(res != PET_NAME_SUCCESS)
{
SendPetNameInvalid(res, name, NULL);
return;
}
if(sObjectMgr->IsReservedName(name))
{
SendPetNameInvalid(PET_NAME_RESERVED, name, NULL);
return;
}
pet->SetName(name);
Unit* owner = pet->GetOwner();
if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && owner->ToPlayer()->GetGroup())
owner->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_NAME);
pet->RemoveByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED);
if(isdeclined)
{
for(uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
{
recv_data >> declinedname.name[i];
}
std::wstring wname;
Utf8toWStr(name, wname);
if(!ObjectMgr::CheckDeclinedNames(wname, declinedname))
{
SendPetNameInvalid(PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME, name, &declinedname);
return;
}
}
SQLTransaction trans = CharacterDatabase.BeginTransaction();
if(isdeclined)
{
for(uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
CharacterDatabase.EscapeString(declinedname.name[i]);
trans->PAppend("DELETE FROM character_pet_declinedname WHERE owner = '%u' AND id = '%u'", _player->GetGUIDLow(), pet->GetCharmInfo()->GetPetNumber());
trans->PAppend("INSERT INTO character_pet_declinedname (id, owner, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u', '%u', '%s', '%s', '%s', '%s', '%s')",
pet->GetCharmInfo()->GetPetNumber(), _player->GetGUIDLow(), declinedname.name[0].c_str(), declinedname.name[1].c_str(), declinedname.name[2].c_str(), declinedname.name[3].c_str(), declinedname.name[4].c_str());
}
CharacterDatabase.EscapeString(name);
trans->PAppend("UPDATE character_pet SET name = '%s', renamed = '1' WHERE owner = '%u' AND id = '%u'", name.c_str(), _player->GetGUIDLow(), pet->GetCharmInfo()->GetPetNumber());
CharacterDatabase.CommitTransaction(trans);
pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL))); // cast can't be helped
}
示例7: SendAuctionWonMail
//does not clear ram
void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, SQLTransaction& trans)
{
Item* pItem = GetAItem(auction->itemGUIDLow);
if (!pItem)
return;
uint32 bidderAccId = 0;
uint64 bidderGuid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
Player* bidder = ObjectAccessor::FindPlayer(bidderGuid);
// data for gm.log
std::string bidderName;
bool logGmTrade = false;
if (bidder)
{
bidderAccId = bidder->GetSession()->GetAccountId();
bidderName = bidder->GetName();
logGmTrade = bidder->GetSession()->HasPermission(RBAC_PERM_LOG_GM_TRADE);
}
else
{
bidderAccId = sObjectMgr->GetPlayerAccountIdByGUID(bidderGuid);
logGmTrade = AccountMgr::HasPermission(bidderAccId, RBAC_PERM_LOG_GM_TRADE, realmID);
if (logGmTrade && !sObjectMgr->GetPlayerNameByGUID(bidderGuid, bidderName))
bidderName = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);
}
if (logGmTrade)
{
std::string ownerName;
if (!sObjectMgr->GetPlayerNameByGUID(auction->owner, ownerName))
ownerName = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);
uint32 ownerAccId = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner);
sLog->outCommand(bidderAccId, "GM %s (Account: %u) won item in auction: %s (Entry: %u Count: %u) and pay money: %u. Original owner %s (Account: %u)",
bidderName.c_str(), bidderAccId, pItem->GetTemplate()->Name1.c_str(), pItem->GetEntry(), pItem->GetCount(), auction->bid, ownerName.c_str(), ownerAccId);
}
// receiver exist
if (bidder || bidderAccId)
{
// set owner to bidder (to prevent delete item with sender char deleting)
// owner in `data` will set at mail receive and item extracting
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ITEM_OWNER);
stmt->setUInt32(0, auction->bidder);
stmt->setUInt32(1, pItem->GetGUIDLow());
trans->Append(stmt);
if (bidder)
{
bidder->GetSession()->SendAuctionBidderNotification(auction->GetHouseId(), auction->Id, bidderGuid, 0, 0, auction->itemEntry);
// FIXME: for offline player need also
bidder->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WON_AUCTIONS, 1);
}
MailDraft(auction->BuildAuctionMailSubject(AUCTION_WON), AuctionEntry::BuildAuctionMailBody(auction->owner, auction->bid, auction->buyout, 0, 0))
.AddItem(pItem)
.SendMailTo(trans, MailReceiver(bidder, auction->bidder), auction, MAIL_CHECK_MASK_COPIED);
}
}
示例8: TC_LOG_DEBUG
void WorldSession::HandleStableChangeSlot(WorldPacket& recvData)
{
TC_LOG_DEBUG("network", "WORLD: Recv CMSG_STABLE_CHANGE_SLOT");
uint32 PetGUID;
uint8 petnumber;
ObjectGuid npcGUID;
recvData >> PetGUID >> petnumber;
recvData.ReadGuidMask(npcGUID, 5, 7, 3, 2, 6, 1, 0, 4);
recvData.ReadGuidBytes(npcGUID, 0, 3, 2, 6, 5, 7, 4, 1);
if (!CheckStableMaster(npcGUID))
{
SendStableResult(STABLE_ERR_STABLE);
return;
}
// remove fake death
if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
PetSlots temp = GetPlayer()->GetSession()->checkPets(petnumber, PetGUID);
if (!GetPlayer()->GetPet())
{
if (!GetPlayer()->GetSession()->movePet(petnumber, PetGUID))
{
SendStableResult(STABLE_ERR_INVALID_SLOT); // Something whent wrong.
return;
}
WorldPacket data(SMSG_PET_SLOT_UPDATED, 16);
data << uint32(PetGUID);
data << uint32(temp.slot);
data << uint32(temp.entry);
data << uint32(petnumber);
SendPacket(&data);
}
else if (GetPlayer()->GetPet() && (GetPlayer()->GetPetSlot() != petnumber && GetPlayer()->GetPet()->GetCharmInfo()->GetPetNumber() != PetGUID))
{
if (!GetPlayer()->GetSession()->movePet(petnumber, PetGUID))
{
SendStableResult(STABLE_ERR_INVALID_SLOT); // Something whent wrong.
return;
}
WorldPacket data(SMSG_PET_SLOT_UPDATED, 16);
data << uint32(PetGUID);
data << uint32(temp.slot);
data << uint32(temp.entry);
data << uint32(petnumber);
SendPacket(&data);
}
else
{
SendStableResult(STABLE_ERR_INVALID_SLOT); // Dont reorder the active pet.
return;
}
SQLTransaction trans = CharacterDatabase.BeginTransaction();
PreparedStatement* stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_PET_SLOT_BY_ID);
stmt2->setUInt8(0, petnumber);
stmt2->setUInt32(1, _player->GetGUIDLow());
stmt2->setUInt32(2, PetGUID);
trans->Append(stmt2);
if ((temp.entry > 0 || temp.name.length() > 0) && temp.entry != PetGUID) // || temp.slot != _player->GetSlot())
{
stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_PET_SLOT_BY_ID);
stmt2->setUInt8(0, temp.slot);
stmt2->setUInt32(1, _player->GetGUIDLow());
stmt2->setUInt32(2, temp.entry);
trans->Append(stmt2);
}
CharacterDatabase.CommitTransaction(trans);
SendStableResult(STABLE_SUCCESS_STABLE);
return;
}
示例9: TC_LOG_DEBUG
// this function is called when client bids or buys out auction
void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
{
TC_LOG_DEBUG("network", "WORLD: Received CMSG_AUCTION_PLACE_BID");
uint64 auctioneer;
uint32 auctionId;
uint64 price;
recvData >> auctioneer;
recvData >> auctionId;
recvData >> price;
if (!auctionId || !price)
return; // check for cheaters
Creature* creature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer, UNIT_NPC_FLAG_AUCTIONEER);
if (!creature)
{
TC_LOG_DEBUG("network", "WORLD: HandleAuctionPlaceBid - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)));
return;
}
// remove fake death
if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(creature->getFaction());
AuctionEntry* auction = auctionHouse->GetAuction(auctionId);
Player* player = GetPlayer();
if (!auction || auction->owner == player->GetGUIDLow())
{
//you cannot bid your own auction:
SendAuctionCommandResult(NULL, AUCTION_PLACE_BID, ERR_AUCTION_BID_OWN);
return;
}
// impossible have online own another character (use this for speedup check in case online owner)
/*Player* auction_owner = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER));
if (!auction_owner && sObjectMgr->GetPlayerAccountIdByGUID(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)) == player->GetSession()->GetAccountId())
{
//you cannot bid your another character auction:
SendAuctionCommandResult(NULL, AUCTION_PLACE_BID, ERR_AUCTION_BID_OWN);
return;
}*/
// cheating
if (price <= auction->bid || price < auction->startbid)
return;
// price too low for next bid if not buyout
if ((price < auction->buyout || auction->buyout == 0) &&
price < auction->bid + auction->GetAuctionOutBid())
{
// client already test it but just in case ...
SendAuctionCommandResult(auction, AUCTION_PLACE_BID, ERR_AUCTION_HIGHER_BID);
return;
}
if (!player->HasEnoughMoney(price))
{
// client already test it but just in case ...
SendAuctionCommandResult(auction, AUCTION_PLACE_BID, ERR_AUCTION_NOT_ENOUGHT_MONEY);
return;
}
SQLTransaction trans = CharacterDatabase.BeginTransaction();
if (price < auction->buyout || auction->buyout == 0)
{
if (auction->bidder > 0)
{
if (auction->bidder == player->GetGUIDLow())
player->ModifyMoney(-int64(price - auction->bid));
else
{
// mail to last bidder and return money
sAuctionMgr->SendAuctionOutbiddedMail(auction, price, GetPlayer(), trans);
player->ModifyMoney(-int64(price));
}
}
else
player->ModifyMoney(-int64(price));
auction->bidder = player->GetGUIDLow();
auction->bid = price;
GetPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, price);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_AUCTION_BID);
stmt->setUInt32(0, auction->bidder);
stmt->setUInt32(1, auction->bid);
stmt->setUInt32(2, auction->Id);
trans->Append(stmt);
SendAuctionCommandResult(auction, AUCTION_PLACE_BID, ERR_AUCTION_OK);
}
else
{
//buyout:
//.........这里部分代码省略.........
示例10: GetPlayer
//this function is called when client bids or buys out auction
void WorldSession::HandleAuctionPlaceBid(WorldPacket & recv_data)
{
uint64 auctioneer;
uint32 auctionId;
uint32 priceTmp;
uint64 price;
recv_data >> auctioneer;
recv_data >> auctionId >> priceTmp;
price = priceTmp;
if (!auctionId || !price)
return; //check for cheaters
Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer, UNIT_NPC_FLAG_AUCTIONEER);
if (!pCreature)
{
sLog->outDebug("WORLD: HandleAuctionPlaceBid - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)));
return;
}
// remove fake death
if (GetPlayer()->HasUnitState(UNIT_STAT_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
AuctionHouseObject *auctionHouse = sAuctionMgr->GetAuctionsMap(pCreature->getFaction());
AuctionEntry *auction = auctionHouse->GetAuction(auctionId);
Player *pl = GetPlayer();
if (!auction || auction->owner == pl->GetGUIDLow())
{
//you cannot bid your own auction:
SendAuctionCommandResult(0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR);
return;
}
// impossible have online own another character (use this for speedup check in case online owner)
Player* auction_owner = sObjectMgr->GetPlayer(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER));
if (!auction_owner && sObjectMgr->GetPlayerAccountIdByGUID(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)) == pl->GetSession()->GetAccountId())
{
//you cannot bid your another character auction:
SendAuctionCommandResult(0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR);
return;
}
// cheating
if (price <= auction->bid || price < auction->startbid)
return;
// price too low for next bid if not buyout
if ((price < auction->buyout || auction->buyout == 0) &&
price < auction->bid + auction->GetAuctionOutBid())
{
//auction has already higher bid, client tests it!
return;
}
if (!pl->HasEnoughMoney(price))
{
//you don't have enought money!, client tests!
//SendAuctionCommandResult(auction->auctionId, AUCTION_PLACE_BID, ???);
return;
}
SQLTransaction trans = CharacterDatabase.BeginTransaction();
if (price < auction->buyout || auction->buyout == 0)
{
if (auction->bidder > 0)
{
if (auction->bidder == pl->GetGUIDLow())
pl->ModifyMoney(-int32(price - auction->bid));
else
{
// mail to last bidder and return money
sAuctionMgr->SendAuctionOutbiddedMail(auction, price, GetPlayer(), trans);
pl->ModifyMoney(-int32(price));
}
}
else
pl->ModifyMoney(-int32(price));
auction->bidder = pl->GetGUIDLow();
auction->bid = (price >> 32);
GetPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, price);
trans->PAppend("UPDATE auctionhouse SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id);
SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK, 0);
}
else
{
//buyout:
if (pl->GetGUIDLow() == auction->bidder)
示例11: SaveToDB
void AchievementMgr::SaveToDB(SQLTransaction& trans)
{
if (!m_completedAchievements.empty())
{
bool need_execute = false;
std::ostringstream ssdel;
std::ostringstream ssins;
for (CompletedAchievementMap::iterator iter = m_completedAchievements.begin(); iter != m_completedAchievements.end(); ++iter)
{
if (!iter->second.changed)
continue;
/// first new/changed record prefix
if (!need_execute)
{
ssdel << "DELETE FROM character_achievement WHERE guid = " << GetPlayer()->GetGUIDLow() << " AND achievement IN (";
ssins << "INSERT INTO character_achievement (guid, achievement, date) VALUES ";
need_execute = true;
}
/// next new/changed record prefix
else
{
ssdel << ',';
ssins << ',';
}
// new/changed record data
ssdel << iter->first;
ssins << '(' << GetPlayer()->GetGUIDLow() << ',' << iter->first << ',' << uint64(iter->second.date) << ')';
/// mark as saved in db
iter->second.changed = false;
}
if (need_execute)
{
ssdel << ')';
trans->Append(ssdel.str().c_str());
trans->Append(ssins.str().c_str());
}
}
if (!m_criteriaProgress.empty())
{
/// prepare deleting and insert
bool need_execute_del = false;
bool need_execute_ins = false;
std::ostringstream ssdel;
std::ostringstream ssins;
for (CriteriaProgressMap::iterator iter = m_criteriaProgress.begin(); iter != m_criteriaProgress.end(); ++iter)
{
if (!iter->second.changed)
continue;
// deleted data (including 0 progress state)
{
/// first new/changed record prefix (for any counter value)
if (!need_execute_del)
{
ssdel << "DELETE FROM character_achievement_progress WHERE guid = " << GetPlayer()->GetGUIDLow() << " AND criteria IN (";
need_execute_del = true;
}
/// next new/changed record prefix
else
ssdel << ',';
// new/changed record data
ssdel << iter->first;
}
// store data only for real progress
if (iter->second.counter != 0)
{
/// first new/changed record prefix
if (!need_execute_ins)
{
ssins << "INSERT INTO character_achievement_progress (guid, criteria, counter, date) VALUES ";
need_execute_ins = true;
}
/// next new/changed record prefix
else
ssins << ',';
// new/changed record data
ssins << '(' << GetPlayer()->GetGUIDLow() << ',' << iter->first << ',' << iter->second.counter << ',' << iter->second.date << ')';
}
/// mark as updated in db
iter->second.changed = false;
}
if (need_execute_del) // DELETE ... IN (.... _)_
ssdel << ')';
if (need_execute_del || need_execute_ins)
{
if (need_execute_del)
trans->Append(ssdel.str().c_str());
if (need_execute_ins)
trans->Append(ssins.str().c_str());
//.........这里部分代码省略.........
示例12: TC_LOG_DEBUG
void WorldSession::HandleWrapItemOpcode(WorldPacket& recvData)
{
TC_LOG_DEBUG("network", "Received opcode CMSG_WRAP_ITEM");
uint8 gift_bag, gift_slot, item_bag, item_slot;
recvData >> gift_bag >> gift_slot; // paper
recvData >> item_bag >> item_slot; // item
TC_LOG_DEBUG("network", "WRAP: receive gift_bag = %u, gift_slot = %u, item_bag = %u, item_slot = %u", gift_bag, gift_slot, item_bag, item_slot);
Item* gift = _player->GetItemByPos(gift_bag, gift_slot);
if (!gift)
{
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, gift, nullptr);
return;
}
if (!(gift->GetTemplate()->Flags & ITEM_FLAG_IS_WRAPPER)) // cheating: non-wrapper wrapper
{
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, gift, nullptr);
return;
}
Item* item = _player->GetItemByPos(item_bag, item_slot);
if (!item)
{
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, item, nullptr);
return;
}
if (item == gift) // not possable with pacjket from real client
{
_player->SendEquipError(EQUIP_ERR_WRAPPED_CANT_BE_WRAPPED, item, nullptr);
return;
}
if (item->IsEquipped())
{
_player->SendEquipError(EQUIP_ERR_EQUIPPED_CANT_BE_WRAPPED, item, nullptr);
return;
}
if (!item->GetGuidValue(ITEM_FIELD_GIFTCREATOR).IsEmpty()) // HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED);
{
_player->SendEquipError(EQUIP_ERR_WRAPPED_CANT_BE_WRAPPED, item, nullptr);
return;
}
if (item->IsBag())
{
_player->SendEquipError(EQUIP_ERR_BAGS_CANT_BE_WRAPPED, item, nullptr);
return;
}
if (item->IsSoulBound())
{
_player->SendEquipError(EQUIP_ERR_BOUND_CANT_BE_WRAPPED, item, nullptr);
return;
}
if (item->GetMaxStackCount() != 1)
{
_player->SendEquipError(EQUIP_ERR_STACKABLE_CANT_BE_WRAPPED, item, nullptr);
return;
}
// maybe not correct check (it is better than nothing)
if (item->GetTemplate()->MaxCount>0)
{
_player->SendEquipError(EQUIP_ERR_UNIQUE_CANT_BE_WRAPPED, item, nullptr);
return;
}
SQLTransaction trans = CharacterDatabase.BeginTransaction();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_GIFT);
stmt->setUInt32(0, item->GetOwnerGUID().GetCounter());
stmt->setUInt32(1, item->GetGUID().GetCounter());
stmt->setUInt32(2, item->GetEntry());
stmt->setUInt32(3, item->GetUInt32Value(ITEM_FIELD_FLAGS));
trans->Append(stmt);
item->SetEntry(gift->GetEntry());
switch (item->GetEntry())
{
case 5042: item->SetEntry(5043); break;
case 5048: item->SetEntry(5044); break;
case 17303: item->SetEntry(17302); break;
case 17304: item->SetEntry(17305); break;
case 17307: item->SetEntry(17308); break;
case 21830: item->SetEntry(21831); break;
}
item->SetGuidValue(ITEM_FIELD_GIFTCREATOR, _player->GetGUID());
item->SetUInt32Value(ITEM_FIELD_FLAGS, ITEM_FIELD_FLAG_WRAPPED);
item->SetState(ITEM_CHANGED, _player);
if (item->GetState() == ITEM_NEW) // save new item, to have alway for `character_gifts` record in `item_instance`
//.........这里部分代码省略.........
示例13: GUID_LOPART
//.........这里部分代码省略.........
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);
}
示例14: TC_LOG_INFO
void WorldSession::HandlePetRename(WorldPacket& recvData)
{
TC_LOG_INFO("network", "HandlePetRename. CMSG_PET_RENAME");
uint64 petguid;
uint8 isdeclined;
std::string name;
DeclinedName declinedname;
recvData >> petguid;
recvData >> name;
recvData >> isdeclined;
Pet* pet = ObjectAccessor::FindPet(petguid);
// check it!
if (!pet || !pet->IsPet() || ((Pet*)pet)->getPetType()!= HUNTER_PET ||
!pet->HasByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED) ||
pet->GetOwnerGUID() != _player->GetGUID() || !pet->GetCharmInfo())
return;
PetNameInvalidReason res = ObjectMgr::CheckPetName(name);
if (res != PET_NAME_SUCCESS)
{
SendPetNameInvalid(res, name, NULL);
return;
}
if (sObjectMgr->IsReservedName(name))
{
SendPetNameInvalid(PET_NAME_RESERVED, name, NULL);
return;
}
pet->SetName(name);
if (pet->GetOwner()->GetGroup())
pet->GetOwner()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_NAME);
pet->RemoveByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED);
if (isdeclined)
{
for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
{
recvData >> declinedname.name[i];
}
std::wstring wname;
if (!Utf8toWStr(name, wname))
return;
if (!ObjectMgr::CheckDeclinedNames(wname, declinedname))
{
SendPetNameInvalid(PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME, name, &declinedname);
return;
}
}
SQLTransaction trans = CharacterDatabase.BeginTransaction();
if (isdeclined)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_PET_DECLINEDNAME);
stmt->setUInt32(0, pet->GetCharmInfo()->GetPetNumber());
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_PET_DECLINEDNAME);
stmt->setUInt32(0, _player->GetGUIDLow());
for (uint8 i = 0; i < 5; i++)
stmt->setString(i+1, declinedname.name[i]);
trans->Append(stmt);
}
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_PET_NAME);
stmt->setString(0, name);
stmt->setUInt32(1, _player->GetGUIDLow());
stmt->setUInt32(2, pet->GetCharmInfo()->GetPetNumber());
trans->Append(stmt);
CharacterDatabase.CommitTransaction(trans);
pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL))); // cast can't be helped
}
示例15: time
void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, bool warn, time_t resetTime)
{
// global reset for all instances of the given map
MapEntry const *mapEntry = sMapStore.LookupEntry(mapid);
if (!mapEntry->Instanceable())
return;
time_t now = time(NULL);
if (!warn)
{
MapDifficulty const* mapDiff = GetMapDifficultyData(mapid, difficulty);
if (!mapDiff || !mapDiff->resetTime)
{
sLog->outError("InstanceSaveManager::ResetOrWarnAll: not valid difficulty or no reset delay for map %d", mapid);
return;
}
// remove all binds to instances of the given map
for (InstanceSaveHashMap::iterator itr = m_instanceSaveById.begin(); itr != m_instanceSaveById.end();)
{
if (itr->second->GetMapId() == mapid && itr->second->GetDifficulty() == difficulty)
_ResetSave(itr);
else
++itr;
}
// delete them from the DB, even if not loaded
SQLTransaction trans = CharacterDatabase.BeginTransaction();
trans->PAppend("DELETE FROM character_instance USING character_instance LEFT JOIN instance ON character_instance.instance = id WHERE map = '%u' and difficulty='%u'", mapid, difficulty);
trans->PAppend("DELETE FROM group_instance USING group_instance LEFT JOIN instance ON group_instance.instance = id WHERE map = '%u' and difficulty='%u'", mapid, difficulty);
trans->PAppend("DELETE FROM instance WHERE map = '%u' and difficulty='%u'", mapid, difficulty);
CharacterDatabase.CommitTransaction(trans);
// calculate the next reset time
uint32 diff = sWorld->getIntConfig(CONFIG_INSTANCE_RESET_TIME_HOUR) * HOUR;
uint32 period = uint32(((mapDiff->resetTime * sWorld->getRate(RATE_INSTANCE_RESET_TIME))/DAY) * DAY);
if (period < DAY)
period = DAY;
uint64 next_reset = ((resetTime + MINUTE) / DAY * DAY) + period + diff;
SetResetTimeFor(mapid, difficulty, next_reset);
ScheduleReset(true, time_t(next_reset-3600), InstResetEvent(1, mapid, difficulty, 0));
// update it in the DB
CharacterDatabase.PExecute("UPDATE instance_reset SET resettime = '%u' WHERE mapid = '%d' AND difficulty = '%d'", uint32(next_reset), mapid, difficulty);
}
// note: this isn't fast but it's meant to be executed very rarely
Map const *map = sMapMgr->CreateBaseMap(mapid); // _not_ include difficulty
MapInstanced::InstancedMaps &instMaps = ((MapInstanced*)map)->GetInstancedMaps();
MapInstanced::InstancedMaps::iterator mitr;
uint32 timeLeft;
for (mitr = instMaps.begin(); mitr != instMaps.end(); ++mitr)
{
Map *map2 = mitr->second;
if (!map2->IsDungeon())
continue;
if (warn)
{
if (now <= resetTime)
timeLeft = 0;
else
timeLeft = uint32(now - resetTime);
((InstanceMap*)map2)->SendResetWarnings(timeLeft);
}
else
((InstanceMap*)map2)->Reset(INSTANCE_RESET_GLOBAL);
}
// TODO: delete creature/gameobject respawn times even if the maps are not loaded
}