/// <summary>
        /// Short CopyUserAuthToken
        /// </summary>
        /// <param name="auth">AuthInterface</param>
        /// <param name="localUserId">Login user id</param>
        /// <returns>Token</returns>
        public static Token CopyUserAuthToken(this AuthInterface auth, EpicAccountId localUserId)
        {
            var result = auth.CopyUserAuthToken(new CopyUserAuthTokenOptions(), localUserId, out Token token);

            if (result == Result.Success)
            {
                return(token);
            }
            Debug.LogError($"error {DebugTools.GetClassMethodName()}:{result}");
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        private void ConnectInterfaceLogin()
        {
            var loginOptions = new OnlineServices.Connect.LoginOptions();

            switch (_connectInterfaceCredentialType)
            {
            case ExternalCredentialType.Epic:
            {
                Result result = AuthInterface.CopyUserAuthToken(new CopyUserAuthTokenOptions(), AccountId.EpicAccountId,
                                                                out Token token);

                if (result == Result.Success)
                {
                    _connectInterfaceCredentialToken = token.AccessToken;
                }
                else
                {
                    if (_enableDebugLogs)
                    {
                        DebugLogger.RegularDebugLog("[EpicManager] - Failed to retrieve User Auth Token");
                    }
                }

                break;
            }

            case ExternalCredentialType.DeviceidAccessToken:
                loginOptions.UserLoginInfo = new UserLoginInfo {
                    DisplayName = displayName
                };
                break;
            }

            loginOptions.Credentials =
                new OnlineServices.Connect.Credentials
            {
                Type = _connectInterfaceCredentialType, Token = _connectInterfaceCredentialToken
            };

            ConnectInterface.Login(loginOptions, null, OnConnectInterfaceLogin);
        }
Esempio n. 3
0
        /// <summary>
        ///     Shutdown epic services.
        /// </summary>
        public void OnDestroy()
        {
            if (_enableDebugLogs)
            {
                DebugLogger.RegularDebugLog("[EpicManager] - Releasing epic resources and shutting down epic services.");
            }

            if (Application.isEditor)
            {
                LogoutOptions logoutOptions =
                    new LogoutOptions {
                    LocalUserId = AccountId.EpicAccountId
                };

                // Callback might not be called since we call Logout in OnDestroy()
                AuthInterface.Logout(logoutOptions, null, OnAuthInterfaceLogout);
            }
            else
            {
                Platform.Release();
                Platform = null;
                PlatformInterface.Shutdown();
            }
        }
Esempio n. 4
0
        public WebServerTest()
        {
            Server = new WebServer();
            Server.EnableExplain     = true;
            Server.EnableFileListing = true;
            Server.SessionMode       = WebServerSessionMode.Cookie;

            Server.TransmitLayout = false;

            User         user;
            EmailAddress email;

            Server.AuthTables.CreateUser("user", "user@localhost", "password", UserState.Confirmed, 10, out user, out email);

            Server.StaticFilesPath = Directory.GetCurrentDirectory();

            Server.Register(new TestPages());

            var authInterface = new AuthInterface <UserLevel>(Server);

            Server.Register(authInterface);

            Server.Listen(8080);
        }
Esempio n. 5
0
        /// <summary>
        ///     Initialize epic sdk.
        /// </summary>
        /// <returns>Returns back whether or not the engine initialized correctly.</returns>
        private void Initialize()
        {
            if (_enableDebugLogs)
            {
                DebugLogger.RegularDebugLog("[EpicManager] - Initializing epic services.");
            }

            InitializeOptions initializeOptions =
                new InitializeOptions {
                ProductName = _options.ProductName, ProductVersion = _options.ProductVersion
            };

            Result initializeResult = PlatformInterface.Initialize(initializeOptions);

            // This code is called each time the game is run in the editor, so we catch the case where the SDK has already been initialized in the editor.
            bool isAlreadyConfiguredInEditor = Application.isEditor && initializeResult == Result.AlreadyConfigured;

            if (initializeResult != Result.Success && !isAlreadyConfiguredInEditor)
            {
                throw new Exception("[EpicManager] - Failed to initialize platform: " + initializeResult);
            }

            if (_enableDebugLogs)
            {
                LoggingInterface.SetLogLevel(LogCategory.AllCategories, _epicLoggingLevel);
                LoggingInterface.SetCallback(message => DebugLogger.EpicDebugLog(message));
            }

            ClientCredentials clientCredentials =
                new ClientCredentials {
                ClientId = _options.ClientId, ClientSecret = _options.ClientSecret
            };

            OnlineServices.Platform.Options options =
                new OnlineServices.Platform.Options
            {
                ProductId                = _options.ProductId,
                SandboxId                = _options.SandboxId,
                ClientCredentials        = clientCredentials,
                IsServer                 = false,
                DeploymentId             = _options.DeploymentId,
                TickBudgetInMilliseconds = (uint)_tickTime * 1000
            };

            Platform = PlatformInterface.Create(options);

            if (Platform != null)
            {
                if (_enableDebugLogs)
                {
                    DebugLogger.RegularDebugLog("[EpicManager] - Initialization of epic services complete.");
                }

                // Process epic services in a separate task.
                _ = UniTask.Run(Tick);

                // If we use the Auth interface then only login into the Connect interface after finishing the auth interface login
                // If we don't use the Auth interface we can directly login to the Connect interface
                if (_authInterfaceLogin)
                {
                    if (_authInterfaceCredentialType == LoginCredentialType.Developer)
                    {
                        _authInterfaceLoginCredentialId = $"localhost:{_devAuthToolPort}";
                        _authInterfaceCredentialToken   = _devAuthToolName;
                    }

                    // Login to Auth Interface
                    LoginOptions loginOptions = new LoginOptions
                    {
                        Credentials = new OnlineServices.Auth.Credentials
                        {
                            Type  = _authInterfaceCredentialType,
                            Id    = _authInterfaceLoginCredentialId,
                            Token = _authInterfaceCredentialToken
                        },
                        ScopeFlags = AuthScopeFlags.BasicProfile | AuthScopeFlags.FriendsList | AuthScopeFlags.Presence
                    };

                    AuthInterface.Login(loginOptions, null, OnAuthInterfaceLogin);
                }
                else
                {
                    // Login to Connect Interface
                    if (_connectInterfaceCredentialType == ExternalCredentialType.DeviceidAccessToken)
                    {
                        CreateDeviceIdOptions createDeviceIdOptions =
                            new CreateDeviceIdOptions
                        {
                            DeviceModel = Application.platform.ToString()
                        };
                        ConnectInterface.CreateDeviceId(createDeviceIdOptions, null, OnCreateDeviceId);
                    }
                    else
                    {
                        ConnectInterfaceLogin();
                    }
                }

                OnInitialized?.Invoke();

                return;
            }

            DebugLogger.RegularDebugLog(
                $"[EpicManager] - Failed to create platform. Ensure the relevant {typeof(Options)} are set or passed into the application as arguments.");
        }
Esempio n. 6
0
        protected override void Worker()
        {
            if (LogConsole != null)
            {
                LogConsole.ExceptionMode = LogExceptionMode.Full;
                LogConsole.Flags        |= LogConsoleFlags.DisplayTimeStamp;
                LogConsole.Mode          = LogReceiverMode.Opportune;
            }

            Logger.DebugReceiver?.Close();

            //init the async mysql connection class we want to use.
            //new MySql.Data.MySqlClient.MySqlConnection().Dispose();

            WebServer      webServer   = null;
            FtpServer      ftpServer   = null;
            MusicDataBase  mdb         = null;
            MDBBroadcaster broadcaster = null;
            DesktopPlayer  player      = null;

            try
            {
                var rootFolder = FileSystem.ProgramDirectory;
                webServer = new WebServer();
                mdb       = new MusicDataBase(rootFolder);
                if (LogSystem != null)
                {
                    //allow user to override loglevel by commandline
                    if (LogSystem.Level == LogLevel.Information)
                    {
                        LogSystem.Level = mdb.Config.ReadEnum <LogLevel>("MusicDataBase", "LogLevel", LogLevel.Information);
                    }
                }

                this.LogInfo("Loading Database...");
                mdb.Load();

                MemoryStorage.Default.LogVerboseMessages = LogSystem?.Level == LogLevel.Verbose;
                if (null != mdb.Database)
                {
                    mdb.Database.Storage.LogVerboseMessages = MemoryStorage.Default.LogVerboseMessages;
                }

                if (mdb.Config.ReadBool("MusicDataBase", "ClearDatabase", false))
                {
                    foreach (ITable t in mdb.Tables)
                    {
                        t.Clear();
                    }
                }

                mdb.Save();

                this.LogInfo("Loading auth tables...");
                if (mdb.Database != null)
                {
                    webServer.AuthTables.Connect(TableConnectorMode.Direct, mdb.Database);
                }
                else
                {
                    try
                    {
                        webServer.AuthTables.Load(mdb.DataBasePath);
                    }
                    catch (Exception ex)
                    {
                        this.LogWarning(ex, "Load auth tables failed. Recreating...");
                    }
                }
                authTables = webServer.AuthTables;

                var authInterface = new AuthInterface <MDBUserLevel>(webServer);
                {
                    //auth interface
                    User admin = webServer.AuthTables.CheckAdminPresent();
                    if (mdb.Config.ReadBool("MusicDataBase", "LocalhostIsAdmin", false))
                    {
                        authInterface.DefaultLocalhostUser = admin;
                    }
                }

                this.LogInfo("Initializing FtpServer...");
                ftpServer             = new FtpServer();
                ftpServer.CheckLogin += this.FtpServerCheckLogin;
                //add music dirs to ftp server
                SetFtpMusicFolders(mdb, ftpServer);

                int ftpPort = mdb.Config.ReadInt32("FtpServer", "Port", 8021);
                ftpServer.Listen(ftpPort);

                player = new DesktopPlayer(mdb, (long)MDBStreamType.JukeBob);
                player.Start();

                this.LogInfo("Initializing WebServer...");
                webServer.SessionMode       = WebServerSessionMode.Cookie;
                webServer.SessionTimeout    = TimeSpan.FromDays(1);
                webServer.PerformanceChecks = mdb.Config.ReadBool("WebServer", "PerformanceChecks", false);
                webServer.EnableExplain     = mdb.Config.ReadBool("WebServer", "Explain", false);
                webServer.TransmitLayout    = false;
                webServer.EnableTemplates   = true;
                webServer.CheckAccess      += WebServerCheckAccess;
                webServer.StaticFilesPath   = mdb.WebFolder;

                //prepare rpc
                var avatarFolder = mdb.GetFolderConfig("MusicDataBase", "AvatarFolder", "avatar");
                webServer.Register(new AvatarInterface(avatarFolder));
                webServer.Register(authInterface);
                var webInterface = new WebInterface(mdb, webServer.AuthTables, player);

                webInterface.LogCollector.Level            = LogLevel.Debug;
                webInterface.LogCollector.MaximumItemCount = 1000;
                webInterface.LogCollector.ExceptionMode    = LogExceptionMode.Full;

                webServer.Register(webInterface);
                webServer.Register(new HostInterface(this));

                //start server
                int webPort = mdb.Config.ReadInt32("WebServer", "Port", 8080);
                webServer.Listen(webPort);

                mdb.SetHostConfiguration(Environment.UserName + "." + Environment.MachineName, webPort, ftpPort, mdb.GetLocalAddresses());

                //using (Streamer streamer = new Streamer(mdb, MDBStreamType.JukeBox))
                broadcaster = new MDBBroadcaster(mdb);
                broadcaster.Start();

                if (mdb.Config.ReadBool("Crawler", "RunAtStartup", false))
                {
                    webInterface.FileCrawler.Start();
                }

                //main loop
                this.LogNotice("Entering main loop...");
                while (!ServiceParameters.Shutdown)
                {
                    ServiceParameters.WaitForShutdown(1000);
                    //SetConsoleTitle();
                }
            }
            finally
            {
                //cleanup
                broadcaster?.Dispose();
                ftpServer?.Close();
                player?.Stop();
                player?.Dispose();
                authTables?.Save();
                authTables = null;
                mdb?.Save();
                webServer?.Close();
            }
            this.LogInfo("Shutdown completed.");
            Logger.Flush();
        }