Пример #1
0
        public override bool Equals(object obj)
        {
            if (!(obj is ChatMessagePacket))
            {
                return(false);
            }
            ChatMessagePacket packet = obj as ChatMessagePacket;

            var  properties = typeof(ChatMessagePacket).GetFields();
            bool suc        = true;

            foreach (var prop in properties)
            {
                if (!prop.GetValue(this).Equals(prop.GetValue(obj)))
                {
                    suc = false;
                    break;
                }
            }
            return(suc);
        }
Пример #2
0
        private bool ProcessMessage(string data, string requestUri)
        {
            bool saveNext = saveNextPoll.Value;

            if (data.Contains("\"success\"") && data.Contains("\"data\""))
            {
                return(ProcessUsernameResponce(data, requestUri));
            }

            if (!data.Contains('['))
            {
                //"ok" responce
                return(true);
            }

            List <string> packets = SplitIntoPackets(data);

            bool success = true;

            foreach (string packet in packets)
            {
                JArray objects = JArray.Parse(packet);

                switch (objects[0].ToString())
                {
                case "canvas":
                case "pixels":
                    string             type   = objects[0].ToString();
                    List <PixelPacket> pixels = objects[1].ToObject <List <PixelPacket> >();
                    if (OnEvent != null)
                    {
                        foreach (PixelPacket pixel in pixels)
                        {
                            pixel.instantPixel = saveNext;
                            OnEvent("pixels", pixel);
                        }
                    }
                    break;

                case "cooldown":
                    OnEvent?.Invoke("cooldown", null);
                    break;

                case "protection":
                    OnEvent?.Invoke("protection", null);
                    break;

                case "canvas.access.requested":
                    break;

                case "canvas.alert":
                    break;

                case "throw.error":
                    int errorId = objects[1].ToObject <int>();
                    if (OnEvent != null)
                    {
                        ErrorPacket eventArgs = new ErrorPacket();
                        eventArgs.id = errorId;
                        OnEvent("throw.error", eventArgs);
                        Logger.Error("Error {0} for {1}", errorId, Username);
                    }
                    if (errorId == 0 || errorId == 1 || errorId == 2 || errorId == 6 || errorId == 7 || errorId == 9 || errorId == 10 || errorId == 18 || errorId == 19 || errorId == 20)
                    {
                        Logger.Error("Site error {0} for {1}", errorId, Username);
                        success = false;
                    }
                    break;

                case "chat.user.message":
                    ChatMessagePacket message = objects[1].ToObject <ChatMessagePacket>();
                    OnEvent?.Invoke("chat.user.message", message);
                    break;

                case "chat.system.message":
                    break;

                case "chat.system.delete":
                    break;

                case "chat.system.announce":
                    break;
                }
            }

            if (saveNext)
            {
                saveNextPoll.Value = false;
            }

            return(success);
        }