/// <summary> /// Loads all history one date close to center /// </summary> public void LoadAllRange (DateTime date, CoordDouble pos, int dimension) { List<HistoryNode> l = new List<HistoryNode> (); string[] files = Directory.GetFiles ("log/packet/" + date.ToString ("yyyy-MM-dd") + "/"); foreach (string f in files) { LoadFile (l, f); } List<HistoryNode> l2 = new List<HistoryNode> (); players.ClearMarked (); foreach (var n in l) { if (n.Dimension != dimension) continue; if (n.Position.DistanceXZTo (pos) < 10) { l2.Add (n); if (n.Item != null && n.Color == Color.Yellow) Console.WriteLine (n.Username + " picked " + n.Item + " at " + n.Position); players.Mark (n.Username); } } list = l2; if (list.Count > 0) { center = list [0].Timestamp.Date.AddHours (12); } Invalidate (); }
public static WorldRegion GetRegion(List <WorldRegion> list, CoordDouble pos, Dimensions dimension) { if (list == null) { return(null); } foreach (WorldRegion r in list) { if (r.Dimension != (int)dimension) { continue; } if (r.Contains(pos)) { if (r.SubRegions == null) { return(r); } WorldRegion w = GetRegion(r.SubRegions, pos, dimension); if (w == null) { return(r); } else { return(w); } } } return(null); }
/// <summary> /// Warp Player /// </summary> public void Warp(CoordDouble destination, Dimensions dimension, World world) { //Prevent multiple warp commands if (nextWarp > DateTime.Now) { return; //Already warped } nextWarp = DateTime.Now.AddSeconds(5); SendToClient(new SoundEffect("portal.trigger", Session.Position, 0.5, 63)); SendToClient(new SoundEffect("portal.travel", Session.Position, 0.5, 63)); ///Vanilla tp is enough if (Session.Dimension == dimension && Session.World == world) { Session.World.Send("tp " + MinecraftUsername + " " + destination.ToStringClean("0.00")); return; } //Change worlds if (Session.World != world) { SetWorld(world); return; } //Error message this.TellSystem("", "Warp cross dimension never worked in vanilla"); }
public SpeedGuard() { for (int n = 0; n < HistorySpeed.Length; n++) { HistorySpeed [n] = new CoordDouble(); HistoryMax [n] = new CoordDouble(double.MaxValue, double.MaxValue, 1); } }
public static WorldRegion GetRegion(CoordDouble pos, Dimensions dimension, RegionList regions) { if (regions == null) { return(null); } return(GetRegion(regions.List, pos, dimension)); }
public CoordDouble CloneDouble() { CoordDouble c = new CoordDouble(); c.X = X; c.Y = Y; c.Z = Z; return(c); }
public double DistanceTo(CoordDouble other) { if (other == null) return this.Abs; double dx = X - other.X; double dy = Y - other.Y; double dz = Z - other.Z; return Math.Sqrt(dx * dx + dy * dy + dz * dz); }
public double DistanceXZTo(CoordDouble other) { if (other == null) { return(this.Abs); } double dx = X - other.X; double dz = Z - other.Z; return(Math.Sqrt(dx * dx + dz * dz)); }
public WorldRegion(Dimensions dimension, CoordDouble start, CoordDouble end, string name) : this(start.X, end.X, start.Y, end.Y, start.Z, end.Z) { //Avoid zero height regions if (start.Y == end.Y) { end.Y = start.Y + 1; } Dimension = (int)dimension; this.Name = name; }
/// <summary> /// Return what direction the coord is in the region /// </summary> string FromDirection(CoordDouble pos) { //Determine Cardinal or spawn message double dx = (pos.X - (MaxX + MinX) / 2) / (MaxX - MinX); double dy = (pos.Y - (MaxY + MinY) / 2) / (MaxY - MinY); double dz = (pos.Z - (MaxZ + MinZ) / 2) / (MaxZ - MinZ); //string d = dx.ToString("0.00") + ", " + dy.ToString("0.00") + ", " + dz.ToString("0.00") + " "; double ax = Math.Abs(dx); double ay = Math.Abs(dy); double az = Math.Abs(dz); if (ax > ay && ax > az) { if (dx > 0) { return("in the East"); } else { return("in the West"); } } if (ay > ax && ay > az) { if (dy > 0) { return("Above"); } else { return("Below"); } } if (az > ax && az > ay) { if (dz > 0) { return("in the South"); } else { return("in the North"); } } return("-"); }
internal static bool FilterClient(WorldRegion region, Client player, Packet packet) { if (packet.PacketID != PlayerPositionLookClient.ID) { return(false); } CoordDouble pos = player.Session.Position; //Inner region if (region.SubRegions.Count == 0) { return(false); } WorldRegion inner = region.SubRegions[0]; //Find proportions between region edges double dOuter = pos.X - region.MinX; dOuter = Math.Min(dOuter, region.MaxX - pos.X); dOuter = Math.Min(dOuter, pos.Z - region.MinZ); dOuter = Math.Min(dOuter, region.MaxZ - pos.Z); double dInner = inner.MinX - pos.X; dInner = Math.Max(dInner, pos.X - inner.MaxX); dInner = Math.Max(dInner, inner.MinZ - pos.Z); dInner = Math.Max(dInner, pos.Z - inner.MaxZ); double frac = dOuter / (dOuter + dInner); #if DEBUG //player.Tell(frac.ToString("0.00") + ": " + dOuter + " " + dInner); #endif player.SendToClient(NightTime(frac)); return(false); }
public static void Paint(Graphics g, MapControl map, int Width, int Height, CoordDouble center, float scale) { if (map.Dimension > Dimensions.End) return; CoordDouble topleft = center - new CoordDouble(Width / 2 * scale, 0, Height / 2 * scale); //Determine center region int rx = (int)center.X & -512; int rz = (int)center.Z & -512; //Sub region chunk index int scx = (((int)center.X) >> 4) & 0x1F; int scz = (((int)center.Z) >> 4) & 0x1F; //Region changed if (rx != lastCX || rz != lastCY) { lastCX = rx; lastCY = rz; //Load region //lastReg = McaFile.Load(map.Dimension, rx, rz); } //.. if (scale < 1) g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; else g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; float drawSize = regionSize / scale - 1; int xStart = (int)Math.Floor(topleft.X / regionSize) * regionSize; int xEnd = (int)Math.Ceiling((topleft.X + Width * scale) / regionSize) * regionSize; int yStart = (int)Math.Floor(topleft.Z / regionSize) * regionSize; int yEnd = (int)Math.Ceiling((topleft.Z + Height * scale) / regionSize) * regionSize; for (int x = xStart; x <= xEnd; x += regionSize) { for (int z = yStart; z <= yEnd; z += regionSize) { float px = ((x - (float)topleft.X) / scale); float py = ((z - (float)topleft.Z) / scale); if (lastReg != null) { if (x == rx && z == rz) { int subSize = (int)(drawSize / 32) - 1; for (int dx = 0; dx < 32; dx++) { for (int dz = 0; dz < 32; dz++) { float pdx = ((x + (dx << 4) - (float)topleft.X) / scale); float pdy = ((z + (dz << 4) - (float)topleft.Z) / scale); if (lastReg.HasChunk(dx, dz)) { if (dx == scx && dz == scz) { //Highlighted g.FillRectangle(Brushes.Orange, pdx, pdy, subSize, subSize); McaChunk c = lastReg.chunks [dx, dz]; g.DrawString(c.ToString(), font, Brushes.Black, pdx, pdy); } else g.FillRectangle(Brushes.Green, pdx, pdy, subSize, subSize); } } } //Console.WriteLine (lastReg); //using (Image b = Bitmap.FromFile(basePath+path)) // g.DrawImage (b, px, py, drawSize, drawSize); } } string path = McaFile.Path(map.Dimension, x, z); if (File.Exists(path)) { //Draw Age border Color c = Color.FromArgb(128, AgeColor(File.GetLastWriteTime(path))); using (Pen p = new Pen(c)) { p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; g.DrawRectangle(p, px, py, drawSize, drawSize); } g.DrawString((x >> 9) + "," + (z >> 9), font, Brushes.GreenYellow, px, py); } else { //g.DrawRectangle (Pens.Orange, px, py, drawSize, drawSize); //g.DrawString (path, font, Brushes.Purple, px, py); //g.DrawString (scale.ToString (), font, Brushes.Purple, px, py); } } } }
/// <summary> /// Check for speed violations and update position /// </summary> internal void ClientMovement(WorldSession player, CoordDouble newPos) { CoordDouble diff = newPos - player.Position; diff.X = Math.Sqrt(diff.X * diff.X + diff.Z * diff.Z); //diff.Z = dt(later below) #if !DEBUG //Ignore movements in Creative mode if (player.Mode == GameMode.Creative || player.Mode == GameMode.Spectator) { player.SetPositionServer(newPos); return; } #endif //Movements if attached already ignored //Ignore movements withing the attached to item circle if (newPos.Y < -900) { return; } //Ignore initial position if (player.Position.Abs < 1) return; //For statistics, record all y positions //FreqAnalyzer.RecordStep (player, player.Position, newPos); //Ignore large client movements if (diff.X > 8 || diff.Y > 8) { //string msg = "Too large movement: " + player.Position + " to " + newPos; //Log.WritePlayer (player.Client, msg); #if DEBUG //player.Tell(msg); //Console.WriteLine(DateTime.Now + " " + msg); #endif diff = new CoordDouble(); } //Calculate max speed during last update double sec = 0.05; CoordDouble max = new CoordDouble(0, 0, sec); //Effect index int ei = player.EffectSpeed.Active ? player.EffectSpeed.Amplifier + 1 : 0; double fac; if (player.Crouched) fac = LawsOfMinecraft.Crounch; else if (player.Sprinting) fac = LawsOfMinecraft.Sprint; else fac = LawsOfMinecraft.Walk; if (player.OnGround == false) fac += 4; double em = (ei - LawsOfMinecraft.ZeroSpeedEffect) * LawsOfMinecraft.SpeedEffectMultiplier * fac; #if !DEBUG //em += 1.5; //Margin, useful for sprintjumping #endif max.X = em * sec; if (em < LawsOfMinecraft.LadderSpeed) #if DEBUG em = LawsOfMinecraft.LadderSpeed; #else em = LawsOfMinecraft.LadderSpeed + 1; #endif max.Y = em * sec; diff.Z = 0.05; HistoryLastDiff += diff; HistoryLastMax += max; DateTime step = DateTime.Now; if (HistoryLastStep.AddSeconds(1) < DateTime.Now) { if (HistoryLastStep == DateTime.MinValue) HistoryLastStep = step.AddSeconds(-1); //Old length TimeSpan dt = step - HistoryLastStep; HistoryLastStep = step; HistoryLastDiff.Z = dt.TotalSeconds; //Speed calculation //Move forward one step for (int n = HistorySpeed.Length - 1; n > 0; n--) { HistorySpeed [n] = HistorySpeed [n - 1]; HistoryMax [n] = HistoryMax [n - 1]; } HistorySpeed [0] = HistoryLastDiff; HistoryMax [0] = HistoryLastMax; //Skip some ridicoulus speeds if (HistorySpeed [0].X > 20 || HistorySpeed [0].Y > 20) HistorySpeed [0] = new CoordDouble(); //Log distance player.Player.Settings.WalkDistance += HistoryLastDiff.X; HistoryLastDiff = new CoordDouble(); HistoryLastMax = new CoordDouble(); //Speed limits: //Currently no vehicle speeds are recorded here. //Ok, since they are controlled serverside anyway. CoordDouble acc = new CoordDouble(); max = new CoordDouble(); int a = 0; while (a < HistorySpeed.Length) { acc += HistorySpeed [a]; max += HistoryMax [a]; a++; //Step check if (acc.X < max.X && acc.Y < max.Y) break; //Calibrated for time diff if (acc.X / acc.Z < max.X / max.Z && acc.Y / acc.Z < max.Y / max.Z) break; } #if DEBUG string dmsg = a + " "; dmsg += HistorySpeed [0].ToString("0.00"); dmsg += " / "; dmsg += HistoryMax [0].ToString("0.00"); dmsg += " "; dmsg += player.Sprinting ? "S" : "s"; dmsg += player.Crouched ? "C" : "c"; dmsg += " E:"; dmsg += player.EffectSpeed.Active ? "+" + player.EffectSpeed.Amplifier : ""; dmsg += player.EffectSlow.Active ? "-" + player.EffectSlow.Amplifier : ""; /*if (a <= 1) player.Tell(Chat.Green, dmsg); else if (a <= 2) player.Tell(Chat.Yellow, dmsg); else player.TellSystem(Chat.Red, dmsg); */ //Console.WriteLine(player.Player.MinecraftUsername + " " + dmsg); #endif if (a <= 2) return; //no violation whatsoever //Log.WritePlayer (player, "Speed " + a + " seconds"); //for (int n = 0; n < HistorySpeed.Length; n++) { // Log.WritePlayer (player, HistorySpeed [n].ToString ("0.00") + " / " + HistoryMax [n].ToString ("0.00")); #if xDEBUG Console.WriteLine(HistorySpeed [n].ToString ("0.00") + " / " + HistoryMax [n].ToString ("0.00")); #endif //} if (a < HistorySpeed.Length - 3) return; //no visual speed warning player.Player.TellAbove(Chat.Aqua, "SLOW DOWN, speed mods are banned!"); Chatting.Parser.TellAdmin(Chat.Aqua + player.Player.MinecraftUsername + " " + a + " s"); Chatting.Parser.TellAdmin(Chat.Aqua + HistorySpeed [0].ToString("0.00") + " / " + HistoryMax [0].ToString("0.00")); if (a >= HistorySpeed.Length) { #if DEBUG player.TellSystem(Chat.Red, "Speed Ban triggered" + Chat.Yellow + " - only testing"); #else player.Player.BanByServer(DateTime.Now.AddMinutes(30), "Moving too fast(modified client)"); #endif } } }
public double Scalar(CoordDouble p) { return(p.X * X + p.Y * Y + p.Z * Z); }
public static WorldRegion GetRegion(List<WorldRegion> list, CoordDouble pos, Dimensions dimension) { if (list == null) return null; foreach (WorldRegion r in list) { if (r.Dimension != (int)dimension) continue; if (r.Contains(pos)) { if (r.SubRegions == null) return r; WorldRegion w = GetRegion(r.SubRegions, pos, dimension); if (w == null) return r; else return w; } } return null; }
public static WorldRegion GetRegion(CoordDouble pos, Dimensions dimension, RegionList regions) { if (regions == null) return null; return GetRegion(regions.List, pos, dimension); }
/// <summary> /// Check for speed violations and update position /// </summary> internal void ClientMovement(WorldSession player, CoordDouble newPos) { CoordDouble diff = newPos - player.Position; diff.X = Math.Sqrt(diff.X * diff.X + diff.Z * diff.Z); //diff.Z = dt(later below) #if !DEBUG //Ignore movements in Creative mode if (player.Mode == GameMode.Creative || player.Mode == GameMode.Spectator) { player.SetPositionServer(newPos); return; } #endif //Movements if attached already ignored //Ignore movements withing the attached to item circle if (newPos.Y < -900) { return; } //Ignore initial position if (player.Position.Abs < 1) { return; } //For statistics, record all y positions //FreqAnalyzer.RecordStep (player, player.Position, newPos); //Ignore large client movements if (diff.X > 8 || diff.Y > 8) { //string msg = "Too large movement: " + player.Position + " to " + newPos; //Log.WritePlayer (player.Client, msg); #if DEBUG //player.Tell(msg); //Console.WriteLine(DateTime.Now + " " + msg); #endif diff = new CoordDouble(); } //Calculate max speed during last update double sec = 0.05; CoordDouble max = new CoordDouble(0, 0, sec); //Effect index int ei = player.EffectSpeed.Active ? player.EffectSpeed.Amplifier + 1 : 0; double fac; if (player.Crouched) { fac = LawsOfMinecraft.Crounch; } else if (player.Sprinting) { fac = LawsOfMinecraft.Sprint; } else { fac = LawsOfMinecraft.Walk; } if (player.OnGround == false) { fac += 4; } double em = (ei - LawsOfMinecraft.ZeroSpeedEffect) * LawsOfMinecraft.SpeedEffectMultiplier * fac; #if !DEBUG //em += 1.5; //Margin, useful for sprintjumping #endif max.X = em * sec; if (em < LawsOfMinecraft.LadderSpeed) #if DEBUG { em = LawsOfMinecraft.LadderSpeed; } #else { em = LawsOfMinecraft.LadderSpeed + 1; } #endif max.Y = em * sec; diff.Z = 0.05; HistoryLastDiff += diff; HistoryLastMax += max; DateTime step = DateTime.Now; if (HistoryLastStep.AddSeconds(1) < DateTime.Now) { if (HistoryLastStep == DateTime.MinValue) { HistoryLastStep = step.AddSeconds(-1); } //Old length TimeSpan dt = step - HistoryLastStep; HistoryLastStep = step; HistoryLastDiff.Z = dt.TotalSeconds; //Speed calculation //Move forward one step for (int n = HistorySpeed.Length - 1; n > 0; n--) { HistorySpeed [n] = HistorySpeed [n - 1]; HistoryMax [n] = HistoryMax [n - 1]; } HistorySpeed [0] = HistoryLastDiff; HistoryMax [0] = HistoryLastMax; //Skip some ridicoulus speeds if (HistorySpeed [0].X > 20 || HistorySpeed [0].Y > 20) { HistorySpeed [0] = new CoordDouble(); } //Log distance player.Player.Settings.WalkDistance += HistoryLastDiff.X; HistoryLastDiff = new CoordDouble(); HistoryLastMax = new CoordDouble(); //Speed limits: //Currently no vehicle speeds are recorded here. //Ok, since they are controlled serverside anyway. CoordDouble acc = new CoordDouble(); max = new CoordDouble(); int a = 0; while (a < HistorySpeed.Length) { acc += HistorySpeed [a]; max += HistoryMax [a]; a++; //Step check if (acc.X < max.X && acc.Y < max.Y) { break; } //Calibrated for time diff if (acc.X / acc.Z < max.X / max.Z && acc.Y / acc.Z < max.Y / max.Z) { break; } } #if DEBUG string dmsg = a + " "; dmsg += HistorySpeed [0].ToString("0.00"); dmsg += " / "; dmsg += HistoryMax [0].ToString("0.00"); dmsg += " "; dmsg += player.Sprinting ? "S" : "s"; dmsg += player.Crouched ? "C" : "c"; dmsg += " E:"; dmsg += player.EffectSpeed.Active ? "+" + player.EffectSpeed.Amplifier : ""; dmsg += player.EffectSlow.Active ? "-" + player.EffectSlow.Amplifier : ""; /*if (a <= 1) * player.Tell(Chat.Green, dmsg); * else if (a <= 2) * player.Tell(Chat.Yellow, dmsg); * else * player.TellSystem(Chat.Red, dmsg); */ //Console.WriteLine(player.Player.MinecraftUsername + " " + dmsg); #endif if (a <= 2) { return; //no violation whatsoever } //Log.WritePlayer (player, "Speed " + a + " seconds"); //for (int n = 0; n < HistorySpeed.Length; n++) { // Log.WritePlayer (player, HistorySpeed [n].ToString ("0.00") + " / " + HistoryMax [n].ToString ("0.00")); #if xDEBUG Console.WriteLine(HistorySpeed [n].ToString("0.00") + " / " + HistoryMax [n].ToString("0.00")); #endif //} if (a < HistorySpeed.Length - 3) { return; //no visual speed warning } player.Player.TellAbove(Chat.Aqua, "SLOW DOWN, speed mods are banned!"); Chatting.Parser.TellAdmin(Permissions.Ban, Chat.Aqua + player.Player.MinecraftUsername + " " + a + " s"); Chatting.Parser.TellAdmin(Permissions.Ban, Chat.Aqua + HistorySpeed [0].ToString("0.00") + " / " + HistoryMax [0].ToString("0.00")); if (a >= HistorySpeed.Length) { #if DEBUG player.TellSystem(Chat.Red, "Speed Ban triggered" + Chat.Yellow + " - only testing"); #else player.Player.BanByServer(DateTime.Now.AddMinutes(30), "Moving too fast(modified client)"); #endif } } }
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); }
/// <summary> /// Screen point from world coords /// </summary> public Point FromCoord(CoordDouble c) { return FromCoord(c.X, c.Z); }
public CoordDouble Clone() { CoordDouble c = new CoordDouble(); c.X = X; c.Y = Y; c.Z = Z; return c; }
public static void Tp(string player, CoordDouble position, Dimensions dimension) { ControlMessage cm = new ControlMessage(); cm.TP = new TpPlayer(); cm.TP.Username = player; cm.TP.Position = position; cm.TP.Dimension = (int)dimension; Send(cm); }
private bool FilterDirection(CoordInt block) { if (block.X == -1 && block.Y == 255 && block.Z == -1) return false; //Player view is 1.5 above its position CoordDouble offset = block - this.Position + new CoordDouble(0.5, -1, 0.5); CoordDouble unit = new CoordDouble( -Math.Cos(Pitch * Math.PI / 180) * Math.Sin(Yaw * Math.PI / 180), -Math.Sin(Pitch * Math.PI / 180), Math.Cos(Pitch * Math.PI / 180) * Math.Cos(Yaw * Math.PI / 180)); double viewDist = offset.Scalar(unit); double perDist = (offset - unit * viewDist).Abs; #if DEBUG /*this.Tell ("Block: " + block + //"Offset: " + offset.ToString ("0.0") + //" Unit: " + unit.ToString ("0.0") + " Dist: " + viewDist.ToString ("0.0") + " Per: " + perDist.ToString ("0.0")); */ #endif //Ignore extreme values if (perDist > 20) return false; if (viewDist > 20) return false; //Logical max i 0.87 //Dont block anymore since client does not restore uncomfirmed blocks if (perDist > 1.5) { //Log.WritePlayer (this, "Aimed sideways: " + perDist.ToString ("0.00") + " > 0.87"); //return true; } if (viewDist > 6) { //Log.WritePlayer (this, "Aimed too far: " + viewDist.ToString ("0.0") + " > 6.0, " + block); //return true; } if (viewDist < -0.1) { //Log.WritePlayer (this, "Aimed behind: " + viewDist.ToString ("0.0") + " < 0"); //return true; } return false; }
protected override void SetPosition(CoordDouble pos, bool speedguard) { base.SetPosition(pos, speedguard); //AFK detection /*if (AfkPos.DistanceTo(pos) > 1) { AfkTime = DateTime.Now; AfkPos = pos; } if (DateTime.Now - AfkTime > AfkWorld.Timeout) { //Dont go afk world automatically, since it could break book writing //Player.SetWorld(World.AFK); }*/ if (Dimension == Dimensions.Nether && pos.Y > 127 && this.Mode != GameMode.Creative) { Player.Warp(new CoordDouble(16, 200, -16), Dimensions.Overworld, World.Main); return; } }
public double Scalar(CoordDouble p) { return p.X * X + p.Y * Y + p.Z * Z; }
/// <summary> /// Warp Player /// </summary> public void Warp(CoordDouble destination, Dimensions dimension, World world) { //Prevent multiple warp commands if (nextWarp > DateTime.Now) return; //Already warped nextWarp = DateTime.Now.AddSeconds(5); SendToClient(new SoundEffect("portal.trigger", Session.Position, 0.5, 63)); SendToClient(new SoundEffect("portal.travel", Session.Position, 0.5, 63)); ///Vanilla tp is enough if (Session.Dimension == dimension && Session.World == world) { Session.World.Send("tp " + MinecraftUsername + " " + destination.ToStringClean("0.00")); return; } //Change worlds if (Session.World != world) { SetWorld(world); return; } //Error message this.TellSystem("", "Warp cross dimension never worked in vanilla"); }
public virtual bool Contains(CoordDouble p) { return(p.X >= MinX && p.X < MaxX && p.Y >= MinY && p.Y < MaxY && p.Z >= MinZ && p.Z < MaxZ); }
public virtual bool Contains(CoordDouble p) { return p.X >= MinX && p.X < MaxX && p.Y >= MinY && p.Y < MaxY && p.Z >= MinZ && p.Z < MaxZ; }