本文整理汇总了C++中SQLTransaction::Append方法的典型用法代码示例。如果您正苦于以下问题:C++ SQLTransaction::Append方法的具体用法?C++ SQLTransaction::Append怎么用?C++ SQLTransaction::Append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLTransaction
的用法示例。
在下文中一共展示了SQLTransaction::Append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandlePetitionBuyOpcode
//.........这里部分代码省略.........
uint32 charterid = 0;
uint32 cost = 0;
uint32 type = 0;
if (creature->isTabardDesigner())
{
// if tabard designer, then trying to buy a guild charter.
// do not let if already in guild.
if (_player->GetGuildId())
return;
charterid = GUILD_CHARTER;
cost = GUILD_CHARTER_COST;
type = GUILD_CHARTER_TYPE;
}
if (type == GUILD_CHARTER_TYPE)
{
if (sGuildMgr->GetGuildByName(name))
{
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_EXISTS_S, name);
return;
}
if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
{
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_INVALID, name);
return;
}
}
ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(charterid);
if (!pProto)
{
_player->SendBuyError(BUY_ERR_CANT_FIND_ITEM, NULL, charterid, 0);
return;
}
if (!_player->HasEnoughMoney(uint64(cost)))
{ //player hasn't got enough money
_player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, creature, charterid, 0);
return;
}
ItemPosCountVec dest;
InventoryResult msg = _player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, charterid, pProto->BuyCount);
if (msg != EQUIP_ERR_OK)
{
_player->SendEquipError(msg, NULL, NULL, charterid);
return;
}
_player->ModifyMoney(-(int32)cost);
Item* charter = _player->StoreNewItem(dest, charterid, true);
if (!charter)
return;
charter->SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1, charter->GetGUIDLow());
// ITEM_FIELD_ENCHANTMENT_1_1 is guild/arenateam id
// ITEM_FIELD_ENCHANTMENT_1_1+1 is current signatures count (showed on item)
charter->SetState(ITEM_CHANGED, _player);
_player->SendNewItem(charter, 1, true, false);
// a petition is invalid, if both the owner and the type matches
// we checked above, if this player is in an arenateam, so this must be
// datacorruption
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PETITION_BY_OWNER);
stmt->setUInt32(0, _player->GetGUIDLow());
stmt->setUInt8(1, type);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
std::ostringstream ssInvalidPetitionGUIDs;
if (result)
{
do
{
Field* fields = result->Fetch();
ssInvalidPetitionGUIDs << '\'' << fields[0].GetUInt32() << "', ";
}
while (result->NextRow());
}
// delete petitions with the same guid as this one
ssInvalidPetitionGUIDs << '\'' << charter->GetGUIDLow() << '\'';
sLog->outDebug(LOG_FILTER_NETWORKIO, "Invalid petition GUIDs: %s", ssInvalidPetitionGUIDs.str().c_str());
CharacterDatabase.EscapeString(name);
SQLTransaction trans = CharacterDatabase.BeginTransaction();
trans->PAppend("DELETE FROM petition WHERE petitionguid IN (%s)", ssInvalidPetitionGUIDs.str().c_str());
trans->PAppend("DELETE FROM petition_sign WHERE petitionguid IN (%s)", ssInvalidPetitionGUIDs.str().c_str());
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_PETITION);
stmt->setUInt32(0, _player->GetGUIDLow());
stmt->setUInt32(1, charter->GetGUIDLow());
stmt->setString(2, name);
stmt->setUInt8(3, uint8(type));
trans->Append(stmt);
CharacterDatabase.CommitTransaction(trans);
}
示例2: HandlePetRename
void WorldSession::HandlePetRename(WorldPacket& recvData)
{
sLog->outInfo(LOG_FILTER_NETWORKIO, "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);
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)
{
recvData >> 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)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_PET_DECLINEDNAME);
stmt->setUInt32(0, pet->GetCharmInfo()->GetPetNumber());
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_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
}
示例3: DeleteFromDB
void AuctionEntry::DeleteFromDB(SQLTransaction& trans) const
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_AUCTION);
stmt->setUInt32(0, Id);
trans->Append(stmt);
}
示例4: DeleteFromInventoryDB
/*static*/
void Item::DeleteFromInventoryDB(SQLTransaction& trans, uint32 itemGuid)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INVENTORY_BY_ITEM);
stmt->setUInt32(0, itemGuid);
trans->Append(stmt);
}
示例5: HandleTurnInPetitionOpcode
//.........这里部分代码省略.........
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);
TC_LOG_DEBUG(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();
TC_LOG_DEBUG(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
TC_LOG_DEBUG(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);
}
示例6: HandleMailReturnToSender
void WorldSession::HandleMailReturnToSender(WorldPacket & recv_data)
{
if (sWorld->getIntConfig(CONFIG_CORE_TYPE) == NODE_TYPE_MASTER)
{
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))
if (!GetPlayer()->GetNPCIfCanInteractWith(mailbox, UNIT_NPC_FLAG_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);
}
示例7: 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());
//.........这里部分代码省略.........
示例8: HandleStableChangeSlot
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: HandleWrapItemOpcode
void WorldSession::HandleWrapItemOpcode(WorldPacket& recv_data)
{
sLog->outDebug(LOG_FILTER_NETWORKIO, "Received opcode CMSG_WRAP_ITEM");
uint8 gift_bag, gift_slot, item_bag, item_slot;
recv_data >> gift_bag >> gift_slot; // paper
recv_data >> item_bag >> item_slot; // item
sLog->outDebug(LOG_FILTER_NETWORKIO, "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, NULL);
return;
}
if (!(gift->GetTemplate()->Flags & ITEM_PROTO_FLAG_WRAPPER)) // cheating: non-wrapper wrapper
{
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, gift, NULL);
return;
}
Item* item = _player->GetItemByPos(item_bag, item_slot);
if (!item)
{
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, item, NULL);
return;
}
if (item == gift) // not possable with pacjket from real client
{
_player->SendEquipError(EQUIP_ERR_WRAPPED_CANT_BE_WRAPPED, item, NULL);
return;
}
if (item->IsEquipped())
{
_player->SendEquipError(EQUIP_ERR_EQUIPPED_CANT_BE_WRAPPED, item, NULL);
return;
}
if (item->GetUInt64Value(ITEM_FIELD_GIFTCREATOR)) // HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED);
{
_player->SendEquipError(EQUIP_ERR_WRAPPED_CANT_BE_WRAPPED, item, NULL);
return;
}
if (item->IsBag())
{
_player->SendEquipError(EQUIP_ERR_BAGS_CANT_BE_WRAPPED, item, NULL);
return;
}
if (item->IsSoulBound())
{
_player->SendEquipError(EQUIP_ERR_BOUND_CANT_BE_WRAPPED, item, NULL);
return;
}
if (item->GetMaxStackCount() != 1)
{
_player->SendEquipError(EQUIP_ERR_STACKABLE_CANT_BE_WRAPPED, item, NULL);
return;
}
// maybe not correct check (it is better than nothing)
if (item->GetTemplate()->MaxCount>0)
{
_player->SendEquipError(EQUIP_ERR_UNIQUE_CANT_BE_WRAPPED, item, NULL);
return;
}
SQLTransaction trans = CharacterDatabase.BeginTransaction();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_GIFT);
stmt->setUInt32(0, GUID_LOPART(item->GetOwnerGUID()));
stmt->setUInt32(1, item->GetGUIDLow());
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->SetUInt64Value(ITEM_FIELD_GIFTCREATOR, _player->GetGUID());
item->SetUInt32Value(ITEM_FIELD_FLAGS, ITEM_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`
//.........这里部分代码省略.........
示例10: HandleMailReturnToSender
void WorldSession::HandleMailReturnToSender(WorldPacket & recvData)
{
uint64 mailbox;
uint32 mailId;
recvData >> mailbox;
recvData >> mailId;
recvData.read_skip<uint64>(); // original sender GUID for return to, not used
if (!CanOpenMailBox(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);
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);
// xinef: update global data
sWorld->UpdateGlobalPlayerMails(player->GetGUIDLow(), -1);
}
示例11: 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);
}
示例12: HandleWrapItem
void WorldSession::HandleWrapItem(WorldPackets::Item::WrapItem& packet)
{
if (packet.Inv.Items.size() != 2)
{
TC_LOG_ERROR("network", "HandleWrapItem - Invalid itemCount (" SZFMTD ")", packet.Inv.Items.size());
return;
}
/// @todo: 6.x find better way for read
// Gift
uint8 giftContainerSlot = packet.Inv.Items[0].ContainerSlot;
uint8 giftSlot = packet.Inv.Items[0].Slot;
// Item
uint8 itemContainerSlot = packet.Inv.Items[1].ContainerSlot;
uint8 itemSlot = packet.Inv.Items[1].Slot;
TC_LOG_DEBUG("network", "HandleWrapItem - Receive giftContainerSlot = %u, giftSlot = %u, itemContainerSlot = %u, itemSlot = %u", giftContainerSlot, giftSlot, itemContainerSlot, itemSlot);
Item* gift = _player->GetItemByPos(giftContainerSlot, giftSlot);
if (!gift)
{
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, gift, NULL);
return;
}
if (!(gift->GetTemplate()->GetFlags() & ITEM_FLAG_WRAPPER)) // cheating: non-wrapper wrapper
{
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, gift, NULL);
return;
}
Item* item = _player->GetItemByPos(itemContainerSlot, itemSlot);
if (!item)
{
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, item, NULL);
return;
}
if (item == gift) // not possable with pacjket from real client
{
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_WRAPPED, item, NULL);
return;
}
if (item->IsEquipped())
{
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_EQUIPPED, item, NULL);
return;
}
if (!item->GetGuidValue(ITEM_FIELD_GIFTCREATOR).IsEmpty()) // HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED);
{
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_WRAPPED, item, NULL);
return;
}
if (item->IsBag())
{
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_BAGS, item, NULL);
return;
}
if (item->IsSoulBound())
{
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_BOUND, item, NULL);
return;
}
if (item->GetMaxStackCount() != 1)
{
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_STACKABLE, item, NULL);
return;
}
// maybe not correct check (it is better than nothing)
if (item->GetTemplate()->GetMaxCount() > 0)
{
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_UNIQUE, item, NULL);
return;
}
SQLTransaction trans = CharacterDatabase.BeginTransaction();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_GIFT);
stmt->setUInt64(0, item->GetOwnerGUID().GetCounter());
stmt->setUInt64(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;
//.........这里部分代码省略.........
示例13: SendAuctionWonMail
//does not clear ram
void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, SQLTransaction& trans)
{
Item* pItem = GetAItem(auction->item_guidlow);
if (!pItem)
return;
uint32 bidder_accId = 0;
uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
Player* bidder = ObjectAccessor::FindPlayer(bidder_guid);
// data for gm.log
if (sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
{
uint32 bidder_security = 0;
std::string bidder_name;
if (bidder)
{
bidder_accId = bidder->GetSession()->GetAccountId();
bidder_security = bidder->GetSession()->GetSecurity();
bidder_name = bidder->GetName();
}
else
{
bidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(bidder_guid);
bidder_security = AccountMgr::GetSecurity(bidder_accId, realmID);
if (!AccountMgr::IsPlayerAccount(bidder_security)) // not do redundant DB requests
{
if (!sObjectMgr->GetPlayerNameByGUID(bidder_guid, bidder_name))
bidder_name = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);
}
}
if (!AccountMgr::IsPlayerAccount(bidder_security))
{
std::string owner_name;
if (!sObjectMgr->GetPlayerNameByGUID(auction->owner, owner_name))
owner_name = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);
uint32 owner_accid = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner);
sLog->outCommand(bidder_accId, "GM %s (Account: %u) won item in auction: %s (Entry: %u Count: %u) and pay money: %u. Original owner %s (Account: %u)",
bidder_name.c_str(), bidder_accId, pItem->GetTemplate()->Name1.c_str(), pItem->GetEntry(), pItem->GetCount(), auction->bid, owner_name.c_str(), owner_accid);
}
}
// receiver exist
if (bidder || bidder_accId)
{
std::ostringstream msgAuctionWonSubject;
msgAuctionWonSubject << auction->item_template << ":0:" << AUCTION_WON;
std::ostringstream msgAuctionWonBody;
msgAuctionWonBody.width(16);
msgAuctionWonBody << std::right << std::hex << auction->owner;
msgAuctionWonBody << std::dec << ':' << auction->bid << ':' << auction->buyout;
sLog->outDebug(LOG_FILTER_AUCTIONHOUSE, "AuctionWon body string : %s", msgAuctionWonBody.str().c_str());
// 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, bidder_guid, 0, 0, auction->item_template);
}
MailDraft(msgAuctionWonSubject.str(), msgAuctionWonBody.str())
.AddItem(pItem)
.SendMailTo(trans, MailReceiver(bidder, auction->bidder), auction, MAIL_CHECK_MASK_COPIED);
}
}
示例14: _ResetOrWarnAll
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();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INSTANCE_BY_MAP_DIFF);
stmt->setUInt16(0, uint16(mapid));
stmt->setUInt8(1, uint8(difficulty));
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_INSTANCE_BY_MAP_DIFF);
stmt->setUInt16(0, uint16(mapid));
stmt->setUInt8(1, uint8(difficulty));
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_INSTANCE_BY_MAP_DIFF);
stmt->setUInt16(0, uint16(mapid));
stmt->setUInt8(1, uint8(difficulty));
trans->Append(stmt);
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;
uint32 next_reset = uint32(((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
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GLOBAL_INSTANCE_RESETTIME);
stmt->setUInt32(0, next_reset);
stmt->setUInt16(1, uint16(mapid));
stmt->setUInt8(2, uint8(difficulty));
CharacterDatabase.Execute(stmt);
}
// 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
}
示例15: SaveToDB
void BattlePetMgr::SaveToDB(SQLTransaction& trans)
{
PreparedStatement* stmt = nullptr;
for (auto itr = _pets.begin(); itr != _pets.end();)
{
switch (itr->second.SaveInfo)
{
case BATTLE_PET_NEW:
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_BATTLE_PETS);
stmt->setUInt64(0, itr->first);
stmt->setUInt32(1, _owner->GetBattlenetAccountId());
stmt->setUInt32(2, itr->second.PacketInfo.Species);
stmt->setUInt16(3, itr->second.PacketInfo.Breed);
stmt->setUInt16(4, itr->second.PacketInfo.Level);
stmt->setUInt16(5, itr->second.PacketInfo.Exp);
stmt->setUInt32(6, itr->second.PacketInfo.Health);
stmt->setUInt8(7, itr->second.PacketInfo.Quality);
stmt->setUInt16(8, itr->second.PacketInfo.Flags);
stmt->setString(9, itr->second.PacketInfo.Name);
trans->Append(stmt);
itr->second.SaveInfo = BATTLE_PET_UNCHANGED;
++itr;
break;
case BATTLE_PET_CHANGED:
stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_BATTLE_PETS);
stmt->setUInt16(0, itr->second.PacketInfo.Level);
stmt->setUInt16(1, itr->second.PacketInfo.Exp);
stmt->setUInt32(2, itr->second.PacketInfo.Health);
stmt->setUInt8(3, itr->second.PacketInfo.Quality);
stmt->setUInt16(4, itr->second.PacketInfo.Flags);
stmt->setString(5, itr->second.PacketInfo.Name);
stmt->setUInt32(6, _owner->GetBattlenetAccountId());
stmt->setUInt64(7, itr->first);
trans->Append(stmt);
itr->second.SaveInfo = BATTLE_PET_UNCHANGED;
++itr;
break;
case BATTLE_PET_REMOVED:
stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_BATTLE_PETS);
stmt->setUInt32(0, _owner->GetBattlenetAccountId());
stmt->setUInt64(1, itr->first);
trans->Append(stmt);
itr = _pets.erase(itr);
break;
default:
++itr;
break;
}
}
stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_BATTLE_PET_SLOTS);
stmt->setUInt32(0, _owner->GetBattlenetAccountId());
trans->Append(stmt);
for (WorldPackets::BattlePet::BattlePetSlot const& slot : _slots)
{
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_BATTLE_PET_SLOTS);
stmt->setUInt8(0, slot.Index);
stmt->setUInt32(1, _owner->GetBattlenetAccountId());
stmt->setUInt64(2, slot.Pet.Guid.GetCounter());
stmt->setBool(3, slot.Locked);
trans->Append(stmt);
}
}