예제 #1
0
        /// <summary>
        /// Retrieve the given two ChannelMembers and the Channel they are on, if they
        /// are all on the channel. If not, sends corresponding error messages to user.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="channelName"></param>
        /// <param name="targetName"></param>
        /// <param name="userMember"></param>
        /// <param name="targetMember"></param>
        /// <returns></returns>
        public static ChatChannel EnsurePresence(IUser user, string channelName, string targetName,
                                                 out ChannelMember userMember, out ChannelMember targetMember)
        {
            if (!string.IsNullOrEmpty(targetName))
            {
                ChatChannel chatChannel = ChatChannelGroup.RetrieveChannel(user, channelName);
                if (chatChannel != null)
                {
                    uint low = user.EntityId.Low;
                    if (!chatChannel.Members.TryGetValue(low, out userMember))
                    {
                        ChannelHandler.SendNotOnChannelReply((IPacketReceiver)user, channelName);
                    }
                    else
                    {
                        IUser namedEntity = World.GetNamedEntity(targetName, false) as IUser;
                        if (namedEntity == null ||
                            !chatChannel.Members.TryGetValue(namedEntity.EntityId.Low, out targetMember))
                        {
                            ChannelHandler.SendTargetNotOnChannelReply((IPacketReceiver)user, channelName, targetName);
                        }
                        else if (namedEntity != user)
                        {
                            return(chatChannel);
                        }
                    }
                }
            }

            userMember   = (ChannelMember)null;
            targetMember = (ChannelMember)null;
            return((ChatChannel)null);
        }
예제 #2
0
        private void OnUserLeft(ChannelMember member)
        {
            var changeOwner = member.IsOwner;

            member.User.ChatChannels.Remove(this);
            m_members.Remove(member.User.EntityId.Low);

            if (changeOwner)
            {
                member = m_members.Values.FirstOrDefault();
                if (member != null)
                {
                    if (Announces)
                    {
                        ChannelHandler.SendLeftReplyToEveryone(this, member.User.EntityId);
                    }
                    Owner = member;
                }
                else
                {
                    m_group.DeleteChannel(this);
                    m_owner = null;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Checks for whether the given member can perform a beneficial or harmful action on the targetMember
        /// within this channel.
        /// </summary>
        /// <param name="member"></param>
        /// <param name="targetMember"></param>
        /// <param name="beneficial"></param>
        /// <returns></returns>
        public bool CheckPrivs(ChannelMember member, ChannelMember targetMember, bool beneficial)
        {
            if (beneficial)
            {
                if (!member.IsModerator || member.User.Role.IsStaff)
                {
                    ChannelHandler.SendNotModeratorReply((IPacketReceiver)member.User, this.m_name);
                    return(false);
                }
            }
            else if (targetMember > member)
            {
                if (targetMember.IsModerator)
                {
                    ChannelHandler.SendNotOwnerReply((IPacketReceiver)member.User, this.m_name);
                }
                else
                {
                    ChannelHandler.SendNotModeratorReply((IPacketReceiver)member.User, this.m_name);
                }
                return(false);
            }

            return(true);
        }
예제 #4
0
        private void OnUserLeft(ChannelMember member)
        {
            bool isOwner = member.IsOwner;

            member.User.ChatChannels.Remove(this);
            this.m_members.Remove(member.User.EntityId.Low);
            if (!isOwner)
            {
                return;
            }
            member = this.m_members.Values.FirstOrDefault <ChannelMember>();
            if (member != null)
            {
                if (this.Announces)
                {
                    ChannelHandler.SendLeftReplyToEveryone(this, member.User.EntityId);
                }
                this.Owner = member;
            }
            else
            {
                this.m_group.DeleteChannel(this);
                this.m_owner = (ChannelMember)null;
            }
        }
예제 #5
0
 public void SetMuted(ChannelMember member, ChannelMember targetMember, bool muted)
 {
     if (targetMember.IsMuted != muted && CheckPrivs(member, targetMember, !muted))
     {
         targetMember.IsMuted = muted;
         ChannelHandler.SendMuteStatusToEveryone(this, member.User.EntityId, targetMember.User.EntityId, muted);
     }
 }
예제 #6
0
 /// <summary>
 /// Whether the given Entity-id is present in this channel
 /// </summary>
 /// <returns>true if the player is in this channel; false otherwise</returns>
 public bool EnsurePresence(IUser user, out ChannelMember member)
 {
     if (this.m_members.TryGetValue(user.EntityId.Low, out member))
     {
         return(true);
     }
     ChannelHandler.SendNotOnChannelReply((IPacketReceiver)user, this.m_name);
     member = (ChannelMember)null;
     return(false);
 }
예제 #7
0
 /// <summary>
 /// Whether the given Entity-id is present in this channel
 /// </summary>
 /// <returns>true if the player is in this channel; false otherwise</returns>
 public bool EnsurePresence(IUser user, out ChannelMember member)
 {
     if (!m_members.TryGetValue(user.EntityId.Low, out member))
     {
         ChannelHandler.SendNotOnChannelReply(user, m_name);
         member = null;
         return(false);
     }
     return(true);
 }
예제 #8
0
        public bool SetBanned(ChannelMember member, string targetName, bool addBan)
        {
            IUser namedEntity = World.GetNamedEntity(targetName, true) as IUser;

            if (namedEntity != null)
            {
                return(this.SetBanned(member, namedEntity, false));
            }
            ChatMgr.SendChatPlayerNotFoundReply((IPacketReceiver)member.User, targetName);
            return(false);
        }
예제 #9
0
        public override void Process(CmdTrigger<RealmServerCmdArgs> trigger)
        {
            var wcellUser = trigger.Args.User as WCellUser;
            var chanName = trigger.Text.NextWord();
            var targetUsr = trigger.Args.GetCharArgumentOrTarget(trigger, trigger.Text.NextWord());

            ChannelMember me = new ChannelMember(wcellUser);
            ChatChannelGroup ircChannelGroup = new ChatChannelGroup(FactionGroup.Invalid);
            var chatChan = new ChatChannel(ircChannelGroup, chanName);
            chatChan.Invite(me, targetUsr);
            //ChatMgr.OnChat += new ChatNotifyDelegate(ChatMgr_OnChat);
        }
예제 #10
0
        public bool SetBanned(ChannelMember member, string targetName, bool addBan)
        {
            var target = World.GetNamedEntity(targetName, true) as IUser;

            if (target != null)
            {
                return(SetBanned(member, target, false));
            }

            ChatMgr.SendChatPlayerNotFoundReply(member.User, targetName);
            return(false);
        }
예제 #11
0
 public void ToggleModerated(ChannelMember toggler)
 {
     if (toggler.IsOwner || toggler.User.Role.IsStaff)
     {
         this.IsModerated = !this.IsModerated;
         ChannelHandler.SendModerateToEveryone(this, toggler.User.EntityId);
     }
     else
     {
         ChannelHandler.SendNotOwnerReply((IPacketReceiver)toggler.User, this.m_name);
     }
 }
예제 #12
0
 /// <summary>
 /// Kicks and -maybe- bans a player from the channel.
 /// </summary>
 /// <returns>Whether the player was found and kicked or false if not found or privs were insufficient.</returns>
 public bool Kick(ChannelMember member, string targetName)
 {
     if (!string.IsNullOrEmpty(targetName))
     {
         var target = World.GetNamedEntity(targetName, true) as IUser;
         if (target != null)
         {
             return(Kick(member, target));
         }
     }
     return(false);
 }
예제 #13
0
        public void Invite(ChannelMember inviter, string targetName)
        {
            IUser namedEntity = World.GetNamedEntity(targetName, false) as IUser;

            if (namedEntity != null)
            {
                this.Invite(inviter, namedEntity);
            }
            else
            {
                ChatMgr.SendChatPlayerNotFoundReply((IPacketReceiver)inviter.User, targetName);
            }
        }
예제 #14
0
        public void Invite(ChannelMember inviter, string targetName)
        {
            var target = World.GetNamedEntity(targetName, false) as IUser;

            if (target != null)
            {
                Invite(inviter, target);
            }
            else
            {
                ChatMgr.SendChatPlayerNotFoundReply(inviter.User, targetName);
            }
        }
예제 #15
0
        /// <summary>Kicks and -maybe- bans a player from the channel.</summary>
        /// <returns>Whether the player was found and kicked or false if not found or privs were insufficient.</returns>
        public bool Kick(ChannelMember member, string targetName)
        {
            if (!string.IsNullOrEmpty(targetName))
            {
                IUser namedEntity = World.GetNamedEntity(targetName, true) as IUser;
                if (namedEntity != null)
                {
                    return(this.Kick(member, namedEntity));
                }
            }

            return(false);
        }
예제 #16
0
        /// <summary>
        /// Returns whether the Ban could be added/removed or false if privs were insufficient.
        /// </summary>
        /// <param name="member"></param>
        /// <param name="target"></param>
        /// <param name="addBan"></param>
        /// <returns></returns>
        public bool SetBanned(ChannelMember member, IUser target, bool addBan)
        {
            if (!member.IsModerator && !member.User.Role.IsStaff)
            {
                return(false);
            }

            if (addBan)
            {
                ChannelMember targetMember;
                if (EnsurePresence(target, out targetMember))
                {
                    // if target is on the channel
                    if (targetMember > member)                                                                                                  // harmful actions require you to have higher privs than the target
                    {
                        if (targetMember.IsModerator)
                        {
                            ChannelHandler.SendNotOwnerReply(member.User, m_name);
                        }
                        return(false);
                    }
                }
            }

            if (addBan)
            {
                if (!m_bannedEntities.Contains(target.EntityId.Low))
                {
                    ChannelHandler.SendTargetNotOnChannelReply(member.User, m_name, target.Name);
                }
                else
                {
                    m_bannedEntities.Add(target.EntityId.Low);
                    ChannelHandler.SendBannedToEveryone(this, member.User.EntityId, target.EntityId);
                }
            }
            else
            {
                if (!m_bannedEntities.Remove(target.EntityId.Low))
                {
                    ChannelHandler.SendTargetNotOnChannelReply(member.User, m_name, target.Name);
                }
                else
                {
                    ChannelHandler.SendUnbannedToEveryone(this, member.User.EntityId, target.EntityId);
                }
            }

            return(true);
        }
예제 #17
0
 public bool SetModerator(ChannelMember mod, ChannelMember newMod, bool makeMod)
 {
     if (newMod.IsModerator != makeMod)
     {
         if (!mod.IsOwner && newMod.IsOwner && !mod.User.Role.IsStaff)
         {
             ChannelHandler.SendNotOwnerReply(mod.User, m_name);
         }
         else
         {
             newMod.IsModerator = makeMod;
             ChannelHandler.SendModeratorStatusToEveryone(this, mod.User.EntityId, newMod.User.EntityId, makeMod);
             return(true);
         }
     }
     return(false);
 }
예제 #18
0
 public bool MakeOwner(ChannelMember oldOwner, ChannelMember newOwner)
 {
     if (!newOwner.IsOwner)
     {
         if (!oldOwner.IsOwner && !oldOwner.User.Role.IsStaff)
         {
             ChannelHandler.SendNotOwnerReply(oldOwner.User, m_name);
         }
         else
         {
             ChannelHandler.SendModeratorStatusToEveryone(this, oldOwner.User.EntityId, newOwner.User.EntityId, true);
             ChannelHandler.SendOwnerChangedToEveryone(this, oldOwner.User.EntityId, newOwner.User.EntityId);
             Owner = newOwner;
             return(true);
         }
     }
     return(false);
 }
예제 #19
0
        /// <summary>
        /// Retrieves the given ChannelMember and the Channel it is on.
        /// If not, sends corresponding error messages to user and returns null.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="channelName"></param>
        /// <returns></returns>
        public static ChatChannel EnsurePresence(IUser user, string channelName, out ChannelMember member)
        {
            ChatChannel chatChannel = ChatChannelGroup.RetrieveChannel(user, channelName);

            if (chatChannel != null)
            {
                uint low = user.EntityId.Low;
                if (chatChannel.Members.TryGetValue(low, out member))
                {
                    return(chatChannel);
                }
                ChannelHandler.SendNotOnChannelReply((IPacketReceiver)user, channelName);
                return((ChatChannel)null);
            }

            member = (ChannelMember)null;
            return((ChatChannel)null);
        }
예제 #20
0
        /// <summary>
        /// Retrieves the given ChannelMember and the Channel it is on.
        /// If not, sends corresponding error messages to user and returns null.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="channelName"></param>
        /// <returns></returns>
        public static ChatChannel EnsurePresence(IUser user, string channelName, out ChannelMember member)
        {
            var chan = ChatChannelGroup.RetrieveChannel(user, channelName);

            if (chan != null)
            {
                var chatterLowId = user.EntityId.Low;
                if (!chan.Members.TryGetValue(chatterLowId, out member))
                {
                    ChannelHandler.SendNotOnChannelReply(user, channelName);
                }
                else
                {
                    return(chan);
                }
                return(null);
            }
            member = null;
            return(null);
        }
예제 #21
0
        /// <summary>Adds a player to this channel.</summary>
        public void TryJoin(IUser user, string password, bool silent)
        {
            if (this.IsTrade || this.RequiresUnguilded || this.IsLFG)
            {
                return;
            }
            uint low = user.EntityId.Low;

            if (this.IsBanned(low) || this.m_joinValidator != null && !this.m_joinValidator(this, user))
            {
                ChannelHandler.SendBannedReply((IPacketReceiver)user, this.Name);
            }
            else if (this.IsPresent(low))
            {
                if (this.IsConstant)
                {
                    return;
                }
                ChannelHandler.SendAlreadyOnChannelReply((IPacketReceiver)user, this.Name, user.EntityId);
            }
            else if (this.Password.Length > 0 && this.Password != password)
            {
                ChannelHandler.SendWrongPassReply((IPacketReceiver)user, this.Name);
            }
            else
            {
                ChannelMember sender = user.Role.IsStaff
                    ? new ChannelMember(user, ChannelMemberFlags.Moderator)
                    : new ChannelMember(user);
                if (this.Announces)
                {
                    ChannelHandler.SendJoinedReplyToEveryone(this, sender);
                }
                if (!this.IsConstant && this.m_owner == null)
                {
                    this.Owner = sender;
                }
                this.m_members.Add(low, sender);
                user.ChatChannels.Add(this);
            }
        }
예제 #22
0
        /// <summary>Kicks and -maybe- bans a player from the channel.</summary>
        /// <returns>Whether the player was kicked or false if privs were insufficient.</returns>
        public bool Kick(ChannelMember member, IUser targetUser)
        {
            IUser         user = member.User;
            ChannelMember member1;

            if (!this.EnsurePresence(targetUser, out member1))
            {
                ChannelHandler.SendTargetNotOnChannelReply((IPacketReceiver)user, this.m_name, targetUser.Name);
                return(false);
            }

            EntityId entityId = targetUser.EntityId;

            if (this.CheckPrivs(member, member1, false))
            {
                ChannelHandler.SendKickedToEveryone(this, user.EntityId, entityId);
            }
            this.m_members.Remove(entityId.Low);
            this.OnUserLeft(member1);
            return(true);
        }
예제 #23
0
        /// <summary>
        /// Returns whether the Ban could be added/removed or false if privs were insufficient.
        /// </summary>
        /// <param name="member"></param>
        /// <param name="target"></param>
        /// <param name="addBan"></param>
        /// <returns></returns>
        public bool SetBanned(ChannelMember member, IUser target, bool addBan)
        {
            if (!member.IsModerator && !member.User.Role.IsStaff)
            {
                return(false);
            }
            ChannelMember member1;

            if (addBan && this.EnsurePresence(target, out member1) && member1 > member)
            {
                if (member1.IsModerator)
                {
                    ChannelHandler.SendNotOwnerReply((IPacketReceiver)member.User, this.m_name);
                }
                return(false);
            }

            if (addBan)
            {
                if (!this.m_bannedEntities.Contains(target.EntityId.Low))
                {
                    ChannelHandler.SendTargetNotOnChannelReply((IPacketReceiver)member.User, this.m_name, target.Name);
                }
                else
                {
                    this.m_bannedEntities.Add(target.EntityId.Low);
                    ChannelHandler.SendBannedToEveryone(this, member.User.EntityId, target.EntityId);
                }
            }
            else if (!this.m_bannedEntities.Remove(target.EntityId.Low))
            {
                ChannelHandler.SendTargetNotOnChannelReply((IPacketReceiver)member.User, this.m_name, target.Name);
            }
            else
            {
                ChannelHandler.SendUnbannedToEveryone(this, member.User.EntityId, target.EntityId);
            }

            return(true);
        }
예제 #24
0
        /// <summary>
        /// Kicks and -maybe- bans a player from the channel.
        /// </summary>
        /// <returns>Whether the player was kicked or false if privs were insufficient.</returns>
        public bool Kick(ChannelMember member, IUser targetUser)
        {
            var           user = member.User;
            ChannelMember targetMember;

            if (!EnsurePresence(targetUser, out targetMember))
            {
                ChannelHandler.SendTargetNotOnChannelReply(user, m_name, targetUser.Name);
            }
            else
            {
                var targetEntitiyId = targetUser.EntityId;
                if (CheckPrivs(member, targetMember, false))
                {
                    ChannelHandler.SendKickedToEveryone(this, user.EntityId, targetEntitiyId);
                }

                m_members.Remove(targetEntitiyId.Low);
                OnUserLeft(targetMember);
                return(true);
            }
            return(false);
        }
예제 #25
0
 public void Invite(ChannelMember inviter, IUser target)
 {
     if (!target.IsIgnoring(inviter.User) || inviter.User.Role.IsStaff)
     {
         if (this.IsPresent(target.EntityId.Low))
         {
             ChannelHandler.SendAlreadyOnChannelReply((IPacketReceiver)inviter.User, target.Name,
                                                      target.EntityId);
         }
         else if (target.FactionGroup != inviter.User.FactionGroup)
         {
             ChannelHandler.SendWrongFaction((IPacketReceiver)inviter.User, this.m_name, target.Name);
         }
         else
         {
             ChannelHandler.SendInvitedMessage((IPacketReceiver)target, this.m_name, inviter.User.EntityId);
             ChannelHandler.SendYouInvitedReply((IPacketReceiver)inviter.User, this.m_name, target.Name);
         }
     }
     else
     {
         ChatMgr.SendChatPlayerNotFoundReply((IPacketReceiver)inviter.User, target.Name);
     }
 }
예제 #26
0
 /// <summary>
 /// Checks for whether the given member can perform a beneficial or harmful action on the targetMember
 /// within this channel.
 /// </summary>
 /// <param name="member"></param>
 /// <param name="targetMember"></param>
 /// <param name="beneficial"></param>
 /// <returns></returns>
 public bool CheckPrivs(ChannelMember member, ChannelMember targetMember, bool beneficial)
 {
     if (beneficial)
     {
         if (!(member.IsModerator && !member.User.Role.IsStaff))                                 // beneficial actions can be done by any mod or staff member
         {
             ChannelHandler.SendNotModeratorReply(member.User, m_name);
             return(false);
         }
     }
     else if (targetMember > member)                                                                                     // harmful actions require you to have higher privs than the target
     {
         if (targetMember.IsModerator)
         {
             ChannelHandler.SendNotOwnerReply(member.User, m_name);
         }
         else
         {
             ChannelHandler.SendNotModeratorReply(member.User, m_name);
         }
         return(false);
     }
     return(true);
 }
예제 #27
0
 public void Invite(ChannelMember inviter, IUser target)
 {
     if (!target.IsIgnoring(inviter.User) || inviter.User.Role.IsStaff)
     {
         if (IsPresent(target.EntityId.Low))
         {
             ChannelHandler.SendAlreadyOnChannelReply(inviter.User, target.Name, target.EntityId);
         }
         else if (target.FactionGroup != inviter.User.FactionGroup)
         {
             ChannelHandler.SendWrongFaction(inviter.User, m_name, target.Name);
         }
         else
         {
             // TODO: all other checks (eg ban etc)
             ChannelHandler.SendInvitedMessage(target, m_name, inviter.User.EntityId);
             ChannelHandler.SendYouInvitedReply(inviter.User, m_name, target.Name);
         }
     }
     else
     {
         ChatMgr.SendChatPlayerNotFoundReply(inviter.User, target.Name);
     }
 }
예제 #28
0
		public bool SetModerator(ChannelMember mod, ChannelMember newMod, bool makeMod)
		{
			if (newMod.IsModerator != makeMod)
			{
				if (!mod.IsOwner && newMod.IsOwner && !mod.User.Role.IsStaff)
				{
					ChannelHandler.SendNotOwnerReply(mod.User, m_name);
				}
				else
				{
					newMod.IsModerator = makeMod;
					ChannelHandler.SendModeratorStatusToEveryone(this, mod.User.EntityId, newMod.User.EntityId, makeMod);
					return true;
				}
			}
			return false;
		}
예제 #29
0
		public bool MakeOwner(ChannelMember oldOwner, ChannelMember newOwner)
		{
			if (!newOwner.IsOwner)
			{
				if (!oldOwner.IsOwner && !oldOwner.User.Role.IsStaff)
				{
					ChannelHandler.SendNotOwnerReply(oldOwner.User, m_name);
				}
				else
				{
					ChannelHandler.SendModeratorStatusToEveryone(this, oldOwner.User.EntityId, newOwner.User.EntityId, true);
					ChannelHandler.SendOwnerChangedToEveryone(this, oldOwner.User.EntityId, newOwner.User.EntityId);
					Owner = newOwner;
					return true;
				}
			}
			return false;
		}
예제 #30
0
		/// <summary>
		/// Kicks and -maybe- bans a player from the channel.
		/// </summary>
		/// <returns>Whether the player was kicked or false if privs were insufficient.</returns>
		public bool Kick(ChannelMember member, IUser targetUser)
		{
			var user = member.User;
			ChannelMember targetMember;
			if (!EnsurePresence(targetUser, out targetMember))
			{
				ChannelHandler.SendTargetNotOnChannelReply(user, m_name, targetUser.Name);
			}
			else
			{
				var targetEntitiyId = targetUser.EntityId;
				if (CheckPrivs(member, targetMember, false))
				{
					ChannelHandler.SendKickedToEveryone(this, user.EntityId, targetEntitiyId);
				}

				m_members.Remove(targetEntitiyId.Low);
				OnUserLeft(targetMember);
				return true;
			}
			return false;
		}
예제 #31
0
		/// <summary>
		/// Kicks and -maybe- bans a player from the channel.
		/// </summary>
		/// <returns>Whether the player was found and kicked or false if not found or privs were insufficient.</returns>
		public bool Kick(ChannelMember member, string targetName)
		{
			if (!string.IsNullOrEmpty(targetName))
			{
				var target = World.GetNamedEntity(targetName, true) as IUser;
				if (target != null)
				{
					return Kick(member, target);
				}
			}
			return false;
		}
예제 #32
0
		public void Invite(ChannelMember inviter, string targetName)
		{
			var target = World.GetNamedEntity(targetName, false) as IUser;
			if (target != null)
			{
				Invite(inviter, target);
			}
			else
			{
				ChatMgr.SendChatPlayerNotFoundReply(inviter.User, targetName);
			}
		}
예제 #33
0
		/// <summary>
		/// Retrieve the given two ChannelMembers and the Channel they are on, if they
		/// are all on the channel. If not, sends corresponding error messages to user.
		/// </summary>
		/// <param name="user"></param>
		/// <param name="channelName"></param>
		/// <param name="targetName"></param>
		/// <param name="userMember"></param>
		/// <param name="targetMember"></param>
		/// <returns></returns>
		public static ChatChannel EnsurePresence(IUser user, string channelName, string targetName, out ChannelMember userMember, out ChannelMember targetMember)
		{
			if (!string.IsNullOrEmpty(targetName))
			{
				var chan = ChatChannelGroup.RetrieveChannel(user, channelName);
				if (chan != null)
				{
					var chatterLowId = user.EntityId.Low;
					if (!chan.Members.TryGetValue(chatterLowId, out userMember))
					{
						ChannelHandler.SendNotOnChannelReply(user, channelName);
					}
					else
					{
						var targetUser = World.GetNamedEntity(targetName, false) as IUser;
						if (targetUser == null || !chan.Members.TryGetValue(targetUser.EntityId.Low, out targetMember))
						{
							ChannelHandler.SendTargetNotOnChannelReply(user, channelName, targetName);
						}
						else if (targetUser != user)
						{
							return chan;
						}
					}
				}
			}
			userMember = null;
			targetMember = null;
			return null;
		}
예제 #34
0
		/// <summary>
		/// Returns whether the Ban could be added/removed or false if privs were insufficient.
		/// </summary>
		/// <param name="member"></param>
		/// <param name="target"></param>
		/// <param name="addBan"></param>
		/// <returns></returns>
		public bool SetBanned(ChannelMember member, IUser target, bool addBan)
		{
			if (!member.IsModerator && !member.User.Role.IsStaff)
			{
				return false;
			}

			if (addBan)
			{
				ChannelMember targetMember;
				if (EnsurePresence(target, out targetMember))
				{
					// if target is on the channel
					if (targetMember > member)										// harmful actions require you to have higher privs than the target
					{
						if (targetMember.IsModerator)
						{
							ChannelHandler.SendNotOwnerReply(member.User, m_name);
						}
						return false;
					}
				}
			}

			if (addBan)
			{
				if (!m_bannedEntities.Contains(target.EntityId.Low))
				{
					ChannelHandler.SendTargetNotOnChannelReply(member.User, m_name, target.Name);
				}
				else
				{
					m_bannedEntities.Add(target.EntityId.Low);
					ChannelHandler.SendBannedToEveryone(this, member.User.EntityId, target.EntityId);
				}
			}
			else
			{
				if (!m_bannedEntities.Remove(target.EntityId.Low))
				{
					ChannelHandler.SendTargetNotOnChannelReply(member.User, m_name, target.Name);
				}
				else
				{
					ChannelHandler.SendUnbannedToEveryone(this, member.User.EntityId, target.EntityId);
				}
			}

			return true;
		}
예제 #35
0
 /// <summary>
 /// Retrieve the given two ChannelMembers and the Channel they are on, if they
 /// are all on the channel. If not, sends corresponding error messages to user.
 /// </summary>
 /// <param name="user"></param>
 /// <param name="channelName"></param>
 /// <param name="targetName"></param>
 /// <param name="userMember"></param>
 /// <param name="targetMember"></param>
 /// <returns></returns>
 public static ChatChannel EnsurePresence(IUser user, string channelName, string targetName, out ChannelMember userMember, out ChannelMember targetMember)
 {
     if (!string.IsNullOrEmpty(targetName))
     {
         var chan = ChatChannelGroup.RetrieveChannel(user, channelName);
         if (chan != null)
         {
             var chatterLowId = user.EntityId.Low;
             if (!chan.Members.TryGetValue(chatterLowId, out userMember))
             {
                 ChannelHandler.SendNotOnChannelReply(user, channelName);
             }
             else
             {
                 var targetUser = World.GetNamedEntity(targetName, false) as IUser;
                 if (targetUser == null || !chan.Members.TryGetValue(targetUser.EntityId.Low, out targetMember))
                 {
                     ChannelHandler.SendTargetNotOnChannelReply(user, channelName, targetName);
                 }
                 else if (targetUser != user)
                 {
                     return(chan);
                 }
             }
         }
     }
     userMember   = null;
     targetMember = null;
     return(null);
 }
예제 #36
0
		public void SetMuted(ChannelMember member, ChannelMember targetMember, bool muted)
		{
			if (targetMember.IsMuted != muted && CheckPrivs(member, targetMember, !muted))
			{
				targetMember.IsMuted = muted;
				ChannelHandler.SendMuteStatusToEveryone(this, member.User.EntityId, targetMember.User.EntityId, muted);
			}
		}
예제 #37
0
		//public uint ChannelId
		//{
		//    get { return m_channelId; }
		//}

		#endregion

		#region Methods

		public void ToggleModerated(ChannelMember toggler)
		{
			if (toggler.IsOwner || toggler.User.Role.IsStaff)
			{
				IsModerated = !IsModerated;
				ChannelHandler.SendModerateToEveryone(this, toggler.User.EntityId);
			}
			else
			{
				ChannelHandler.SendNotOwnerReply(toggler.User, m_name);
			}
		}
예제 #38
0
		public bool SetBanned(ChannelMember member, string targetName, bool addBan)
		{
			var target = World.GetNamedEntity(targetName, true) as IUser;
			if (target != null)
			{
				return SetBanned(member, target, false);
			}

		    ChatMgr.SendChatPlayerNotFoundReply(member.User, targetName);
		    return false;
		}
예제 #39
0
		/// <summary>
		/// Whether the given Entity-id is present in this channel
		/// </summary>
		/// <returns>true if the player is in this channel; false otherwise</returns>
		public bool EnsurePresence(IUser user, out ChannelMember member)
		{
			if (!m_members.TryGetValue(user.EntityId.Low, out member))
			{
				ChannelHandler.SendNotOnChannelReply(user, m_name);
				member = null;
				return false;
			}
			return true;
		}
예제 #40
0
		/// <summary>
		/// Retrieves the given ChannelMember and the Channel it is on. 
		/// If not, sends corresponding error messages to user and returns null.
		/// </summary>
		/// <param name="user"></param>
		/// <param name="channelName"></param>
		/// <returns></returns>
		public static ChatChannel EnsurePresence(IUser user, string channelName, out ChannelMember member)
		{
			var chan = ChatChannelGroup.RetrieveChannel(user, channelName);

			if (chan != null)
			{
				var chatterLowId = user.EntityId.Low;
				if (!chan.Members.TryGetValue(chatterLowId, out member))
				{
					ChannelHandler.SendNotOnChannelReply(user, channelName);
				}
				else
				{
					return chan;
				}
				return null;
			}
			member = null;
			return null;
		}
예제 #41
0
		private void OnUserLeft(ChannelMember member)
		{
			var changeOwner = member.IsOwner;

			member.User.ChatChannels.Remove(this);
			m_members.Remove(member.User.EntityId.Low);

			if (changeOwner)
			{
				member = m_members.Values.FirstOrDefault();
				if (member != null)
				{
					if (Announces)
					{
						ChannelHandler.SendLeftReplyToEveryone(this, member.User.EntityId);
					}
					Owner = member;
				}
				else
				{
					m_group.DeleteChannel(this);
					m_owner = null;
				}
			}
		}
예제 #42
0
		/// <summary>
		/// Checks for whether the given member can perform a beneficial or harmful action on the targetMember
		/// within this channel.
		/// </summary>
		/// <param name="member"></param>
		/// <param name="targetMember"></param>
		/// <param name="beneficial"></param>
		/// <returns></returns>
		public bool CheckPrivs(ChannelMember member, ChannelMember targetMember, bool beneficial)
		{
			if (beneficial)
			{
				if (!(member.IsModerator && !member.User.Role.IsStaff))			// beneficial actions can be done by any mod or staff member
				{
					ChannelHandler.SendNotModeratorReply(member.User, m_name);
					return false;
				}
			}
			else if (targetMember > member)										// harmful actions require you to have higher privs than the target
			{
				if (targetMember.IsModerator)
				{
					ChannelHandler.SendNotOwnerReply(member.User, m_name);
				}
				else
				{
					ChannelHandler.SendNotModeratorReply(member.User, m_name);
				}
				return false;
			}
			return true;
		}
예제 #43
0
		/// <summary>
		/// Send the "name has joined channel" reply to everyone
		/// </summary>
		/// <param name="chan">name of channel</param>
		/// <param name="sender">sender (to check the ignore list)</param>
		public static void SendJoinedReplyToEveryone(ChatChannel chan, ChannelMember sender)
		{
            // the packet has the same size no matter the opcode, so it's really
            // a retarded way of doing it... but blame blizz.
            var opcode = chan.IsConstant ? RealmServerOpCode.SMSG_USERLIST_ADD
                : RealmServerOpCode.SMSG_USERLIST_UPDATE;

			using (RealmPacketOut packet = new RealmPacketOut(opcode))
			{
				//packet.WriteByte((byte)ChannelNotification.PlayerJoined);
				packet.Write(sender.User.EntityId);
                packet.Write((byte)sender.Flags);
                packet.Write((byte)chan.ClientFlags);
                packet.WriteUInt(chan.MemberCount);
                packet.WriteCString(chan.Name);

				SendPacketToChannel(chan, packet, sender.User.EntityId);
			}
		}
예제 #44
0
		public void Invite(ChannelMember inviter, IUser target)
		{
			if (!target.IsIgnoring(inviter.User) || inviter.User.Role.IsStaff)
			{
				if (IsPresent(target.EntityId.Low))
				{
					ChannelHandler.SendAlreadyOnChannelReply(inviter.User, target.Name, target.EntityId);
				}
				else if (target.FactionGroup != inviter.User.FactionGroup)
				{
					ChannelHandler.SendWrongFaction(inviter.User, m_name, target.Name);
				}
				else
				{
					// TODO: all other checks (eg ban etc)
					ChannelHandler.SendInvitedMessage(target, m_name, inviter.User.EntityId);
					ChannelHandler.SendYouInvitedReply(inviter.User, m_name, target.Name);
				}
			}
			else
			{
				ChatMgr.SendChatPlayerNotFoundReply(inviter.User, target.Name);
			}
		}
예제 #45
0
        public override void Process(CmdTrigger<RealmServerCmdArgs> trigger)
        {
            var ticket = trigger.Args.TicketHandler.HandlingTicket;
            if (ticket != null)
            {
                Character user = ticket.Owner;

                if (ticket.Owner == null)
                {
                    trigger.Reply("The owner of this Ticket is offline.");
                }
                else
                {
                    var me = new ChannelMember(trigger.Args.User);
                    var ircChannel = new ChatChannelGroup(FactionGroup.Invalid);
                    var chan = new ChatChannel(ircChannel);

                    chan.Invite(me, user);
                    //user.SendMessage(trigger.Args.User,
                    //                 "A staff member wants to chat with you about your ticket. Please do not leave the channel.");
                }
            }
            else
            {
                trigger.Reply("You must have a ticket selected.");
            }
        }