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");
            }
        }
Пример #2
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");
            }
        }
        public override void WriteString(string value)
        {
            base.WriteString(value);

            if (value == null)
            {
                this.WriteIntToByteArray(-1);
            }
            else
            {
                byte[] bytes  = LogicStringUtil.GetBytes(value);
                int    length = bytes.Length;

                if (length <= 900000)
                {
                    this.EnsureCapacity(length + 4);
                    this.WriteIntToByteArray(length);

                    Buffer.BlockCopy(bytes, 0, this.m_buffer, this.m_offset, length);

                    this.m_offset += length;
                }
                else
                {
                    Debugger.Warning("ByteStream::writeString invalid string length " + length);
                    this.WriteIntToByteArray(-1);
                }
            }
        }
Пример #4
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);
            }
        }
Пример #5
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);
 }
        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);
        }
Пример #7
0
        /// <summary>
        ///     Saves the account info to json.
        /// </summary>
        internal void SaveAccount(ServerType serverType, string passToken, int accHighId, int accLowId)
        {
            LogicJSONObject jsonRoot = new LogicJSONObject();

            jsonRoot.Put("High", new LogicJSONNumber(accHighId));
            jsonRoot.Put("Low", new LogicJSONNumber(accLowId));
            jsonRoot.Put("Pass", new LogicJSONString(passToken));

            byte[] fileContent = LogicStringUtil.GetBytes(LogicJSONParser.CreateJSONString(jsonRoot));

            using (FileStream stream = new FileStream("Files/save.json", FileMode.OpenOrCreate))
            {
                stream.Write(fileContent, 0, fileContent.Length);
            }
        }
        /// <summary>
        ///     Compresses the <see cref="LogicCompressibleString" /> instance.
        /// </summary>
        public static void Compress(LogicCompressibleString str)
        {
            string strInstance = str.Get();

            if (strInstance != null)
            {
                byte[] uncompressedData = LogicStringUtil.GetBytes(strInstance);
                int    compressedLength = ZLibHelper.CompressInZLibFormat(uncompressedData, out byte[] compressedData);

                if (compressedLength > 0)
                {
                    str.Set(compressedData, compressedLength);
                }
            }
        }
        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);
        }
Пример #10
0
        /// <summary>
        /// Writes the string.
        /// </summary>
        public void WriteString(string value)
        {
            if (value != null)
            {
                int length = value.Length;

                if (length > 0)
                {
                    this.WriteInt(length);
                    this.Write(LogicStringUtil.GetBytes(value), length);
                }
                else
                {
                    this.WriteInt(0);
                }
            }
            else
            {
                this.WriteInt(-1);
            }
        }
        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));
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Handles the request.
        /// </summary>
        private static void EndProcess(this HttpListenerContext context)
        {
            LogicLong player   = LogicTagUtil.ToLogicLong(context.Request.QueryString["player"]);
            int       debugCmd = LogicStringUtil.ConvertToInt(context.Request.QueryString["command"]);

            Connection connection = Avatars.Get(player).Connection;

            if (connection != null)
            {
                if (connection.IsConnected && LogicVersion.IsIntegration)
                {
                    new AvailableServerCommandMessage(connection, new LogicDebugCommand(connection, debugCmd)).Send();
                    context.Response.Close(LogicStringUtil.GetBytes("OK"), true);
                }
                else
                {
                    context.Response.Close(LogicStringUtil.GetBytes("Error: Connection.IsConnected == false or the server is not in integration mode"), true);
                }
            }
            else
            {
                context.Response.Close(LogicStringUtil.GetBytes("Error: Connection == null"), true);
            }
        }
Пример #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RC4"/> class.
 /// </summary>
 internal RC4(string Key)
 {
     this.Key = RC4.KSA(LogicStringUtil.GetBytes(Key));
 }
        public static void DownloadDataUpdate(string fingerprintJSON, string contentUrl)
        {
            LogicJSONObject     oldFingerprintJSON = LogicJSONParser.ParseObject(ResourceManager.FINGERPRINT_JSON);
            LogicJSONObject     newFingerprintJSON = LogicJSONParser.ParseObject(fingerprintJSON);
            LogicJSONArray      oldfileArray       = oldFingerprintJSON.GetJSONArray("files");
            LogicJSONArray      newfileArray       = newFingerprintJSON.GetJSONArray("files");
            List <DownloadTask> results            = new List <DownloadTask>();

            string fingerprintSha = newFingerprintJSON.GetJSONString("sha").GetStringValue();

            for (int i = 0; i < newfileArray.Size(); i++)
            {
                LogicJSONObject newFileObject = newfileArray.GetJSONObject(i);
                string          newFileName   = newFileObject.GetJSONString("file").GetStringValue();
                string          newFileSha    = newFileObject.GetJSONString("sha").GetStringValue();
                bool            needUpdate    = true;

                for (int j = 0; j < oldfileArray.Size(); j++)
                {
                    LogicJSONObject oldFileObject = oldfileArray.GetJSONObject(j);
                    string          oldFileName   = oldFileObject.GetJSONString("file").GetStringValue();

                    if (oldFileName == newFileName)
                    {
                        string oldFileSha = oldFileObject.GetJSONString("sha").GetStringValue();

                        if (oldFileSha == newFileSha)
                        {
                            needUpdate = false;
                        }

                        break;
                    }
                }

                if (needUpdate)
                {
                    results.Add(new DownloadTask(contentUrl, fingerprintSha, newFileName));
                }
            }

            bool success = true;

            for (int i = 0; i < results.Count; i++)
            {
                DownloadTask task = results[i];
                byte[]       data = task.Result;

                if (data != null)
                {
                    File.WriteAllBytes("assets/" + task.FileName, data);
                }
                else
                {
                    Debugger.Warning("ResourceManager.downloadDataUpdate: download file failed: " + task.FileName);
                    success = false;
                }
            }

            if (success)
            {
                File.WriteAllBytes("assets/fingerprint.json", LogicStringUtil.GetBytes(fingerprintJSON));
                ResourceManager.Init();
            }
        }