Esempio n. 1
0
        public static async Task Initialize()
        {
            Logger = new Logger();
            Logger.Log(
                $"Starting [{DateTime.Now.ToLongTimeString()}] ...");

            StartTime = DateTime.UtcNow;

            Configuration = new Configuration();
            Configuration.Initialize();

            Firebase = new Firebase();

            StatusDatabase      = new StatusDatabase();
            FingerprintDatabase = new FingerprintDatabase();
            EventDatabase       = new EventDatabase();
            Logger.Log(
                $"Loaded MySql with {await StatusDatabase.CountAsync()} status(es), {await FingerprintDatabase.CountAsync()} fingerprint(s) & {await EventDatabase.CountAsync()} event(s)");

            EventCache       = new EventCache();
            FingerprintCache = new FingerprintCache();

            GameVersionManager = new GameVersionManager();

            GameStatusManager = new GameStatusManager();
            GameStatusManager.Initialize();

            Logger.Log("Resources initialized.");
        }
Esempio n. 2
0
        private async void Update(object sender, ElapsedEventArgs args)
        {
            foreach (var game in _games)
            {
                var logs = await FingerprintDatabase.GetFingerprintLogs(game);

                UpdateLogs(logs, game);
            }
        }
Esempio n. 3
0
        public async Task <GameStatus> CreateGameStatus(string gameName)
        {
            var status = new GameStatus
            {
                GameName    = gameName,
                LastUpdated = TimeUtils.CurrentUnixTimestamp
            };

            var fingerprint = await FingerprintDatabase.GetLatestFingerprint(gameName);

            if (fingerprint == null)
            {
                status.LatestFingerprintSha     = "unknown";
                status.LatestFingerprintVersion = "unknown";
            }
            else
            {
                status.LatestFingerprintVersion = fingerprint.Version;
                status.LatestFingerprintSha     = fingerprint.Sha;
            }

            return(status);
        }
Esempio n. 4
0
        /// <summary>
        /// Configure the container with the necessary routes for your ServiceStack application.
        /// </summary>
        /// <param name="container">The built-in IoC used with ServiceStack.</param>
        public override void Configure(Container container)
        {
            //ServiceStack.Text.JsConfig.IncludeTypeInfo = true;

            //Permit modern browsers (e.g. Firefox) to allow sending of any REST HTTP Method
            Plugins.Add(new CorsFeature());

            SetConfig(new EndpointHostConfig {
                DebugMode = true,
//				DefaultContentType = "text/json", //Change default content type
            });

            //var config = new AppConfig((RestFiles.ServiceInterface.AppConfig.IAppSettings)new AppSettings());
            //container.Register(config);
            //Register Typed Config some services might need to access
            //var appSettings = new AppSettings();
            //var config = new AppConfig(new AppSettings());

            var config = new AppConfig(new ConfigurationResourceManager());

            container.Register(config);

            container.Register(config); container.Register(config);
            //All Registrations and Instances are singleton by default in Funq
            FingerprintDatabase = new FingerprintDatabase();
            container.Register(FingerprintDatabase);
            //			List<MyPerson> database = PersonList.GetPersonListAsync();
            Task database = GetPersonListAsync(container);

//			container.Register(database);

            if (!Directory.Exists(config.RootDirectory))
            {
                Directory.CreateDirectory(config.RootDirectory);
            }
        }
Esempio n. 5
0
        /// <summary>
        ///     Updates the status of a game depending on the gameserver
        /// </summary>
        /// <param name="game"></param>
        /// <param name="statusCode"></param>
        /// <param name="json"></param>
        public async void SetStatus(Enums.Game game, int statusCode, string json = null)
        {
            if (!StatusList.ContainsKey(game))
            {
                return;
            }
            var status = StatusList[game];
            var client = GetClient(game);

            client.UpdatingVersion = false;

            // Content update was the last status, before we set a new status we keep this for a given time
            if (status.Status == (int)Enums.Status.Content)
            {
                var current = TimeUtils.CurrentUnixTimestamp;
                var diff    = Math.Abs(current - status.LastUpdated);

                if (diff < TimeSpan.FromHours(Constants.ContentUpdateTimeout).TotalMilliseconds)
                {
                    Logger.Log(
                        $"Content update is newer than {Constants.ContentUpdateTimeout} hours! Not updating status.",
                        Logger.ErrorLevel.Debug);
                    return;
                }
            }

            // Content Update is new and fingerprint is given
            if (statusCode == (int)Enums.Status.Content && !string.IsNullOrEmpty(json))
            {
                var fingerprint = JsonSerializer.Deserialize <Fingerprint>(json);

                if (status.LatestFingerprintSha == fingerprint.Sha)
                {
                    Logger.Log($"The new Fingerprint of {game} has the same sha!", Logger.ErrorLevel.Error);
                    return;
                }

                status.LatestFingerprintSha     = fingerprint.Sha;
                status.LatestFingerprintVersion = fingerprint.Version;

                Logger.Log($"Fingerprint ({fingerprint.Sha}:{fingerprint.Version}) updated for {game}");

                await FingerprintDatabase.SaveFingerprintLog(new FingerprintLog
                {
                    Sha       = fingerprint.Sha,
                    Version   = fingerprint.Version,
                    Timestamp = TimeUtils.CurrentUnixTimestamp
                }, status.GameName, json);
            }

            status.LastUpdated = TimeUtils.CurrentUnixTimestamp;

            if (status.Status == statusCode)
            {
                return;
            }

            // Not send a status update after a content update
            if (status.Status != (int)Enums.Status.Content || statusCode != (int)Enums.Status.Online)
            {
                Resources.Firebase.SendNotification("Status Update", $"{status.GameName}: {(Enums.Status) statusCode}");
            }

            status.Status = statusCode;
            await StatusDatabase.SaveGameStatus(status);
        }
        public async Task <Fingerprint> Get(string gameName, string sha)
        {
            Resources.IncrementRequests();

            return(await FingerprintDatabase.GetFingerprintBySha(gameName, sha));
        }