public byte[] OnDestroyCommand(CoreNetworkServer server, CoreNetworkOpcode opcode, byte[] payload)
        {
            //Get requested ID
            ushort id = BinaryTool.ReadUInt16(payload, 0);

            //Find requested server ID
            ManagerInstance instance = null;

            foreach (var s in Program.server_types)
            {
                foreach (var p in s.Value.instances)
                {
                    if (p.settings.server_id == id)
                    {
                        instance = p;
                    }
                }
            }

            //Check if failed
            if (instance == null)
            {
                return(CreateFailResponse("Could not find requested instance."));
            }

            //End
            instance.RemoveInstance().GetAwaiter().GetResult();

            //Return OK status
            return(new byte[] { 0x00 });
        }
Ejemplo n.º 2
0
        public ManagerInstance CreateInstance(bool reloadApache, JObject config)
        {
            //Generate ports to use
            int        netPort     = Program.GetNextPort();
            List <int> customPorts = new List <int>();

            for (int i = 0; i < type_config.required_ports; i++)
            {
                customPorts.Add(netPort + 1 + i);
            }

            //Generate an instance id
            ushort instanceId = Program.GetNextServerId();

            //Generate token to use
            uint token = (uint)LibDeltaSystem.Tools.SecureStringTool.GenerateSecureInteger();

            //Create server entry
            var settings = new DbSystemServer
            {
                server_id    = instanceId,
                server_token = token.ToString(),
                server_type  = type_config.type.ToString(),
                address      = Program.config.ip_address,
                port         = netPort,
                enviornment  = Program.connection.config.env,
                manager_id   = Program.config.server_id,
                ports        = customPorts,
                config       = config,
                _id          = ObjectId.GenerateNewId()
            };

            //Add
            Program.connection.system_delta_servers.InsertOne(settings);
            Program.server_instances.Add(settings);

            //Notify all of this change and allow it to propigate
            Program.connection.network.NotifyAllServerListModified();
            Thread.Sleep(400);

            //Create instances
            var instance = new ManagerInstance(this, settings);

            instances.Add(instance);

            //Modify the Apache2 config file
            UpdateApacheFile(reloadApache);

            return(instance);
        }