mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-10-01 03:26:35 -05:00
GPCM: Check reported payload version
This commit is contained in:
@@ -7,16 +7,16 @@ import (
|
||||
)
|
||||
|
||||
type GPError struct {
|
||||
errorCode int
|
||||
errorString string
|
||||
fatal bool
|
||||
ErrorCode int
|
||||
ErrorString string
|
||||
Fatal bool
|
||||
}
|
||||
|
||||
func MakeGPError(errorCode int, errorString string, fatal bool) GPError {
|
||||
return GPError{
|
||||
errorCode: errorCode,
|
||||
errorString: errorString,
|
||||
fatal: fatal,
|
||||
ErrorCode: errorCode,
|
||||
ErrorString: errorString,
|
||||
Fatal: fatal,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,12 +144,12 @@ func (err GPError) GetMessage() string {
|
||||
Command: "error",
|
||||
CommandValue: "",
|
||||
OtherValues: map[string]string{
|
||||
"err": strconv.Itoa(err.errorCode),
|
||||
"errmsg": err.errorString,
|
||||
"err": strconv.Itoa(err.ErrorCode),
|
||||
"errmsg": err.ErrorString,
|
||||
},
|
||||
}
|
||||
|
||||
if err.fatal {
|
||||
if err.Fatal {
|
||||
command.OtherValues["fatal"] = ""
|
||||
}
|
||||
|
||||
@@ -157,6 +157,6 @@ func (err GPError) GetMessage() string {
|
||||
}
|
||||
|
||||
func (g *GameSpySession) replyError(err GPError) {
|
||||
logging.Error(g.ModuleName, "Reply error:", err.errorString)
|
||||
logging.Error(g.ModuleName, "Reply error:", err.ErrorString)
|
||||
g.Conn.Write([]byte(err.GetMessage()))
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"crypto/md5"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"wwfc/common"
|
||||
"wwfc/database"
|
||||
"wwfc/logging"
|
||||
)
|
||||
|
||||
func generateResponse(gpcmChallenge, nasChallenge, authToken, clientChallenge string) string {
|
||||
@@ -32,21 +32,30 @@ func generateProof(gpcmChallenge, nasChallenge, authToken, clientChallenge strin
|
||||
|
||||
func (g *GameSpySession) login(command common.GameSpyCommand) {
|
||||
if g.LoggedIn {
|
||||
log.Fatalf("Attempt to login twice")
|
||||
logging.Error(g.ModuleName, "Attempt to login twice")
|
||||
g.replyError(ErrLogin)
|
||||
return
|
||||
}
|
||||
|
||||
if command.OtherValues["payload_ver"] != "1" {
|
||||
g.replyError(GPError{
|
||||
ErrorCode: ErrLogin.ErrorCode,
|
||||
ErrorString: "The payload version is invalid.",
|
||||
Fatal: true,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
authToken := command.OtherValues["authtoken"]
|
||||
challenge := database.GetChallenge(pool, ctx, authToken)
|
||||
if challenge == "" {
|
||||
// There was an error validating the pre-authentication.
|
||||
g.replyError(ErrLoginBadPreAuth)
|
||||
g.replyError(ErrLogin)
|
||||
return
|
||||
}
|
||||
|
||||
response := generateResponse(g.Challenge, challenge, authToken, command.OtherValues["challenge"])
|
||||
if response != command.OtherValues["response"] {
|
||||
// There was an error validating the pre-authentication.
|
||||
g.replyError(ErrLoginBadPreAuth)
|
||||
g.replyError(ErrLogin)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user