public void JoinResult() { LoginResultState state = LoginResultState.Success; var msg = new JoinResultMessage(state, new UserInfo(Nickname, Nickname, UserId, ChannelId, true)); Assert.AreEqual(state, msg.Result); Assert.AreEqual(UserId, msg.UserInfo.UserId); Assert.AreEqual(Nickname, msg.UserInfo.Nickname); Assert.AreEqual(ChannelId, msg.UserInfo.CurrentChannelId); Assert.AreEqual(Muted, msg.UserInfo.IsMuted); msg.WritePayload(serverContext, writer); long length = stream.Position; stream.Position = 0; msg = new JoinResultMessage(); msg.ReadPayload(clientContext, reader); Assert.AreEqual(length, stream.Position); Assert.AreEqual(state, msg.Result); Assert.AreEqual(UserId, msg.UserInfo.UserId); Assert.AreEqual(Nickname, msg.UserInfo.Nickname); Assert.AreEqual(ChannelId, msg.UserInfo.CurrentChannelId); Assert.AreEqual(Muted, msg.UserInfo.IsMuted); }
internal void OnJoinMessage(MessageEventArgs <JoinMessage> e) { var join = e.Message; if (!e.Connection.IsConnected) { return; } if (join.Nickname.IsNullOrWhitespace()) { e.Connection.SendAsync(new JoinResultMessage(LoginResultState.FailedInvalidNickname, null)); return; } if (!String.IsNullOrEmpty(this.context.Settings.ServerPassword) && join.ServerPassword != this.context.Settings.ServerPassword) { e.Connection.SendAsync(new JoinResultMessage(LoginResultState.FailedServerPassword, null)); return; } IUserInfo info = GetJoiningUserInfo(e.Connection, join); if (info == null) { return; } LoginResultState result = LoginResultState.Success; if (Manager.GetIsNicknameInUse(join.Nickname)) { if (!AttemptNicknameRecovery(info, join.Nickname)) { result = LoginResultState.FailedNicknameInUse; } } var msg = new JoinResultMessage(result, info); if (result == LoginResultState.Success) { Manager.Join(e.Connection, info); e.Connection.SendAsync(msg); if (!Manager.GetIsLoggedIn(e.Connection)) { e.Connection.SendAsync(new PermissionsMessage(info.UserId, this.context.PermissionsProvider.GetPermissions(info.UserId))); } foreach (IConnection connection in this.context.Connections) { connection.SendAsync(new UserJoinedMessage(info)); } } else { e.Connection.SendAsync(msg); } }
public JoinResultMessage(LoginResultState state, IUserInfo user) : this() { this.Result = state; if (user != null) UserInfo = user; }
public JoinResultMessage(LoginResultState state, IUserInfo user) : this() { this.Result = state; if (user != null) { UserInfo = user; } }
public void LoginResult(LoginResultState state, string errorMsg) { if (state == LoginResultState.LoginSucceed) { m_IsLoggedIn = true; } else { m_IsLoggedIn = false; } Debug.Log("LoginResult: state: " + state.ToString() + " errorMsg: " + errorMsg); }
// Handle Moolah public void handleLoginResult(LoginResultState state, string errorMsg) { if (state == LoginResultState.LoginSucceed) { _isLogined = true; } else { _isLogined = false; } Debug.Log("LoginResult: state: " + state.ToString() + " errorMsg: " + errorMsg); }
public void LoginResult() { LoginResultState state = LoginResultState.Success; var msg = new LoginResultMessage(new LoginResult(UserId, state)); Assert.IsTrue(msg.Result.Succeeded); Assert.AreEqual(state, msg.Result.ResultState); Assert.AreEqual(UserId, msg.Result.UserId); var provider = new MockConnectionProvider(GablarskiProtocol.Instance); provider.Start(MessageTypes.All); var cs = provider.GetConnections(GablarskiProtocol.Instance); this.clientContext = new SerializationContext(cs.Item1, new Dictionary <byte, Protocol> { { 42, GablarskiProtocol.Instance } }); this.serverContext = new SerializationContext(cs.Item2, new Dictionary <byte, Protocol> { { 42, GablarskiProtocol.Instance } }); }
public LoginResult Login(string username, string password) { if (username == null) { throw new ArgumentNullException("username"); } username = username.Trim().ToLower(); if (this.bans.Any(b => !b.IsExpired && b.Username != null && b.Username.Trim().ToLower() == username)) { return(new LoginResult(0, LoginResultState.FailedBanned)); } LoginResultState state = LoginResultState.Success; MockUser user = users.FirstOrDefault(u => u.Username.Trim().ToLower() == username); if (user != null) { if (password == null) { state = LoginResultState.FailedPassword; } else if (password.Trim().ToLower() != user.Password.Trim().ToLower()) { state = LoginResultState.FailedPassword; } } else { if (password != null) { state = LoginResultState.FailedUsernameAndPassword; } } return(new LoginResult((user != null) ? user.UserId : Interlocked.Decrement(ref nextGuestId), state)); }
public LoginResult(int userId, LoginResultState state) { this.UserId = userId; this.ResultState = state; }
public ReceivedJoinResultEventArgs(LoginResultState result) { this.Result = result; }
/// <summary> /// 构造登陆结果 /// </summary> /// <param name="state">登陆结果状态</param> /// <param name="userLoginLog">该次登陆的日志</param> public LoginResult(LoginResultState state, UserLoginLog userLoginLog) { this._State = state; this._UserLoginLog = userLoginLog; }
public void Deserialize(ISerializationContext context, IValueReader reader) { this.UserId = reader.ReadInt32(); this.ResultState = (LoginResultState)reader.ReadByte(); }