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; } }
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); } }
static void Write(Stream stream, User user) { var str = JsonConvert.SerializeObject(user, Formatting.Indented); using (var sw = new StreamWriter(stream)) { sw.Write(str); } }
static void Write(string path, User user) { using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Write)) { Write(fs, user); } }
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); } }
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; } }