GPCM: Do updatepro/getprofile in the right order

This commit is contained in:
TheLordScruffy 2023-09-14 17:31:20 -04:00
parent eb45c1b5cc
commit a3108d819d
4 changed files with 28 additions and 13 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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)

View File

@ -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
}
}
}