From 788bf7ff0bc91c6fb7c850b7f3873506d953c0be Mon Sep 17 00:00:00 2001 From: Palapeli <26661008+mkwcat@users.noreply.github.com> Date: Sat, 1 Mar 2025 08:50:22 -0500 Subject: [PATCH] Database: Only update last IP addr on real login --- database/login.go | 12 +++++++----- gpcm/login.go | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/database/login.go b/database/login.go index 2fb6475..f0c2418 100644 --- a/database/login.go +++ b/database/login.go @@ -42,7 +42,7 @@ var ( ErrProfileBannedTOS = errors.New("profile is banned for violating the Terms of Service") ) -func LoginUserToGPCM(pool *pgxpool.Pool, ctx context.Context, userId uint64, gsbrcd string, profileId uint32, ngDeviceId uint32, ipAddress string, ingamesn string) (User, error) { +func LoginUserToGPCM(pool *pgxpool.Pool, ctx context.Context, userId uint64, gsbrcd string, profileId uint32, ngDeviceId uint32, ipAddress string, ingamesn string, deviceAuth bool) (User, error) { var exists bool err := pool.QueryRow(ctx, DoesUserExist, userId, gsbrcd).Scan(&exists) if err != nil { @@ -123,7 +123,7 @@ func LoginUserToGPCM(pool *pgxpool.Pool, ctx context.Context, userId uint64, gsb user.NgDeviceId = append(user.NgDeviceId, ngDeviceId) _, err = pool.Exec(ctx, UpdateUserNGDeviceID, user.ProfileId, user.NgDeviceId) - } else if !validDeviceId && ngDeviceId == 0 { + } else if deviceAuth && !validDeviceId && ngDeviceId == 0 { if len(user.NgDeviceId) > 0 && !common.GetConfig().AllowConnectWithoutDeviceID { logging.Error("DATABASE", "NG device ID not provided for profile", aurora.Cyan(user.ProfileId), "- expected one of {", deviceIdList[:len(deviceIdList)-2], "} but got", aurora.Cyan("00000000")) return User{}, ErrDeviceIDMismatch @@ -154,9 +154,11 @@ func LoginUserToGPCM(pool *pgxpool.Pool, ctx context.Context, userId uint64, gsb } // Update the user's last IP address and ingamesn - _, err = pool.Exec(ctx, UpdateUserLastIPAddress, user.ProfileId, ipAddress, ingamesn) - if err != nil { - return User{}, err + if deviceAuth { + _, err = pool.Exec(ctx, UpdateUserLastIPAddress, user.ProfileId, ipAddress, ingamesn) + if err != nil { + return User{}, err + } } emptyString := "" diff --git a/gpcm/login.go b/gpcm/login.go index d6c8d2e..7b931b6 100644 --- a/gpcm/login.go +++ b/gpcm/login.go @@ -261,7 +261,7 @@ func (g *GameSpySession) login(command common.GameSpyCommand) { cmdProfileId = uint32(cmdProfileId2) } - if !g.performLoginWithDatabase(userId, gsbrcd, cmdProfileId, deviceId) { + if !g.performLoginWithDatabase(userId, gsbrcd, cmdProfileId, deviceId, deviceAuth) { return } @@ -353,7 +353,7 @@ func (g *GameSpySession) exLogin(command common.GameSpyCommand) { return } - if !g.performLoginWithDatabase(g.User.UserId, g.User.GsbrCode, 0, deviceId) { + if !g.performLoginWithDatabase(g.User.UserId, g.User.GsbrCode, 0, deviceId, true) { return } @@ -428,14 +428,14 @@ func (g *GameSpySession) verifyExLoginInfo(command common.GameSpyCommand, authTo return deviceId } -func (g *GameSpySession) performLoginWithDatabase(userId uint64, gsbrCode string, profileId uint32, deviceId uint32) bool { +func (g *GameSpySession) performLoginWithDatabase(userId uint64, gsbrCode string, profileId uint32, deviceId uint32, deviceAuth bool) bool { // Get IP address without port ipAddress := g.RemoteAddr if strings.Contains(ipAddress, ":") { ipAddress = ipAddress[:strings.Index(ipAddress, ":")] } - user, err := database.LoginUserToGPCM(pool, ctx, userId, gsbrCode, profileId, deviceId, ipAddress, g.InGameName) + user, err := database.LoginUserToGPCM(pool, ctx, userId, gsbrCode, profileId, deviceId, ipAddress, g.InGameName, deviceAuth) g.User = user if err != nil {