public byte[] OnDeployCommand(CoreNetworkServer server, CoreNetworkOpcode opcode, byte[] payload) { //Get the parameters CoreNetworkServerType serverType = (CoreNetworkServerType)BinaryTool.ReadInt16(payload, 0); string configString = Encoding.UTF8.GetString(payload, 4, payload.Length - 4); byte count = payload[2]; //Validate that we support this if (!Program.server_types.ContainsKey(serverType)) { return(CreateFailResponse("This server manager is not configured to support this type of server.")); } //Get the config data JObject serverConfig; try { serverConfig = JsonConvert.DeserializeObject <JObject>(configString); } catch { return(CreateFailResponse("Config JSON is invalid.")); } //Create servers List <ManagerInstance> instances = new List <ManagerInstance>(); for (int i = 0; i < count; i++) { ManagerInstance instance; try { instance = Program.server_types[serverType].CreateInstance(i == count - 1, serverConfig); } catch (Exception ex) { return(CreateFailResponse($"Failed to create instance: {ex.Message} {ex.StackTrace}")); } //Start instance instance.StartProcess(); instances.Add(instance); } //Validate instances is running Thread.Sleep(500); foreach (var i in instances) { if (!i.IsProcessRunning()) { return(CreateFailResponse($"A spawned instance ({i.settings.server_id}) ended early. More may have failed.")); } } //Create response payload byte[] response = new byte[3]; response[0] = 0x00; BinaryTool.WriteUInt16(response, 1, (ushort)instances[0].settings.server_id); return(response); }