Unverified Commit 23b7ea7a authored by Simon Esposito's avatar Simon Esposito Committed by GitHub
Browse files

Always log out a deleted user (#987)

parent 285305e5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Use stricter validation of method param in Lua server framework HTTP request function.
- Disable SQL statement cache mode describe by default. This reverts to the same behaviour as before 3.14.0 release.
- Build with Go 1.19.4 release.
- Always log out and disconnect a user when it's deleted.

### Fixed
- Fix response structure in purchase lookups by identifier.
+1 −1
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ func main() {
	statusHandler := server.NewLocalStatusHandler(logger, sessionRegistry, matchRegistry, tracker, metrics, config.GetName())

	apiServer := server.StartApiServer(logger, startupLogger, db, jsonpbMarshaler, jsonpbUnmarshaler, config, version, socialClient, leaderboardCache, leaderboardRankCache, sessionRegistry, sessionCache, statusRegistry, matchRegistry, matchmaker, tracker, router, streamManager, metrics, pipeline, runtime)
	consoleServer := server.StartConsoleServer(logger, startupLogger, db, config, tracker, router, streamManager, metrics, sessionCache, consoleSessionCache, loginAttemptCache, statusRegistry, statusHandler, runtimeInfo, matchRegistry, configWarnings, semver, leaderboardCache, leaderboardRankCache, leaderboardScheduler, apiServer, runtime, cookie)
	consoleServer := server.StartConsoleServer(logger, startupLogger, db, config, tracker, router, streamManager, metrics, sessionRegistry, sessionCache, consoleSessionCache, loginAttemptCache, statusRegistry, statusHandler, runtimeInfo, matchRegistry, configWarnings, semver, leaderboardCache, leaderboardRankCache, leaderboardScheduler, apiServer, runtime, cookie)

	gaenabled := len(os.Getenv("NAKAMA_TELEMETRY")) < 1
	console.UIFS.Nt = !gaenabled
+1 −12
Original line number Diff line number Diff line
@@ -93,23 +93,12 @@ func (s *ApiServer) DeleteAccount(ctx context.Context, in *emptypb.Empty) (*empt
		}
	}

	if err := DeleteAccount(ctx, s.logger, s.db, s.leaderboardRankCache, userID, false); err != nil {
	if err := DeleteAccount(ctx, s.logger, s.db, s.config, s.leaderboardRankCache, s.sessionRegistry, s.sessionCache, s.tracker, userID, false); err != nil {
		if err == ErrAccountNotFound {
			return nil, status.Error(codes.NotFound, "Account not found.")
		}
		return nil, status.Error(codes.Internal, "Error deleting user account.")
	}
	// Logout and disconnect.
	err := SessionLogout(s.config, s.sessionCache, userID, "", "")
	if err != nil {
		return nil, err
	}
	for _, presence := range s.tracker.ListPresenceIDByStream(PresenceStream{Mode: StreamModeNotifications, Subject: userID}) {
		err = s.sessionRegistry.Disconnect(ctx, presence.SessionID)
		if err != nil {
			return nil, err
		}
	}

	// After hook.
	if fn := s.runtime.AfterDeleteAccount(); fn != nil {
+3 −1
Original line number Diff line number Diff line
@@ -143,6 +143,7 @@ type ConsoleServer struct {
	streamManager        StreamManager
	metrics              Metrics
	sessionCache         SessionCache
	sessionRegistry      SessionRegistry
	consoleSessionCache  SessionCache
	loginAttemptCache    LoginAttemptCache
	statusRegistry       *StatusRegistry
@@ -163,7 +164,7 @@ type ConsoleServer struct {
	httpClient           *http.Client
}

func StartConsoleServer(logger *zap.Logger, startupLogger *zap.Logger, db *sql.DB, config Config, tracker Tracker, router MessageRouter, streamManager StreamManager, metrics Metrics, sessionCache SessionCache, consoleSessionCache SessionCache, loginAttemptCache LoginAttemptCache, statusRegistry *StatusRegistry, statusHandler StatusHandler, runtimeInfo *RuntimeInfo, matchRegistry MatchRegistry, configWarnings map[string]string, serverVersion string, leaderboardCache LeaderboardCache, leaderboardRankCache LeaderboardRankCache, leaderboardScheduler LeaderboardScheduler, api *ApiServer, runtime *Runtime, cookie string) *ConsoleServer {
func StartConsoleServer(logger *zap.Logger, startupLogger *zap.Logger, db *sql.DB, config Config, tracker Tracker, router MessageRouter, streamManager StreamManager, metrics Metrics, sessionRegistry SessionRegistry, sessionCache SessionCache, consoleSessionCache SessionCache, loginAttemptCache LoginAttemptCache, statusRegistry *StatusRegistry, statusHandler StatusHandler, runtimeInfo *RuntimeInfo, matchRegistry MatchRegistry, configWarnings map[string]string, serverVersion string, leaderboardCache LeaderboardCache, leaderboardRankCache LeaderboardRankCache, leaderboardScheduler LeaderboardScheduler, api *ApiServer, runtime *Runtime, cookie string) *ConsoleServer {
	var gatewayContextTimeoutMs string
	if config.GetConsole().IdleTimeoutMs > 500 {
		// Ensure the GRPC Gateway timeout is just under the idle timeout (if possible) to ensure it has priority.
@@ -189,6 +190,7 @@ func StartConsoleServer(logger *zap.Logger, startupLogger *zap.Logger, db *sql.D
		router:               router,
		streamManager:        streamManager,
		metrics:              metrics,
		sessionRegistry:      sessionRegistry,
		sessionCache:         sessionCache,
		consoleSessionCache:  consoleSessionCache,
		loginAttemptCache:    loginAttemptCache,
+1 −1
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ func (s *ConsoleServer) DeleteAccount(ctx context.Context, in *console.AccountDe
		return nil, status.Error(codes.InvalidArgument, "Cannot delete the system user.")
	}

	if err = DeleteAccount(ctx, s.logger, s.db, s.leaderboardRankCache, userID, in.RecordDeletion != nil && in.RecordDeletion.Value); err != nil {
	if err = DeleteAccount(ctx, s.logger, s.db, s.config, s.leaderboardRankCache, s.sessionRegistry, s.sessionCache, s.tracker, userID, in.RecordDeletion != nil && in.RecordDeletion.Value); err != nil {
		// Error already logged in function above.
		return nil, status.Error(codes.Internal, "An error occurred while trying to delete the user.")
	}
Loading