コード例 #1
0
        static void Main(string[] args)
        {
            Log.Backend = new ConsoleLogger();

            var instance_server_credentials = new List <InstanceServerDecl>();

            instance_server_credentials.Add(new InstanceServerDecl
            {
                login = new InstanceServerLogin
                {
                    app_id = Guid.Empty.ToString(),
                    secret = Guid.Empty.ToString()
                },
                name = "Test Server",
                url  = "localhost:" + PortConstants.MainServerPort
            });

            try
            {
                using (var instance_servers = InstanceServers.Create())
                {
                    var auth                 = new PlayerAuthDev();
                    var player_store         = new PlayerStore();
                    var public_service_impl  = new PublicLoginServiceImpl(auth, player_store, instance_servers);
                    var private_service_impl = new PrivateLoginServiceImpl(instance_servers, player_store);

                    public_service_impl.SetServerCredentials(instance_server_credentials);
                    instance_servers.SetServerCredentials(instance_server_credentials);



                    var server = new Server
                    {
                        Services =
                        {
                            LoginServices.LoginPrivateService.BindService(private_service_impl),
                            LoginServices.LoginPublicService.BindService(public_service_impl)
                        },
                        Ports = { new ServerPort("localhost", PortConstants.LoginServerPort, ServerCredentials.Insecure) } //TODO: SSL is required here. ALWAYS
                    };

                    Log.Msg("Starting server...");
                    server.Start();
                    Log.Msg(string.Format("Listening on port '{0}'", PortConstants.LoginServerPort));
                    Log.Msg("Press any key to stop the server...");
                    Console.ReadKey();

                    Log.Msg("Shutting down...");
                    server.ShutdownAsync().Wait();
                    Log.Msg("Shut down server...");
                }
            } catch (Exception e)
            {
                Log.Exception(e);
            }
        }
コード例 #2
0
        public static async Task RemovePlayerAndTellInstanceServer(PlayerStore player_store, Guid player_permanent_id, InstanceServers instance_servers)
        {
            var res = await player_store.RemovePlayer(player_permanent_id);

            if (res.owning_server_id.HasValue)
            {
                var server_stream = instance_servers.GetServerStream(res.owning_server_id.Value);
                if (server_stream == null)
                {
                    return;
                }
                server_stream.Enqueue(new PrivateEvent
                {
                    PlayerDisconnected = new PlayerDisconnected
                    {
                        PermanentId = player_permanent_id.ToString()
                    }
                });
            }
        }
コード例 #3
0
 public PrivateLoginServiceImpl(InstanceServers instance_servers, PlayerStore player_store)
 {
     this.instance_servers = instance_servers;
     this.player_store     = player_store;
 }
コード例 #4
0
        public override async Task ConnectAndLogIn(LogInAttempt request, IServerStreamWriter <Event> responseStream, ServerCallContext context)
        {
            {
                var name = request.Username;
                var pw   = request.Password;
                if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(pw))
                {
                    await responseStream.WriteAsync(login_failed);

                    return;
                }

                Guid permanent_id;
                if (!await auth.GetPermanentId(name, pw, out permanent_id))
                {
                    await responseStream.WriteAsync(login_failed);

                    return;
                }

                var out_stream = MTNetOutStream <Event> .Create(context, responseStream);

                if (!await player_store.AddPlayer(permanent_id, out_stream))
                {
                    await responseStream.WriteAsync(login_failed);

                    return;
                }

                {
                    var ev = new Event
                    {
                        LoginResult = new EventLoginResult
                        {
                            Success = true,
                            Token   = permanent_id.ToString()
                        }
                    };
                    ev.LoginResult.Servers.AddRange(server_credentials);
                    await responseStream.WriteAsync(ev);
                }

                for (; ;)
                {
                    try
                    {
                        if (!await out_stream.SendCurrentEvents())
                        {
                            break;
                        }
                        await Task.Delay(100);
                    }
                    catch (InvalidOperationException)
                    {
                        //Happens when cancellation token is set to true
                        break;
                    }
                    catch (RpcException)
                    {
                        break; //This is expected to happen when user logs out
                    } catch (Exception e)
                    {
                        Log.Exception(e);
                        break;
                    }
                }

                out_stream.Nullify();
                await PlayerStore.RemovePlayerAndTellInstanceServer(player_store, permanent_id, instance_servers);
            }
        }
コード例 #5
0
 public PublicLoginServiceImpl(IPlayerAuth auth, PlayerStore player_store, InstanceServers instance_servers)
 {
     this.auth             = auth;
     this.player_store     = player_store;
     this.instance_servers = instance_servers;
 }