public override bool Validate(CharacterRecord charInfo, CharacterRecord relatedCharInfo, out RelationResult relResult) { //Check if the character exists. This should always be true in theory if (charInfo == null) { relResult = RelationResult.FRIEND_DB_ERROR; return false; } //Checks if the relation target char exist if (relatedCharInfo == null) { relResult = RelationResult.IGNORE_NOT_FOUND; return false; } //Checks if the target char is the same as the related one if (charInfo.EntityLowId == relatedCharInfo.EntityLowId) { relResult = RelationResult.IGNORE_SELF; return false; } //Checks if the relation currently exist if (RelationMgr.Instance.HasRelation(charInfo.EntityLowId, relatedCharInfo.EntityLowId, this.Type)) { relResult = RelationResult.IGNORE_ALREADY; return false; } relResult = RelationResult.IGNORE_ADDED; return true; }
Guild CreateGuild(CmdTrigger<RealmServerCmdArgs> trigger, string name, CharacterRecord record) { var guild = new Guild(record, name); trigger.Reply("Guild created"); return guild; }
public ArenaTeamMember(CharacterRecord chr, ArenaTeam team, bool isLeader) : this() { ArenaTeam = team; CharacterLowId = (int)chr.EntityLowId; ArenaTeamId = team.Id; _name = chr.Name; Class = chr.Class; GamesWeek = 0; WinsWeek = 0; GamesSeason = 0; WinsSeason = 0; PersonalRating = 1500; }
public override bool Validate(CharacterRecord charInfo, CharacterRecord relatedCharInfo, out RelationResult relResult) { //Check if the character exists. This should always be true in theory if (charInfo == null) { relResult = RelationResult.FRIEND_DB_ERROR; return false; } //Checks if the relation target char exist if (relatedCharInfo == null) { relResult = RelationResult.FRIEND_NOT_FOUND; return false; } //Checks if the target char is the same as the related one if (charInfo.EntityLowId == relatedCharInfo.EntityLowId) { relResult = RelationResult.FRIEND_SELF; return false; } //Checks if both chars are in the same faction if (FactionMgr.GetFactionGroup(charInfo.Race) != FactionMgr.GetFactionGroup(relatedCharInfo.Race)) { relResult = RelationResult.FRIEND_ENEMY; return false; } //Checks if the relation currently exist if (RelationMgr.Instance.HasRelation(charInfo.EntityLowId, relatedCharInfo.EntityLowId, Type)) { relResult = RelationResult.FRIEND_ALREADY; return false; } //All checks are ok so check if the related char is online if (World.GetCharacter(relatedCharInfo.EntityLowId) != null) { relResult = RelationResult.FRIEND_ADDED_ONLINE; } else { relResult = RelationResult.FRIEND_ADDED_OFFLINE; } return true; }
public GuildMember(CharacterRecord chr, Guild guild, GuildRank rank) : this() { var zoneId = (int)chr.Zone; Guild = guild; CharacterLowId = (int)chr.EntityLowId; _rankId = rank.RankIndex; _name = chr.Name; _lastLevel = chr.Level; _lastLogin = DateTime.Now; _lastZoneId = zoneId; _class = (int)chr.Class; _publicNote = string.Empty; _officerNote = string.Empty; }
public override bool Validate(CharacterRecord charInfo, CharacterRecord relatedCharInfo, out RelationResult relResult) { //Check if the character exists. This should always be true in theory if (charInfo == null) { relResult = RelationResult.FRIEND_DB_ERROR; return false; } //Checks if the relation target char exist if (relatedCharInfo == null) { relResult = RelationResult.MUTED_NOT_FOUND; return false; } //Checks if the target char is the same as the related one if (charInfo.EntityLowId == relatedCharInfo.EntityLowId) { relResult = RelationResult.MUTED_SELF; return false; } ////Checks if both chars are in the same faction //if (Factions.FactionMgr.GetFactionGroup(charInfo.Race) != Factions.FactionMgr.GetFactionGroup((RaceType)relatedCharInfo.Race)) //{ // relResult = RelationResult.MUTED_ENEMY; // return false; //} //Checks if the relation currently exist if (RelationMgr.Instance.HasRelation(charInfo.EntityLowId, relatedCharInfo.EntityLowId, this.Type)) { relResult = RelationResult.MUTED_ALREADY; return false; } relResult = RelationResult.MUTED_ADDED; return true; }
/// <summary> /// Creates a new CharacterRecord row in the database with the given information. /// </summary> /// <param name="account">the account this character is on</param> /// <param name="name">the name of the new character</param> /// <returns>the <seealso cref="CharacterRecord"/> object</returns> public static CharacterRecord CreateNewCharacterRecord(RealmAccount account, string name) { CharacterRecord record; try { record = new CharacterRecord(account.AccountId) { EntityLowId = (uint)NextId(), Name = name, Created = DateTime.Now }; } catch (Exception ex) { Log.Error("Character creation error (DBS: " + RealmServerConfiguration.DBType + "): ", ex); record = null; } return record; }
/// <summary> /// Creates and sends a new Mail with the given parameters /// </summary> public MailError SendMail(CharacterRecord recipient, string subject, string body, MailStationary stationary, ICollection<Item> items, uint money, uint cod) { if (subject.Length > MailMgr.MaxMailSubjectLength || body.Length > MailMgr.MaxMailBodyLength) { // Player cannot send mails this long through the mail dialog return MailError.INTERNAL_ERROR; } // Can't send mail to yourself. if (recipient.EntityLowId == m_chr.EntityId.Low) { MailHandler.SendResult(m_chr.Client, 0, MailResult.MailSent, MailError.CANNOT_SEND_TO_SELF); return MailError.CANNOT_SEND_TO_SELF; } var requiredCash = money; // Check that sender is good for the money. if (MailMgr.ChargePostage) { if (!m_chr.GodMode) { requiredCash += MailMgr.PostagePrice; var count = (items == null) ? 0u : (uint) items.Count; if (count > 0) { requiredCash += ((count - 1)*MailMgr.PostagePrice); } } } if (requiredCash > m_chr.Money) { MailHandler.SendResult(m_chr.Client, 0u, MailResult.MailSent, MailError.NOT_ENOUGH_MONEY); return MailError.NOT_ENOUGH_MONEY; } // Charge for the letter (already checked, Character has enough) m_chr.Money -= requiredCash; // All good, send an ok message MailHandler.SendResult(m_chr.Client, 0u, MailResult.MailSent, MailError.OK); m_chr.Achievements.CheckPossibleAchievementUpdates(AchievementCriteriaType.GoldSpentForMail, requiredCash); var deliveryDelay = 0u; if (!m_chr.GodMode) { if ((money > 0 || (items != null && items.Count > 0)) && (m_chr.Account.AccountId != recipient.AccountId)) { deliveryDelay = MailMgr.MaxPacketDeliveryDelay; } } // Create a new letter object var letter = new MailMessage(subject, body) { LastModifiedOn = null, SenderId = m_chr.EntityId.Low, ReceiverId = recipient.EntityLowId, MessageStationary = stationary, MessageType = MailType.Normal, CashOnDelivery = cod, IncludedMoney = money, SendTime = DateTime.Now, DeliveryTime = DateTime.Now.AddSeconds(deliveryDelay) }; // Attach items to the new letter if (items != null && items.Count > 0) { // remove the item from the sender's inventory and add them to the list letter.SetItems(items); } MailMgr.SendMail(letter); return MailError.OK; }
private static void CharacterRenameCallback(IRealmClient client, CharacterRecord ch, string newName, EntityId guid) { if (CharacterRecord.Exists(newName)) { SendCharacterRenameError(client, LoginErrorCode.CHAR_CREATE_NAME_IN_USE); } else { log.Debug(WCell_RealmServer.RenamingCharacter, ch.Name, newName); ch.Name = newName; SendCharacterRename(client, guid, ch.Name); } }
private static void CharCreateCallback(IRealmClient client, CharacterRecord newCharRecord) { // check again, to avoid people creating 2 chars with the same name at the same time screwing up the server if (CharacterRecord.Exists(newCharRecord.Name)) { SendCharCreateReply(client, LoginErrorCode.CHAR_CREATE_NAME_IN_USE); } else { try { RealmWorldDBMgr.DatabaseProvider.SaveOrUpdate(newCharRecord); } catch (Exception e) { //LogUtil.ErrorException(e, "Could not create Character \"{0}\" for: {1}", newCharRecord.Name, client.Account); //SendCharCreateReply(client, LoginErrorCode.CHAR_CREATE_ERROR); try { RealmWorldDBMgr.OnDBError(e); RealmWorldDBMgr.DatabaseProvider.SaveOrUpdate(newCharRecord); } catch (Exception) { SendCharCreateReply(client, LoginErrorCode.CHAR_CREATE_ERROR); return; } } client.Account.Characters.Add(newCharRecord); SendCharCreateReply(client, LoginErrorCode.CHAR_CREATE_SUCCESS); } }
public virtual bool Validate(CharacterRecord charInfo, CharacterRecord relatedCharInfo, out RelationResult relResult) { relResult = RelationResult.FRIEND_DB_ERROR; return true; }
/// <summary> /// Creates a new character and loads all required character data from the database /// </summary> /// <param name="acc">The account the character is associated with</param> /// <param name="record">The name of the character to load</param> /// <param name="client">The client to associate with this character</param> internal protected void Create(RealmAccount acc, CharacterRecord record, IRealmClient client) { client.ActiveCharacter = this; acc.ActiveCharacter = this; Type |= ObjectTypes.Player; ChatChannels = new List<ChatChannel>(5); m_logoutTimer = new TimerEntry(0, DefaultLogoutDelayMillis, totalTime => FinishLogout()); Account = acc; m_client = client; m_record = record; EntityId = EntityId.GetPlayerId(m_record.EntityLowId); m_name = m_record.Name; Archetype = ArchetypeMgr.GetArchetype(record.Race, record.Class); MainWeapon = GenericWeapon.Fists; PowerType = m_archetype.Class.DefaultPowerType; StandState = StandState.Sit; Money = (uint)m_record.Money; Outfit = m_record.Outfit; //ScaleX = m_archetype.Race.Scale; ScaleX = 1; Gender = m_record.Gender; Skin = m_record.Skin; Facial = m_record.Face; HairStyle = m_record.HairStyle; HairColor = m_record.HairColor; FacialHair = m_record.FacialHair; UnitFlags = UnitFlags.PlayerControlled; Experience = m_record.Xp; RestXp = m_record.RestXp; ////TODO: Work out if this is the correct location for setting the mask //ActionBarMask = m_record.ActionBarMask; SetInt32(UnitFields.LEVEL, m_record.Level); // cannot use Level property, since it will trigger certain events that we don't want triggered NextLevelXP = XpGenerator.GetXpForlevel(m_record.Level + 1); MaxLevel = RealmServerConfiguration.MaxCharacterLevel; RestState = RestState.Normal; Orientation = m_record.Orientation; m_bindLocation = new WorldZoneLocation( m_record.BindMap, new Vector3(m_record.BindX, m_record.BindY, m_record.BindZ), m_record.BindZone); PvPRank = 1; YieldsXpOrHonor = true; foreach (var school in SpellConstants.AllDamageSchools) { SetFloat(PlayerFields.MOD_DAMAGE_DONE_PCT + (int)school, 1); } SetFloat(PlayerFields.DODGE_PERCENTAGE, 1.0f); // Auras m_auras = new PlayerAuraCollection(this); // spells m_spells = PlayerSpellCollection.Obtain(this); // factions WatchedFaction = m_record.WatchedFaction; Faction = FactionMgr.ByRace[(uint)record.Race]; m_reputations = new ReputationCollection(this); // skills m_skills = new SkillCollection(this); // talents m_talents = new PlayerTalentCollection(this); // achievements m_achievements = new AchievementCollection(this); // Items m_inventory = new PlayerInventory(this); m_mailAccount = new MailAccount(this); m_questLog = new QuestLog(this); // tutorial flags TutorialFlags = new TutorialFlags(m_record.TutorialFlags); // Make sure client and internal state is updated with combat base values UnitUpdates.UpdateSpellCritChance(this); // Mask of activated TaxiNodes m_taxiNodeMask = new TaxiNodeMask(); PowerCostMultiplier = 1f; m_lastPlayTimeUpdate = DateTime.Now; MoveControl.Mover = this; MoveControl.CanControl = true; IncMeleePermissionCounter(); SpeedFactor = DefaultSpeedFactor; // basic setup if (record.JustCreated) { ModStatsForLevel(m_record.Level); BasePower = RegenerationFormulas.GetPowerForLevel(this); } else { BaseHealth = m_record.BaseHealth; SetBasePowerDontUpdate(m_record.BasePower); SetBaseStat(StatType.Strength, m_record.BaseStrength); SetBaseStat(StatType.Stamina, m_record.BaseStamina); SetBaseStat(StatType.Spirit, m_record.BaseSpirit); SetBaseStat(StatType.Intellect, m_record.BaseIntellect); SetBaseStat(StatType.Agility, m_record.BaseAgility); Power = m_record.Power; SetInt32(UnitFields.HEALTH, m_record.Health); } }