Exemplo n.º 1
0
        public static User GetUser(string name, string uuid)
        {
            if (File.Exists(Path.Combine(UsersPath, uuid + ".json")))
            {
                return Read(Path.Combine(UsersPath, uuid + ".json"), new string[] { name, uuid });
            }
            else
            {
                User user = new User(name, uuid, StarryboundServer.defaultGroup, false, true, 0);
                Write(Path.Combine(UsersPath, uuid + ".json"), user);

                return user;
            }
        }
Exemplo n.º 2
0
 public static void SaveUser(Player player)
 {
     try
     {
         User user = new User(player.name, player.uuid, player.group.name, player.isMuted, player.canBuild, Utils.getTimestamp());
         Write(Path.Combine(UsersPath, player.uuid + ".json"), user);
     }
     catch (Exception e)
     {
         StarryboundServer.logException("Unable to save player data file for " + player.name + ": " + e.StackTrace);
     }
 }
Exemplo n.º 3
0
 static void Write(Stream stream, User user)
 {
     var str = JsonConvert.SerializeObject(user, Formatting.Indented);
     using (var sw = new StreamWriter(stream))
     {
         sw.Write(str);
     }
 }
Exemplo n.º 4
0
 static void Write(string path, User user)
 {
     using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Write))
     {
         Write(fs, user);
     }
 }
Exemplo n.º 5
0
 public static void SaveUser(PlayerData player)
 {
     try
     {
         User user = new User(player.name, player.uuid, player.ip, player.group.name, player.isMuted, player.canBuild, Utils.getTimestamp(), player.freeFuel, player.receivedStarterKit, player.privateShip, player.shipWhitelist, player.shipBlacklist);
         Write(Path.Combine(UsersPath, player.name.ToLower() + ".json"), user);
     }
     catch (Exception e)
     {
         StarryboundServer.logException("Unable to save player data file for " + player.name + ": " + e.StackTrace);
     }
 }
Exemplo n.º 6
0
        public static User GetUser(string name, string uuid, string ip)
        {
            if (File.Exists(Path.Combine(UsersPath, name.ToLower() + ".json")))
            {
                try
                {
                    User user = Read(Path.Combine(UsersPath, name.ToLower() + ".json"), new string[] { name, uuid });
                    return user;
                }
                catch (Exception)
                {
                    StarryboundServer.logError("Player data for user " + name.ToLower() + " with UUID " + uuid + " is corrupt. Re-generating user file");

                    User user = new User(name, uuid, ip, StarryboundServer.defaultGroup, false, true, 0, true, true, false, new List<string>(), new List<string>());
                    Write(Path.Combine(UsersPath, name.ToLower() + ".json"), user);

                    return user;
                }
            }
            else
            {
                User user = new User(name, uuid, ip, StarryboundServer.defaultGroup, false, true, 0, false, false, false, new List<string>(), new List<string>());
                Write(Path.Combine(UsersPath, name.ToLower() + ".json"), user);

                return user;
            }
        }