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 void GetIsNicknameInUseNull() { Assert.Throws <ArgumentNullException> (() => manager.GetIsNicknameInUse(null)); }