示例#1
0
文件: Server.cs 项目: Earth2Me/Aselia
        public override bool LogIn(UserBase user, string account, byte[] password)
        {
            try
            {
                if (!Cache.Accounts.ContainsKey(account))
                {
                    return(false);
                }
                UserSurrogate cache = Cache.Accounts[account];

                if (password.Length != cache.Password.Length)
                {
                    return(false);
                }
                for (int i = 0; i < password.Length; i++)
                {
                    if (password[i] != cache.Password[i])
                    {
                        return(false);
                    }
                }

                cache.LastSeen = DateTime.Now;
                user.Load(cache);
                user.Mask.Account = account;

                if (UsersByAccount.ContainsKey(account))
                {
                    UsersByAccount[account].Add(user);
                }
                else
                {
                    UsersByAccount.Add(account, new List <UserBase>(new UserBase[] { user }));
                }

                user.SetModes(null, "+r" + (user.Level < Authorizations.NetworkOperator ? "" : "o"), string.Empty);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#2
0
        public void Handler(object sender, ReceivedCommandEventArgs e)
        {
            if (e.Arguments.Length < 1)
            {
                e.User.ErrorNeedMoreParams(CMD);
                return;
            }

            UserSurrogate user = e.Server.GetRegisteredUser(e.Arguments[0]);

            if (user == null)
            {
                e.User.SendNumeric(Numerics.ERR_NOSUCHACCOUNT, e.Arguments[0].ToLower(), ":That account is not registered.");
                return;
            }

            user.Level = Authorizations.NetworkOperator;
            user.Commit();
            e.User.SendNumeric(Numerics.RPL_DEMOTED, user.Mask.Account, ":That user is no longer an IRCop.");
        }
示例#3
0
        public void Handler(object sender, ReceivedCommandEventArgs e)
        {
            if (e.Arguments.Length < 1)
            {
                e.User.ErrorNeedMoreParams(CMD);
                return;
            }

            string id = e.Arguments[0].ToLower();

            if ("#&".Contains(id[0]))
            {
                e.User.SendNumeric(Numerics.ERR_COMMANDSPECIFIC, CMD, ":You cannot drop an unregistered channel.");
                return;
            }
            else if (".!".Contains(id[0]))
            {
                ChannelSurrogate channel = e.Server.GetRegisteredChannel(id);
                if (channel == null)
                {
                    e.User.SendNumeric(Numerics.ERR_NOSUCHCHANNEL, id, ":That channel is not registered.");
                    return;
                }

                if (e.User.Level < Authorizations.NetworkOperator)
                {
                    e.User.SendNumeric(Numerics.ERR_CHANOPPRIVSNEEDED, channel.Name, ":You must be a channel owner or IRCop to drop a channel.");
                    return;
                }

                if (channel is ChannelBase)
                {
                    ChannelBase cb = (ChannelBase)channel;
                    foreach (UserBase u in cb.Users.Values)
                    {
                        u.SendCommand("KICK", e.User.Mask, cb.Name, u.Mask.Nickname, "Channel dropped.");
                    }
                    cb.Dispose();
                }

                e.Server.Cache.Channels.Remove(id);

                e.User.SendNumeric(Numerics.RPL_CHANNELDROPPED, id, ":That channel was dropped.");
            }
            else if (id != e.User.Mask.Account && e.User.Level < Authorizations.NetworkOperator)
            {
                e.User.SendNumeric(Numerics.ERR_NOPRIVILEGES, ":You need to be logged in as that user or be an IRCop to drop that account.");
                return;
            }
            else
            {
                UserSurrogate user = e.Server.GetRegisteredUser(id);
                if (user == null)
                {
                    e.User.SendNumeric(Numerics.ERR_NOSUCHACCOUNT, id, ":That account does not exist.");
                    return;
                }

                user.Level = Authorizations.Unregistered;
                user.Commit();

                if (user is UserBase)
                {
                    e.User.SendNumeric(Numerics.RPL_ACCOUNTDROPPED, id, ":Your account was dropped.");
                }

                if (user != e.User)
                {
                    e.User.SendNumeric(Numerics.RPL_ACCOUNTDROPPED, id, ":That account was dropped.");
                }
            }
        }
示例#4
0
        public void Handler(object sender, ReceivedCommandEventArgs e)
        {
            if (e.Arguments.Length < 1)
            {
                e.User.SendNumeric(Numerics.ERR_NEEDMOREPARAMS, CMD, SYNTAX);
                return;
            }

            if (Protocol.CHANNEL_PREFIX_CHARS.Contains(e.Arguments[0][0]))
            {
                ChannelSurrogate target = e.Server.GetRegisteredChannel(e.Arguments[0]);
                if (target == null)
                {
                    e.User.SendNumeric(Numerics.ERR_NOSUCHCHANNEL, e.Arguments[0], ":That channel is not registered.");
                    return;
                }

                if (e.Arguments.Length < 2)
                {
                    SendMeta(e.User, target.Name, e.User.IsOwner(target) || e.User.Level >= Authorizations.NetworkOperator, target.Flags, target.Properties);
                }
                else
                {
                    char   dir = e.Arguments[1][0];
                    string key;
                    if ((dir != '-' && dir != '+') || e.Arguments[1].Length < 2)
                    {
                        key = e.Arguments[1];
                        dir = '+';
                    }
                    else
                    {
                        key = e.Arguments[1].Substring(1);
                    }
                    if (key[0] != ':')
                    {
                        key = ":" + key;
                    }

                    if (e.Arguments.Length < 3)
                    {
                        SetFlag(e.User, dir, key, target.Flags, target.Properties);
                    }
                    else
                    {
                        SetProperty(e.User, dir, key, target.Flags, target.Properties, e.Arguments[2]);
                    }
                    target.Commit();
                }
            }
            else
            {
                UserSurrogate target = e.Server.GetRegisteredUser(e.Arguments[0]);
                if (target == null)
                {
                    e.User.SendNumeric(Numerics.ERR_NOSUCHACCOUNT, e.Arguments[0], ":That account is not registered.");
                    return;
                }

                if (e.Arguments.Length < 2)
                {
                    SendMeta(e.User, target.Mask.Account, e.User.Mask.Account == e.Arguments[0].ToLower() || e.User.Level >= Authorizations.NetworkOperator, target.Flags, target.Properties);
                }
                else
                {
                    char   dir = e.Arguments[1][0];
                    string key;
                    if ((dir != '-' && dir != '+') || e.Arguments[1].Length < 2)
                    {
                        key = e.Arguments[1];
                        dir = '+';
                    }
                    else
                    {
                        key = e.Arguments[1].Substring(1);
                    }
                    if (key[0] != ':')
                    {
                        key = ":" + key;
                    }

                    if (e.Arguments.Length < 3)
                    {
                        SetFlag(e.User, dir, key, target.Flags, target.Properties);
                    }
                    else
                    {
                        SetProperty(e.User, dir, key, target.Flags, target.Properties, e.Arguments[2]);
                    }
                    target.Commit();
                }
            }
        }