Exemple #1
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);
            }
        }
Exemple #2
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);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        private void Eval_VC_PM_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, 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);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #4
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);
                }
            }
        }
        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));
        }
Exemple #6
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;
                }
            }
        }
Exemple #7
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);
        }
Exemple #8
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);
                }
            }
        }
Exemple #9
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);
        }
Exemple #10
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);
                }
            }
        }
Exemple #11
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;
            }
        }