QR2: Check message with TCP IP rather than UDP

This commit is contained in:
mkwcat 2024-02-18 07:40:33 -05:00
parent db5d6f4f2f
commit 825b67405b
No known key found for this signature in database
GPG Key ID: 7A505679CE9E7AA9
4 changed files with 15 additions and 15 deletions

View File

@ -129,11 +129,11 @@ func ProcessGPResvOK(matchVersion int, reservation common.MatchCommandDataReserv
}
// Validate dwc_pid values
if !from.setProfileID(moduleName, senderPidStr) {
if !from.setProfileID(moduleName, senderPidStr, "") {
return false
}
if !to.setProfileID(moduleName, destPidStr) {
if !to.setProfileID(moduleName, destPidStr, "") {
return false
}
@ -166,7 +166,7 @@ func ProcessGPStatusUpdate(profileID uint32, senderIP uint64, status string) {
return
}
if !session.setProfileID(moduleName, strconv.FormatUint(uint64(profileID), 10)) {
if !session.setProfileID(moduleName, strconv.FormatUint(uint64(profileID), 10), "") {
return
}
}
@ -251,7 +251,7 @@ func CheckGPReservationAllowed(senderIP uint64, senderPid uint32, destPid uint32
}
// Validate dwc_pid value
if !from.setProfileID(moduleName, senderPidStr) || from.Login == nil {
if !from.setProfileID(moduleName, senderPidStr, "") || from.Login == nil {
return ""
}

View File

@ -107,7 +107,7 @@ func heartbeat(moduleName string, conn net.PacketConn, addr net.Addr, buffer []b
} else if sessionPtr.Login == nil {
profileId := unknowns[0]
logging.Info(moduleName, "Attempting to use unknown as profile ID", aurora.Cyan(profileId))
sessionPtr.setProfileID(moduleName, profileId)
sessionPtr.setProfileID(moduleName, profileId, "")
}
session = *sessionPtr
mutex.Unlock()

View File

@ -7,6 +7,7 @@ import (
"net"
"os"
"strconv"
"strings"
"time"
"wwfc/common"
"wwfc/logging"
@ -33,7 +34,6 @@ func SendClientMessage(senderIP string, destSearchID uint64, message []byte) {
var matchData common.MatchCommandData
var sender *Session
var receiver *Session
senderIPInt, _ := common.IPFormatToInt(senderIP)
useSearchID := destSearchID < (1 << 24)
if useSearchID {
@ -93,18 +93,13 @@ func SendClientMessage(senderIP string, destSearchID uint64, message []byte) {
qr2IP := binary.BigEndian.Uint32(message[0x0C:0x10])
qr2Port := binary.LittleEndian.Uint16(message[0x0A:0x0C])
if senderIPInt != int32(qr2IP) {
logging.Error(moduleName, "Wrong QR2 IP in match command packet header")
return
}
sender = sessions[(uint64(qr2Port)<<32)|uint64(qr2IP)]
if sender == nil || !sender.Authenticated {
logging.Error(moduleName, "Session does not exist with QR2 IP and port")
return
}
if !sender.setProfileID(moduleName, strconv.FormatUint(uint64(senderProfileID), 10)) {
if !sender.setProfileID(moduleName, strconv.FormatUint(uint64(senderProfileID), 10), strings.Split(senderIP, ":")[0]) {
// Error already logged
return
}

View File

@ -4,6 +4,7 @@ import (
"math/rand"
"net"
"strconv"
"strings"
"time"
"wwfc/common"
"wwfc/logging"
@ -120,7 +121,7 @@ func setSessionData(moduleName string, addr net.Addr, sessionId uint32, payload
}
}
if newPIDValid && !session.setProfileID(moduleName, newPID) {
if newPIDValid && !session.setProfileID(moduleName, newPID, "") {
return Session{}, false
}
@ -158,7 +159,7 @@ func setSessionData(moduleName string, addr net.Addr, sessionId uint32, payload
// Set the session's profile ID if it doesn't already exists.
// Returns false if the profile ID is invalid.
// Expects the global mutex to already be locked.
func (session *Session) setProfileID(moduleName string, newPID string) bool {
func (session *Session) setProfileID(moduleName string, newPID string, gpcmIP string) bool {
if oldPID, oldPIDValid := session.Data["dwc_pid"]; oldPIDValid && oldPID != "" {
if newPID != oldPID {
logging.Error(moduleName, "New dwc_pid mismatch: new:", aurora.Cyan(newPID), "old:", aurora.Cyan(oldPID))
@ -180,13 +181,17 @@ func (session *Session) setProfileID(moduleName string, newPID string) bool {
var loginInfo *LoginInfo
var ok bool
if loginInfo, ok = logins[uint32(profileID)]; ok {
gpPublicIP = loginInfo.GPPublicIP
gpPublicIP = strings.Split(loginInfo.GPPublicIP, ":")[0]
} else {
logging.Error(moduleName, "Provided dwc_pid is not logged in:", aurora.Cyan(newPID))
return false
}
// TODO: Some kind of authentication
if gpcmIP != "" && gpcmIP != gpPublicIP {
logging.Error(moduleName, "TCP public IP mismatch: SB:", aurora.Cyan(gpcmIP), "GP:", aurora.Cyan(gpPublicIP))
return false
}
if ratingError := checkValidRating(moduleName, session.Data); ratingError != "ok" {
callback := loginInfo.GPErrorCallback