public world_messages.EnterRoomResult EnterRoom(WorldSession session, string id, out string[] players) { Room room = rooms.Find(x => x.Id == id); if (room != null) { playerRoomDict[session.SessionID] = room; lock (room) { return room.AddPlayer(session.SessionID, out players); } } players = null; return world_messages.EnterRoomResult.RoomNotExists; }
public Room CreateRoom(WorldSession session, int capacity) { Room ret = Room.Create(session.SessionID, capacity); rooms.Add(ret); return ret; }
static bool HandleCharacterChangeAccountCommand(StringArguments args, CommandHandler handler) { string playerNameStr; string accountName; handler.extractOptFirstArg(args, out playerNameStr, out accountName); if (accountName.IsEmpty()) { return(false); } ObjectGuid targetGuid; string targetName; Player playerNotUsed; if (!handler.extractPlayerTarget(new StringArguments(playerNameStr), out playerNotUsed, out targetGuid, out targetName)) { return(false); } CharacterInfo characterInfo = Global.WorldMgr.GetCharacterInfo(targetGuid); if (characterInfo == null) { handler.SendSysMessage(CypherStrings.PlayerNotFound); return(false); } uint oldAccountId = characterInfo.AccountId; uint newAccountId = oldAccountId; PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ID_BY_NAME); stmt.AddValue(0, accountName); SQLResult result = DB.Login.Query(stmt); if (!result.IsEmpty()) { newAccountId = result.Read <uint>(0); } else { handler.SendSysMessage(CypherStrings.AccountNotExist, accountName); return(false); } // nothing to do :) if (newAccountId == oldAccountId) { return(true); } uint charCount = Global.AccountMgr.GetCharactersCount(newAccountId); if (charCount != 0) { if (charCount >= WorldConfig.GetIntValue(WorldCfg.CharactersPerRealm)) { handler.SendSysMessage(CypherStrings.AccountCharacterListFull, accountName, newAccountId); return(false); } } stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ACCOUNT_BY_GUID); stmt.AddValue(0, newAccountId); stmt.AddValue(1, targetGuid.GetCounter()); DB.Characters.DirectExecute(stmt); Global.WorldMgr.UpdateRealmCharCount(oldAccountId); Global.WorldMgr.UpdateRealmCharCount(newAccountId); Global.WorldMgr.UpdateCharacterInfoAccount(targetGuid, newAccountId); handler.SendSysMessage(CypherStrings.ChangeAccountSuccess, targetName, accountName); string logString = $"changed ownership of player {targetName} ({targetGuid.ToString()}) from account {oldAccountId} to account {newAccountId}"; WorldSession session = handler.GetSession(); if (session != null) { Player player = session.GetPlayer(); if (player != null) { Log.outCommand(session.GetAccountId(), $"GM {player.GetName()} (Account: {session.GetAccountId()}) {logString}"); } } else { Log.outCommand(0, $"{handler.GetCypherString(CypherStrings.Console)} {logString}"); } return(true); }
private static void SendStoreFinalise(WorldSession session) { session.EnqueueMessageEncrypted(new ServerStoreFinalise()); }
public CollectionMgr(WorldSession owner) { _owner = owner; _appearances = new BitSet(0); }
public void LogPacket(WorldSession session) { Log.outDebug(LogFilter.Network, "Received ClientOpcode: {0} From: {1}", GetOpcode(), session != null ? session.GetPlayerInfo() : "Unknown IP"); }
public static void HandleHousingEditMode(WorldSession session, ClientHousingEditMode housingEditMode) { }
public static void HandleHolomarkUpdate(WorldSession session, ClientGuildHolomarkUpdate guildHolomarkUpdate) { session.Player.GuildManager.UpdateHolomark(guildHolomarkUpdate.LeftHidden, guildHolomarkUpdate.RightHidden, guildHolomarkUpdate.BackHidden, guildHolomarkUpdate.DistanceNear); }
public static void HandleCharacterSelect(WorldSession session, ClientCharacterSelect characterSelect) { CharacterModel character = session.Characters.SingleOrDefault(c => c.Id == characterSelect.CharacterId); if (character == null) { session.EnqueueMessageEncrypted(new ServerCharacterSelectFail { Result = CharacterSelectResult.Failed }); return; } if (PlayerCleanupManager.HasPendingCleanup(session.Account)) { session.EnqueueMessageEncrypted(new ServerCharacterSelectFail { Result = CharacterSelectResult.FailedCharacterInWorld }); return; } session.Player = new Player(session, character); WorldEntry entry = GameTableManager.Instance.World.GetEntry(character.WorldId); if (entry == null) { throw new ArgumentOutOfRangeException(); } switch ((MapType)entry.Type) { case MapType.Residence: case MapType.Community: { // characters logging in to a housing map are returned to their own residence Residence residence = session.Player.ResidenceManager.Residence; residence ??= GlobalResidenceManager.Instance.CreateResidence(session.Player); ResidenceEntrance entrance = GlobalResidenceManager.Instance.GetResidenceEntrance(residence.PropertyInfoId); session.Player.Rotation = entrance.Rotation.ToEulerDegrees(); MapManager.Instance.AddToMap(session.Player, new MapPosition { Info = new MapInfo { Entry = entrance.Entry, InstanceId = residence.Parent?.Id ?? residence.Id }, Position = entrance.Position }); break; } default: { session.Player.Rotation = new Vector3(character.RotationX, character.RotationY, character.RotationZ); MapManager.Instance.AddToMap(session.Player, new MapPosition { Info = new MapInfo { Entry = entry }, Position = new Vector3(character.LocationX, character.LocationY, character.LocationZ) }); break; } } }
public static void HandleCharacterDelete(WorldSession session, ClientCharacterDelete characterDelete) { CharacterModel characterToDelete = session.Characters.FirstOrDefault(c => c.Id == characterDelete.CharacterId); (CharacterModifyResult, uint) GetResult() { if (characterToDelete == null) { return(CharacterModifyResult.DeleteFailed, 0); } // TODO: Not sure if this is definitely the case, but put it in for good measure if (characterToDelete.Mail.Count > 0) { foreach (CharacterMailModel characterMail in characterToDelete.Mail) { if (characterMail.Attachment.Count > 0) { return(CharacterModifyResult.DeleteFailed, 0); } } } uint leaderCount = (uint)GlobalGuildManager.Instance.GetCharacterGuilds(characterToDelete.Id) .Count(g => g.LeaderId == characterDelete.CharacterId); if (leaderCount > 0) { return(CharacterModifyResult.DeleteFailed, leaderCount); } return(CharacterModifyResult.DeleteOk, 0); } (CharacterModifyResult result, uint data)deleteCheck = GetResult(); if (deleteCheck.result != CharacterModifyResult.DeleteOk) { session.EnqueueMessageEncrypted(new ServerCharacterDeleteResult { Result = deleteCheck.result, Data = deleteCheck.data }); return; } session.CanProcessPackets = false; void Save(CharacterContext context) { var model = new CharacterModel { Id = characterToDelete.Id }; EntityEntry <CharacterModel> entity = context.Attach(model); model.DeleteTime = DateTime.UtcNow; entity.Property(e => e.DeleteTime).IsModified = true; model.OriginalName = characterToDelete.Name; entity.Property(e => e.OriginalName).IsModified = true; model.Name = null; entity.Property(e => e.Name).IsModified = true; } session.Events.EnqueueEvent(new TaskEvent(DatabaseManager.Instance.CharacterDatabase.Save(Save), () => { session.CanProcessPackets = true; GlobalResidenceManager.Instance.RemoveResidence(characterToDelete.Name); CharacterManager.Instance.DeleteCharacter(characterToDelete.Id, characterToDelete.Name); session.EnqueueMessageEncrypted(new ServerCharacterDeleteResult { Result = deleteCheck.result }); })); }
public static void HandleCharacterCreate(WorldSession session, ClientCharacterCreate characterCreate) { CharacterModifyResult?GetResult() { // TODO: validate name and path if (DatabaseManager.Instance.CharacterDatabase.CharacterNameExists(characterCreate.Name)) { return(CharacterModifyResult.CreateFailed_UniqueName); } CharacterCreationEntry creationEntry = GameTableManager.Instance.CharacterCreation.GetEntry(characterCreate.CharacterCreationId); if (creationEntry == null) { return(CharacterModifyResult.CreateFailed_Internal); } if ((CharacterCreationStart)creationEntry.CharacterCreationStartEnum == CharacterCreationStart.Level50 && !session.AccountCurrencyManager.CanAfford(AccountCurrencyType.MaxLevelToken, 1ul)) { return(CharacterModifyResult.CreateFailed_InsufficientFunds); } return(null); } try { CharacterModifyResult?result = GetResult(); if (result.HasValue) { session.EnqueueMessageEncrypted(new ServerCharacterCreate { Result = result.Value }); return; } CharacterCreationEntry creationEntry = GameTableManager.Instance.CharacterCreation.GetEntry(characterCreate.CharacterCreationId); if (creationEntry == null) { throw new InvalidPacketValueException(); } if (creationEntry.EntitlementIdRequired != 0u) { // TODO: Aurin engineer has this } var character = new CharacterModel { AccountId = session.Account.Id, Id = AssetManager.Instance.NextCharacterId, Name = characterCreate.Name, Race = (byte)creationEntry.RaceId, Sex = (byte)creationEntry.Sex, Class = (byte)creationEntry.ClassId, FactionId = (ushort)creationEntry.FactionId, ActivePath = characterCreate.Path, TotalXp = creationEntry.Xp }; uint startingLevel = GameTableManager.Instance.XpPerLevel.Entries.First(l => l.MinXpForLevel >= creationEntry.Xp).Id; for (Path path = Path.Soldier; path <= Path.Explorer; path++) { character.Path.Add(new CharacterPathModel { Path = (byte)path, Unlocked = Convert.ToByte(characterCreate.Path == (byte)path) }); } // merge seperate label and value lists into a single dictonary Dictionary <uint, uint> customisations = characterCreate.Labels .Zip(characterCreate.Values, (l, v) => new { l, v }) .ToDictionary(p => p.l, p => p.v); foreach ((uint label, uint value) in customisations) { character.Customisation.Add(new CharacterCustomisationModel { Label = label, Value = value }); CharacterCustomizationEntry entry = GetCharacterCustomisation(customisations, creationEntry.RaceId, creationEntry.Sex, label, value); if (entry == null) { continue; } character.Appearance.Add(new CharacterAppearanceModel { Slot = (byte)entry.ItemSlotId, DisplayId = (ushort)entry.ItemDisplayId }); } for (int i = 0; i < characterCreate.Bones.Count; ++i) { character.Bone.Add(new CharacterBoneModel { BoneIndex = (byte)(i), Bone = characterCreate.Bones[i] }); } Location startingLocation = AssetManager.Instance.GetStartingLocation((Race)creationEntry.RaceId, (Faction)creationEntry.FactionId, (CharacterCreationStart)creationEntry.CharacterCreationStartEnum); if (startingLocation == null) { throw new ArgumentNullException(nameof(startingLocation)); } character.LocationX = startingLocation.Position.X; character.LocationY = startingLocation.Position.Y; character.LocationZ = startingLocation.Position.Z; character.WorldId = (ushort)startingLocation.World.Id; character.ActiveSpec = 0; // create initial LAS abilities UILocation location = 0; foreach (SpellLevelEntry spellLevelEntry in GameTableManager.Instance.SpellLevel.Entries .Where(s => s.ClassId == character.Class && s.CharacterLevel == 1)) { Spell4Entry spell4Entry = GameTableManager.Instance.Spell4.GetEntry(spellLevelEntry.Spell4Id); if (spell4Entry == null) { continue; } character.Spell.Add(new CharacterSpellModel { Id = character.Id, Spell4BaseId = spell4Entry.Spell4BaseIdBaseSpell, Tier = 1 }); character.ActionSetShortcut.Add(new CharacterActionSetShortcutModel { Id = character.Id, SpecIndex = 0, Location = (ushort)location, ShortcutType = (byte)ShortcutType.Spell, ObjectId = spell4Entry.Spell4BaseIdBaseSpell, Tier = 1 }); location++; } // create a temporary inventory to create starting gear var inventory = new Inventory(character.Id, creationEntry); IEnumerable <Item> items = inventory .SelectMany(b => b) .Select(i => i); //TODO: handle starting stats per class/race character.Stat.Add(new CharacterStatModel { Id = character.Id, Stat = (byte)Stat.Health, Value = 800 }); character.Stat.Add(new CharacterStatModel { Id = character.Id, Stat = (byte)Stat.Dash, Value = 200 }); character.Stat.Add(new CharacterStatModel { Id = character.Id, Stat = (byte)Stat.Level, Value = startingLevel }); character.Stat.Add(new CharacterStatModel { Id = character.Id, Stat = (byte)Stat.StandState, Value = 3 }); character.Stat.Add(new CharacterStatModel { Id = character.Id, Stat = (byte)Stat.Sheathed, Value = 1 }); // TODO: actually error check this session.Events.EnqueueEvent(new TaskEvent(DatabaseManager.Instance.CharacterDatabase.Save(c => { c.Character.Add(character); foreach (Item item in items) { item.Save(c); } }), () => { session.Characters.Add(character); if ((CharacterCreationStart)creationEntry.CharacterCreationStartEnum == CharacterCreationStart.Level50) { session.AccountCurrencyManager.CurrencySubtractAmount(AccountCurrencyType.MaxLevelToken, 1u); } session.EnqueueMessageEncrypted(new ServerCharacterCreate { CharacterId = character.Id, WorldId = character.WorldId, Result = CharacterModifyResult.CreateOk }); })); } catch { session.EnqueueMessageEncrypted(new ServerCharacterCreate { Result = CharacterModifyResult.CreateFailed }); throw; } CharacterCustomizationEntry GetCharacterCustomisation(Dictionary <uint, uint> customisations, uint race, uint sex, uint primaryLabel, uint primaryValue) { ImmutableList <CharacterCustomizationEntry> entries = AssetManager.Instance.GetPrimaryCharacterCustomisation(race, sex, primaryLabel, primaryValue); if (entries == null) { return(null); } if (entries.Count == 1) { return(entries[0]); } // customisation has multiple results, filter with secondary label and value uint secondaryLabel = entries.First(e => e.CharacterCustomizationLabelId01 != 0).CharacterCustomizationLabelId01; uint secondaryValue = customisations[secondaryLabel]; CharacterCustomizationEntry entry = entries.SingleOrDefault(e => e.CharacterCustomizationLabelId01 == secondaryLabel && e.Value01 == secondaryValue); return(entry ?? entries.Single(e => e.CharacterCustomizationLabelId01 == 0 && e.Value01 == 0)); } }
public static void HandleCharacterList(WorldSession session, ClientCharacterList characterList) { session.Events.EnqueueEvent(new TaskGenericEvent <List <CharacterModel> >(DatabaseManager.Instance.CharacterDatabase.GetCharacters(session.Account.Id), characters => { byte maxCharacterLevelAchieved = 1; session.Characters.Clear(); session.Characters.AddRange(characters); session.AccountCurrencyManager.SendCharacterListPacket(); session.GenericUnlockManager.SendUnlockList(); session.EnqueueMessageEncrypted(new ServerAccountEntitlements { Entitlements = session.EntitlementManager.GetAccountEntitlements() .Select(e => new ServerAccountEntitlements.AccountEntitlementInfo { Entitlement = e.Type, Count = e.Amount }) .ToList() }); session.EnqueueMessageEncrypted(new ServerAccountTier { Tier = session.AccountTier }); // 2 is just a fail safe for the minimum amount of character slots // this is set in the tbl files so a value should always exist uint characterSlots = (uint)(session.EntitlementManager.GetRewardProperty(RewardPropertyType.CharacterSlots).GetValue(0u) ?? 2u); uint characterCount = (uint)characters.Count(c => c.DeleteTime == null); var serverCharacterList = new ServerCharacterList { RealmId = WorldServer.RealmId, // no longer used as replaced by entitlements but retail server still used to send this AdditionalCount = characterCount, AdditionalAllowedCharCreations = (uint)Math.Max(0, (int)(characterSlots - characterCount)), // Free Level 50 needs(?) support. It appears to have just been a custom flag on the account that was consume when used up. // FreeLevel50 = true }; foreach (CharacterModel character in characters.Where(c => c.DeleteTime == null)) { var listCharacter = new ServerCharacterList.Character { Id = character.Id, Name = character.Name, Sex = (Sex)character.Sex, Race = (Race)character.Race, Class = (Class)character.Class, Faction = character.FactionId, Level = character.Level, WorldId = character.WorldId, WorldZoneId = character.WorldZoneId, RealmId = WorldServer.RealmId, Path = (byte)character.ActivePath, LastLoggedOutDays = (float)DateTime.UtcNow.Subtract(character.LastOnline ?? DateTime.UtcNow).TotalDays * -1f }; maxCharacterLevelAchieved = Math.Max(maxCharacterLevelAchieved, character.Level); try { // create a temporary Inventory and CostumeManager to show equipped gear var inventory = new Inventory(null, character); var costumeManager = new CostumeManager(null, session.Account, character); CostumeEntity costume = null; if (character.ActiveCostumeIndex >= 0) { costume = costumeManager.GetCostume((byte)character.ActiveCostumeIndex); } listCharacter.GearMask = costume?.Mask ?? 0xFFFFFFFF; foreach (ItemVisual itemVisual in inventory.GetItemVisuals(costume)) { listCharacter.Gear.Add(itemVisual); } foreach (CharacterAppearanceModel appearance in character.Appearance) { listCharacter.Appearance.Add(new ItemVisual { Slot = (ItemSlot)appearance.Slot, DisplayId = appearance.DisplayId }); } /*foreach (CharacterCustomisation customisation in character.CharacterCustomisation) * { * listCharacter.Labels.Add(customisation.Label); * listCharacter.Values.Add(customisation.Value); * }*/ foreach (CharacterBoneModel bone in character.Bone.OrderBy(bone => bone.BoneIndex)) { listCharacter.Bones.Add(bone.Bone); } foreach (CharacterStatModel stat in character.Stat) { if ((Stat)stat.Stat == Stat.Level) { listCharacter.Level = (uint)stat.Value; break; } } serverCharacterList.Characters.Add(listCharacter); } catch (Exception ex) { log.Fatal(ex, $"An error has occured while loading character '{character.Name}'"); continue; } } session.EnqueueMessageEncrypted(new ServerMaxCharacterLevelAchieved { Level = maxCharacterLevelAchieved }); session.EnqueueMessageEncrypted(serverCharacterList); })); }
public static void HandleHousingCommunityPlacement(WorldSession session, ClientHousingCommunityPlacement housingCommunityPlacement) { if (session.Player.Map is not ResidenceMapInstance) { throw new InvalidPacketValueException(); } Community community = session.Player.GuildManager.GetGuild <Community>(GuildType.Community); if (community?.Residence == null) { throw new InvalidPacketValueException(); } ResidenceEntrance entrance = GlobalResidenceManager.Instance.GetResidenceEntrance((PropertyInfoId)(housingCommunityPlacement.PropertyIndex + 100)); if (entrance == null) { throw new InvalidPacketValueException(); } Residence residence = session.Player.ResidenceManager.Residence; if (residence == null) { throw new InvalidPacketValueException(); } if (residence.Parent != null) { if (community.Residence.GetChild(session.Player.CharacterId) == null) { throw new InvalidPacketValueException(); } // for residences on a community just remove the residence // any players on the map at the time can stay in the instance if (residence.Map != null) { residence.Map.RemoveChild(residence); } else { residence.Parent.RemoveChild(residence); } session.Player.Rotation = entrance.Rotation.ToEulerDegrees(); session.Player.TeleportTo(entrance.Entry, entrance.Position, community.Residence.Id); } else { // move owner to new instance only if not on the same instance as the residence // otherwise they will be moved to the new instance during the unload if (residence.Map != session.Player.Map) { session.Player.Rotation = entrance.Rotation.ToEulerDegrees(); session.Player.TeleportTo(entrance.Entry, entrance.Position, community.Residence.Id); } // for individual residences remove the entire instance // move any players on the map at the time to the community residence.Map?.Unload(new MapPosition { Info = new MapInfo { Entry = entrance.Entry, InstanceId = community.Residence.Id, }, Position = entrance.Position }); } // update residence with new plot location and add to community residence.PropertyInfoId = (PropertyInfoId)(housingCommunityPlacement.PropertyIndex + 100); if (community.Residence.Map != null) { community.Residence.Map.AddChild(residence, true); } else { community.Residence.AddChild(residence, true); } }
public static void HandleHousingCommunityDonate(WorldSession session, ClientHousingCommunityDonate housingCommunityDonate) { // can only donate to a community from a residence map if (session.Player.Map is not ResidenceMapInstance) { throw new InvalidPacketValueException(); } Residence residence = session.Player.ResidenceManager.Residence; if (residence == null) { throw new InvalidPacketValueException(); } Community community = session.Player.GuildManager.GetGuild <Community>(GuildType.Community); if (community?.Residence == null) { throw new InvalidPacketValueException(); } foreach (DecorInfo decorInfo in housingCommunityDonate.Decor) { Decor decor = residence.GetDecor(decorInfo.DecorId); if (decor == null) { throw new InvalidPacketValueException(); } if (decor.Type != DecorType.Crate) { throw new InvalidPacketValueException(); } // copy decor to recipient residence if (community.Residence.Map != null) { community.Residence.Map.DecorCopy(community.Residence, decor); } else { community.Residence.DecorCopy(decor); } // remove decor from donor residence if (residence.Map != null) { residence.Map.DecorDelete(residence, decor); } else { if (decor.PendingCreate) { residence.DecorRemove(decor); } else { decor.EnqueueDelete(); } } } }
public static void HandleHousingCommunityRename(WorldSession session, ClientHousingCommunityRename housingCommunityRename) { if (session.Player.Map is not ResidenceMapInstance) { throw new InvalidPacketValueException(); } // ignore the value in the packet Community community = session.Player.GuildManager.GetGuild <Community>(GuildType.Community); if (community == null) { throw new InvalidPacketValueException(); } HousingResult GetResult() { // client checks if the player has a rank of 0, this is the same if (community.LeaderId != session.Player.CharacterId) { return(HousingResult.InvalidPermissions); } if (!TextFilterManager.Instance.IsTextValid(housingCommunityRename.Name) || !TextFilterManager.Instance.IsTextValid(housingCommunityRename.Name, UserText.HousingResidenceName)) { return(HousingResult.InvalidResidenceName); } GameFormulaEntry entry = GameTableManager.Instance.GameFormula.GetEntry(2395); if (entry == null) { return(HousingResult.Failed); } bool canAfford; if (housingCommunityRename.AlternativeCurrency) { canAfford = session.Player.CurrencyManager.CanAfford(CurrencyType.Renown, entry.Dataint01); } else { canAfford = session.Player.CurrencyManager.CanAfford(CurrencyType.Credits, entry.Dataint0); } if (!canAfford) { return(HousingResult.InsufficientFunds); } return(HousingResult.Success); } HousingResult result = GetResult(); if (result == HousingResult.Success) { // fun fact: 2395 is the final game formula entry GameFormulaEntry entry = GameTableManager.Instance.GameFormula.GetEntry(2395); if (housingCommunityRename.AlternativeCurrency) { session.Player.CurrencyManager.CurrencySubtractAmount(CurrencyType.Renown, entry.Dataint01); } else { session.Player.CurrencyManager.CurrencySubtractAmount(CurrencyType.Credits, entry.Dataint0); } community.RenameGuild(housingCommunityRename.Name); community.Residence.Map?.RenameResidence(community.Residence, housingCommunityRename.Name); } session.EnqueueMessageEncrypted(new ServerHousingCommunityRename { Result = HousingResult.Success, TargetGuild = new TargetGuild { RealmId = WorldServer.RealmId, GuildId = community.Id } }); }
public static void HandleHousingVisit(WorldSession session, ClientHousingVisit housingVisit) { if (!(session.Player.Map is ResidenceMapInstance)) { throw new InvalidPacketValueException(); } if (!session.Player.CanTeleport()) { return; } Residence residence; if (!string.IsNullOrEmpty(housingVisit.TargetResidenceName)) { residence = GlobalResidenceManager.Instance.GetResidenceByOwner(housingVisit.TargetResidenceName); } else if (!string.IsNullOrEmpty(housingVisit.TargetCommunityName)) { residence = GlobalResidenceManager.Instance.GetCommunityByOwner(housingVisit.TargetCommunityName); } else if (housingVisit.TargetResidence.ResidenceId != 0ul) { residence = GlobalResidenceManager.Instance.GetResidence(housingVisit.TargetResidence.ResidenceId); } else if (housingVisit.TargetCommunity.NeighbourhoodId != 0ul) { ulong residenceId = GlobalGuildManager.Instance.GetGuild <Community>(housingVisit.TargetCommunity.NeighbourhoodId)?.Residence?.Id ?? 0ul; residence = GlobalResidenceManager.Instance.GetResidence(residenceId); } else { throw new NotImplementedException(); } if (residence == null) { //session.Player.SendGenericError(); // TODO: show error return; } switch (residence.PrivacyLevel) { case ResidencePrivacyLevel.Private: { // TODO: show error return; } // TODO: check if player is either a neighbour or roommate case ResidencePrivacyLevel.NeighborsOnly: break; case ResidencePrivacyLevel.RoommatesOnly: break; } // teleport player to correct residence instance ResidenceEntrance entrance = GlobalResidenceManager.Instance.GetResidenceEntrance(residence.PropertyInfoId); session.Player.Rotation = entrance.Rotation.ToEulerDegrees(); session.Player.TeleportTo(new MapPosition { Info = new MapInfo { Entry = entrance.Entry, InstanceId = residence.Parent?.Id ?? residence.Id }, Position = entrance.Position }); }
public static void HandleDBQueryBulk(DBQueryBulk req, WorldSession session) { //2DO }
public static void HandleLogoutConfirm(WorldSession session, ClientLogoutConfirm logoutConfirm) { session.Player.LogoutFinish(); }
public static void HandleOperation(WorldSession session, ClientGuildOperation clientGuildOperation) { GlobalGuildManager.Instance.HandleGuildOperation(session.Player, clientGuildOperation); }
public static void HandleTitleSet(WorldSession session, ClientTitleSet request) { session.Player.TitleManager.ActiveTitleId = request.TitleId; }
public static void HandleHousingPlugUpdate(WorldSession session, ClientHousingPlugUpdate housingPlugUpdate) { // TODO }
public static void HandleClientTarget(WorldSession session, ClientEntitySelect target) { session.Player.TargetGuid = target.Guid; }
public void LogPacket(WorldSession session) { Log.outDebug(LogFilter.Network, "Sent ServerOpcode: {0} To: {1}", GetOpcode(), session != null ? session.GetPlayerInfo() : ""); }
public static void HandleReplayLevel(WorldSession session, ClientReplayLevelUp request) { session.Player.CastSpell(53378, (byte)(request.Level - 1), new SpellParameters()); }
/// <summary> /// This method is used to send the current Store Catalog to the <see cref="WorldSession"/> /// </summary> public static void HandleCatalogRequest(WorldSession session) { SendStoreCategories(session); SendStoreOffers(session); SendStoreFinalise(session); }
private void OnWorldPort(WorldSession session, PacketReader reader) { session.SendPacket(session.Player.PacketBuilder.BuildOwnCharacterPacket()); }
public void ActivateTalentGroup(ChrSpecializationRecord spec) { if (GetActiveTalentGroup() == spec.OrderIndex) { return; } if (IsNonMeleeSpellCast(false)) { InterruptNonMeleeSpells(false); } SQLTransaction trans = new SQLTransaction(); _SaveActions(trans); DB.Characters.CommitTransaction(trans); // TO-DO: We need more research to know what happens with warlock's reagent Pet pet = GetPet(); if (pet) { RemovePet(pet, PetSaveMode.NotInSlot); } ClearAllReactives(); UnsummonAllTotems(); ExitVehicle(); RemoveAllControlled(); // remove single target auras at other targets var scAuras = GetSingleCastAuras(); foreach (var aura in scAuras) { if (aura.GetUnitOwner() != this) { aura.Remove(); } } // Let client clear his current Actions SendActionButtons(2); foreach (var talentInfo in CliDB.TalentStorage.Values) { // unlearn only talents for character class // some spell learned by one class as normal spells or know at creation but another class learn it as talent, // to prevent unexpected lost normal learned spell skip another class talents if (talentInfo.ClassID != (int)GetClass()) { continue; } if (talentInfo.SpellID == 0) { continue; } SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(talentInfo.SpellID); if (spellInfo == null) { continue; } RemoveSpell(talentInfo.SpellID, true); // search for spells that the talent teaches and unlearn them foreach (SpellEffectInfo effect in spellInfo.GetEffectsForDifficulty(Difficulty.None)) { if (effect != null && effect.TriggerSpell > 0 && effect.Effect == SpellEffectName.LearnSpell) { RemoveSpell(effect.TriggerSpell, true); } } if (talentInfo.OverridesSpellID != 0) { RemoveOverrideSpell(talentInfo.OverridesSpellID, talentInfo.SpellID); } } foreach (var talentInfo in CliDB.PvpTalentStorage.Values) { SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(talentInfo.SpellID); if (spellInfo == null) { continue; } RemoveSpell(talentInfo.SpellID, true); // search for spells that the talent teaches and unlearn them foreach (SpellEffectInfo effect in spellInfo.GetEffectsForDifficulty(Difficulty.None)) { if (effect != null && effect.TriggerSpell > 0 && effect.Effect == SpellEffectName.LearnSpell) { RemoveSpell(effect.TriggerSpell, true); } } if (talentInfo.OverridesSpellID != 0) { RemoveOverrideSpell(talentInfo.OverridesSpellID, talentInfo.SpellID); } } // Remove spec specific spells RemoveSpecializationSpells(); foreach (uint glyphId in GetGlyphs(GetActiveTalentGroup())) { RemoveAurasDueToSpell(CliDB.GlyphPropertiesStorage.LookupByKey(glyphId).SpellID); } SetActiveTalentGroup(spec.OrderIndex); SetPrimarySpecialization(spec.Id); foreach (var talentInfo in CliDB.TalentStorage.Values) { // learn only talents for character class if (talentInfo.ClassID != (int)GetClass()) { continue; } if (talentInfo.SpellID == 0) { continue; } if (HasTalent(talentInfo.Id, GetActiveTalentGroup())) { LearnSpell(talentInfo.SpellID, false); // add the talent to the PlayerSpellMap if (talentInfo.OverridesSpellID != 0) { AddOverrideSpell(talentInfo.OverridesSpellID, talentInfo.SpellID); } } } for (byte slot = 0; slot < PlayerConst.MaxPvpTalentSlots; ++slot) { PvpTalentRecord talentInfo = CliDB.PvpTalentStorage.LookupByKey(GetPvpTalentMap(GetActiveTalentGroup())[slot]); if (talentInfo == null) { continue; } if (talentInfo.SpellID == 0) { continue; } AddPvpTalent(talentInfo, GetActiveTalentGroup(), slot); } LearnSpecializationSpells(); if (CanUseMastery()) { for (uint i = 0; i < PlayerConst.MaxMasterySpells; ++i) { uint mastery = spec.MasterySpellID[i]; if (mastery != 0) { LearnSpell(mastery, false); } } } InitTalentForLevel(); PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARACTER_ACTIONS_SPEC); stmt.AddValue(0, GetGUID().GetCounter()); stmt.AddValue(1, GetActiveTalentGroup()); WorldSession mySess = GetSession(); mySess.GetQueryProcessor().AddCallback(DB.Characters.AsyncQuery(stmt).WithCallback(result => { // in case player logs out before db response (player would be deleted in that case) Player thisPlayer = mySess.GetPlayer(); if (thisPlayer != null) { thisPlayer.LoadActions(result); } })); UpdateDisplayPower(); PowerType pw = GetPowerType(); if (pw != PowerType.Mana) { SetPower(PowerType.Mana, 0); // Mana must be 0 even if it isn't the active power type. } SetPower(pw, 0); UpdateItemSetAuras(false); // update visible transmog for (byte i = EquipmentSlot.Start; i < EquipmentSlot.End; ++i) { Item equippedItem = GetItemByPos(InventorySlots.Bag0, i); if (equippedItem) { SetVisibleItemSlot(i, equippedItem); } } foreach (uint glyphId in GetGlyphs(spec.OrderIndex)) { CastSpell(this, CliDB.GlyphPropertiesStorage.LookupByKey(glyphId).SpellID, true); } ActiveGlyphs activeGlyphs = new ActiveGlyphs(); foreach (uint glyphId in GetGlyphs(spec.OrderIndex)) { List <uint> bindableSpells = Global.DB2Mgr.GetGlyphBindableSpells(glyphId); foreach (uint bindableSpell in bindableSpells) { if (HasSpell(bindableSpell) && !m_overrideSpells.ContainsKey(bindableSpell)) { activeGlyphs.Glyphs.Add(new GlyphBinding(bindableSpell, (ushort)glyphId)); } } } activeGlyphs.IsFullUpdate = true; SendPacket(activeGlyphs); Item item = GetItemByEntry(PlayerConst.ItemIdHeartOfAzeroth, ItemSearchLocation.Everywhere); if (item != null) { AzeriteItem azeriteItem = item.ToAzeriteItem(); if (azeriteItem != null) { if (azeriteItem.IsEquipped()) { ApplyAllAzeriteEmpoweredItemMods(false); ApplyAzeritePowers(azeriteItem, false); } azeriteItem.SetSelectedAzeriteEssences(spec.Id); if (azeriteItem.IsEquipped()) { ApplyAzeritePowers(azeriteItem, true); ApplyAllAzeriteEmpoweredItemMods(true); } azeriteItem.SetState(ItemUpdateState.Changed, this); } } var shapeshiftAuras = GetAuraEffectsByType(AuraType.ModShapeshift); foreach (AuraEffect aurEff in shapeshiftAuras) { aurEff.HandleShapeshiftBoosts(this, false); aurEff.HandleShapeshiftBoosts(this, true); } }
private void OnMoveTimeSkipped(WorldSession session, PCMoveTimeSkipped packet) { session.OutOfSyncDelay = packet.OutOfSyncDelay; }
static bool HandleCharacterRenameCommand(StringArguments args, CommandHandler handler) { Player target; ObjectGuid targetGuid; string targetName; if (!handler.extractPlayerTarget(args, out target, out targetGuid, out targetName)) { return(false); } string newNameStr = args.NextString(); if (!string.IsNullOrEmpty(newNameStr)) { string playerOldName; string newName = newNameStr; if (target) { // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } playerOldName = target.GetName(); } else { // check offline security if (handler.HasLowerSecurity(null, targetGuid)) { return(false); } ObjectManager.GetPlayerNameByGUID(targetGuid, out playerOldName); } if (!ObjectManager.NormalizePlayerName(ref newName)) { handler.SendSysMessage(CypherStrings.BadValue); return(false); } if (ObjectManager.CheckPlayerName(newName, target ? target.GetSession().GetSessionDbcLocale() : Global.WorldMgr.GetDefaultDbcLocale(), true) != ResponseCodes.CharNameSuccess) { handler.SendSysMessage(CypherStrings.BadValue); return(false); } WorldSession session = handler.GetSession(); if (session != null) { if (!session.HasPermission(RBACPermissions.SkipCheckCharacterCreationReservedname) && Global.ObjectMgr.IsReservedName(newName)) { handler.SendSysMessage(CypherStrings.ReservedName); return(false); } } PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHECK_NAME); stmt.AddValue(0, newName); SQLResult result = DB.Characters.Query(stmt); if (!result.IsEmpty()) { handler.SendSysMessage(CypherStrings.RenamePlayerAlreadyExists, newName); return(false); } // Remove declined name from db stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHAR_DECLINED_NAME); stmt.AddValue(0, targetGuid.GetCounter()); DB.Characters.Execute(stmt); if (target) { target.SetName(newName); session = target.GetSession(); if (session != null) { session.KickPlayer(); } } else { stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_NAME_BY_GUID); stmt.AddValue(0, newName); stmt.AddValue(1, targetGuid.GetCounter()); DB.Characters.Execute(stmt); } Global.WorldMgr.UpdateCharacterInfo(targetGuid, newName); handler.SendSysMessage(CypherStrings.RenamePlayerWithNewName, playerOldName, newName); Player player = handler.GetPlayer(); if (player) { Log.outCommand(session.GetAccountId(), "GM {0} (Account: {1}) forced rename {2} to player {3} (Account: {4})", player.GetName(), session.GetAccountId(), newName, playerOldName, ObjectManager.GetPlayerAccountIdByGUID(targetGuid)); } else { Log.outCommand(0, "CONSOLE forced rename '{0}' to '{1}' ({2})", playerOldName, newName, targetGuid.ToString()); } } else { if (target) { // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } handler.SendSysMessage(CypherStrings.RenamePlayer, handler.GetNameLink(target)); target.SetAtLoginFlag(AtLoginFlags.Rename); } else { // check offline security if (handler.HasLowerSecurity(null, targetGuid)) { return(false); } string oldNameLink = handler.playerLink(targetName); handler.SendSysMessage(CypherStrings.RenamePlayerGuid, oldNameLink, targetGuid.ToString()); PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ADD_AT_LOGIN_FLAG); stmt.AddValue(0, AtLoginFlags.Rename); stmt.AddValue(1, targetGuid.GetCounter()); DB.Characters.Execute(stmt); } } return(true); }
private void UpdateEntity(WorldSession session, PCMoveInfo handler) { session.Player.Location.X = handler.X; session.Player.Location.Y = handler.Y; session.Player.Location.Z = handler.Z; }
private void TransmitMovement(WorldSession session, PCMoveInfo handler, WorldOpcodes code) { UpdateEntity(session, handler); //ToList because collection can be modified while iterating. session.Player.SubscribedBy.ToList().ForEach(s => s.SendPacket(new PSMovement(code, session, handler))); }
static bool HandleModifyGenderCommand(CommandHandler handler, StringArguments args) { if (args.Empty()) { return(false); } Player target = handler.GetSelectedPlayerOrSelf(); if (!target) { handler.SendSysMessage(CypherStrings.PlayerNotFound); return(false); } PlayerInfo info = Global.ObjectMgr.GetPlayerInfo(target.GetRace(), target.GetClass()); if (info == null) { return(false); } string gender_str = args.NextString(); Gender gender; if (gender_str == "male") // MALE { if (target.GetGender() == Gender.Male) { return(true); } gender = Gender.Male; } else if (gender_str == "female") // FEMALE { if (target.GetGender() == Gender.Female) { return(true); } gender = Gender.Female; } else { handler.SendSysMessage(CypherStrings.MustMaleOrFemale); return(false); } // Set gender target.SetGender(gender); target.SetNativeGender(gender); // Change display ID target.InitDisplayIds(); target.RestoreDisplayId(false); Global.CharacterCacheStorage.UpdateCharacterGender(target.GetGUID(), (byte)gender); // Generate random customizations List <ChrCustomizationChoice> customizations = new(); var options = Global.DB2Mgr.GetCustomiztionOptions(target.GetRace(), gender); WorldSession worldSession = target.GetSession(); foreach (ChrCustomizationOptionRecord option in options) { ChrCustomizationReqRecord optionReq = CliDB.ChrCustomizationReqStorage.LookupByKey(option.ChrCustomizationReqID); if (optionReq != null && !worldSession.MeetsChrCustomizationReq(optionReq, target.GetClass(), false, customizations)) { continue; } // Loop over the options until the first one fits var choicesForOption = Global.DB2Mgr.GetCustomiztionChoices(option.Id); foreach (ChrCustomizationChoiceRecord choiceForOption in choicesForOption) { var choiceReq = CliDB.ChrCustomizationReqStorage.LookupByKey(choiceForOption.ChrCustomizationReqID); if (choiceReq != null && !worldSession.MeetsChrCustomizationReq(choiceReq, target.GetClass(), false, customizations)) { continue; } ChrCustomizationChoiceRecord choiceEntry = choicesForOption[0]; ChrCustomizationChoice choice = new(); choice.ChrCustomizationOptionID = option.Id; choice.ChrCustomizationChoiceID = choiceEntry.Id; customizations.Add(choice); break; } } target.SetCustomizations(customizations); handler.SendSysMessage(CypherStrings.YouChangeGender, handler.GetNameLink(target), gender); if (handler.NeedReportToTarget(target)) { target.SendSysMessage(CypherStrings.YourGenderChanged, gender, handler.GetNameLink()); } return(true); }