Unverified Commit 478fa5fa authored by Simon Esposito's avatar Simon Esposito Committed by GitHub
Browse files

Disconnect banned users (#1001)

Send notification when user is banned.
parent 013702bb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Token and credentials as inputs on unlink operations are now optional.
- Improve runtime IAP operation errors to include provider payload in error message.
- Build with Go 1.19.2 release.
- Disconnect users when they are banned from the console or runtime functions.

### Fixed
- Observe the error if returned in storage list errors in JavaScript runtime.
+1 −1
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ func (s *ConsoleServer) BanAccount(ctx context.Context, in *console.AccountId) (
		return nil, status.Error(codes.InvalidArgument, "Cannot ban the system user.")
	}

	if err := BanUsers(ctx, s.logger, s.db, s.sessionCache, []uuid.UUID{userID}); err != nil {
	if err := BanUsers(ctx, s.logger, s.db, s.config, s.sessionCache, s.sessionRegistry, s.tracker, []uuid.UUID{userID}); err != nil {
		// Error logged in the core function above.
		return nil, status.Error(codes.Internal, "An error occurred while trying to ban the user.")
	}
+1 −1
Original line number Diff line number Diff line
@@ -524,7 +524,7 @@ func DeleteAccount(ctx context.Context, logger *zap.Logger, db *sql.DB, config C
			return err
		}
		for _, presence := range tracker.ListPresenceIDByStream(PresenceStream{Mode: StreamModeNotifications, Subject: userID}) {
			if err = sessionRegistry.Disconnect(ctx, presence.SessionID); err != nil {
			if err = sessionRegistry.Disconnect(ctx, presence.SessionID, false); err != nil {
				return err
			}
		}
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ const (
	NotificationCodeGroupJoinRequest int32 = -5
	NotificationCodeFriendJoinGame   int32 = -6
	NotificationCodeSingleSocket     int32 = -7
	NotificationCodeUserBanned       int32 = -8
)

type notificationCacheableCursor struct {
+10 −1
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ func DeleteUser(ctx context.Context, tx *sql.Tx, userID uuid.UUID) (int64, error
	return res.RowsAffected()
}

func BanUsers(ctx context.Context, logger *zap.Logger, db *sql.DB, sessionCache SessionCache, ids []uuid.UUID) error {
func BanUsers(ctx context.Context, logger *zap.Logger, db *sql.DB, config Config, sessionCache SessionCache, sessionRegistry SessionRegistry, tracker Tracker, ids []uuid.UUID) error {
	statements := make([]string, 0, len(ids))
	params := make([]interface{}, 0, len(ids))
	for i, id := range ids {
@@ -196,6 +196,15 @@ func BanUsers(ctx context.Context, logger *zap.Logger, db *sql.DB, sessionCache

	sessionCache.Ban(ids)

	for _, id := range ids {
		// Disconnect.
		for _, presence := range tracker.ListPresenceIDByStream(PresenceStream{Mode: StreamModeNotifications, Subject: id}) {
			if err = sessionRegistry.Disconnect(ctx, presence.SessionID, true); err != nil {
				return err
			}
		}
	}

	return nil
}

Loading