Example #1
0
        private void Eval_UserlistItem(TCPPacketReader packet)
        {
            User   u     = new User();
            ushort files = packet;

            packet.SkipBytes(4);
            u.ExternalIP = packet;
            u.Port       = packet;
            packet.SkipBytes(4);
            u.SupportsPMEnc = ((ushort)packet) == 65535;
            packet.SkipByte();
            u.Name     = packet.ReadString(this.crypto);
            u.LocalIP  = packet;
            u.HasFiles = ((byte)packet) == 1 && files > 0;
            u.Level    = packet;
            u.Age      = packet;
            u.Gender   = packet;
            byte country = packet;

            u.Country = Helpers.CountryCodeToString(country);
            u.Region  = packet.ReadString(this.crypto);

            if (packet.Remaining > 0)
            {
                ClientFeatures features = (ClientFeatures)((byte)packet);
                u.SupportsVC     = ((features & ClientFeatures.CLIENT_SUPPORTS_VC) == ClientFeatures.CLIENT_SUPPORTS_VC);
                u.SupportsOpusVC = ((features & ClientFeatures.CLIENT_SUPPORTS_OPUS_VC) == ClientFeatures.CLIENT_SUPPORTS_OPUS_VC);

                if (u.SupportsOpusVC)
                {
                    u.SupportsVC = true;
                }
            }

            u.IsFriend = Friends.IsFriend(u.Name);

            if (this.users.Find(x => x.Name == u.Name) != null)
            {
                return;
            }

            this.users.Add(u);
            this.Panel.Userlist.AddUserItem(u);
            Scripting.ScriptManager.AddUser(this.EndPoint, u);

            if (u.Name == this.MyName)
            {
                u.IsAway = Settings.IsAway;
                this.Panel.Userlist.MyLevel = u.Level;
            }
        }
Example #2
0
        private void Eval_Redirect(TCPPacketReader packet, uint time)
        {
            if (Settings.GetReg <bool>("block_redirect", false))
            {
                return;
            }

            Redirect redirect = new Redirect();

            redirect.IP   = packet;
            redirect.Port = packet;
            packet.SkipBytes(4);
            redirect.Name     = packet.ReadString(this.crypto);
            redirect.Hashlink = Hashlink.EncodeHashlink(redirect);

            if (ScriptEvents.OnRedirecting(this, redirect))
            {
                this.Credentials.IP   = redirect.IP;
                this.Credentials.Port = redirect.Port;
                this.Credentials.Name = redirect.Name;
                this.ticks            = (time - 19);
                this.state            = SessionState.Sleeping;
                this.sock.Disconnect();
                this.Panel.AnnounceText(StringTemplate.Get(STType.Messages, 15).Replace("+x", redirect.Name));
            }
        }
Example #3
0
        private void Eval_UpdateUserStatus(TCPPacketReader packet)
        {
            String name = packet.ReadString(this.crypto);
            User   u    = this.users.Find(x => x.Name == name);

            if (u != null)
            {
                packet.SkipBytes(13);
                byte level = packet;

                if (u.Level != level)
                {
                    byte before = u.Level;
                    u.Level = level;
                    this.Panel.Userlist.UpdateUserLevel(u, before);
                    ScriptEvents.OnUserLevelChanged(this, u);
                }

                if (u.Name == this.MyName)
                {
                    this.Panel.Userlist.MyLevel = u.Level;
                }
            }
        }
Example #4
0
        public BrowseItem(TCPPacketReader packet, CryptoService c)
        {
            byte b = packet;

            switch (b)
            {
            case 1:
                this.Mime = BrowseType.Audio;
                break;

            case 3:
                this.Mime = BrowseType.Software;
                break;

            case 5:
                this.Mime = BrowseType.Video;
                break;

            case 6:
                this.Mime = BrowseType.Document;
                break;

            case 7:
                this.Mime = BrowseType.Image;
                break;

            default:
                this.Mime = BrowseType.Other;
                break;
            }

            if (packet.Remaining >= 27)
            {
                this.FileSize = ((uint)packet);
                packet.SkipBytes(16);     // ignore - pre 2005 file guid, now uses SHA1

                switch (this.Mime)        // params
                {
                case BrowseType.Audio:    // audio
                    this.param1 = packet; // bit rate
                    this.param3 = packet; // duration
                    break;

                case BrowseType.Video:     // video
                    this.param1 = packet;  // bit rate
                    this.param2 = packet;  // sample rate
                    this.param3 = packet;  // duration
                    break;

                case BrowseType.Image:            // image
                    this.param1 = packet;         // width
                    this.param2 = packet;         // height
                    this.param3 = ((byte)packet); // depth
                    break;
                }

                if (packet.Remaining >= 10)
                {
                    ushort data_size = packet;
                    ushort counter   = 0;

                    while (packet.Remaining >= 2) // details
                    {
                        byte length = packet;
                        byte type   = packet;

                        if (length > packet.Remaining)
                        {
                            break;
                        }

                        switch (type) // could make an object out of these !!
                        {
                        case 1:       // title
                            this.Title = Encoding.UTF8.GetString(packet.ReadBytes(length));
                            break;

                        case 2:     // artist
                            this.Artist = Encoding.UTF8.GetString(packet.ReadBytes(length));
                            break;

                        case 3:     // album
                            this.Album = Encoding.UTF8.GetString(packet.ReadBytes(length));
                            break;

                        case 4:     // category
                            this.Category = Encoding.UTF8.GetString(packet.ReadBytes(length));
                            break;

                        case 5:     // year
                            this.Year = Encoding.UTF8.GetString(packet.ReadBytes(length));
                            break;

                        case 6:     // language
                            this.Language = Encoding.UTF8.GetString(packet.ReadBytes(length));
                            break;

                        case 7:     // url
                            this.URL = Encoding.UTF8.GetString(packet.ReadBytes(length));
                            break;

                        case 8:     // comment
                            this.Comment = Encoding.UTF8.GetString(packet.ReadBytes(length));
                            break;

                        case 9:     // genre
                            this.Genre = Encoding.UTF8.GetString(packet.ReadBytes(length));
                            break;

                        case 10:     // format
                            this.Format = Encoding.UTF8.GetString(packet.ReadBytes(length));
                            break;

                        case 15:     // filename
                            this.FileName = Encoding.UTF8.GetString(packet.ReadBytes(length));
                            break;

                        case 20:     // SHA1 hash
                            this.SHA1Hash = packet.ReadBytes(20);
                            break;

                        case 23:     // path
                            this.Path = Encoding.UTF8.GetString(packet.ReadBytes(length));
                            break;

                        case 24:     // size64
                            this.FileSize = packet;
                            break;
                        }

                        counter += 2;
                        counter += length;

                        if (counter >= data_size)
                        {
                            break;
                        }
                    }
                }
            }

            if (this.Title.Length == 0)
            {
                this.Title = this.FileName;
            }

            this.FileSizeString = this.FileSize > 1024 ? (this.FileSize / 1024).ToString("#,##0") + " KB" : this.FileSize.ToString();
        }
Example #5
0
        private void Eval_Join(TCPPacketReader packet)
        {
            User   u     = new User();
            ushort files = packet;

            packet.SkipBytes(4);
            u.ExternalIP = packet;
            u.Port       = packet;
            packet.SkipBytes(4);
            u.SupportsPMEnc = ((ushort)packet) == 65535;
            packet.SkipByte();
            u.Name     = packet.ReadString(this.crypto);
            u.LocalIP  = packet;
            u.HasFiles = ((byte)packet) == 1 && files > 0;
            u.Level    = packet;
            u.Age      = packet;
            u.Gender   = packet;
            byte country = packet;

            u.Country  = Helpers.CountryCodeToString(country);
            u.Region   = packet.ReadString(this.crypto);
            u.IsFriend = Friends.IsFriend(u.Name);

            if (packet.Remaining > 0)
            {
                ClientFeatures features = (ClientFeatures)((byte)packet);
                u.SupportsVC     = ((features & ClientFeatures.CLIENT_SUPPORTS_VC) == ClientFeatures.CLIENT_SUPPORTS_VC);
                u.SupportsOpusVC = ((features & ClientFeatures.CLIENT_SUPPORTS_OPUS_VC) == ClientFeatures.CLIENT_SUPPORTS_OPUS_VC);

                if (u.SupportsOpusVC)
                {
                    u.SupportsVC = true;
                }
            }

            User ghost = this.users.Find(x => x.Name == u.Name);

            if (ghost != null)
            {
                this.users.RemoveAll(x => x.Name == ghost.Name);

                if (ghost.Writing)
                {
                    ghost.Writing = false;
                    this.Panel.UpdateWriter(ghost);
                }

                this.Panel.Userlist.RemoveUserItem(ghost);

                if (ScriptEvents.OnUserParting(this, ghost))
                {
                    this.Panel.AnnounceText(GlobalSettings.GetDefaultColorString(GlobalSettings.DefaultColorType.Part, this.BlackBG) + StringTemplate.Get(STType.Messages, 12).Replace("+x", ghost.Name));
                }

                ScriptEvents.OnUserParted(this, ghost);
                Scripting.ScriptManager.RemoveUser(this.EndPoint, u);
                ghost.Dispose();
                ghost = null;
            }

            this.users.Add(u);
            this.Panel.Userlist.AddUserItem(u);
            Scripting.ScriptManager.AddUser(this.EndPoint, u);

            if (ScriptEvents.OnUserJoining(this, u))
            {
                this.Panel.AnnounceText(GlobalSettings.GetDefaultColorString(GlobalSettings.DefaultColorType.Join, this.BlackBG) + StringTemplate.Get(STType.Messages, 13).Replace("+x", u.Name));
            }

            if (u.Name == this.MyName)
            {
                u.IsAway = Settings.IsAway;
                this.Panel.Userlist.MyLevel = u.Level;
            }

            ScriptEvents.OnUserJoined(this, u);

            if (u.IsFriend)
            {
                if (!Settings.GetReg <bool>("block_friend_popup", false))
                {
                    this.ShowPopup("cb0t :: " + StringTemplate.Get(STType.Messages, 4), StringTemplate.Get(STType.Messages, 14).Replace("+x", u.Name).Replace("+y", this.Credentials.Name), PopupSound.Friend);
                }
            }
        }