rbac::RBACPermission const* AccountMgr::GetRBACPermission(uint32 permissionId) const { TC_LOG_TRACE("rbac", "AccountMgr::GetRBACPermission: %u", permissionId); rbac::RBACPermissionsContainer::const_iterator it = _permissions.find(permissionId); if (it != _permissions.end()) return it->second; return NULL; }
/// Logging helper for unexpected opcodes void WorldSession::LogUnprocessedTail(WorldPacket* packet) { if (!sLog->ShouldLog(LOG_FILTER_OPCODES, LOG_LEVEL_TRACE) || packet->rpos() >= packet->wpos()) return; TC_LOG_TRACE(LOG_FILTER_OPCODES, "Unprocessed tail data (read stop at %u from %u) Opcode %s from %s", uint32(packet->rpos()), uint32(packet->wpos()), GetOpcodeNameForLogging(packet->GetOpcode()).c_str(), GetPlayerInfo().c_str()); packet->print_storage(); }
RBACPermission const* AccountMgr::GetRBACPermission(uint32 permissionId) const { TC_LOG_TRACE(LOG_FILTER_RBAC, "AccountMgr::GetRBACPermission: roleId: %u", permissionId); RBACPermissionsContainer::const_iterator it = _permissions.find(permissionId); if (it != _permissions.end()) return it->second; return NULL; }
RBACRole const* AccountMgr::GetRBACRole(uint32 roleId) const { TC_LOG_TRACE(LOG_FILTER_RBAC, "AccountMgr::GetRBACRole: roleId: %u", roleId); RBACRolesContainer::const_iterator it = _roles.find(roleId); if (it != _roles.end()) return it->second; return NULL; }
RBACGroup const* AccountMgr::GetRBACGroup(uint32 groupId) const { TC_LOG_TRACE(LOG_FILTER_RBAC, "AccountMgr::GetRBACGroup: groupId: %u", groupId); RBACGroupsContainer::const_iterator it = _groups.find(groupId); if (it != _groups.end()) return it->second; return NULL; }
void process_message(struct soap* soap_message) { TC_LOG_TRACE("network.soap", "SOAPWorkingThread::process_message"); soap_serve(soap_message); soap_destroy(soap_message); // dealloc C++ data soap_end(soap_message); // dealloc data and clean up soap_done(soap_message); // detach soap struct free(soap_message); }
RBACCommandResult RBACData::DenyPermission(uint32 permissionId, int32 realmId /* = 0*/) { // Check if permission Id exists RBACPermission const* perm = sAccountMgr->GetRBACPermission(permissionId); if (!perm) { TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission does not exists", GetId(), GetName().c_str(), permissionId, realmId); return RBAC_ID_DOES_NOT_EXISTS; } // Check if already added in granted list if (HasGrantedPermission(permissionId)) { TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission in grant list", GetId(), GetName().c_str(), permissionId, realmId); return RBAC_IN_GRANTED_LIST; } // Already added? if (HasDeniedPermission(permissionId)) { TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission already denied", GetId(), GetName().c_str(), permissionId, realmId); return RBAC_CANT_ADD_ALREADY_ADDED; } AddDeniedPermission(permissionId); // Do not save to db when loading data from DB (realmId = 0) if (realmId) { TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok and DB updated", GetId(), GetName().c_str(), permissionId, realmId); SavePermission(permissionId, false, realmId); CalculateNewPermissions(); } else TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok", GetId(), GetName().c_str(), permissionId, realmId); return RBAC_OK; }
RBACCommandResult RBACData::DenyRole(uint32 roleId, int32 realmId /* = 0*/) { // Check if role Id exists RBACRole const* role = sAccountMgr->GetRBACRole(roleId); if (!role) { TC_LOG_TRACE(LOG_FILTER_RBAC, "RBACData::DenyRole [Id: %u Name: %s] (Role %u, RealmId %d). Role does not exists", GetId(), GetName().c_str(), roleId, realmId); return RBAC_ID_DOES_NOT_EXISTS; } // Check if already added in granted list if (_grantedRoles.find(roleId) != _grantedRoles.end()) { TC_LOG_TRACE(LOG_FILTER_RBAC, "RBACData::DenyRole [Id: %u Name: %s] (Role %u, RealmId %d). Role in grant list", GetId(), GetName().c_str(), roleId, realmId); return RBAC_IN_GRANTED_LIST; } // Already added? std::pair<std::set<uint32>::iterator, bool> ret = _deniedRoles.insert(roleId); if (!ret.second) { TC_LOG_TRACE(LOG_FILTER_RBAC, "RBACData::DenyRole [Id: %u Name: %s] (Role %u, RealmId %d). Role already denied", GetId(), GetName().c_str(), roleId, realmId); return RBAC_CANT_ADD_ALREADY_ADDED; } // Do not save to db when loading data from DB (realmId = 0) if (realmId) { TC_LOG_TRACE(LOG_FILTER_RBAC, "RBACData::DenyRole [Id: %u Name: %s] (Role %u, RealmId %d). Ok and DB updated", GetId(), GetName().c_str(), roleId, realmId); SaveRole(roleId, false, realmId); CalculateNewPermissions(); } else TC_LOG_TRACE(LOG_FILTER_RBAC, "RBACData::DenyRole [Id: %u Name: %s] (Role %u, RealmId %d). Ok", GetId(), GetName().c_str(), roleId, realmId); return RBAC_OK; }
void RBACData::CalculateNewPermissions() { TC_LOG_TRACE("rbac", "RBACData::CalculateNewPermissions [Id: %u Name: %s]", GetId(), GetName().c_str()); // Get the list of granted permissions _globalPerms = GetGrantedPermissions(); ExpandPermissions(_globalPerms); RBACPermissionContainer revoked = GetDeniedPermissions(); ExpandPermissions(revoked); RemovePermissions(_globalPerms, revoked); }
void RBACRole::RevokePermission(uint32 permissionId) { if (permissionId < RBAC_PERM_MAX) { TC_LOG_TRACE(LOG_FILTER_RBAC, "RBACRole::RevokePermission (Role %u, Permission %u). Ok", GetId(), permissionId); _perms.reset(permissionId); } else TC_LOG_ERROR(LOG_FILTER_RBAC, "RBACRole::RevokePermission (Role %u, Permission %u). Permission not lower than %u", GetId(), permissionId, RBAC_PERM_MAX); }
void Battlenet::Session::Start() { std::string ip_address = GetRemoteIpAddress().to_string(); TC_LOG_TRACE("session", "Accepted connection from %s", ip_address.c_str()); PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_INFO); stmt->setString(0, ip_address); stmt->setUInt32(1, inet_addr(ip_address.c_str())); _queryCallback = std::bind(&Battlenet::Session::CheckIpCallback, this, std::placeholders::_1); _queryFuture = LoginDatabase.AsyncQuery(stmt); }
RBACCommandResult RBACData::AddGroup(uint32 groupId, int32 realmId /* = 0 */) { // Check if group Id exists RBACGroup const* group = sAccountMgr->GetRBACGroup(groupId); if (!group) { TC_LOG_TRACE(LOG_FILTER_RBAC, "RBACData::AddGroup [Id: %u Name: %s] (Group %u, RealmId %d). Group does not exists", GetId(), GetName().c_str(), groupId, realmId); return RBAC_ID_DOES_NOT_EXISTS; } // Already added? std::pair<std::set<uint32>::iterator, bool> ret = _groups.insert(groupId); if (!ret.second) { TC_LOG_TRACE(LOG_FILTER_RBAC, "RBACData::AddGroup [Id: %u Name: %s] (Group %u, RealmId %d). Group Already added", GetId(), GetName().c_str(), groupId, realmId); return RBAC_CANT_ADD_ALREADY_ADDED; } // Do not save to db when loading data from DB (realmId = 0) if (realmId) { TC_LOG_TRACE(LOG_FILTER_RBAC, "RBACData::AddGroup [Id: %u Name: %s] (Group %u, RealmId %d). Added and DB updated", GetId(), GetName().c_str(), groupId, realmId); PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_RBAC_ACCOUNT_GROUP); stmt->setUInt32(0, GetId()); stmt->setUInt32(1, groupId); stmt->setInt32(2, realmId); LoginDatabase.Execute(stmt); CalculateNewPermissions(); } else TC_LOG_TRACE(LOG_FILTER_RBAC, "RBACData::AddGroup [Id: %u Name: %s] (Group %u, RealmId %d). Added", GetId(), GetName().c_str(), groupId, realmId); return RBAC_OK; }
void ByteBuffer::print_storage() const { if (!sLog->ShouldLog("network", LOG_LEVEL_TRACE)) // optimize disabled trace output return; std::ostringstream o; o << "STORAGE_SIZE: " << size(); for (uint32 i = 0; i < size(); ++i) o << read<uint8>(i) << " - "; o << " "; TC_LOG_TRACE("network", "%s", o.str().c_str()); }
void Battlenet::Session::Start() { std::string ip_address = GetRemoteIpAddress().to_string(); TC_LOG_TRACE("session", "%s Accepted connection", GetClientInfo().c_str()); // Verify that this IP is not in the ip_banned table LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS)); PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_INFO); stmt->setString(0, ip_address); stmt->setUInt32(1, inet_addr(ip_address.c_str())); _queryProcessor.AddQuery(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&Battlenet::Session::CheckIpCallback, this, std::placeholders::_1))); }
void BuildPlayerLockDungeonBlock(WorldPacket& data, lfg::LfgLockMap const& lock) { data << uint32(lock.size()); // Size of lock dungeons for (lfg::LfgLockMap::const_iterator it = lock.begin(); it != lock.end(); ++it) { TC_LOG_TRACE("lfg", "BuildPlayerLockDungeonBlock:: DungeonID: %u Lock status: %u Required itemLevel: %u Current itemLevel: %f", (it->first & 0x00FFFFFF), it->second.lockStatus, it->second.requiredItemLevel, it->second.currentItemLevel); data << uint32(it->first); // Dungeon entry (id + type) data << uint32(it->second.lockStatus); // Lock status data << uint32(it->second.requiredItemLevel); // Required itemLevel data << uint32(it->second.currentItemLevel); // Current itemLevel } }
void LFGQueue::UpdateQueueTimers(uint8 queueId, time_t currTime) { TC_LOG_TRACE("lfg.queue.timers.update", "Updating queue timers..."); for (LfgQueueDataContainer::iterator itQueue = QueueDataStore.begin(); itQueue != QueueDataStore.end(); ++itQueue) { LfgQueueData& queueinfo = itQueue->second; uint32 dungeonId = (*queueinfo.dungeons.begin()); uint32 queuedTime = uint32(currTime - queueinfo.joinTime); uint8 role = PLAYER_ROLE_NONE; int32 waitTime = -1; int32 wtTank = waitTimesTankStore[dungeonId].time; int32 wtHealer = waitTimesHealerStore[dungeonId].time; int32 wtDps = waitTimesDpsStore[dungeonId].time; int32 wtAvg = waitTimesAvgStore[dungeonId].time; for (LfgRolesMap::const_iterator itPlayer = queueinfo.roles.begin(); itPlayer != queueinfo.roles.end(); ++itPlayer) role |= itPlayer->second; role &= ~PLAYER_ROLE_LEADER; switch (role) { case PLAYER_ROLE_NONE: // Should not happen - just in case waitTime = -1; break; case PLAYER_ROLE_TANK: waitTime = wtTank; break; case PLAYER_ROLE_HEALER: waitTime = wtHealer; break; case PLAYER_ROLE_DAMAGE: waitTime = wtDps; break; default: waitTime = wtAvg; break; } if (queueinfo.bestCompatible.empty()) FindBestCompatibleInQueue(itQueue); LfgQueueStatusData queueData(queueId, dungeonId, queueinfo.joinTime, waitTime, wtAvg, wtTank, wtHealer, wtDps, queuedTime, queueinfo.tanks, queueinfo.healers, queueinfo.dps); for (LfgRolesMap::const_iterator itPlayer = queueinfo.roles.begin(); itPlayer != queueinfo.roles.end(); ++itPlayer) { uint64 pguid = itPlayer->first; LFGMgr::SendLfgQueueStatus(pguid, queueData); } } }
bool QuestObjectiveCriteriaMgr::CanUpdateCriteriaTree(Criteria const* criteria, CriteriaTree const* tree, Player* referencePlayer) const { QuestObjective const* objective = tree->QuestObjective; if (!objective) return false; if (HasCompletedObjective(objective)) { TC_LOG_TRACE("criteria.quest", "QuestObjectiveCriteriaMgr::CanUpdateCriteriaTree: (Id: %u Type %s Quest Objective %u) Objective already completed", criteria->ID, CriteriaMgr::GetCriteriaTypeString(criteria->Entry->Type), objective->ID); return false; } return CriteriaHandler::CanUpdateCriteriaTree(criteria, tree, referencePlayer); }
void ByteBuffer::textlike() const { if (!sLog->ShouldLog("network", LOG_LEVEL_TRACE)) // optimize disabled trace output return; std::ostringstream o; o << "STORAGE_SIZE: " << size(); for (uint32 i = 0; i < size(); ++i) { char buf[2]; snprintf(buf, 2, "%c", read<uint8>(i)); o << buf; } o << " "; TC_LOG_TRACE("network", "%s", o.str().c_str()); }
void Battlenet::Session::Start() { std::string ip_address = GetRemoteIpAddress().to_string(); TC_LOG_TRACE("session", "Accepted connection from %s", ip_address.c_str()); if (_queryCallback) { Authentication::LogonResponse* logonResponse = new Authentication::LogonResponse(); logonResponse->SetAuthResult(AUTH_LOGON_TOO_FAST); AsyncWrite(logonResponse); TC_LOG_DEBUG("session", "[Session::Start] %s attempted to log too quick after previous attempt!", GetClientInfo().c_str()); return; } // Verify that this IP is not in the ip_banned table LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS)); PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_INFO); stmt->setString(0, ip_address); stmt->setUInt32(1, inet_addr(ip_address.c_str())); _queryCallback = std::bind(&Battlenet::Session::CheckIpCallback, this, std::placeholders::_1); _queryFuture = LoginDatabase.AsyncQuery(stmt); }
void WorldSession::SendLfgJoinResult(lfg::LfgJoinResultData const& joinData) { uint32 size = 0; ObjectGuid guid = GetPlayer()->GetGUID(); uint32 queueId = sLFGMgr->GetQueueId(_player->GetGUID()); for (lfg::LfgLockPartyMap::const_iterator it = joinData.lockmap.begin(); it != joinData.lockmap.end(); ++it) size += 8 + 4 + uint32(it->second.size()) * (4 + 4 + 4 + 4); TC_LOG_DEBUG("lfg", "SMSG_LFG_JOIN_RESULT %s checkResult: %u checkValue: %u", GetPlayerInfo().c_str(), joinData.result, joinData.state); WorldPacket data(SMSG_LFG_JOIN_RESULT, 4 + 4 + size); data << uint32(3); data << uint8(joinData.result); // Check Result data << uint32(queueId); // Queue Id data << uint8(joinData.state); // Check Value data << uint32(time(NULL)); // Join date data.WriteBit(guid[2]); data.WriteBit(guid[7]); data.WriteBit(guid[3]); data.WriteBit(guid[0]); data.WriteBits(joinData.lockmap.size(), 24); for (lfg::LfgLockPartyMap::const_iterator it = joinData.lockmap.begin(); it != joinData.lockmap.end(); ++it) { ObjectGuid playerGuid = it->first; data.WriteBit(playerGuid[7]); data.WriteBit(playerGuid[5]); data.WriteBit(playerGuid[3]); data.WriteBit(playerGuid[6]); data.WriteBit(playerGuid[0]); data.WriteBit(playerGuid[2]); data.WriteBit(playerGuid[4]); data.WriteBit(playerGuid[1]); data.WriteBits(it->second.size(), 22); } data.WriteBit(guid[4]); data.WriteBit(guid[5]); data.WriteBit(guid[1]); data.WriteBit(guid[6]); for (lfg::LfgLockPartyMap::const_iterator it = joinData.lockmap.begin(); it != joinData.lockmap.end(); ++it) { ObjectGuid playerGuid = it->first; for (lfg::LfgLockMap::const_iterator itr = it->second.begin(); itr != it->second.end(); ++itr) { TC_LOG_TRACE("lfg", "SendLfgJoinResult:: PlayerGUID: " UI64FMTD " DungeonID: %u Lock status: %u Required itemLevel: %u Current itemLevel: %f", uint64(playerGuid), (itr->first & 0x00FFFFFF), itr->second.lockStatus, itr->second.requiredItemLevel, itr->second.currentItemLevel); data << uint32(itr->second.lockStatus); // Lock status data << uint32(itr->second.currentItemLevel); // Current itemLevel data << uint32(itr->second.requiredItemLevel); // Required itemLevel data << uint32(itr->first); // Dungeon entry (id + type) } data.WriteByteSeq(playerGuid[2]); data.WriteByteSeq(playerGuid[5]); data.WriteByteSeq(playerGuid[1]); data.WriteByteSeq(playerGuid[0]); data.WriteByteSeq(playerGuid[4]); data.WriteByteSeq(playerGuid[3]); data.WriteByteSeq(playerGuid[6]); data.WriteByteSeq(playerGuid[7]); } data.WriteByteSeq(guid[1]); data.WriteByteSeq(guid[4]); data.WriteByteSeq(guid[3]); data.WriteByteSeq(guid[5]); data.WriteByteSeq(guid[0]); data.WriteByteSeq(guid[7]); data.WriteByteSeq(guid[2]); data.WriteByteSeq(guid[6]); SendPacket(&data); }
void RealmList::UpdateRealms(boost::system::error_code const& error) { if (error) return; TC_LOG_DEBUG("realmlist", "Updating Realm List..."); PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_REALMLIST); PreparedQueryResult result = LoginDatabase.Query(stmt); // Circle through results and add them to the realm map if (result) { do { try { boost::asio::ip::tcp::resolver::iterator end; Field* fields = result->Fetch(); std::string name = fields[1].GetString(); boost::asio::ip::tcp::resolver::query externalAddressQuery(ip::tcp::v4(), fields[2].GetString(), ""); boost::system::error_code ec; boost::asio::ip::tcp::resolver::iterator endPoint = _resolver->resolve(externalAddressQuery, ec); if (endPoint == end || ec) { TC_LOG_ERROR("realmlist", "Could not resolve address %s", fields[2].GetString().c_str()); continue; } ip::address externalAddress = (*endPoint).endpoint().address(); boost::asio::ip::tcp::resolver::query localAddressQuery(ip::tcp::v4(), fields[3].GetString(), ""); endPoint = _resolver->resolve(localAddressQuery, ec); if (endPoint == end || ec) { TC_LOG_ERROR("realmlist", "Could not resolve address %s", fields[3].GetString().c_str()); continue; } ip::address localAddress = (*endPoint).endpoint().address(); boost::asio::ip::tcp::resolver::query localSubmaskQuery(ip::tcp::v4(), fields[4].GetString(), ""); endPoint = _resolver->resolve(localSubmaskQuery, ec); if (endPoint == end || ec) { TC_LOG_ERROR("realmlist", "Could not resolve address %s", fields[4].GetString().c_str()); continue; } ip::address localSubmask = (*endPoint).endpoint().address(); uint16 port = fields[5].GetUInt16(); uint8 icon = fields[6].GetUInt8(); RealmFlags flag = RealmFlags(fields[7].GetUInt8()); uint8 timezone = fields[8].GetUInt8(); uint8 allowedSecurityLevel = fields[9].GetUInt8(); float pop = fields[10].GetFloat(); uint32 realmId = fields[0].GetUInt32(); uint32 build = fields[11].GetUInt32(); uint8 region = fields[12].GetUInt8(); uint8 battlegroup = fields[13].GetUInt8(); Battlenet::RealmId id{ region, battlegroup, realmId, build }; UpdateRealm(id, name, externalAddress, localAddress, localSubmask, port, icon, flag, timezone, (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop); TC_LOG_TRACE("realmlist", "Realm \"%s\" at %s:%u.", name.c_str(), externalAddress.to_string().c_str(), port); } catch (std::exception& ex) { TC_LOG_ERROR("realmlist", "Realmlist::UpdateRealms has thrown an exception: %s", ex.what()); ASSERT(false); } } while (result->NextRow()); } std::vector<Realm const*> updatedRealms; std::vector<Battlenet::RealmId> deletedRealms; for (RealmMap::value_type& pair : _realms) { if (pair.second.Updated) updatedRealms.push_back(&pair.second); else if (!pair.second.Keep) deletedRealms.push_back(pair.first); pair.second.Updated = false; pair.second.Keep = false; } for (Battlenet::RealmId const& deleted : deletedRealms) _realms.erase(deleted); if (!updatedRealms.empty() || !deletedRealms.empty()) { sSessionMgr.LockedForEach([&updatedRealms, &deletedRealms](Battlenet::Session* session) { if (session->IsSubscribedToRealmListUpdates()) session->UpdateRealms(updatedRealms, deletedRealms); }); } if (_updateInterval) { _updateTimer->expires_from_now(boost::posix_time::seconds(_updateInterval)); _updateTimer->async_wait(std::bind(&RealmList::UpdateRealms, this, std::placeholders::_1)); } }
void PetAI::UpdateAI(uint32 diff) { if (!me->IsAlive() || !me->GetCharmInfo()) return; Unit* owner = me->GetCharmerOrOwner(); if (_updateAlliesTimer <= diff) // UpdateAllies self set update timer UpdateAllies(); else _updateAlliesTimer -= diff; if (me->GetVictim() && me->EnsureVictim()->IsAlive()) { // is only necessary to stop casting, the pet must not exit combat if (!me->GetCurrentSpell(CURRENT_CHANNELED_SPELL) && // ignore channeled spells (Pin, Seduction) me->EnsureVictim()->HasBreakableByDamageCrowdControlAura(me)) { me->InterruptNonMeleeSpells(false); return; } if (NeedToStop()) { TC_LOG_TRACE("scripts.ai.petai", "PetAI::UpdateAI: AI stopped attacking %s", me->GetGUID().ToString().c_str()); StopAttack(); return; } // Check before attacking to prevent pets from leaving stay position if (me->GetCharmInfo()->HasCommandState(COMMAND_STAY)) { if (me->GetCharmInfo()->IsCommandAttack() || (me->GetCharmInfo()->IsAtStay() && me->IsWithinMeleeRange(me->GetVictim()))) DoMeleeAttackIfReady(); } else DoMeleeAttackIfReady(); } else { if (me->HasReactState(REACT_AGGRESSIVE) || me->GetCharmInfo()->IsAtStay()) { // Every update we need to check targets only in certain cases // Aggressive - Allow auto select if owner or pet don't have a target // Stay - Only pick from pet or owner targets / attackers so targets won't run by // while chasing our owner. Don't do auto select. // All other cases (ie: defensive) - Targets are assigned by DamageTaken(), OwnerAttackedBy(), OwnerAttacked(), etc. Unit* nextTarget = SelectNextTarget(me->HasReactState(REACT_AGGRESSIVE)); if (nextTarget) AttackStart(nextTarget); else HandleReturnMovement(); } else HandleReturnMovement(); } // Autocast (cast only in combat or persistent spells in any state) if (!me->HasUnitState(UNIT_STATE_CASTING)) { TargetSpellList targetSpellStore; for (uint8 i = 0; i < me->GetPetAutoSpellSize(); ++i) { uint32 spellID = me->GetPetAutoSpellOnPos(i); if (!spellID) continue; SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellID); if (!spellInfo) continue; if (me->GetSpellHistory()->HasGlobalCooldown(spellInfo)) continue; // check spell cooldown if (!me->GetSpellHistory()->IsReady(spellInfo)) continue; if (spellInfo->IsPositive()) { if (spellInfo->CanBeUsedInCombat()) { // Check if we're in combat or commanded to attack if (!me->IsInCombat() && !me->GetCharmInfo()->IsCommandAttack()) continue; } Spell* spell = new Spell(me, spellInfo, TRIGGERED_NONE); bool spellUsed = false; // Some spells can target enemy or friendly (DK Ghoul's Leap) // Check for enemy first (pet then owner) Unit* target = me->getAttackerForHelper(); if (!target && owner) target = owner->getAttackerForHelper(); if (target) { if (CanAttack(target) && spell->CanAutoCast(target)) { targetSpellStore.push_back(std::make_pair(target, spell)); spellUsed = true; } } if (spellInfo->HasEffect(SPELL_EFFECT_JUMP_DEST)) { if (!spellUsed) delete spell; continue; // Pets must only jump to target } // No enemy, check friendly if (!spellUsed) { for (GuidSet::const_iterator tar = _allySet.begin(); tar != _allySet.end(); ++tar) { Unit* ally = ObjectAccessor::GetUnit(*me, *tar); //only buff targets that are in combat, unless the spell can only be cast while out of combat if (!ally) continue; if (spell->CanAutoCast(ally)) { targetSpellStore.push_back(std::make_pair(ally, spell)); spellUsed = true; break; } } } // No valid targets at all if (!spellUsed) delete spell; } else if (me->GetVictim() && CanAttack(me->GetVictim()) && spellInfo->CanBeUsedInCombat()) { Spell* spell = new Spell(me, spellInfo, TRIGGERED_NONE); if (spell->CanAutoCast(me->GetVictim())) targetSpellStore.push_back(std::make_pair(me->GetVictim(), spell)); else delete spell; } } // found units to cast on to if (!targetSpellStore.empty()) { TargetSpellList::iterator it = targetSpellStore.begin(); std::advance(it, urand(0, targetSpellStore.size() - 1)); Spell* spell = (*it).second; Unit* target = (*it).first; targetSpellStore.erase(it); SpellCastTargets targets; targets.SetUnitTarget(target); spell->prepare(targets); } // deleted cached Spell objects for (TargetSpellList::const_iterator itr = targetSpellStore.begin(); itr != targetSpellStore.end(); ++itr) delete itr->second; } // Update speed as needed to prevent dropping too far behind and despawning me->UpdateSpeed(MOVE_RUN); me->UpdateSpeed(MOVE_WALK); me->UpdateSpeed(MOVE_FLIGHT); }
int WorldSocket::SendPacket(WorldPacket const& pct) { ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1); if (closing_) return -1; // Dump outgoing packet if (sPacketLog->CanLogPacket()) sPacketLog->LogPacket(pct, SERVER_TO_CLIENT); WorldPacket const* pkt = &pct; // Empty buffer used in case packet should be compressed // Disable compression for now :) /* WorldPacket buff; if (m_Session && pkt->size() > 0x400) { buff.Compress(m_Session->GetCompressionStream(), pkt); pkt = &buff; }*/ if (m_Session) TC_LOG_TRACE("network.opcode", "S->C: %s %s", m_Session->GetPlayerInfo().c_str(), GetOpcodeNameForLogging(pkt->GetOpcode()).c_str()); sScriptMgr->OnPacketSend(this, *pkt); ServerPktHeader header(!m_Crypt.IsInitialized() ? pkt->size() + 2 : pct.size(), pkt->GetOpcode(), &m_Crypt); if (m_OutBuffer->space() >= pkt->size() + header.getHeaderLength() && msg_queue()->is_empty()) { // Put the packet on the buffer. if (m_OutBuffer->copy((char*) header.header, header.getHeaderLength()) == -1) ACE_ASSERT (false); if (!pkt->empty()) if (m_OutBuffer->copy((char*) pkt->contents(), pkt->size()) == -1) ACE_ASSERT (false); } else { // Enqueue the packet. ACE_Message_Block* mb; ACE_NEW_RETURN(mb, ACE_Message_Block(pkt->size() + header.getHeaderLength()), -1); mb->copy((char*) header.header, header.getHeaderLength()); if (!pkt->empty()) mb->copy((const char*)pkt->contents(), pkt->size()); if (msg_queue()->enqueue_tail(mb, (ACE_Time_Value*)&ACE_Time_Value::zero) == -1) { TC_LOG_ERROR("network", "WorldSocket::SendPacket enqueue_tail failed"); mb->release(); return -1; } } return 0; }
rbac::RBACPermissionContainer const& AccountMgr::GetRBACDefaultPermissions(uint8 secLevel) { TC_LOG_TRACE("rbac", "AccountMgr::GetRBACDefaultPermissions: secLevel %u - size: %u", secLevel, uint32(_defaultPermissions[secLevel].size())); return _defaultPermissions[secLevel]; }
static int CreateChildProcess(T waiter, std::string const& executable, std::vector<std::string> const& args, std::string const& logger, std::string const& input, bool secure) { auto outPipe = create_pipe(); auto errPipe = create_pipe(); Optional<file_descriptor_source> inputSource; if (!secure) { TC_LOG_TRACE(logger, "Starting process \"%s\" with arguments: \"%s\".", executable.c_str(), boost::algorithm::join(args, " ").c_str()); } // Start the child process child c = [&] { if (!input.empty()) { inputSource = file_descriptor_source(input); // With binding stdin return execute(run_exe(boost::filesystem::absolute(executable)), set_args(args), inherit_env(), bind_stdin(*inputSource), bind_stdout(file_descriptor_sink(outPipe.sink, close_handle)), bind_stderr(file_descriptor_sink(errPipe.sink, close_handle))); } else { // Without binding stdin return execute(run_exe(boost::filesystem::absolute(executable)), set_args(args), inherit_env(), bind_stdout(file_descriptor_sink(outPipe.sink, close_handle)), bind_stderr(file_descriptor_sink(errPipe.sink, close_handle))); } }(); file_descriptor_source outFd(outPipe.source, close_handle); file_descriptor_source errFd(errPipe.source, close_handle); auto outInfo = MakeTCLogSink([&](std::string msg) { TC_LOG_INFO(logger, "%s", msg.c_str()); }); auto outError = MakeTCLogSink([&](std::string msg) { TC_LOG_ERROR(logger, "%s", msg.c_str()); }); copy(outFd, outInfo); copy(errFd, outError); // Call the waiter in the current scope to prevent // the streams from closing too early on leaving the scope. int const result = waiter(c); if (!secure) { TC_LOG_TRACE(logger, ">> Process \"%s\" finished with return value %i.", executable.c_str(), result); } if (inputSource) inputSource->close(); return result; }
void Battlenet::Session::Start() { TC_LOG_TRACE("session", "Accepted connection from %s", GetRemoteIpAddress().to_string().c_str()); AsyncRead(); }
void RBACGroup::RevokeRole(uint32 roleId) { TC_LOG_TRACE(LOG_FILTER_RBAC, "RBACRole::GrantPermission (Role %u, Permission %u). Ok", GetId(), roleId); _roles.erase(roleId); }