Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
UserManager.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
4 public static class UserManager {
5 public static List<UserInfo> m_users;
6
7 public static UserInfo ActiveUser {
8 get => GetUser(SettingsManager.UserId) ?? GetUsers().FirstOrDefault();
9 set => SettingsManager.UserId = value != null ? value.UniqueId : string.Empty;
10 }
11
12 static UserManager() {
13 m_users = [];
14 string text;
15 try {
16 string path = ModsManager.UserDataPath;
17 if (!Storage.FileExists(path)) {
18 text = Guid.NewGuid().ToString();
19 Storage.WriteAllText(path, text);
20 }
21 else {
22 text = Storage.ReadAllText(path);
23 }
24 }
25 catch (Exception) {
26 text = Guid.NewGuid().ToString();
27 }
28 m_users.Add(new UserInfo(text, "Windows User"));
29 }
30
31 public static IEnumerable<UserInfo> GetUsers() => new ReadOnlyList<UserInfo>(m_users);
32
33 public static UserInfo GetUser(string uniqueId) {
34 return GetUsers().FirstOrDefault(u => u.UniqueId == uniqueId);
35 }
36 }
37}
static bool FileExists(string path)
static string ReadAllText(string path)
static void WriteAllText(string path, string text)
static IEnumerable< UserInfo > GetUsers()
static UserInfo GetUser(string uniqueId)
static List< UserInfo > m_users
static UserInfo ActiveUser
static string UserDataPath