mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-08-28 11:34:16 -05:00
Reverse QR2 dependency on GPCM
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"wwfc/common"
|
||||
"wwfc/database"
|
||||
"wwfc/logging"
|
||||
"wwfc/qr2"
|
||||
)
|
||||
|
||||
func generateResponse(gpcmChallenge, nasChallenge, authToken, clientChallenge string) string {
|
||||
@@ -183,6 +184,10 @@ func (g *GameSpySession) login(command common.GameSpyCommand) {
|
||||
g.ModuleName = "GPCM:" + strconv.FormatInt(int64(g.User.ProfileId), 10)
|
||||
g.ModuleName += "/" + common.CalcFriendCodeString(g.User.ProfileId, "RMCJ")
|
||||
|
||||
// Notify QR2 of the login
|
||||
// TODO: Get ingamesn and cfc from NAS
|
||||
qr2.Login(g.User.ProfileId, "", "", g.Conn.RemoteAddr().String())
|
||||
|
||||
payload := common.CreateGameSpyMessage(common.GameSpyCommand{
|
||||
Command: "lc",
|
||||
CommandValue: "2",
|
||||
@@ -207,15 +212,3 @@ func IsLoggedIn(profileID uint32) bool {
|
||||
session, exists := sessions[profileID]
|
||||
return exists && session.LoggedIn
|
||||
}
|
||||
|
||||
func GetSessionIP(profileID uint32) string {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
|
||||
session, exists := sessions[profileID]
|
||||
if exists && session.LoggedIn {
|
||||
return session.Conn.RemoteAddr().String()
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"wwfc/common"
|
||||
"wwfc/database"
|
||||
"wwfc/logging"
|
||||
"wwfc/qr2"
|
||||
)
|
||||
|
||||
type GameSpySession struct {
|
||||
@@ -77,6 +78,7 @@ func StartServer() {
|
||||
|
||||
func (g *GameSpySession) closeSession() {
|
||||
if g.LoggedIn {
|
||||
qr2.Logout(g.User.ProfileId)
|
||||
g.sendLogoutStatus()
|
||||
}
|
||||
|
||||
|
||||
27
qr2/logins.go
Normal file
27
qr2/logins.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package qr2
|
||||
|
||||
type LoginInfo struct {
|
||||
ProfileID uint32
|
||||
InGameName string
|
||||
ConsoleFriendCode string
|
||||
GPPublicIP string
|
||||
}
|
||||
|
||||
var logins = map[uint32]LoginInfo{}
|
||||
|
||||
func Login(profileID uint32, inGameName, consoleFriendCode, publicIP string) {
|
||||
mutex.Lock()
|
||||
logins[profileID] = LoginInfo{
|
||||
ProfileID: profileID,
|
||||
InGameName: inGameName,
|
||||
ConsoleFriendCode: consoleFriendCode,
|
||||
GPPublicIP: publicIP,
|
||||
}
|
||||
mutex.Unlock()
|
||||
}
|
||||
|
||||
func Logout(profileID uint32) {
|
||||
mutex.Lock()
|
||||
delete(logins, profileID)
|
||||
mutex.Unlock()
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
"wwfc/common"
|
||||
"wwfc/gpcm"
|
||||
"wwfc/logging"
|
||||
)
|
||||
|
||||
@@ -116,10 +115,12 @@ func setSessionData(sessionId uint32, payload map[string]string, addr net.Addr)
|
||||
return *session, true
|
||||
}
|
||||
|
||||
if pid, ok := session.Data["dwc_pid"]; ok && pid != "" {
|
||||
payload["dwc_pid"] = pid
|
||||
// Save certain fields
|
||||
for k, v := range session.Data {
|
||||
if k[0] == '+' || k == "dwc_pid" {
|
||||
payload[k] = v
|
||||
}
|
||||
}
|
||||
payload["+searchid"] = session.Data["+searchid"]
|
||||
|
||||
session.Data = payload
|
||||
session.LastKeepAlive = time.Now().Unix()
|
||||
@@ -146,16 +147,16 @@ func (session *Session) setProfileID(moduleName string, newPID string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Lookup the profile ID in GPCM and verify it's logged in.
|
||||
// Maybe we don't need this? It relies on GPCM being hosted in the same application, and
|
||||
// makes GPCM a dependency of QR2. Perhaps we could use the database.
|
||||
gpcmIP := gpcm.GetSessionIP(uint32(profileID))
|
||||
if gpcmIP == "" {
|
||||
// Check if the public IP matches the one used for the GPCM session
|
||||
var gpPublicIP string
|
||||
if loginInfo, ok := logins[uint32(profileID)]; ok {
|
||||
gpPublicIP = loginInfo.GPPublicIP
|
||||
} else {
|
||||
logging.Error(moduleName, "Provided dwc_pid is not logged in:", aurora.Cyan(newPID))
|
||||
return false
|
||||
}
|
||||
|
||||
if strings.Split(gpcmIP, ":")[0] != strings.Split(session.Addr.String(), ":")[0] {
|
||||
if strings.Split(gpPublicIP, ":")[0] != strings.Split(session.Addr.String(), ":")[0] {
|
||||
logging.Error(moduleName, "Caller public IP does not match GPCM session")
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user