diff --git a/database/login.go b/database/login.go index 39123c8..e2a1691 100644 --- a/database/login.go +++ b/database/login.go @@ -2,8 +2,9 @@ package database import ( "context" - "github.com/jackc/pgx/v4/pgxpool" "wwfc/common" + + "github.com/jackc/pgx/v4/pgxpool" ) const ( @@ -88,8 +89,10 @@ func LoginUserToGCPM(pool *pgxpool.Pool, ctx context.Context, authToken string) // Create the GPCM account user.CreateUser(pool, ctx) } else { - // TODO get the profile ID!!!!! - user.ProfileId = 474888031 + err := pool.QueryRow(ctx, GetUserProfileID, userId).Scan(&user.ProfileId) + if err != nil { + panic(err) + } } return user diff --git a/database/user.go b/database/user.go index 1c22ea2..ec20cc7 100644 --- a/database/user.go +++ b/database/user.go @@ -3,9 +3,10 @@ package database import ( "context" "errors" + "wwfc/common" + "github.com/jackc/pgx/v4" "github.com/jackc/pgx/v4/pgxpool" - "wwfc/common" ) const ( @@ -15,6 +16,7 @@ const ( CreateUserSession = `INSERT INTO sessions (session_key, profile_id, login_ticket) VALUES ($1, $2, $3)` DoesUserExist = `SELECT EXISTS(SELECT 1 FROM users WHERE user_id = $1 AND gsbrcd = $2)` DeleteUserSession = `DELETE FROM sessions WHERE profile_id = $1` + GetUserProfileID = `SELECT profile_id FROM users WHERE user_id = $1` ) type User struct { diff --git a/gpcm/login.go b/gpcm/login.go index f2669cb..cd204e1 100644 --- a/gpcm/login.go +++ b/gpcm/login.go @@ -5,12 +5,13 @@ import ( "crypto/md5" "encoding/base64" "encoding/hex" - "github.com/jackc/pgx/v4/pgxpool" "log" "strconv" "strings" "wwfc/common" "wwfc/database" + + "github.com/jackc/pgx/v4/pgxpool" ) func generateResponse(gpcmChallenge, nasChallenge, authToken, clientChallenge string) string { @@ -45,8 +46,7 @@ func login(pool *pgxpool.Pool, ctx context.Context, command common.GameSpyComman // Perform the login with the database. user := database.LoginUserToGCPM(pool, ctx, authToken) loginTicket := strings.Replace(base64.StdEncoding.EncodeToString([]byte(common.RandomString(16))), "=", "_", -1) - // TODO: REMOVE!!!!! - userId = user.UserId + // Now initiate the session _ = database.CreateSession(pool, ctx, user.ProfileId, loginTicket) diff --git a/gpcm/main.go b/gpcm/main.go index 8fe0ace..d94a457 100644 --- a/gpcm/main.go +++ b/gpcm/main.go @@ -5,14 +5,15 @@ import ( "context" "errors" "fmt" - "github.com/jackc/pgx/v4/pgxpool" - "github.com/logrusorgru/aurora/v3" "io" "log" "net" "os" "time" "wwfc/common" + + "github.com/jackc/pgx/v4/pgxpool" + "github.com/logrusorgru/aurora/v3" ) var ( @@ -97,6 +98,19 @@ func handleRequest(conn net.Conn) { for _, command := range commands { log.Printf("%s: Message received. Command: %s", aurora.Green("[NOTICE]"), aurora.Yellow(command.Command)) + } + + // Make sure update profile runs before get profile + for _, command := range commands { + switch command.Command { + case "updatepro": + // Nothing is written here. + updateProfile(pool, ctx, command) + break + } + } + + for _, command := range commands { switch command.Command { case "ka": conn.Write([]byte(`\ka\\final\`)) @@ -110,10 +124,6 @@ func handleRequest(conn net.Conn) { fmt.Println(payload) conn.Write([]byte(payload)) break - case "updatepro": - // Nothing is written here. - updateProfile(pool, ctx, command) - break } } }