Example #1
0
        public void MultiCastLeave(ChatChannelUser leaver, string message)
        {
            string leaveMessage = ChatCommandBase.BuildMessageRPL(
                $"{leaver.UserInfo.NickName}!{leaver.UserInfo.UserName}@{ChatServer.ServerDomain}",
                $"PART {Property.ChannelName}", message);

            MultiCast(leaveMessage);
        }
        public void MultiCastLeave(ChatChannelUser leaver, string message)
        {
            string leaveMessage =
                ChatReply.BuildPartReply(
                    leaver, Property.ChannelName, message);

            MultiCast(leaveMessage);
        }
Example #3
0
 public bool IsUserBanned(ChatChannelUser user)
 {
     if (Property.BanList.Where(u => u.Session.Equals(user.Session)).Count() == 1)
     {
         return(true);
     }
     return(false);
 }
        public void SendChannelModesToJoiner(ChatChannelUser joiner)
        {
            string modes = Property.ChannelMode.GetChannelMode();

            string modesMessage =
                ChatReply.BuildChannelModesReply(
                    joiner, Property.ChannelName, modes);

            joiner.Session.SendAsync(modesMessage);
        }
Example #5
0
        public void SendChannelModesToJoiner(ChatChannelUser joiner)
        {
            string modes        = Property.ChannelMode.GetChannelMode();
            string modesMessage =
                ChatCommandBase.BuildNormalRPL(
                    ChatServer.ServerDomain,
                    ChatResponseType.ChannelModels,
                    $"{joiner.UserInfo.NickName} {Property.ChannelName} {modes}", "");

            joiner.Session.SendAsync(modesMessage);
        }
        /// <summary>
        /// We only care about how to set mode in this channel
        /// we do not need to care about if the user is legal
        /// because MODEHandler will check for us
        /// </summary>
        /// <param name="changer"></param>
        /// <param name="cmd"></param>
        public void SetProperties(ChatChannelUser changer, MODERequest cmd)
        {
            switch (cmd.RequestType)
            {
            case ModeRequestType.AddChannelUserLimits:
                AddChannelUserLimits(cmd);
                break;

            case ModeRequestType.RemoveChannelUserLimits:
                RemoveChannelUserLimits(cmd);
                break;

            case ModeRequestType.AddBanOnUser:
                AddBanOnUser(cmd);
                break;

            case ModeRequestType.RemoveBanOnUser:
                RemoveBanOnUser(cmd);
                break;

            case ModeRequestType.AddChannelPassword:
                AddChannelPassword(cmd);
                break;

            case ModeRequestType.RemoveChannelPassword:
                RemoveChannelPassword(cmd);
                break;

            case ModeRequestType.AddChannelOperator:
                AddChannelOperator(cmd);
                break;

            case ModeRequestType.RemoveChannelOperator:
                RemoveChannelOperator(cmd);
                break;

            case ModeRequestType.EnableUserVoicePermission:
                EnableUserVoicePermission(cmd);
                break;

            case ModeRequestType.DisableUserVoicePermission:
                DisableUserVoicePermission(cmd);
                break;

            case ModeRequestType.SetChannelModesWithUserLimit:
                AddChannelUserLimits(cmd);
                goto default;

            default:
                ChannelMode.ChangeModes(cmd);
                break;
            }
        }
Example #7
0
        public void RemoveBindOnUserAndChannel(ChatChannelUser leaver)
        {
            if (Property.ChannelUsers.Contains(leaver))
            {
                Property.ChannelUsers.TryTake(out leaver);
            }

            if (leaver.UserInfo.JoinedChannels.Contains(this))
            {
                leaver.UserInfo.JoinedChannels.Remove(this);
            }
        }
        public void AddBindOnUserAndChannel(ChatChannelUser joiner)
        {
            if (!Property.ChannelUsers.Contains(joiner))
            {
                Property.ChannelUsers.Add(joiner);
            }

            if (!joiner.UserInfo.JoinedChannels.Contains(this))
            {
                joiner.UserInfo.JoinedChannels.Add(this);
            }
        }
        public void LeaveChannel(ChatChannelUser user, string reason)
        {
            if (Property.IsPeerServer && user.IsChannelCreator)
            {
                KickAllUserAndShutDownChannel(user);
            }
            else
            {
                MultiCastLeave(user, reason);
            }

            RemoveBindOnUserAndChannel(user);
        }
        public virtual bool MultiCastExceptSender(ChatChannelUser sender, string message)
        {
            foreach (var o in Property.ChannelUsers)
            {
                if (o.Session.Id == sender.Session.Id)
                {
                    continue;
                }
                o.Session.SendAsync(message);
            }

            return(true);
        }
        public void MultiCastJoin(ChatChannelUser joiner)
        {
            string joinMessage =
                ChatReply.BuildJoinReply(
                    joiner, Property.ChannelName);

            string modes =
                Property.ChannelMode.GetChannelMode();

            joinMessage +=
                ChatReply.BuildModeReply(
                    Property.ChannelName, modes);

            MultiCast(joinMessage);
        }
        private void RemoveChannelOperator(MODERequest cmd)
        {
            var result = ChannelUsers.Where(u => u.UserInfo.UserName == cmd.UserName);

            if (result.Count() != 1)
            {
                return;
            }
            ChatChannelUser user = result.First();

            if (user.IsChannelCreator)
            {
                user.SetChannelCreator(false);
            }
        }
        public bool GetChannelUserByNickName(string nickname, out ChatChannelUser user)
        {
            var result = Property.ChannelUsers.Where(u => u.Session.UserInfo.NickName == nickname);

            if (result.Count() == 1)
            {
                user = result.First();
                return(true);
            }
            else
            {
                user = null;
                return(false);
            }
        }
        public bool GetChannelUserBySession(ChatSession session, out ChatChannelUser user)
        {
            var result = Property.ChannelUsers.Where(u => u.Session.Equals(session));

            if (result.Count() == 1)
            {
                user = result.First();
                return(true);
            }
            else
            {
                user = null;
                return(false);
            }
        }
        private void RemoveBanOnUser(MODERequest cmd)
        {
            var result = BanList.Where(u => u.UserInfo.NickName == cmd.NickName);

            if (result.Count() == 1)
            {
                ChatChannelUser user = result.First();
                BanList.TryTake(out user);
                return;
            }
            if (result.Count() > 1)
            {
                LogWriter.ToLog(LogEventLevel.Error,
                                $"Multiple user with same nick name in channel {ChannelName}");
            }
        }
Example #16
0
        public void MultiCastJoin(ChatChannelUser joiner)
        {
            string ip          = ((IPEndPoint)joiner.Session.Socket.RemoteEndPoint).Address.ToString();
            string joinMessage =
                ChatCommandBase.BuildMessageRPL(
                    $"{joiner.UserInfo.NickName}!{joiner.UserInfo.UserName}@{ip}",
                    "JOIN", $"{Property.ChannelName}");


            string modes = Property.ChannelMode.GetChannelMode();

            joinMessage += ChatCommandBase.BuildMessageRPL(
                $"{ChatServer.ServerDomain}", $"MODE {Property.ChannelName} {modes}", "");

            MultiCast(joinMessage);
        }
        private void DisableUserVoicePermission(MODERequest cmd)
        {
            var result = ChannelUsers.Where(u => u.UserInfo.UserName == cmd.UserName);

            if (result.Count() != 1)
            {
                return;
            }

            ChatChannelUser user = result.First();

            if (user.IsVoiceable)
            {
                user.SetVoicePermission(false);
            }
        }
        private void AddBanOnUser(MODERequest cmd)
        {
            var result = ChannelUsers.Where(u => u.UserInfo.NickName == cmd.NickName);

            if (result.Count() != 1)
            {
                return;
            }
            ChatChannelUser user = result.First();

            if (BanList.Where(u => u.UserInfo.NickName == cmd.NickName).Count() == 1)
            {
                return;
            }

            BanList.Add(user);
        }
        private void AddChannelOperator(MODERequest cmd)
        {
            // check whether this user is in this channel
            var result = ChannelUsers.Where(u => u.UserInfo.UserName == cmd.UserName);

            if (result.Count() != 1)
            {
                return;
            }
            ChatChannelUser user = result.First();

            //if this user is already in operator we do not add it
            if (user.IsChannelOperator)
            {
                return;
            }
            user.SetChannelOperator(true);
        }
        private void KickAllUserAndShutDownChannel(ChatChannelUser kicker)
        {
            foreach (var user in Property.ChannelUsers)
            {
                //kick all user out
                string kickMsg =
                    ChatReply.BuildKickReply(
                        Property.ChannelName, kicker, user, "Server Hoster leaves channel");

                user.Session.SendAsync(kickMsg);
            }

            ChatChannelManager.RemoveChannel(this);

            GameServer.DeleteSimilarServer(
                kicker.Session.RemoteEndPoint,
                kicker.Session.UserInfo.GameName);
        }
Example #21
0
        public void SendChannelUsersToJoiner(ChatChannelUser joiner)
        {
            string modes = Property.ChannelMode.GetChannelMode();

            string buffer = ChatCommandBase.BuildMessageRPL(
                ChatServer.ServerDomain, $"MODE {Property.ChannelName} {modes}", "");

            string nicks = "";

            foreach (var user in Property.ChannelUsers)
            {
                if (user.IsChannelCreator)
                {
                    nicks += "@" + user.UserInfo.NickName + " ";
                }
                else
                {
                    nicks += user.UserInfo.NickName + " ";
                }
            }

            if (nicks.Length < 3)
            {
                return;
            }
            //if user equals last user in channel we do not add space after it
            nicks = nicks.Substring(0, nicks.Length - 1);

            //check the message :@<nickname> whether broadcast char @ ?
            buffer += ChatCommandBase.BuildNormalRPL(
                ChatResponseType.NameReply,
                $"{joiner.UserInfo.NickName} = {Property.ChannelName}",
                $"{nicks}");
            buffer += ChatCommandBase.BuildNormalRPL(
                ChatResponseType.EndOfNames,
                $"{joiner.UserInfo.NickName} {Property.ChannelName}",
                @"End of /NAMES list.");

            joiner.Session.SendAsync(buffer);
        }
        public void SendChannelUsersToJoiner(ChatChannelUser joiner)
        {
            string modes = Property.ChannelMode.GetChannelMode();

            string buffer =
                ChatReply.BuildModeReply(
                    Property.ChannelName, modes);

            string nicks = "";

            foreach (var user in Property.ChannelUsers)
            {
                if (user.IsChannelCreator)
                {
                    nicks += "@" + user.UserInfo.NickName + " ";
                }
                else
                {
                    nicks += user.UserInfo.NickName + " ";
                }
            }

            if (nicks.Length < 3)
            {
                return;
            }
            //if user equals last user in channel we do not add space after it
            nicks = nicks.Substring(0, nicks.Length - 1);

            //check the message :@<nickname> whether broadcast char @ ?
            buffer += ChatReply.BuildNameReply(
                joiner.UserInfo.NickName, Property.ChannelName, nicks);

            buffer += ChatReply.BuildEndOfNameReply(
                joiner.UserInfo.NickName, Property.ChannelName);

            joiner.Session.SendAsync(buffer);
        }
 public void SetDefaultProperties(ChatChannelUser creator, JOINRequest cmd)
 {
     MaxNumberUser = 200;
     ChannelName   = cmd.ChannelName;
     ChannelMode.SetDefaultModes();
 }
 public bool IsUserExisted(ChatChannelUser user)
 {
     return(GetChannelUserBySession(user.Session, out _));
 }