コード例 #1
0
        private List <UserAccount> ReadAccounts(ThwargFilter.CharacterBook characterMgr, string accountFilepath)
        {
            var    acctList    = new List <UserAccount>();
            string fileVersion = null;

            using (var reader = new StreamReader(accountFilepath))
            {
                while (!reader.EndOfStream)
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.StartsWith("#") || line.StartsWith("'"))
                        {
                            continue;
                        }
                        if (fileVersion == null)
                        {
                            if (!line.StartsWith("Version="))
                            {
                                throw new Exception("Bad account file, first line not Version");
                            }
                            if (!line.StartsWith("Version=2"))
                            {
                                throw new Exception("Bad account file, Version not 2");
                            }
                            fileVersion = line.Substring("Version=".Length);
                        }
                        if (string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }
                        var nameValueSet = ParseLineIntoAttributeSet(line);
                        // Ignore any accounts that do not at least have Name & Password
                        if (nameValueSet == null)
                        {
                            continue;
                        }
                        if (!nameValueSet.ContainsKey("Name"))
                        {
                            continue;
                        }
                        if (!nameValueSet.ContainsKey("Password"))
                        {
                            continue;
                        }
                        string accountName = nameValueSet["Name"];

                        var user = new UserAccount(accountName);
                        if (characterMgr != null)
                        {
                            user.LoadAllProperties(characterMgr, nameValueSet);
                        }

                        acctList.Add(user);
                    }
                }
            }
            return(acctList);
        }
コード例 #2
0
        private void InitializeMe(ThwargFilter.CharacterBook characterBook)
        {
            foreach (var serverItem in ServerManager.ServerList)
            {
                //TODO: Actual Server Selection
                //if (!IsServerEnabled(serverName)) { continue; }
                // Get characters from dll
                ThwargFilter.ServerCharacterListByAccount charlist = null;
                if (characterBook != null)
                {
                    charlist = characterBook.GetCharacters(serverName: serverItem.ServerName, accountName: this.Name);
                }
                // Construct server & character data
                var server = new Server(this, serverItem);

                server.ChosenCharacter = "None";

                LoadCharacterListFromThwargFilterData(server, charlist);
                if (charlist != null)
                {
                    this.ZoneId = charlist.ZoneId; // recording this each time through this loop, but it will be the same so that is okay
                }
                server.PropertyChanged += ServerPropertyChanged;
                // Record data
                _servers.Add(server);
            }
        }
コード例 #3
0
        private List <UserAccount> ReadOldUserNames(ThwargFilter.CharacterBook charBook, string oldUsersFilePath)
        {
            var acctList = new List <UserAccount>();

            using (var reader = new StreamReader(oldUsersFilePath))
            {
                while (!reader.EndOfStream)
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }
                        string[] arr = line.Split(',');
                        if (arr.Length != 2)
                        {
                            continue;
                        }
                        string accountName = arr[0];
                        string password    = arr[1];

                        var user = new UserAccount(accountName)
                        {
                            Password = password
                        };
                        acctList.Add(user);
                    }
                }
            }
            return(acctList);
        }
コード例 #4
0
 /// <summary>
 /// Used to load data from file on disk
 /// </summary>
 public void LoadAllProperties(ThwargFilter.CharacterBook characterBook, Dictionary <string, string> properties)
 {
     foreach (KeyValuePair <string, string> property in properties)
     {
         _properties[property.Key] = property.Value;
     }
     InitializeMe(characterBook);
 }