示例#1
0
        public static void HandleLoginRequestPacket(IPacket packet, IRemoteClient client, IMultiplayerServer server)
        {
            var loginRequestPacket = (LoginRequestPacket)packet;
            var remoteClient = (RemoteClient)client;
            if (loginRequestPacket.ProtocolVersion < server.PacketReader.ProtocolVersion)
                remoteClient.QueuePacket(new DisconnectPacket("Client outdated! Use beta 1.7.3."));
            else if (loginRequestPacket.ProtocolVersion > server.PacketReader.ProtocolVersion)
                remoteClient.QueuePacket(new DisconnectPacket("Server outdated! Use beta 1.7.3."));
            else if (server.Worlds.Count == 0)
                remoteClient.QueuePacket(new DisconnectPacket("Server has no worlds configured."));
            else if (!server.PlayerIsWhitelisted(remoteClient.Username) && server.PlayerIsBlacklisted(remoteClient.Username))
                remoteClient.QueuePacket(new DisconnectPacket("You're banned from this server"));
            else if (server.Clients.Count(c => c.Username == client.Username) > 1)
                remoteClient.QueuePacket(new DisconnectPacket("The player with this username is already logged in"));
            else
            {
                remoteClient.LoggedIn = true;
                remoteClient.Entity = new PlayerEntity(remoteClient.Username);
                remoteClient.World = server.Worlds[0];
                remoteClient.ChunkRadius = 2;

                if (!remoteClient.Load())
                    remoteClient.Entity.Position = remoteClient.World.SpawnPoint;
                // Make sure they don't spawn in the ground
                var collision = new Func<bool>(() =>
                {
                    var feet = client.World.GetBlockID((Coordinates3D)client.Entity.Position);
                    var head = client.World.GetBlockID((Coordinates3D)(client.Entity.Position + Vector3.Up));
                    var feetBox = server.BlockRepository.GetBlockProvider(feet).BoundingBox;
                    var headBox = server.BlockRepository.GetBlockProvider(head).BoundingBox;
                    return feetBox != null || headBox != null;
                });
                while (collision())
                    client.Entity.Position += Vector3.Up;

                // Send setup packets
                remoteClient.QueuePacket(new LoginResponsePacket(0, 0, Dimension.Overworld));
                remoteClient.UpdateChunks();
                remoteClient.QueuePacket(new WindowItemsPacket(0, remoteClient.Inventory.GetSlots()));
                remoteClient.QueuePacket(new SpawnPositionPacket((int)remoteClient.Entity.Position.X,
                        (int)remoteClient.Entity.Position.Y, (int)remoteClient.Entity.Position.Z));
                remoteClient.QueuePacket(new SetPlayerPositionPacket(remoteClient.Entity.Position.X,
                        remoteClient.Entity.Position.Y + 1,
                        remoteClient.Entity.Position.Y + remoteClient.Entity.Size.Height + 1,
                        remoteClient.Entity.Position.Z, remoteClient.Entity.Yaw, remoteClient.Entity.Pitch, true));
                remoteClient.QueuePacket(new TimeUpdatePacket(remoteClient.World.Time));

                // Start housekeeping for this client
                var entityManager = server.GetEntityManagerForWorld(remoteClient.World);
                entityManager.SpawnEntity(remoteClient.Entity);
                entityManager.SendEntitiesToClient(remoteClient);
                server.Scheduler.ScheduleEvent("remote.keepalive", remoteClient, TimeSpan.FromSeconds(10), remoteClient.SendKeepAlive);
                server.Scheduler.ScheduleEvent("remote.chunks", remoteClient, TimeSpan.FromSeconds(1), remoteClient.ExpandChunkRadius);

                if (!string.IsNullOrEmpty(Program.ServerConfiguration.MOTD))
                    remoteClient.SendMessage(Program.ServerConfiguration.MOTD);
                if (!Program.ServerConfiguration.Singleplayer)
                    server.SendMessage(ChatColor.Yellow + "{0} joined the server.", remoteClient.Username);
            }
        }
示例#2
0
 public static void HandleHandshakePacket(IPacket packet, IRemoteClient client, IMultiplayerServer server)
 {
     var handshakePacket = (HandshakePacket) packet;
     var remoteClient = (RemoteClient)client;
     remoteClient.Username = handshakePacket.Username;
     remoteClient.QueuePacket(new HandshakeResponsePacket("-")); // TODO: Implement some form of authentication
 }
示例#3
0
 public override void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     var chunk = world.FindChunk(descriptor.Coordinates);
     user.Server.Scheduler.ScheduleEvent(chunk,
         DateTime.UtcNow.AddSeconds(MathHelper.Random.Next(MinGrowthTime, MaxGrowthTime)),
         s => TrySpread(descriptor.Coordinates, world, user.Server));
 }
示例#4
0
 public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
 {
     coordinates += MathHelper.BlockFaceToCoordinates(face);
     var descriptor = world.GetBlockData(coordinates);
     LadderDirection direction;
     switch (MathHelper.DirectionByRotationFlat(user.Entity.Yaw))
     {
         case Direction.North:
             direction = LadderDirection.North;
             break;
         case Direction.South:
             direction = LadderDirection.South;
             break;
         case Direction.East:
             direction = LadderDirection.East;
             break;
         default:
             direction = LadderDirection.West;
             break;
     }
     descriptor.Metadata = (byte)direction;
     if (IsSupported(descriptor, user.Server, world))
     {
         world.SetBlockID(descriptor.Coordinates, BlockID);
         world.SetMetadata(descriptor.Coordinates, (byte)direction);
         item.Count--;
         user.Inventory[user.SelectedSlot] = item;
     }
 }
示例#5
0
        public override void Handle(IRemoteClient client, string alias, string[] arguments)
        {
            switch (arguments.Length)
            {
                case 0:
                    client.SendMessage(client.World.Time.ToString());
                    break;
                case 2:
                    if (!arguments[0].Equals("set"))
                        Help(client, alias, arguments);

                    int newTime;

                    if(!Int32.TryParse(arguments[1], out newTime))
                        Help(client, alias, arguments);

                    client.World.Time = newTime;

                    client.SendMessage(string.Format("Setting time to {0}", arguments[1]));

                    foreach (var remoteClient in client.Server.Clients.Where(c => c.World.Equals(client.World)))
                        remoteClient.QueuePacket(new TimeUpdatePacket(newTime));
                    
                    break;
                default:
                    Help(client, alias, arguments);
                    break;
            }
        }
示例#6
0
 public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
 {
     var bottom = coordinates + MathHelper.BlockFaceToCoordinates(face);
     var top = bottom + Coordinates3D.Up;
     if (world.GetBlockID(top) != 0 || world.GetBlockID(bottom) != 0)
         return;
     DoorFlags direction;
     switch (MathHelper.DirectionByRotationFlat(user.Entity.Yaw))
     {
         case Direction.North:
             direction = DoorFlags.Northwest;
             break;
         case Direction.South:
             direction = DoorFlags.Southeast;
             break;
         case Direction.East:
             direction = DoorFlags.Northeast;
             break;
         default: // Direction.West:
             direction = DoorFlags.Southwest;
             break;
     }
     user.Server.BlockUpdatesEnabled = false;
     world.SetBlockID(bottom, BlockID);
     world.SetMetadata(bottom, (byte)direction);
     world.SetBlockID(top, BlockID);
     world.SetMetadata(top, (byte)(direction | DoorFlags.Upper));
     user.Server.BlockUpdatesEnabled = true;
     item.Count--;
     user.Inventory[user.SelectedSlot] = item;
 }
示例#7
0
        public override void Handle(IRemoteClient client, string alias, string[] arguments)
        {
            if (arguments.Length < 2)
            {
                Help(client, alias, arguments);
                return;
            }
            
            string username = arguments[0];
            var messageBuilder = new System.Text.StringBuilder();

            for (int i = 1; i < arguments.Length; i++)
                messageBuilder.Append(arguments[i] + " ");
            var message = messageBuilder.ToString();

            var receivingPlayer = GetPlayerByName(client, username);

            if (receivingPlayer == null)
            {
                client.SendMessage("No client with the username \"" + username + "\" was found.");
                return;
            }
            if (receivingPlayer == client)
            {
                client.SendMessage(ChatColor.Red + "You can't send a private message to yourself!");
                return;
            }

            receivingPlayer.SendMessage(ChatColor.Gray + "<"+ client.Username + " -> You> " + message);
        }
示例#8
0
 public override void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     var chunk = world.FindChunk(descriptor.Coordinates);
     user.Server.Scheduler.ScheduleEvent("crops", chunk,
         TimeSpan.FromSeconds(MathHelper.Random.Next(30, 60)),
         (server) => GrowBlock(server, world, descriptor.Coordinates + MathHelper.BlockFaceToCoordinates(face)));
 }
示例#9
0
        public override void Handle(IRemoteClient client, string alias, string[] arguments)
        {
            if (arguments.Length > 1)
            {
                Help(client, alias, arguments);
                return;
            }

            var identifier = arguments.Length == 1 ? arguments[0] : "1";

            ICommand found;
            if ((found = Program.CommandManager.FindByName(identifier)) != null)
            {
                found.Help(client, identifier, new string[0]);
                return;
            }
            else if ((found = Program.CommandManager.FindByAlias(identifier)) != null)
            {
                found.Help(client, identifier, new string[0]);
                return;
            }

            int pageNumber;
            if (int.TryParse(identifier, out pageNumber))
            {
                HelpPage(client, pageNumber);
                return;
            }
            Help(client, alias, arguments);
        }
示例#10
0
        public override void Handle(IRemoteClient client, string alias, string[] arguments)
        {
            if (arguments.Length != 1)
            {
                Help(client, alias, arguments);
                return;
            }

            int id;
            if (!int.TryParse(arguments[0], out id))
            {
                Help(client, alias, arguments);
                return;
            }

            var manager = client.Server.GetEntityManagerForWorld(client.World);
            var entity = manager.GetEntityByID(id) as MobEntity;
            if (entity == null)
            {
                client.SendMessage(ChatColor.Red + "An entity with that ID does not exist in this world.");
                return;
            }

            manager.DespawnEntity(entity);
        }
示例#11
0
        public override void Handle(IRemoteClient client, string alias, string[] arguments)
        {
            if (arguments.Length < 2)
            {
                Help(client, alias, arguments);
                return;
            }

            string  username    = arguments[0],
                    itemid      = arguments[1],
                    amount      = "1";

            if(arguments.Length >= 3)
                    amount = arguments[2];
            
            var receivingPlayer = GetPlayerByName(client, username);

            if (receivingPlayer == null)
            {
                client.SendMessage("No client with the username \"" + username + "\" was found.");
                return;
            }

            if (!GiveItem(receivingPlayer, itemid, amount, client))
            {
                Help(client, alias, arguments);
            }
        }
示例#12
0
 protected static IRemoteClient GetPlayerByName(IRemoteClient client, string username)
 {
     var receivingPlayer =
         client.Server.Clients.FirstOrDefault(
             c => String.Equals(c.Username, username, StringComparison.CurrentCultureIgnoreCase));
     return receivingPlayer;
 }
示例#13
0
        public static ScenarioResult Run(this Scenario scenario, IRemoteClient proxy)
        {
            var scenarioResult = new ScenarioResult();

            scenarioResult.ScenarioName = scenario.Name;

            scenario.Children = scenario.Children.OrderBy(d => d.Index).ToList();

            scenario.Children.ForEach(i => scenarioResult.InteractionResults.Add((i as Interaction).Run(proxy)));

            scenarioResult.SetResult();

            if (!scenario.ExpectFailure)
                return scenarioResult;
            else
                if (scenarioResult.Result.status.ToLower().Equals("pass"))
                {
                    scenarioResult.Result.status = "FAIL";
                    scenarioResult.Result.error = "Expected failure, but scenario incorrectly passed.";
                }
                else
                {
                    scenarioResult.Result.status = "PASS";
                    scenarioResult.Result.error = "";
                    scenarioResult.Result.retrn = "Scenario failed correctly.";
                }

            return scenarioResult;
        }
示例#14
0
        public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
        {
            if (face == BlockFace.PositiveY || face == BlockFace.NegativeY)
            {
                // Trapdoors are not placed when the user clicks on the top or bottom of a block
                return;
            }

            // NOTE: These directions are rotated by 90 degrees so that the hinge of the trapdoor is placed
            // where the user had their cursor.
            switch (face)
            {
                case BlockFace.NegativeZ:
                    item.Metadata = (byte)TrapdoorDirection.West;
                    break;
                case BlockFace.PositiveZ:
                    item.Metadata = (byte)TrapdoorDirection.East;
                    break;
                case BlockFace.NegativeX:
                    item.Metadata = (byte)TrapdoorDirection.South;
                    break;
                case BlockFace.PositiveX:
                    item.Metadata = (byte)TrapdoorDirection.North;
                    break;
                default:
                    return;
            }

            base.ItemUsedOnBlock(coordinates, item, face, world, user);
        }
示例#15
0
 public override void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     if (IsHydrated(descriptor.Coordinates, world))
     {
         world.SetMetadata(descriptor.Coordinates, 1);
     }
     user.Server.Scheduler.ScheduleEvent(DateTime.Now.AddSeconds(UpdateIntervalSeconds), (server) => HydrationCheckEvent(server, descriptor.Coordinates, world));
 }
示例#16
0
        public ClientViewModel(IRemoteClient remoteClient)
        {
            RemoteClient = remoteClient;

            _clientInformationDecorator = new ClientInformationDecorator(RemoteClient);

            UpdateInformation();
        }
示例#17
0
 public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
 {
     coordinates += MathHelper.BlockFaceToCoordinates(face);
     if (world.GetBlockID(coordinates) == AirBlock.BlockID)
     {
         world.SetBlockID(coordinates, FireBlock.BlockID);
     }
 }
示例#18
0
 public override bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     if (descriptor.Metadata == 5)
         world.SetBlockID(descriptor.Coordinates, AirBlock.BlockID);
     else
         world.SetMetadata(descriptor.Coordinates, (byte)(descriptor.Metadata + 1));
     return false;
 }
示例#19
0
        public override void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
        {
            double rotation = user.Entity.Yaw + 180 % 360;
            if (rotation < 0)
                rotation += 360;

            world.SetMetadata(descriptor.Coordinates, (byte)(rotation / 22.5));
        }
示例#20
0
 public static void HandleChangeHeldItem(IPacket _packet, IRemoteClient _client, IMultiplayerServer server)
 {
     var packet = (ChangeHeldItemPacket)_packet;
     var client = (RemoteClient)_client;
     client.SelectedSlot = (short)(packet.Slot + InventoryWindow.HotbarIndex);
     var notified = server.GetEntityManagerForWorld(client.World).ClientsForEntity(client.Entity);
     foreach (var c in notified)
         c.QueuePacket(new EntityEquipmentPacket(client.Entity.EntityID, 0, client.SelectedItem.ID, client.SelectedItem.Metadata));
 }
示例#21
0
 protected override void HandleInternal(CommandLine commandLine, IRemoteClient remoteClient)
 {
     var decorator = new ClientInformationDecorator(remoteClient);
     for (var i = 0; i < 5; i++) {
         var duration = decorator.Ping();
         WriteInfo(string.Format("Ping to client : {0} ms", duration));
         Thread.Sleep(500);
     }
 }
示例#22
0
 internal static void HandleChatMessage(IPacket _packet, IRemoteClient _client, IMultiplayerServer _server)
 {
     // TODO: Abstract this to support things like commands
     // TODO: Sanitize messages
     var packet = (ChatMessagePacket)_packet;
     var server = (MultiplayerServer)_server;
     var args = new ChatMessageEventArgs(_client, packet.Message);
     server.OnChatMessageReceived(args);
 }
示例#23
0
 public override void Handle(IRemoteClient client, string alias, string[] arguments)
 {
     if (arguments.Length != 0)
     {
         Help(client, alias, arguments);
         return;
     }
     client.World.Save();
 }
示例#24
0
 public override void Handle(IRemoteClient client, string alias, string[] arguments)
 {
     if (arguments.Length != 0)
     {
         Help(client, alias, arguments);
         return;
     }
     client.SendMessage(client.Entity.Position.ToString());
 }
 public void fixture_setup()
 {
     //setup robot service
     _service = new RemoteService(CLibrary,CType,CPort,CDocFile);
     _service.StartAsync();
     //setup client proxy
     _client = (IRemoteClient)XmlRpcProxyGen.Create(typeof(IRemoteClient));
     _client.Url = "http://127.0.0.1:" + CPort + "/" + CUrl;
 }
示例#26
0
 public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
 {
     if (world.GetBlockID(coordinates) == FarmlandBlock.BlockID)
     {
         world.SetBlockID(coordinates + MathHelper.BlockFaceToCoordinates(face), CropsBlock.BlockID);
         world.BlockRepository.GetBlockProvider(CropsBlock.BlockID).BlockPlaced(
             new BlockDescriptor { Coordinates = coordinates }, face, world, user);
     }
 }
示例#27
0
 public override bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     bool upper = ((DoorItem.DoorFlags)descriptor.Metadata & DoorItem.DoorFlags.Upper) == DoorItem.DoorFlags.Upper;
     var other = upper ? Coordinates3D.Down : Coordinates3D.Up;
     var otherMeta = world.GetMetadata(descriptor.Coordinates + other);
     world.SetMetadata(descriptor.Coordinates, (byte)(descriptor.Metadata ^ (byte)DoorItem.DoorFlags.Open));
     world.SetMetadata(descriptor.Coordinates + other, (byte)(otherMeta ^ (byte)DoorItem.DoorFlags.Open));
     return false;
 }
示例#28
0
 /// <summary>
 ///     Tries to find the specified command by first performing a
 ///     case-insensitive search on the command names, then a
 ///     case-sensitive search on the aliases.
 /// </summary>
 /// <param name="client">Client which called the command</param>
 /// <param name="alias">Case-insensitive name or case-sensitive alias of the command</param>
 /// <param name="arguments"></param>
 public void HandleCommand(IRemoteClient client, string alias, string[] arguments)
 {
     ICommand foundCommand = FindByName(alias) ?? FindByAlias(alias);
     if (foundCommand == null)
     {
         client.SendMessage("Invalid command \"" + alias + "\".");
         return;
     }
     foundCommand.Handle(client, alias, arguments);
 }
示例#29
0
 public string ExecuteCommand(IRemoteClient remoteClient, IEnumerable<string> parameters)
 {
     if (!parameters.Any()) {
         return "Missing parameters";
     }
     var sourceFilePath = parameters.First();
     var targetDirectory = parameters.Count() == 2 ? parameters.Last() : string.Empty;
     var filePath = remoteClient.UploadFile(sourceFilePath, targetDirectory);
     return string.Format("Le fichier '{0}' a bien été uploadé à l'emplacement '{1}'.", Path.GetFileName(sourceFilePath), filePath);
 }
示例#30
0
 public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
 {
     var id = world.GetBlockID(coordinates);
     if (id == DirtBlock.BlockID || id == GrassBlock.BlockID)
     {
         world.SetBlockID(coordinates, FarmlandBlock.BlockID);
         user.Server.BlockRepository.GetBlockProvider(FarmlandBlock.BlockID).BlockPlaced(
             new BlockDescriptor { Coordinates = coordinates }, face, world, user);
     }
 }
示例#31
0
        public static void HandleUpdateSignPacket(IPacket _packet, IRemoteClient _client, IMultiplayerServer server)
        {
            var packet = (UpdateSignPacket)_packet;
            var client = (RemoteClient)_client;
            var coords = new Coordinates3D(packet.X, packet.Y, packet.Z);

            if (client.Entity.Position.DistanceTo(coords) < 10) // TODO: Reach
            {
                var block = client.World.GetBlockID(coords);
                if (block == UprightSignBlock.BlockID || block == WallSignBlock.BlockID)
                {
                    client.World.SetTileEntity(coords, new NbtCompound(new[]
                    {
                        new NbtString("Text1", packet.Text[0]),
                        new NbtString("Text2", packet.Text[1]),
                        new NbtString("Text3", packet.Text[2]),
                        new NbtString("Text4", packet.Text[3]),
                    }));
                    // TODO: Some utility methods for things like "clients with given chunk loaded"
                    server.Clients.Where(c => ((RemoteClient)c).LoggedIn && c.World == _client.World).ToList().ForEach(c => c.QueuePacket(packet));
                }
            }
        }
示例#32
0
        public override void Handle(IRemoteClient client, string alias, string[] arguments)
        {
            if (arguments.Length < 2)
            {
                Help(client, alias, arguments);
                return;
            }

            string itemid = arguments[1],
                   amount = "1";

            if (arguments.Length >= 3)
            {
                amount = arguments[2];
            }

            var receivingPlayer = client;

            if (!GiveItem(receivingPlayer, itemid, amount, client))
            {
                Help(client, alias, arguments);
            }
        }
示例#33
0
        public override void Handle(IRemoteClient client, string alias, string[] arguments)
        {
            if (arguments.Length != 1)
            {
                Help(client, alias, arguments);
                return;
            }

            int Id;

            if (!int.TryParse(arguments[0], out Id))
            {
                Help(client, alias, arguments);
                return;
            }

            var manager = client.Server.GetEntityManagerForWorld(client.World);
            var entity  = manager.GetEntityById(Id);

            if (entity == null)
            {
                client.SendMessage(ChatColor.Red + "An entity with that Id does not exist in this world.");
                return;
            }

            client.SendMessage(string.Format(
                                   "{0} {1}", entity.GetType().Name, entity.Position));
            if (entity is MobEntity)
            {
                var mob = entity as MobEntity;
                client.SendMessage(string.Format(
                                       "{0}/{1} HP, {2} State, moving to to {3}",
                                       mob.Health, mob.MaxHealth,
                                       mob.CurrentState?.GetType().Name ?? "null",
                                       mob.CurrentPath?.Waypoints.Last().ToString() ?? "null"));
            }
        }
示例#34
0
        public async Task OnConnected(IRemoteClient remoteClient)
        {
            if (_remoteClientAssetFsLayer == null)
            {
                return;
            }

            var outbound = await remoteClient.ObtainOutboundReaderWriter().ConfigureAwait(false);

            try
            {
                outbound.Writer.Write("list-assets");
                outbound.Writer.Flush();
                var assetCount = outbound.Reader.ReadInt32();
                var assets     = new RemoteAssetFsFile[assetCount];
                for (var i = 0; i < assetCount; i++)
                {
                    assets[i] = ReadRemoteAssetFsFileFromStream(remoteClient, outbound.Reader);
                }
                var assetsByName = assets.ToDictionary(k => k.Name, v => v);
                foreach (var kv in assetsByName)
                {
                    _remoteClientAssetFsLayer.SetCachedFile(kv.Key, kv.Value);
                }
                foreach (var name in _remoteClientAssetFsLayer.GetCachedFileKeys())
                {
                    if (!assetsByName.ContainsKey(name))
                    {
                        _remoteClientAssetFsLayer.RemoveCachedFile(name);
                    }
                }
            }
            finally
            {
                remoteClient.ReleaseOutboundReaderWriter();
            }
        }
示例#35
0
        public override void Handle(IRemoteClient client, string alias, string[] arguments)
        {
            if (arguments.Length != 1)
            {
                Help(client, alias, arguments);
                return;
            }

            int id;

            if (!int.TryParse(arguments[0], out id))
            {
                Help(client, alias, arguments);
                return;
            }

            var manager = client.Server.GetEntityManagerForWorld(client.World);
            var entity  = manager.GetEntityByID(id) as MobEntity;

            if (entity == null)
            {
                client.SendMessage(ChatColor.Red + "An entity with that ID does not exist in this world.");
                return;
            }

            Task.Factory.StartNew(() =>
            {
                var astar = new AStarPathFinder();
                var path  = astar.FindPath(client.World, entity.BoundingBox, (Coordinates3D)entity.Position, (Coordinates3D)client.Entity.Position);
                if (path == null)
                {
                    client.SendMessage(ChatColor.Red + "It is impossible for this entity to reach you.");
                    return;
                }
                entity.CurrentPath = path;
            });
        }
示例#36
0
        public override void Handle(IRemoteClient Client, string alias, string[] arguments)
        {
            switch (arguments.Length)
            {
            case 1:
                Client.SendMessage(Client.World.Time.ToString());
                break;

            case 3:
                if (!arguments[1].Equals("set"))
                {
                    Help(Client, alias, arguments);
                }

                int newTime;

                if (!Int32.TryParse(arguments[2], out newTime))
                {
                    Help(Client, alias, arguments);
                }

                Client.World.Time = newTime;

                Client.SendMessage(string.Format("Setting time to {0}", arguments[2]));

                foreach (var client in Client.Server.Clients.Where(c => c.World.Equals(Client.World)))
                {
                    client.QueuePacket(new TimeUpdatePacket(newTime));
                }

                break;

            default:
                Help(Client, alias, arguments);
                break;
            }
        }
示例#37
0
        public async Task BackupDeployment(int deploymentId)
        {
            Deployment deployment = await _deploymentRepository.GetDeployment(deploymentId);

            if (deployment == null)
            {
                return;
            }

            Server server = await _serverRepository.GetServer(deployment.Server);

            IReadOnlyCollection <Deployment> deployments = await _deploymentRepository.GetServerDeployments(deployment.Server);

            IRemoteClient client = GetClient(server);

            string backupPath = await GetVersionedRemotePath(client, deployment, server.Paths.Backup);

            IReadOnlyCollection <string> skipPaths = deployments
                                                     .Except(new[] { deployment })
                                                     .Select(x => x.RemotePath)
                                                     .ToArray();

            await CopyRemoteFolder(client, deployment.RemotePath, backupPath, skipPaths);
        }
示例#38
0
        public static void HandleLoginRequestPacket(IPacket packet, IRemoteClient client, IMultiPlayerServer server)
        {
            var loginRequestPacket = (LoginRequestPacket)packet;

            DisconnectPacket error = default;

            if (loginRequestPacket.ProtocolVersion < server.PacketReader.ProtocolVersion)
            {
                error = new DisconnectPacket("Client outdated! Use beta 1.7.3.");
            }
            else if (loginRequestPacket.ProtocolVersion > server.PacketReader.ProtocolVersion)
            {
                error = new DisconnectPacket("Server outdated! Use beta 1.7.3.");
            }
            else if (server.Worlds.Count == 0)
            {
                error = new DisconnectPacket("Server has no worlds configured.");
            }
            else if (!server.PlayerIsWhitelisted(client.Username) && server.PlayerIsBlacklisted(client.Username))
            {
                error = new DisconnectPacket("You are banned from this server.");
            }
            else if (server.Clients.Count(c => c.Username == client.Username) > 1)
            {
                error = new DisconnectPacket("The player with this username is already logged in.");
            }

            if (error.Reason != null)
            {
                server.Trace.TraceData(TraceEventType.Start, 0, $"sending disconnect for reason: " + error.Reason);
            }
            else
            {
                Login(server, (RemoteClient)client);
            }
        }
示例#39
0
        public override void Handle(IRemoteClient client, string alias, string[] arguments)
        {
            if (arguments.Length != 1)
            {
                Help(client, alias, arguments);
                return;
            }

            var entityTypes = new List <Type>();

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var t in assembly.GetTypes())
                {
                    if (typeof(IEntity).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface)
                    {
                        entityTypes.Add(t);
                    }
                }
            }

            arguments[0] = arguments[0].ToUpper();
            var type = entityTypes.SingleOrDefault(t => t.Name.ToUpper() == arguments[0] + "ENTITY");

            if (type == null)
            {
                client.SendMessage(ChatColor.Red + "Unknown entity type.");
                return;
            }

            var entity = (IEntity)Activator.CreateInstance(type);
            var em     = client.Server.GetEntityManagerForWorld(client.World);

            entity.Position = client.Entity.Position + MathHelper.FowardVector(client.Entity.Yaw) * 3;
            em.SpawnEntity(entity);
        }
示例#40
0
 public override void Handle(IRemoteClient client, string alias, string[] arguments)
 {
     client.SendMessage("Pong!");
 }
示例#41
0
 public override void Help(IRemoteClient client, string alias, string[] arguments)
 {
     client.SendMessage("/pos: Shows your position.");
 }
示例#42
0
 public override void TileEntityLoadedForClient(BlockDescriptor descriptor, IWorld world, NbtCompound entity, IRemoteClient client)
 {
     client.QueuePacket(new UpdateSignPacket
     {
         X    = descriptor.Coordinates.X,
         Y    = (short)descriptor.Coordinates.Y,
         Z    = descriptor.Coordinates.Z,
         Text = new[]
         {
             entity["Text1"].StringValue,
             entity["Text2"].StringValue,
             entity["Text3"].StringValue,
             entity["Text4"].StringValue
         }
     });
 }
示例#43
0
 public override void BlockMined(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     world.SetTileEntity(descriptor.Coordinates, null);
     base.BlockMined(descriptor, face, world, user);
 }
示例#44
0
        public override void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
        {
            var chunk = world.FindChunk(descriptor.Coordinates);

            user.Server.Scheduler.ScheduleEvent("grass", chunk,
                                                TimeSpan.FromSeconds(MathHelper.Random.Next(MinGrowthTime, MaxGrowthTime)),
                                                s => TrySpread(descriptor.Coordinates, world, user.Server));
        }
示例#45
0
        protected static bool GiveItem(IRemoteClient receivingPlayer, string itemid, string amount, IRemoteClient client)
        {
            short id;
            int   count;

            if (!short.TryParse(itemid, out id) || !Int32.TryParse(amount, out count))
            {
                return(false);
            }

            if (client.Server.ItemRepository.GetItemProvider(id) == null)
            {
                client.SendMessage("Invalid item id \"" + id + "\".");
                return(true);
            }

            string username  = receivingPlayer.Username;
            var    inventory = receivingPlayer.Inventory as InventoryWindow;

            if (inventory == null)
            {
                return(false);
            }

            while (count > 0)
            {
                sbyte amountToGive;
                if (count >= 64)
                {
                    amountToGive = 64;
                }
                else
                {
                    amountToGive = (sbyte)count;
                }

                count -= amountToGive;

                inventory.PickUpStack(new ItemStack(id, amountToGive));
            }

            return(true);
        }
示例#46
0
        public override void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
        {
            if (ValidCactusPosition(descriptor, user.Server.BlockRepository, world))
            {
                base.BlockPlaced(descriptor, face, world, user);
            }
            else
            {
                world.SetBlockId(descriptor.Coordinates, AirBlock.BlockId);

                var manager = user.Server.GetEntityManagerForWorld(world);
                manager.SpawnEntity(
                    new ItemEntity(descriptor.Coordinates.AsVector3() + Coordinates3D.Up.AsVector3(),
                                   new ItemStack(BlockId, 1)));
                // user.Inventory.PickUpStack() wasn't working?
            }

            var chunk = world.FindChunk(descriptor.Coordinates);

            user.Server.Scheduler.ScheduleEvent("cactus", chunk,
                                                TimeSpan.FromSeconds(MathHelper.Random.Next(MinGrowthSeconds, MaxGrowthSeconds)),
                                                server => TryGrowth(server, descriptor.Coordinates, world));
        }
示例#47
0
        public override void BlockMined(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
        {
            var self    = descriptor.Coordinates;
            var entity  = world.GetTileEntity(self);
            var manager = user.Server.GetEntityManagerForWorld(world);

            if (entity != null)
            {
                foreach (var item in (NbtList)entity["Items"])
                {
                    var slot = ItemStack.FromNbt((NbtCompound)item);
                    manager.SpawnEntity(new ItemEntity(descriptor.Coordinates + new Vector3(0.5), slot));
                }
            }
            world.SetTileEntity(self, null);
            base.BlockMined(descriptor, face, world, user);
        }
示例#48
0
 public override void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     world.SetMetadata(descriptor.Coordinates, (byte)MathHelper.DirectionByRotationFlat(user.Entity.Yaw, true));
 }
示例#49
0
 public RemoteServiceDiscovery(IRemoteClient client)
 {
     _client = client;
 }
示例#50
0
 public override void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     user.Server.Scheduler.ScheduleEvent(DateTime.Now.AddSeconds(MathHelper.Random.Next(30, 60)),
                                         (server) => GrowBlock(server, world, descriptor.Coordinates + MathHelper.BlockFaceToCoordinates(face)));
 }
 public RemoteClientConnectedEventArgs(IRemoteClient remoteClient)
 {
     RemoteClient = remoteClient;
 }
示例#52
0
        public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
        {
            var bottom = coordinates + MathHelper.BlockFaceToCoordinates(face);
            var top    = bottom + Coordinates3D.Up;

            if (world.GetBlockID(top) != 0 || world.GetBlockID(bottom) != 0)
            {
                return;
            }
            DoorFlags direction;

            switch (MathHelper.DirectionByRotationFlat(user.Entity.Yaw))
            {
            case Direction.North:
                direction = DoorFlags.Northwest;
                break;

            case Direction.South:
                direction = DoorFlags.Southeast;
                break;

            case Direction.East:
                direction = DoorFlags.Northeast;
                break;

            default:     // Direction.West:
                direction = DoorFlags.Southwest;
                break;
            }
            user.Server.BlockUpdatesEnabled = false;
            world.SetBlockID(bottom, BlockID);
            world.SetMetadata(bottom, (byte)direction);
            world.SetBlockID(top, BlockID);
            world.SetMetadata(top, (byte)(direction | DoorFlags.Upper));
            user.Server.BlockUpdatesEnabled = true;
            item.Count--;
            user.Inventory[user.SelectedSlot] = item;
        }
示例#53
0
        public override void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
        {
            double rotation = user.Entity.Yaw + 180 % 360;

            if (rotation < 0)
            {
                rotation += 360;
            }

            world.SetMetadata(descriptor.Coordinates, (byte)(rotation / 22.5));
        }
示例#54
0
 public override void Help(IRemoteClient client, string alias, string[] arguments)
 {
     client.SendMessage("Correct usage is /" + alias);
 }
示例#55
0
 public override void Help(IRemoteClient client, string alias, string[] arguments)
 {
     client.SendMessage("/time: Shows the current time.");
 }
示例#56
0
        public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
        {
            coordinates += MathHelper.BlockFaceToCoordinates(face);
            if (world.GetBlockID(coordinates) == AirBlock.BlockID)
            {
                world.SetBlockID(coordinates, FireBlock.BlockID);
                world.BlockRepository.GetBlockProvider(FireBlock.BlockID)
                .BlockPlaced(world.GetBlockData(coordinates), face, world, user);

                var slot = user.SelectedItem;
                slot.Metadata += 1;
                if (slot.Metadata >= Uses)
                {
                    slot.Count = 0; // Destroy item
                }
                user.Inventory[user.SelectedSlot] = slot;
            }
        }
示例#57
0
        public override bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
        {
            var adjacent = -Coordinates3D.One; // -1, no adjacent chest
            var self     = descriptor.Coordinates;

            for (int i = 0; i < AdjacentBlocks.Length; i++)
            {
                var test = self + AdjacentBlocks[i];
                if (world.GetBlockID(test) == ChestBlock.BlockID)
                {
                    adjacent = test;
                    var up = world.BlockRepository.GetBlockProvider(world.GetBlockID(test + Coordinates3D.Up));
                    if (up.Opaque)
                    {
                        return(false); // Obstructed
                    }
                    break;
                }
            }
            var upSelf = world.BlockRepository.GetBlockProvider(world.GetBlockID(self + Coordinates3D.Up));

            if (upSelf.Opaque)
            {
                return(false); // Obstructed
            }
            if (adjacent != -Coordinates3D.One)
            {
                // Ensure that chests are always opened in the same arrangement
                if (adjacent.X < self.X ||
                    adjacent.Z < self.Z)
                {
                    var _ = adjacent;
                    adjacent = self;
                    self     = _; // Swap
                }
            }

            var window = new ChestWindow((InventoryWindow)user.Inventory, adjacent != -Coordinates3D.One);
            // Add items
            var entity = world.GetTileEntity(self);

            if (entity != null)
            {
                foreach (var item in (NbtList)entity["Items"])
                {
                    var slot = ItemStack.FromNbt((NbtCompound)item);
                    window.ChestInventory[slot.Index] = slot;
                }
            }
            // Add adjacent items
            if (adjacent != -Coordinates3D.One)
            {
                entity = world.GetTileEntity(adjacent);
                if (entity != null)
                {
                    foreach (var item in (NbtList)entity["Items"])
                    {
                        var slot = ItemStack.FromNbt((NbtCompound)item);
                        window.ChestInventory[slot.Index + ChestWindow.DoubleChestSecondaryIndex] = slot;
                    }
                }
            }
            window.WindowChange += (sender, e) =>
            {
                var entitySelf     = new NbtList("Items", NbtTagType.Compound);
                var entityAdjacent = new NbtList("Items", NbtTagType.Compound);
                for (int i = 0; i < window.ChestInventory.Items.Length; i++)
                {
                    var item = window.ChestInventory.Items[i];
                    if (!item.Empty)
                    {
                        if (i < ChestWindow.DoubleChestSecondaryIndex)
                        {
                            item.Index = i;
                            entitySelf.Add(item.ToNbt());
                        }
                        else
                        {
                            item.Index = i - ChestWindow.DoubleChestSecondaryIndex;
                            entityAdjacent.Add(item.ToNbt());
                        }
                    }
                }
                var newEntity = world.GetTileEntity(self);
                if (newEntity == null)
                {
                    newEntity = new NbtCompound(new[] { entitySelf });
                }
                else
                {
                    newEntity["Items"] = entitySelf;
                }
                world.SetTileEntity(self, newEntity);
                if (adjacent != -Coordinates3D.One)
                {
                    newEntity = world.GetTileEntity(adjacent);
                    if (newEntity == null)
                    {
                        newEntity = new NbtCompound(new[] { entityAdjacent });
                    }
                    else
                    {
                        newEntity["Items"] = entityAdjacent;
                    }
                    world.SetTileEntity(adjacent, newEntity);
                }
            };
            user.OpenWindow(window);
            return(false);
        }
示例#58
0
 public override void Help(IRemoteClient client, string alias, string[] arguments)
 {
     client.SendMessage("/reinv: Resends your inventory.");
 }
示例#59
0
        public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
        {
            int           adjacent = 0;
            var           coords   = coordinates + MathHelper.BlockFaceToCoordinates(face);
            Coordinates3D _        = Coordinates3D.Down;

            // Check for adjacent chests. We can only allow one adjacent check block.
            for (int i = 0; i < AdjacentBlocks.Length; i++)
            {
                if (world.GetBlockID(coords + AdjacentBlocks[i]) == ChestBlock.BlockID)
                {
                    _ = coords + AdjacentBlocks[i];
                    adjacent++;
                }
            }
            if (adjacent <= 1)
            {
                if (_ != Coordinates3D.Down)
                {
                    // Confirm that adjacent chest is not a double chest
                    for (int i = 0; i < AdjacentBlocks.Length; i++)
                    {
                        if (world.GetBlockID(_ + AdjacentBlocks[i]) == ChestBlock.BlockID)
                        {
                            adjacent++;
                        }
                    }
                }
                if (adjacent <= 1)
                {
                    base.ItemUsedOnBlock(coordinates, item, face, world, user);
                }
            }
        }
示例#60
0
 public override void Help(IRemoteClient client, string alias, string[] arguments)
 {
     client.SendMessage("/pos: Toggles client logging.");
 }