Example #1
0
        public static async Task <LogicArrayList <AllianceHeaderEntry> > GetAllianceHeaderList(LogicArrayList <LogicLong> ids)
        {
            LogicArrayList <AllianceHeaderEntry> allianceList = new LogicArrayList <AllianceHeaderEntry>(ids.Size());

            Task <IOperationResult <string> >[] results = new Task <IOperationResult <string> > [ids.Size()];

            for (int i = 0; i < ids.Size(); i++)
            {
                results[i] = ServerSearch.AllianceDatabase.Get(ids[i]);
            }

            for (int i = 0; i < ids.Size(); i++)
            {
                IOperationResult <string> result = await results[i];

                if (result.Success)
                {
                    LogicJSONObject     jsonObject          = LogicJSONParser.ParseObject(result.Value);
                    AllianceHeaderEntry allianceHeaderEntry = new AllianceHeaderEntry();

                    allianceHeaderEntry.Load(jsonObject);
                    allianceHeaderEntry.SetAllianceId(new LogicLong(jsonObject.GetJSONNumber(CouchbaseDocument.JSON_ATTRIBUTE_ID_HIGH).GetIntValue(),
                                                                    jsonObject.GetJSONNumber(CouchbaseDocument.JSON_ATTRIBUTE_ID_LOW).GetIntValue()));
                    allianceList.Add(allianceHeaderEntry);
                }
            }

            return(allianceList);
        }
Example #2
0
        /// <summary>
        ///     Laods the calendar.
        /// </summary>
        public void Load(string json, int activeTimestamp)
        {
            Debugger.DoAssert(json != null, "Event json NULL");

            if (json.Length > 0)
            {
                LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(json);

                if (jsonObject != null)
                {
                    LogicJSONArray eventArray = jsonObject.GetJSONArray("events");

                    if (eventArray != null)
                    {
                        for (int i = 0; i < eventArray.Size(); i++)
                        {
                            LogicJSONObject calendarObject = eventArray.GetJSONObject(i);

                            if (calendarObject != null)
                            {
                            }
                            else
                            {
                                Debugger.Error("Events json malformed!");
                            }
                        }
                    }
                }
                else
                {
                    Debugger.Error("Events json malformed!");
                }
            }
        }
        private void LoadAccount(LogicLong id)
        {
            if (id != null)
            {
                string path = string.Format("accounts/{0}-{1}", id.GetHigherInt(), id.GetLowerInt());

                if (File.Exists(path))
                {
                    LogicJSONObject jsonObject = LogicJSONParser.ParseObject(File.ReadAllText(path));

                    this.m_accountInfo = new AccountInfo
                    {
                        AccountId = new LogicLong(jsonObject.GetJSONNumber("id_high").GetIntValue(), jsonObject.GetJSONNumber("id_low").GetIntValue()),
                        PassToken = jsonObject.GetJSONString("passToken").GetStringValue()
                    };
                }
                else
                {
                    Debugger.Warning("ServerConnection.loadAccount: account doesn't exists!");
                }
            }
            else
            {
                this.m_accountInfo = new AccountInfo();
            }
        }
        public static void LoadDebugJSON(LogicLevel level, string json)
        {
            LogicJSONObject jsonObject = LogicJSONParser.ParseObject(json);

            if (jsonObject != null)
            {
                LogicArrayList <LogicComponent> unitStorageComponents = level.GetComponentManager().GetComponents(LogicComponentType.UNIT_STORAGE);

                for (int i = 0; i < unitStorageComponents.Size(); i++)
                {
                    ((LogicUnitStorageComponent)unitStorageComponents[i]).RemoveAllUnits();
                }

                level.SetLoadingVillageType(0);

                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("buildings"), LogicGameObjectType.BUILDING, 0);
                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("obstacles"), LogicGameObjectType.OBSTACLE, 0);
                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("traps"), LogicGameObjectType.TRAP, 0);
                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("decos"), LogicGameObjectType.DECO, 0);

                level.SetLoadingVillageType(1);

                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("buildings2"), LogicGameObjectType.BUILDING, 1);
                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("obstacles2"), LogicGameObjectType.OBSTACLE, 1);
                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("traps2"), LogicGameObjectType.TRAP, 1);
                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("decos2"), LogicGameObjectType.DECO, 1);

                level.SetLoadingVillageType(-1);
            }
        }
Example #5
0
        /// <summary>
        ///     Loads resources file.
        /// </summary>
        private static void LoadResources()
        {
            ResourceManager.ContentUrlList        = new LogicArrayList <string>();
            ResourceManager.ChronosContentUrlList = new LogicArrayList <string>();
            ResourceManager.AppStoreUrlList       = new LogicArrayList <string>();

            string resourceFile = WebManager.DownloadConfigString("/res/resources.json");

            if (resourceFile != null)
            {
                LogicJSONObject jsonObject          = (LogicJSONObject)LogicJSONParser.Parse(resourceFile);
                LogicJSONArray  contentArray        = jsonObject.GetJSONArray("content");
                LogicJSONArray  chronosContentArray = jsonObject.GetJSONArray("chronosContent");
                LogicJSONArray  appStoreArray       = jsonObject.GetJSONArray("appstore");

                for (int i = 0; i < contentArray.Size(); i++)
                {
                    ResourceManager.ContentUrlList.Add(contentArray.GetJSONString(i).GetStringValue());
                }

                for (int i = 0; i < chronosContentArray.Size(); i++)
                {
                    ResourceManager.ChronosContentUrlList.Add(chronosContentArray.GetJSONString(i).GetStringValue());
                }

                for (int i = 0; i < appStoreArray.Size(); i++)
                {
                    ResourceManager.AppStoreUrlList.Add(appStoreArray.GetJSONString(i).GetStringValue());
                }
            }
            else
            {
                Debugger.Error("ResourceManager::loadResources resources.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");
            }
        }
Example #7
0
        /// <summary>
        /// Initializes the <see cref="Fingerprint"/> class.
        /// </summary>
        public static void Init()
        {
            if (Fingerprint.Initialized)
            {
                return;
            }

            try
            {
                if (!Fingerprint.Patched)
                {
                    FileInfo file = new FileInfo($@"{Directory.GetCurrentDirectory()}\Gamefiles\fingerprint.json");

                    if (file.Exists)
                    {
                        Fingerprint.Json = file.ReadAllText();

                        LogicJSONObject json = LogicJSONParser.ParseObject(Fingerprint.Json);
                        Fingerprint.Sha     = json.GetJsonString("sha").GetStringValue();
                        Fingerprint.Version = json.GetJsonString("version").GetStringValue().Split('.');
                    }
                    else
                    {
                        Debugger.Error("The Fingerprint cannot be loaded, the file does not exist.");
                    }
                }
            }
            catch (Exception exception)
            {
                Debugger.Error($"{exception.GetType().Name} while parsing the fingerprint.");
            }

            Fingerprint.Initialized = true;
        }
Example #8
0
        public void LoadNpcDuelState(LogicClientHome home, LogicAvatar homeOwnerAvatar, LogicAvatar visitorAvatar, int currentTimestamp, int secondsSinceLastSave)
        {
            if (this.m_state != 0)
            {
                Debugger.Error("loadNpcDuelState called from invalid state");
            }
            else
            {
                this.m_state          = 2;
                this.m_startTimestamp = currentTimestamp;
                this.m_configuration.Load((LogicJSONObject)LogicJSONParser.Parse(home.GetGlobalJSON()));
                this.m_calendar.Load(home.GetCalendarJSON(), currentTimestamp);

                if (this.m_battleTimer != null)
                {
                    this.m_battleTimer.Destruct();
                    this.m_battleTimer = null;
                }

                this.m_level.SetMatchType(9, null);
                this.m_level.SetVillageType(1);
                this.m_level.SetHome(home, false);
                this.m_level.SetHomeOwnerAvatar(homeOwnerAvatar);
                this.m_level.SetVisitorAvatar(visitorAvatar);
                this.m_level.FastForwardTime(secondsSinceLastSave);
                this.m_level.LoadingFinished();

                this.m_replay = new LogicReplay(this.m_level);
            }
        }
Example #9
0
        /// <summary>
        ///     Loads this instance from json.
        /// </summary>
        internal void Load(string json)
        {
            LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(json);

            this.Id                 = new LogicLong(LogicJSONHelper.GetJSONNumber(jsonObject, "id_hi"), LogicJSONHelper.GetJSONNumber(jsonObject, "id_lo"));
            this.PassToken          = LogicJSONHelper.GetJSONString(jsonObject, "pass_t");
            this.PlayTimeSecs       = LogicJSONHelper.GetJSONNumber(jsonObject, "pt_secs");
            this.AccountCreatedDate = LogicJSONHelper.GetJSONString(jsonObject, "acc_cr");
            this.TotalBan           = LogicJSONHelper.GetJSONNumber(jsonObject, "t_ban");

            LogicJSONArray sessionArray = jsonObject.GetJSONArray("sessions");

            if (sessionArray != null)
            {
                int size = LogicMath.Min(sessionArray.Size(), 20);

                for (int i = 0; i < size; i++)
                {
                    LogicJSONObject obj     = sessionArray.GetJSONObject(i);
                    AccountSession  session = new AccountSession();
                    session.Load(obj);
                    this.LastSessions.Add(session);
                }
            }

            LogicJSONObject banObject = jsonObject.GetJSONObject("ban");

            if (banObject != null)
            {
                this.CurrentBan = new AccountBan();
                this.CurrentBan.Load(banObject);
            }
        }
Example #10
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");
            }
        }
Example #11
0
        private void CreateChallengeReplay()
        {
            string battleLog = LogicJSONParser.CreateJSONString(this.m_logicGameMode.GetLevel().GetBattleLog().GenerateAttackerJSON());

            ServerRequestManager.Create(new CreateReplayStreamRequestMessage
            {
                JSON = LogicJSONParser.CreateJSONString(this.m_logicGameMode.GetReplay().GetJson(), 1536)
            }, ServerManager.GetNextSocket(11)).OnComplete = args =>
            {
                LogicLong replayId = null;

                if (args.ErrorCode == ServerRequestError.Success && args.ResponseMessage.Success)
                {
                    replayId = ((CreateReplayStreamResponseMessage)args.ResponseMessage).Id;
                }

                ServerMessageManager.SendMessage(new AllianceChallengeReportMessage
                {
                    AccountId = this.m_challengeAllianceId,
                    StreamId  = this.m_challengeStreamId,
                    ReplayId  = replayId,
                    BattleLog = battleLog
                }, 11);
            };
        }
Example #12
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);
            }
        }
Example #13
0
        public override void Decode(ByteStream stream)
        {
            this.m_id   = stream.ReadVInt();
            this.m_data = (LogicGameObjectData)LogicDataTables.GetDataById(stream.ReadVInt());
            this.m_json = LogicJSONParser.ParseObject(stream.ReadString(900000) ?? string.Empty);

            base.Decode(stream);
        }
Example #14
0
        public override void Encode(ChecksumEncoder encoder)
        {
            encoder.WriteVInt(this.m_id);
            encoder.WriteVInt(this.m_data.GetGlobalID());
            encoder.WriteString(LogicJSONParser.CreateJSONString(this.m_json));

            base.Encode(encoder);
        }
Example #15
0
        public static void SaveHomeOwnerAvatarInHome(LogicClientAvatar logicClientAvatar, LogicClientHome logicClientHome)
        {
            CompressibleStringHelper.Uncompress(logicClientHome.GetCompressibleHomeJSON());
            LogicJSONObject jsonObject = LogicJSONParser.ParseObject(logicClientHome.GetCompressibleHomeJSON().Get());

            logicClientAvatar.SaveToDirect(jsonObject);
            logicClientHome.SetHomeJSON(LogicJSONParser.CreateJSONString(jsonObject, 512));
            CompressibleStringHelper.Compress(logicClientHome.GetCompressibleHomeJSON());
        }
        /// <summary>
        ///     Create a new <see cref="AvatarAccount"/> instance.
        /// </summary>
        internal static AvatarAccount CreatePartyAccount(LogicLong homeId)
        {
            AvatarAccount avatarAccount = new AvatarAccount(homeId);

            AvatarAccountManager._accounts.Add(homeId, avatarAccount);
            DatabaseManager.Insert(0, homeId, LogicJSONParser.CreateJSONString(avatarAccount.Save()));

            return(avatarAccount);
        }
Example #17
0
        /// <summary>
        ///     Initializes this instance.
        /// </summary>
        internal static void Initialize()
        {
            ResourceManager.FingerprintJson = File.ReadAllText("Assets/fingerprint.json");

            LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(ResourceManager.FingerprintJson);

            ResourceManager.FingerprintSha     = LogicJSONHelper.GetJSONString(jsonObject, "sha");
            ResourceManager.FingerprintVersion = LogicJSONHelper.GetJSONString(jsonObject, "version");
        }
        public static string Save(CouchbaseDocument document)
        {
            LogicJSONObject jsonObject = new LogicJSONObject();

            jsonObject.Put(CouchbaseDocument.JSON_ATTRIBUTE_ID_HIGH, new LogicJSONNumber(document.Id.GetHigherInt()));
            jsonObject.Put(CouchbaseDocument.JSON_ATTRIBUTE_ID_LOW, new LogicJSONNumber(document.Id.GetLowerInt()));
            document.Save(jsonObject);

            return(LogicJSONParser.CreateJSONString(jsonObject, 256));
        }
        /// <summary>
        ///     Loads the account info from json.
        /// </summary>
        internal void LoadAccount()
        {
            if (File.Exists("Files/save.json"))
            {
                LogicJSONObject jsonRoot = (LogicJSONObject)LogicJSONParser.Parse(File.ReadAllText("Files/save.json"));

                this._account.AccountHighId    = LogicJSONHelper.GetJSONNumber(jsonRoot, "High");
                this._account.AccountLowId     = LogicJSONHelper.GetJSONNumber(jsonRoot, "Low");
                this._account.AccountPassToken = LogicJSONHelper.GetJSONString(jsonRoot, "Pass");
            }
        }
        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);
        }
        public static T Load <T>(string json) where T : CouchbaseDocument, new()
        {
            LogicJSONObject jsonObject = LogicJSONParser.ParseObject(json);

            T document = new T();

            document.Id = LogicLong.ToLong(jsonObject.GetJSONNumber(CouchbaseDocument.JSON_ATTRIBUTE_ID_HIGH).GetIntValue(),
                                           jsonObject.GetJSONNumber(CouchbaseDocument.JSON_ATTRIBUTE_ID_LOW).GetIntValue());
            document.Load(jsonObject);

            return(document);
        }
Example #22
0
        /// <summary>
        ///     Called when a <see cref="ServerUnboundMessage"/> is received.
        /// </summary>
        internal void ServerUnboundMessageReceived(ServerUnboundMessage message)
        {
            byte[] sessionId = message.GetSessionId();

            if (NetAvatarSessionManager.TryRemove(sessionId, out NetAvatarSession session))
            {
                DatabaseManager.Update(0, session.AvatarAccount.Id, LogicJSONParser.CreateJSONString(session.AvatarAccount.Save()));

                session.AvatarAccount.SetSession(null);
                session.Destruct();
            }
        }
Example #23
0
        /// <summary>
        ///     Loads this instance from json.
        /// </summary>
        internal void Load(string json)
        {
            LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(json);

            this.Id = new LogicLong(LogicJSONHelper.GetJSONNumber(jsonObject, "id_hi"), LogicJSONHelper.GetJSONNumber(jsonObject, "id_lo"));

            LogicJSONObject entryObject = jsonObject.GetJSONObject("entry");

            if (entryObject != null)
            {
                this.AvatarEntry.Load(entryObject);
            }
        }
Example #24
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);
        }
        /// <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);
            }
        }
Example #26
0
        public void LoadDirectAttackState(LogicClientHome home, LogicAvatar homeOwnerAvatar, LogicAvatar visitorAvatar, int secondsSinceLastSave, bool war, bool village2,
                                          int currentTimestamp)
        {
            if (this.m_state != 0)
            {
                Debugger.Error("loadAttackState called from invalid state");
            }

            this.m_state          = 2;
            this.m_startTimestamp = currentTimestamp;
            this.m_configuration.Load((LogicJSONObject)LogicJSONParser.Parse(home.GetGlobalJSON()));
            this.m_calendar.Load(home.GetCalendarJSON(), currentTimestamp);

            if (this.m_battleTimer != null)
            {
                this.m_battleTimer.Destruct();
                this.m_battleTimer = null;
            }

            this.m_battleTimer = new LogicTimer();
            this.m_battleTimer.StartTimer(
                LogicDataTables.GetGlobals().GetAttackLengthSecs() + (village2
                    ? LogicDataTables.GetGlobals().GetAttackVillage2PreparationLengthSecs()
                    : LogicDataTables.GetGlobals().GetAttackPreparationLengthSecs()),
                this.m_level.GetLogicTime(), false, -1);

            if (!homeOwnerAvatar.IsClientAvatar())
            {
                Debugger.Error("loadDirectAttackState called and home owner is not client avatar");
            }

            this.m_level.SetMatchType(village2 ? 8 : war ? 7 : 3, null);

            if (village2)
            {
                this.m_level.SetVillageType(1);
            }

            this.m_level.SetHome(home, false);
            this.m_level.SetHomeOwnerAvatar(homeOwnerAvatar);

            homeOwnerAvatar.SetLevel(this.m_level);

            this.m_level.SetVisitorAvatar(visitorAvatar);
            this.m_level.FastForwardTime(secondsSinceLastSave);
            this.m_level.LoadingFinished();
            this.m_replay = new LogicReplay(this.m_level);
        }
        public static LogicJSONObject DownloadJSON(string path)
        {
            try
            {
                using (WebClient client = ServerHttpClient.CreateWebClient())
                {
                    return(LogicJSONParser.ParseObject(client.DownloadString(string.Format("{0}/{1}", ServerCore.ConfigurationServer, path))));
                }
            }
            catch (Exception)
            {
                Logging.Warning(string.Format("ServerHttpClient: file {0} doesn't exist", path));
            }

            return(null);
        }
        public override void Decode()
        {
            base.Decode();

            this.m_serverChecksum = this.m_stream.ReadInt();
            this.m_clientChecksum = this.m_stream.ReadInt();
            this.m_subtick        = this.m_stream.ReadInt();

            if (this.m_stream.ReadBoolean())
            {
                string json = this.m_stream.ReadString(900000);

                if (json != null)
                {
                    this.m_debugJSON = LogicJSONParser.ParseObject(json);
                }
            }
        }
        public override void Encode()
        {
            base.Encode();

            this.m_stream.WriteInt(this.m_serverChecksum);
            this.m_stream.WriteInt(this.m_clientChecksum);
            this.m_stream.WriteInt(this.m_subtick);

            if (this.m_debugJSON != null)
            {
                this.m_stream.WriteBoolean(true);
                this.m_stream.WriteString(LogicJSONParser.CreateJSONString(this.m_debugJSON, 1024));
            }
            else
            {
                this.m_stream.WriteBoolean(false);
            }
        }
Example #30
0
        private static void GenerateFingerprint()
        {
            string version = Program.m_currentVersion[0] + "." + Program.m_currentVersion[1] + "." + (Program.m_currentVersion[2] + 1);

            LogicJSONObject jsonObject = new LogicJSONObject();
            LogicJSONArray  fileArray  = new LogicJSONArray(Program.m_files.Count);

            for (int i = 0; i < Program.m_files.Count; i++)
            {
                fileArray.Add(Program.m_files[i].SaveToJson());
            }

            jsonObject.Put("files", fileArray);
            jsonObject.Put("sha", new LogicJSONString(Program.m_sha));
            jsonObject.Put("version", new LogicJSONString(version));

            Program.m_fingerprint = LogicJSONParser.CreateJSONString(jsonObject);
        }