Пример #1
0
            internal Account Login(Player player, string name)
            {
                Account account;

                if (accounts.ContainsKey(name.ToLower()))
                {
                    account = accounts[name.ToLower()];
                    if (account.Online)
                    {
                        throw new Exception("Account is already used by another player.");
                    }
                    string filename = "accounts/" + name + "." + host.Extension;
                    if (File.Exists(filename) && File.GetLastWriteTime(filename) > account.fileModified)
                    {
                        Account a = Account.Load(groups, name);
                        if (a != null)
                        {
                            accounts[name.ToLower()] = a; account = a;
                        }
                    }
                }
                else
                {
                    account       = new Account(name);
                    account.group = groups.Standard;
                    accounts.Add(name.ToLower(), account);
                } account.player = player;
                account.lastIP   = player.IP;
                account.logins++;
                account.lastLogin = DateTime.Now;
                return(account);
            }
Пример #2
0
            internal void Load(Group.List groups)
            {
                accounts.Clear();
                this.groups = groups;
                int loaded = 0;
                int failed = 0;
                int cursor = Console.CursorLeft;

                if (!Directory.Exists("accounts"))
                {
                    return;
                }
                foreach (string file in Directory.GetFiles("accounts", "*." + host.Extension))
                {
                    string  name    = file.Substring(9, file.Length - host.Extension.Length - 10);
                    Account account = Account.Load(groups, name);
                    if (account == null)
                    {
                        failed++;
                    }
                    else
                    {
                        loaded++; accounts.Add(account.name.ToLower(), account);
                    }
                    Console.Write(loaded + " account" + (loaded == 1?"":"s") + " loaded" + (failed == 0?"":" (" + failed + " failed)") + ".");
                    Console.CursorLeft = cursor;
                }
                Console.Write(loaded + " account" + (loaded == 1?"":"s") + " loaded" + (failed == 0?"":" (" + failed + " failed)") + ".");
            }