bool ArenaTeam::AddMember(ObjectGuid playerGuid) { std::string plName; uint8 plClass; // arena team is full (can't have more than type * 2 players!) if (GetMembersSize() >= GetMaxMembersSize()) return false; Player* pl = sObjectMgr.GetPlayer(playerGuid); if (pl) { if (pl->GetArenaTeamId(GetSlot())) { sLog.outError("Arena::AddMember() : player already in this sized team"); return false; } plClass = pl->getClass(); plName = pl->GetName(); } else { // 0 1 QueryResult* result = CharacterDatabase.PQuery("SELECT name, class FROM characters WHERE guid='%u'", playerGuid.GetCounter()); if (!result) return false; plName = (*result)[0].GetCppString(); plClass = (*result)[1].GetUInt8(); delete result; // check if player already in arenateam of that size if (Player::GetArenaTeamIdFromDB(playerGuid, GetType()) != 0) { sLog.outError("Arena::AddMember() : player %s already in this sized team", playerGuid.GetString().c_str()); return false; } } // remove all player signs from another petitions // this will be prevent attempt joining player to many arenateams and corrupt arena team data integrity Player::RemovePetitionsAndSigns(playerGuid, GetType()); ArenaTeamMember newmember; newmember.name = plName; newmember.guid = playerGuid; newmember.Class = plClass; newmember.games_season = 0; newmember.games_week = 0; newmember.wins_season = 0; newmember.wins_week = 0; int32 conf_value = sWorld.getConfig(CONFIG_INT32_ARENA_STARTPERSONALRATING); if (conf_value < 0) // -1 = select by season id { if (sWorld.getConfig(CONFIG_UINT32_ARENA_SEASON_ID) >= 6) { if (m_stats.rating < 1000) newmember.personal_rating = 0; else newmember.personal_rating = 1000; } else { newmember.personal_rating = 1500; } } else newmember.personal_rating = uint32(conf_value); m_members.push_back(newmember); CharacterDatabase.PExecute("INSERT INTO arena_team_member (arenateamid, guid, personal_rating) VALUES ('%u', '%u', '%u')", m_TeamId, newmember.guid.GetCounter(), newmember.personal_rating); if (pl) { pl->SetInArenaTeam(m_TeamId, GetSlot(), GetType()); pl->SetArenaTeamIdInvited(0); pl->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_PERSONAL_RATING, newmember.personal_rating); // hide promote/remove buttons if (m_CaptainGuid != playerGuid) pl->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_MEMBER, 1); } return true; }
void WorldSession::HandleQuestgiverStatusQueryOpcode(WorldPacket & recv_data) { ObjectGuid guid; recv_data >> guid; uint8 dialogStatus = DIALOG_STATUS_NONE; Object* questgiver = _player->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_OR_GAMEOBJECT); if (!questgiver) { DETAIL_LOG("Error in CMSG_QUESTGIVER_STATUS_QUERY, called for not found questgiver %s", guid.GetString().c_str()); return; } DEBUG_LOG("WORLD: Received CMSG_QUESTGIVER_STATUS_QUERY - for %s to %s", _player->GetGuidStr().c_str(), guid.GetString().c_str()); switch(questgiver->GetTypeId()) { case TYPEID_UNIT: { Creature* cr_questgiver = (Creature*)questgiver; if (!cr_questgiver->IsHostileTo(_player)) // not show quest status to enemies { dialogStatus = sScriptMgr.GetDialogStatus(_player, cr_questgiver); if (dialogStatus > DIALOG_STATUS_REWARD_REP) dialogStatus = getDialogStatus(_player, cr_questgiver, DIALOG_STATUS_NONE); } break; } case TYPEID_GAMEOBJECT: { GameObject* go_questgiver = (GameObject*)questgiver; dialogStatus = sScriptMgr.GetDialogStatus(_player, go_questgiver); if (dialogStatus > DIALOG_STATUS_REWARD_REP) dialogStatus = getDialogStatus(_player, go_questgiver, DIALOG_STATUS_NONE); break; } default: sLog.outError("QuestGiver called for unexpected type %u", questgiver->GetTypeId()); break; } //inform client about status of quest _player->PlayerTalkClass->SendQuestGiverStatus(dialogStatus, guid); }
bool WorldSession::CanInteractWithQuestGiver(ObjectGuid guid, char const* descr) { if (guid.IsCreatureOrVehicle()) { Creature* pCreature = _player->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_QUESTGIVER); if (!pCreature) { DEBUG_LOG("WORLD: %s - %s cannot interact with %s.", descr, _player->GetGuidStr().c_str(), guid.GetString().c_str()); return false; } } else if (guid.IsGameObject()) { GameObject* pGo = _player->GetGameObjectIfCanInteractWith(guid, GAMEOBJECT_TYPE_QUESTGIVER); if (!pGo) { DEBUG_LOG("WORLD: %s - %s cannot interact with %s.", descr, _player->GetGuidStr().c_str(), guid.GetString().c_str()); return false; } } else if (!_player->isAlive()) { DEBUG_LOG("WORLD: %s - %s is dead, requested guid was %s", descr, _player->GetGuidStr().c_str(), guid.GetString().c_str()); return false; } return true; }
void WorldSession::HandleQuestgiverAcceptQuestOpcode(WorldPacket & recv_data) { ObjectGuid guid; uint32 quest; uint32 unk1; recv_data >> guid >> quest >> unk1; if (!CanInteractWithQuestGiver(guid, "CMSG_QUESTGIVER_ACCEPT_QUEST")) return; DEBUG_LOG("WORLD: Received CMSG_QUESTGIVER_ACCEPT_QUEST - for %s to %s, quest = %u, unk1 = %u", _player->GetGuidStr().c_str(), guid.GetString().c_str(), quest, unk1 ); Object* pObject = _player->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_GAMEOBJECT_PLAYER_OR_ITEM); // no or incorrect quest giver (player himself is questgiver for SPELL_EFFECT_QUEST_OFFER) if (!pObject || (pObject->GetTypeId() != TYPEID_PLAYER && !pObject->HasQuest(quest)) || (pObject->GetTypeId() == TYPEID_PLAYER && pObject != _player && !((Player*)pObject)->CanShareQuest(quest)) ) { _player->PlayerTalkClass->CloseGossip(); _player->ClearDividerGuid(); return; } Quest const* qInfo = sObjectMgr.GetQuestTemplate(quest); if ( qInfo ) { // prevent cheating if(!GetPlayer()->CanTakeQuest(qInfo,true) ) { _player->PlayerTalkClass->CloseGossip(); _player->ClearDividerGuid(); return; } if (Player *pPlayer = ObjectAccessor::FindPlayer(_player->GetDividerGuid())) { pPlayer->SendPushToPartyResponse(_player, QUEST_PARTY_MSG_ACCEPT_QUEST); _player->ClearDividerGuid(); } if( _player->CanAddQuest( qInfo, true ) ) { _player->AddQuest( qInfo, pObject ); // pObject (if it item) can be destroyed at call if (qInfo->HasQuestFlag(QUEST_FLAGS_PARTY_ACCEPT)) { if (Group* pGroup = _player->GetGroup()) { for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next()) { Player* pPlayer = itr->getSource(); if (!pPlayer || pPlayer == _player) // not self continue; if (pPlayer->CanTakeQuest(qInfo, true)) { pPlayer->SetDividerGuid(_player->GetObjectGuid()); //need confirmation that any gossip window will close pPlayer->PlayerTalkClass->CloseGossip(); _player->SendQuestConfirmAccept(qInfo, pPlayer); } } } } if ( _player->CanCompleteQuest( quest ) ) _player->CompleteQuest( quest ); _player->GetAchievementMgr().StartTimedAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST, quest); _player->PlayerTalkClass->CloseGossip(); if( qInfo->GetSrcSpell() > 0 ) _player->CastSpell( _player, qInfo->GetSrcSpell(), true); return; } } _player->PlayerTalkClass->CloseGossip(); }
void WorldSession::HandleQuestgiverChooseRewardOpcode(WorldPacket & recv_data) { uint32 quest, reward; ObjectGuid guid; recv_data >> guid >> quest >> reward; if(reward >= QUEST_REWARD_CHOICES_COUNT) { sLog.outError("Error in CMSG_QUESTGIVER_CHOOSE_REWARD - %s tried to get invalid reward (%u) (probably packet hacking)", _player->GetGuidStr().c_str(), _player->GetGUIDLow(), reward); return; } if (!CanInteractWithQuestGiver(guid, "CMSG_QUESTGIVER_CHOOSE_REWARD")) return; DEBUG_LOG("WORLD: Received CMSG_QUESTGIVER_CHOOSE_REWARD - for %s to %s, quest = %u, reward = %u", _player->GetGuidStr().c_str(), guid.GetString().c_str(), quest, reward); Object* pObject = _player->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_OR_GAMEOBJECT); if(!pObject) return; if(!pObject->HasInvolvedQuest(quest)) return; Quest const *pQuest = sObjectMgr.GetQuestTemplate(quest); if( pQuest ) { if( _player->CanRewardQuest( pQuest, reward, true ) ) { _player->RewardQuest( pQuest, reward, pObject ); // Send next quest if (Quest const* nextquest = _player->GetNextQuest(guid, pQuest)) _player->PlayerTalkClass->SendQuestGiverQuestDetails(nextquest, guid, true); } else _player->PlayerTalkClass->SendQuestGiverOfferReward(pQuest, guid, 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<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 >> 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::HandleTurnInPetitionOpcode(WorldPacket& recv_data) { DEBUG_LOG("Received opcode CMSG_TURN_IN_PETITION"); // ok // recv_data.hexlike(); ObjectGuid petitionGuid; recv_data >> petitionGuid; DEBUG_LOG("Petition %s turned in by %s", petitionGuid.GetString().c_str(), _player->GetGuidStr().c_str()); /// Collect petition info data ObjectGuid ownerGuid; uint32 type; std::string name; // data QueryResult* result = CharacterDatabase.PQuery("SELECT ownerguid, name, type FROM petition WHERE petitionguid = '%u'", petitionGuid.GetCounter()); if (result) { Field* fields = result->Fetch(); ownerGuid = ObjectGuid(HIGHGUID_PLAYER, fields[0].GetUInt32()); name = fields[1].GetCppString(); type = fields[2].GetUInt32(); delete result; } else { sLog.outError("CMSG_TURN_IN_PETITION: petition table not have data for guid %u!", petitionGuid.GetCounter()); return; } if (type == 9) { if (_player->GetGuildId()) { WorldPacket data(SMSG_TURN_IN_PETITION_RESULTS, 4); data << uint32(PETITION_TURN_ALREADY_IN_GUILD); // already in guild _player->GetSession()->SendPacket(&data); return; } } else { if (!IsArenaTypeValid(ArenaType(type))) return; uint8 slot = ArenaTeam::GetSlotByType(ArenaType(type)); if (slot >= MAX_ARENA_SLOT) return; if (_player->GetArenaTeamId(slot)) { // data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4); // data << (uint32)PETITION_TURN_ALREADY_IN_GUILD; // already in guild //_player->GetSession()->SendPacket(&data); SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ALREADY_IN_ARENA_TEAM); return; } } if (_player->GetObjectGuid() != ownerGuid) return; // signs result = CharacterDatabase.PQuery("SELECT playerguid FROM petition_sign WHERE petitionguid = '%u'", petitionGuid.GetCounter()); uint8 signs = result ? (uint8)result->GetRowCount() : 0; uint32 count = type == 9 ? sWorld.getConfig(CONFIG_UINT32_MIN_PETITION_SIGNS) : type - 1; if (signs < count) { WorldPacket data(SMSG_TURN_IN_PETITION_RESULTS, 4); data << uint32(PETITION_TURN_NEED_MORE_SIGNATURES); // need more signatures... SendPacket(&data); delete result; return; } if (type == 9) { if (sGuildMgr.GetGuildByName(name)) { SendGuildCommandResult(GUILD_CREATE_S, name, ERR_GUILD_NAME_EXISTS_S); delete result; return; } } else { if (sObjectMgr.GetArenaTeamByName(name)) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S); delete result; return; } } // and at last charter item check Item* item = _player->GetItemByGuid(petitionGuid); if (!item) { delete result; return; } // OK! // delete charter item _player->DestroyItem(item->GetBagSlot(), item->GetSlot(), true); if (type == 9) // create guild { Guild* guild = new Guild; if (!guild->Create(_player, name)) { delete guild; delete result; return; } // register guild and add guildmaster sGuildMgr.AddGuild(guild); // add members for (uint8 i = 0; i < signs; ++i) { Field* fields = result->Fetch(); ObjectGuid signGuid = ObjectGuid(HIGHGUID_PLAYER, fields[0].GetUInt32()); if (!signGuid) continue; guild->AddMember(signGuid, guild->GetLowestRank()); result->NextRow(); } } else // or arena team { ArenaTeam* at = new ArenaTeam; if (!at->Create(_player->GetObjectGuid(), ArenaType(type), name)) { sLog.outError("PetitionsHandler: arena team create failed."); delete at; delete result; return; } uint32 icon, iconcolor, border, bordercolor, backgroud; recv_data >> backgroud >> icon >> iconcolor >> border >> bordercolor; at->SetEmblem(backgroud, icon, iconcolor, border, bordercolor); // register team and add captain sObjectMgr.AddArenaTeam(at); DEBUG_LOG("PetitonsHandler: arena team added to objmrg"); // add members for (uint8 i = 0; i < signs; ++i) { Field* fields = result->Fetch(); ObjectGuid memberGUID = ObjectGuid(HIGHGUID_PLAYER, fields[0].GetUInt32()); if (!memberGUID) continue; DEBUG_LOG("PetitionsHandler: adding arena member %s", memberGUID.GetString().c_str()); at->AddMember(memberGUID); result->NextRow(); } } delete result; CharacterDatabase.BeginTransaction(); CharacterDatabase.PExecute("DELETE FROM petition WHERE petitionguid = '%u'", petitionGuid.GetCounter()); CharacterDatabase.PExecute("DELETE FROM petition_sign WHERE petitionguid = '%u'", petitionGuid.GetCounter()); CharacterDatabase.CommitTransaction(); // created DEBUG_LOG("TURN IN PETITION %s", petitionGuid.GetString().c_str()); WorldPacket data(SMSG_TURN_IN_PETITION_RESULTS, 4); data << uint32(PETITION_TURN_OK); SendPacket(&data); }
void WorldSession::HandleTrainerBuySpellOpcode( WorldPacket & recv_data ) { ObjectGuid guid; uint32 spellId = 0; recv_data >> guid >> spellId; DEBUG_LOG("WORLD: Received CMSG_TRAINER_BUY_SPELL Trainer: %s, learn spell id is: %u", guid.GetString().c_str(), spellId); Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_TRAINER); if (!unit) { DEBUG_LOG("WORLD: HandleTrainerBuySpellOpcode - %s not found or you can't interact with him.", guid.GetString().c_str()); return; } // remove fake death if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); if (!unit->IsTrainerOf(_player, true)) return; // check present spell in trainer spell list TrainerSpellData const* cSpells = unit->GetTrainerSpells(); TrainerSpellData const* tSpells = unit->GetTrainerTemplateSpells(); if (!cSpells && !tSpells) return; // Try find spell in npc_trainer TrainerSpell const* trainer_spell = cSpells ? cSpells->Find(spellId) : NULL; // Not found, try find in npc_trainer_template if (!trainer_spell && tSpells) trainer_spell = tSpells->Find(spellId); // Not found anywhere, cheating? if (!trainer_spell) return; // can't be learn, cheat? Or double learn with lags... if (_player->GetTrainerSpellState(trainer_spell) != TRAINER_SPELL_GREEN) return; // apply reputation discount uint32 nSpellCost = uint32(floor(trainer_spell->spellCost * _player->GetReputationPriceDiscount(unit))); // check money requirement if(_player->GetMoney() < nSpellCost ) return; _player->ModifyMoney( -int32(nSpellCost) ); WorldPacket data(SMSG_PLAY_SPELL_VISUAL, 12); // visual effect on trainer data << ObjectGuid(guid); data << uint32(0xB3); // index from SpellVisualKit.dbc SendPacket(&data); data.Initialize(SMSG_PLAY_SPELL_IMPACT, 12); // visual effect on player data << _player->GetObjectGuid(); data << uint32(0x016A); // index from SpellVisualKit.dbc SendPacket(&data); // learn explicitly or cast explicitly if(trainer_spell->IsCastable()) _player->CastSpell(_player, trainer_spell->spell, true); else _player->learnSpell(spellId, false); data.Initialize(SMSG_TRAINER_BUY_SUCCEEDED, 12); data << ObjectGuid(guid); data << uint32(spellId); // should be same as in packet from client SendPacket(&data); }
void WorldSession::HandleGossipHelloOpcode(WorldPacket & recv_data) { DEBUG_LOG("WORLD: Received CMSG_GOSSIP_HELLO"); ObjectGuid guid; recv_data >> guid; Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_NONE); if (!pCreature) { DEBUG_LOG("WORLD: HandleGossipHelloOpcode - %s not found or you can't interact with him.", guid.GetString().c_str()); return; } // remove fake death if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); if (!pCreature->IsStopped()) pCreature->StopMoving(); if (pCreature->isSpiritGuide()) pCreature->SendAreaSpiritHealerQueryOpcode(_player); if (!sScriptMgr.OnGossipHello(_player, pCreature)) { _player->PrepareGossipMenu(pCreature, pCreature->GetCreatureInfo()->GossipMenuId); _player->SendPreparedGossip(pCreature); } }
void PlayerMenu::SendQuestGiverRequestItems(Quest const* pQuest, ObjectGuid npcGUID, bool Completable, bool CloseOnCancel) { // We can always call to RequestItems, but this packet only goes out if there are actually // items. Otherwise, we'll skip straight to the OfferReward std::string Title = pQuest->GetTitle(); std::string RequestItemsText = pQuest->GetRequestItemsText(); int loc_idx = GetMenuSession()->GetSessionDbLocaleIndex(); if (loc_idx >= 0) { if (QuestLocale const* ql = sObjectMgr.GetQuestLocale(pQuest->GetQuestId())) { if (ql->Title.size() > (size_t)loc_idx && !ql->Title[loc_idx].empty()) Title = ql->Title[loc_idx]; if (ql->RequestItemsText.size() > (size_t)loc_idx && !ql->RequestItemsText[loc_idx].empty()) RequestItemsText = ql->RequestItemsText[loc_idx]; } } if (!pQuest->GetReqItemsCount() && Completable) { SendQuestGiverOfferReward(pQuest, npcGUID, true); return; } WorldPacket data(SMSG_QUESTGIVER_REQUEST_ITEMS, 50); // guess size data << ObjectGuid(npcGUID); data << uint32(pQuest->GetQuestId()); data << Title; data << RequestItemsText; data << uint32(0x00); // emote delay if (Completable) data << pQuest->GetCompleteEmote(); // emote id else data << pQuest->GetIncompleteEmote(); // Close Window after cancel if (CloseOnCancel) data << uint32(0x01); // auto finish else data << uint32(0x00); data << uint32(pQuest->GetQuestFlags()); // 3.3.3 questFlags data << uint32(pQuest->GetSuggestedPlayers()); // SuggestedGroupNum // Required Money data << uint32(pQuest->GetRewOrReqMoney() < 0 ? -pQuest->GetRewOrReqMoney() : 0); data << uint32(pQuest->GetReqItemsCount()); ItemPrototype const* pItem; for (int i = 0; i < QUEST_ITEM_OBJECTIVES_COUNT; ++i) { if (!pQuest->ReqItemId[i]) continue; pItem = ObjectMgr::GetItemPrototype(pQuest->ReqItemId[i]); data << uint32(pQuest->ReqItemId[i]); data << uint32(pQuest->ReqItemCount[i]); if (pItem) data << uint32(pItem->DisplayInfoID); else data << uint32(0); } if (!Completable) // Completable = flags1 && flags2 && flags3 && flags4 data << uint32(0x00); // flags1 else data << uint32(0x03); data << uint32(0x04); // flags2 data << uint32(0x08); // flags3 data << uint32(0x10); // flags4 GetMenuSession()->SendPacket(&data); DEBUG_LOG("WORLD: Sent SMSG_QUESTGIVER_REQUEST_ITEMS NPCGuid = %s, questid = %u", npcGUID.GetString().c_str(), pQuest->GetQuestId()); }
void WorldSession::SendTrainerList(ObjectGuid guid, const std::string& strTitle) { DEBUG_LOG( "WORLD: SendTrainerList" ); Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_TRAINER); if (!unit) { DEBUG_LOG("WORLD: SendTrainerList - %s not found or you can't interact with him.", guid.GetString().c_str()); return; } // remove fake death if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); // trainer list loaded at check; if (!unit->IsTrainerOf(_player,true)) return; CreatureInfo const *ci = unit->GetCreatureInfo(); if (!ci) return; TrainerSpellData const* cSpells = unit->GetTrainerSpells(); TrainerSpellData const* tSpells = unit->GetTrainerTemplateSpells(); if (!cSpells && !tSpells) { DEBUG_LOG("WORLD: SendTrainerList - Training spells not found for %s", guid.GetString().c_str()); return; } uint32 maxcount = (cSpells ? cSpells->spellList.size() : 0) + (tSpells ? tSpells->spellList.size() : 0); uint32 trainer_type = cSpells && cSpells->trainerType ? cSpells->trainerType : (tSpells ? tSpells->trainerType : 0); WorldPacket data( SMSG_TRAINER_LIST, 8+4+4+maxcount*38 + strTitle.size()+1); data << ObjectGuid(guid); data << uint32(trainer_type); size_t count_pos = data.wpos(); data << uint32(maxcount); // reputation discount float fDiscountMod = _player->GetReputationPriceDiscount(unit); bool can_learn_primary_prof = GetPlayer()->GetFreePrimaryProfessionPoints() > 0; uint32 count = 0; if (cSpells) { for(TrainerSpellMap::const_iterator itr = cSpells->spellList.begin(); itr != cSpells->spellList.end(); ++itr) { TrainerSpell const* tSpell = &itr->second; if(!_player->IsSpellFitByClassAndRace(tSpell->learnedSpell)) continue; TrainerSpellState state = _player->GetTrainerSpellState(tSpell); SendTrainerSpellHelper(data, tSpell, state, fDiscountMod, can_learn_primary_prof); ++count; } } if (tSpells) { for(TrainerSpellMap::const_iterator itr = tSpells->spellList.begin(); itr != tSpells->spellList.end(); ++itr) { TrainerSpell const* tSpell = &itr->second; if(!_player->IsSpellFitByClassAndRace(tSpell->learnedSpell)) continue; TrainerSpellState state = _player->GetTrainerSpellState(tSpell); SendTrainerSpellHelper(data, tSpell, state, fDiscountMod, can_learn_primary_prof); ++count; } } data << strTitle; data.put<uint32>(count_pos,count); SendPacket(&data); }
void PlayerMenu::SendQuestGiverOfferReward(Quest const* pQuest, ObjectGuid npcGUID, bool EnableNext) { std::string Title = pQuest->GetTitle(); std::string OfferRewardText = pQuest->GetOfferRewardText(); int loc_idx = GetMenuSession()->GetSessionDbLocaleIndex(); if (loc_idx >= 0) { if (QuestLocale const* ql = sObjectMgr.GetQuestLocale(pQuest->GetQuestId())) { if (ql->Title.size() > (size_t)loc_idx && !ql->Title[loc_idx].empty()) Title = ql->Title[loc_idx]; if (ql->OfferRewardText.size() > (size_t)loc_idx && !ql->OfferRewardText[loc_idx].empty()) OfferRewardText = ql->OfferRewardText[loc_idx]; } } WorldPacket data(SMSG_QUESTGIVER_OFFER_REWARD, 50); // guess size data << ObjectGuid(npcGUID); data << uint32(pQuest->GetQuestId()); data << Title; data << OfferRewardText; data << uint8(EnableNext ? 1 : 0); // Auto Finish data << uint32(pQuest->GetQuestFlags()); // 3.3.3 questFlags data << uint32(pQuest->GetSuggestedPlayers()); // SuggestedGroupNum uint32 EmoteCount = 0; for (uint32 i = 0; i < QUEST_EMOTE_COUNT; ++i) { if (pQuest->OfferRewardEmote[i] <= 0) break; ++EmoteCount; } data << EmoteCount; // Emote Count for (uint32 i = 0; i < EmoteCount; ++i) { data << uint32(pQuest->OfferRewardEmoteDelay[i]); // Delay Emote data << uint32(pQuest->OfferRewardEmote[i]); } ItemPrototype const* pItem; data << uint32(pQuest->GetRewChoiceItemsCount()); for (uint32 i = 0; i < pQuest->GetRewChoiceItemsCount(); ++i) { pItem = ObjectMgr::GetItemPrototype(pQuest->RewChoiceItemId[i]); data << uint32(pQuest->RewChoiceItemId[i]); data << uint32(pQuest->RewChoiceItemCount[i]); if (pItem) data << uint32(pItem->DisplayInfoID); else data << uint32(0); } data << uint32(pQuest->GetRewItemsCount()); for (uint32 i = 0; i < pQuest->GetRewItemsCount(); ++i) { pItem = ObjectMgr::GetItemPrototype(pQuest->RewItemId[i]); data << uint32(pQuest->RewItemId[i]); data << uint32(pQuest->RewItemCount[i]); if (pItem) data << uint32(pItem->DisplayInfoID); else data << uint32(0); } // send rewMoneyMaxLevel explicit for max player level, else send RewOrReqMoney if (GetMenuSession()->GetPlayer()->getLevel() >= sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) data << uint32(pQuest->GetRewMoneyMaxLevel()); else data << uint32(pQuest->GetRewOrReqMoney()); // xp data << uint32(pQuest->XPValue(GetMenuSession()->GetPlayer())); // TODO: fixme. rewarded honor points. Multiply with 10 to satisfy client data << uint32(10 * MaNGOS::Honor::hk_honor_at_level(GetMenuSession()->GetPlayer()->getLevel(), pQuest->GetRewHonorAddition())); data << float(pQuest->GetRewHonorMultiplier()); data << uint32(0x08); // unused by client? data << uint32(pQuest->GetRewSpell()); // reward spell, this spell will display (icon) (casted if RewSpellCast==0) data << uint32(pQuest->GetRewSpellCast()); // casted spell data << uint32(pQuest->GetCharTitleId()); // character title data << uint32(pQuest->GetBonusTalents()); // bonus talents data << uint32(0); // bonus arena points data << uint32(0); // rew rep show mask? for (int i = 0; i < QUEST_REPUTATIONS_COUNT; ++i) // reward factions ids data << uint32(pQuest->RewRepFaction[i]); for (int i = 0; i < QUEST_REPUTATIONS_COUNT; ++i) // columnid in QuestFactionReward.dbc (if negative, from second row) data << int32(pQuest->RewRepValueId[i]); for (int i = 0; i < QUEST_REPUTATIONS_COUNT; ++i) // reward reputation override. No diplomacy bonus is expected given, reward also does not display in chat window data << int32(0); // data << int32(pQuest->RewRepValue[i]); GetMenuSession()->SendPacket(&data); DEBUG_LOG("WORLD: Sent SMSG_QUESTGIVER_OFFER_REWARD NPCGuid = %s, questid = %u", npcGUID.GetString().c_str(), pQuest->GetQuestId()); }
void PlayerMenu::SendQuestGiverQuestDetails(Quest const* pQuest, ObjectGuid guid, bool ActivateAccept) { std::string Title = pQuest->GetTitle(); std::string Details = pQuest->GetDetails(); std::string Objectives = pQuest->GetObjectives(); int loc_idx = GetMenuSession()->GetSessionDbLocaleIndex(); if (loc_idx >= 0) { if (QuestLocale const* ql = sObjectMgr.GetQuestLocale(pQuest->GetQuestId())) { if (ql->Title.size() > (size_t)loc_idx && !ql->Title[loc_idx].empty()) Title = ql->Title[loc_idx]; if (ql->Details.size() > (size_t)loc_idx && !ql->Details[loc_idx].empty()) Details = ql->Details[loc_idx]; if (ql->Objectives.size() > (size_t)loc_idx && !ql->Objectives[loc_idx].empty()) Objectives = ql->Objectives[loc_idx]; } } WorldPacket data(SMSG_QUESTGIVER_QUEST_DETAILS, 100); // guess size data << guid; data << uint64(0); // wotlk, something todo with quest sharing? data << uint32(pQuest->GetQuestId()); data << Title; data << Details; data << Objectives; data << uint8(ActivateAccept ? 1 : 0); // auto finish data << uint32(pQuest->GetQuestFlags()); // 3.3.3 questFlags data << uint32(pQuest->GetSuggestedPlayers()); data << uint8(0); // IsFinished? value is sent back to server in quest accept packet if (pQuest->HasQuestFlag(QUEST_FLAGS_HIDDEN_REWARDS)) { data << uint32(0); // Rewarded chosen items hidden data << uint32(0); // Rewarded items hidden data << uint32(0); // Rewarded money hidden data << uint32(0); // Rewarded XP hidden } else { ItemPrototype const* IProto; data << uint32(pQuest->GetRewChoiceItemsCount()); for (uint32 i = 0; i < QUEST_REWARD_CHOICES_COUNT; ++i) { if (!pQuest->RewChoiceItemId[i]) continue; data << uint32(pQuest->RewChoiceItemId[i]); data << uint32(pQuest->RewChoiceItemCount[i]); IProto = ObjectMgr::GetItemPrototype(pQuest->RewChoiceItemId[i]); if (IProto) data << uint32(IProto->DisplayInfoID); else data << uint32(0x00); } data << uint32(pQuest->GetRewItemsCount()); for (uint32 i = 0; i < QUEST_REWARDS_COUNT; ++i) { if (!pQuest->RewItemId[i]) continue; data << uint32(pQuest->RewItemId[i]); data << uint32(pQuest->RewItemCount[i]); IProto = ObjectMgr::GetItemPrototype(pQuest->RewItemId[i]); if (IProto) data << uint32(IProto->DisplayInfoID); else data << uint32(0); } // send rewMoneyMaxLevel explicit for max player level, else send RewOrReqMoney if (GetMenuSession()->GetPlayer()->getLevel() >= sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) data << uint32(pQuest->GetRewMoneyMaxLevel()); else data << uint32(pQuest->GetRewOrReqMoney()); data << uint32(pQuest->XPValue(GetMenuSession()->GetPlayer())); } // TODO: fixme. rewarded honor points data << uint32(pQuest->GetRewHonorAddition()); data << float(pQuest->GetRewHonorMultiplier()); // new 3.3.0 data << uint32(pQuest->GetRewSpell()); // reward spell, this spell will display (icon) (casted if RewSpellCast==0) data << uint32(pQuest->GetRewSpellCast()); // casted spell data << uint32(pQuest->GetCharTitleId()); // CharTitleId, new 2.4.0, player gets this title (id from CharTitles) data << uint32(pQuest->GetBonusTalents()); // bonus talents data << uint32(0); // bonus arena points data << uint32(0); // rep reward show mask? for (int i = 0; i < QUEST_REPUTATIONS_COUNT; ++i) // reward factions ids data << uint32(pQuest->RewRepFaction[i]); for (int i = 0; i < QUEST_REPUTATIONS_COUNT; ++i) // columnid in QuestFactionReward.dbc (if negative, from second row) data << int32(pQuest->RewRepValueId[i]); for (int i = 0; i < QUEST_REPUTATIONS_COUNT; ++i) // reward reputation override. No bonus is expected given data << int32(0); // data << int32(pQuest->RewRepValue[i]); // current field for store of rep value, can be reused to implement "override value" data << uint32(QUEST_EMOTE_COUNT); for (uint32 i = 0; i < QUEST_EMOTE_COUNT; ++i) { data << uint32(pQuest->DetailsEmote[i]); data << uint32(pQuest->DetailsEmoteDelay[i]); // DetailsEmoteDelay (in ms) } GetMenuSession()->SendPacket(&data); DEBUG_LOG("WORLD: Sent SMSG_QUESTGIVER_QUEST_DETAILS - for %s of %s, questid = %u", GetMenuSession()->GetPlayer()->GetGuidStr().c_str(), guid.GetString().c_str(), pQuest->GetQuestId()); }
// this void creates new auction and adds auction to some auctionhouse void WorldSession::HandleAuctionSellItem(WorldPacket& recv_data) { DEBUG_LOG("WORLD: HandleAuctionSellItem"); ObjectGuid auctioneerGuid; ObjectGuid itemGuid; uint32 etime, bid, buyout; recv_data >> auctioneerGuid; recv_data >> itemGuid; recv_data >> bid; recv_data >> buyout; recv_data >> etime; if (!bid || !etime) return; // check for cheaters Player* pl = GetPlayer(); AuctionHouseEntry const* auctionHouseEntry = GetCheckedAuctionHouseForAuctioneer(auctioneerGuid); if (!auctionHouseEntry) return; // always return pointer AuctionHouseObject* auctionHouse = sAuctionMgr.GetAuctionsMap(auctionHouseEntry); // client send time in minutes, convert to common used sec time etime *= MINUTE; // client understand only 3 auction time switch (etime) { case 1*MIN_AUCTION_TIME: case 2*MIN_AUCTION_TIME: case 4*MIN_AUCTION_TIME: break; default: return; } // remove fake death if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); if (!itemGuid) return; Item* it = pl->GetItemByGuid(itemGuid); // do not allow to sell already auctioned items if (sAuctionMgr.GetAItem(itemGuid.GetCounter())) { sLog.outError("AuctionError, %s is sending %s, but item is already in another auction", pl->GetGuidStr().c_str(), itemGuid.GetString().c_str()); SendAuctionCommandResult(NULL, AUCTION_STARTED, AUCTION_ERR_INVENTORY, EQUIP_ERR_ITEM_NOT_FOUND); return; } // prevent sending bag with items (cheat: can be placed in bag after adding equipped empty bag to auction) if (!it) { SendAuctionCommandResult(NULL, AUCTION_STARTED, AUCTION_ERR_INVENTORY, EQUIP_ERR_ITEM_NOT_FOUND); return; } if (!it->CanBeTraded()) { SendAuctionCommandResult(NULL, AUCTION_STARTED, AUCTION_ERR_INVENTORY, EQUIP_ERR_CANNOT_TRADE_THAT); return; } if ((it->GetProto()->Flags & ITEM_FLAG_CONJURED) || it->GetUInt32Value(ITEM_FIELD_DURATION)) { SendAuctionCommandResult(NULL, AUCTION_STARTED, AUCTION_ERR_INVENTORY, EQUIP_ERR_CANNOT_TRADE_THAT); return; } // check money for deposit uint32 deposit = AuctionHouseMgr::GetAuctionDeposit(auctionHouseEntry, etime, it); if (pl->GetMoney() < deposit) { SendAuctionCommandResult(NULL, AUCTION_STARTED, AUCTION_ERR_NOT_ENOUGH_MONEY); return; } if (GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_BOOL_GM_LOG_TRADE)) { sLog.outCommand(GetAccountId(), "GM %s (Account: %u) create auction: %s (Entry: %u Count: %u)", GetPlayerName(), GetAccountId(), it->GetProto()->Name1, it->GetEntry(), it->GetCount()); } pl->ModifyMoney(-int32(deposit)); AuctionEntry* AH = auctionHouse->AddAuction(auctionHouseEntry, it, etime, bid, buyout, deposit, pl); DETAIL_LOG("selling %s to auctioneer %s with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", itemGuid.GetString().c_str(), auctioneerGuid.GetString().c_str(), bid, buyout, etime, auctionHouseEntry->houseId); SendAuctionCommandResult(AH, AUCTION_STARTED, AUCTION_OK); // used by eluna sHookMgr.OnAdd(auctionHouse); }
void WorldSession::HandlePetitionRenameOpcode(WorldPacket& recv_data) { DEBUG_LOG("Received opcode MSG_PETITION_RENAME"); // ok // recv_data.hexlike(); ObjectGuid petitionGuid; uint32 type; std::string newname; recv_data >> petitionGuid; // guid recv_data >> newname; // new name Item* item = _player->GetItemByGuid(petitionGuid); if (!item) return; QueryResult* result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", petitionGuid.GetCounter()); if (result) { Field* fields = result->Fetch(); type = fields[0].GetUInt32(); delete result; } else { DEBUG_LOG("CMSG_PETITION_QUERY failed for petition: %s", petitionGuid.GetString().c_str()); return; } if (type == 9) { if (sGuildMgr.GetGuildByName(newname)) { SendGuildCommandResult(GUILD_CREATE_S, newname, ERR_GUILD_NAME_EXISTS_S); return; } if (sObjectMgr.IsReservedName(newname) || !ObjectMgr::IsValidCharterName(newname)) { SendGuildCommandResult(GUILD_CREATE_S, newname, ERR_GUILD_NAME_INVALID); return; } } else { if (sObjectMgr.GetArenaTeamByName(newname)) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newname, "", ERR_ARENA_TEAM_NAME_EXISTS_S); return; } if (sObjectMgr.IsReservedName(newname) || !ObjectMgr::IsValidCharterName(newname)) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newname, "", ERR_ARENA_TEAM_NAME_INVALID); return; } } std::string db_newname = newname; CharacterDatabase.escape_string(db_newname); CharacterDatabase.PExecute("UPDATE petition SET name = '%s' WHERE petitionguid = '%u'", db_newname.c_str(), petitionGuid.GetCounter()); DEBUG_LOG("Petition %s renamed to '%s'", petitionGuid.GetString().c_str(), newname.c_str()); WorldPacket data(MSG_PETITION_RENAME, (8 + newname.size() + 1)); data << ObjectGuid(petitionGuid); data << newname; SendPacket(&data); }
void WorldSession::HandleTabardVendorActivateOpcode( WorldPacket & recv_data ) { ObjectGuid guid; recv_data >> guid; Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_TABARDDESIGNER); if (!unit) { DEBUG_LOG("WORLD: HandleTabardVendorActivateOpcode - %s not found or you can't interact with him.", guid.GetString().c_str()); return; } // remove fake death if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); SendTabardVendorActivate(guid); }
void WorldSession::HandlePetitionSignOpcode(WorldPacket& recv_data) { DEBUG_LOG("Received opcode CMSG_PETITION_SIGN"); // ok // recv_data.hexlike(); Field* fields; ObjectGuid petitionGuid; uint8 unk; recv_data >> petitionGuid; // petition guid recv_data >> unk; uint32 petitionLowGuid = petitionGuid.GetCounter(); QueryResult* result = CharacterDatabase.PQuery( "SELECT ownerguid, " " (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs, " " type " "FROM petition WHERE petitionguid = '%u'", petitionLowGuid, petitionLowGuid); if (!result) { sLog.outError("any petition on server..."); return; } fields = result->Fetch(); uint32 ownerLowGuid = fields[0].GetUInt32(); ObjectGuid ownerGuid = ObjectGuid(HIGHGUID_PLAYER, ownerLowGuid); uint8 signs = fields[1].GetUInt8(); uint32 type = fields[2].GetUInt32(); delete result; if (ownerGuid == _player->GetObjectGuid()) return; // not let enemies sign guild charter if (!sWorld.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeam() != sObjectMgr.GetPlayerTeamByGUID(ownerGuid)) { if (type != 9) SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", "", ERR_ARENA_TEAM_NOT_ALLIED); else SendGuildCommandResult(GUILD_CREATE_S, "", ERR_GUILD_NOT_ALLIED); return; } if (type != 9) { if (_player->getLevel() < sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, "", _player->GetName(), ERR_ARENA_TEAM_TARGET_TOO_LOW_S); return; } if (!IsArenaTypeValid(ArenaType(type))) return; uint8 slot = ArenaTeam::GetSlotByType(ArenaType(type)); if (slot >= MAX_ARENA_SLOT) return; if (_player->GetArenaTeamId(slot)) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", _player->GetName(), ERR_ALREADY_IN_ARENA_TEAM_S); return; } if (_player->GetArenaTeamIdInvited()) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", _player->GetName(), ERR_ALREADY_INVITED_TO_ARENA_TEAM_S); return; } } else { if (_player->GetGuildId()) { SendGuildCommandResult(GUILD_INVITE_S, _player->GetName(), ERR_ALREADY_IN_GUILD_S); return; } if (_player->GetGuildIdInvited()) { SendGuildCommandResult(GUILD_INVITE_S, _player->GetName(), ERR_ALREADY_INVITED_TO_GUILD_S); return; } } if (++signs > type) // client signs maximum return; // client doesn't allow to sign petition two times by one character, but not check sign by another character from same account // not allow sign another player from already sign player account result = CharacterDatabase.PQuery("SELECT playerguid FROM petition_sign WHERE player_account = '%u' AND petitionguid = '%u'", GetAccountId(), petitionLowGuid); if (result) { delete result; WorldPacket data(SMSG_PETITION_SIGN_RESULTS, (8 + 8 + 4)); data << ObjectGuid(petitionGuid); data << ObjectGuid(_player->GetObjectGuid()); data << uint32(PETITION_SIGN_ALREADY_SIGNED); // close at signer side SendPacket(&data); // update for owner if online if (Player* owner = sObjectMgr.GetPlayer(ownerGuid)) owner->GetSession()->SendPacket(&data); return; } CharacterDatabase.PExecute("INSERT INTO petition_sign (ownerguid,petitionguid, playerguid, player_account) VALUES ('%u', '%u', '%u','%u')", ownerLowGuid, petitionLowGuid, _player->GetGUIDLow(), GetAccountId()); DEBUG_LOG("PETITION SIGN: %s by %s", petitionGuid.GetString().c_str(), _player->GetGuidStr().c_str()); WorldPacket data(SMSG_PETITION_SIGN_RESULTS, (8 + 8 + 4)); data << ObjectGuid(petitionGuid); data << ObjectGuid(_player->GetObjectGuid()); data << uint32(PETITION_SIGN_OK); // close at signer side SendPacket(&data); // update signs count on charter, required testing... // Item *item = _player->GetItemByGuid(petitionguid)); // if(item) // item->SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1+1, signs); // update for owner if online if (Player* owner = sObjectMgr.GetPlayer(ownerGuid)) owner->GetSession()->SendPacket(&data); }
void WorldSession::HandleBattlemasterJoinOpcode( WorldPacket & recv_data ) { ObjectGuid guid; uint32 bgTypeId_; uint32 instanceId; uint8 joinAsGroup; bool isPremade = false; Group * grp; recv_data >> guid; // battlemaster guid recv_data >> bgTypeId_; // battleground type id (DBC id) recv_data >> instanceId; // instance id, 0 if First Available selected recv_data >> joinAsGroup; // join as group if (!sBattlemasterListStore.LookupEntry(bgTypeId_)) { sLog.outError("Battleground: invalid bgtype (%u) received. possible cheater? player guid %u",bgTypeId_,_player->GetGUIDLow()); return; } BattleGroundTypeId bgTypeId = BattleGroundTypeId(bgTypeId_); DEBUG_LOG( "WORLD: Recvd CMSG_BATTLEMASTER_JOIN Message from %s", guid.GetString().c_str()); // can do this, since it's battleground, not arena BattleGroundQueueTypeId bgQueueTypeId = BattleGroundMgr::BGQueueTypeId(bgTypeId, ARENA_TYPE_NONE); // ignore if player is already in BG if (_player->InBattleGround()) return; Creature *unit = GetPlayer()->GetMap()->GetCreature(guid); if (!unit) return; if (!unit->isBattleMaster()) // it's not battlemaster return; // get bg instance or bg template if instance not found BattleGround *bg = NULL; if (instanceId) bg = sBattleGroundMgr.GetBattleGroundThroughClientInstance(instanceId, bgTypeId); if (!bg && !(bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId))) { sLog.outError("Battleground: no available bg / template found"); return; } BattleGroundBracketId bgBracketId = _player->GetBattleGroundBracketIdFromLevel(bgTypeId); // check queue conditions if (!joinAsGroup) { // check Deserter debuff if (!_player->CanJoinToBattleground()) { WorldPacket data(SMSG_GROUP_JOINED_BATTLEGROUND, 4); data << uint32(0xFFFFFFFE); _player->GetSession()->SendPacket(&data); return; } // check if already in queue if (_player->GetBattleGroundQueueIndex(bgQueueTypeId) < PLAYER_MAX_BATTLEGROUND_QUEUES) //player is already in this queue return; // check if has free queue slots if (!_player->HasFreeBattleGroundQueueId()) return; } else { grp = _player->GetGroup(); // no group found, error if (!grp) return; uint32 err = grp->CanJoinBattleGroundQueue(bgTypeId, bgQueueTypeId, 0, bg->GetMaxPlayersPerTeam(), false, 0); isPremade = sWorld.getConfig(CONFIG_UINT32_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH) && (grp->GetMembersCount() >= bg->GetMinPlayersPerTeam()); if (err != BG_JOIN_ERR_OK) { SendBattleGroundOrArenaJoinError(err); return; } } // if we're here, then the conditions to join a bg are met. We can proceed in joining. // _player->GetGroup() was already checked, grp is already initialized BattleGroundQueue& bgQueue = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId]; if (joinAsGroup) { DEBUG_LOG("Battleground: the following players are joining as group:"); GroupQueueInfo * ginfo = bgQueue.AddGroup(_player, grp, bgTypeId, bgBracketId, ARENA_TYPE_NONE, false, isPremade, 0); uint32 avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, _player->GetBattleGroundBracketIdFromLevel(bgTypeId)); for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next()) { Player *member = itr->getSource(); if(!member) continue; // this should never happen uint32 queueSlot = member->AddBattleGroundQueueId(bgQueueTypeId); // add to queue // store entry point coords (same as leader entry point) member->SetBattleGroundEntryPoint(_player); // send status packet (in queue) WorldPacket data; sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, queueSlot, STATUS_WAIT_QUEUE, avgTime, 0, ginfo->arenaType); member->GetSession()->SendPacket(&data); sBattleGroundMgr.BuildGroupJoinedBattlegroundPacket(&data, bgTypeId); member->GetSession()->SendPacket(&data); DEBUG_LOG("Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,member->GetGUIDLow(), member->GetName()); } DEBUG_LOG("Battleground: group end"); } else { GroupQueueInfo * ginfo = bgQueue.AddGroup(_player, NULL, bgTypeId, bgBracketId, ARENA_TYPE_NONE, false, isPremade, 0); uint32 avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, _player->GetBattleGroundBracketIdFromLevel(bgTypeId)); // already checked if queueSlot is valid, now just get it uint32 queueSlot = _player->AddBattleGroundQueueId(bgQueueTypeId); // store entry point coords _player->SetBattleGroundEntryPoint(); WorldPacket data; // send status packet (in queue) sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, queueSlot, STATUS_WAIT_QUEUE, avgTime, 0, ginfo->arenaType); SendPacket(&data); DEBUG_LOG("Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,_player->GetGUIDLow(), _player->GetName()); } sBattleGroundMgr.ScheduleQueueUpdate(0, ARENA_TYPE_NONE, bgQueueTypeId, bgTypeId, _player->GetBattleGroundBracketIdFromLevel(bgTypeId)); }
void WorldSession::HandleOfferPetitionOpcode(WorldPacket& recv_data) { DEBUG_LOG("Received opcode CMSG_OFFER_PETITION"); // ok // recv_data.hexlike(); ObjectGuid petitionGuid; ObjectGuid playerGuid; uint32 junk; recv_data >> junk; // this is not petition type! recv_data >> petitionGuid; // petition guid recv_data >> playerGuid; // player guid Player* player = ObjectAccessor::FindPlayer(playerGuid); if (!player) return; /// Get petition type and check QueryResult* result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", petitionGuid.GetCounter()); if (!result) return; Field* fields = result->Fetch(); uint32 type = fields[0].GetUInt32(); delete result; DEBUG_LOG("OFFER PETITION: type %u petition %s to %s", type, petitionGuid.GetString().c_str(), playerGuid.GetString().c_str()); if (!sWorld.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeam() != player->GetTeam()) { if (type != 9) SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", "", ERR_ARENA_TEAM_NOT_ALLIED); else SendGuildCommandResult(GUILD_CREATE_S, "", ERR_GUILD_NOT_ALLIED); return; } if (type != 9) { if (player->getLevel() < sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) { // player is too low level to join an arena team SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, "", player->GetName(), ERR_ARENA_TEAM_TARGET_TOO_LOW_S); return; } if (!IsArenaTypeValid(ArenaType(type))) return; uint8 slot = ArenaTeam::GetSlotByType(ArenaType(type)); if (slot >= MAX_ARENA_SLOT) return; if (player->GetArenaTeamId(slot)) { // player is already in an arena team SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, "", player->GetName(), ERR_ALREADY_IN_ARENA_TEAM_S); return; } if (player->GetArenaTeamIdInvited()) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", _player->GetName(), ERR_ALREADY_INVITED_TO_ARENA_TEAM_S); return; } } else { if (player->GetGuildId()) { SendGuildCommandResult(GUILD_INVITE_S, _player->GetName(), ERR_ALREADY_IN_GUILD_S); return; } if (player->GetGuildIdInvited()) { SendGuildCommandResult(GUILD_INVITE_S, _player->GetName(), ERR_ALREADY_INVITED_TO_GUILD_S); return; } } /// Get petition signs count uint8 signs = 0; result = CharacterDatabase.PQuery("SELECT playerguid FROM petition_sign WHERE petitionguid = '%u'", petitionGuid.GetCounter()); // result==nullptr also correct charter without signs if (result) signs = (uint8)result->GetRowCount(); /// Send response WorldPacket data(SMSG_PETITION_SHOW_SIGNATURES, (8 + 8 + 4 + signs + signs * 12)); data << ObjectGuid(petitionGuid); // petition guid data << ObjectGuid(_player->GetObjectGuid()); // owner guid data << uint32(petitionGuid.GetCounter()); // guild guid (in mangos always same as low part of petition guid) data << uint8(signs); // sign's count for (uint8 i = 1; i <= signs; ++i) { Field* fields2 = result->Fetch(); ObjectGuid signerGuid = ObjectGuid(HIGHGUID_PLAYER, fields2[0].GetUInt32()); data << ObjectGuid(signerGuid); // Player GUID data << uint32(0); // there 0 ... result->NextRow(); } delete result; player->GetSession()->SendPacket(&data); }
void WorldSession::HandleSellItemOpcode( WorldPacket & recv_data ) { DEBUG_LOG( "WORLD: Received CMSG_SELL_ITEM" ); ObjectGuid vendorGuid; uint64 itemguid; uint32 count; recv_data >> vendorGuid; recv_data >> itemguid; recv_data >> count; if(!itemguid) return; Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(vendorGuid, UNIT_NPC_FLAG_VENDOR); if (!pCreature) { DEBUG_LOG("WORLD: HandleSellItemOpcode - %s not found or you can't interact with him.", vendorGuid.GetString().c_str()); _player->SendSellError( SELL_ERR_CANT_FIND_VENDOR, NULL, itemguid, 0); return; } // remove fake death if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); Item *pItem = _player->GetItemByGuid( itemguid ); if( pItem ) { // prevent sell not owner item if(_player->GetGUID() != pItem->GetOwnerGUID()) { _player->SendSellError( SELL_ERR_CANT_SELL_ITEM, pCreature, itemguid, 0); return; } // prevent sell non empty bag by drag-and-drop at vendor's item list if(pItem->IsBag() && !((Bag*)pItem)->IsEmpty()) { _player->SendSellError( SELL_ERR_CANT_SELL_ITEM, pCreature, itemguid, 0); return; } // prevent sell currently looted item if(_player->GetLootGUID() == pItem->GetGUID()) { _player->SendSellError( SELL_ERR_CANT_SELL_ITEM, pCreature, itemguid, 0); return; } // special case at auto sell (sell all) if(count == 0) { count = pItem->GetCount(); } else { // prevent sell more items that exist in stack (possible only not from client) if(count > pItem->GetCount()) { _player->SendSellError( SELL_ERR_CANT_SELL_ITEM, pCreature, itemguid, 0); return; } } ItemPrototype const *pProto = pItem->GetProto(); if( pProto ) { if( pProto->SellPrice > 0 ) { if(count < pItem->GetCount()) // need split items { Item *pNewItem = pItem->CloneItem( count, _player ); if (!pNewItem) { sLog.outError("WORLD: HandleSellItemOpcode - could not create clone of item %u; count = %u", pItem->GetEntry(), count ); _player->SendSellError( SELL_ERR_CANT_SELL_ITEM, pCreature, itemguid, 0); return; } pItem->SetCount( pItem->GetCount() - count ); _player->ItemRemovedQuestCheck( pItem->GetEntry(), count ); if( _player->IsInWorld() ) pItem->SendCreateUpdateToPlayer( _player ); pItem->SetState(ITEM_CHANGED, _player); _player->AddItemToBuyBackSlot( pNewItem ); if( _player->IsInWorld() ) pNewItem->SendCreateUpdateToPlayer( _player ); } else { _player->ItemRemovedQuestCheck( pItem->GetEntry(), pItem->GetCount()); _player->RemoveItem( pItem->GetBagSlot(), pItem->GetSlot(), true); pItem->RemoveFromUpdateQueueOf(_player); _player->AddItemToBuyBackSlot( pItem ); } uint32 money = pProto->SellPrice * count; _player->ModifyMoney( money ); _player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_MONEY_FROM_VENDORS, money); } else _player->SendSellError( SELL_ERR_CANT_SELL_ITEM, pCreature, itemguid, 0); return; } } _player->SendSellError( SELL_ERR_CANT_FIND_ITEM, pCreature, itemguid, 0); return; }
void WorldSession::SendPetitionShowList(ObjectGuid guid) { Creature* pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_PETITIONER); if (!pCreature) { DEBUG_LOG("WORLD: HandlePetitionShowListOpcode - %s not found or you can't interact with him.", guid.GetString().c_str()); return; } uint8 count; if (pCreature->isTabardDesigner()) count = 1; else count = 3; WorldPacket data(SMSG_PETITION_SHOWLIST, 8 + 1 + 4 * 6); data << ObjectGuid(guid); // npc guid data << uint8(count); // count if (count == 1) { data << uint32(1); // index data << uint32(GUILD_CHARTER); // charter entry data << uint32(CHARTER_DISPLAY_ID); // charter display id data << uint32(GUILD_CHARTER_COST); // charter cost data << uint32(0); // unknown data << uint32(9); // required signs? } else { // 2v2 data << uint32(1); // index data << uint32(ARENA_TEAM_CHARTER_2v2); // charter entry data << uint32(CHARTER_DISPLAY_ID); // charter display id data << uint32(ARENA_TEAM_CHARTER_2v2_COST); // charter cost data << uint32(2); // unknown data << uint32(2); // required signs? // 3v3 data << uint32(2); // index data << uint32(ARENA_TEAM_CHARTER_3v3); // charter entry data << uint32(CHARTER_DISPLAY_ID); // charter display id data << uint32(ARENA_TEAM_CHARTER_3v3_COST); // charter cost data << uint32(3); // unknown data << uint32(3); // required signs? // 5v5 data << uint32(3); // index data << uint32(ARENA_TEAM_CHARTER_5v5); // charter entry data << uint32(CHARTER_DISPLAY_ID); // charter display id data << uint32(ARENA_TEAM_CHARTER_5v5_COST); // charter cost data << uint32(5); // unknown data << uint32(5); // required signs? } // for(uint8 i = 0; i < count; ++i) //{ // data << uint32(i); // index // data << uint32(GUILD_CHARTER); // charter entry // data << uint32(CHARTER_DISPLAY_ID); // charter display id // data << uint32(GUILD_CHARTER_COST+i); // charter cost // data << uint32(0); // unknown // data << uint32(9); // required signs? //} SendPacket(&data); DEBUG_LOG("Sent SMSG_PETITION_SHOWLIST"); }
void WorldSession::HandleBuybackItem(WorldPacket & recv_data) { DEBUG_LOG( "WORLD: Received CMSG_BUYBACK_ITEM" ); ObjectGuid vendorGuid; uint32 slot; recv_data >> vendorGuid >> slot; Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(vendorGuid, UNIT_NPC_FLAG_VENDOR); if (!pCreature) { DEBUG_LOG("WORLD: HandleBuybackItem - %s not found or you can't interact with him.", vendorGuid.GetString().c_str()); _player->SendSellError( SELL_ERR_CANT_FIND_VENDOR, NULL, 0, 0); return; } // remove fake death if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); Item *pItem = _player->GetItemFromBuyBackSlot( slot ); if( pItem ) { uint32 price = _player->GetUInt32Value( PLAYER_FIELD_BUYBACK_PRICE_1 + slot - BUYBACK_SLOT_START ); if( _player->GetMoney() < price ) { _player->SendBuyError( BUY_ERR_NOT_ENOUGHT_MONEY, pCreature, pItem->GetEntry(), 0); return; } ItemPosCountVec dest; uint8 msg = _player->CanStoreItem( NULL_BAG, NULL_SLOT, dest, pItem, false ); if( msg == EQUIP_ERR_OK ) { _player->ModifyMoney( -(int32)price ); _player->RemoveItemFromBuyBackSlot( slot, false ); _player->ItemAddedQuestCheck( pItem->GetEntry(), pItem->GetCount()); _player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, pItem->GetEntry(), pItem->GetCount()); _player->StoreItem( dest, pItem, true ); } else _player->SendEquipError( msg, pItem, NULL ); return; } else _player->SendBuyError( BUY_ERR_CANT_FIND_ITEM, pCreature, 0, 0); }
void WorldSession::HandleQuestgiverQueryQuestOpcode( WorldPacket & recv_data ) { ObjectGuid guid; uint32 quest; uint8 unk1; recv_data >> guid >> quest >> unk1; DEBUG_LOG("WORLD: Received CMSG_QUESTGIVER_QUERY_QUEST - for %s to %s, quest = %u, unk1 = %u", _player->GetGuidStr().c_str(), guid.GetString().c_str(), quest, unk1); // Verify that the guid is valid and is a questgiver or involved in the requested quest Object* pObject = _player->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_GAMEOBJECT_OR_ITEM); if (!pObject || (!pObject->HasQuest(quest) && !pObject->HasInvolvedQuest(quest))) { _player->PlayerTalkClass->CloseGossip(); return; } if (Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest)) _player->PlayerTalkClass->SendQuestGiverQuestDetails(pQuest, pObject->GetObjectGuid(), true); }
// this void creates new auction and adds auction to some auctionhouse void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data ) { DEBUG_LOG("WORLD: HandleAuctionSellItem"); ObjectGuid auctioneerGuid; uint64 item; uint32 etime, bid, buyout; recv_data >> auctioneerGuid; recv_data >> item; recv_data >> bid; recv_data >> buyout; recv_data >> etime; if (!item || !bid || !etime) return; // check for cheaters Player *pl = GetPlayer(); AuctionHouseEntry const* auctionHouseEntry = GetCheckedAuctionHouseForAuctioneer(auctioneerGuid); if (!auctionHouseEntry) return; // always return pointer AuctionHouseObject* auctionHouse = sAuctionMgr.GetAuctionsMap(auctionHouseEntry); // client send time in minutes, convert to common used sec time etime *= MINUTE; // client understand only 3 auction time switch(etime) { case 1*MIN_AUCTION_TIME: case 2*MIN_AUCTION_TIME: case 4*MIN_AUCTION_TIME: break; default: return; } // remove fake death if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); Item *it = pl->GetItemByGuid( item ); // do not allow to sell already auctioned items if(sAuctionMgr.GetAItem(GUID_LOPART(item))) { sLog.outError("AuctionError, player %s is sending item id: %u, but item is already in another auction", pl->GetName(), GUID_LOPART(item)); SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); return; } // prevent sending bag with items (cheat: can be placed in bag after adding equipped empty bag to auction) if(!it) { SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_ITEM_NOT_FOUND); return; } if(!it->CanBeTraded()) { SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); return; } if ((it->GetProto()->Flags & ITEM_FLAG_CONJURED) || it->GetUInt32Value(ITEM_FIELD_DURATION)) { SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); return; } //we have to take deposit : uint32 deposit = AuctionHouseMgr::GetAuctionDeposit( auctionHouseEntry, etime, it ); if ( pl->GetMoney() < deposit ) { SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_NOT_ENOUGHT_MONEY); return; } if( GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_BOOL_GM_LOG_TRADE) ) { sLog.outCommand(GetAccountId(),"GM %s (Account: %u) create auction: %s (Entry: %u Count: %u)", GetPlayerName(), GetAccountId(), it->GetProto()->Name1, it->GetEntry(), it->GetCount()); } pl->ModifyMoney( -int32(deposit) ); uint32 auction_time = uint32(etime * sWorld.getConfig(CONFIG_FLOAT_RATE_AUCTION_TIME)); AuctionEntry *AH = new AuctionEntry; AH->Id = sObjectMgr.GenerateAuctionID(); AH->item_guidlow = GUID_LOPART(item); AH->item_template = it->GetEntry(); AH->owner = pl->GetGUIDLow(); AH->startbid = bid; AH->bidder = 0; AH->bid = 0; AH->buyout = buyout; AH->expire_time = time(NULL) + auction_time; AH->deposit = deposit; AH->auctionHouseEntry = auctionHouseEntry; DETAIL_LOG("selling item %u to auctioneer %s with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", GUID_LOPART(item), auctioneerGuid.GetString().c_str(), bid, buyout, auction_time, AH->GetHouseId()); auctionHouse->AddAuction(AH); sAuctionMgr.AddAItem(it); pl->MoveItemFromInventory( it->GetBagSlot(), it->GetSlot(), true); CharacterDatabase.BeginTransaction(); it->DeleteFromInventoryDB(); it->SaveToDB(); // recursive and not have transaction guard into self, not in inventiory and can be save standalone AH->SaveToDB(); pl->SaveInventoryAndGoldToDB(); CharacterDatabase.CommitTransaction(); SendAuctionCommandResult(AH->Id, AUCTION_SELL_ITEM, AUCTION_OK); }
void WorldSession::HandleQuestgiverRequestRewardOpcode( WorldPacket & recv_data ) { uint32 quest; ObjectGuid guid; recv_data >> guid >> quest; if (!CanInteractWithQuestGiver(guid, "CMSG_QUESTGIVER_REQUEST_REWARD")) return; DEBUG_LOG("WORLD: Received CMSG_QUESTGIVER_REQUEST_REWARD - for %s to %s, quest = %u", _player->GetGuidStr().c_str(), guid.GetString().c_str(), quest); Object* pObject = _player->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_OR_GAMEOBJECT); if (!pObject||!pObject->HasInvolvedQuest(quest)) return; if (_player->CanCompleteQuest(quest)) _player->CompleteQuest(quest); if (_player->GetQuestStatus(quest) != QUEST_STATUS_COMPLETE) return; if (Quest const *pQuest = sObjectMgr.GetQuestTemplate(quest)) _player->PlayerTalkClass->SendQuestGiverOfferReward(pQuest, guid, true); }
// void called when player click on auctioneer npc void WorldSession::HandleAuctionHelloOpcode( WorldPacket & recv_data ) { ObjectGuid auctioneerGuid; // NPC guid recv_data >> auctioneerGuid; Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(auctioneerGuid, UNIT_NPC_FLAG_AUCTIONEER); if (!unit) { DEBUG_LOG("WORLD: HandleAuctionHelloOpcode - %s not found or you can't interact with him.", auctioneerGuid.GetString().c_str()); return; } // remove fake death if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); SendAuctionHello(unit); }
void WorldSession::HandleQuestgiverCompleteQuest(WorldPacket& recv_data) { uint32 quest; ObjectGuid guid; recv_data >> guid >> quest; if (!CanInteractWithQuestGiver(guid, "CMSG_QUESTGIVER_COMPLETE_QUEST")) return; // All ok, continue DEBUG_LOG("WORLD: Received CMSG_QUESTGIVER_COMPLETE_QUEST - for %s to %s, quest = %u", _player->GetGuidStr().c_str(), guid.GetString().c_str(), quest); if (Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest)) { if (_player->GetQuestStatus(quest) != QUEST_STATUS_COMPLETE) { if (pQuest->IsRepeatable()) _player->PlayerTalkClass->SendQuestGiverRequestItems(pQuest, guid, _player->CanCompleteRepeatableQuest(pQuest), false); else _player->PlayerTalkClass->SendQuestGiverRequestItems(pQuest, guid, _player->CanRewardQuest(pQuest, false), false); } else { if (pQuest->GetReqItemsCount()) // some items required _player->PlayerTalkClass->SendQuestGiverRequestItems(pQuest, guid, _player->CanRewardQuest(pQuest,false), false); else // no items required _player->PlayerTalkClass->SendQuestGiverOfferReward(pQuest, guid, true); } } }
void WorldSession::HandleGetMirrorimageData(WorldPacket& recv_data) { ObjectGuid guid; uint32 displayId; recv_data >> guid >> displayId; Creature* pCreature = _player->GetMap()->GetAnyTypeCreature(guid); if (!pCreature) return; Unit::AuraList const& images = pCreature->GetAurasByType(SPELL_AURA_MIRROR_IMAGE); if (images.empty()) return; Unit* pCaster = images.front()->GetCaster(); DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "WorldSession::HandleGetMirrorimageData CMSG_GET_MIRRORIMAGE_DATA creature %s aura %u caster %s", guid.GetString().c_str(), images.front()->GetId(), pCaster ? pCaster->GetObjectGuid().GetString().c_str() : "<none>"); WorldPacket data(SMSG_MIRRORIMAGE_DATA, 68); data << guid; data << (uint32)pCreature->GetDisplayId(); data << (uint8)pCreature->getRace(); data << (uint8)pCreature->getGender(); data << (uint8)pCreature->getClass(); if (pCaster && pCaster->GetTypeId() == TYPEID_PLAYER) { Player* pPlayer = (Player*)pCaster; // skin, face, hair, haircolor data << (uint8)pPlayer->GetByteValue(PLAYER_BYTES, 0); data << (uint8)pPlayer->GetByteValue(PLAYER_BYTES, 1); data << (uint8)pPlayer->GetByteValue(PLAYER_BYTES, 2); data << (uint8)pPlayer->GetByteValue(PLAYER_BYTES, 3); // facial hair data << (uint8)pPlayer->GetByteValue(PLAYER_BYTES_2, 0); // guild guid data << pPlayer->GetGuildGuid(); if (pPlayer->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_HIDE_HELM)) data << (uint32)0; else data << (uint32)pPlayer->GetItemDisplayIdInSlot(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_HEAD); data << (uint32)pPlayer->GetItemDisplayIdInSlot(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_SHOULDERS); data << (uint32)pPlayer->GetItemDisplayIdInSlot(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_BODY); data << (uint32)pPlayer->GetItemDisplayIdInSlot(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_CHEST); data << (uint32)pPlayer->GetItemDisplayIdInSlot(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_WAIST); data << (uint32)pPlayer->GetItemDisplayIdInSlot(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_LEGS); data << (uint32)pPlayer->GetItemDisplayIdInSlot(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_FEET); data << (uint32)pPlayer->GetItemDisplayIdInSlot(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_WRISTS); data << (uint32)pPlayer->GetItemDisplayIdInSlot(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_HANDS); if (pPlayer->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_HIDE_CLOAK)) data << (uint32)0; else data << (uint32)pPlayer->GetItemDisplayIdInSlot(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_BACK); data << (uint32)pPlayer->GetItemDisplayIdInSlot(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_TABARD); } else { // pCaster may have been NULL (usually not expected, but may happen at disconnect, etc) // OR // pCaster is not player, data is taken from CreatureDisplayInfoExtraEntry by model already data << (uint8)0; data << (uint8)0; data << (uint8)0; data << (uint8)0; data << (uint8)0; data << ObjectGuid(); for (int i = 0; i < 11; ++i) data << (uint32)0; } SendPacket(&data); }
void WorldSession::HandleQuestgiverHelloOpcode(WorldPacket & recv_data) { ObjectGuid guid; recv_data >> guid; DEBUG_LOG("WORLD: Received CMSG_QUESTGIVER_HELLO - for %s to %s", _player->GetGuidStr().c_str(), guid.GetString().c_str()); Creature* pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_NONE); if (!pCreature) { DEBUG_LOG ("WORLD: HandleQuestgiverHelloOpcode - for %s to %s not found or you can't interact with him.", _player->GetGuidStr().c_str(), guid.GetString().c_str()); return; } // remove fake death if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); // Stop the npc if moving if (!pCreature->IsStopped()) pCreature->StopMoving(); if (sScriptMgr.OnGossipHello(_player, pCreature)) return; _player->PrepareGossipMenu(pCreature, pCreature->GetCreatureInfo()->GossipMenuId); _player->SendPreparedGossip(pCreature); }
void WorldSession::HandlePetCastSpellOpcode(WorldPacket& recvPacket) { DETAIL_LOG("WORLD: CMSG_PET_CAST_SPELL"); ObjectGuid guid; uint32 spellid; recvPacket >> guid >> spellid; DEBUG_LOG("WORLD: CMSG_PET_CAST_SPELL, %s, spellid %u", guid.GetString().c_str(), spellid); Creature* pet = _player->GetMap()->GetAnyTypeCreature(guid); if (!pet || (guid != _player->GetPetGuid() && guid != _player->GetCharmGuid())) { sLog.outError("HandlePetCastSpellOpcode: %s isn't pet of %s .", guid.GetString().c_str(), GetPlayer()->GetGuidStr().c_str()); return; } SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid); if (!spellInfo) { sLog.outError("WORLD: unknown PET spell id %i", spellid); return; } if (pet->GetCharmInfo() && pet->GetCharmInfo()->GetGlobalCooldownMgr().HasGlobalCooldown(spellInfo)) return; // do not cast not learned spells if (!pet->HasSpell(spellid) || IsPassiveSpell(spellInfo)) return; SpellCastTargets targets; recvPacket >> targets.ReadForCaster(pet); pet->clearUnitState(UNIT_STAT_MOVING); Spell* spell = new Spell(pet, spellInfo, false); spell->m_targets = targets; SpellCastResult result = spell->CheckPetCast(NULL); if (result == SPELL_CAST_OK) { pet->AddCreatureSpellCooldown(spellid); if (pet->IsPet()) { ((Pet*)pet)->CheckLearning(spellid); // 10% chance to play special pet attack talk, else growl // actually this only seems to happen on special spells, fire shield for imp, torment for voidwalker, but it's stupid to check every spell if (((Pet*)pet)->getPetType() == SUMMON_PET && (urand(0, 100) < 10)) pet->SendPetTalk((uint32)PET_TALK_SPECIAL_SPELL); else pet->SendPetAIReaction(); } spell->prepare(&(spell->m_targets)); } else { pet->SendPetCastFail(spellid, result); if (!pet->HasSpellCooldown(spellid)) GetPlayer()->SendClearCooldown(spellid, pet); spell->finish(false); delete spell; } }