예제 #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 Logout(Account account)
 {
     if (!account.Online) { throw new Exception("Account isn't used."); }
     account.player = null;
     account.lastLogout = DateTime.Now;
     account.total += account.lastLogout-account.lastLogin;
     account.Save();
 }
예제 #3
0
 private static Account Load(Group.List groups,string name)
 {
     try {
         string filename = "accounts/"+name+"."+host.Extension;
         string rootName;
         Node node = host.Load(filename,out rootName);
         if (rootName!="account") { return null; }
         string n = (string)node["name"].Value;
         if (n.ToLower()!=name.ToLower()) { return null; }
         Group group = groups[(string)node["group"].Value];
         if (group==null) { return null; }
         Account account = new Account(n);
         Node statistics = node["statistics"];
         account.group = group;
         account.logins = (int)statistics["logins"].Value;
         account.total = TimeSpan.Parse((string)statistics["total"].Value);
         account.lastLogin = DateTime.Parse((string)statistics["lastLogin"].Value);
         account.lastLogout = DateTime.Parse((string)statistics["lastLogout"].Value);
         account.lastIP = (string)statistics["lastIP"].Value;
         account.fileModified = File.GetLastWriteTime(filename);
         account.custom = node["custom"]??account.custom;
         return account;
     } catch { return null; }
 }