コード例 #1
0
        static async Task Main(string[] args)
        {
            // https://stackoverflow.com/questions/4926676/mono-https-webrequest-fails-with-the-authentication-or-decryption-has-failed
            ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            ServicePointManager.CheckCertificateRevocationList = false;

            IAuthenticationService authService = Refit.RestService.For <IAuthenticationService>(@"https://72.190.177.214:443");

            Console.Write($"Username: "******"Password: "******"CharacterId: ");
            string characterId = Console.ReadLine();

            string token = (await authService.TryAuthenticate(new AuthenticationRequestModel(username, password))
                            .ConfigureAwaitFalse()).AccessToken;

            HubConnection connection = new HubConnectionBuilder()
                                       .WithUrl("http://127.0.0.1:7777/realtime/social", options =>
            {
                options.Headers.Add(SocialNetworkConstants.CharacterIdRequestHeaderName, characterId);
                options.AccessTokenProvider = () => Task.FromResult(token);
            })
                                       .Build();

            await connection.StartAsync()
            .ConfigureAwaitFalseVoid();

            connection.RegisterClientInterface <IRemoteSocialHubClient>(new TestClientHandler());

            SignalRForwardedIRemoteSocialHubClient client = new SignalRForwardedIRemoteSocialHubClient(connection);

            while (true)
            {
                string input = Console.ReadLine();

                await client.SendTestMessageAsync(new TestSocialModel(input));

                /*if(input.Contains("/guild"))
                 * {
                 *      await client.SendGuildChannelTextChatMessageAsync(new GuildChatMessageRequestModel(input))
                 *              .ConfigureAwaitFalse();
                 * }
                 * else
                 *      await client.SendZoneChannelTextChatMessageAsync(new ZoneChatMessageRequestModel(input))
                 *              .ConfigureAwaitFalse();*/
            }
        }
コード例 #2
0
        static async Task Main(string[] args)
        {
            IAuthenticationService authService = Refit.RestService.For <IAuthenticationService>("http://192.168.0.3:5001");

            Console.Write($"Username: "******"Password: "******"CharacterId: ");
            string characterId = Console.ReadLine();

            string token = (await authService.TryAuthenticate(new AuthenticationRequestModel(username, password))
                            .ConfigureAwait(false)).AccessToken;

            HubConnection connection = new HubConnectionBuilder()
                                       .WithUrl("http://192.168.0.3:5008/realtime/textchat", options =>
            {
                options.Headers.Add(SocialNetworkConstants.CharacterIdRequestHeaderName, characterId);
                options.AccessTokenProvider = () => Task.FromResult(token);
            })
                                       .Build();

            await connection.StartAsync()
            .ConfigureAwait(false);

            connection.RegisterClientInterface <IRemoteSocialTextChatHubClient>(new TestClientHandler());

            SignalRForwardedIRemoteSocialTextChatHubClient client = new SignalRForwardedIRemoteSocialTextChatHubClient(connection);

            while (true)
            {
                string input = Console.ReadLine();

                if (input.Contains("/guild"))
                {
                    await client.SendGuildChannelTextChatMessageAsync(new GuildChatMessageRequestModel(input))
                    .ConfigureAwait(false);
                }
                else
                {
                    await client.SendZoneChannelTextChatMessageAsync(new ZoneChatMessageRequestModel(input))
                    .ConfigureAwait(false);
                }
            }
        }
コード例 #3
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;
                }
            });
        }