示例#1
0
        private void ParseDeleteInContainer(Internal.CommunicationStream message)
        {
            byte   containerId = message.ReadUnsignedByte();
            ushort slot;

            Appearances.ObjectInstance appendObject = null;

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameContainerPagination))
            {
                slot = message.ReadUnsignedShort();
                ushort itemId = message.ReadUnsignedShort();

                if (itemId != 0)
                {
                    appendObject = ProtocolGameExtentions.ReadObjectInstance(message, itemId);
                }
            }
            else
            {
                slot = message.ReadUnsignedByte();
            }

            var containerView = ContainerStorage.GetContainerView(containerId);

            if (!!containerView)
            {
                containerView.RemoveObject(slot, appendObject);
            }
        }
示例#2
0
        private void ParseOpenContainer(Internal.CommunicationStream message)
        {
            byte   containerId     = message.ReadUnsignedByte();
            var    objectIcon      = ProtocolGameExtentions.ReadObjectInstance(message);
            string name            = message.ReadString();
            byte   nOfSlotsPerPage = message.ReadUnsignedByte(); // capacity of shown view
            bool   isSubContainer  = message.ReadBoolean();

            bool canUseDepotSearch    = false;
            bool isDragAndDropEnabled = true;
            bool isPaginationEnabled  = false;
            int  nOfTotalObjects;
            int  indexOfFirstObject = 0;
            int  nOfContentObjects; // objects in the current shown view //

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameContainerPagination))
            {
                if (OpenTibiaUnity.GameManager.ClientVersion >= 1220)
                {
                    canUseDepotSearch = message.ReadBoolean();
                }

                isDragAndDropEnabled = message.ReadBoolean();
                isPaginationEnabled  = message.ReadBoolean();
                nOfTotalObjects      = message.ReadUnsignedShort();
                indexOfFirstObject   = message.ReadUnsignedShort();
                nOfContentObjects    = message.ReadUnsignedByte();

                if (nOfContentObjects > nOfSlotsPerPage)
                {
                    throw new System.Exception("ProtocolGame.ParseOpenContainer: Number of content objects " + nOfContentObjects + " exceeds number of slots per page " + nOfSlotsPerPage);
                }

                if (nOfContentObjects > nOfTotalObjects)
                {
                    throw new System.Exception("ProtocolGame.ParseOpenContainer: Number of content objects " + nOfContentObjects + " exceeds number of total objects " + nOfTotalObjects);
                }
            }
            else
            {
                nOfContentObjects = message.ReadUnsignedByte();
                nOfTotalObjects   = nOfContentObjects;

                if (nOfContentObjects > nOfSlotsPerPage)
                {
                    throw new System.Exception("ProtocolGame.ParseOpenContainer: Number of content objects " + nOfContentObjects + " exceeds the capaciy " + nOfSlotsPerPage);
                }
            }

            var containerView = ContainerStorage.CreateContainerView(containerId, objectIcon, name, isSubContainer,
                                                                     isDragAndDropEnabled, isPaginationEnabled, nOfSlotsPerPage,
                                                                     nOfTotalObjects - nOfContentObjects, indexOfFirstObject, nOfContentObjects);

            for (int i = 0; i < nOfContentObjects; i++)
            {
                containerView.AddObject(indexOfFirstObject + i, ProtocolGameExtentions.ReadObjectInstance(message));
            }
        }
示例#3
0
        private void ParseCreateInContainer(Internal.CommunicationStream message)
        {
            byte   containerId = message.ReadUnsignedByte();
            ushort slot        = 0;

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameContainerPagination))
            {
                slot = message.ReadUnsignedShort();
            }
            var @object = ProtocolGameExtentions.ReadObjectInstance(message);

            var containerView = ContainerStorage.GetContainerView(containerId);

            if (!!containerView)
            {
                containerView.AddObject(slot, @object);
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            var id = Guid.Parse("716025c3-441b-4ae5-a985-1b44fa698530");

            Layer[] layers;
            switch (args[0])
            {
            case "-dismount":
                ContainerStorage.DismountSandbox(args[1]);
                break;

            case "-mount":
                layers = new Layer[] { new Layer {
                                           Id = id, Path = args[2]
                                       } };
                var sandbox = ContainerStorage.MountSandbox(args[1], layers);
                Console.Out.WriteLine(sandbox.MountPath);
                break;

            case "-create":
                layers = new Layer[] { new Layer {
                                           Id = id, Path = args[2]
                                       } };
                ContainerStorage.CreateSandbox(args[1], layers);
                break;

            case "-destroy":
                ContainerStorage.DestroyLayer(args[1]);
                break;

            case "-process":
                ContainerStorage.ProcessBaseLayer(args[1]);
                break;

            case "-processvm":
                ContainerStorage.ProcessUtilityVMImage(args[1]);
                break;
            }
        }
示例#5
0
        private void ParseChangeInContainer(Internal.ByteArray message)
        {
            byte   containerId = message.ReadUnsignedByte();
            ushort slot        = 0;

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameContainerPagination))
            {
                slot = message.ReadUnsignedShort();
            }
            else
            {
                slot = message.ReadUnsignedByte();
            }
            var @object = ReadObjectInstance(message);

            var containerView = ContainerStorage.GetContainerView(containerId);

            if (!!containerView)
            {
                containerView.ChangeObject(slot, @object);
            }
        }
        public Sandbox(ContainerType containerType, Guid id)
        {
            string parent;
            string baseLayerEnv;

            switch (containerType)
            {
            case ContainerType.ServerCore:
                baseLayerEnv = servercoreBaseLayerEnv;
                break;

            case ContainerType.NanoServer:
                baseLayerEnv = nanoserverBaseLayerEnv;
                break;

            default:
                throw new ArgumentException("Invalid container type");
            }
            parent = Environment.GetEnvironmentVariable(baseLayerEnv);

            path = String.Format("C:\\\\ComputeVirtualizationTest\\{0}", id.ToString());

            layers = new Layer[]
            {
                new Layer {
                    Id = id, Path = parent
                }
            };

            try
            {
                ContainerStorage.CreateSandbox(path, layers);
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Failed to create sandbox, ensure that environment variable {0} is set to a valid base layer path", baseLayerEnv), ex);
            }
        }
示例#7
0
        public Sandbox(Guid id)
        {
            string parent;

            parent = Environment.GetEnvironmentVariable(baseLayerEnv);

            path = String.Format("C:\\\\ComputeVirtualizationTest\\{0}", id.ToString());

            layers = new Layer[]
            {
                new Layer {
                    Id = id, Path = parent
                }
            };

            try
            {
                ContainerStorage.CreateSandbox(path, layers);
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Failed to create sandbox, ensure that environment variable {0} is set to a valid base layer path", baseLayerEnv), ex);
            }
        }
示例#8
0
        private void ParseCloseContainer(Internal.CommunicationStream message)
        {
            byte containerId = message.ReadUnsignedByte();

            ContainerStorage.CloseContainerView(containerId);
        }
示例#9
0
        static void Main(string[] args)
        {
            try
            {
                var parent  = args[0];
                var path    = args[1];
                var command = args[2];
                var id      = Guid.NewGuid();
                var layers  = new Layer[]
                {
                    new Layer {
                        Id = id, Path = parent
                    }
                };

                ContainerStorage.CreateSandbox(path, layers);
                try
                {
                    Console.Out.WriteLine("creating container");

                    var cs = new ContainerSettings
                    {
                        SandboxPath = path,
                        Layers      = layers,
                        KillOnClose = true,
                        NetworkId   = HostComputeService.FindNatNetwork(),
                    };
                    using (var container = HostComputeService.CreateContainer(id.ToString(), cs))
                    {
                        Console.Out.WriteLine("starting container");
                        Console.Out.Flush();
                        container.Start();
                        try
                        {
                            var si = new ProcessStartInfo
                            {
                                CommandLine            = command,
                                RedirectStandardOutput = true,
                                KillOnClose            = true,
                            };
                            using (var process = container.CreateProcess(si))
                            {
                                Console.Out.Write(process.StandardOutput.ReadToEnd());
                                process.WaitForExit(5000);
                                Console.Out.WriteLine("process exited with {0}", process.ExitCode);
                            }
                        }
                        finally
                        {
                            Console.Out.WriteLine("shutting down container");
                            container.Shutdown(Timeout.Infinite);
                        }
                    }
                }
                finally
                {
                    ContainerStorage.DestroyLayer(path);
                }
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.Message);
                Console.Out.WriteLine(e.StackTrace);
                Environment.Exit(1);
            }
        }
 public void Dispose()
 {
     ContainerStorage.DestroyLayer(path);
 }
示例#11
0
        private void ParseCloseContainer(Internal.ByteArray message)
        {
            byte containerId = message.ReadUnsignedByte();

            ContainerStorage.CloseContainerView(containerId);
        }