Ejemplo n.º 1
0
        /// <summary>
        ///     Loads the fingerprint file.
        /// </summary>
        private static void LoadFingeprint()
        {
            ResourceManager.FingerprintJson = ResourceManager.LoadAssetFile("fingerprint.json");

            if (ResourceManager.FingerprintJson != null)
            {
                LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(ResourceManager.FingerprintJson);

                ResourceManager.FingerprintSha     = LogicJSONHelper.GetJSONString(jsonObject, "sha");
                ResourceManager.FingerprintVersion = LogicJSONHelper.GetJSONString(jsonObject, "version");

                string[] version = ResourceManager.FingerprintVersion.Split('.');

                if (version.Length == 3)
                {
                    ResourceManager._version = new int[3];

                    for (int i = 0; i < 3; i++)
                    {
                        ResourceManager._version[i] = int.Parse(version[i]);
                    }
                }
                else
                {
                    Debugger.Error("ResourceManager::loadFingeprint invalid fingerprint version: " + ResourceManager.FingerprintVersion);
                }

                ZLibHelper.CompressInZLibFormat(LogicStringUtil.GetBytes(ResourceManager.FingerprintJson), out ResourceManager.CompressedFingeprintJson);
            }
            else
            {
                Debugger.Error("ResourceManager::loadFingeprint fingerprint.json not exist");
            }
        }
        private static void LoadFingerprint()
        {
            ResourceManager.FINGERPRINT_JSON = ResourceManager.LoadAssetString("fingerprint.json");

            if (ResourceManager.FINGERPRINT_JSON != null)
            {
                LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(ResourceManager.FINGERPRINT_JSON);

                ResourceManager.FINGERPRINT_SHA     = LogicJSONHelper.GetString(jsonObject, "sha");
                ResourceManager.FINGERPRINT_VERSION = LogicJSONHelper.GetString(jsonObject, "version");

                string[] version = ResourceManager.FINGERPRINT_VERSION.Split('.');

                if (version.Length == 3)
                {
                    ResourceManager.m_version = new int[3];

                    for (int i = 0; i < 3; i++)
                    {
                        ResourceManager.m_version[i] = int.Parse(version[i]);
                    }
                }
                else
                {
                    Logging.Error("ResourceManager.loadFingerprint: invalid fingerprint version: " + ResourceManager.FINGERPRINT_VERSION);
                }

                ZLibHelper.CompressInZLibFormat(LogicStringUtil.GetBytes(ResourceManager.FINGERPRINT_JSON), out ResourceManager.COMPRESSED_FINGERPRINT_DATA);
            }
            else
            {
                Logging.Error("ResourceManager.loadFingerprint: fingerprint.json not exist");
            }
        }
Ejemplo n.º 3
0
        private void SaveState()
        {
            if (this.m_logicGameMode.GetState() == 1)
            {
                LogicJSONObject jsonObject = new LogicJSONObject(64);

                this.m_logicGameMode.SaveToJSON(jsonObject);

                ZLibHelper.CompressInZLibFormat(LogicStringUtil.GetBytes(LogicJSONParser.CreateJSONString(jsonObject, 1536)), out byte[] homeJSON);
                ServerMessageManager.SendMessage(new GameStateCallbackMessage
                {
                    AccountId              = this.m_logicGameMode.GetLevel().GetPlayerAvatar().GetId(),
                    SessionId              = this.m_session.Id,
                    LogicClientAvatar      = this.m_logicGameMode.GetLevel().GetPlayerAvatar(),
                    AvatarChanges          = this.m_avatarChangeListener.RemoveAvatarChanges(),
                    ExecutedServerCommands = new LogicArrayList <LogicServerCommand>(),
                    HomeJSON              = homeJSON,
                    RemainingShieldTime   = this.m_logicGameMode.GetShieldRemainingSeconds(),
                    RemainingGuardTime    = this.m_logicGameMode.GetGuardRemainingSeconds(),
                    NextPersonalBreakTime = this.m_logicGameMode.GetPersonalBreakCooldownSeconds(),
                    SaveTime              = TimeUtil.GetTimestamp()
                }, 9);
            }
            else
            {
                ServerMessageManager.SendMessage(new GameStateCallbackMessage
                {
                    AccountId         = this.m_logicGameMode.GetLevel().GetPlayerAvatar().GetId(),
                    SessionId         = this.m_session.Id,
                    LogicClientAvatar = this.m_logicGameMode.GetLevel().GetPlayerAvatar(),
                    AvatarChanges     = this.m_avatarChangeListener.RemoveAvatarChanges()
                }, 9);
            }
        }
Ejemplo n.º 4
0
 private static void OnCreateReplayStreamRequestMessageReceived(CreateReplayStreamRequestMessage message)
 {
     ZLibHelper.CompressInZLibFormat(LogicStringUtil.GetBytes(message.JSON), out byte[] entry);
     StreamManager.Create(entry, out LogicLong id);
     ServerRequestManager.SendResponse(new CreateReplayStreamResponseMessage
     {
         Success = true,
         Id      = id
     }, message);
 }
Ejemplo n.º 5
0
        public static GameMode LoadMatchedAttackState(HomeSession session, GameMatchedAttackState state)
        {
            LogicClientHome   home                      = state.Home;
            LogicClientAvatar homeOwnerAvatar           = state.HomeOwnerAvatar;
            LogicClientAvatar attackerLogicClientAvatar = state.PlayerAvatar;

            int currentTimestamp            = TimeUtil.GetTimestamp();
            int secondsSinceLastSave        = state.SaveTime != -1 ? currentTimestamp - state.SaveTime : 0;
            int secondsSinceLastMaintenance = state.MaintenanceTime != -1 ? currentTimestamp - state.MaintenanceTime : 0;

            EnemyHomeDataMessage enemyHomeDataMessage = new EnemyHomeDataMessage();

            enemyHomeDataMessage.SetCurrentTimestamp(currentTimestamp);
            enemyHomeDataMessage.SetSecondsSinceLastSave(secondsSinceLastSave);
            enemyHomeDataMessage.SetSecondsSinceLastMaintenance(secondsSinceLastMaintenance);
            enemyHomeDataMessage.SetLogicClientHome(home);
            enemyHomeDataMessage.SetLogicClientAvatar(homeOwnerAvatar);
            enemyHomeDataMessage.SetAttackerLogicClientAvatar(attackerLogicClientAvatar);
            enemyHomeDataMessage.SetAttackSource(3);
            enemyHomeDataMessage.Encode();

            CompressibleStringHelper.Uncompress(home.GetCompressibleHomeJSON());
            CompressibleStringHelper.Uncompress(home.GetCompressibleCalendarJSON());
            CompressibleStringHelper.Uncompress(home.GetCompressibleGlobalJSON());

            try
            {
                GameMode gameMode = new GameMode(session);

                gameMode.m_avatarChangeListener = new AvatarChangeListener(gameMode, attackerLogicClientAvatar);
                attackerLogicClientAvatar.SetChangeListener(gameMode.m_avatarChangeListener);

                gameMode.m_logicGameMode.LoadMatchedAttackState(home, homeOwnerAvatar, attackerLogicClientAvatar, currentTimestamp, secondsSinceLastSave, secondsSinceLastMaintenance);
                gameMode.m_gameDefenderLocked = state.GameDefenderLocked;
                gameMode.m_liveReplayId       = state.LiveReplayId;

                ZLibHelper.CompressInZLibFormat(LogicStringUtil.GetBytes(LogicJSONParser.CreateJSONString(gameMode.m_logicGameMode.GetReplay().GetJson())), out byte[] streamJSON);
                ServerMessageManager.SendMessage(new InitializeLiveReplayMessage
                {
                    AccountId  = gameMode.m_liveReplayId,
                    StreamData = streamJSON
                }, 9);

                session.SendPiranhaMessage(enemyHomeDataMessage, 1);

                return(gameMode);
            }
            catch (Exception exception)
            {
                Logging.Error("GameMode.loadMatchedAttackState: exception while the loading of attack state: " + exception);
            }

            return(null);
        }
Ejemplo n.º 6
0
        public static LogicClientAvatar LoadHomeOwnerAvatarFromHome(LogicClientHome home)
        {
            string json = home.GetCompressibleHomeJSON().Get();

            if (json == null)
            {
                ZLibHelper.DecompressInMySQLFormat(home.GetCompressibleHomeJSON().GetCompressed(), out byte[] output);
                json = LogicStringUtil.CreateString(output, 0, output.Length);
            }

            LogicClientAvatar logicClientAvatar = new LogicClientAvatar();

            logicClientAvatar.LoadForReplay(LogicJSONParser.ParseObject(json), true);
            return(logicClientAvatar);
        }
Ejemplo n.º 7
0
        private void OnLoginFailedMessageReceived(LoginFailedMessage message)
        {
            this.m_serverConnection.SetState(ServerConnectionState.LOGIN_FAILED);

            switch (message.GetErrorCode())
            {
            case LoginFailedMessage.ErrorCode.DATA_VERSION:
                ZLibHelper.DecompressInMySQLFormat(message.GetCompressedFingerprint(), out byte[] output);
                ResourceManager.DownloadDataUpdate(LogicStringUtil.CreateString(output, 0, output.Length), message.GetContentUrl());
                break;

            default:
                Debugger.Warning("MessageManager.onLoginFailedMessageReceived: error code: " + message.GetErrorCode());
                break;
            }
        }
Ejemplo n.º 8
0
        public byte[] CreateChallengeSnapshot()
        {
            if (this.m_logicGameMode.GetState() != 1)
            {
                throw new Exception("GameMode.createChallengeSnapshot called in invalid logic state.");
            }

            LogicLevel      logicLevel = this.m_logicGameMode.GetLevel();
            LogicJSONObject jsonObject = new LogicJSONObject(64);

            jsonObject.Put("exp_ver", new LogicJSONNumber(logicLevel.GetExperienceVersion()));
            logicLevel.GetGameObjectManagerAt(0).SaveToSnapshot(jsonObject, 6);

            this.m_logicGameMode.GetLevel().GetHomeOwnerAvatar().SaveToDirect(jsonObject);

            ZLibHelper.CompressInZLibFormat(LogicStringUtil.GetBytes(LogicJSONParser.CreateJSONString(jsonObject, 1536)), out byte[] homeJSON);

            return(homeJSON);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Handles the specified <see cref="Message"/>.
        /// </summary>
        /// <param name="Device">The device.</param>
        /// <param name="Message">The message.</param>
        /// <param name="Cancellation">The cancellation.</param>
        public static async Task Handle(Device Device, Message Message, CancellationToken Cancellation)
        {
            var HomeBattleReplayMessage = (HomeBattleReplayMessage)Message;

            if (HomeBattleReplayMessage == null)
            {
                throw new LogicException(typeof(HomeBattleReplayHandler), nameof(HomeBattleReplayMessage) + " == null at Handle(Device, Message, CancellationToken).");
            }

            if (!HomeBattleReplayMessage.ReplayId.IsZero)
            {
                BattleLog BattleLog = await Battles.Get(HomeBattleReplayMessage.ReplayId.HigherInt, HomeBattleReplayMessage.ReplayId.LowerInt);

                if (BattleLog != null)
                {
                    int ChannelIdx = RoyalTvManager.GetChannelArenaData(HomeBattleReplayMessage.ArenaData);

                    if (ChannelIdx != -1)
                    {
                        RoyalTvEntry TvEntry = RoyalTvManager.GetEntryByIdx(ChannelIdx, HomeBattleReplayMessage.ReplayShardId);

                        if (TvEntry != null)
                        {
                            Interlocked.Increment(ref TvEntry.ViewCount);
                        }
                    }

                    byte[] Decompressed = Encoding.UTF8.GetBytes(BattleLog.ReplayJson);
                    byte[] Compressed   = ZLibHelper.CompressCompressableByteArray(Decompressed);

                    Device.NetworkManager.SendMessage(new HomeBattleReplayDataMessage(Compressed));
                }
                else
                {
                    Logging.Info(typeof(HomeBattleReplayHandler), "BattleLog == null at Handle(Device, Message, CancellationToken).");
                }
            }
            else
            {
                Logging.Info(typeof(HomeBattleReplayHandler), "ReplayId.IsZero == true at Handle(Device, Message, CancellationToken).");
            }
        }
        private static void LoadResources()
        {
            ZLibHelper.CompressInZLibFormat(LogicStringUtil.GetBytes(ServerHttpClient.DownloadString("/data/calendar.json")), out ResourceManager.SERVER_SAVE_FILE_CALENDAR);
            ZLibHelper.CompressInZLibFormat(LogicStringUtil.GetBytes(ResourceManager.LoadAssetString("globals.json")), out ResourceManager.SERVER_SAVE_FILE_GLOBAL);

            LogicDataTables.Init();
            LogicArrayList <LogicDataTableResource> resources = LogicResources.CreateDataTableResourcesArray();

            for (int i = 0; i < resources.Size(); i++)
            {
                string fileName = resources[i].GetFileName();
                string content  = ResourceManager.LoadAssetString(fileName);

                if (content != null)
                {
                    LogicResources.Load(resources, i, new CSVNode(content.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None), fileName));
                }
                else
                {
                    Logging.Error(string.Format("ResourceManager.loadResources: file {0} not exist.", fileName));
                }
            }
        }
        /// <summary>
        /// Encodes this instance.
        /// </summary>
        public override void Encode()
        {
            this.Stream.WriteVInt(3);  // Crown
            this.Stream.WriteVInt(99); // Trophies Gain
            this.Stream.WriteVInt(0);
            this.Stream.WriteVInt(0);
            this.Stream.WriteVInt(0);
            this.Stream.WriteVInt(0);
            this.Stream.WriteVInt(0);
            this.Stream.WriteVInt(0);
            this.Stream.WriteVInt(0);
            this.Stream.WriteVInt(0);

            this.Stream.WriteVInt(0);
            this.Stream.WriteBytes(ZLibHelper.CompressCompressableByteArray(this.FullUpdate));
            this.Stream.WriteBoolean(false);

            this.Stream.WriteVInt(0);
            this.Stream.WriteVInt(0);
            this.Stream.WriteVInt(0);
            this.Stream.WriteVInt(0);

            this.Stream.WriteBoolean(false);
        }
 private static byte[] Compress(byte[] json)
 {
     ZLibHelper.CompressInZLibFormat(json, out byte[] output);
     return(output);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Encodes this instance.
 /// </summary>
 public override void Encode()
 {
     this.Stream.AddRange(ZLibHelper.CompressCompressableByteArray(this.FullUpdate));
 }