Пример #1
0
		public static void Update (MineProxy.Control.Player player)
		{
			if (player.Position == null)
				return;
			PlayerHistory ph;
			lock (list) {
				if (list.ContainsKey (player.Username) == false) {
					ph = new PlayerHistory ();
					list.Add (player.Username, ph);
				} else
					ph = list [player.Username];
			}
			ph.UpdateHistory (player);
		}
Пример #2
0
        public static void Update(MineProxy.Control.Player player)
        {
            if (player.Position == null)
            {
                return;
            }
            PlayerHistory ph;

            lock (list) {
                if (list.ContainsKey(player.Username) == false)
                {
                    ph = new PlayerHistory();
                    list.Add(player.Username, ph);
                }
                else
                {
                    ph = list [player.Username];
                }
            }
            ph.UpdateHistory(player);
        }
Пример #3
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            Graphics       g    = e.Graphics;
            PlayerListItem item = (PlayerListItem)Items [e.Index];
            var            p    = item.Item;
            Rectangle      r    = e.Bounds;

            if (p.BannedUntil > DateTime.Now)
            {
                g.FillRectangle(Brushes.Red, e.Bounds);
            }
            else
            {
                if (item.Online)
                {
                    switch (p.Session)
                    {
                    case "VanillaSession":
                    case "RealSession":
                        switch (p.Dimension)
                        {
                        case -1:
                            g.FillRectangle(Brushes.LightPink, e.Bounds);
                            break;

                        case 1:
                            g.FillRectangle(Brushes.Yellow, e.Bounds);
                            break;

                        case 0:
                            g.FillRectangle(Brushes.White, e.Bounds);
                            break;

                        default:
                            throw new NotImplementedException("Dimension: " + p.Dimension);
                        }
                        break;

                    case "HellSession":
                        g.FillRectangle(Brushes.Red, e.Bounds);
                        break;

                    case "GreenSession":
                        g.FillRectangle(Brushes.LightGreen, e.Bounds);
                        break;

                    case "WarpSession":
                        g.FillRectangle(Brushes.Cyan, e.Bounds);
                        break;

                    case "TheConstructSession":
                    case "CastleSession":
                    case "AfkSession":
                        g.FillRectangle(Brushes.LightGray, e.Bounds);
                        break;

                    case "VoidSession":
                    case "PossessSession":
                        g.FillRectangle(Brushes.DarkGray, e.Bounds);
                        break;

                    default:
                        throw new NotImplementedException("Session: " + p.Session);
                    }
                }
                else
                {
                    g.FillRectangle(Brushes.Gray, e.Bounds);
                }
            }
            if (item.Selected)
            {
                g.FillRectangle(Brushes.LightBlue, e.Bounds);
            }

            //e.DrawFocusRectangle ();
            g.DrawRectangle(Pens.Black, r);

            int hScale = 1;
            int vScale = 1;

            //Calculate Speed
            PlayerHistory.HistoryItem[] hist = PlayerHistory.GetHistory(p);
            //double lastHSpeed = 0;
            //double lastVSpeed = 0;
            if (hist != null)
            {
                int dx = Width / hist.Length;

                //int hlw = (int)(hScale * LawsOfMinecraft.LimitRunning);
                //int hlb = (int)(hScale * LawsOfMinecraft.LimitBoat);
                int hlc = (int)(hScale * LawsOfMinecraft.LimitCart);
                //int hll = (int)(vScale * LawsOfMinecraft.LimitStairs);

                //Background
                if (item.Online)
                {
                    //g.FillRectangle (Brushes.Green, r.X, r.Bottom - hlw, r.Width, hlw);
                    //g.FillRectangle (Brushes.Blue, r.X, r.Bottom - hlb, r.Width, hlb - hlw);
                    //g.FillRectangle (Brushes.Gray, r.X, r.Bottom - hlc, r.Width, hlc - hlb);
                    //g.FillRectangle (Brushes.LightCyan, r.X, r.Bottom - hlc - hll, r.Width, hll);
                }
                for (int n = 1; n < hist.Length - 1; n++)
                {
                    CoordDouble speed;
                    if (hist [n + 1] == null || hist [n] == null)
                    {
                        speed = new CoordDouble();
                    }
                    else
                    {
                        speed = (hist [n].Position - hist [n + 1].Position) / PlayerHistory.StepSize.TotalSeconds;
                    }

                    double hspeed = Math.Sqrt(speed.X * speed.X + speed.Z * speed.Z);
                    if (n == 1)
                    {
                        //lastHSpeed = hspeed;
                        //lastVSpeed = speed.Y;
                    }

                    double limit = 5;
                    if (p.AttachedTo > 0) //Boat or Cart
                    {
                        limit = LawsOfMinecraft.LimitCart;
                    }

                    if (hspeed > 12)
                    {
                        hspeed = 12;
                    }

                    int hs = (int)(hScale * hspeed);
                    int hl = (int)(hScale * limit);

                    Brush hBrush = Brushes.LightGreen;
                    if (p.AttachedTo == 333) //Boat
                    {
                        hBrush = Brushes.LightBlue;
                    }
                    if (p.AttachedTo == 328) //Cart
                    {
                        hBrush = Brushes.LightGray;
                    }

                    //Bars
                    if (hs > hl)
                    {
                        g.FillRectangle(hBrush, dx * n, r.Bottom - hl, dx, hl);
                        g.FillRectangle(Brushes.Red, dx * n, r.Bottom - hs, dx, hs - hl);
                    }
                    else
                    {
                        g.FillRectangle(hBrush, dx * n, r.Bottom - hs, dx, hs);
                    }

                    //Y-speed
                    int ycenter = r.Bottom - hlc;
                    int vs      = ycenter - (int)(speed.Y * vScale);
                    if (vs <= r.Y)
                    {
                        vs = r.Y + 1;
                    }
                    if (vs >= r.Bottom)
                    {
                        vs = r.Bottom - 1;
                    }
                    //g.DrawLine (Pens.Black, dx * n, ycenter, dx * (n + 1), ycenter);
                    Pen pen = Pens.Gold;
                    if (speed.Y > limit)
                    {
                        pen = Pens.Red;
                    }
                    g.DrawLine(pen, dx * n, vs, dx * (n + 1), vs);
                }
            }
            string t = p.Username;

            if (p.Chat != null && p.Chat.Timestamp.AddMinutes(1) > DateTime.Now)
            {
                t += "\n" + p.Chat;
            }

            g.DrawString(t, Font, Brushes.Black, r);

            t = p.Session.Replace("Session", "") + ": " + p.Uptime.TotalDays.ToString("0.00") + " D";
            var m = g.MeasureString(t, Font);

            g.DrawString(t, Font, Brushes.Black, Width - m.Width, r.Y);
        }
Пример #4
0
        void DrawPlayer(Graphics g, StatusControl.PlayerListItem i)
        {
            MineProxy.Control.Player p = i.Item;
            if (p.Position == null)
            {
                return;
            }

            CoordDouble np = p.Position.ToMapDimensions((Dimensions)p.Dimension);
            Point       pp = FromCoord(np);

            //Röd Cirkel
            int r = 2;

            if (i.Selected)
            {
                g.DrawEllipse(Pens.Red, pp.X - r, pp.Y - r, r * 2, r * 2);

                //Historik
                var hist = PlayerHistory.GetHistory(p);
                foreach (var hi in hist)
                {
                    if (hi == null)
                    {
                        continue;
                    }
                    Point hp = FromCoord(hi.Position.ToMapDimensions((Dimensions)hi.Dimension));
                    g.DrawEllipse(Pens.Red, hp.X - r, hp.Y - r, r * 2, r * 2);
                }
            }
            //Namnbricka
            Size  size = g.MeasureString(p.Username, Font, 500).ToSize();
            Color back = Color.White;

            if (p.Dimension == -1)
            {
                back = Color.Red;
            }
            if (p.Dimension == 1)
            {
                back = Color.Yellow;
            }
            if (p.Session != "RealSession" && p.Session != "VanillaSession")
            {
                back = Color.Gray;
            }
            using (Brush b = new SolidBrush(System.Drawing.Color.FromArgb(128, back)))
                g.FillRectangle(b, pp.X, pp.Y, size.Width, size.Height);
            if (i.Selected)
            {
                g.DrawRectangle(Pens.White, pp.X, pp.Y, size.Width, size.Height);
            }



            g.DrawString(p.Username, this.Font, Brushes.Black, pp.X, pp.Y);

            //Höjd
            int h = (int)(p.Position.Y / 8);

            g.DrawRectangle(Pens.Black, pp.X, pp.Y - 32, r, 32);
            using (Brush b = new SolidBrush(back))
                g.FillRectangle(b, pp.X, pp.Y - h, r, h);


            //g.DrawLine (Pens.Red, Width / 2, Height / 2, (float)x, (float)y);
        }
Пример #5
0
        static void Run()
        {
            DateTime nextUpdate = DateTime.Now;

            while (active)
            {
                try
                {
                    TcpClient client = new TcpClient();
                    client.Connect(IPAddress.Loopback, port);
                    var stream = client.GetStream();
                    var reader = new BinaryReader(stream);
                    writer = new BinaryWriter(stream);

                    Console.WriteLine("Listening on proxy");

                    Connected = true;

                    while (true)
                    {
                        TimeSpan wait = nextUpdate - DateTime.Now;
                        if (wait.Ticks > 0)
                        {
                            Thread.Sleep(wait);
                        }
                        nextUpdate = DateTime.Now.Add(PlayerHistory.StepSize);

                        //Console.WriteLine ("Sending");
                        ControlMessage cm = new ControlMessage();
                        cm.PlayerUpdate = true;
                        Send(cm);

                        int           length = reader.ReadInt32();
                        byte[]        data   = reader.ReadBytes(length);
                        PlayersUpdate pu     = Json.Deserialize <PlayersUpdate>(data);
                        if (pu.List == null)
                        {
                            continue;
                        }
                        Players = pu;
                        //Console.WriteLine ("Got reply");

                        foreach (var p in Players.List)
                        {
                            PlayerHistory.Update(p);
                        }

                        if (Update != null)
                        {
                            Update();
                        }
                    }
                } catch (SocketException se)
                {
                    Console.WriteLine(se.Message);
                    Thread.Sleep(1000);
                } catch (IOException ioe)
                {
                    Console.WriteLine(ioe.Message);
                    Thread.Sleep(1000);
                } catch (ObjectDisposedException ode)
                {
                    Console.WriteLine(ode.Message);
                    Thread.Sleep(1000);
                } finally
                {
                    Connected = false;
                    if (writer != null)
                    {
                        writer.Dispose();
                    }
                    Players      = new PlayersUpdate();
                    Players.List = new List <MineProxy.Control.Player>();
                    if (Update != null)
                    {
                        Update();
                    }
                }
            }
        }