예제 #1
0
        private void Eval_Part(TCPPacketReader packet)
        {
            String name = packet.ReadString(this.crypto);
            User   u    = this.users.Find(x => x.Name == name);

            this.users.RemoveAll(x => x.Name == name);

            if (u != null)
            {
                if (u.Writing)
                {
                    u.Writing = false;
                    this.Panel.UpdateWriter(u);
                }

                this.Panel.Userlist.RemoveUserItem(u);

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

                ScriptEvents.OnUserParted(this, u);
                Scripting.ScriptManager.RemoveUser(this.EndPoint, u);
                u.Dispose();
                u = null;
            }
        }
예제 #2
0
        private void Eval_VC_PM_First(TCPPacketReader packet)
        {
            VoicePlayerInboundItem item = new VoicePlayerInboundItem(packet, this.crypto, this.EndPoint);

            VoicePlayer.Inbound.RemoveAll(x => x.Ident == item.Ident && x.EndPoint.Equals(this.EndPoint));

            if (item.Received)
            {
                item.Save();

                if (!String.IsNullOrEmpty(item.FileName))
                {
                    VoicePlayerItem vc = item.ToVoicePlayerItem(++VoicePlayer.NEXT_SHORTCUT, this.BlackBG);
                    VoicePlayer.Records.Add(vc);
                    User u = this.users.Find(x => x.Name == vc.Sender);

                    if (u != null)
                    {
                        if (!u.Ignored)
                        {
                            if (ScriptEvents.OnVoiceClipReceiving(this, u, true))
                            {
                                this.Panel.PMTextReceived(this, u, vc.Sender, GlobalSettings.GetDefaultColorString(GlobalSettings.DefaultColorType.Server, this.BlackBG) + "--- \\\\voice_clip_#" + vc.ShortCut + " " + StringTemplate.Get(STType.Messages, 8).Replace("+x", vc.Sender), null, PMTextReceivedType.Announce);
                                ScriptEvents.OnVoiceClipReceived(this, u, true);
                            }
                        }
                    }
                }
            }
            else
            {
                VoicePlayer.Inbound.Add(item);
            }
        }
예제 #3
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));
            }
        }
예제 #4
0
        private void Eval_Emote(TCPPacketReader packet)
        {
            String   name = packet.ReadString(this.crypto);
            String   text = packet.ReadString(this.crypto);
            User     u    = this.users.Find(x => x.Name == name);
            AresFont font = null;

            if (u != null)
            {
                if (u.Ignored)
                {
                    return;
                }

                if (u.Font != null)
                {
                    font = u.Font;
                }
            }

            text = ScriptEvents.OnEmoteReceiving(this, name, text);

            if (!String.IsNullOrEmpty(text))
            {
                this.Panel.EmoteText(name, text, font);
                this.Panel.CheckUnreadStatus();
                ScriptEvents.OnEmoteReceived(this, name, text);
            }
        }
예제 #5
0
        private void Eval_Avatar(TCPPacketReader packet)
        {
            String name = packet.ReadString(this.crypto);
            User   u    = this.users.Find(x => x.Name == name);

            if (u != null)
            {
                if (!ScriptEvents.OnUserAvatarReceiving(this, u))
                {
                    return;
                }

                byte[] data = packet;

                if (data.Length <= 10)
                {
                    u.ClearAvatar();
                }
                else
                {
                    u.SetAvatar(data);
                }

                this.Panel.Userlist.UpdateUserAppearance(u);
            }
        }
예제 #6
0
        private void Eval_VC_UserSupported(TCPPacketReader packet)
        {
            String name = packet.ReadString(this.crypto);

            if (packet.Remaining < 2)
            {
                return;
            }

            User user = this.users.Find(x => x.Name == name);

            if (user != null)
            {
                bool can_public = ((byte)packet) == 1;

                if (!can_public)
                {
                    user.SupportsVC     = false;
                    user.SupportsOpusVC = false;
                    this.Panel.Userlist.UpdateUserAppearance(user);
                }
                else if (!user.SupportsVC)
                {
                    user.SupportsVC     = true;
                    user.SupportsOpusVC = false;
                    this.Panel.Userlist.UpdateUserAppearance(user);
                }
            }
        }
예제 #7
0
        private void Eval_StartBrowse(TCPPacketReader packet)
        {
            ushort ident = packet;
            ushort count = packet;

            this.Panel.StartBrowse(ident, count);
        }
예제 #8
0
        private void Eval_BrowseItem(TCPPacketReader packet)
        {
            ushort     ident = packet;
            BrowseItem item  = new BrowseItem(packet, this.crypto);

            this.Panel.BrowseItemReceived(ident, item);
        }
예제 #9
0
        private void Eval_Font(TCPPacketReader packet)
        {
            String name = packet.ReadString(this.crypto);
            User   u    = this.users.Find(x => x.Name == name);

            if (u != null)
            {
                if (packet.Remaining > 2)
                {
                    AresFont f = new AresFont();
                    f.Size     = (int)((byte)packet);
                    f.FontName = packet.ReadString(this.crypto);
                    byte oldN = packet;
                    byte oldT = packet;

                    if (oldN == 255 || oldT == 255)
                    {
                        u.Font = null;
                        return;
                    }

                    if (this.new_sbot)
                    {
                        if (packet.Remaining > 0)
                        {
                            f.NameColor = packet.ReadString(this.crypto);
                        }

                        if (packet.Remaining > 0)
                        {
                            f.TextColor = packet.ReadString(this.crypto);
                        }
                    }

                    if (String.IsNullOrEmpty(f.NameColor))
                    {
                        f.NameColor = Helpers.AresColorToHTMLColor(oldN);
                    }

                    if (String.IsNullOrEmpty(f.TextColor))
                    {
                        f.TextColor = Helpers.AresColorToHTMLColor(oldT);
                    }

                    if (ScriptEvents.OnUserFontChanging(this, u, f))
                    {
                        u.Font = f;
                    }
                }
                else
                {
                    u.Font = null;
                }
            }
        }
예제 #10
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;
            }
        }
예제 #11
0
        private void Eval_VC_Chunk(TCPPacketReader packet)
        {
            String sender = packet.ReadString(this.crypto);
            uint   ident  = packet;
            int    index  = VoicePlayer.Inbound.FindIndex(x => x.EndPoint.Equals(this.EndPoint) && x.Ident == ident);

            byte[] chunk = packet;

            if (index > -1)
            {
                VoicePlayerInboundItem item = VoicePlayer.Inbound[index];
                item.AddChunk(chunk);

                if (item.Received)
                {
                    VoicePlayer.Inbound.RemoveAt(index);
                    item.Save();

                    if (!String.IsNullOrEmpty(item.FileName))
                    {
                        VoicePlayerItem vc = item.ToVoicePlayerItem(++VoicePlayer.NEXT_SHORTCUT, this.BlackBG);
                        VoicePlayer.Records.Add(vc);
                        User u = this.users.Find(x => x.Name == vc.Sender);

                        if (u != null)
                        {
                            if (!u.Ignored)
                            {
                                if (ScriptEvents.OnVoiceClipReceiving(this, u, false))
                                {
                                    if (this.CanAutoPlayVC)
                                    {
                                        vc.Auto = true;
                                        VoicePlayer.QueueItem(vc);
                                    }
                                    else
                                    {
                                        this.Panel.ShowVoice(vc.Sender, vc.ShortCut);
                                    }

                                    ScriptEvents.OnVoiceClipReceived(this, u, false);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #12
0
        private void Eval_URL(TCPPacketReader packet)
        {
            String addr  = packet.ReadString(this.crypto);
            String check = addr.ToUpper();

            if (check.StartsWith("HTTP://") || check.StartsWith("ARLNK://") || check.StartsWith("WWW") || check.StartsWith("HTTPS://"))
            {
                String text = packet.ReadString(this.crypto);
                text = ScriptEvents.OnUrlReceiving(this, text, addr);

                if (!String.IsNullOrEmpty(text))
                {
                    this.Panel.SetURL(text, addr);
                }
            }
        }
예제 #13
0
        private void Eval_Ack(TCPPacketReader packet, uint time)
        {
            this.ticks           = time;
            this.last_lag        = (time - 25);
            this.reconnect_count = 0;
            this.Panel.CheckUnreadStatus();
            this.Panel.Userlist.ClearUserList();
            this.users.ForEach(x => x.Dispose());
            this.users.Clear();
            this.users = new List <User>();
            Scripting.ScriptManager.ClearUsers(this.EndPoint);
            this.Panel.ServerText(StringTemplate.Get(STType.Messages, 18) + "...");
            this.Panel.CanVC(false);
            this.CanVC        = false;
            this.CanOpusVC    = false;
            this.MyName       = packet.ReadString(this.crypto);
            this.Panel.MyName = this.MyName;

            if (packet.Remaining > 0)
            {
                String room_name   = packet.ReadString(this.crypto);
                bool   update_name = false;

                if (!String.IsNullOrEmpty(this.Credentials.Name))
                {
                    if (this.Credentials.Name != room_name)
                    {
                        if (this.EndPoint.Equals(this.Credentials.ToEndPoint()))
                        {
                            update_name = true;
                        }
                    }
                }

                this.Credentials.Name = room_name;

                if (update_name)
                {
                    this.RoomNameChanged(this.Credentials, EventArgs.Empty);
                }
            }

            this.Panel.Userlist.MyLevel = 0;
            this.is_writing             = false;
            this.Panel.ClearWriters();
        }
예제 #14
0
        private void Eval_VC_Supported(TCPPacketReader packet)
        {
            bool supported = ((byte)packet) == 1;

            if (!supported)
            {
                this.CanVC     = false;
                this.CanOpusVC = false;
                this.Panel.CanVC(false);
            }
            else if (!this.CanVC)
            {
                this.CanVC     = true;
                this.CanOpusVC = false;
                this.Panel.CanVC(true);
                this.sock.Send(TCPOutbound.EnableClips());
            }
        }
예제 #15
0
        public void SetCrypto(TCPPacketReader packet)
        {
            byte[] guid = Settings.Guid.ToByteArray();
            byte[] key  = packet;

            using (MD5 md5 = MD5.Create())
                guid = md5.ComputeHash(guid);

            for (int i = (guid.Length - 2); i > -1; i -= 2)
            {
                key = this.d67(key, BitConverter.ToUInt16(guid, i));
            }

            List <byte> list = new List <byte>(key);

            this.Mode = CryptoMode.Encrypted;
            this.IV   = list.GetRange(0, 16).ToArray();
            this.Key  = list.GetRange(16, 32).ToArray();
        }
예제 #16
0
        private void Eval_VC_First(TCPPacketReader packet)
        {
            VoicePlayerInboundItem item = new VoicePlayerInboundItem(packet, this.crypto, this.EndPoint);

            VoicePlayer.Inbound.RemoveAll(x => x.Ident == item.Ident && x.EndPoint.Equals(this.EndPoint));

            if (item.Received)
            {
                item.Save();

                if (!String.IsNullOrEmpty(item.FileName))
                {
                    VoicePlayerItem vc = item.ToVoicePlayerItem(++VoicePlayer.NEXT_SHORTCUT, this.BlackBG);
                    VoicePlayer.Records.Add(vc);
                    User u = this.users.Find(x => x.Name == vc.Sender);

                    if (u != null)
                    {
                        if (!u.Ignored)
                        {
                            if (ScriptEvents.OnVoiceClipReceiving(this, u, false))
                            {
                                if (this.CanAutoPlayVC)
                                {
                                    vc.Auto = true;
                                    VoicePlayer.QueueItem(vc);
                                }
                                else
                                {
                                    this.Panel.ShowVoice(vc.Sender, vc.ShortCut);
                                }

                                ScriptEvents.OnVoiceClipReceived(this, u, false);
                            }
                        }
                    }
                }
            }
            else
            {
                VoicePlayer.Inbound.Add(item);
            }
        }
예제 #17
0
        private void Eval_PersonalMessage(TCPPacketReader packet)
        {
            String name = packet.ReadString(this.crypto);
            String text = packet.ReadString(this.crypto);

            if (!String.IsNullOrEmpty(text))
            {
                text = Helpers.FormatAresColorCodes(text);
            }

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

            if (u != null)
            {
                if (ScriptEvents.OnUserMessageReceiving(this, u, text))
                {
                    u.PersonalMessage = text;
                    this.Panel.Userlist.UpdateUserAppearance(u);
                }
            }
        }
예제 #18
0
        public VoicePlayerInboundItem(TCPPacketReader packet, CryptoService c, IPEndPoint ep)
        {
            this.EndPoint = ep;
            this.Sender   = packet.ReadString(c);
            this.Ident    = packet;
            packet.SkipByte();
            this.compression_count   = packet;
            this.uncompressed_length = packet;

            for (int i = 0; i < this.compression_count; i++)
            {
                this.compressed_length = packet;
            }

            if (this.compressed_length == 0)
            {
                this.compressed_length = this.uncompressed_length;
            }

            this.is_opus = (this.compressed_length == this.uncompressed_length);
            this.data_in.AddRange(((byte[])packet));
        }
예제 #19
0
        private void Eval_Announce(TCPPacketReader packet)
        {
            String str = packet.ReadString(this.crypto);

            str = str.Replace("\r\n", "\0");
            str = str.Replace("\r", "\0");
            str = str.Replace("\n", "\0");
            String[] lines = str.Split(new String[] { "\0" }, StringSplitOptions.None);
            String   text;

            foreach (String l in lines)
            {
                text = l;
                text = ScriptEvents.OnAnnounceReceiving(this, text);

                if (text != null)
                {
                    this.Panel.AnnounceText(text);
                    ScriptEvents.OnAnnounceReceived(this, text);
                }
            }
        }
예제 #20
0
        private void Eval_Private(TCPPacketReader packet)
        {
            if (!Settings.GetReg <bool>("can_receive_pms", true))
            {
                return;
            }

            String name = packet.ReadString(this.crypto);
            String text = packet.ReadString(this.crypto);
            User   u    = this.users.Find(x => x.Name == name);

            if (u == null)
            {
                return;
            }

            AresFont font = null;

            if (u.Font != null)
            {
                font = u.Font;
            }

            if (u.Ignored)
            {
                return;
            }

            text = ScriptEvents.OnPmReceiving(this, u, text);

            if (!String.IsNullOrEmpty(text))
            {
                this.Panel.PMTextReceived(this, u, name, text, font, PMTextReceivedType.Text);
                this.Panel.CheckUnreadStatus();
                ScriptEvents.OnPmReceived(this, u, text);
            }
        }
예제 #21
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;
                }
            }
        }
예제 #22
0
        private void CustomProtoReceived(TCPPacketReader packet, uint time)
        {
            String command = packet.ReadString(this.crypto);
            String sender  = packet.ReadString(this.crypto);
            User   u       = this.users.Find(x => x.Name == sender);

            ulong lag;
            bool  b;

            switch (command)
            {
            case "cb0t_writing":
                if (u == null)
                {
                    return;
                }
                b = ((byte)packet) == 2;

                if (b != u.Writing)
                {
                    u.Writing = b;
                    this.Panel.UpdateWriter(u);
                    ScriptEvents.OnUserWritingStatusChanged(this, u);
                }
                break;

            case "cb0t_latency_check":
                lag = (Helpers.UnixTimeMS - ((ulong)packet));
                this.Panel.Userlist.UpdateLag(lag);
                break;

            case "cb0t_latency_mcheck":
                lag = (Helpers.UnixTimeMS - ((ulong)packet));
                this.sock.Send(TCPOutbound.Public(StringTemplate.Get(STType.Messages, 7) + ": " + lag + " milliseconds", this.crypto));
                break;

            case "cb0t_online_status":
                if (u == null)
                {
                    return;
                }
                b = ((byte)packet) != 1;

                if (u.IsAway != b)
                {
                    u.IsAway = b;
                    this.Panel.Userlist.UpdateUserAppearance(u);
                    ScriptEvents.OnUserOnlineStatusChanged(this, u);
                }

                break;

            case "cb0t_nudge":
                if (u == null)
                {
                    return;
                }
                this.Eval_Nudge(u, ((byte[])packet), time);
                break;

            case "cb0t_pm_msg":
                if (u == null)
                {
                    return;
                }
                this.Eval_cb0t_pm_msg(u, ((byte[])packet));
                break;

            case "cb0t_scribble_once":
                if (u != null)
                {
                    u.ScribbleBuffer = new List <byte>();
                    u.ScribbleBuffer.AddRange((byte[])packet);
                    this.Eval_Scribble(u);
                }
                else if (String.IsNullOrEmpty(sender))
                {
                    this.unknown_scribble_buffer = new List <byte>();
                    this.unknown_scribble_buffer.AddRange((byte[])packet);
                    this.Eval_Scribble_Unknown();
                }
                break;

            case "cb0t_scribble_first":
                if (u != null)
                {
                    u.ScribbleBuffer = new List <byte>();
                    u.ScribbleBuffer.AddRange((byte[])packet);
                }
                else if (String.IsNullOrEmpty(sender))
                {
                    this.unknown_scribble_buffer = new List <byte>();
                    this.unknown_scribble_buffer.AddRange((byte[])packet);
                }
                break;

            case "cb0t_scribble_chunk":
                if (u != null)
                {
                    u.ScribbleBuffer.AddRange((byte[])packet);
                }
                else if (String.IsNullOrEmpty(sender))
                {
                    this.unknown_scribble_buffer.AddRange((byte[])packet);
                }
                break;

            case "cb0t_scribble_last":
                if (u != null)
                {
                    u.ScribbleBuffer.AddRange((byte[])packet);
                    this.Eval_Scribble(u);
                }
                else if (String.IsNullOrEmpty(sender))
                {
                    this.unknown_scribble_buffer.AddRange((byte[])packet);
                    this.Eval_Scribble_Unknown();
                }
                break;

            default:
                if (command.StartsWith("cb3_custom_"))
                {
                    command = command.Substring(11);

                    if (u != null)
                    {
                        String c_text = Encoding.UTF8.GetString((byte[])packet);
                        ScriptEvents.OnCustomDataReceived(this, u, command, c_text);
                    }
                }
                break;
            }
        }
예제 #23
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();
        }
예제 #24
0
        private void Eval_Features(TCPPacketReader packet)
        {
            String version = packet.ReadString(this.crypto);

            this.Credentials.Server = version;
            this.Panel.ServerText(StringTemplate.Get(STType.Messages, 17) + ": " + version);
            this.Panel.Userlist.UpdateServerVersion(version);
            this.should_check_for_current_topic_update = true;

            if (version.StartsWith("sb0t 5."))
            {
                version = version.Substring(version.IndexOf(" ") + 1).Split(' ')[0];
                String vnum_str = new String(version.Where(x => Char.IsNumber(x)).ToArray());

                uint vnum;

                if (!uint.TryParse(vnum_str, out vnum))
                {
                    vnum = 0;
                }

                this.new_sbot = (vnum >= 514);
            }
            else if (version.StartsWith("Ares 2.") || version.StartsWith("Ares_2."))
            {
                this.new_sbot = true; // maybe future Ares Server will support cb0t Custom Fonts?
            }
            ServerFeatures flag = (ServerFeatures)((byte)packet);

            this.CanVC = ((flag & ServerFeatures.SERVER_SUPPORTS_VC) == ServerFeatures.SERVER_SUPPORTS_VC);
            bool has_html        = ((flag & ServerFeatures.SERVER_SUPPORTS_HTML) == ServerFeatures.SERVER_SUPPORTS_HTML);
            bool has_scribble    = ((flag & ServerFeatures.SERVER_SUPPORTS_ROOM_SCRIBBLES) == ServerFeatures.SERVER_SUPPORTS_ROOM_SCRIBBLES);
            bool has_pm_scribble = ((flag & ServerFeatures.SERVER_SUPPORTS_PM_SCRIBBLES) == ServerFeatures.SERVER_SUPPORTS_PM_SCRIBBLES);

            this.CanOpusVC = ((flag & ServerFeatures.SERVER_SUPPORTS_OPUS_VC) == ServerFeatures.SERVER_SUPPORTS_OPUS_VC);
            this.Panel.CanVC(this.CanVC);
            this.Panel.CanScribbleAll(has_scribble);
            this.Panel.CanScribblePM(has_pm_scribble);
            this.Panel.InitScribbleButton();
            this.CanNP = true;

            if (has_html)
            {
                this.Panel.Userlist.AcquireServerIcon(this.EndPoint);
            }

            packet.SkipByte();
            this.Panel.ServerText(StringTemplate.Get(STType.Messages, 16) + ": " + (RoomLanguage)((byte)packet));
            uint cookie = packet;

            if (!String.IsNullOrEmpty(this.Credentials.Password))
            {
                this.sock.Send(TCPOutbound.SecureAdminLogin(this.Credentials.Password, cookie, this.Credentials.IP));
            }

            this.UpdatePersonalMessage();

            if (Avatar.Data != null)
            {
                this.sock.SendTrickle(TCPOutbound.Avatar());
            }

            if (Settings.GetReg <bool>("user_font_enabled", false))
            {
                this.sock.SendTrickle(TCPOutbound.Font(this.new_sbot, this.crypto));
            }

            if (Settings.GetReg <bool>("block_custom_names", false))
            {
                this.sock.SendTrickle(TCPOutbound.BlockCustomNames(true));
            }

            ScriptEvents.OnConnected(this);
        }
예제 #25
0
        private void Eval_HTML(TCPPacketReader packet)
        {
            if (!Settings.CanHTML)
            {
                return;
            }

            String html = packet.ReadString();

            if (html == "<!--MOTDSTART-->")
            {
                this.Panel.SetScreenWidth(true);
                this.IsMOTDReceiving = true;
            }
            else if (html == "<!--MOTDEND-->")
            {
                this.Panel.SetScreenWidth(false);
                this.IsMOTDReceiving = false;
            }
            else
            {
                /* SANDBOXED CUSTOM HTML CONTENT */

                // images
                if (html.StartsWith("<img"))
                {
                    if (Settings.GetReg <bool>("receive_scribbles", true))
                    {
                        if (html.StartsWith("<img ") && !html.Contains("onload="))
                        {
                            html = "<img onload=\"imageLoaded(this)\" " + html.Substring(5);
                        }

                        if (html.LastIndexOf("<") == 0)
                        {
                            this.Panel.ShowCustomHTML(html);
                        }
                    }
                }

                // audio
                else if (html.StartsWith("<audio") && this.IsMOTDReceiving)
                {
                    if (html.LastIndexOf("<") == 0)
                    {
                        this.Panel.ShowCustomHTML(html);
                    }
                }

                // video
                else if (html.StartsWith("<video") && this.IsMOTDReceiving)
                {
                    if (html.LastIndexOf("<") == 0)
                    {
                        this.Panel.ShowCustomHTML(html);
                    }
                }

                // youtube
                else if (html.StartsWith("<!--EMBEDYOUTUBE:") && this.IsMOTDReceiving)
                {
                    html = html.Substring(17);

                    if (html.EndsWith("-->"))
                    {
                        html = html.Substring(0, html.Length - 3);

                        if (html.Length > 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.Append("<iframe width=\"420\" height=\"315\" src=\"http://www.youtube.com/embed/");
                            sb.Append(html);
                            sb.Append("\" frameborder=\"0\" allowfullscreen></iframe>");
                            this.Panel.ShowCustomHTML(sb.ToString());
                            sb.Clear();
                        }
                    }
                }

                // let the script engine decide...
                else if (!html.ToUpper().Contains("<object"))
                {
                    ScriptEvents.OnHTMLReceived(this, html);
                }
            }
        }
예제 #26
0
 private void Eval_FavIcon(TCPPacketReader packet)
 {
     byte[] buf = packet;
     this.Panel.Userlist.HereFavicon(buf);
 }
예제 #27
0
        private void Eval_BrowseError(TCPPacketReader packet)
        {
            ushort ident = packet;

            this.Panel.BrowseError(ident);
        }
예제 #28
0
        private void Eval_EndBrowse(TCPPacketReader packet)
        {
            ushort ident = packet;

            this.Panel.BrowseEnd(ident);
        }
예제 #29
0
        private void Eval_OfflineUser(TCPPacketReader packet)
        {
            String name = packet.ReadString(this.crypto);

            this.Panel.PMTextReceived(null, null, name, StringTemplate.Get(STType.Messages, 9), null, PMTextReceivedType.Announce);
        }
예제 #30
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);
                }
            }
        }