Beispiel #1
0
 public void Use(Client client, string[] tokens)
 {
     int newTime = -1;
     if (tokens.Length < 2)
     {
         client.SendMessage("You must specify an explicit time, day, or night.");
         return;
     }
     if (int.TryParse(tokens[1], out newTime) && newTime >= 0 && newTime <= 24000)
     {
         client.Owner.World.Time = newTime;
     }
     else if (tokens[1].ToLower() == "day")
     {
         client.Owner.World.Time = 0;
     }
     else if (tokens[1].ToLower() == "night")
     {
         client.Owner.World.Time = 12000;
     }
     else
     {
         client.SendMessage("You must specify a time value between 0 and 24000");
         return;
     }
     client.Owner.Server.Broadcast(new TimeUpdatePacket { Time = client.Owner.World.Time });
 }
Beispiel #2
0
        public void DamageMob(Client hitBy = null)
        {
            if (hitBy != null)
            {
                // TODO: Get the Clients held item.
                this.Health -= 1;
            }
            else
            {
                // TODO: Generic damage from falling/lava/fire?
                this.Health -= 1;
            }

            foreach (Client c in World.Server.GetNearbyPlayers(World, Position.X, Position.Y, Position.Z))
            {
                c.PacketHandler.SendPacket(new AnimationPacket // Hurt Animation
                {
                    Animation = 2,
                    PlayerId = this.EntityId
                });

                c.PacketHandler.SendPacket(new EntityStatusPacket // Hurt Action
                {
                    EntityId = this.EntityId,
                    EntityStatus = 2
                });
            }

            // TODO: Entity Knockback

            if (this.Health == 0) HandleDeath(hitBy);
        }
Beispiel #3
0
        public void Use(Client client, string commandName, string[] tokens)
        {
            Vector3 facing = new Vector3(client.Owner.Yaw, client.Owner.Pitch);

            Vector3 start = new Vector3(client.Owner.Position.X, client.Owner.Position.Y + client.Owner.EyeHeight, client.Owner.Position.Z);
            Vector3 end = facing * 100 + start;
            if (end.Y < 0)
            {
                end = end * (Math.Abs(end.Y) / start.Y);
                end.Y = 0;
            }

            RayTraceHitBlock hit = client.Owner.World.RayTraceBlocks(new AbsWorldCoords(start), new AbsWorldCoords(end));

            if (hit != null)
            {
                if (tokens.Length == 0)
                {
                }
                else
                {
                    MobType mobType;
                    if (Enum.TryParse<MobType>(tokens[0], true, out mobType))
                    {
                        Mob theMob = MobFactory.CreateMob(client.Owner.World, client.Server.AllocateEntity(), mobType, null);
                        theMob.Position = new AbsWorldCoords(client.Owner.World.FromFace(hit.TargetBlock, hit.FaceHit));
                        client.Server.AddEntity(theMob);
                    }
                    else
                    {
                        client.SendMessage(String.Format("Unrecognised mob type: '{0}'", tokens[0]));
                    }
                }
            }
        }
Beispiel #4
0
        public void Use(Client client, string commandName, string[] tokens)
        {
            if (client.Point2 == null || client.Point1 == null)
            {
                client.SendMessage("§cPlease select a cuboid first.");
                return;
            }

            UniversalCoords start = client.SelectionStart.Value;
            UniversalCoords end = client.SelectionEnd.Value;

            ItemStack item = client.Owner.Server.Items[tokens[0]];
            if (ItemStack.IsVoid(item))
            {
                client.SendMessage("§cUnknown item.");
                return;
            }

            if (item.Type > 255)
            {
                client.SendMessage("§cInvalid item.");
            }

            for (int x = start.WorldX; x <= end.WorldX; x++)
            {
                for (int y = start.WorldY; y <= end.WorldY; y++)
                {
                    for (int z = start.WorldZ; z <= end.WorldZ; z++)
                    {
                        client.Owner.World.SetBlockAndData(UniversalCoords.FromWorld(x, y, z), (byte)item.Type, (byte)item.Durability);
                    }
                }
            }
        }
Beispiel #5
0
        protected override void DoInteraction(Client client, Interfaces.ItemStack item)
        {
            base.DoInteraction(client, item);

            if (client != null && !Chraft.Interfaces.ItemStack.IsVoid(item))
            {
                if (item.Type == (short)Chraft.World.BlockData.Items.Shears && !Data.Sheared)
                {
                    // Drop wool when sheared
                    sbyte count = (sbyte)Server.Rand.Next(2, 4);
                    if (count > 0)
                        Server.DropItem(World, UniversalCoords.FromWorld(Position.X, Position.Y, Position.Z), new Interfaces.ItemStack((short)Chraft.World.BlockData.Blocks.Wool, count, (short)Data.WoolColor));
                    Data.Sheared = true;

                    SendMetadataUpdate();
                }
                else if (item.Type == (short)Chraft.World.BlockData.Items.Ink_Sack)
                {
                    // Set the wool colour of this Sheep based on the item.Durability
                    // Safety check. Values of 16 and higher (color do not exist) may crash the client v1.8.1 and below
                    if (item.Durability >= 0 && item.Durability <= 15)
                    {
                        //this.Data.WoolColor = (WoolColor)Enum.ToObject(typeof(WoolColor), (15 - item.Durability));
                        Data.WoolColor = DyeColorToWoolColor((MetaData.Dyes)Enum.ToObject(typeof(MetaData.Dyes), item.Durability));
                        SendMetadataUpdate();
                    }
                }
            }
        }
Beispiel #6
0
 public void Use(Client client, string[] tokens)
 {
     if (tokens.Length < 2)
     {
         client.SendMessage("§cUsage <player> <mode>");
         return;
     }
     Client c = client.Owner.Server.GetClients(tokens[1]).FirstOrDefault();
     if (c != null)
     {
         if (c.Owner.GameMode == Convert.ToByte(tokens[2]))
         {
             client.SendMessage("§7You are already in that mode");
             return;
         }
         c.SendPacket(new NewInvalidStatePacket
         {
             GameMode = c.Owner.GameMode = Convert.ToByte(tokens[2]),
             Reason = NewInvalidStatePacket.NewInvalidReason.ChangeGameMode
         });
     }
     else
     {
         client.SendMessage(string.Format("§cPlayer {0} not found", tokens[1]));
     }
 }
Beispiel #7
0
 public void Use(Client client, string commandName, string[] tokens)
 {
     switch (tokens.Length)
     {
         case 0:
             ChangeGameMode(client, client.Owner.GameMode == 0 ? 1 : 0);
             break;
         case 2:
             if (Int32.Parse(tokens[1]) != 0)
             {
                 if (Int32.Parse(tokens[1]) != 1)
                 {
                     Help(client);
                     break;
                 }
             }
             Client c = client.Owner.Server.GetClients(tokens[0]).FirstOrDefault();
             if (c != null)
             {
                 if (c.Owner.GameMode == Convert.ToByte(tokens[1]))
                 {
                     client.SendMessage(ChatColor.Red + "Player is already in that mode");
                     break;
                 }
                 ChangeGameMode(client, Int32.Parse(tokens[1]));
                 break;
             }
             client.SendMessage(string.Format(ChatColor.Red + "Player {0} not found", tokens[0]));
             break;
         default:
             Help(client);
             break;
     }
 }
Beispiel #8
0
        public void Use(Client client, string[] tokens)
        {
            if (client.Point2 == null || client.Point1 == null)
            {
                client.SendMessage("§cPlease select a cuboid first.");
                return;
            }

            PointI start = client.SelectionStart.Value;
            PointI end = client.SelectionEnd.Value;

            ItemStack item = client.Owner.Server.Items[tokens[1]];
            if (ItemStack.IsVoid(item))
            {
                client.SendMessage("§cUnknown item.");
                return;
            }

            if (item.Type > 255)
            {
                client.SendMessage("§cInvalid item.");
            }

            for (int x = start.X; x <= end.X; x++)
            {
                for (int y = start.Y; y <= end.Y; y++)
                {
                    for (int z = start.Z; z <= end.Z; z++)
                    {
                        client.Owner.World.SetBlockAndData(x, y, z, (byte)item.Type, (byte)item.Durability);
                    }
                }
            }
        }
        public static void ReadCloseWindow(Client client, PacketReader reader)
        {
            CloseWindowPacket cw = new CloseWindowPacket();
            cw.Read(reader);

            if(!reader.Failed)
                Client.HandlePacketCloseWindow(client, cw);
        }
Beispiel #10
0
        public static void ReadChatMessage(Client client, PacketReader reader)
        {
            ChatMessagePacket cm = new ChatMessagePacket();
            cm.Read(reader);

            if (!reader.Failed)
                Client.HandlePacketChatMessage(client, cm);
        }
Beispiel #11
0
        public static void ReadKeepAlive(Client client, PacketReader reader)
        {
            KeepAlivePacket ka = new KeepAlivePacket();
            ka.Read(reader);

            if (!reader.Failed)
                Client.HandlePacketKeepAlive(client, ka);
        }
Beispiel #12
0
        public static void ReadAnimation(Client client, PacketReader reader)
        {
            AnimationPacket ap = new AnimationPacket();
            ap.Read(reader);

            if(!reader.Failed)
                Client.HandlePacketAnimation(client, ap);
        }
Beispiel #13
0
 internal Inventory(Client client)
     : base(InterfaceType.Inventory, 4, 45)
 {
     _ActiveSlot = 36;
     Associate(client);
     _IsOpen = true;
     UpdateClient();
 }
Beispiel #14
0
 private void SetHealth(Client client, short health)
 {
     if (health > 20)
     {
         health = 20;
     }
     client.SendPacket(new UpdateHealthPacket { Health = health });
 }
Beispiel #15
0
 public void Use(Client client, string[] tokens)
 {
     if (tokens.Length < 2)
     {
         SetHealth(client, 20);
         return;
     }
     SetHealth(client, short.Parse(tokens[1]));
 }
Beispiel #16
0
 public void Use(Client client, string[] tokens)
 {
     string message = "";
     for (int i = 1; i < tokens.Length; i++)
     {
         message += tokens[i] + " ";
     }
     client.Owner.Server.Broadcast(message);
 }
Beispiel #17
0
 public void Use(Client client, string[] tokens)
 {
     client.Owner.Server.Broadcast("The server is shutting down.");
     client.Owner.Server.Logger.Log(Logger.LogLevel.Info, "The server is shutting down.");
     Thread.Sleep(5000);
     client.Owner.Server.Stop();
     Thread.Sleep(10);
     Console.WriteLine("Press Enter to exit.");
 }
Beispiel #18
0
 internal Inventory(Client client)
     : base(InterfaceType.Inventory, 4, 45)
 {
     _ActiveSlot = 36;
     Associate(client);
     _IsOpen = true;
     // Inventory is always WindowId 0
     Handle = 0;
     UpdateClient();
 }
Beispiel #19
0
 public Player(Server server, int entityId, Client client)
     : base(server, entityId, null)
 {
     _client = client;
     EnsureServer(server);
     Inventory = null;
     DisplayName = client.Username;
     InitializePosition();
     PermHandler = new PermissionHandler(server);
 }
Beispiel #20
0
 public void Use(Client client, string commandName, string[] tokens)
 {
     short newHealth = 20;
     if (tokens.Length > 0)
     {
         if (!short.TryParse(tokens[0], out newHealth))
             newHealth = 20;
     }
     client.Owner.SetHealth(newHealth);
 }
Beispiel #21
0
        public void Use(Client client, string commandName, string[] tokens)
        {
            MobType type = MobType.Sheep;
            int amount = 1;
            bool validMob = false;

            if (tokens.Length > 1)
                Int32.TryParse(tokens[1], out amount);

            if (tokens.Length > 0)
            {
                int mobId;
                Int32.TryParse(tokens[0], out mobId);
                string mobName = Enum.GetName(typeof(MobType), mobId);
                if (mobId == 0)
                {
                    if (mobId.ToString() != tokens[0])
                    {
                        Enum.TryParse(tokens[0], true, out type);
                        validMob = true;
                    }
                }
                else if (!string.IsNullOrEmpty(mobName))
                {
                    type = (MobType)Enum.Parse(typeof(MobType), mobName);
                    validMob = true;
                }
            }
            else
                validMob = true;

            if (amount < 1 || !validMob)
            {
                Help(client);
                return;
            }

            for (int i = 0; i < amount; i++)
            {
                var mob = MobFactory.CreateMob(client.Owner.World, client.Server.AllocateEntity(), type, null);
                mob.Position = client.Owner.Position;

                //Event
                Chraft.Plugins.Events.Args.EntitySpawnEventArgs e = new Chraft.Plugins.Events.Args.EntitySpawnEventArgs(mob, mob.Position);
                client.Server.PluginManager.CallEvent(Plugins.Events.Event.EntitySpawn, e);
                if (e.EventCanceled)
                    continue;
                mob.Position = e.Location;
                //End Event

                client.Server.AddEntity(mob);
            }
        }
Beispiel #22
0
 public void Use(Client client, string[] tokens)
 {
     MobType type;
     int amount = 1;
     if(tokens.Length > 2)amount = parseint(tokens[2]);
     try
     {
         type = (MobType) Enum.Parse(typeof(MobType), tokens[1], true);
     }
     catch (Exception e) { client.Logger.Log(e); type = MobType.Sheep; }
     for (int i = 0; i < amount; i++)
     {
         client.Owner.World.SpawnMob((int)client.Owner.Position.X, (int)client.Owner.Position.Y, (int)client.Owner.Position.Z, type);
     }
 }
Beispiel #23
0
        public void Use(Client client, string commandName, string[] tokens)
        {
            if (tokens.Length == 0)
            {
                client.SendMessage(String.Format("§7Your position: X={0:0.00},Y={1:0.00},Z={2:0.00}, Yaw={3:0.00}, Pitch={4:0.00}", client.Owner.Position.X, client.Owner.Position.Y, client.Owner.Position.Z, client.Owner.Yaw, client.Owner.Pitch));
            }
            else if (tokens[0] == "yaw")
            {
                Vector3 z1 = client.Owner.Position.ToVector() + Vector3.ZAxis;
                Vector3 posToZ1 = (client.Owner.Position.ToVector() - z1);

                client.SendMessage(String.Format("§7Player.Position.Yaw {0:0.00}, vector computed yaw (SignedAngle) {1:0.00}", client.Owner.Yaw % 360, Vector3.ZAxis.SignedAngle(Vector3.ZAxis.Yaw(client.Owner.Yaw.ToRadians()), Vector3.ZAxis.Yaw(client.Owner.Yaw.ToRadians()).Yaw(90.0.ToRadians())).ToDegrees()));
                client.SendMessage(String.Format("§7Normalised facing Yaw: " + new Vector3(client.Owner.Position.X, client.Owner.Position.Y, client.Owner.Position.Z).Normalize().Yaw(client.Owner.Yaw % 360).ToString()));
            }
        }
Beispiel #24
0
        public void Use(Client client, string[] tokens)
        {
            if (tokens.Length < 2)
            {
                client.SendMessage("You must specify a player to mute");
                return;
            }

            Client[] matchedClients = client.Owner.Server.GetClients(tokens[1]).ToArray();
            Client clientToMute = null;
            if (matchedClients.Length < 1)
            {
                client.SendMessage("Unknown Player");
                return;
            }
            else if (matchedClients.Length == 1)
            {
                clientToMute = matchedClients[0];
            }
            else if (matchedClients.Length > 1)
            {
                // We've got more than 1 client. I.e. "Test" and "Test123" for the "test" pattern.
                // Looking for exact name match.
                int exactMatchClient = -1;
                for (int i = 0; i < matchedClients.Length; i++)
                {
                    if (matchedClients[i].Owner.DisplayName.ToLower() == tokens[1].ToLower())
                        exactMatchClient = i;
                }

                // If we found the player with the exactly same name - he is our target
                if (exactMatchClient != -1)
                {
                    clientToMute = matchedClients[exactMatchClient];
                } else
                {
                    // We do not found a proper target and aren't going to randomly punish anyone
                    client.SendMessage("More than one player found. Provide the exact name.");
                    return;
                }
            }
            bool clientMuted = clientToMute.Owner.IsMuted;
            clientToMute.Owner.IsMuted = !clientMuted;
            clientToMute.SendMessage(clientMuted ? "You have been unmuted" : "You have been muted");
            client.SendMessage(clientMuted ? clientToMute.Owner.DisplayName + " has been unmuted" : clientToMute.Owner.DisplayName + " has been muted");
        }
Beispiel #25
0
 public void Use(Client client, string[] tokens)
 {
     if (tokens.Length < 2)
     {
         client.SendMessage("§cPlease specify a target.");
         return;
     }
     Client[] targets = client.Owner.Server.GetClients(tokens[1]).ToArray();
     if (targets.Length < 1)
     {
         client.SendMessage("§cUnknown payer.");
         return;
     }
     foreach (Client c in targets)
     {
         c.Owner.World = client.Owner.World;
         c.Owner.TeleportTo(new AbsWorldCoords(client.Owner.Position.X, client.Owner.Position.Y, client.Owner.Position.Z));
     }
 }
Beispiel #26
0
        protected override void DoInteraction(Client client, Chraft.Interfaces.ItemStack item)
        {
            base.DoInteraction(client, item);

            if (!ItemStack.IsVoid(item))
            {
                if ((item.Type == (short)BlockData.Items.Pork || item.Type == (short)BlockData.Items.Grilled_Pork))
                {
                    client.Owner.Inventory.RemoveItem(item.Slot); // consume the item

                    if (this.Data.IsTamed)
                    {
                        // Feed a tame wolf pork chop
                        if (this.Health < this.MaxHealth &&
                            (item.Type == (short)BlockData.Items.Pork || item.Type == (short)BlockData.Items.Grilled_Pork))
                        {
                            if (this.Health < this.MaxHealth)
                            {
                                this.Health += 3; // Health is clamped, no need to check if exceeds MaxHealth
                                SendMetadataUpdate();
                            }
                        }
                    }
                }
                else if (!this.Data.IsTamed && item.Type == (short)BlockData.Items.Bone)
                {
                    // Give a bone
                    this.BonesUntilTamed--;
                    client.Owner.Inventory.RemoveItem(item.Slot); // consume the item

                    if (this.BonesUntilTamed <= 0)
                    {
                        this.Data.IsTamed = true;
                        this.Data.TamedBy = client.Owner.Username;
                        this.Health = this.MaxHealth;
                        // TODO: begin following this.Data.TamedBy
                        SendMetadataUpdate();
                    }
                }
            }
        }
Beispiel #27
0
        public void Use(Client client, string commandName, string[] tokens)
        {
            int newTime = -1;
            if (tokens.Length < 1)
            {
                client.SendMessage("You must specify a time value between 0 and 24000 or <sunrise|day|sunset|night>");
                return;
            }
            if (int.TryParse(tokens[0], out newTime) && newTime >= 0 && newTime <= 24000)
            {
                client.Owner.World.Time = newTime;
            }
            else if (tokens[0].ToLower() == "sunrise")
            {
                client.Owner.World.Time = 0;
            }
            else if (tokens[0].ToLower() == "day")
            {
                client.Owner.World.Time = 6000;
            }
            else if (tokens[0].ToLower() == "sunset")
            {
                client.Owner.World.Time = 12000;
            }

            else if (tokens[0].ToLower() == "night")
            {
                client.Owner.World.Time = 18000;
            }
            else
            {
                client.SendMessage("You must specify a time value between 0 and 24000 or <sunrise|day|sunset|night>");
                return;
            }
            client.Owner.Server.Broadcast(new TimeUpdatePacket { Time = client.Owner.World.Time });
        }
Beispiel #28
0
        internal void RemoveClient(Client client)
        {
            lock (Clients)
                Clients.Remove(client);
            lock (Entities)
                Entities.Remove(client.Owner);

            if (Clients.Count == 0 && !Persistent)
            {
                ContainerFactory.UnloadContainers(this);
                Save();
                World.RemoveChunk(this);
            }
        }
Beispiel #29
0
 internal void AddClient(Client client)
 {
     lock (Clients)
         Clients.Add(client);
     lock (Entities)
         Entities.Add(client.Owner);
 }
Beispiel #30
0
 public static void HandlePacketWindowClick(Client client, WindowClickPacket packet)
 {
     Interface iface = client.Owner.CurrentInterface ?? client.Owner.Inventory;
     iface.OnClicked(packet);
 }