mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-08-26 18:44:57 -05:00
Database: Only update last IP addr on real login
Some checks failed
Build CI / build (push) Has been cancelled
Some checks failed
Build CI / build (push) Has been cancelled
This commit is contained in:
@@ -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 := ""
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user