Ejemplo n.º 1
0
        public void WriteCharacters(string zonename, List <Character> characters)
        {
            var launchInfo = LaunchControl.GetLaunchInfo();

            if (!launchInfo.IsValid)
            {
                log.WriteError("LaunchInfo not valid");
                return;
            }
            if (!IsValidCharacterName(launchInfo.CharacterName))
            {
                try
                {
                    log.WriteInfo("WriteCharacters called with no character name, so writing launch response");
                    LaunchControl.RecordLaunchResponse(DateTime.UtcNow);
                }
                catch
                {
                    log.WriteError("WriteCharacters: Exception trying to record launch response");
                }
            }
            log.WriteDebug("LaunchInfo valid");

            // Pass info to Heartbeat
            Heartbeat.RecordServer(launchInfo.ServerName);
            Heartbeat.RecordAccount(launchInfo.AccountName);
            GameRepo.Game.SetServerAccount(server: launchInfo.ServerName, account: launchInfo.AccountName);

            string key   = GetKey(server: launchInfo.ServerName, accountName: launchInfo.AccountName);
            var    clist = new ServerCharacterListByAccount()
            {
                ZoneId        = zonename,
                CharacterList = characters
            };

            log.WriteInfo("Writing characters: " + clist.ToString());
            this._data[key] = clist;
            string contents = JsonConvert.SerializeObject(_data, Formatting.Indented);
            string path     = FileLocations.GetCharacterFilePath();

            using (var file = new StreamWriter(path, append: false))
            {
                file.Write(contents);
            }
        }
Ejemplo n.º 2
0
        private static CharacterBook ReadCharactersImpl()
        {
            string path = FileLocations.GetCharacterFilePath();

            if (!File.Exists(path))
            {
                path = FileLocations.GetOldCharacterFilePath();
            }

            if (!File.Exists(path))
            {
                return(new CharacterBook());
            }
            using (var file = new StreamReader(path))
            {
                string        contents = file.ReadToEnd();
                var           data     = JsonConvert.DeserializeObject <Dictionary <string, ServerCharacterListByAccount> >(contents);
                CharacterBook charMgr  = new CharacterBook(data);
                return(charMgr);
            }
        }