public override int GetHashCode() { int hash = 1; if (Name.Length != 0) { hash ^= Name.GetHashCode(); } if (Zone != 0) { hash ^= Zone.GetHashCode(); } if (RoleUUID.Length != 0) { hash ^= RoleUUID.GetHashCode(); } if (PlayerUUID.Length != 0) { hash ^= PlayerUUID.GetHashCode(); } if (MapUUID.Length != 0) { hash ^= MapUUID.GetHashCode(); } if (MailUUID.Length != 0) { hash ^= MailUUID.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public void SerializeTest() { var o = PlayerUUID.Random(); var s = JsonConvert.SerializeObject(o); var d = JsonConvert.DeserializeObject <string>(s); var d2 = JsonConvert.DeserializeObject <PlayerUUID>(s); Assert.AreEqual(o, new PlayerUUID(d)); Assert.AreEqual(o, d2); }
protected override void Prepare(EndianBinaryWriter w) { Debug.WriteLine("Prepare " + this); WriteVarInt(w, EID); w.Write(PlayerUUID.ToByteArray()); WriteAbsInt(w, Position); w.Write((sbyte)(Yaw * 128 / Math.PI)); w.Write((sbyte)(Pitch * 128 / Math.PI)); w.Write((short)CurrentItem); Metadata.Write(w, Meta); }
/// <summary> /// 验证凭据。 /// </summary> /// <param name="userField">该参数将被忽略。</param> /// <returns>身份验证结果。</returns> public AuthResult Auth(bool userField = false) { var authProperty = new AuthPropertyModel { Name = "preferredLanguage", ProfileId = string.Empty, UserId = PlayerUUID.Random(), Value = "zh-cn" }; var uuid = PlayerUUID.FromOfflinePlayerName(Username); var result = new AuthResult { AccessToken = GuidHelper.NewGuidString(), AuthStatus = AuthStatus.Succeeded, SelectedProfile = new ProfileInfoModel { Name = Username, UUID = uuid }, User = new UserInfoModel { UUID = uuid, Properties = new List <PropertyModel> { new PropertyModel { Name = authProperty.Name, Value = authProperty.Value } } } }; var authInfo = new AuthInfoModel { UserName = Username, Profiles = new Dictionary <PlayerUUID, AuthProfileModel> { { result.SelectedProfile.UUID, new AuthProfileModel { DisplayName = Username } } }, Properties = new List <AuthPropertyModel> { authProperty } }; LauncherProfileParser.AddNewAuthInfo(authInfo, uuid); return(result); }
public void AddNewAuthInfo(AuthInfoModel authInfo, PlayerUUID uuid) { if (IsAuthInfoExist(uuid, authInfo.UserName)) { return; } if (!(LauncherProfile.AuthenticationDatabase?.Any() ?? false)) { LauncherProfile.AuthenticationDatabase = new Dictionary <PlayerUUID, AuthInfoModel>(); } LauncherProfile.AuthenticationDatabase.Add( authInfo.Properties.Any() ? authInfo.Properties.First().UserId : authInfo.Profiles.First().Key, authInfo); SaveProfile(); }
public void SerializeAsDictionaryKeyTest() { var pairs = new Dictionary <PlayerUUID, string> { { PlayerUUID.Random(), "abc" }, { PlayerUUID.Random(), "def" }, }; var s = JsonConvert.SerializeObject(pairs); var d = JsonConvert.DeserializeObject <Dictionary <PlayerUUID, string> >(s); Assert.AreEqual(pairs.Count, d.Count); foreach (var p in pairs) { Assert.AreEqual(p.Value, d[p.Key]); } }
public bool IsAuthInfoExist(PlayerUUID uuid, string userName) { if (!(LauncherProfile.AuthenticationDatabase?.Any() ?? false)) { return(false); } var isMatched = LauncherProfile.AuthenticationDatabase .AsParallel() .Any(a => a.Value.Profiles? .AsParallel() .Any(aa => aa.Key .ToString() .Equals(uuid.ToString(), StringComparison.OrdinalIgnoreCase) && aa.Value.DisplayName.Equals(userName, StringComparison.Ordinal) ) ?? false); return(isMatched); }
public void SelectUser(PlayerUUID uuid) { LauncherProfile.SelectedUser.Account = uuid.ToString(); SaveProfile(); }
public void RemoveAuthInfo(PlayerUUID uuid) { LauncherProfile.AuthenticationDatabase.Remove(uuid); }
public AuthInfoModel GetAuthInfo(PlayerUUID uuid) { return(LauncherProfile.AuthenticationDatabase.TryGetValue(uuid, out var authInfo) ? authInfo : null); }