void QuestMgr::OnQuestFinished(Player* plr, Quest* qst, Object *qst_giver, uint32 reward_slot) { QuestLogEntry *qle = plr->GetQuestLogForEntry(qst->id); if(!qle) return; BuildQuestComplete(plr, qst); CALL_QUESTSCRIPT_EVENT(qle, OnQuestComplete)(plr); ScriptSystem->OnQuestEvent(qst, ((Creature*)qst_giver), plr, QUEST_EVENT_ON_COMPLETE); qle->Finish(); if(IsQuestRepeatable(qst)) return; if(qst_giver->GetTypeId() == TYPEID_UNIT) { if(!((Creature*)qst_giver)->HasQuest(qst->id, 2)) { sCheatLog.writefromsession(plr->GetSession(), "tried to finish quest from invalid npc."); plr->GetSession()->Disconnect(); return; } } plr->ModUInt32Value(PLAYER_FIELD_COINAGE, qst->reward_money); // Reputation reward for(int z = 0; z < 2; z++) { uint32 fact = 19; // default to 19 if no factiondbc uint32 amt = uint32(float(GenerateQuestXP(plr, qst)) * 0.1f * sWorld.getRate(RATE_QUESTREPUTATION)); // guess if(!qst->reward_repfaction[z]) { if(z == 1) break; // Let's do this properly. Determine the faction of the creature, and give reputation to his faction. if(qst_giver->GetTypeId() == TYPEID_UNIT) if(((Creature*)qst_giver)->m_factionDBC != NULL) fact = ((Creature*)qst_giver)->m_factionDBC->ID; if(qst_giver->GetTypeId() == TYPEID_GAMEOBJECT) fact = qst_giver->GetUInt32Value(GAMEOBJECT_FACTION); } else { fact = qst->reward_repfaction[z]; if(qst->reward_repvalue[z]) amt = qst->reward_repvalue[z]; } if(qst->reward_replimit) if(plr->GetStanding(fact) >= (int32)qst->reward_replimit) continue; plr->ModStanding(fact, amt); } // Static Item reward for(uint32 i = 0; i < 4; ++i) { if(qst->reward_item[i]) { ItemPrototype *proto = ItemPrototypeStorage.LookupEntry(qst->reward_item[i]); if(!proto) { sLog.outError("Invalid item prototype in quest reward! ID %d, quest %d", qst->reward_item[i], qst->id); } else { Item *itm = objmgr.CreateItem(qst->reward_item[i], plr); itm->SetUInt32Value(ITEM_FIELD_STACK_COUNT, uint32(qst->reward_itemcount[i])); plr->GetItemInterface()->AddItemToFreeSlot(itm); //possible memleak and no safe check. } } } // Choice Rewards if(qst->reward_choiceitem[reward_slot]) { ItemPrototype *proto = ItemPrototypeStorage.LookupEntry(qst->reward_choiceitem[reward_slot]); if(!proto) { sLog.outError("Invalid item prototype in quest reward! ID %d, quest %d", qst->reward_choiceitem[reward_slot], qst->id); } else { Item *itm = objmgr.CreateItem(qst->reward_choiceitem[reward_slot], plr); itm->SetUInt32Value(ITEM_FIELD_STACK_COUNT, qst->reward_choiceitemcount[reward_slot]); plr->GetItemInterface()->AddItemToFreeSlot(itm); //possible mem leak and no item check } } // Remove items for(uint32 i = 0; i < 4; ++i) { if(qst->required_item[i]) plr->GetItemInterface()->RemoveItemAmt(qst->required_item[i],qst->required_itemcount[i]); } // Remove srcitem if(qst->srcitem && qst->srcitem != qst->receive_items[0]) plr->GetItemInterface()->RemoveItemAmt(qst->srcitem, qst->srcitemcount ? qst->srcitemcount : 1); // cast learning spell if(qst->reward_spell) { if(!plr->HasSpell(qst->reward_spell)) { // "Teaching" effect WorldPacket data(SMSG_SPELL_START, 200); data << qst_giver->GetNewGUID() << qst_giver->GetNewGUID(); data << uint32(7763); data << uint16(0); data << uint32(0); data << uint16(2); data << plr->GetGUID(); plr->GetSession()->SendPacket( &data ); data.Initialize( SMSG_SPELL_GO ); data << qst_giver->GetNewGUID() << qst_giver->GetNewGUID(); data << uint32(7763); // spellID data << uint8(0) << uint8(1); // flags data << uint8(1); // amount of targets data << plr->GetGUID(); // target data << uint8(0); data << uint16(2); data << plr->GetGUID(); plr->GetSession()->SendPacket( &data ); // Teach the spell plr->addSpell(qst->reward_spell); } } // cast Effect Spell if(qst->effect_on_player) { SpellEntry * inf =sSpellStore.LookupEntry(qst->effect_on_player); if(inf) { Spell * spe = new Spell(qst_giver,inf,true,NULL); SpellCastTargets tgt; tgt.m_unitTarget = plr->GetGUID(); spe->prepare(&tgt); } } //Add to finished quests plr->AddToFinishedQuests(qst->id); }
void WorldSession::HandleAutostoreLootItemOpcode( WorldPacket & recv_data ) { if(!_player->IsInWorld()) return; // uint8 slot = 0; uint32 itemid = 0; uint32 amt = 1; uint8 lootSlot = 0; uint8 error = 0; SlotResult slotresult; Item *add; Loot *pLoot = NULL; if(_player->isCasting()) _player->InterruptSpell(); GameObject * pGO = NULL; Creature * pCreature = NULL; if(UINT32_LOPART(GUID_HIPART(GetPlayer()->GetLootGUID())) == HIGHGUID_UNIT) { pCreature = _player->GetMapMgr()->GetCreature((uint32)GetPlayer()->GetLootGUID()); if (!pCreature)return; pLoot=&pCreature->loot; } else if(UINT32_LOPART(GUID_HIPART(_player->GetLootGUID())) == HIGHGUID_GAMEOBJECT) { pGO = _player->GetMapMgr()->GetGameObject((uint32)GetPlayer()->GetLootGUID()); if(!pGO)return; pLoot=&pGO->loot; }else if( (UINT32_LOPART(GUID_HIPART(_player->GetLootGUID())) == HIGHGUID_ITEM) ) { Item *pItem = _player->GetItemInterface()->GetItemByGUID(_player->GetLootGUID()); if(!pItem) return; pLoot = pItem->loot; } if(!pLoot) return; recv_data >> lootSlot; if (lootSlot >= pLoot->items.size()) { sLog.outDebug("AutoLootItem: Player %s might be using a hack! (slot %d, size %d)", GetPlayer()->GetName(), lootSlot, pLoot->items.size()); return; } amt = pLoot->items.at(lootSlot).iItemsCount; if (!amt)//Test for party loot { GetPlayer()->GetItemInterface()->BuildInventoryChangeError(NULL, NULL,INV_ERR_ALREADY_LOOTED); return; } itemid = pLoot->items.at(lootSlot).item.itemid; ItemPrototype* it = ItemPrototypeStorage.LookupEntry(itemid); if((error = _player->GetItemInterface()->CanReceiveItem(it, 1))) { _player->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, error); return; } if(pGO) CALL_GO_SCRIPT_EVENT(pGO, OnLootTaken)(_player, it); else if(pCreature) CALL_SCRIPT_EVENT(pCreature, OnLootTaken)(_player, it); add = GetPlayer()->GetItemInterface()->FindItemLessMax(itemid, amt, false); sHookInterface.OnLoot(_player, pCreature, 0, itemid); if (!add) { slotresult = GetPlayer()->GetItemInterface()->FindFreeInventorySlot(it); if(!slotresult.Result) { GetPlayer()->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL); return; } sLog.outDebug("AutoLootItem MISC"); Item *item = objmgr.CreateItem( itemid, GetPlayer()); item->SetUInt32Value(ITEM_FIELD_STACK_COUNT,amt); uint32 rndprop=pLoot->items.at(lootSlot).iRandomProperty; if(rndprop) item->SetUInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID,rndprop); item->ApplyRandomProperties(); GetPlayer()->GetItemInterface()->SafeAddItem(item,slotresult.ContainerSlot, slotresult.Slot); if (it->Class == 12) // Quest item sQuestMgr.OnPlayerItemPickup(GetPlayer(),item); } else { add->SetCount(add->GetUInt32Value(ITEM_FIELD_STACK_COUNT) + amt); add->m_isDirty = true; if (it->Class == 12) // Quest item sQuestMgr.OnPlayerItemPickup(GetPlayer(),add); } pLoot->items.at(lootSlot).iItemsCount=0; // this gets sent to all looters WorldPacket data(1); data.SetOpcode(SMSG_LOOT_REMOVED); data << lootSlot; Player * plr; for(LooterSet::iterator itr = pLoot->looters.begin(); itr != pLoot->looters.end(); ++itr) { if((plr = _player->GetMapMgr()->GetPlayer(*itr))) plr->GetSession()->SendPacket(&data); } WorldPacket idata; if(it->Class == ITEM_CLASS_QUEST) { uint32 pcount = _player->GetItemInterface()->GetItemCount(it->ItemId, true); BuildItemPushResult(&idata, _player->GetGUID(), ITEM_PUSH_TYPE_LOOT, amt, itemid, pLoot->items.at(lootSlot).iRandomProperty,0xFF,0,0xFFFFFFFF,pcount); } else BuildItemPushResult(&idata, _player->GetGUID(), ITEM_PUSH_TYPE_LOOT, amt, itemid, pLoot->items.at(lootSlot).iRandomProperty); if(_player->InGroup()) _player->GetGroup()->SendPacketToAll(&idata); else SendPacket(&idata); }
//used when player copies mail body to his inventory void WorldSession::HandleMailCreateTextItem(WorldPacket & recv_data) { uint64 mailbox; uint32 mailId; recv_data >> mailbox; recv_data >> mailId; if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX)) return; Player* player = _player; Mail* m = player->GetMail(mailId); if (!m || (m->body.empty() && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL)) { player->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR); return; } Item* bodyItem = new Item; // This is not bag and then can be used new Item. if (!bodyItem->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_ITEM), MAIL_BODY_ITEM_TEMPLATE, player)) { delete bodyItem; return; } // in mail template case we need create new item text if (m->mailTemplateId) { MailTemplateEntry const* mailTemplateEntry = sMailTemplateStore.LookupEntry(m->mailTemplateId); if (!mailTemplateEntry) { player->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR); return; } bodyItem->SetText(mailTemplateEntry->content[GetSessionDbcLocale()]); } else bodyItem->SetText(m->body); bodyItem->SetUInt32Value(ITEM_FIELD_CREATOR, m->sender); bodyItem->SetFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_MAIL_TEXT_MASK); sLog->outDetail("HandleMailCreateTextItem mailid=%u", mailId); ItemPosCountVec dest; uint8 msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, bodyItem, false); if (msg == EQUIP_ERR_OK) { m->checked = m->checked | MAIL_CHECK_MASK_COPIED; m->state = MAIL_STATE_CHANGED; player->m_mailsUpdated = true; player->StoreItem(dest, bodyItem, true); player->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_OK); } else { player->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_EQUIP_ERROR, msg); delete bodyItem; } }
void LootRoll::Finalize() { sEventMgr.RemoveEvents(this); // this we will have to finalize with groups types.. for now // we'll just assume need before greed. person with highest roll // in need gets the item. uint32 highest = 0; int8 hightype = -1; uint64 player = 0; WorldPacket data(34); /* Player * gplr = NULL; for(std::map<uint64, uint32>::iterator itr = NeedRolls.begin(); itr != NeedRolls.end(); ++itr) { gplr = _mgr->GetPlayer((uint32)itr->first); if(gplr) break; } if(!gplr) { for(std::map<uint64, uint32>::iterator itr = GreedRolls.begin(); itr != GreedRolls.end(); ++itr) { gplr = _mgr->GetPlayer((uint32)itr->first); if(gplr) break; } } */ for(std::map<uint32, uint32>::iterator itr = m_NeedRolls.begin(); itr != m_NeedRolls.end(); ++itr) { if(itr->second > highest) { highest = itr->second; player = itr->first; hightype = NEED; } /* data.Initialize(SMSG_LOOT_ROLL); data << _guid << _slotid << itr->first; data << _itemid << _itemunk1 << _itemunk2; data << uint8(itr->second) << uint8(NEED); if(gplr && gplr->GetGroup()) gplr->GetGroup()->SendPacketToAll(&data); */ } if(!highest) { for(std::map<uint32, uint32>::iterator itr = m_GreedRolls.begin(); itr != m_GreedRolls.end(); ++itr) { if(itr->second > highest) { highest = itr->second; player = itr->first; hightype = GREED; } /* data.Initialize(SMSG_LOOT_ROLL); data << _guid << _slotid << itr->first; data << _itemid << _itemunk1 << _itemunk2; data << uint8(itr->second) << uint8(GREED); if(gplr && gplr->GetGroup()) gplr->GetGroup()->SendPacketToAll(&data); */ } } Loot * pLoot = 0; uint32 guidtype = GET_TYPE_FROM_GUID(_guid); if( guidtype == HIGHGUID_TYPE_UNIT ) { Creature * pc = _mgr->GetCreature(GET_LOWGUID_PART(_guid)); if(pc) pLoot = &pc->m_loot; } else if( guidtype == HIGHGUID_TYPE_GAMEOBJECT ) { GameObject * go = _mgr->GetGameObject(GET_LOWGUID_PART(_guid)); if(go) pLoot = &go->m_loot; } if(!pLoot) { delete this; return; } if(_slotid >= pLoot->items.size()) { delete this; return; } pLoot->items.at(_slotid).roll = NULL; uint32 itemid = pLoot->items.at(_slotid).item.itemproto->ItemId; uint32 amt = pLoot->items.at(_slotid).iItemsCount; if(!amt) { delete this; return; } Player * _player = (player) ? _mgr->GetPlayer((uint32)player) : 0; if(!player || !_player) { /* all passed */ data.Initialize(SMSG_LOOT_ALL_PASSED); data << _guid << _groupcount << _itemid << _itemunk1 << _itemunk2; set<uint32>::iterator pitr = m_passRolls.begin(); while(_player == NULL && pitr != m_passRolls.end()) _player = _mgr->GetPlayer( (*(pitr++)) ); if( _player != NULL ) { if(_player->InGroup()) _player->GetGroup()->SendPacketToAll(&data); else _player->GetSession()->SendPacket(&data); } /* item can now be looted by anyone :) */ pLoot->items.at(_slotid).passed = true; delete this; return; } pLoot->items.at(_slotid).roll = 0; data.Initialize(SMSG_LOOT_ROLL_WON); data << _guid << _slotid << _itemid << _itemunk1 << _itemunk2; data << _player->GetGUID() << uint8(highest) << uint8(hightype); if(_player->InGroup()) _player->GetGroup()->SendPacketToAll(&data); else _player->GetSession()->SendPacket(&data); ItemPrototype* it = ItemPrototypeStorage.LookupEntry(itemid); int8 error; if((error = _player->GetItemInterface()->CanReceiveItem(it, 1, NULL))) { _player->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, error); return; } Item * add = _player->GetItemInterface()->FindItemLessMax(itemid, amt, false); if (!add) { SlotResult slotresult = _player->GetItemInterface()->FindFreeInventorySlot(it); if(!slotresult.Result) { _player->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL); return; } DEBUG_LOG("AutoLootItem MISC"); Item *item = objmgr.CreateItem( itemid, _player); item->SetUInt32Value(ITEM_FIELD_STACK_COUNT,amt); if(pLoot->items.at(_slotid).iRandomProperty!=NULL) { item->SetRandomProperty(pLoot->items.at(_slotid).iRandomProperty->ID); item->ApplyRandomProperties(false); } else if(pLoot->items.at(_slotid).iRandomSuffix != NULL) { item->SetRandomSuffix(pLoot->items.at(_slotid).iRandomSuffix->id); item->ApplyRandomProperties(false); } if( _player->GetItemInterface()->SafeAddItem(item,slotresult.ContainerSlot, slotresult.Slot) ) { _player->GetSession()->SendItemPushResult(item,false,true,true,true,slotresult.ContainerSlot,slotresult.Slot,1); sQuestMgr.OnPlayerItemPickup(_player,item); } else delete item; } else { add->SetCount(add->GetUInt32Value(ITEM_FIELD_STACK_COUNT) + amt); add->m_isDirty = true; sQuestMgr.OnPlayerItemPickup(_player,add); _player->GetSession()->SendItemPushResult(add, false, true, true, false, _player->GetItemInterface()->GetBagSlotByGuid(add->GetGUID()), 0xFFFFFFFF, 1); } pLoot->items.at(_slotid).iItemsCount=0; // this gets sent to all looters data.Initialize(SMSG_LOOT_REMOVED); data << uint8(_slotid); Player * plr; for(LooterSet::iterator itr = pLoot->looters.begin(); itr != pLoot->looters.end(); ++itr) { if((plr = _player->GetMapMgr()->GetPlayer(*itr))) plr->GetSession()->SendPacket(&data); } /*WorldPacket idata(45); _player->GetSession()->BuildItemPushResult(&idata, _player->GetGUID(), ITEM_PUSH_TYPE_LOOT, amt, itemid, pLoot->items.at(_slotid).iRandomProperty ? pLoot->items.at(_slotid).iRandomProperty->ID : 0); if(_player->InGroup()) _player->GetGroup()->SendPacketToAll(&idata); else _player->GetSession()->SendPacket(&idata);*/ delete this; }
void WorldSession::HandleWrapItemOpcode(WorldPacket& recv_data) { DEBUG_LOG("Received opcode CMSG_WRAP_ITEM"); uint8 gift_bag, gift_slot, item_bag, item_slot; // recv_data.hexlike(); recv_data >> gift_bag >> gift_slot; // paper recv_data >> item_bag >> item_slot; // item DEBUG_LOG("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; } // cheating: non-wrapper wrapper (all empty wrappers is stackable) if (!(gift->GetProto()->Flags & ITEM_FLAG_WRAPPER) || gift->GetMaxStackCount() == 1) { _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 possible with packet 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->GetGuidValue(ITEM_FIELD_GIFTCREATOR)) // HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_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->GetProto()->MaxCount > 0) { _player->SendEquipError(EQUIP_ERR_UNIQUE_CANT_BE_WRAPPED, item, NULL); return; } CharacterDatabase.BeginTransaction(); CharacterDatabase.PExecute("INSERT INTO character_gifts VALUES ('%u', '%u', '%u', '%u')", item->GetOwnerGuid().GetCounter(), item->GetGUIDLow(), item->GetEntry(), item->GetUInt32Value(ITEM_FIELD_FLAGS)); 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->GetObjectGuid()); item->SetUInt32Value(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED); item->SetState(ITEM_CHANGED, _player); if (item->GetState() == ITEM_NEW) // save new item, to have alway for `character_gifts` record in `item_instance` { // after save it will be impossible to remove the item from the queue item->RemoveFromUpdateQueueOf(_player); item->SaveToDB(); // item gave inventory record unchanged and can be save standalone } CharacterDatabase.CommitTransaction(); uint32 count = 1; _player->DestroyItemCount(gift, count, true); }
void WorldSession::HandleSwapItemOpcode(WorldPacket& recv_data) { if(!_player->IsInWorld()) return; CHECK_PACKET_SIZE(recv_data, 4); WorldPacket data; WorldPacket packet; Item *SrcItem = NULL; Item *DstItem = NULL; //Item *SrcTemp = NULL; //Item *DstTemp = NULL; int8 DstInvSlot=0, DstSlot=0, SrcInvSlot=0, SrcSlot=0, error=0; // 20 5 255 26 if(!GetPlayer()) return; recv_data >> DstInvSlot >> DstSlot >> SrcInvSlot >> SrcSlot; sLog.outDetail("ITEM: swap, DstInvSlot %u DstSlot %u SrcInvSlot %u SrcSlot %u", (uint32)DstInvSlot, (uint32)DstSlot, (uint32)SrcInvSlot, (uint32)SrcSlot); if(DstInvSlot == SrcSlot && SrcInvSlot == -1) // player trying to add self container to self container slots { GetPlayer()->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_ITEMS_CANT_BE_SWAPPED); return; } SrcItem=_player->GetItemInterface()->GetInventoryItem(SrcInvSlot,SrcSlot); if(!SrcItem) return; DstItem=_player->GetItemInterface()->GetInventoryItem(DstInvSlot,DstSlot); if(DstItem) { //check if it will go to equipment slot if(SrcInvSlot==INVENTORY_SLOT_NOT_SET)//not bag { if(DstItem->IsContainer()) { if(((Container*)DstItem)->HasItems()) { if(SrcSlot < INVENTORY_SLOT_BAG_START || SrcSlot >= INVENTORY_SLOT_BAG_END || SrcSlot < BANK_SLOT_BAG_START || SrcSlot >= BANK_SLOT_BAG_END) { _player->GetItemInterface()->BuildInventoryChangeError(SrcItem, DstItem, INV_ERR_NONEMPTY_BAG_OVER_OTHER_BAG); return; } } } if(SrcSlot < INVENTORY_KEYRING_END) { if((error=GetPlayer()->GetItemInterface()->CanEquipItemInSlot(SrcInvSlot, SrcSlot, DstItem->GetProto()))) { _player->GetItemInterface()->BuildInventoryChangeError(SrcItem, DstItem, error); return; } } } else { if(DstItem->IsContainer()) { if(((Container*)DstItem)->HasItems()) { _player->GetItemInterface()->BuildInventoryChangeError(SrcItem, DstItem, INV_ERR_NONEMPTY_BAG_OVER_OTHER_BAG); return; } } if((error=GetPlayer()->GetItemInterface()->CanEquipItemInSlot(SrcInvSlot, SrcInvSlot, DstItem->GetProto()))) { _player->GetItemInterface()->BuildInventoryChangeError(SrcItem, DstItem, error); return; } } } if(SrcItem) { //check if it will go to equipment slot if(DstInvSlot==INVENTORY_SLOT_NOT_SET)//not bag { if(SrcItem->IsContainer()) { if(((Container*)SrcItem)->HasItems()) { if(DstSlot < INVENTORY_SLOT_BAG_START || DstSlot >= INVENTORY_SLOT_BAG_END || DstSlot < BANK_SLOT_BAG_START || DstSlot >= BANK_SLOT_BAG_END) { _player->GetItemInterface()->BuildInventoryChangeError(SrcItem, DstItem, INV_ERR_NONEMPTY_BAG_OVER_OTHER_BAG); return; } } } if(DstSlot < INVENTORY_KEYRING_END) { if((error=GetPlayer()->GetItemInterface()->CanEquipItemInSlot(DstInvSlot, DstSlot, SrcItem->GetProto()))) { _player->GetItemInterface()->BuildInventoryChangeError(SrcItem, DstItem, error); return; } } } else { if(SrcItem->IsContainer()) { if(((Container*)SrcItem)->HasItems()) { _player->GetItemInterface()->BuildInventoryChangeError(SrcItem, DstItem, INV_ERR_NONEMPTY_BAG_OVER_OTHER_BAG); return; } } if((error=GetPlayer()->GetItemInterface()->CanEquipItemInSlot(DstInvSlot, DstInvSlot, SrcItem->GetProto()))) { _player->GetItemInterface()->BuildInventoryChangeError(SrcItem, DstItem, error); return; } } } if(GetPlayer()->isInCombat()) { GetPlayer()->GetItemInterface()->BuildInventoryChangeError(SrcItem, NULL, INV_ERR_CANT_DO_IN_COMBAT); return; } if(SrcInvSlot==DstInvSlot)//in 1 bag { if(SrcInvSlot == INVENTORY_SLOT_NOT_SET)//in backpack { _player->GetItemInterface()->SwapItemSlots(SrcSlot,DstSlot); } else//in bag { ((Container*)_player->GetItemInterface()->GetInventoryItem(SrcInvSlot))->SwapItems(SrcSlot,DstSlot); } } else { // this is done in CanEquipItemInSlot ;) /*if (DstInvSlot != INVENTORY_SLOT_NOT_SET) { uint32 DstInvSubClass = _player->GetItemInterface()->GetInventoryItem(DstInvSlot)->GetProto()->SubClass; uint32 SrcItemClass = SrcItem->GetProto()->Class; uint32 SrcItemSubClass = SrcItem->GetProto()->SubClass; uint32 DstInvClass = _player->GetItemInterface()->GetInventoryItem(DstInvSlot)->GetProto()->Class; // if its not ammo/arrows it shouldnt go there if( DstInvSubClass != 0 && SrcItemSubClass != DstInvSubClass || ( SrcItemClass == 11 && DstInvClass == 11 ) ) { _player->GetItemInterface()->BuildInventoryChangeError(SrcItem, NULL, INV_ERR_ONLY_AMMO_CAN_GO_HERE); return; } }*/ //Check for stacking if(DstItem && SrcItem->GetEntry()==DstItem->GetEntry() && SrcItem->GetProto()->MaxCount>1) { uint32 total=SrcItem->GetUInt32Value(ITEM_FIELD_STACK_COUNT)+DstItem->GetUInt32Value(ITEM_FIELD_STACK_COUNT); if(total<=DstItem->GetProto()->MaxCount) { DstItem->ModUInt32Value(ITEM_FIELD_STACK_COUNT,SrcItem->GetUInt32Value(ITEM_FIELD_STACK_COUNT)); DstItem->m_isDirty = true; bool result = _player->GetItemInterface()->SafeFullRemoveItemFromSlot(SrcInvSlot,SrcSlot); if(!result) { GetPlayer()->GetItemInterface()->BuildInventoryChangeError(SrcItem, DstItem, INV_ERR_ITEM_CANT_STACK); } return; } else { if(DstItem->GetUInt32Value(ITEM_FIELD_STACK_COUNT) == DstItem->GetProto()->MaxCount) { } else { int32 delta=DstItem->GetProto()->MaxCount-DstItem->GetUInt32Value(ITEM_FIELD_STACK_COUNT); DstItem->SetUInt32Value(ITEM_FIELD_STACK_COUNT,DstItem->GetProto()->MaxCount); SrcItem->ModUInt32Value(ITEM_FIELD_STACK_COUNT,-delta); SrcItem->m_isDirty = true; DstItem->m_isDirty = true; return; } } } if(SrcItem) SrcItem = _player->GetItemInterface()->SafeRemoveAndRetreiveItemFromSlot(SrcInvSlot,SrcSlot, false); if(DstItem) DstItem = _player->GetItemInterface()->SafeRemoveAndRetreiveItemFromSlot(DstInvSlot,DstSlot, false); if(SrcItem) { bool result =_player->GetItemInterface()->SafeAddItem(SrcItem,DstInvSlot,DstSlot); if(!result) { printf("HandleSwapItem: Error while adding item to dstslot\n"); } } if(DstItem) { bool result = _player->GetItemInterface()->SafeAddItem(DstItem,SrcInvSlot,SrcSlot); if(!result) { printf("HandleSwapItem: Error while adding item to srcslot\n"); } } } }
bool ChatHandler::HandleQuestStartCommand(const char * args, WorldSession * m_session) { if(!*args) return false; Player *plr = getSelectedChar(m_session, true); if(!plr) { plr = m_session->GetPlayer(); SystemMessage(m_session, "Auto-targeting self."); } uint32 quest_id = atol(args); std::string recout = "|cff00ff00"; Quest * qst = QuestStorage.LookupEntry(quest_id); if(qst) { if (plr->HasFinishedQuest(quest_id)) recout += "Player has already completed that quest."; else { QuestLogEntry * IsPlrOnQuest = plr->GetQuestLogForEntry(quest_id); if (IsPlrOnQuest) recout += "Player is currently on that quest."; else { int32 open_slot = plr->GetOpenQuestSlot(); if (open_slot == -1) { sQuestMgr.SendQuestLogFull(plr); recout += "Player's quest log is full."; } else { QuestLogEntry *qle = new QuestLogEntry(); qle->Init(qst, plr, (uint32)open_slot); qle->UpdatePlayerFields(); // If the quest should give any items on begin, give them the items. for(uint32 i = 0; i < 4; ++i) { if(qst->receive_items[i]) { Item *item = objmgr.CreateItem( qst->receive_items[i], plr); if(!plr->GetItemInterface()->AddItemToFreeSlot(item)) delete item; } } if(qst->srcitem && qst->srcitem != qst->receive_items[0]) { Item * item = objmgr.CreateItem( qst->srcitem, plr); if(item) { item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, qst->srcitemcount ? qst->srcitemcount : 1); if(!plr->GetItemInterface()->AddItemToFreeSlot(item)) delete item; } } //if(qst->count_required_item || qst_giver->GetTypeId() == TYPEID_GAMEOBJECT) // gameobject quests deactivate // plr->UpdateNearbyGameObjects(); //ScriptSystem->OnQuestEvent(qst, static_cast< Creature* >( qst_giver ), _player, QUEST_EVENT_ON_ACCEPT); sHookInterface.OnQuestAccept( plr, qst ); recout += "Quest has been added to the player's quest log."; } } } } else { recout += "Quest Id ["; recout += args; recout += "] was not found and unable to add it to the player's quest log."; } recout += "\n\n"; SendMultilineMessage(m_session, recout.c_str()); return true; }
void WorldSession::HandleQuestgiverAcceptQuestOpcode( WorldPacket & recv_data ) { DEBUG_LOG( "WORLD"," Received CMSG_QUESTGIVER_ACCEPT_QUEST" ); CHECK_INWORLD_RETURN; //WorldPacket data; uint64 guid; uint32 quest_id; uint32 unk; recv_data >> guid; recv_data >> quest_id; recv_data >> unk; bool bValid = false; bool hasquest = true; bool bSkipLevelCheck = false; Quest *qst = NULL; Object* qst_giver = NULLOBJ; uint32 guidtype = GET_TYPE_FROM_GUID(guid); if(guidtype == HIGHGUID_TYPE_CREATURE) { Creature* quest_giver = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(quest_giver) qst_giver = TO_OBJECT(quest_giver); else return; bValid = quest_giver->isQuestGiver(); hasquest = quest_giver->HasQuest(quest_id, 1); if(bValid) qst = QuestStorage.LookupEntry(quest_id); } else if(guidtype==HIGHGUID_TYPE_GAMEOBJECT) { GameObject* quest_giver = _player->GetMapMgr()->GetGameObject(GET_LOWGUID_PART(guid)); if(quest_giver) qst_giver = TO_OBJECT(quest_giver); else return; //bValid = quest_giver->isQuestGiver(); //if(bValid) bValid = true; qst = QuestStorage.LookupEntry(quest_id); } else if(guidtype==HIGHGUID_TYPE_ITEM) { Item* quest_giver = GetPlayer()->GetItemInterface()->GetItemByGUID(guid); if(quest_giver) qst_giver = TO_OBJECT(quest_giver); else return; bValid = true; bSkipLevelCheck=true; qst = QuestStorage.LookupEntry(quest_id); if( qst && qst->id != quest_giver->GetProto()->QuestId ) return; } else if(guidtype==HIGHGUID_TYPE_PLAYER) { Player* quest_giver = _player->GetMapMgr()->GetPlayer((uint32)guid); if(quest_giver) qst_giver = TO_OBJECT(quest_giver); else return; bValid = true; qst = QuestStorage.LookupEntry(quest_id); } if (!qst_giver) { OUT_DEBUG("WORLD: Invalid questgiver GUID."); return; } if( !bValid || qst == NULL ) { OUT_DEBUG("WORLD: Creature is not a questgiver."); return; } if( _player->GetQuestLogForEntry( qst->id ) ) return; if( qst_giver->GetTypeId() == TYPEID_UNIT && TO_CREATURE( qst_giver )->m_escorter != NULL ) { SystemMessage("You cannot accept this quest at this time."); return; } // Check the player hasn't already taken this quest, or // it isn't available. uint32 status = sQuestMgr.CalcQuestStatus(_player,qst,3, bSkipLevelCheck); if((!sQuestMgr.IsQuestRepeatable(qst) && _player->HasFinishedQuest(qst->id)) || ( status != QMGR_QUEST_AVAILABLE && status != QMGR_QUEST_REPEATABLE && status != QMGR_QUEST_CHAT ) || !hasquest) { // We've got a hacker. Disconnect them. //sWorld.LogCheater(this, "tried to accept incompatible quest %u from %u.", qst->id, qst_giver->GetEntry()); //Disconnect(); return; } int32 log_slot = _player->GetOpenQuestSlot(); if (log_slot == -1) { sQuestMgr.SendQuestLogFull(GetPlayer()); return; } //FIXME /*if(Player Has Timed quest && qst->HasFlag(QUEST_FLAG_TIMED)) sQuestMgr.SendQuestInvalid(INVALID_REASON_HAVE_TIMED_QUEST);*/ if(qst->count_receiveitems || qst->srcitem) { uint32 slots_required = qst->count_receiveitems; if(_player->GetItemInterface()->CalculateFreeSlots(NULL) < slots_required) { _player->GetItemInterface()->BuildInventoryChangeError(NULLITEM, NULLITEM, INV_ERR_BAG_FULL); sQuestMgr.SendQuestFailed(FAILED_REASON_INV_FULL, qst, _player); return; } } /* if(qst_giver->GetTypeId() == TYPEID_UNIT && !ScriptSystem->OnQuestRequireEvent(qst, TO_CREATURE( qst_giver ), _player, QUEST_EVENT_CAN_ACCEPT)) return;*/ QuestLogEntry *qle = new QuestLogEntry(); qle->Init(qst, _player, log_slot); qle->UpdatePlayerFields(); // If the quest should give any items on begin, give them the items. for(uint32 i = 0; i < 4; i++) { if(qst->receive_items[i]) { Item* item = objmgr.CreateItem( qst->receive_items[i], GetPlayer()); if(item) { item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, qst->receive_itemcount[i]); if(!_player->GetItemInterface()->AddItemToFreeSlot(item)) { item->DeleteMe(); item = NULLITEM; } else SendItemPushResult(item, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1); } } } if(qst->srcitem && qst->srcitem != qst->receive_items[0]) { Item* item = objmgr.CreateItem( qst->srcitem, _player ); if(item) { item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, qst->srcitemcount ? qst->srcitemcount : 1); if(!_player->GetItemInterface()->AddItemToFreeSlot(item)) { item->DeleteMe(); item = NULLITEM; } } } if(qst->count_required_item || qst_giver->GetTypeId() == TYPEID_GAMEOBJECT) // gameobject quests deactivate _player->UpdateNearbyGameObjects(); CALL_QUESTSCRIPT_EVENT(qst->id, OnQuestStart)(_player, qle); sQuestMgr.OnQuestAccepted(_player,qst,qst_giver); if(qst->start_phase != 0 ) _player->SetPhaseMask(qst->start_phase, true); sHookInterface.OnQuestAccept(_player, qst, qst_giver); }
void SpellHitTarget(Unit* /*target*/, SpellInfo const* spell) { if (aftercastTargetGuid != 0) { //only players for now if (!IS_PLAYER_GUID(aftercastTargetGuid)) { aftercastTargetGuid = 0; return; } Player* pTarget = sObjectAccessor->FindPlayer(aftercastTargetGuid); aftercastTargetGuid = 0; if (!pTarget/* || me->GetDistance(pTarget) > 15*/) return; //handle effects for (uint8 i = 0; i != MAX_SPELL_EFFECTS; ++i) { switch (spell->Effects[i].Effect) { case SPELL_EFFECT_CREATE_ITEM: case SPELL_EFFECT_CREATE_ITEM_2: { uint32 newitemid = spell->Effects[i].ItemType; if (newitemid) { ItemPosCountVec dest; ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(newitemid); if (!pProto) return; uint32 count = pProto->GetMaxStackSize(); uint32 no_space = 0; InventoryResult msg = pTarget->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, newitemid, count, &no_space); if (msg != EQUIP_ERR_OK) { if (msg == EQUIP_ERR_INVENTORY_FULL || msg == EQUIP_ERR_CANT_CARRY_MORE_OF_THIS) count -= no_space; else { // if not created by another reason from full inventory or unique items amount limitation pTarget->SendEquipError(msg, NULL, NULL, newitemid); continue; } } if (count) { Item* pItem = pTarget->StoreNewItem(dest, newitemid, true, Item::GenerateItemRandomPropertyId(newitemid)); if (!pItem) { pTarget->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL); continue; } //unsafe possible pItem->SetUInt32Value(ITEM_FIELD_CREATOR, me->GetGUIDLow()); pTarget->SendNewItem(pItem, count, true, false, true); } } break; } default: break; } } } }
bool ChatHandler::HandleAddInvItemCommand(const char *args, WorldSession *m_session) { uint32 itemid, count=1; int32 randomprop=0; if(strlen(args) < 1) { return false; } if(sscanf(args, "%u %u %d", &itemid, &count, &randomprop) < 1) return false; Player *chr = getSelectedChar(m_session); if (chr == NULL) return true; ItemPrototype* it = ItemPrototypeStorage.LookupEntry(itemid); if(it) { sGMLog.writefromsession(m_session, "used add item command, item id %u [%s] to %s", it->ItemId, it->Name1, chr->GetName()); Item *item; item = objmgr.CreateItem( itemid, chr); item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, ((count > it->MaxCount) ? it->MaxCount : count)); if(it->Bonding==ITEM_BIND_ON_PICKUP) item->SoulBind(); uint32 pr = 0; uint32 sf = 0; if(randomprop!=0) { if(randomprop<0) { sf = abs(int(randomprop)); item->SetRandomSuffix(abs(int(randomprop))); } else { pr = randomprop; item->SetRandomProperty(randomprop); } item->ApplyRandomProperties(false); } if(!chr->GetItemInterface()->AddItemToFreeSlot(item)) { m_session->SendNotification("No free slots were found in your inventory!"); delete item; return true; } char messagetext[500]; string itemlink = it->ConstructItemLink(pr, sf, item->GetUInt32Value(ITEM_FIELD_STACK_COUNT)); snprintf(messagetext, 500, "Adding item %d %s to %s's inventory.",(unsigned int)it->ItemId,itemlink.c_str(), chr->GetName()); SystemMessage(m_session, messagetext); snprintf(messagetext, 500, "%s added item %d %s to your inventory.", m_session->GetPlayer()->GetName(), (unsigned int)itemid, itemlink.c_str()); SystemMessageToPlr(chr, messagetext); SlotResult *lr = chr->GetItemInterface()->LastSearchResult(); chr->GetSession()->SendItemPushResult(item,false,true,false,true,lr->ContainerSlot,lr->Slot,item->GetUInt32Value(ITEM_FIELD_STACK_COUNT)); return true; } else { RedSystemMessage(m_session, "Item %d is not a valid item!",itemid); return true; } }
void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket) { DETAIL_LOG("WORLD: CMSG_OPEN_ITEM packet, data length = " SIZEFMTD, recvPacket.size()); uint8 bagIndex, slot; recvPacket >> bagIndex >> slot; DETAIL_LOG("bagIndex: %u, slot: %u", bagIndex, slot); Player* pUser = _player; // ignore for remote control state if (!pUser->IsSelfMover()) return; Item* pItem = pUser->GetItemByPos(bagIndex, slot); if (!pItem) { pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, nullptr, nullptr); return; } ItemPrototype const* proto = pItem->GetProto(); if (!proto) { pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, pItem, nullptr); return; } // locked item uint32 lockId = proto->LockID; if (lockId && !pItem->HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_UNLOCKED)) { LockEntry const* lockInfo = sLockStore.LookupEntry(lockId); if (!lockInfo) { pUser->SendEquipError(EQUIP_ERR_ITEM_LOCKED, pItem, nullptr); sLog.outError("WORLD::OpenItem: item [guid = %u] has an unknown lockId: %u!", pItem->GetGUIDLow() , lockId); return; } // required picklocking if (lockInfo->Skill[1] || lockInfo->Skill[0]) { pUser->SendEquipError(EQUIP_ERR_ITEM_LOCKED, pItem, nullptr); return; } } if (pItem->HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED))// wrapped? { QueryResult* result = CharacterDatabase.PQuery("SELECT entry, flags FROM character_gifts WHERE item_guid = '%u'", pItem->GetGUIDLow()); if (result) { Field* fields = result->Fetch(); uint32 entry = fields[0].GetUInt32(); uint32 flags = fields[1].GetUInt32(); pItem->SetGuidValue(ITEM_FIELD_GIFTCREATOR, ObjectGuid()); pItem->SetEntry(entry); pItem->SetUInt32Value(ITEM_FIELD_FLAGS, flags); pItem->SetState(ITEM_CHANGED, pUser); delete result; } else { sLog.outError("Wrapped item %u don't have record in character_gifts table and will deleted", pItem->GetGUIDLow()); pUser->DestroyItem(pItem->GetBagSlot(), pItem->GetSlot(), true); return; } static SqlStatementID delGifts ; SqlStatement stmt = CharacterDatabase.CreateStatement(delGifts, "DELETE FROM character_gifts WHERE item_guid = ?"); stmt.PExecute(pItem->GetGUIDLow()); } else { Loot*& loot = pItem->loot; if (!loot) loot = new Loot(pUser, pItem, LOOT_PICKPOCKETING); loot->ShowContentTo(pUser); } }
bool EyeOfTheStorm::GivePoints(uint32 team, uint32 points) { //printf("EOTS: Give team %u %u points.\n", team, points); m_points[team] += points; if((m_points[team] - m_lastHonorGainPoints[team]) >= resourcesToGainBH) { uint32 honorToAdd = m_honorPerKill; m_mainLock.Acquire(); for(set<Player*>::iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr) { (*itr)->m_bgScore.BonusHonor += honorToAdd; HonorHandler::AddHonorPointsToPlayer((*itr), honorToAdd); } UpdatePvPData(); m_mainLock.Release(); m_lastHonorGainPoints[team] += resourcesToGainBH; } if( m_points[team] >= 2000 ) { m_points[team] = 2000; m_ended = true; m_winningteam = static_cast<uint8>( team ); m_nextPvPUpdateTime = 0; sEventMgr.RemoveEvents(this); sEventMgr.AddEvent(((CBattleground*)this), &CBattleground::Close, EVENT_BATTLEGROUND_CLOSE, 120000, 1,0); /* add the marks of honor to all players */ uint32 lostHonorToAdd = m_honorPerKill; uint32 winHonorToAdd = 2 * lostHonorToAdd; m_mainLock.Acquire(); for(uint32 i = 0; i < 2; ++i) { for(set<Player*>::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr) { (*itr)->Root(); if ( (*itr)== NULL ) continue; if(i == m_winningteam) { (*itr)->m_bgScore.BonusHonor += winHonorToAdd; HonorHandler::AddHonorPointsToPlayer((*itr), winHonorToAdd); Item *item = objmgr.CreateItem( 29024 , *itr ); if( item != NULL ) { item->SetUInt32Value( ITEM_FIELD_STACK_COUNT, 3 ); item->SoulBind(); if( !(*itr)->GetItemInterface()->AddItemToFreeSlot( item ) ) { (*itr)->GetSession()->SendNotification("No free slots were found in your inventory!"); item->DeleteMe(); } else { (*itr)->m_bgScore.BonusHonor += lostHonorToAdd; HonorHandler::AddHonorPointsToPlayer( (*itr), lostHonorToAdd ); SlotResult *lr = (*itr)->GetItemInterface()->LastSearchResult(); (*itr)->GetSession()->SendItemPushResult( item, false, true, false, true, lr->ContainerSlot, lr->Slot, 3 ); } } if(i && (*itr)->GetQuestLogForEntry(11341)) (*itr)->GetQuestLogForEntry(11341)->SendQuestComplete(); else if((*itr)->GetQuestLogForEntry(11337)) (*itr)->GetQuestLogForEntry(11337)->SendQuestComplete(); } else { Item *item = objmgr.CreateItem( 29024 , *itr ); if( item != NULL ) { item->SetUInt32Value( ITEM_FIELD_STACK_COUNT, 1 ); item->SoulBind(); if( !(*itr)->GetItemInterface()->AddItemToFreeSlot( item ) ) { (*itr)->GetSession()->SendNotification("No free slots were found in your inventory!"); item->DeleteMe(); } else { SlotResult *lr = (*itr)->GetItemInterface()->LastSearchResult(); (*itr)->GetSession()->SendItemPushResult( item, false, true, false, true, lr->ContainerSlot, lr->Slot, 1 ); } } } } } m_mainLock.Release(); SetWorldState( EOTS_WORLDSTATE_ALLIANCE_VICTORYPOINTS + team, m_points[team] ); UpdatePvPData(); return true; } SetWorldState( EOTS_WORLDSTATE_ALLIANCE_VICTORYPOINTS + team, m_points[team] ); return false; }
//used when player copies mail body to his inventory void WorldSession::HandleMailCreateTextItem(WorldPacket & recv_data ) { uint64 mailbox; uint32 mailId; recv_data >> mailbox; recv_data >> mailId; recv_data.read_skip<uint32>(); // mailTemplateId, non need, Mail store own 100% correct value anyway if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX)) return; Player *pl = _player; Mail* m = pl->GetMail(mailId); if (!m || (!m->itemTextId && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL)) { pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR); return; } uint32 itemTextId = m->itemTextId; // in mail template case we need create new text id if(!itemTextId) { MailTemplateEntry const* mailTemplateEntry = sMailTemplateStore.LookupEntry(m->mailTemplateId); if(!mailTemplateEntry) { pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR); return; } itemTextId = sObjectMgr.CreateItemText(mailTemplateEntry->content[GetSessionDbcLocale()]); } Item *bodyItem = new Item; // This is not bag and then can be used new Item. if(!bodyItem->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_ITEM), MAIL_BODY_ITEM_TEMPLATE, pl)) { delete bodyItem; return; } bodyItem->SetUInt32Value( ITEM_FIELD_ITEM_TEXT_ID, itemTextId ); bodyItem->SetUInt32Value( ITEM_FIELD_CREATOR, m->sender); sLog.outDetail("HandleMailCreateTextItem mailid=%u",mailId); ItemPosCountVec dest; uint8 msg = _player->CanStoreItem( NULL_BAG, NULL_SLOT, dest, bodyItem, false ); if( msg == EQUIP_ERR_OK ) { m->itemTextId = 0; m->state = MAIL_STATE_CHANGED; pl->m_mailsUpdated = true; pl->StoreItem(dest, bodyItem, true); //bodyItem->SetState(ITEM_NEW, pl); is set automatically pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_OK); } else { pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_EQUIP_ERROR, msg); delete bodyItem; } }
bool EyeOfTheStorm::GivePoints(uint32 team, uint32 points) { uint32 honor; //printf("EOTS: Give team %u %u points.\n", team, points); m_points[team] += points; if( m_points[team] >= 2000 ) { m_points[team] = 2000; m_ended = true; m_winningteam = team; m_nextPvPUpdateTime = 0; sEventMgr.RemoveEvents(this); sEventMgr.AddEvent(((CBattleground*)this), &CBattleground::Close, EVENT_BATTLEGROUND_CLOSE, 120000, 1,0); /* add the marks of honor to all players */ m_mainLock.Acquire(); for(uint32 i = 0; i < 2; ++i) { for(set<Player*>::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr) { (*itr)->Root(); if ( (*itr)==NULL )// never happen? continue; /* Winning team will gain 2000 / 12 = 166.6 extra honor points */ /* On weekend 2000 / 8 = 250 (guessing) */ /* Losing team will also gain the honor from already earned points */ honor = m_points[i] / extraHonorDiv; (*itr)->m_bgScore.BonusHonor += honor; HonorHandler::AddHonorPointsToPlayer((*itr), honor); if(i == m_winningteam) { Item *item; item = objmgr.CreateItem( 29024 , *itr); item->SetUInt32Value(ITEM_FIELD_STACK_COUNT,3); item->SoulBind(); if(!(*itr)->GetItemInterface()->AddItemToFreeSlot(item)) { (*itr)->GetSession()->SendNotification("No free slots were found in your inventory!"); item->DeleteMe(); } else { SlotResult *lr = (*itr)->GetItemInterface()->LastSearchResult(); (*itr)->GetSession()->SendItemPushResult(item,false,true,false,true,lr->ContainerSlot,lr->Slot,3); } } else { Item *item; item = objmgr.CreateItem( 29024 , *itr); item->SetUInt32Value(ITEM_FIELD_STACK_COUNT,1); item->SoulBind(); if(!(*itr)->GetItemInterface()->AddItemToFreeSlot(item)) { (*itr)->GetSession()->SendNotification("No free slots were found in your inventory!"); item->DeleteMe(); } else { SlotResult *lr = (*itr)->GetItemInterface()->LastSearchResult(); (*itr)->GetSession()->SendItemPushResult(item,false,true,false,true,lr->ContainerSlot,lr->Slot,1); } } } } m_mainLock.Release(); SetWorldState( EOTS_WORLDSTATE_ALLIANCE_VICTORYPOINTS + team, m_points[team] ); UpdatePvPData(); return true; } SetWorldState( EOTS_WORLDSTATE_ALLIANCE_VICTORYPOINTS + team, m_points[team] ); return false; }
// Charter part void WorldSession::HandleCharterBuy(WorldPacket & recv_data) { /* {CLIENT} Packet: (0x01BD) CMSG_PETITION_BUY PacketSize = 85 |------------------------------------------------|----------------| |00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F |0123456789ABCDEF| |------------------------------------------------|----------------| |50 91 00 00 6E 13 01 F0 00 00 00 00 00 00 00 00 |P...n...........| |00 00 00 00 53 74 6F 72 6D 62 72 69 6E 67 65 72 |....Stormbringer| |73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |s...............| |00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| |00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 |................| |00 00 00 00 00 |..... | ------------------------------------------------------------------- */ if(!_player->IsInWorld()) return; uint64 creature_guid; uint64 crap; uint32 crap2; string name; uint8 error; uint32 crap3,crap4,crap5,crap6,crap7,crap8,crap9,crap10,crap11,arena_index,crap12; uint16 crap13; uint8 crap14; uint32 crap15; recv_data >> creature_guid >> crap >> crap2 >> name; recv_data >> crap3 >> crap4 >> crap5 >> crap6 >> crap7 >> crap8 >> crap9 >> crap10 >> crap11 >> crap12 >> crap13 >> crap14 >> arena_index >> crap15; Creature * crt = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(creature_guid)); if(!crt) { Disconnect(); return; } if(crt->GetEntry()==19861 || crt->GetEntry()==18897 || crt->GetEntry()==19856 || crt->GetEntry()==sWorld.m_CustomCharterGiver ) /* i am lazy! */ { uint32 arena_type = arena_index - 1; if(arena_type > 2) return; if(_player->m_arenaTeams[arena_type] || _player->m_charters[arena_index]) { SendNotification(_player->GetSession()->LocalizedWorldSrv(71)); return; } ArenaTeam * t = objmgr.GetArenaTeamByName(name, arena_type); if(t != NULL) { sChatHandler.SystemMessage(this,_player->GetSession()->LocalizedWorldSrv(72)); return; } if(objmgr.GetCharterByName(name, (CharterTypes)arena_index)) { sChatHandler.SystemMessage(this,_player->GetSession()->LocalizedWorldSrv(72)); return; } if(_player->m_charters[arena_type]) { SendNotification(_player->GetSession()->LocalizedWorldSrv(73)); return; } static uint32 item_ids[] = {ARENA_TEAM_CHARTER_2v2, ARENA_TEAM_CHARTER_3v3, ARENA_TEAM_CHARTER_5v5}; static uint32 costs[] = {ARENA_TEAM_CHARTER_2v2_COST,ARENA_TEAM_CHARTER_3v3_COST,ARENA_TEAM_CHARTER_5v5_COST}; if(_player->GetUInt32Value(PLAYER_FIELD_COINAGE) < costs[arena_type]) return; // error message needed here ItemPrototype * ip = ItemPrototypeStorage.LookupEntry(item_ids[arena_type]); ASSERT(ip); SlotResult res = _player->GetItemInterface()->FindFreeInventorySlot(ip); if(res.Result == 0) { _player->GetItemInterface()->BuildInventoryChangeError(0, 0, INV_ERR_INVENTORY_FULL); return; } error = _player->GetItemInterface()->CanReceiveItem(ip,1); if(error) { _player->GetItemInterface()->BuildInventoryChangeError(NULL,NULL,error); } else { // Create the item and charter Item * i = objmgr.CreateItem(item_ids[arena_type], _player); Charter * c = objmgr.CreateCharter(_player->GetLowGUID(), (CharterTypes)arena_index); c->GuildName = name; c->ItemGuid = i->GetGUID(); i->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1); i->SetUInt32Value(ITEM_FIELD_FLAGS, 1); i->SetUInt32Value(ITEM_FIELD_ENCHANTMENT, c->GetID()); i->SetUInt32Value(ITEM_FIELD_PROPERTY_SEED, 57813883); if( !_player->GetItemInterface()->AddItemToFreeSlot(i) ) { c->Destroy(); i->DeleteMe(); return; } c->SaveToDB(); /*WorldPacket data(45); BuildItemPushResult(&data, _player->GetGUID(), ITEM_PUSH_TYPE_RECEIVE, 1, item_ids[arena_type], 0); SendPacket(&data);*/ SendItemPushResult(i, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1); _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)costs[arena_type]); _player->m_charters[arena_index] = c; _player->SaveToDB(false); } } else { Guild * g = objmgr.GetGuildByGuildName(name); Charter * c = objmgr.GetCharterByName(name, CHARTER_TYPE_GUILD); if(g != 0 || c != 0) { SendNotification(_player->GetSession()->LocalizedWorldSrv(74)); return; } if(_player->m_charters[CHARTER_TYPE_GUILD]) { SendNotification(_player->GetSession()->LocalizedWorldSrv(75)); return; } ItemPrototype * ip = ItemPrototypeStorage.LookupEntry(ITEM_ENTRY_GUILD_CHARTER); assert(ip); SlotResult res = _player->GetItemInterface()->FindFreeInventorySlot(ip); if(res.Result == 0) { _player->GetItemInterface()->BuildInventoryChangeError(0, 0, INV_ERR_INVENTORY_FULL); return; } error = _player->GetItemInterface()->CanReceiveItem(ItemPrototypeStorage.LookupEntry(ITEM_ENTRY_GUILD_CHARTER),1); if(error) { _player->GetItemInterface()->BuildInventoryChangeError(NULL,NULL,error); } else { // Meh... WorldPacket data(SMSG_PLAY_OBJECT_SOUND, 12); data << uint32(0x000019C2); data << creature_guid; SendPacket(&data); // Create the item and charter Item * i = objmgr.CreateItem(ITEM_ENTRY_GUILD_CHARTER, _player); c = objmgr.CreateCharter(_player->GetLowGUID(), CHARTER_TYPE_GUILD); c->GuildName = name; c->ItemGuid = i->GetGUID(); i->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1); i->SetUInt32Value(ITEM_FIELD_FLAGS, 1); i->SetUInt32Value(ITEM_FIELD_ENCHANTMENT, c->GetID()); i->SetUInt32Value(ITEM_FIELD_PROPERTY_SEED, 57813883); if( !_player->GetItemInterface()->AddItemToFreeSlot(i) ) { c->Destroy(); i->DeleteMe(); return; } c->SaveToDB(); /*data.clear(); data.resize(45); BuildItemPushResult(&data, _player->GetGUID(), ITEM_PUSH_TYPE_RECEIVE, 1, ITEM_ENTRY_GUILD_CHARTER, 0); SendPacket(&data);*/ SendItemPushResult(i, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1); _player->m_charters[CHARTER_TYPE_GUILD] = c; _player->SaveToDB(false); } } }
void WorldSession::HandleOpenItemOpcode(WorldPackets::Spells::OpenItem& packet) { Player* player = _player; // ignore for remote control state if (player->m_mover != player) return; TC_LOG_INFO("network", "bagIndex: %u, slot: %u", packet.Slot, packet.PackSlot); Item* item = player->GetItemByPos(packet.Slot, packet.PackSlot); if (!item) { player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL); return; } ItemTemplate const* proto = item->GetTemplate(); if (!proto) { player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, item, NULL); return; } // Verify that the bag is an actual bag or wrapped item that can be used "normally" if (!(proto->GetFlags() & ITEM_FLAG_OPENABLE) && !item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FIELD_FLAG_WRAPPED)) { player->SendEquipError(EQUIP_ERR_CLIENT_LOCKED_OUT, item, NULL); TC_LOG_ERROR("network", "Possible hacking attempt: Player %s [%s] tried to open item [%s, entry: %u] which is not openable!", player->GetName().c_str(), player->GetGUID().ToString().c_str(), item->GetGUID().ToString().c_str(), proto->GetId()); return; } // locked item uint32 lockId = proto->GetLockID(); if (lockId) { LockEntry const* lockInfo = sLockStore.LookupEntry(lockId); if (!lockInfo) { player->SendEquipError(EQUIP_ERR_ITEM_LOCKED, item, NULL); TC_LOG_ERROR("network", "WORLD::OpenItem: item [%s] has an unknown lockId: %u!", item->GetGUID().ToString().c_str(), lockId); return; } // was not unlocked yet if (item->IsLocked()) { player->SendEquipError(EQUIP_ERR_ITEM_LOCKED, item, NULL); return; } } if (item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FIELD_FLAG_WRAPPED))// wrapped? { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_GIFT_BY_ITEM); stmt->setUInt64(0, item->GetGUID().GetCounter()); PreparedQueryResult result = CharacterDatabase.Query(stmt); if (result) { Field* fields = result->Fetch(); uint32 entry = fields[0].GetUInt32(); uint32 flags = fields[1].GetUInt32(); item->SetGuidValue(ITEM_FIELD_GIFTCREATOR, ObjectGuid::Empty); item->SetEntry(entry); item->SetUInt32Value(ITEM_FIELD_FLAGS, flags); item->SetState(ITEM_CHANGED, player); } else { TC_LOG_ERROR("network", "Wrapped item %s don't have record in character_gifts table and will deleted", item->GetGUID().ToString().c_str()); player->DestroyItem(item->GetBagSlot(), item->GetSlot(), true); return; } stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GIFT); stmt->setUInt64(0, item->GetGUID().GetCounter()); CharacterDatabase.Execute(stmt); } else player->SendLoot(item->GetGUID(), LOOT_CORPSE); }
void WorldSession::HandlePetitionBuyOpcode(WorldPacket& recvData) { TC_LOG_DEBUG("network", "Received opcode CMSG_PETITION_BUY"); ObjectGuid guid; recvData.ReadGuidMask(guid, 5, 2, 3); uint8 nameLength = recvData.ReadBits(7); recvData.ReadGuidMask(guid, 4, 1, 7, 0, 6); std::string name = recvData.ReadString(nameLength); recvData.ReadGuidBytes(guid, 1, 7, 4, 6, 0, 5, 2, 3); TC_LOG_DEBUG("network", "Petitioner with GUID %u tried sell petition: name %s", GUID_LOPART(guid), name.c_str()); // prevent cheating Creature* creature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_PETITIONER); if (!creature) { TC_LOG_DEBUG("network", "WORLD: HandlePetitionBuyOpcode - Unit (GUID: %u) not found or you can't interact with him.", GUID_LOPART(guid)); return; } // remove fake death if (GetPlayer()->HasUnitState(UNIT_STATE_DIED)) GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); uint32 charterid = 0; uint32 cost = 0; uint32 type = 0; // 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 (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; //I think this has changed charter->SetUInt32Value(ITEM_FIELD_ENCHANTMENT, charter->GetGUIDLow()); // ITEM_FIELD_ENCHANTMENT is guild/arenateam id // ITEM_FIELD_ENCHANTMENT+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() << '\''; //Probably DB Charter Petitions has changed too TC_LOG_DEBUG("network", "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)); //Type no needed anymore trans->Append(stmt); CharacterDatabase.CommitTransaction(trans); }
void WorldSession::HandleGuildBankSwapItem(WorldPacket & recv_data) { uint64 guid; uint8 source_isfrombank; uint32 itementry, unk1; uint8 autostore; uint32 i; Guild * pGuild = _player->m_playerInfo->guild; GuildMember * pMember = _player->m_playerInfo->guildMember; if(pGuild== NULL || pMember== NULL) return; recv_data >> guid >> source_isfrombank; if(source_isfrombank) { GuildBankTab * pSourceTab; GuildBankTab * pDestTab; Item* pSourceItem; Item* pDestItem; uint8 dest_bank; uint8 dest_bankslot; uint8 source_bank; uint8 source_bankslot; int32 splitted_count; /* read packet */ recv_data >> dest_bank; recv_data >> dest_bankslot; recv_data >> unk1; recv_data >> source_bank; recv_data >> source_bankslot; recv_data >> itementry; recv_data >> autostore; recv_data >> splitted_count; /* sanity checks to avoid overflows */ if(source_bankslot >= MAX_GUILD_BANK_SLOTS || dest_bankslot >= MAX_GUILD_BANK_SLOTS || source_bank >= MAX_GUILD_BANK_TABS || dest_bank >= MAX_GUILD_BANK_TABS) { return; } /* make sure we have permissions */ if(!pMember->pRank->CanPerformBankCommand(GR_RIGHT_GUILD_BANK_DEPOSIT_ITEMS, dest_bank) || !pMember->pRank->CanPerformBankCommand(GR_RIGHT_GUILD_BANK_DEPOSIT_ITEMS, source_bank)) return; /* locate the tabs */ pSourceTab = pGuild->GetBankTab( source_bank ); pDestTab = pGuild->GetBankTab( dest_bank ); if(pSourceTab == NULL || pDestTab == NULL) return; if(pSourceTab == pDestTab && source_bankslot == dest_bankslot) return; pSourceItem = pSourceTab->pSlots[source_bankslot]; pDestItem = pDestTab->pSlots[dest_bankslot]; if(pSourceItem == NULL && pDestItem == NULL) return; if(splitted_count) { uint32 source_count = pSourceItem->GetUInt32Value( ITEM_FIELD_STACK_COUNT ); if(pDestItem == NULL) { if(source_count == (uint32)splitted_count) { // swap pSourceTab->pSlots[source_bankslot] = pDestItem; pDestTab->pSlots[dest_bankslot] = pSourceItem; } else { pSourceItem->ModUnsigned32Value( ITEM_FIELD_STACK_COUNT, -splitted_count ); pDestItem = objmgr.CreateItem(pSourceItem->GetEntry(), NULL); pDestItem->SetUInt32Value(ITEM_FIELD_STACK_COUNT, splitted_count); pDestItem->SetUInt32Value(ITEM_FIELD_CREATOR, pSourceItem->GetUInt32Value(ITEM_FIELD_CREATOR)); pDestTab->pSlots[dest_bankslot] = pDestItem; } } else { pDestItem->ModUnsigned32Value( ITEM_FIELD_STACK_COUNT, splitted_count ); if((uint32)splitted_count != source_count) pSourceItem->ModUnsigned32Value( ITEM_FIELD_STACK_COUNT, -splitted_count ); else { pSourceItem->DeleteMe(); pSourceItem = NULLITEM; pSourceTab->pSlots[source_bankslot] = NULLITEM; } } } else { // swap pSourceTab->pSlots[source_bankslot] = pDestItem; pDestTab->pSlots[dest_bankslot] = pSourceItem; } /* update the client */ if(pSourceTab == pDestTab) { /* send both slots in the packet */ pGuild->SendGuildBank(this, pSourceTab, source_bankslot, dest_bankslot); } else { /* send a packet for each different bag */ pGuild->SendGuildBank(this, pSourceTab, source_bankslot, -1); pGuild->SendGuildBank(this, pDestTab, dest_bankslot, -1); } /* update in sql */ if(pDestItem == NULL) { /* this means the source slot is no longer being used. */ CharacterDatabase.Execute("DELETE FROM guild_bankitems WHERE guildId = %u AND tabId = %u AND slotId = %u", pGuild->GetGuildId(), (uint32)pSourceTab->iTabId, (uint32)source_bankslot); } else { /* insert the new Item* */ CharacterDatabase.Execute("REPLACE INTO guild_bankitems VALUES(%u, %u, %u, %u)", pGuild->GetGuildId(), (uint32)pSourceTab->iTabId, (uint32)source_bankslot, pDestItem->GetLowGUID()); } if(pSourceItem == NULL) { /* this means the destination slot is no longer being used. */ CharacterDatabase.Execute("DELETE FROM guild_bankitems WHERE guildId = %u AND tabId = %u AND slotId = %u", pGuild->GetGuildId(), (uint32)pDestTab->iTabId, (uint32)dest_bankslot); } else { /* insert the new Item* */ CharacterDatabase.Execute("REPLACE INTO guild_bankitems VALUES(%u, %u, %u, %u)", pGuild->GetGuildId(), (uint32)pDestTab->iTabId, (uint32)dest_bankslot, pSourceItem->GetLowGUID()); } } else {
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_IS_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; 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` { // after save it will be impossible to remove the item from the queue RemoveItemFromUpdateQueueOf(item, _player); item->SaveToDB(trans); // item gave inventory record unchanged and can be save standalone } CharacterDatabase.CommitTransaction(trans); uint32 count = 1; _player->DestroyItemCount(gift, count, true); }
// Charter part void WorldSession::HandleCharterBuy(WorldPacket & recv_data) { uint8 error; uint64 creature_guid; uint64 crap; uint32 crap2; string name; uint64 crap3, crap4, crap5, crap6, crap7, crap8; uint32 crap9; uint8 crap10; uint32 arena_index; uint32 crap11; recv_data >> creature_guid; recv_data >> crap >> crap2; recv_data >> name; recv_data >> crap3 >> crap4 >> crap5 >> crap6 >> crap7 >> crap8; recv_data >> crap9; recv_data >> crap10; recv_data >> arena_index; recv_data >> crap11; Creature* crt = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(creature_guid)); if(!crt) { Disconnect(); return; } if( arena_index >= NUM_CHARTER_TYPES ) return; //All arena organizers should be allowed to create arena charter's if( !crt->ArenaOrganizersFlags() ) { uint32 arena_type = arena_index - 1; if(arena_type > 2) return; if(_player->m_playerInfo->arenaTeam[arena_type]) { SendNotification("You are already in an arena team."); return; } if(_player->m_playerInfo->charterId[arena_index] != 0) { SendNotification("You already have an arena charter of this type."); return; } if(!sWorld.VerifyName(name.c_str(), name.length())) { SendNotification("That name is invalid or contains invalid characters."); return; } ArenaTeam * t = objmgr.GetArenaTeamByName(name, arena_type); if(t != NULL) { sChatHandler.SystemMessage(this,"That name is already in use."); return; } if(objmgr.GetCharterByName(name, (CharterTypes)arena_index)) { sChatHandler.SystemMessage(this,"That name is already in use."); return; } static uint32 item_ids[] = {ARENA_TEAM_CHARTER_2v2, ARENA_TEAM_CHARTER_3v3, ARENA_TEAM_CHARTER_5v5}; static uint32 costs[] = {ARENA_TEAM_CHARTER_2v2_COST,ARENA_TEAM_CHARTER_3v3_COST,ARENA_TEAM_CHARTER_5v5_COST}; if(_player->GetUInt32Value(PLAYER_FIELD_COINAGE) < costs[arena_type]) { sChatHandler.SystemMessage(this,"You don't have enough money!"); return; // error message needed here } ItemPrototype * ip = ItemPrototypeStorage.LookupEntry(item_ids[arena_type]); ASSERT(ip); SlotResult res = _player->GetItemInterface()->FindFreeInventorySlot(ip); if(res.Result == 0) { _player->GetItemInterface()->BuildInventoryChangeError(NULLITEM, NULLITEM, INV_ERR_INVENTORY_FULL); return; } error = _player->GetItemInterface()->CanReceiveItem(ip,1, NULL); if(error) { _player->GetItemInterface()->BuildInventoryChangeError(NULLITEM, NULLITEM,error); } else { // Create the item and charter Item* i = objmgr.CreateItem(item_ids[arena_type], _player); Charter * c = objmgr.CreateCharter(_player->GetLowGUID(), (CharterTypes)arena_index); c->GuildName = name; c->ItemGuid = i->GetGUID(); i->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1); i->SetUInt32Value(ITEM_FIELD_FLAGS, 1); i->SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1, c->GetID()); i->SetUInt32Value(ITEM_FIELD_PROPERTY_SEED, 57813883); if( !_player->GetItemInterface()->AddItemToFreeSlot(i) ) { c->Destroy(); c = NULL; i->DeleteMe(); i = NULL; return; } c->SaveToDB(); SendItemPushResult(i, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1); _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)costs[arena_type]); _player->m_playerInfo->charterId[arena_index] = c->GetID(); _player->SaveToDB(false); } } else { if( _player->GetUInt32Value(PLAYER_FIELD_COINAGE) < 1000) { SendNotification("You don't have enough money."); return; } if(_player->m_playerInfo->charterId[CHARTER_TYPE_GUILD] != 0) { SendNotification("You already have a guild charter."); return; } if(!sWorld.VerifyName(name.c_str(), name.length())) { SendNotification("That name is invalid or contains invalid characters."); return; } Guild * g = objmgr.GetGuildByGuildName(name); Charter * c = objmgr.GetCharterByName(name, CHARTER_TYPE_GUILD); if(g != 0 || c != 0) { SendNotification("A guild with that name already exists."); return; } ItemPrototype * ip = ItemPrototypeStorage.LookupEntry(ITEM_ENTRY_GUILD_CHARTER); assert(ip); SlotResult res = _player->GetItemInterface()->FindFreeInventorySlot(ip); if(res.Result == 0) { _player->GetItemInterface()->BuildInventoryChangeError(NULLITEM, NULLITEM, INV_ERR_INVENTORY_FULL); return; } error = _player->GetItemInterface()->CanReceiveItem(ItemPrototypeStorage.LookupEntry(ITEM_ENTRY_GUILD_CHARTER),1, NULL); if(error) { _player->GetItemInterface()->BuildInventoryChangeError(NULLITEM, NULLITEM,error); } else { // Meh... WorldPacket data(SMSG_PLAY_OBJECT_SOUND, 12); data << uint32(0x000019C2); data << creature_guid; SendPacket(&data); // Create the item and charter Item * i = objmgr.CreateItem(ITEM_ENTRY_GUILD_CHARTER, _player); c = objmgr.CreateCharter(_player->GetLowGUID(), CHARTER_TYPE_GUILD); c->GuildName = name; c->ItemGuid = i->GetGUID(); i->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1); i->SetUInt32Value(ITEM_FIELD_FLAGS, 1); i->SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1, c->GetID()); i->SetUInt32Value(ITEM_FIELD_PROPERTY_SEED, 57813883); if( !_player->GetItemInterface()->AddItemToFreeSlot(i) ) { c->Destroy(); c = NULL; i->DeleteMe(); i = NULL; return; } c->SaveToDB(); SendItemPushResult(i, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1); _player->m_playerInfo->charterId[CHARTER_TYPE_GUILD] = c->GetID(); // 10 silver _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -1000); _player->SaveToDB(false); } } }
void WorldSession::HandlePetitionBuyOpcode(WorldPacket & recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "Received opcode CMSG_PETITION_BUY"); uint64 guidNPC; uint32 clientIndex; // 1 for guild and arenaslot+1 for arenas in client std::string name; recv_data >> guidNPC; // NPC GUID recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint64>(); // 0 recv_data >> name; // name recv_data.read_skip<std::string>(); // some string recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint16>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 for (int i = 0; i < 10; ++i) recv_data.read_skip<std::string>(); recv_data >> clientIndex; // index recv_data.read_skip<uint32>(); // 0 sLog->outDebug(LOG_FILTER_NETWORKIO, "Petitioner with GUID %u tried sell petition: name %s", GUID_LOPART(guidNPC), name.c_str()); // prevent cheating Creature* creature = GetPlayer()->GetNPCIfCanInteractWith(guidNPC, UNIT_NPC_FLAG_PETITIONER); if (!creature) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: HandlePetitionBuyOpcode - Unit (GUID: %u) not found or you can't interact with him.", GUID_LOPART(guidNPC)); return; } // remove fake death if (GetPlayer()->HasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); 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; } else { // TODO: find correct opcode if (_player->getLevel() < sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)) { SendNotification(LANG_ARENA_ONE_TOOLOW, sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)); return; } switch (clientIndex) // arenaSlot+1 as received from client (1 from 3 case) { case 1: charterid = ARENA_TEAM_CHARTER_2v2; cost = ARENA_TEAM_CHARTER_2v2_COST; type = ARENA_TEAM_CHARTER_2v2_TYPE; break; case 2: charterid = ARENA_TEAM_CHARTER_3v3; cost = ARENA_TEAM_CHARTER_3v3_COST; type = ARENA_TEAM_CHARTER_3v3_TYPE; break; case 3: charterid = ARENA_TEAM_CHARTER_5v5; cost = ARENA_TEAM_CHARTER_5v5_COST; type = ARENA_TEAM_CHARTER_5v5_TYPE; break; default: sLog->outDebug(LOG_FILTER_NETWORKIO, "unknown selection at buy arena petition: %u", clientIndex); return; } if (_player->GetArenaTeamId(clientIndex - 1)) // arenaSlot+1 as received from client { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ALREADY_IN_ARENA_TEAM); return; } } if (type == GUILD_CHARTER_TYPE) { if (sGuildMgr->GetGuildByName(name)) { Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_EXISTS_S, name); return; } if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name)) { Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_INVALID, name); return; } } else { if (sArenaTeamMgr->GetArenaTeamByName(name)) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S); return; } if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name)) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_INVALID); return; } } ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(charterid); if (!pProto) { _player->SendBuyError(BUY_ERR_CANT_FIND_ITEM, NULL, charterid, 0); return; } if (!_player->HasEnoughMoney(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 QueryResult result = CharacterDatabase.PQuery("SELECT petitionguid FROM petition WHERE ownerguid = '%u' AND type = '%u'", _player->GetGUIDLow(), type); 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()); trans->PAppend("INSERT INTO petition (ownerguid, petitionguid, name, type) VALUES ('%u', '%u', '%s', '%u')", _player->GetGUIDLow(), charter->GetGUIDLow(), name.c_str(), type); CharacterDatabase.CommitTransaction(trans); }
/** * Handles the packet sent by the client when he copies the body a mail to his inventory. * * When a player copies the body of a mail to his inventory this method is called. It will create * a new item with the text of the mail and store it in the players inventory (if possible). * */ void WorldSession::HandleMailCreateTextItem(WorldPacket& recv_data) { ObjectGuid mailboxGuid; uint32 mailId; recv_data >> mailboxGuid; recv_data >> mailId; recv_data.read_skip<uint32>(); // mailTemplateId, non need, Mail store own 100% correct value anyway if (!CheckMailBox(mailboxGuid)) return; Player* pl = _player; Mail* m = pl->GetMail(mailId); if (!m || (!m->itemTextId && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL)) { pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR); return; } uint32 itemTextId = m->itemTextId; // in mail template case we need create new item text if (!itemTextId) { MailTemplateEntry const* mailTemplateEntry = sMailTemplateStore.LookupEntry(m->mailTemplateId); if (!mailTemplateEntry) { pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR); return; } itemTextId = sObjectMgr.CreateItemText(mailTemplateEntry->content[GetSessionDbcLocale()]); } Item* bodyItem = new Item; // This is not bag and then can be used new Item. if (!bodyItem->Create(sObjectMgr.GenerateItemLowGuid(), MAIL_BODY_ITEM_TEMPLATE, pl)) { delete bodyItem; return; } bodyItem->SetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID, itemTextId); bodyItem->SetGuidValue(ITEM_FIELD_CREATOR, ObjectGuid(HIGHGUID_PLAYER, m->sender)); DETAIL_LOG("HandleMailCreateTextItem mailid=%u", mailId); ItemPosCountVec dest; InventoryResult msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, bodyItem, false); if (msg == EQUIP_ERR_OK) { m->checked = m->checked | MAIL_CHECK_MASK_COPIED; m->state = MAIL_STATE_CHANGED; pl->m_mailsUpdated = true; pl->StoreItem(dest, bodyItem, true); pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_OK); } else { pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_EQUIP_ERROR, msg); delete bodyItem; } }
void WorldSession::HandlePetitionBuyOpcode(WorldPacket & recv_data) { CHECK_PACKET_SIZE(recv_data, 8+8+4+1+5*8+2+1+4+4); sLog.outDebug("Received opcode CMSG_PETITION_BUY"); //recv_data.hexlike(); uint64 guidNPC; uint64 unk1, unk3, unk4, unk5, unk6, unk7; uint32 unk2; std::string name; uint16 unk8; uint8 unk9; uint32 unk10; // selected index uint32 unk11; recv_data >> guidNPC; // NPC GUID recv_data >> unk1; // 0 recv_data >> unk2; // 0 recv_data >> name; // name // recheck CHECK_PACKET_SIZE(recv_data, 8+8+4+(name.size()+1)+5*8+2+1+4+4); recv_data >> unk3; // 0 recv_data >> unk4; // 0 recv_data >> unk5; // 0 recv_data >> unk6; // 0 recv_data >> unk7; // 0 recv_data >> unk8; // 0 recv_data >> unk9; // 0 recv_data >> unk10; // index recv_data >> unk11; // 0 sLog.outDebug("Petitioner with GUID %u tried sell petition: name %s", GUID_LOPART(guidNPC), name.c_str()); // prevent cheating Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guidNPC, UNIT_NPC_FLAG_PETITIONER); if (!pCreature) { sLog.outDebug("WORLD: HandlePetitionBuyOpcode - Unit (GUID: %u) not found or you can't interact with him.", GUID_LOPART(guidNPC)); return; } // remove fake death if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); uint32 charterid = 0; uint32 cost = 0; uint32 type = 0; if (pCreature->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 = 9; } else { // TODO: find correct opcode if (_player->getLevel() < sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL)) { SendNotification(LANG_ARENA_ONE_TOOLOW, sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL)); return; } switch (unk10) { case 1: charterid = ARENA_TEAM_CHARTER_2v2; cost = ARENA_TEAM_CHARTER_2v2_COST; type = 2; // 2v2 break; case 2: charterid = ARENA_TEAM_CHARTER_3v3; cost = ARENA_TEAM_CHARTER_3v3_COST; type = 3; // 3v3 break; case 3: charterid = ARENA_TEAM_CHARTER_5v5; cost = ARENA_TEAM_CHARTER_5v5_COST; type = 5; // 5v5 break; default: sLog.outDebug("unknown selection at buy petition: %u", unk10); return; } if (_player->GetArenaTeamId(unk10-1)) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ALREADY_IN_ARENA_TEAM); return; } } if (type == 9) { if (sGuildMgr.GetGuildByName(name)) { SendGuildCommandResult(GUILD_CREATE_S, name, GUILD_NAME_EXISTS); return; } if (sObjectMgr.IsReservedName(name) || !ObjectMgr::IsValidCharterName(name)) { SendGuildCommandResult(GUILD_CREATE_S, name, GUILD_NAME_INVALID); return; } } else { if (sObjectMgr.GetArenaTeamByName(name)) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S); return; } if (sObjectMgr.IsReservedName(name) || !ObjectMgr::IsValidCharterName(name)) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_INVALID); return; } } ItemPrototype const *pProto = ObjectMgr::GetItemPrototype(charterid); if (!pProto) { _player->SendBuyError(BUY_ERR_CANT_FIND_ITEM, NULL, charterid, 0); return; } if (_player->GetMoney() < cost) { //player hasn't got enough money _player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, pCreature, charterid, 0); return; } ItemPosCountVec dest; uint8 msg = _player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, charterid, pProto->BuyCount); if (msg != EQUIP_ERR_OK) { _player->SendBuyError(msg, pCreature, charterid, 0); 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 QueryResultAutoPtr result = RealmDataDatabase.PQuery("SELECT petitionguid FROM petition WHERE ownerguid = '%u' AND type = '%u'", _player->GetGUIDLow(), type); 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("Invalid petition GUIDs: %s", ssInvalidPetitionGUIDs.str().c_str()); RealmDataDatabase.escape_string(name); RealmDataDatabase.BeginTransaction(); RealmDataDatabase.PExecute("DELETE FROM petition WHERE petitionguid IN (%s)", ssInvalidPetitionGUIDs.str().c_str()); RealmDataDatabase.PExecute("DELETE FROM petition_sign WHERE petitionguid IN (%s)", ssInvalidPetitionGUIDs.str().c_str()); RealmDataDatabase.PExecute("INSERT INTO petition (ownerguid, petitionguid, name, type) VALUES ('%u', '%u', '%s', '%u')", _player->GetGUIDLow(), charter->GetGUIDLow(), name.c_str(), type); RealmDataDatabase.CommitTransaction(); }
void WorldSession::HandlePetitionBuyOpcode(WorldPacket & recv_data) { if (_player->GetGuildId()) return; sLog->outDebug(LOG_FILTER_NETWORKIO, "Received opcode CMSG_PETITION_BUY"); recv_data.hexlike(); uint64 guidNPC; uint32 clientIndex; // 1 for guild and arenaslot+1 for arenas in client std::string name; recv_data >> guidNPC; // NPC GUID recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint64>(); // 0 recv_data >> name; // name recv_data.read_skip<std::string>(); // some string recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint16>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 for (int i = 0; i < 10; ++i) recv_data.read_skip<std::string>(); recv_data >> clientIndex; // index recv_data.read_skip<uint32>(); // 0 sLog->outDebug(LOG_FILTER_NETWORKIO, "Petitioner with GUID %u tried sell petition: name %s", GUID_LOPART(guidNPC), name.c_str()); // prevent cheating Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guidNPC,UNIT_NPC_FLAG_PETITIONER); if (!pCreature) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: HandlePetitionBuyOpcode - Unit (GUID: %u) not found or you can't interact with him.", GUID_LOPART(guidNPC)); return; } if (!pCreature->isTabardDesigner()) return; // remove fake death if (GetPlayer()->HasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); uint32 charterid = GUILD_CHARTER; uint32 cost = GUILD_CHARTER_COST; if (sObjectMgr->GetGuildByName(name)) { Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_EXISTS_S, name); return; } if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name)) { Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_INVALID, name); return; } ItemPrototype const *pProto = ObjectMgr::GetItemPrototype(charterid); if (!pProto) { _player->SendBuyError(BUY_ERR_CANT_FIND_ITEM, NULL, charterid, 0); return; } if (!_player->HasEnoughMoney(cost)) { //player hasn't got enough money _player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, pCreature, charterid, 0); return; } ItemPosCountVec dest; uint8 msg = _player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, charterid, pProto->BuyCount); if (msg != EQUIP_ERR_OK) { _player->SendBuyError(msg, pCreature, charterid, 0); 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 QueryResult result = CharDB.PQuery("SELECT petitionguid FROM petition WHERE ownerguid = '%u'", _player->GetGUIDLow()); 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()); CharDB.escape_string(name); SQLTransaction trans = CharDB.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()); trans->PAppend("INSERT INTO petition (ownerguid, petitionguid, name) VALUES ('%u', '%u', '%s')", _player->GetGUIDLow(), charter->GetGUIDLow(), name.c_str()); CharDB.CommitTransaction(trans); }
void WorldSession::HandleWrapItemOpcode(WorldPacket& recvData) { IC_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 IC_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, 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` { // after save it will be impossible to remove the item from the queue item->RemoveFromUpdateQueueOf(_player); item->SaveToDB(trans); // item gave inventory record unchanged and can be save standalone } CharacterDatabase.CommitTransaction(trans); uint32 count = 1; _player->DestroyItemCount(gift, count, true); }
void WorldSession::HandlePetitionBuyOpcode(WorldPacket& recv_data) { DEBUG_LOG("Received opcode CMSG_PETITION_BUY"); recv_data.hexlike(); ObjectGuid guidNPC; uint32 clientIndex; // 1 for guild and arenaslot+1 for arenas in client std::string name; recv_data >> guidNPC; // NPC GUID recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint64>(); // 0 recv_data >> name; // name recv_data.read_skip<std::string>(); // some string recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint16>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 for (int i = 0; i < 10; ++i) recv_data.read_skip<std::string>(); recv_data >> clientIndex; // index recv_data.read_skip<uint32>(); // 0 DEBUG_LOG("Petitioner %s tried sell petition: name %s", guidNPC.GetString().c_str(), name.c_str()); // prevent cheating Creature* pCreature = GetPlayer()->GetNPCIfCanInteractWith(guidNPC, UNIT_NPC_FLAG_PETITIONER); if (!pCreature) { DEBUG_LOG("WORLD: HandlePetitionBuyOpcode - %s not found or you can't interact with him.", guidNPC.GetString().c_str()); return; } uint32 charterid; uint32 cost; uint32 type; if (pCreature->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 = 9; } else { // TODO: find correct opcode if (_player->getLevel() < sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) { SendNotification(LANG_ARENA_ONE_TOOLOW, sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)); return; } switch (clientIndex) // arenaSlot+1 as received from client (1 from 3 case) { case 1: charterid = ARENA_TEAM_CHARTER_2v2; cost = ARENA_TEAM_CHARTER_2v2_COST; type = 2; // 2v2 break; case 2: charterid = ARENA_TEAM_CHARTER_3v3; cost = ARENA_TEAM_CHARTER_3v3_COST; type = 3; // 3v3 break; case 3: charterid = ARENA_TEAM_CHARTER_5v5; cost = ARENA_TEAM_CHARTER_5v5_COST; type = 5; // 5v5 break; default: DEBUG_LOG("unknown selection at buy arena petition: %u", clientIndex); return; } if (_player->GetArenaTeamId(clientIndex - 1)) // arenaSlot+1 as received from client { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ALREADY_IN_ARENA_TEAM); return; } } if (type == 9) { if (sGuildMgr.GetGuildByName(name)) { SendGuildCommandResult(GUILD_CREATE_S, name, ERR_GUILD_NAME_EXISTS_S); return; } if (sObjectMgr.IsReservedName(name) || !ObjectMgr::IsValidCharterName(name)) { SendGuildCommandResult(GUILD_CREATE_S, name, ERR_GUILD_NAME_INVALID); return; } } else { if (sObjectMgr.GetArenaTeamByName(name)) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S); return; } if (sObjectMgr.IsReservedName(name) || !ObjectMgr::IsValidCharterName(name)) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_INVALID); return; } } ItemPrototype const* pProto = ObjectMgr::GetItemPrototype(charterid); if (!pProto) { _player->SendBuyError(BUY_ERR_CANT_FIND_ITEM, nullptr, charterid, 0); return; } if (_player->GetMoney() < cost) { // player hasn't got enough money _player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, pCreature, 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, nullptr, nullptr, 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 data corruption QueryResult* result = CharacterDatabase.PQuery("SELECT petitionguid FROM petition WHERE ownerguid = '%u' AND type = '%u'", _player->GetGUIDLow(), type); std::ostringstream ssInvalidPetitionGUIDs; if (result) { do { Field* fields = result->Fetch(); ssInvalidPetitionGUIDs << "'" << fields[0].GetUInt32() << "' , "; } while (result->NextRow()); delete result; } // delete petitions with the same guid as this one ssInvalidPetitionGUIDs << "'" << charter->GetGUIDLow() << "'"; DEBUG_LOG("Invalid petition GUIDs: %s", ssInvalidPetitionGUIDs.str().c_str()); CharacterDatabase.escape_string(name); CharacterDatabase.BeginTransaction(); CharacterDatabase.PExecute("DELETE FROM petition WHERE petitionguid IN ( %s )", ssInvalidPetitionGUIDs.str().c_str()); CharacterDatabase.PExecute("DELETE FROM petition_sign WHERE petitionguid IN ( %s )", ssInvalidPetitionGUIDs.str().c_str()); CharacterDatabase.PExecute("INSERT INTO petition (ownerguid, petitionguid, name, type) VALUES ('%u', '%u', '%s', '%u')", _player->GetGUIDLow(), charter->GetGUIDLow(), name.c_str(), type); CharacterDatabase.CommitTransaction(); }
void WorldSession::HandlePetitionBuyOpcode(WorldPacket& recv_data) { DEBUG_LOG("Received opcode CMSG_PETITION_BUY"); recv_data.hexlike(); ObjectGuid guidNPC; uint32 unk2; std::string name; recv_data >> guidNPC; // NPC GUID recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint64>(); // 0 recv_data >> name; // name recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint32>(); // 0 recv_data.read_skip<uint16>(); // 0 recv_data.read_skip<uint8>(); // 0 recv_data >> unk2; // index recv_data.read_skip<uint32>(); // 0 DEBUG_LOG("Petitioner %s tried sell petition: name %s", guidNPC.GetString().c_str(), name.c_str()); // prevent cheating Creature* pCreature = GetPlayer()->GetNPCIfCanInteractWith(guidNPC, UNIT_NPC_FLAG_PETITIONER); if (!pCreature) { DEBUG_LOG("WORLD: HandlePetitionBuyOpcode - %s not found or you can't interact with him.", guidNPC.GetString().c_str()); return; } if (!pCreature->isTabardDesigner()) return; // remove fake death if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); // if tabard designer, then trying to buy a guild charter. // do not let if already in guild. if (_player->GetGuildId()) return; uint32 charterid = GUILD_CHARTER; uint32 cost = GUILD_CHARTER_COST; if (sGuildMgr.GetGuildByName(name)) { SendGuildCommandResult(GUILD_CREATE_S, name, ERR_GUILD_NAME_EXISTS_S); return; } if (sObjectMgr.IsReservedName(name) || !ObjectMgr::IsValidCharterName(name)) { SendGuildCommandResult(GUILD_CREATE_S, name, ERR_GUILD_NAME_INVALID); return; } ItemPrototype const* pProto = ObjectMgr::GetItemPrototype(charterid); if (!pProto) { _player->SendBuyError(BUY_ERR_CANT_FIND_ITEM, NULL, charterid, 0); return; } if (_player->GetMoney() < cost) { // player hasn't got enough money _player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, pCreature, 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, charter->GetGUIDLow()); // ITEM_FIELD_ENCHANTMENT is guild // ITEM_FIELD_ENCHANTMENT+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 data corruption QueryResult* result = CharacterDatabase.PQuery("SELECT petitionguid FROM petition WHERE ownerguid = '%u'", _player->GetGUIDLow()); std::ostringstream ssInvalidPetitionGUIDs; if (result) { do { Field* fields = result->Fetch(); ssInvalidPetitionGUIDs << "'" << fields[0].GetUInt32() << "' , "; } while (result->NextRow()); delete result; } // delete petitions with the same guid as this one ssInvalidPetitionGUIDs << "'" << charter->GetGUIDLow() << "'"; DEBUG_LOG("Invalid petition GUIDs: %s", ssInvalidPetitionGUIDs.str().c_str()); CharacterDatabase.escape_string(name); CharacterDatabase.BeginTransaction(); CharacterDatabase.PExecute("DELETE FROM petition WHERE petitionguid IN ( %s )", ssInvalidPetitionGUIDs.str().c_str()); CharacterDatabase.PExecute("DELETE FROM petition_sign WHERE petitionguid IN ( %s )", ssInvalidPetitionGUIDs.str().c_str()); CharacterDatabase.PExecute("INSERT INTO petition (ownerguid, petitionguid, name) VALUES ('%u', '%u', '%s')", _player->GetGUIDLow(), charter->GetGUIDLow(), name.c_str()); CharacterDatabase.CommitTransaction(); }
void WorldSession::HandleQuestgiverAcceptQuestOpcode( WorldPacket & recv_data ) { sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_ACCEPT_QUEST" ); if(!_player) return; if(!_player->IsInWorld()) return; //WorldPacket data; uint64 guid; uint32 quest_id; recv_data >> guid; recv_data >> quest_id; bool bValid = false; bool hasquest = true; bool bSkipLevelCheck = false; Quest *qst = NULL; Object *qst_giver = NULL; uint32 guidtype = GET_TYPE_FROM_GUID(guid); if(guidtype==HIGHGUID_TYPE_UNIT) { Creature *quest_giver = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(quest_giver) qst_giver = (Object*)quest_giver; else return; bValid = quest_giver->isQuestGiver(); hasquest = quest_giver->HasQuest(quest_id, 1); if(bValid) qst = QuestStorage.LookupEntry(quest_id); } else if(guidtype==HIGHGUID_TYPE_GAMEOBJECT) { GameObject *quest_giver = _player->GetMapMgr()->GetGameObject(GET_LOWGUID_PART(guid)); if(quest_giver) qst_giver = (Object*)quest_giver; else return; //bValid = quest_giver->isQuestGiver(); //if(bValid) bValid = true; qst = QuestStorage.LookupEntry(quest_id); } else if(guidtype==HIGHGUID_TYPE_ITEM) { Item *quest_giver = GetPlayer()->GetItemInterface()->GetItemByGUID(guid); if(quest_giver) qst_giver = (Object*)quest_giver; else return; bValid = true; bSkipLevelCheck=true; qst = QuestStorage.LookupEntry(quest_id); } else if(guidtype==HIGHGUID_TYPE_PLAYER) { Player *quest_giver = _player->GetMapMgr()->GetPlayer((uint32)guid); if(quest_giver) qst_giver = (Object*)quest_giver; else return; bValid = true; qst = QuestStorage.LookupEntry(quest_id); } if (!qst_giver) { sLog.outDebug("WORLD: Invalid questgiver GUID."); return; } if( !bValid || qst == NULL ) { sLog.outDebug("WORLD: Creature is not a questgiver."); return; } if( _player->GetQuestLogForEntry( qst->id ) ) return; if( qst_giver->GetTypeId() == TYPEID_UNIT && static_cast< Creature* >( qst_giver )->m_escorter != NULL ) { SystemMessage("You cannot accept this quest at this time."); return; } // Check the player hasn't already taken this quest, or // it isn't available. uint32 status = sQuestMgr.CalcQuestStatus(qst_giver, _player,qst,3, bSkipLevelCheck); if((!sQuestMgr.IsQuestRepeatable(qst) && _player->HasFinishedQuest(qst->id)) || ( status != QMGR_QUEST_AVAILABLE && status != QMGR_QUEST_REPEATABLE && status != QMGR_QUEST_CHAT ) || !hasquest) { // We've got a hacker. Disconnect them. //sCheatLog.writefromsession(this, "tried to accept incompatible quest %u from %u.", qst->id, qst_giver->GetEntry()); //Disconnect(); return; } int32 log_slot = GetPlayer()->GetOpenQuestSlot(); if (log_slot == -1) { sQuestMgr.SendQuestLogFull(GetPlayer()); return; } //FIXME /*if(Player Has Timed quest && qst->HasFlag(QUEST_FLAG_TIMED)) sQuestMgr.SendQuestInvalid(INVALID_REASON_HAVE_TIMED_QUEST);*/ if(qst->count_receiveitems || qst->srcitem) { uint32 slots_required = qst->count_receiveitems; if(GetPlayer()->GetItemInterface()->CalculateFreeSlots(NULL) < slots_required) { GetPlayer()->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_BAG_FULL); sQuestMgr.SendQuestFailed(FAILED_REASON_INV_FULL, qst, GetPlayer()); return; } } /* if(qst_giver->GetTypeId() == TYPEID_UNIT && !ScriptSystem->OnQuestRequireEvent(qst, static_cast< Creature* >( qst_giver ), _player, QUEST_EVENT_CAN_ACCEPT)) return;*/ QuestLogEntry *qle = new QuestLogEntry(); qle->Init(qst, _player, log_slot); qle->UpdatePlayerFields(); // If the quest should give any items on begin, give them the items. for(uint32 i = 0; i < 4; ++i) { if(qst->receive_items[i]) { Item *item = objmgr.CreateItem( qst->receive_items[i], GetPlayer()); if(item == NULL) continue; if(!GetPlayer()->GetItemInterface()->AddItemToFreeSlot(item)) { item->DeleteMe(); } else SendItemPushResult(item, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1); } } if(qst->srcitem && qst->srcitem != qst->receive_items[0]) { Item * item = objmgr.CreateItem( qst->srcitem, _player ); if(item) { item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, qst->srcitemcount ? qst->srcitemcount : 1); if(!_player->GetItemInterface()->AddItemToFreeSlot(item)) item->DeleteMe(); } } // Timed quest handler. if(qst->time > 0) { //Start Quest Timer Event Here //sEventMgr.AddEvent(GetPlayer(), &Player::EventTimedQuestExpire, qst, qle, static_cast<uint32>(log_slot), EVENT_TIMED_QUEST_EXPIRE, qst->time * 1000, 1); //uint32 qtime = static_cast<uint32>(time(NULL) + qst->time); //GetPlayer()->SetUInt32Value(log_slot+2, qtime); //GetPlayer()->SetUInt32Value(PLAYER_QUEST_LOG_1_01 + (log_slot * 3), qtime); //GetPlayer()->timed_quest_slot = log_slot; } if(qst->count_required_item || qst_giver->GetTypeId() == TYPEID_GAMEOBJECT) // gameobject quests deactivate GetPlayer()->UpdateNearbyGameObjects(); //ScriptSystem->OnQuestEvent(qst, static_cast< Creature* >( qst_giver ), _player, QUEST_EVENT_ON_ACCEPT); sQuestMgr.OnQuestAccepted(_player,qst,qst_giver); sLog.outDebug("WORLD: Added new QLE."); sHookInterface.OnQuestAccept(_player, qst, qst_giver); }
void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket) { sLog.outDetail("WORLD: CMSG_OPEN_ITEM packet, data length = %i",(uint32)recvPacket.size()); Player* pUser = _player; // ignore for remote control state if (pUser->m_mover != pUser) return; uint8 bagIndex, slot; recvPacket >> bagIndex >> slot; sLog.outDetail("bagIndex: %u, slot: %u",bagIndex,slot); Item *pItem = pUser->GetItemByPos(bagIndex, slot); if (!pItem) { pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL ); return; } ItemPrototype const *proto = pItem->GetProto(); if (!proto) { pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, pItem, NULL ); return; } if (!pUser->GetSession()->HandleOnItemOpen(pItem)) return; // locked item uint32 lockId = proto->LockID; if (lockId) { LockEntry const *lockInfo = sLockStore.LookupEntry(lockId); if (!lockInfo) { pUser->SendEquipError(EQUIP_ERR_ITEM_LOCKED, pItem, NULL ); sLog.outError("WORLD::OpenItem: item [guid = %u] has an unknown lockId: %u!", pItem->GetGUIDLow(), lockId); return; } // required picklocking if (lockInfo->Skill[1] || lockInfo->Skill[0]) { pUser->SendEquipError(EQUIP_ERR_ITEM_LOCKED, pItem, NULL ); return; } } if (pItem->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED))// wrapped? { QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT entry, flags FROM character_gifts WHERE item_guid = '%u'", pItem->GetGUIDLow()); if (result) { Field *fields = result->Fetch(); uint32 entry = fields[0].GetUInt32(); uint32 flags = fields[1].GetUInt32(); pItem->SetUInt64Value(ITEM_FIELD_GIFTCREATOR, 0); pItem->SetEntry(entry); pItem->SetUInt32Value(ITEM_FIELD_FLAGS, flags); pItem->SetState(ITEM_CHANGED, pUser); } else { sLog.outError("Wrapped item %u don't have record in character_gifts table and will deleted", pItem->GetGUIDLow()); pUser->DestroyItem(pItem->GetBagSlot(), pItem->GetSlot(), true); return; } CharacterDatabase.PExecute("DELETE FROM character_gifts WHERE item_guid = '%u'", pItem->GetGUIDLow()); } else pUser->SendLoot(pItem->GetGUID(),LOOT_CORPSE); }
bool HandlePlayerAddItem(BaseConsole * pConsole, int argc, const char * argv[]) { if ( argc < 4 ) { pConsole->Write( "ERROR:Not enough parameters.\r\n"); return false; } const char *PlayerName = argv[1]; uint32 itemid = atoi( argv[2] ); uint32 itemCount = atoi( argv[3] ); Player *plr = objmgr.GetPlayer(PlayerName, false); if( !plr || plr->IsInWorld() == false ) { pConsole->Write( "ERROR:Could not find player %s.\r\n", argv[1]); return true; } ItemPrototype *m_itemProto = ItemPrototypeStorage.LookupEntry( itemid ); if( m_itemProto == NULL ) { pConsole->Write( "ERROR:Could not find item.\r\n" ); return true; } itemCount = MAX( 1, itemCount ); //morron protection :P uint32 max_stack = MAX( 1, m_itemProto->MaxCount ); if( itemCount < max_stack ) max_stack = itemCount; for( uint32 i=0; i< ( itemCount + max_stack - 1) / max_stack; i++ ) //roundup { Item *item = objmgr.CreateItem( itemid, plr ); if( item == NULL ) { pConsole->Write( "ERROR:Could not create new item.\r\n" ); return true; } uint32 added_until_now = i*max_stack; uint32 need_to_add = itemCount - added_until_now; uint32 add_now = MAX(1, MIN( need_to_add, max_stack )); FILE *fp = fopen("ConsoleCommands.Log","at"); if( fp ) { fprintf(fp,"GUID = %u, name = %s, acct = %u has received item = %u count = %u guid = %u at %I64u \n",(uint32)plr->GetGUID(),plr->GetName(), plr->GetSession()->GetAccountId(),itemid, add_now,(uint32)item->GetGUID(), UNIXTIME); fclose( fp ); } item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, add_now ); if( plr->GetItemInterface()->SafeAddItem(item, INVENTORY_SLOT_NOT_SET, INVENTORY_SLOT_NOT_SET ) == ADD_ITEM_RESULT_ERROR ) { plr->RemoveAndMailItem( &item ); plr->BroadcastMessage("You have received a new item from a GM command in mail."); } else { plr->BroadcastMessage("You have received a new item from a GM command in your backpack. Your item has been saved"); } } plr->SaveToDB(false); pConsole->Write( "SUCCESS:Player has received the item\r\n" ); return true; }