private async void Start()
        {
            Application.targetFrameRate = 60;

            IConnectionFlow      flow;
            ConnectionParameters connectionParameters;

            if (Application.isEditor)
            {
                flow = new ReceptionistFlow(CreateNewWorkerId(WorkerUtils.UnityGameLogic));
                connectionParameters = CreateConnectionParameters(WorkerUtils.UnityGameLogic);
            }
            else
            {
                flow = new ReceptionistFlow(CreateNewWorkerId(WorkerUtils.UnityGameLogic),
                                            new CommandLineConnectionFlowInitializer());
                connectionParameters = CreateConnectionParameters(WorkerUtils.UnityGameLogic,
                                                                  new CommandLineConnectionParameterInitializer());
            }

            var builder = new SpatialOSConnectionHandlerBuilder()
                          .SetConnectionFlow(flow)
                          .SetConnectionParameters(connectionParameters);

            await Connect(builder, new ForwardingDispatcher()).ConfigureAwait(false);
        }
Esempio n. 2
0
        private async void Start()
        {
            PlayerLifecycleConfig.CreatePlayerEntityTemplate = EntityTemplates.CreatePlayerEntityTemplate;

            IConnectionFlow      flow;
            ConnectionParameters connectionParameters;

            if (Application.isEditor)
            {
                flow = new ReceptionistFlow(CreateNewWorkerId(WorkerType));
                connectionParameters = CreateConnectionParameters(WorkerType);
            }
            else
            {
                flow = new ReceptionistFlow(CreateNewWorkerId(WorkerType),
                                            new CommandLineConnectionFlowInitializer());
                connectionParameters = CreateConnectionParameters(WorkerType,
                                                                  new CommandLineConnectionParameterInitializer());
            }

            var builder = new SpatialOSConnectionHandlerBuilder()
                          .SetConnectionFlow(flow)
                          .SetConnectionParameters(connectionParameters);

            await Connect(builder, new ForwardingDispatcher()).ConfigureAwait(false);
        }
        protected virtual IConnectionHandlerBuilder GetConnectionHandlerBuilder()
        {
            IConnectionFlow connectionFlow;
            var             connectionParams = CreateConnectionParameters(WorkerUtils.UnityClient);
            var             workerId         = CreateNewWorkerId(WorkerUtils.UnityClient);

            if (Application.isEditor)
            {
                connectionFlow = new ReceptionistFlow(workerId);
            }
            else
            {
                var initializer = new CommandLineConnectionFlowInitializer();

                switch (initializer.GetConnectionService())
                {
                case ConnectionService.Receptionist:
                    connectionFlow = new ReceptionistFlow(workerId, initializer);
                    break;

                case ConnectionService.Locator:
                    connectionParams.Network.UseExternalIp = true;
                    connectionFlow = new LocatorFlow(initializer);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(new SpatialOSConnectionHandlerBuilder()
                   .SetConnectionFlow(connectionFlow)
                   .SetConnectionParameters(connectionParams));
        }
        public void ReceptionistFlow_connects_to_local_deployment_by_default()
        {
            var receptionistFlow = new ReceptionistFlow("My-Worker-Id");

            Assert.DoesNotThrow(() => connection = receptionistFlow.CreateAsync(GetConnectionParameters()).Result);
            Assert.AreEqual(ConnectionStatusCode.Success, connection.GetConnectionStatusCode());
        }
Esempio n. 5
0
        private async void Start()
        {
            Application.targetFrameRate = 60;

            IConnectionFlow      flow;
            ConnectionParameters connectionParameters;

            if (Application.isEditor)
            {
                flow = new ReceptionistFlow(CreateNewWorkerId(WorkerUtils.UnityGameLogic));
                connectionParameters = CreateConnectionParameters(WorkerUtils.UnityGameLogic);
            }
            else
            {
                flow = new ReceptionistFlow(CreateNewWorkerId(WorkerUtils.UnityGameLogic),
                                            new CommandLineConnectionFlowInitializer());
                connectionParameters = CreateConnectionParameters(WorkerUtils.UnityGameLogic,
                                                                  new CommandLineConnectionParameterInitializer());
            }

            var builder = new SpatialOSConnectionHandlerBuilder()
                          .SetConnectionFlow(flow)
                          .SetConnectionParameters(connectionParameters);

            await Connect(builder, new ForwardingDispatcher());

            if (level == null)
            {
                return;
            }

            levelInstance = Instantiate(level, transform.position, transform.rotation);
        }
        public void ReceptionistFlow_propagates_my_worker_id()
        {
            var receptionistFlow = new ReceptionistFlow("My-Worker-Id");

            connection = receptionistFlow.CreateAsync(GetConnectionParameters()).Result;

            Assert.AreEqual("My-Worker-Id", connection.GetWorkerId());
        }
        public void Initialize_receptionist_ignores_params_that_arent_there()
        {
            var initializer = new CommandLineConnectionFlowInitializer(new Dictionary <string, string>());
            var flow        = new ReceptionistFlow("a_worker_id", initializer);

            Assert.AreEqual(RuntimeConfigDefaults.ReceptionistHost, flow.ReceptionistHost);
            Assert.AreEqual(RuntimeConfigDefaults.ReceptionistPort, flow.ReceptionistPort);
            Assert.AreEqual("a_worker_id", flow.WorkerId);
        }
        public void Initialize_receptionist_flow_correctly()
        {
            var initializer = new CommandLineConnectionFlowInitializer(GetBaseArgs());
            var flow        = new ReceptionistFlow("a_worker_id", initializer);

            Assert.AreEqual(GetBaseArgs()[RuntimeConfigNames.ReceptionistHost], flow.ReceptionistHost);
            Assert.AreEqual(1337, flow.ReceptionistPort);
            Assert.AreEqual(GetBaseArgs()[RuntimeConfigNames.WorkerId], flow.WorkerId);
        }
        protected override IConnectionHandlerBuilder GetConnectionHandlerBuilder()
        {
            var connectionParams = new ConnectionParameters
            {
                DefaultComponentVtable = new ComponentVtable(),
                WorkerType             = WorkerUtils.UnityClient
            };

            var builder = new SpatialOSConnectionHandlerBuilder()
                          .SetConnectionParameters(connectionParams);

            if (UseSessionFlow)
            {
                connectionParams.Network.UseExternalIp = true;
                builder.SetConnectionFlow(new ChosenDeploymentAlphaLocatorFlow(deployment,
                                                                               new SessionConnectionFlowInitializer(new CommandLineConnectionFlowInitializer())));
            }
            else if (Application.isEditor)
            {
                builder.SetConnectionFlow(new ReceptionistFlow(CreateNewWorkerId(WorkerUtils.UnityClient)));
            }
            else
            {
                var initializer = new CommandLineConnectionFlowInitializer();

                switch (initializer.GetConnectionService())
                {
                case ConnectionService.Receptionist:
                    var rec = new ReceptionistFlow(CreateNewWorkerId(WorkerUtils.UnityClient),
                                                   initializer);

                    connectionParams.Network.UseExternalIp = true;
                    rec.ReceptionistHost = "192.168.20.238";

                    builder.SetConnectionFlow(rec);
                    break;

                case ConnectionService.Locator:
                    connectionParams.Network.UseExternalIp = true;
                    var loc = new LocatorFlow(initializer);
                    builder.SetConnectionFlow(loc);
                    break;

                case ConnectionService.AlphaLocator:
                    connectionParams.Network.UseExternalIp = true;
                    builder.SetConnectionFlow(new AlphaLocatorFlow(initializer));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(builder);
        }
        public void ReceptionistFlow_fails_to_connection_with_invalid_port()
        {
            var receptionistFlow = new ReceptionistFlow("My-Worker-Id")
            {
                ReceptionistPort = 1337
            };

            var aggregateException = Assert.Throws <AggregateException>(() =>
                                                                        connection = receptionistFlow.CreateAsync(GetConnectionParameters()).Result);

            Assert.IsInstanceOf <ConnectionFailedException>(aggregateException.InnerExceptions[0]);
        }
Esempio n. 11
0
        public async Task ConnectSimulatedPlayer()
        {
            var connectionParams = CreateConnectionParameters(WorkerUtils.UnityClient);

            // Force the Worker ID back to the generated one otherwise it will take the coordinator's worker ID.
            var workerId = CreateNewWorkerId(WorkerUtils.UnityClient);
            var flow     = new ReceptionistFlow(workerId, new CommandLineConnectionFlowInitializer());

            flow.WorkerId = workerId;

            var builder = new SpatialOSConnectionHandlerBuilder()
                          .SetConnectionParameters(connectionParams)
                          .SetConnectionFlow(flow);

            await Connect(builder, new ForwardingDispatcher());
        }
Esempio n. 12
0
    //public bool DisableRenderers = true;

    private async void Start()
    {
        Debug.Log("Creating server worker");

        Application.targetFrameRate = 60;

        PlayerLifecycleConfig.CreatePlayerEntityTemplate = EntityTemplates.CreatePlayerEntityTemplate;

        IConnectionFlow      flow;
        ConnectionParameters connectionParameters;

        if (Application.isEditor)
        {
            flow = new ReceptionistFlow(CreateNewWorkerId(WorkerType));
            connectionParameters = CreateConnectionParameters(WorkerType);
        }
        else
        {
            flow = new ReceptionistFlow(CreateNewWorkerId(WorkerType),
                                        new CommandLineConnectionFlowInitializer());
            connectionParameters = CreateConnectionParameters(WorkerType,
                                                              new CommandLineConnectionParameterInitializer());
        }

        var builder = new SpatialOSConnectionHandlerBuilder()
                      .SetConnectionFlow(flow)
                      .SetConnectionParameters(connectionParameters);

        Debug.Log("Server configured; connecting");
        await Connect(builder, new ForwardingDispatcher()).ConfigureAwait(false);

        //if (DisableRenderers)
        //{
        //    foreach (var childRenderer in LevelInstance.GetComponentsInChildren<Renderer>())
        //    {
        //        childRenderer.enabled = false;
        //    }
        //}
    }
Esempio n. 13
0
        private IConnectionHandlerBuilder GetConnectionHandlerBuilder()
        {
            IConnectionFlow      connectionFlow;
            ConnectionParameters connectionParameters;

            var workerId = CreateNewWorkerId(WorkerUtils.UnityGameLogic);

            if (Application.isEditor)
            {
                connectionFlow       = new ReceptionistFlow(workerId);
                connectionParameters = CreateConnectionParameters(WorkerUtils.UnityGameLogic);
            }
            else
            {
                connectionFlow       = new ReceptionistFlow(workerId, new CommandLineConnectionFlowInitializer());
                connectionParameters = CreateConnectionParameters(WorkerUtils.UnityGameLogic,
                                                                  new CommandLineConnectionParameterInitializer());
            }

            return(new SpatialOSConnectionHandlerBuilder()
                   .SetConnectionFlow(connectionFlow)
                   .SetConnectionParameters(connectionParameters));
        }
Esempio n. 14
0
        protected override IConnectionHandlerBuilder GetConnectionHandlerBuilder()
        {
            IConnectionFlow      connectionFlow;
            ConnectionParameters connectionParameters;

            var workerId = CreateNewWorkerId(WorkerUtils.SimulatedPlayerCoordinator);

            if (Application.isEditor)
            {
                connectionFlow       = new ReceptionistFlow(workerId);
                connectionParameters = CreateConnectionParameters(WorkerUtils.SimulatedPlayerCoordinator);
            }
            else
            {
                connectionFlow       = new ReceptionistFlow(workerId, new CommandLineConnectionFlowInitializer());
                connectionParameters = CreateConnectionParameters(WorkerUtils.SimulatedPlayerCoordinator,
                                                                  new CommandLineConnectionParameterInitializer());
            }

            return(new SpatialOSConnectionHandlerBuilder()
                   .SetConnectionFlow(connectionFlow)
                   .SetConnectionParameters(connectionParameters));
        }