コード例 #1
0
        public static List <string> EnumerateCharacterFilepaths()
        {
            List <string> filepaths = new List <string>();
            string        xpath     = FileLocations.GetCharacterFilePath(ServerName: GameRepo.Game.Server, AccountName: GameRepo.Game.Account);
            string        chardir   = System.IO.Path.GetDirectoryName(xpath);

            FileLocations.EnsureFolderExists(chardir);
            foreach (string charfilename in Directory.GetFiles(chardir))
            {
                string path = Path.Combine(chardir, charfilename);
                filepaths.Add(path);
            }
            return(filepaths);
        }
コード例 #2
0
        public static void WriteCharacters(string ServerName, 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");
                }
            }

            // Pass info to Heartbeat
            Heartbeat.RecordServer(launchInfo.ServerName);
            Heartbeat.RecordAccount(launchInfo.AccountName);

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

            // Create a dictionary of only our characters to save
            Dictionary <string, ServerCharacterListByAccount> solodict = new Dictionary <string, ServerCharacterListByAccount>();

            solodict[key] = clist;

            string contents = JsonConvert.SerializeObject(solodict, Formatting.Indented);
            string path     = FileLocations.GetCharacterFilePath(ServerName: launchInfo.ServerName, AccountName: launchInfo.AccountName);

            using (var file = new StreamWriter(path, append: false))
            {
                file.Write(contents);
            }
        }
コード例 #3
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();
                // to avoid json vulnerability, do not use TypeNameHandling.All
                var           data    = JsonConvert.DeserializeObject <Dictionary <string, ServerCharacterListByAccount> >(contents);
                CharacterBook charMgr = new CharacterBook(data);
                return(charMgr);
            }
        }