예제 #1
0
        public void VersionTooHigh(Enums.Game game)
        {
            if (!VersionList.ContainsKey(game))
            {
                return;
            }
            var version = VersionList[game];

            Logger.Log($"Incorrect version! The version for {game}:{version} is too high!",
                       Logger.ErrorLevel.Warning);

            if (version.Minor > 0)
            {
                version.Minor--;
            }
            else if (version.Build > 0)
            {
                version.Minor = MinorMax;
                version.Build--;
            }
            else
            {
                version.Build = BuildMax;
                version.Major--;
            }

            ReconnectForUpdate(game);
        }
예제 #2
0
        public void VersionTooLow(Enums.Game game)
        {
            if (!VersionList.ContainsKey(game))
            {
                return;
            }
            var version = VersionList[game];

            Logger.Log($"Incorrect version! The version for {game}:{version} is too low!",
                       Logger.ErrorLevel.Warning);

            if (version.Minor < MinorMax)
            {
                version.Minor++;
            }
            else if (version.Build < BuildMax)
            {
                version.Minor = 0;
                version.Build++;
            }
            else
            {
                version.Build = 0;
                version.Major++;
            }

            ReconnectForUpdate(game);
        }
예제 #3
0
 /// <summary>
 ///     Returns the latest Fingerprint Hash for the game
 /// </summary>
 /// <param name="game"></param>
 /// <returns></returns>
 public string GetLatestFingerprintSha(Enums.Game game)
 {
     if (!StatusList.ContainsKey(game))
     {
         return("unknown");
     }
     return(StatusList[game].LatestFingerprintSha ?? "unknown");
 }
예제 #4
0
        public async void ReconnectForUpdate(Enums.Game game)
        {
            var client = Resources.GameStatusManager.GetClient(game);

            client.UpdatingVersion = true;

            await client.ConnectAsync(game);
        }
예제 #5
0
        /// <summary>
        ///     Connect to a game and send ClientHello
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public async Task ConnectAsync(Enums.Game game)
        {
            PacketHandler = new PacketHandler(this);
            GameClient    = new Client {
                TcpClient = this
            };

            string host;

            switch (game)
            {
            case Enums.Game.ClashofClans:
                host = "gamea.clashofclans.com";
                break;

            case Enums.Game.ClashRoyale:
                host = "game.clashroyaleapp.com";
                break;

            case Enums.Game.BrawlStars:
                host = "game.brawlstarsgame.com";
                break;

            case Enums.Game.HayDayPop:
                host = "game.prod.haydaypop.com";
                break;

            case Enums.Game.BoomBeach:
                host = "game.boombeachgame.com";
                break;

            case Enums.Game.HayDay:
                host = "game.haydaygame.com";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(game), game, null);
            }

            GameClient.CurrentGame = game;

            try
            {
                Bootstrap = new Bootstrap();
                Bootstrap.Group(Group);
                Bootstrap.Channel <TcpSocketChannel>();

                Bootstrap
                .Option(ChannelOption.TcpNodelay, true)
                .Option(ChannelOption.SoKeepalive, true)
                .Handler(new ActionChannelInitializer <IChannel>(channel =>
                {
                    var pipeline = channel.Pipeline;
                    pipeline.AddFirst("FrameDecoder",
                                      new LengthFieldBasedFrameDecoder(int.MaxValue, 2, 3, 2, 0));
                    pipeline.AddLast("PacketHandler", PacketHandler);
                    pipeline.AddLast("PacketEncoder", new PacketEncoder());
                }));

                ServerChannel =
                    await Bootstrap.ConnectAsync(host, 9339);

                /*var endpoint = (IPEndPoint) ServerChannel.RemoteAddress;
                 *
                 * Logger.Log(
                 *  $"Connected to {endpoint.Address.MapToIPv4()}:{endpoint.Port}.", Logger.ErrorLevel.Debug);*/

                GameClient.Login(Resources.GameStatusManager.GetLatestFingerprintSha(game));
            }
            catch (Exception exc)
            {
                Logger.Log(
                    $"Failed to connect ({game}): {exc}",
                    Logger.ErrorLevel.Warning);
            }
        }
예제 #6
0
 /// <summary>
 /// Get the TcpClient of a Game
 /// </summary>
 /// <param name="game"></param>
 /// <returns></returns>
 public TcpClient GetClient(Enums.Game game)
 {
     return(_clientList.ContainsKey(game) ? _clientList[game] : null);
 }
예제 #7
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);
        }
예제 #8
0
 public GameVersion GetGameVersion(Enums.Game game)
 {
     return(!VersionList.ContainsKey(game) ? null : VersionList[game]);
 }