Example #1
0
 public PlayerManager(MinecraftServer minecraftserver)
 {
     field_9216_a = new ArrayList();
     field_9215_b = new MCHashTable2();
     field_833_c  = new ArrayList();
     mcServer     = minecraftserver;
 }
Example #2
0
 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     byte[] data = new byte[] {PacketId}
         .Concat(DataUtility.CreateInt32(EntityId))
         .Concat(new byte[] {(byte)Animation}).ToArray();
     client.SendData(data);
 }
Example #3
0
        public override void HandlePacket(MinecraftServer server, MinecraftClient client)
        {
            var target = server.EntityManager.GetEntity(TargetId);
            if (target == null || 
                server.EntityManager.GetEntityWorld(target) != server.EntityManager.GetEntityWorld(client.Entity) ||
                target.Position.DistanceTo(client.Entity.Position) > client.Reach)
                return;

            if (target is LivingEntity)
            {
                // Do damage
                if (LeftClick)
                {
                    var livingEntity = target as LivingEntity;
                    if (livingEntity.Invulnerable)
                        return;

                    var item = client.Entity.SelectedItem.Item;
                    if (item == null)
                        item = new AirBlock();
                    client.Entity.FoodExhaustion += 0.3f;
                    livingEntity.Damage(item.AttackDamage);
                    livingEntity.Velocity /*+*/= DataUtility.RotateY(new Vector3(0, 0, client.Entity.IsSprinting ? 10 : 3),
                                                                     // TODO: Knockback enchantment
                                                                     DataUtility.DegreesToRadians(client.Entity.Yaw));
                    if (livingEntity is PlayerEntity)
                    {
                        (livingEntity as PlayerEntity).LastDamageType = DamageType.Combat;
                        (livingEntity as PlayerEntity).LastAttackingEntity = client.Entity;
                    }
                    // TODO: Physics
                }
            }
        }
        public override void SendPacket(MinecraftServer server, MinecraftClient client)
        {
            // TODO: Refactor like mad
            var buffer = new List<byte>();
            buffer.Add(PacketId);
            buffer.AddRange(DataUtility.CreateInt32(Item.Id));
            if (Item.Item.Empty)
                buffer.AddRange(DataUtility.CreateInt16(-1));
            else
            {
                buffer.AddRange(DataUtility.CreateInt16((short)Item.Item.Id)); // TODO: Make slots use signed shorts
                buffer.Add(Item.Item.Count);
                buffer.AddRange(DataUtility.CreateInt16((short)Item.Item.Metadata));
                buffer.AddRange(DataUtility.CreateInt16(-1)); // TODO: Nbt appears to be sent here
            }

            buffer.AddRange(DataUtility.CreateAbsoluteInteger(Item.Position.X));
            buffer.AddRange(DataUtility.CreateAbsoluteInteger(Item.Position.Y));
            buffer.AddRange(DataUtility.CreateAbsoluteInteger(Item.Position.Z));
            buffer.AddRange(DataUtility.CreatePackedByte(Item.Pitch));
            buffer.AddRange(DataUtility.CreatePackedByte(Item.Pitch));
            buffer.AddRange(DataUtility.CreatePackedByte(Item.Yaw));

            client.SendData(buffer.ToArray());
        }
Example #5
0
 public static void KeepAlive(MinecraftClient client, MinecraftServer server, IPacket _packet)
 {
     var packet = (KeepAlivePacket)_packet;
     // TODO: Confirm value validity
     client.LastKeepAlive = DateTime.Now;
     client.Ping = (short)(client.LastKeepAlive - client.LastKeepAliveSent).TotalMilliseconds;
 }
 public static void PlayerLook(RemoteClient client, MinecraftServer server, IPacket _packet)
 {
     var packet = (PlayerLookPacket)_packet;
     client.Entity.Pitch = packet.Pitch;
     client.Entity.Yaw = packet.Yaw;
     client.Entity.HeadYaw = packet.Yaw;
 }
Example #7
0
        public static void ClientStatus(MinecraftClient client, MinecraftServer server, IPacket _packet)
        {
            var packet = (ClientStatusPacket)_packet;
            if (packet.Status == ClientStatusPacket.ClientStatus.InitialSpawn)
            {
                // Create a hash for session verification
                SHA1 sha1 = SHA1.Create();
                AsnKeyBuilder.AsnMessage encodedKey = AsnKeyBuilder.PublicKeyToX509(server.ServerKey);
                byte[] shaData = Encoding.UTF8.GetBytes(client.AuthenticationHash)
                    .Concat(client.SharedKey)
                    .Concat(encodedKey.GetBytes()).ToArray();
                string hash = Cryptography.JavaHexDigest(shaData);

                // Talk to session.minecraft.net
                if (server.Settings.OnlineMode)
                {
                    var webClient = new WebClient();
                    var webReader = new StreamReader(webClient.OpenRead(
                        new Uri(string.Format(sessionCheckUri, client.Username, hash))));
                    string response = webReader.ReadToEnd();
                    webReader.Close();
                    if (response != "YES")
                    {
                        client.SendPacket(new DisconnectPacket("Failed to verify username!"));
                        return;
                    }
                }

                server.LogInPlayer(client);
            }
            else if (packet.Status == ClientStatusPacket.ClientStatus.Respawn)
            {
                // TODO
            }
        }
 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     client.SendData(CreateBuffer(
         DataUtility.CreateString(PlayerName),
         DataUtility.CreateBoolean(Online),
         DataUtility.CreateInt16(Ping)));
 }
Example #9
0
        public static void RegisterHandlers(MinecraftServer server)
        {
            server.RegisterPacketHandler(typeof(HandshakePacket), LoginHandlers.Handshake);
            server.RegisterPacketHandler(typeof(LoginStartPacket), LoginHandlers.LoginStart);
            server.RegisterPacketHandler(typeof(EncryptionKeyResponsePacket), LoginHandlers.EncryptionKeyResponse);
            server.RegisterPacketHandler(typeof(ClientStatusPacket), LoginHandlers.ClientStatus);
            server.RegisterPacketHandler(typeof(ClientSettingsPacket), LoginHandlers.ClientSettings);

            server.RegisterPacketHandler(typeof(PlayerPacket), PlayerMovementHandlers.Player);
            server.RegisterPacketHandler(typeof(PlayerPositionPacket), PlayerMovementHandlers.PlayerPosition);
            server.RegisterPacketHandler(typeof(PlayerLookPacket), PlayerMovementHandlers.PlayerLook);
            server.RegisterPacketHandler(typeof(PlayerPositionAndLookPacket), PlayerMovementHandlers.PlayerPositionAndLook);
            server.RegisterPacketHandler(typeof(AnimationPacket), PlayerMovementHandlers.Animation);
            server.RegisterPacketHandler(typeof(EntityActionPacket), PlayerMovementHandlers.EntityAction);
            server.RegisterPacketHandler(typeof(PlayerAbilitiesPacket), PlayerMovementHandlers.PlayerAbilities);

            server.RegisterPacketHandler(typeof(CreativeInventoryActionPacket), InventoryHandlers.CreativeInventoryAction);
            server.RegisterPacketHandler(typeof(ClickWindowPacket), InventoryHandlers.ClickWindow);
            server.RegisterPacketHandler(typeof(CloseWindowPacket), InventoryHandlers.CloseWindow);
            server.RegisterPacketHandler(typeof(HeldItemPacket), InventoryHandlers.HeldItemChange);

            server.RegisterPacketHandler(typeof(PlayerBlockActionPacket), InteractionHandlers.PlayerDigging);
            server.RegisterPacketHandler(typeof(RightClickPacket), InteractionHandlers.RightClick);

            server.RegisterPacketHandler(typeof(StatusRequestPacket), StatusRequest);
            server.RegisterPacketHandler(typeof(StatusPingPacket), StatusPing);
            server.RegisterPacketHandler(typeof(ChatMessagePacket), ChatMessage);
            server.RegisterPacketHandler(typeof(KeepAlivePacket), KeepAlive);
        }
Example #10
0
 public override void HandlePacket(MinecraftServer server, MinecraftClient client)
 {
     if (!client.ReadyToSpawn)
         return;
     client.Entity.Pitch = Pitch;
     client.Entity.Yaw = Yaw;
 }
Example #11
0
        public static void PlayerLook(MinecraftClient client, MinecraftServer server, IPacket _packet)
        {
            var packet = (PlayerLookPacket)_packet;

            client.Entity.Pitch = packet.Pitch;
            client.Entity.Yaw   = packet.Yaw;
        }
        public static void RightClick(RemoteClient client, MinecraftServer server, IPacket _packet)
        {
            var       packet         = (RightClickPacket)_packet;
            var       slot           = client.Entity.Inventory[client.Entity.SelectedSlot];
            var       position       = new Coordinates3D(packet.X, packet.Y, packet.Z);
            var       cursorPosition = new Coordinates3D(packet.CursorX, packet.CursorY, packet.CursorZ);
            BlockInfo?block          = null;

            if (position != -Coordinates3D.One)
            {
                if (position.DistanceTo((Coordinates3D)client.Entity.Position) > client.Reach)
                {
                    return;
                }
                block = client.World.GetBlockInfo(position);
            }
            bool use = true;

            if (block != null)
            {
                use = client.World.RightClickBlock(position, packet.Face, cursorPosition, slot.AsItem());
            }
            if (!slot.Empty)
            {
                var item = slot.AsItem();
                if (use)
                {
                    if (block != null)
                    {
                        client.World.UseItemOnBlock(position, packet.Face, cursorPosition, item.Value);
                        if (item.Value.ItemId < 0x100)
                        {
                            client.SendPacket(new SoundEffectPacket(Block.GetPlacementSoundEffect(item.Value.ItemId),
                                                                    position.X, position.Y, position.Z, SoundEffectPacket.DefaultVolume, SoundEffectPacket.DefaultPitch));
                        }
                        if (client.GameMode != GameMode.Creative)
                        {
                            slot.Count--; // TODO: This is probably a bad place to put this code
                            if (slot.Count == 0)
                            {
                                client.Entity.Inventory[client.Entity.SelectedSlot] = ItemStack.EmptyStack;
                            }
                            else
                            {
                                client.Entity.Inventory[client.Entity.SelectedSlot] = slot;
                            }
                        }
                    }
                    else
                    {
                        client.World.UseItemOnBlock(position, packet.Face, cursorPosition, item.Value);
                        if (item.Value.ItemId < 0x100)
                        {
                            client.SendPacket(new SoundEffectPacket(Block.GetPlacementSoundEffect(item.Value.ItemId),
                                                                    position.X, position.Y, position.Z, SoundEffectPacket.DefaultVolume, SoundEffectPacket.DefaultPitch));
                        }
                    }
                }
            }
        }
Example #13
0
        private static async Task <int> StartUp()
        {
            MinecraftServer server = new MinecraftServer();
            await server.Start();

            return(0);
        }
Example #14
0
        private MinecraftServer mc; /* synthetic field */

        public ThreadSleepForever(MinecraftServer minecraftserver)
        {
            mc = minecraftserver;
//
            setDaemon(true);
            start();
        }
        public List <MinecraftServer> ListServices()
        {
            var services = kservice.ListNamespacedService("default");

            List <MinecraftServer> kservices = new List <MinecraftServer>();

            foreach (var service in services.Items)
            {
                MinecraftServer ms = new MinecraftServer();
                ms.Name = service.Metadata.Name;

                MinecraftEndpoint me = new MinecraftEndpoint();
                if (service.Status.LoadBalancer.Ingress != null)
                {
                    me.Minecraft = service.Status.LoadBalancer.Ingress.FirstOrDefault().Ip + ":" + service.Spec.Ports.FirstOrDefault(x => x.Name.Equals("main")).Port;
                    me.RCon      = service.Status.LoadBalancer.Ingress.FirstOrDefault().Ip + ":" + service.Spec.Ports.FirstOrDefault(x => x.Name.Equals("openhackcheck")).Port;
                }
                else
                {
                    continue;
                }

                ms.Endpoints = me;
                kservices.Add(ms);
            }

            return(kservices);
        }
 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     client.SendData(CreateBuffer(
         DataUtility.CreateInt32((int)SpawnPosition.X),
         DataUtility.CreateInt32((int)SpawnPosition.Y),
         DataUtility.CreateInt32((int)SpawnPosition.Z)));
 }
 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     client.SendData(CreateBuffer(
         DataUtility.CreateInt16(Health),
         DataUtility.CreateInt16(Food),
         DataUtility.CreateFloat(FoodSaturation)));
 }
Example #18
0
        public Server(ISettingsProvider settingsProvider)
        {
            SettingsProvider = settingsProvider;
            // Touch TerrainGeneration to load it into app domain
            FlatlandGenerator.DefaultGeneratorOptions.ToString();
            var generator = Level.GetGenerator(SettingsProvider.Get <string>("level.type"));

            if (generator == null)
            {
                generator = new FlatlandGenerator();
            }
            Level level;

            if (Directory.Exists(SettingsProvider.Get <string>("level.name")))
            {
                level = Level.LoadFrom(SettingsProvider.Get <string>("level.name"));
            }
            else
            {
                level = new Level(generator, SettingsProvider.Get <string>("level.name"));
                level.AddWorld("overworld");
                level.SaveTo(SettingsProvider.Get <string>("level.name"));
            }
            MinecraftServer = new MinecraftServer(level);
            MinecraftServer.Settings.MotD       = SettingsProvider.Get <string>("server.motd");
            MinecraftServer.Settings.OnlineMode = SettingsProvider.Get <bool>("server.onlinemode");
            MinecraftServer.ChatMessage        += MinecraftServerOnChatMessage;
            MinecraftServer.PlayerLoggedIn     += MinecraftServerOnPlayerLoggedIn;
            MinecraftServer.PlayerLoggedOut    += MinecraftServerOnPlayerLoggedOut;
            //MinecraftServer.TabComplete += MinecraftServer_TabComplete;
        }
Example #19
0
 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     client.SendData(CreateBuffer(
         new[] {WindowId},
         DataUtility.CreateInt16(Index),
         Slot.GetData()));
 }
Example #20
0
 private void MinecraftServerOnPlayerLoggedIn(object sender, PlayerLogInEventArgs playerLogInEventArgs)
 {
     playerLogInEventArgs.Handled     = true;
     playerLogInEventArgs.Client.Tags = new Dictionary <string, object>();
     playerLogInEventArgs.Client.Tags.Add("PartyCraft.UserGroups", GetUserGroups(playerLogInEventArgs.Username));
     MinecraftServer.SendChat(string.Format(SettingsProvider.Get <string>("chat.join"), playerLogInEventArgs.Username));
 }
        public static void EntityAction(RemoteClient client, MinecraftServer server, IPacket _packet)
        {
            var packet = (EntityActionPacket)_packet;

            switch (packet.Action)
            {
            case EntityActionPacket.EntityAction.Crouch:
                client.Entity.IsCrouching = true;
                break;

            case EntityActionPacket.EntityAction.Uncrouch:
                client.Entity.IsCrouching = false;
                break;

            case EntityActionPacket.EntityAction.StartSprinting:
                client.Entity.IsSprinting = true;
                break;

            case EntityActionPacket.EntityAction.StopSprinting:
                client.Entity.IsSprinting = false;
                break;
//                case EntityActionPacket.EntityAction.LeaveBed:
//                    client.Entity.LeaveBed();
//                    break;
            }
            if (packet.Action != EntityActionPacket.EntityAction.LeaveBed) // NOTE: Does this matter?
            {
                // TODO ?
            }
        }
Example #22
0
        private MinecraftServer mc; /* synthetic field */

        #endregion Fields

        #region Constructors

        public ThreadSleepForever(MinecraftServer minecraftserver)
        {
            mc = minecraftserver;
            //
            setDaemon(true);
            start();
        }
Example #23
0
        public static void LoginStart(RemoteClient client, MinecraftServer server, IPacket _packet)
        {
            var packet = (LoginStartPacket)_packet;

            if (server.Clients.Any(c => c.IsLoggedIn && c.Username == packet.Username))
            {
                client.Disconnect("You're already on this server!");
            }
            else
            {
                client.Username = packet.Username;
                if (server.Settings.OnlineMode)
                {
                    client.ServerId = CreateId();
                }
                else
                {
                    client.ServerId = CreateId();
                    client.UUID     = Guid.NewGuid().ToJavaUUID();
                }
                if (server.Settings.EnableEncryption)
                {
                    client.SendPacket(CreateEncryptionRequest(client, server));
                }
                else
                {
                    server.LogInPlayer(client);
                }
            }
        }
        public static void PlayerPositionAndLook(RemoteClient client, MinecraftServer server, IPacket _packet)
        {
            var packet = (PlayerPositionAndLookPacket)_packet;

            // Position
            client.Entity.FoodExhaustion += (float)client.Entity.Position.DistanceTo(
                new Vector3(packet.X, packet.Y, packet.Z));// *
            //(client.Entity.IsSprinting ? 0.1f : 0.01f); // TODO: Swimming

            if ((packet.Y - client.Entity.Position.Y) > 0)
            {
                client.Entity.PositiveDeltaY += (packet.Y - client.Entity.Position.Y);
            }
            else
            {
                client.Entity.PositiveDeltaY = 0;
            }

            client.Entity.Position = new Vector3(packet.X, packet.Y, packet.Z);
            client.UpdateChunksAsync();
            // Look
            client.Entity.Pitch   = packet.Pitch;
            client.Entity.Yaw     = packet.Yaw;
            client.Entity.HeadYaw = packet.Yaw;
        }
Example #25
0
 public override void HandlePacket(MinecraftServer server, MinecraftClient client)
 {
     switch (Action)
     {
         case EntityAction.Crouch:
             client.IsCrouching = true;
             break;
         case EntityAction.Uncrouch:
             client.IsCrouching = false;
             break;
         case EntityAction.StartSprinting:
             client.IsSprinting = true;
             break;
         case EntityAction.StopSprinting:
             client.IsSprinting = false;
             break;
         case EntityAction.LeaveBed:
             client.Entity.LeaveBed();
             break;
     }
     if (Action != EntityAction.LeaveBed) // NOTE: Does this matter?
     {
         // TODO ?
     }
 }
Example #26
0
 public override void HandlePacket(MinecraftServer Server, ref MinecraftClient Client)
 {
     switch (Action)
     {
         case EntityAction.Crouch:
             Client.IsCrouching = true;
             break;
         case EntityAction.Uncrouch:
             Client.IsCrouching = false;
             break;
         case EntityAction.StartSprinting:
             Client.IsSprinting = true;
             break;
         case EntityAction.StopSprinting:
             Client.IsSprinting = false;
             break;
     }
     if (Action != EntityAction.LeaveBed) // NOTE: Does this matter?
     {
         this.EntityId = Client.Entity.Id;
         for (int i = 0; i < 
              Server.GetClientsInWorld(Server.GetClientWorld(Client)).Count(); i++)
         {
             if (Server.Clients [i] != Client)
                 Server.Clients [i].SendPacket(this);
         }
         Server.ProcessSendQueue();
     }
 }
Example #27
0
 public PlayerManager(MinecraftServer minecraftserver)
 {
     field_9216_a = new ArrayList();
     field_9215_b = new MCHashTable2();
     field_833_c = new ArrayList();
     mcServer = minecraftserver;
 }
Example #28
0
        public static void RegisterHandlers(MinecraftServer server)
        {
            server.RegisterPacketHandler(HandshakePacket.PacketId, LoginHandlers.Handshake);
            server.RegisterPacketHandler(EncryptionKeyResponsePacket.PacketId, LoginHandlers.EncryptionKeyResponse);
            server.RegisterPacketHandler(ClientStatusPacket.PacketId, LoginHandlers.ClientStatus);
            server.RegisterPacketHandler(ClientSettingsPacket.PacketId, LoginHandlers.ClientSettings);

            server.RegisterPacketHandler(PlayerPacket.PacketId, PlayerMovementHandlers.Player);
            server.RegisterPacketHandler(PlayerPositionPacket.PacketId, PlayerMovementHandlers.PlayerPosition);
            server.RegisterPacketHandler(PlayerLookPacket.PacketId, PlayerMovementHandlers.PlayerLook);
            server.RegisterPacketHandler(PlayerPositionAndLookPacket.PacketId, PlayerMovementHandlers.PlayerPositionAndLook);
            server.RegisterPacketHandler(AnimationPacket.PacketId, PlayerMovementHandlers.Animation);
            server.RegisterPacketHandler(EntityActionPacket.PacketId, PlayerMovementHandlers.EntityAction);
            server.RegisterPacketHandler(PlayerAbilitiesPacket.PacketId, PlayerMovementHandlers.PlayerAbilities);

            server.RegisterPacketHandler(CreativeInventoryActionPacket.PacketId, InventoryHandlers.CreativeInventoryAction);
            server.RegisterPacketHandler(ClickWindowPacket.PacketId, InventoryHandlers.ClickWindow);
            server.RegisterPacketHandler(CloseWindowPacket.PacketId, InventoryHandlers.CloseWindow);
            server.RegisterPacketHandler(HeldItemChangePacket.PacketId, InventoryHandlers.HeldItemChange);

            server.RegisterPacketHandler(PlayerDiggingPacket.PacketId, InteractionHandlers.PlayerDigging);
            server.RegisterPacketHandler(RightClickPacket.PacketId, InteractionHandlers.RightClick);

            server.RegisterPacketHandler(ServerListPingPacket.PacketId, ServerListPing);
            server.RegisterPacketHandler(ChatMessagePacket.PacketId, ChatMessage);
            server.RegisterPacketHandler(KeepAlivePacket.PacketId, KeepAlive);
        }
Example #29
0
 public override void HandlePacket(MinecraftServer Server, ref MinecraftClient Client)
 {
     if (!Client.ReadyToSpawn)
         return;
     Client.Entity.Pitch = Pitch;
     Client.Entity.Yaw = Yaw;
 }
Example #30
0
 public EntityTracker(MinecraftServer minecraftserver)
 {
     trackedEntitySet       = new HashSet();
     trackedEntityHashTable = new MCHashTable();
     mcServer = minecraftserver;
     maxTrackingDistanceThreshold = minecraftserver.configManager.func_640_a();
 }
 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     client.SendData(CreateBuffer(
         DataUtility.CreateInt32(EntityId),
         DataUtility.CreateInt16(SlotIndex),
         Item.GetData()));
 }
Example #32
0
        /// <summary>
        /// Starts the server
        /// </summary>
        public void StartServer()
        {
            Invoke((MethodInvoker) delegate
            {
                var openFileDialog = new OpenFileDialog
                {
                    Filter          = "Minecraft Server Files (*.jar)|*.jar",
                    CheckFileExists = true
                };

                if ((Server == null && openFileDialog.ShowDialog() == DialogResult.OK) || (Server != null && !Server.Running))
                {
                    if (Server != null)
                    {
                        Server.Start();
                    }
                    else
                    {
                        Server = new MinecraftServer(openFileDialog.FileName, config.JvmArguments);
                        Server.StandardOutput += Server_StandardOutputTextReceived;
                        Server.StandardError  += Server_StandardOutputTextReceived;
                        Server.Exited         += Server_Exited;
                        Server.Started        += Server_Started;
                        Server.Start();
                    }
                }
            });
        }
Example #33
0
        public ServerConsole()
        {
            Server = null;
            InitializeComponent();

            config = ConfigFile.Load <Config>("config.json");
        }
Example #34
0
 public void Start()
 {
     MinecraftServer.AddLevel(new Level(Level.GetGenerator(SettingsProvider.Get <string>("level.type")),
                                        SettingsProvider.Get <string>("level.name")));
     MinecraftServer.DefaultLevel.GameMode = SettingsProvider.Get <GameMode>("level.gamemode");
     MinecraftServer.Start();
 }
Example #35
0
 private static string GetPingValue(MinecraftServer server)
 {
     return "§1\0" + PacketReader.ProtocolVersion + "\0" +
         PacketReader.FriendlyVersion + "\0" +
         server.Settings.MotD + "\0" + server.Clients.Count(c => c.IsLoggedIn) +
         "\0" + server.Settings.MaxPlayers;
 }
Example #36
0
        private void MinecraftServerOnChatMessage(object sender, ChatMessageEventArgs chatMessageEventArgs)
        {
            var internalArgs = new ChatMessageEventArgs(chatMessageEventArgs.Origin, chatMessageEventArgs.RawMessage);

            if (ChatMessage != null)
            {
                ChatMessage(this, internalArgs);
                if (internalArgs.Handled)
                {
                    chatMessageEventArgs.Handled = true;
                    return;
                }
            }
            chatMessageEventArgs.Handled = true;
            if (chatMessageEventArgs.RawMessage.StartsWith("/"))
            {
                if (chatMessageEventArgs.RawMessage.StartsWith("//"))
                {
                    MinecraftServer.SendChat(string.Format(SettingsProvider.Get <string>("chat.format"),
                                                           chatMessageEventArgs.Origin.Username, chatMessageEventArgs.RawMessage.Substring(1)));
                }
                else
                {
                    Command.ExecuteCommand(this, chatMessageEventArgs.Origin, chatMessageEventArgs.RawMessage);
                }
            }
            else
            {
                MinecraftServer.SendChat(string.Format(SettingsProvider.Get <string>("chat.format"),
                                                       chatMessageEventArgs.Origin.Username, chatMessageEventArgs.RawMessage));
            }
        }
Example #37
0
 public EntityTracker(MinecraftServer minecraftserver)
 {
     trackedEntitySet = new HashSet();
     trackedEntityHashTable = new MCHashTable();
     mcServer = minecraftserver;
     maxTrackingDistanceThreshold = minecraftserver.configManager.func_640_a();
 }
Example #38
0
 private static string GetPingValue(MinecraftServer server)
 {
     return("§1\0" + PacketReader.ProtocolVersion + "\0" +
            MinecraftServer.TargetClientVersion + "\0" +
            server.Settings.MotD + "\0" + server.Clients.Count(c => c.IsLoggedIn) +
            "\0" + server.Settings.MaxPlayers);
 }
Example #39
0
        /// <summary>
        /// Registers all built-in packet handlers.
        /// </summary>
        public static void RegisterHandlers()
        {
            MinecraftServer.RegisterPacketHandler(HandshakePacket.PacketId, LoginHandlers.Handshake);
            MinecraftServer.RegisterPacketHandler(EncryptionKeyResponsePacket.PacketId, LoginHandlers.EncryptionKeyResponse);
            MinecraftServer.RegisterPacketHandler(ClientStatusPacket.PacketId, LoginHandlers.ClientStatus);
            MinecraftServer.RegisterPacketHandler(ClientSettingsPacket.PacketId, LoginHandlers.ClientSettings);

            MinecraftServer.RegisterPacketHandler(PlayerPacket.PacketId, PlayerMovementHandlers.Player);
            MinecraftServer.RegisterPacketHandler(PlayerPositionPacket.PacketId, PlayerMovementHandlers.PlayerPosition);
            MinecraftServer.RegisterPacketHandler(PlayerLookPacket.PacketId, PlayerMovementHandlers.PlayerLook);
            MinecraftServer.RegisterPacketHandler(PlayerPositionAndLookPacket.PacketId, PlayerMovementHandlers.PlayerPositionAndLook);
            MinecraftServer.RegisterPacketHandler(AnimationPacket.PacketId, PlayerMovementHandlers.Animation);
            MinecraftServer.RegisterPacketHandler(EntityActionPacket.PacketId, PlayerMovementHandlers.EntityAction);
            MinecraftServer.RegisterPacketHandler(PlayerAbilitiesPacket.PacketId, PlayerMovementHandlers.PlayerAbilities);

            MinecraftServer.RegisterPacketHandler(CreativeInventoryActionPacket.PacketId, InventoryHandlers.CreativeInventoryAction);
            MinecraftServer.RegisterPacketHandler(ClickWindowPacket.PacketId, InventoryHandlers.ClickWindow);
            MinecraftServer.RegisterPacketHandler(CloseWindowPacket.PacketId, InventoryHandlers.CloseWindow);
            MinecraftServer.RegisterPacketHandler(HeldItemChangePacket.PacketId, InventoryHandlers.HeldItemChange);

            MinecraftServer.RegisterPacketHandler(PlayerDiggingPacket.PacketId, InteractionHandlers.PlayerDigging);
            MinecraftServer.RegisterPacketHandler(RightClickPacket.PacketId, InteractionHandlers.RightClick);
            MinecraftServer.RegisterPacketHandler(UseEntityPacket.PacketId, InteractionHandlers.UseEntity);
            MinecraftServer.RegisterPacketHandler(UpdateSignPacket.PacketId, InteractionHandlers.UpdateSign);

            MinecraftServer.RegisterPacketHandler(ServerListPingPacket.PacketId, ServerListPing);
            MinecraftServer.RegisterPacketHandler(PluginMessagePacket.PacketId, PluginMessage);
            MinecraftServer.RegisterPacketHandler(ChatMessagePacket.PacketId, ChatMessage);
            MinecraftServer.RegisterPacketHandler(KeepAlivePacket.PacketId, KeepAlive);
            MinecraftServer.RegisterPacketHandler(TabCompletePacket.PacketId, TabComplete);
        }
 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     if (Entity.Data != 0)
     {
         client.SendData(CreateBuffer(
             DataUtility.CreateInt32(Entity.Id),
             new[] { Entity.EntityType },
             DataUtility.CreateAbsoluteInteger(Entity.Position.X),
             DataUtility.CreateAbsoluteInteger(Entity.Position.Y),
             DataUtility.CreateAbsoluteInteger(Entity.Position.Z),
             DataUtility.CreateInt32(Entity.Data),
             DataUtility.CreateInt16((short)Entity.Velocity.X),
             DataUtility.CreateInt16((short)Entity.Velocity.Y),
             DataUtility.CreateInt16((short)Entity.Velocity.Z)));
     }
     else
     {
         client.SendData(CreateBuffer(
             DataUtility.CreateInt32(Entity.Id),
             new[] { Entity.EntityType },
             DataUtility.CreateAbsoluteInteger(Entity.Position.X),
             DataUtility.CreateAbsoluteInteger(Entity.Position.Y),
             DataUtility.CreateAbsoluteInteger(Entity.Position.Z),
             DataUtility.CreateInt32(Entity.Data)));
     }
 }
Example #41
0
 public static void Handshake(MinecraftClient client, MinecraftServer server, IPacket _packet)
 {
     var packet = (HandshakePacket)_packet;
     if (packet.ProtocolVersion < PacketReader.ProtocolVersion)
     {
         client.SendPacket(new DisconnectPacket("Outdated client!"));
         return;
     }
     if (packet.ProtocolVersion > PacketReader.ProtocolVersion)
     {
         client.SendPacket(new DisconnectPacket("Outdated server!"));
         return;
     }
     if (server.Clients.Any(c => c.Username == packet.Username))
     {
         client.SendPacket(new DisconnectPacket(""));
         return;
     }
     client.Username = packet.Username;
     client.Hostname = packet.ServerHostname + ":" + packet.ServerPort;
     if (server.Settings.OnlineMode)
         client.AuthenticationHash = CreateHash();
     else
         client.AuthenticationHash = "-";
     if (server.Settings.EnableEncryption)
         client.SendPacket(CreateEncryptionRequest(client, server));
     else
         server.LogInPlayer(client);
 }
 public async Task HandleMessageAsync(MinecraftServer sender, string message)
 {
     if (doneRegex.IsMatch(message))
     {
         HandleDoneMessageInternal(message);
         return;
     }
     if (messageRegex.IsMatch(message))
     {
         HandlePlayerMessageInternal(message);
         return;
     }
     if (tpsRegex.IsMatch(message))
     {
         HandleTpsMessageInternal(message);
         return;
     }
     if (playerRegex.IsMatch(message))
     {
         HandlePlayerInternal(message);
         return;
     }
     if (PlayerJoinedRegex.IsMatch(message))
     {
         HandlePlayerJoinedInternal(message);
         return;
     }
     if (PlayerLeftRegex.IsMatch(message))
     {
         HandlePlayerLeftInternal(message);
         return;
     }
 }
Example #43
0
        public static void EncryptionKeyResponse(MinecraftClient client, MinecraftServer server, IPacket _packet)
        {
            var packet = (EncryptionKeyResponsePacket)_packet;

            client.SharedKey = server.CryptoServiceProvider.Decrypt(packet.SharedSecret, false);
            client.SendPacket(new EncryptionKeyResponsePacket(new byte[0], new byte[0]));
        }
Example #44
0
        public static void RegisterHandlers(MinecraftServer server)
        {
            server.RegisterPacketHandler(typeof(HandshakePacket), LoginHandlers.Handshake);
            server.RegisterPacketHandler(typeof(LoginStartPacket), LoginHandlers.LoginStart);
            server.RegisterPacketHandler(typeof(EncryptionKeyResponsePacket), LoginHandlers.EncryptionKeyResponse);
            server.RegisterPacketHandler(typeof(ClientStatusPacket), LoginHandlers.ClientStatus);
            server.RegisterPacketHandler(typeof(ClientSettingsPacket), LoginHandlers.ClientSettings);

            server.RegisterPacketHandler(typeof(PlayerPacket), PlayerMovementHandlers.Player);
            server.RegisterPacketHandler(typeof(PlayerPositionPacket), PlayerMovementHandlers.PlayerPosition);
            server.RegisterPacketHandler(typeof(PlayerLookPacket), PlayerMovementHandlers.PlayerLook);
            server.RegisterPacketHandler(typeof(PlayerPositionAndLookPacket), PlayerMovementHandlers.PlayerPositionAndLook);
            server.RegisterPacketHandler(typeof(AnimationPacket), PlayerMovementHandlers.Animation);
            server.RegisterPacketHandler(typeof(EntityActionPacket), PlayerMovementHandlers.EntityAction);
            server.RegisterPacketHandler(typeof(PlayerAbilitiesPacket), PlayerMovementHandlers.PlayerAbilities);

            server.RegisterPacketHandler(typeof(CreativeInventoryActionPacket), InventoryHandlers.CreativeInventoryAction);
            server.RegisterPacketHandler(typeof(ClickWindowPacket), InventoryHandlers.ClickWindow);
            server.RegisterPacketHandler(typeof(CloseWindowPacket), InventoryHandlers.CloseWindow);
            server.RegisterPacketHandler(typeof(HeldItemPacket), InventoryHandlers.HeldItemChange);

            server.RegisterPacketHandler(typeof(PlayerBlockActionPacket), InteractionHandlers.PlayerDigging);
            server.RegisterPacketHandler(typeof(RightClickPacket), InteractionHandlers.RightClick);

            server.RegisterPacketHandler(typeof(StatusRequestPacket), StatusRequest);
            server.RegisterPacketHandler(typeof(StatusPingPacket), StatusPing);
            server.RegisterPacketHandler(typeof(ChatMessagePacket), ChatMessage);
            server.RegisterPacketHandler(typeof(KeepAlivePacket), KeepAlive);
        }
Example #45
0
        public IActionResult Index()
        {
            var s = new MinecraftServer();

            s.StartServer();
            return(View());
        }
Example #46
0
        public EntityPlayerMP(MinecraftServer minecraftserver, World world, string s,
                              ItemInWorldManager iteminworldmanager)
            : base(world)
        {
            loadedChunks    = new LinkedList();
            field_420_ah    = new HashSet();
            lastHealth      = unchecked ((int)0xfa0a1f01);
            field_15004_bw  = 60;
            currentWindowId = 0;
            ChunkCoordinates chunkcoordinates = world.func_22078_l();
            int i = chunkcoordinates.posX;
            int j = chunkcoordinates.posZ;
            int k = chunkcoordinates.posY;

            if (!world.worldProvider.field_4306_c)
            {
                i += rand.nextInt(20) - 10;
                k  = world.findTopSolidBlock(i, j);
                j += rand.nextInt(20) - 10;
            }
            setLocationAndAngles(i + 0.5D, k, j + 0.5D, 0.0F, 0.0F);
            mcServer   = minecraftserver;
            stepHeight = 0.0F;
            iteminworldmanager.thisPlayer = this;
            username           = s;
            itemInWorldManager = iteminworldmanager;
            yOffset            = 0.0F;
        }
Example #47
0
        public static void Main(string[] args)
        {
            // Create a server on 0.0.0.0:25565
            minecraftServer = new MinecraftServer(
                new IPEndPoint(IPAddress.Any, 25565));
            minecraftServer.Settings.OnlineMode       = false;
            minecraftServer.Settings.EnableEncryption = true;
            CustomLeatherItem.Server = minecraftServer;
            Item.SetItemClass(new CustomLeatherItem());
            // Add a console logger
            LogProvider.RegisterProvider(new ConsoleLogWriter(LogImportance.Medium));
            LogProvider.RegisterProvider(new FileLogWriter("packetLog.txt", LogImportance.Low));
            // Add a flatland world
#if DEBUG
            // Use a fresh world each time
            if (Directory.Exists("world"))
            {
                Directory.Delete("world", true);
            }
#endif
            IWorldGenerator generator = new FlatlandGenerator();
            minecraftServer.AddLevel(new Level(generator, Path.Combine(Directory.GetCurrentDirectory(), "world")));
            minecraftServer.DefaultLevel.GameMode = GameMode.Survival;
            // Register the chat handler
            minecraftServer.ChatMessage += HandleOnChatMessage;
            // Start the server
            minecraftServer.Start();
            Console.WriteLine("Press 'q' key to exit.");
            while (Console.ReadKey(true).Key != ConsoleKey.Q)
            {
            }
            // Stop the server
            minecraftServer.Stop();
            minecraftServer.DefaultLevel.Save();
        }
 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     byte[] payload = new byte[] { PacketId }
         .Concat(DataUtility.CreateInt32(EntityId))
         .Concat(new byte[] { (byte)DeltaX, (byte)DeltaY, (byte)DeltaZ }).ToArray();
     client.SendData(payload);
 }
Example #49
0
        public static void CreativeInventoryAction(RemoteClient client, MinecraftServer server, IPacket _packet)
        {
            var packet = (CreativeInventoryActionPacket)_packet;

            if (packet.Slot == -1)
            {
                var entity = new ItemEntity(client.Entity.Position +
                                            new Vector3(0, client.Entity.Size.Height, 0), packet.Item);
                entity.Velocity = MathHelper.FowardVector(client.Entity.Yaw) * new Vector3(0.25);
                server.EntityManager.SpawnEntity(client.Entity.World, entity);
            }
            else if (packet.Slot < client.Entity.Inventory.Length && packet.Slot > 0)
            {
                client.Entity.Inventory[packet.Slot] = packet.Item;
                if (packet.Slot == client.Entity.SelectedSlot)
                {
                    var clients = server.EntityManager.GetKnownClients(client.Entity);
                    foreach (var _client in clients)
                    {
                        _client.SendPacket(new EntityEquipmentPacket(client.Entity.EntityId, EntityEquipmentPacket.EntityEquipmentSlot.HeldItem,
                                                                     client.Entity.Inventory[packet.Slot]));
                    }
                }
            }
        }
Example #50
0
 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     byte[] payload = new byte[] { PacketId, WindowId }
         .Concat(DataUtility.CreateInt16(Index))
         .Concat(Slot.GetData()).ToArray();
     client.SendData(payload);
 }
 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     client.SendData(CreateBuffer(
         DataUtility.CreateString(Channel),
         DataUtility.CreateInt16((short)Message.Length),
         Message));
 }
Example #52
0
        static void Main(string[] args)
        {
            if (Directory.Exists("world"))
            {
                Directory.Delete("world", true);
            }
            level = new Level(new StandardGenerator(), "world");
            level.AddWorld("region");
            level.AddWorld("test", new FlatlandGenerator());
            level.Worlds[1].GenerateChunk(Coordinates2D.Zero);
            level.SaveTo("world");
            server                     = new MinecraftServer(level);
            server.ChatMessage        += server_ChatMessage;
            server.Settings.OnlineMode = true;
            server.Settings.MotD       = "Craft.Net Test Server";
            server.Start(new IPEndPoint(IPAddress.Any, 25565));
            Console.WriteLine("Press 'q' to exit");
            ConsoleKeyInfo cki;

            do
            {
                cki = Console.ReadKey(true);
            }while (cki.KeyChar != 'q');
            server.Stop();
        }
 public static void EntityAction(MinecraftClient client, MinecraftServer server, IPacket _packet)
 {
     var packet = (EntityActionPacket)_packet;
     switch (packet.Action)
     {
         case EntityActionPacket.EntityAction.Crouch:
             client.Entity.IsCrouching = true;
             break;
         case EntityActionPacket.EntityAction.Uncrouch:
             client.Entity.IsCrouching = false;
             break;
         case EntityActionPacket.EntityAction.StartSprinting:
             client.Entity.IsSprinting = true;
             break;
         case EntityActionPacket.EntityAction.StopSprinting:
             client.Entity.IsSprinting = false;
             break;
         case EntityActionPacket.EntityAction.LeaveBed:
             client.Entity.LeaveBed();
             break;
     }
     if (packet.Action != EntityActionPacket.EntityAction.LeaveBed) // NOTE: Does this matter?
     {
         // TODO ?
     }
 }
 public static void Animation(MinecraftClient client, MinecraftServer server, IPacket _packet)
 {
     var packet = (AnimationPacket)_packet;
     var clients = server.EntityManager.GetKnownClients(client.Entity);
     foreach (var _client in clients)
         _client.SendPacket(packet);
 }
Example #55
0
 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     byte[] payload = new byte[] { PacketId, (byte)EntityIds.Length };
     foreach (int id in EntityIds)
         payload = payload.Concat(DataUtility.CreateInt32(id)).ToArray();
     client.SendData(payload);
 }
Example #56
0
 public WorldServer(MinecraftServer minecraftserver, ISaveHandler isavehandler, string s, int i)
     : base(isavehandler, s, (new Random()).nextLong(), WorldProvider.func_4091_a(i))
 {
     field_819_z   = false;
     field_20912_E = new MCHashTable();
     field_6160_D  = minecraftserver;
 }
 public override void HandlePacket(MinecraftServer server, MinecraftClient client)
 {
     LogProvider.Log("<" + client.Username + "> " + Message, LogImportance.Medium);
     var args = new ChatMessageEventArgs(client, Message);
     server.OnChatMessage(args);
     if (!args.Handled)
         server.SendChat("<" + client.Username + "> " + Message);
 }
Example #58
0
        public static void KeepAlive(MinecraftClient client, MinecraftServer server, IPacket _packet)
        {
            var packet = (KeepAlivePacket)_packet;

            // TODO: Confirm value validity
            client.LastKeepAlive = DateTime.Now;
            client.Ping          = (short)(client.LastKeepAlive - client.LastKeepAliveSent).TotalMilliseconds;
        }
Example #59
0
 public void Dispose()
 {
     if (_server != null)
     {
         _server.WorkerCancelToken.Cancel();
         _server = null;
     }
 }
Example #60
0
        public static void PluginMessage(MinecraftClient client, MinecraftServer server, IPacket _packet)
        {
            var packet = (PluginMessagePacket)_packet;

            if (server.PluginChannels.ContainsKey(packet.Channel))
            {
                server.PluginChannels[packet.Channel].MessageRecieved(client, packet.Data);
            }
        }