public override void Handle(ChatPacket packet) { string rawmsg = packet.Message; if (rawmsg.StartsWith("/")) { var p = rawmsg.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (p[0] == "/tp") { int x = (int)player.X; int.TryParse(p[1], out x); int y; if (p.Length > 2 && int.TryParse(p[2], out y)) { int z = (int)player.Z; if (p.Length > 3) int.TryParse(p[3], out z); SetPosition(x, y, z, 0, 0); } else { var toPlayer = server.World.EntityHandler.Players.FirstOrDefault(e => e.Name == p[1]); if (toPlayer != null) { SetPosition(toPlayer.X, toPlayer.Y + 2, toPlayer.Z, 0, 0); } else { pipe.SendPacket(new ChatPacket("Couldn't find player " + p[1])); } } } else if (p[0] == "/save") { Broadcast(new ChatPacket("Saving world..")); server.World.ChunkPool.SaveAll(); Broadcast(new ChatPacket(".. done.")); } else if (p[0] == "/time") { if (p.Length == 2) { int time; if (int.TryParse(p[1], out time)) server.World.UpdateTime(time); } } else if (p[0] == "/item") { if (p.Length == 2) { int id; if (int.TryParse(p[1], out id)) pipe.SendPacket(new PlayerAddItemPacket { Count = 255, TypeId = (short)id }); } } else if (p[0] == "/reltp") { int x, y, z; if (p.Length == 4 && int.TryParse(p[1], out x) && int.TryParse(p[2], out y) && int.TryParse(p[3], out z)) SetPosition(player.X + x, player.Y + y, player.Z + z, player.RotationX, player.RotationY); } else { pipe.SendPacket(new ChatPacket("Unknown command: " + p[0])); } return; } string message = String.Format("<{0}> {1}", player.Name, packet.Message); Broadcast(new ChatPacket(message)); }
public virtual void Handle(ChatPacket packet) { Handle(packet as Packet); }