示例#1
0
        private void Eval_Nudge(User user, byte[] data, uint time)
        {
            if (data.Length == 4)
            {
                if (data.SequenceEqual(new byte[] { 78, 65, 61, 61 }))
                {
                    this.Panel.AnnounceText(GlobalSettings.GetDefaultColorString(GlobalSettings.DefaultColorType.Server, this.BlackBG) + "--- " + StringTemplate.Get(STType.Messages, 6).Replace("+x", user.Name));
                    return;
                }
            }

            if (Settings.GetReg <bool>("receive_nudge", true) && !user.Ignored)
            {
                if (time > this.last_nudge)
                {
                    this.last_nudge = time;
                }
                else
                {
                    return;
                }

                if (ScriptEvents.OnNudgeReceiving(this, user))
                {
                    this.Panel.AnnounceText(GlobalSettings.GetDefaultColorString(GlobalSettings.DefaultColorType.Server, this.BlackBG) + "--- " + StringTemplate.Get(STType.Messages, 5).Replace("+x", user.Name));
                    this.owner_frm.Nudge();
                    this.ShowPopup("cb0t :: " + StringTemplate.Get(STType.Messages, 3), StringTemplate.Get(STType.Messages, 5).Replace("+x", user.Name), PopupSound.None);
                }
                else
                {
                    this.sock.Send(TCPOutbound.NudgeReject(user.Name, this.crypto));
                }
            }
            else
            {
                this.sock.Send(TCPOutbound.NudgeReject(user.Name, this.crypto));
            }
        }
示例#2
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);
        }
示例#3
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;
            }
        }
示例#4
0
        public static byte[][] GetPackets(VoiceRecorderSendMethod m, byte len)
        {
            List <byte[]> packets = new List <byte[]>();

            byte[]      org_data          = RecordBytes();
            uint        ident             = Settings.Time;
            byte        clip_len          = (byte)(len + 2);
            uint        uncompressed_size = (uint)org_data.Length;
            uint        compressed_size   = uncompressed_size;
            List <uint> compress_results  = new List <uint>();

            if (m == VoiceRecorderSendMethod.Opus)
            {
                org_data          = Opus.Encode(org_data);
                uncompressed_size = (uint)org_data.Length;
                List <byte> data_to_send = new List <byte>(org_data);

                if (data_to_send.Count < MAX_CHUNK_SIZE)
                {
                    packets.Add(TCPOutbound.VoiceFirst(ident, clip_len, 0, uncompressed_size, data_to_send.ToArray()));
                }
                else
                {
                    packets.Add(TCPOutbound.VoiceFirst(ident, clip_len, 0, uncompressed_size, data_to_send.ToArray()));
                    data_to_send.RemoveRange(0, MAX_CHUNK_SIZE);

                    while (data_to_send.Count >= MAX_CHUNK_SIZE)
                    {
                        packets.Add(TCPOutbound.VoiceChunk(ident, data_to_send.GetRange(0, MAX_CHUNK_SIZE).ToArray()));
                        data_to_send.RemoveRange(0, MAX_CHUNK_SIZE);
                    }

                    if (data_to_send.Count > 0)
                    {
                        packets.Add(TCPOutbound.VoiceChunk(ident, data_to_send.ToArray()));
                    }
                }
            }
            else
            {
                while (true)
                {
                    byte[] tmp = Zip.Compress(org_data);

                    if (tmp.Length < org_data.Length)
                    {
                        compress_results.Add((uint)tmp.Length);
                        compressed_size = (uint)tmp.Length;
                        org_data        = tmp;
                    }
                    else
                    {
                        break;
                    }
                }

                List <byte> data_to_send          = new List <byte>(org_data);
                List <byte> compress_results_data = new List <byte>();

                for (int i = 0; i < compress_results.Count; i++)
                {
                    compress_results_data.AddRange(BitConverter.GetBytes(compress_results[i]));
                }

                if (data_to_send.Count < MAX_CHUNK_SIZE)
                {
                    packets.Add(TCPOutbound.VoiceFirst(ident, clip_len, (byte)compress_results.Count,
                                                       uncompressed_size, compress_results_data.ToArray().Concat(data_to_send).ToArray()));
                }
                else
                {
                    packets.Add(TCPOutbound.VoiceFirst(ident, clip_len, (byte)compress_results.Count,
                                                       uncompressed_size, compress_results_data.ToArray().Concat(data_to_send.GetRange(0, MAX_CHUNK_SIZE)).ToArray()));

                    data_to_send.RemoveRange(0, MAX_CHUNK_SIZE);

                    while (data_to_send.Count >= MAX_CHUNK_SIZE)
                    {
                        packets.Add(TCPOutbound.VoiceChunk(ident, data_to_send.GetRange(0, MAX_CHUNK_SIZE).ToArray()));
                        data_to_send.RemoveRange(0, MAX_CHUNK_SIZE);
                    }

                    if (data_to_send.Count > 0)
                    {
                        packets.Add(TCPOutbound.VoiceChunk(ident, data_to_send.ToArray()));
                    }
                }
            }

            return(packets.ToArray());
        }