コード例 #1
0
ファイル: Form1.cs プロジェクト: furrychemistry/UOX3-Tools
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            fldrAccounts.Description = "Please Select the UOX3 Accounts Directory to Load.";
            if (fldrAccounts.ShowDialog() == DialogResult.OK)
            {
                string dirPath = fldrAccounts.SelectedPath + "\\accounts.adm";
                accountList.Clear();
                listAccounts.Items.Clear();
                if (myForm.Visible)
                {
                    myForm.Clear();
                }
                txtAccountsDir.Text = fldrAccounts.SelectedPath;
                listAccounts.Update();
                txtAccountsDir.Update();

                progressBar.Minimum = 0;
                if (File.Exists(dirPath))
                {
                    progressBar.Value = 1;
                    UOXData.Script.AccountScript mScript = new UOXData.Script.AccountScript(dirPath);
                    progressBar.Maximum = mScript.Sections.Count;
                    foreach (UOXData.Script.AccountSection mSect in mScript.Sections)
                    {
                        ushort acctNum = UOXData.Conversion.ToUInt16(mSect.SectionName);
                        if (acctNum >= nextAcct)
                        {
                            nextAcct = acctNum + 1;
                        }
                        AccountObject toAdd = new AccountObject(acctNum);
                        foreach (UOXData.Script.TagDataPair mPair in mSect.TagDataPairs)
                        {
                            string mTag  = mPair.Tag.ToUpper();
                            string mData = mPair.Data;

                            switch (mTag)
                            {
                            case "NAME":
                                toAdd.Name = mData;
                                break;

                            case "PASS":
                                toAdd.Pass = mData;
                                break;

                            case "FLAGS":
                                toAdd.Flags = UOXData.Conversion.ToUInt16(mData);
                                break;

                            case "PATH":
                                toAdd.Path = mData;
                                break;

                            case "CONTACT":
                                toAdd.Contact = mData;
                                break;

                            case "TIMEBAN":
                                toAdd.TimeBan = UOXData.Conversion.ToUInt32(mData);
                                break;

                            case "CHARACTER-1":
                            case "CHARACTER-2":
                            case "CHARACTER-3":
                            case "CHARACTER-4":
                            case "CHARACTER-5":
                            case "CHARACTER-6":
                                string []  tagSplit = mTag.Split('-');
                                byte       charNum  = (byte)(UOXData.Conversion.ToUInt08(tagSplit[1]) - 1);
                                SlotObject mSlot    = toAdd.CharSlots[charNum];

                                string[] dataSplit = mData.Split(' ');
                                mSlot.Serial = UOXData.Conversion.ToUInt32(dataSplit[0]);
                                if (dataSplit[1].Length > 0)
                                {
                                    mSlot.Name = dataSplit[1].Substring(1, dataSplit[1].Length - 2);
                                }

                                if (mSlot.Serial != 0xFFFFFFFF)
                                {
                                    ++numPlayers;
                                }
                                break;

                            default:
                                break;
                            }
                        }
                        if (toAdd.GetFlag(0x0001))
                        {
                            ++numBans;
                        }
                        accountList.Add(toAdd.Name, toAdd);
                        ++numAccts;
                        listAccounts.Items.Add(toAdd.Name + " (" + mSect.SectionName + ")");
                        progressBar.PerformStep();
                    }

                    LoadOrphans();

                    UpdateStats();

                    if (listAccounts.Items.Count > 0)
                    {
                        listAccounts.SelectedIndex = 0;
                    }
                    else
                    {
                        listAccounts.Items.Add("No Accounts to Display");
                    }
                }
                else
                {
                    MessageBox.Show("Accounts.adm not found, please select a valid directory", "File Not Found");
                }
            }
        }