Esempio n. 1
0
        public static void Test_isSuccessful_True_On_Success(string endpoint, int port)
        {
            //arrange
            ResolveServiceEndpointResponse model = new ResolveServiceEndpointResponse(new ResolvedEndpoint(endpoint, port));

            //assert
            Assert.True(model.isSuccessful);
        }
Esempio n. 2
0
        public static void Test_isSuccessful_False_On_Failed_ResponseCodes(ResolveServiceEndpointResponseCode resultCode)
        {
            //arrange
            ResolveServiceEndpointResponse model = new ResolveServiceEndpointResponse(resultCode);

            //assert
            Assert.False(model.isSuccessful);
        }
Esempio n. 3
0
        public async Task Test_ZoneServer_GetEndpoint_ReturnsFail_On_Empty()
        {
            //arrange
            IServiceProvider     provider   = BuildServiceProvider <ZoneServerController>("Test", 1);
            ZoneServerController controller = provider.GetService <ZoneServerController>();

            //assert
            ResolveServiceEndpointResponse result = GetActionResultObject <ResolveServiceEndpointResponse>(await controller.GetServerEndpoint(1));

            //assert
            Assert.False(result.isSuccessful);
        }
Esempio n. 4
0
        //TODO: Put this in a base class or something
        protected async Task <string> QueryForRemoteServiceEndpoint(IServiceDiscoveryService serviceDiscovery, string serviceType)
        {
            ResolveServiceEndpointResponse endpointResponse = await serviceDiscovery.DiscoverService(new ResolveServiceEndpointRequest(ClientRegionLocale.US, serviceType));

            if (!endpointResponse.isSuccessful)
            {
                throw new System.InvalidOperationException($"Failed to query for Service: {serviceType} Result: {endpointResponse.ResultCode}");
            }

            //TODO: Do we need extra slash?
            return($"{endpointResponse.Endpoint.EndpointAddress}:{endpointResponse.Endpoint.EndpointPort}/");
        }
Esempio n. 5
0
        public static void Test_Can_JSON_Serialize_To_NonNull_Non_Whitespace(string endpoint, int port)
        {
            //arrange
            ResolveServiceEndpointResponse authModel = new ResolveServiceEndpointResponse(new ResolvedEndpoint(endpoint, port));

            //act
            string serializedModel = JsonConvert.SerializeObject(authModel);

            //assert
            Assert.NotNull(serializedModel);
            Assert.IsNotEmpty(serializedModel);
            Assert.True(serializedModel.Contains(endpoint));
            Assert.True(serializedModel.Contains(port.ToString()));
        }
Esempio n. 6
0
        public static void Test_Can_JSON_Serialize_Then_Deserialize_With_Preserved_Values(ResolveServiceEndpointResponseCode resultCode)
        {
            //arrange
            ResolveServiceEndpointResponse authModel = new ResolveServiceEndpointResponse(resultCode);

            //act
            ResolveServiceEndpointResponse deserializedModel =
                JsonConvert.DeserializeObject <ResolveServiceEndpointResponse>(JsonConvert.SerializeObject(authModel));

            //assert
            Assert.NotNull(deserializedModel);
            Assert.Null(deserializedModel.Endpoint);
            Assert.True(Enum.IsDefined(typeof(ResolveServiceEndpointResponseCode), deserializedModel.ResultCode), $"Enum value: {deserializedModel.ResultCode} was not valid.");
        }
Esempio n. 7
0
        public static void Test_Can_JSON_Serialize_To_NonNull_Non_Whitespace(ResolveServiceEndpointResponseCode resultCode)
        {
            //arrange
            ResolveServiceEndpointResponse authModel = new ResolveServiceEndpointResponse(resultCode);

            //act
            string serializedModel = JsonConvert.SerializeObject(authModel);

            //assert
            Assert.NotNull(serializedModel);
            Assert.True(!serializedModel.Contains(nameof(authModel.isSuccessful)), $"JSON modle contains what should be unlisted field {nameof(authModel.isSuccessful)}. JSON: {serializedModel}");
            Assert.IsNotEmpty(serializedModel);
            Assert.True(serializedModel.Contains(((int)resultCode).ToString()));
        }
Esempio n. 8
0
        public async Task OnGameInitialized()
        {
            try
            {
                if (Client.isConnected)
                {
                    throw new InvalidOperationException($"Encountered network client already initialized.");
                }

                //To know where we must connect, we must query for the zone-endpoint that we should be connecting to.
                ResolveServiceEndpointResponse endpointResponse = await ZoneServiceClient.GetZoneConnectionEndpointAsync(ZoneDataRepository.ZoneId);

                //TODO: Handle failed queries, probably have to sent back to titlescreen
                if (endpointResponse.isSuccessful)
                {
                    if (Logger.IsInfoEnabled)
                    {
                        Logger.Info($"Recieved ZoneEndpoint: {endpointResponse.ToString()}");
                    }

                    //TODO: Handle DNS
                    if (await Client.ConnectAsync(endpointResponse.Endpoint.EndpointAddress,
                                                  endpointResponse.Endpoint.EndpointPort))
                    {
                        //TODO: We could broadcast a successful connection, but no listeners/interest right now.
                        if (Logger.IsDebugEnabled)
                        {
                            Logger.Debug($"Connected to: {endpointResponse}");
                        }
                    }
                }
                else
                if (Logger.IsErrorEnabled)
                {
                    Logger.Error($"Failed to query ZoneEndpoint.");
                }
            }
            catch (Exception e)
            {
                if (Logger.IsErrorEnabled)
                {
                    Logger.Error($"Failed to initialize instance server connection. Reason: {e.Message}");
                }

                //We NEVER throw within an initializer
                GeneralErrorPublisher.PublishEvent(this, new GeneralErrorEncounteredEventArgs("Network Error", "Failed to initialize instance server connection.", () => SceneManager.LoadScene(GladMMOClientConstants.CHARACTER_SELECTION_SCENE_NAME)));
            }
        }
Esempio n. 9
0
        public static void Test_Can_JSON_Serialize_Then_Deserialize_With_Preserved_Values(string endpoint, int port)
        {
            //arrange
            ResolveServiceEndpointResponse authModel = new ResolveServiceEndpointResponse(new ResolvedEndpoint(endpoint, port));

            //act
            ResolveServiceEndpointResponse deserializedModel =
                JsonConvert.DeserializeObject <ResolveServiceEndpointResponse>(JsonConvert.SerializeObject(authModel));

            //assert
            Assert.NotNull(deserializedModel);
            Assert.NotNull(deserializedModel.Endpoint);
            Assert.NotNull(deserializedModel.Endpoint.EndpointAddress);
            Assert.AreEqual(endpoint, deserializedModel.Endpoint.EndpointAddress);
            Assert.AreEqual(port, deserializedModel.Endpoint.EndpointPort);
        }
Esempio n. 10
0
        public async Task Test_ZoneServer_GetEndpoint_Succeeds_On_Known_Id(string endpoint, int port)
        {
            //arrange
            IServiceProvider      provider   = BuildServiceProvider <ZoneServerController>("Test", 1);
            ZoneServerController  controller = provider.GetService <ZoneServerController>();
            IZoneServerRepository repo       = provider.GetService <IZoneServerRepository>();
            await repo.TryCreateAsync(new ZoneInstanceEntryModel(1, endpoint, (short)port, 1));

            //assert
            ResolveServiceEndpointResponse result = GetActionResultObject <ResolveServiceEndpointResponse>(await controller.GetServerEndpoint(1));

            //assert
            Assert.True(result.isSuccessful);
            Assert.AreEqual(ResolveServiceEndpointResponseCode.Success, result.ResultCode);
            Assert.AreEqual(endpoint, result.Endpoint.EndpointAddress);
            Assert.AreEqual(port, result.Endpoint.EndpointPort);
        }
Esempio n. 11
0
        public async Task Test_ZoneServer_GetEndpoint_ReturnsFail_On_NoExistingZoneId(int zoneId)
        {
            //arrange
            IServiceProvider      provider   = BuildServiceProvider <ZoneServerController>("Test", 1);
            ZoneServerController  controller = provider.GetService <ZoneServerController>();
            IZoneServerRepository repo       = provider.GetService <IZoneServerRepository>();
            await repo.TryCreateAsync(new ZoneInstanceEntryModel(1, "127.0.0.1", 1080, 1));

            await repo.TryCreateAsync(new ZoneInstanceEntryModel(2, "127.0.0.1", 1080, 1));

            await repo.TryCreateAsync(new ZoneInstanceEntryModel(3, "127.0.0.1", 1080, 1));

            //assert
            ResolveServiceEndpointResponse result = GetActionResultObject <ResolveServiceEndpointResponse>(await controller.GetServerEndpoint(25));

            //assert
            Assert.False(result.isSuccessful);
        }
Esempio n. 12
0
        protected override void OnLocalPlayerSpawned(LocalPlayerSpawnedEventArgs args)
        {
            UnityAsyncHelper.UnityMainThreadContext.PostAsync(async() =>
            {
                try
                {
                    //We need to connect the hub to the social backend
                    ResolveServiceEndpointResponse endpointResponse = await ServiceDiscoveryService.DiscoverService(new ResolveServiceEndpointRequest(ClientRegionLocale.US, GladMMONetworkConstants.SOCIAL_SERVICE_NAME))
                                                                      .ConfigureAwaitFalse();

                    if (!endpointResponse.isSuccessful)
                    {
                        throw new InvalidOperationException($"Failed to query for SocialService. Reason: {endpointResponse.ResultCode}");
                    }

                    string hubConnectionString = $@"{endpointResponse.Endpoint.EndpointAddress}:{endpointResponse.Endpoint.EndpointPort}/realtime/social";

                    if (Logger.IsInfoEnabled)
                    {
                        Logger.Info($"Social HubConnection String: {hubConnectionString}");
                    }

                    //TODO: Handle failed service disc query
                    HubConnection connection = new HubConnectionBuilder()
                                               .WithUrl(hubConnectionString, options =>
                    {
                        options.Headers.Add(SocialNetworkConstants.CharacterIdRequestHeaderName, PlayerDetails.LocalPlayerGuid.EntityId.ToString());
                        options.AccessTokenProvider = () => Task.FromResult(AuthTokenProvider.Retrieve());
                    })
                                               .AddJsonProtocol()
                                               .Build();

                    //Register the reciever interface instance for the Connection Hub
                    connection.RegisterClientInterface <IRemoteSocialHubClient>(RemoteSocialClient);

                    foreach (var initable in ConnectionHubInitializable)
                    {
                        initable.Connection = connection;
                    }

                    //Just start the service when the game initializes
                    //This will make it so that the signalR clients will start to recieve messages.
                    await connection.StartAsync()
                    .ConfigureAwaitFalseVoid();

                    if (Logger.IsInfoEnabled)
                    {
                        Logger.Info($"Connected to realtime Social Service.");
                    }

                    OnRealtimeSocialServiceConnected?.Invoke(this, EventArgs.Empty);
                }
                catch (Exception e)
                {
                    if (Logger.IsErrorEnabled)
                    {
                        Logger.Error($"Failed to connect to Social Service: {e.ToString()}");
                    }

                    throw;
                }
            });
        }