Aselia.Core.Channel.AddPrefix C# (CSharp) Method

AddPrefix() public method

public AddPrefix ( UserBase user, char add ) : void
user UserBase
add char
return void
        public unsafe override void AddPrefix(UserBase user, char add)
        {
            if (user.Level >= Authorizations.Service)
            {
                return;
            }
            if (add == '$' || add == '!')
            {
                return;
            }
            if (IsSystem && user.Level >= Authorizations.NetworkOperator)
            {
                return;
            }

            if (Prefixes.ContainsKey(user.Mask.Account))
            {
                char[] chars = Prefixes[user.Mask.Account].ToCharArray();

                int max = chars.Length + 1;
                int len = 0;

                char* prefix = stackalloc char[max];

                for (int i = 0; i < CoreProtocol.RANK_CHARS.Length && len < max; i++)
                {
                    char c = CoreProtocol.RANK_CHARS[i];
                    if (add == c || chars.Contains(c))
                    {
                        prefix[len++] = c;
                    }
                }

                Prefixes[user.Mask.Account] = new string(prefix, 0, len);
            }
            else
            {
                Prefixes[user.Mask.Account] = add.ToString();
            }

            Server.Commit(this);
        }

Usage Example

Exemplo n.º 1
0
        public override ChannelBase CreateChannel(string name, UserBase user)
        {
            Channel channel = new Channel(this, name, name.ToLower());

            if (Cache.Channels.ContainsKey(channel.Id))
            {
                channel.Load(Cache.Channels[channel.Id]);
            }
            else
            {
                if (channel.IsSystem && user.Level < Authorizations.NetworkOperator)
                {
                    user.SendNumeric(Numerics.ERR_UNIQOPRIVSNEEDED, ":You need to be a network operator to register a system channel.");
                    return null;
                }

                if (channel.IsRegistered && user.Level < Authorizations.Registered)
                {
                    user.SendNumeric(Numerics.ERR_NOLOGIN, ":You need to be registered to own a channel.  To create a temporary channel, prefix the channel name with # instead of !.");
                    return null;
                }

                channel.AddPrefix(user, '~');

                switch (channel.Name[0])
                {
                case '!':
                    channel.SetModes(null, Settings.DefaultChannelModesReg);
                    break;

                case '#':
                    channel.SetModes(null, Settings.DefaultChannelModesTemp);
                    break;

                case '&':
                    channel.SetModes(null, Settings.DefaultChannelModesLoc);
                    break;
                }
            }

            if (channel != null)
            {
                Channels.Add(channel.Id, channel);
            }

            return channel;
        }