Ejemplo n.º 1
0
        private void UnofficialProtoReceived(PacketReceivedEventArgs e)
        {
            e.Packet.SkipBytes(2);
            TCPMsg msg = (TCPMsg)((byte)e.Packet);

            switch (msg)
            {
            case TCPMsg.MSG_CHAT_SERVER_CRYPTO_KEY:
                this.crypto.SetCrypto(e.Packet);
                this.Panel.Userlist.SetCrypto(true);
                break;

            case TCPMsg.MSG_CHAT_SERVER_CUSTOM_FONT:
                this.Eval_Font(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_VC_SUPPORTED:
                this.Eval_VC_Supported(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_VC_USER_SUPPORTED:
                this.Eval_VC_UserSupported(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_VC_FIRST:
                this.Eval_VC_First(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_VC_CHUNK:
                this.Eval_VC_Chunk(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_CLIENT_VC_FIRST_TO:
                this.Eval_VC_PM_First(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_CLIENT_VC_CHUNK_TO:
                this.Eval_VC_PM_Chunk(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_FAVICON:
                this.Eval_FavIcon(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_NOW_PLAYING_EVENT:
                this.CanNP = ((byte)e.Packet) == 1;
                break;
            }
        }
Ejemplo n.º 2
0
        private void PacketReceived(object sender, PacketReceivedEventArgs e)
        {
            switch (e.Msg)
            {
            case TCPMsg.MSG_CHAT_SERVER_LOGIN_ACK:
                this.Eval_Ack(e.Packet, e.Time);
                break;

            case TCPMsg.MSG_CHAT_SERVER_MYFEATURES:
                this.Eval_Features(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_CHANNEL_USER_LIST:
                this.Eval_UserlistItem(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_CHANNEL_USER_LIST_END:
                this.Eval_UserlistEnds();
                break;

            case TCPMsg.MSG_CHAT_SERVER_ERROR:
                this.Panel.AnnounceText(e.Packet.ReadString(this.crypto));
                break;

            case TCPMsg.MSG_CHAT_SERVER_NOSUCH:
                this.Eval_Announce(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_TOPIC:
                this.Eval_Topic(e.Packet.ReadString(this.crypto), true);
                break;

            case TCPMsg.MSG_CHAT_SERVER_TOPIC_FIRST:
                this.Eval_Topic(e.Packet.ReadString(this.crypto), false);
                break;

            case TCPMsg.MSG_CHAT_SERVER_AVATAR:
                this.Eval_Avatar(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_PERSONAL_MESSAGE:
                this.Eval_PersonalMessage(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_URL:
                this.Eval_URL(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_UPDATE_USER_STATUS:
                this.Eval_UpdateUserStatus(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_JOIN:
                this.Eval_Join(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_PART:
                this.Eval_Part(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_PUBLIC:
                this.Eval_Public(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_EMOTE:
                this.Eval_Emote(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_REDIRECT:
                this.Eval_Redirect(e.Packet, e.Time);
                break;

            case TCPMsg.MSG_CHAT_SERVER_PVT:
                this.Eval_Private(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_ISIGNORINGYOU:
                this.Eval_IsIgnoringYou(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_OFFLINEUSER:
                this.Eval_OfflineUser(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_ADVANCED_FEATURES_PROTOCOL:
                this.UnofficialProtoReceived(e);
                break;

            case TCPMsg.MSG_CHAT_SERVER_CUSTOM_DATA:
                this.CustomProtoReceived(e.Packet, e.Time);
                break;

            case TCPMsg.MSG_CHAT_SERVER_STARTOFBROWSE:
                this.Eval_StartBrowse(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_BROWSEITEM:
                this.Eval_BrowseItem(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_BROWSEERROR:
                this.Eval_BrowseError(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_ENDOFBROWSE:
                this.Eval_EndBrowse(e.Packet);
                break;

            case TCPMsg.MSG_CHAT_SERVER_HTML:
                this.Eval_HTML(e.Packet);
                break;
            }
        }
Ejemplo n.º 3
0
        public bool Service(uint time)
        {
            while (this.data_out.Count > 0)
            {
                try
                {
                    this.sock.Send(this.data_out[0]);
                    this.data_out.RemoveAt(0);
                }
                catch { break; }
            }

            byte[]      buf     = new byte[8192];
            SocketError e       = SocketError.Success;
            int         size    = 0;
            bool        success = true;

            try
            {
                this.avail = this.sock.Available;

                if (this.avail > 8192)
                {
                    this.avail = 8192;
                }

                size = this.sock.Receive(buf, 0, this.avail, SocketFlags.None, out e);
            }
            catch { }

            if (size == 0)
            {
                if (e == SocketError.WouldBlock)
                {
                    this.health = 0;
                }
                else if (this.health++ > 3)
                {
                    this.SockCode = (int)e;
                    success       = false;
                }
            }
            else
            {
                this.health = 0;
                this.data_in.AddRange(buf.Take(size));
            }

            while (this.data_in.Count >= 3)
            {
                ushort len = BitConverter.ToUInt16(this.data_in.ToArray(), 0);

                if (this.data_in.Count >= (len + 3))
                {
                    byte   id     = this.data_in[2];
                    byte[] packet = this.data_in.GetRange(3, len).ToArray();
                    this.data_in.RemoveRange(0, (len + 3));

                    PacketReceivedEventArgs args = new PacketReceivedEventArgs
                    {
                        Msg    = (TCPMsg)id,
                        Packet = new TCPPacketReader(packet),
                        Time   = time
                    };

                    if (args.Msg == TCPMsg.MSG_CHAT_CLIENTCOMPRESSED)
                    {
                        packet = Zip.Decompress(packet);

                        if (packet != null)
                        {
                            if (packet.Length > 0)
                            {
                                this.data_in.InsertRange(0, packet);
                            }
                        }
                    }
                    else
                    {
                        try { this.PacketReceived(null, args); }
                        catch { }
                    }
                }
                else
                {
                    break;
                }
            }

            return(success);
        }