diff --git a/common/config.go b/common/config.go
index c91ae3a..8e9c176 100644
--- a/common/config.go
+++ b/common/config.go
@@ -14,6 +14,7 @@ type Config struct {
Port string `xml:"nasPort"`
PortHTTPS string `xml:"nasPortHttps"`
EnableHTTPS bool `xml:"enableHttps"`
+ LogLevel int `xml:"logLevel"`
}
func GetConfig() Config {
diff --git a/config_example.xml b/config_example.xml
index 0d4d7fe..5a27d13 100644
--- a/config_example.xml
+++ b/config_example.xml
@@ -12,4 +12,7 @@
127.0.0.1
wwfc
+
+
+ 4
diff --git a/gpcm/friend.go b/gpcm/friend.go
index a7fee79..f6ac139 100644
--- a/gpcm/friend.go
+++ b/gpcm/friend.go
@@ -90,7 +90,7 @@ func (g *GameSpySession) addFriend(command common.GameSpyCommand) {
}
fc := common.CalcFriendCodeString(uint32(newProfileId), "RMCJ")
- logging.Notice(g.ModuleName, "Add friend:", aurora.Cyan(strNewProfileId), aurora.Cyan(fc))
+ logging.Info(g.ModuleName, "Add friend:", aurora.Cyan(strNewProfileId), aurora.Cyan(fc))
if g.isFriendAuthorized(uint32(newProfileId)) {
logging.Info(g.ModuleName, "Attempt to add a friend who is already authorized")
@@ -204,6 +204,7 @@ func (g *GameSpySession) authAddFriend(command common.GameSpyCommand) {
func (g *GameSpySession) setStatus(command common.GameSpyCommand) {
status := command.CommandValue
+ logging.Notice(g.ModuleName, "New status:", aurora.BrightMagenta(status))
qr2.ProcessGPStatusUpdate(g.User.ProfileId, g.QR2IP, status)
@@ -220,16 +221,15 @@ func (g *GameSpySession) setStatus(command common.GameSpyCommand) {
}
statusMsg := "|s|" + status + "|ss|" + statstring + "|ls|" + locstring + "|ip|0|p|0|qm|0"
- logging.Notice(g.ModuleName, "New status:", aurora.BrightMagenta(statusMsg))
mutex.Lock()
+ defer mutex.Unlock()
g.LocString = locstring
g.Status = statusMsg
for _, storedPid := range g.FriendList {
g.sendFriendStatus(storedPid)
}
- mutex.Unlock()
}
const (
@@ -245,7 +245,7 @@ const (
func (g *GameSpySession) bestieMessage(command common.GameSpyCommand) {
// TODO: There are other command values that mean the same thing
if command.CommandValue != "1" {
- logging.Notice(g.ModuleName, "Received unknown bestie message type:", aurora.Cyan(command.CommandValue))
+ logging.Error(g.ModuleName, "Received unknown bestie message type:", aurora.Cyan(command.CommandValue))
return
}
diff --git a/gpcm/login.go b/gpcm/login.go
index 445b6bc..023ed8d 100644
--- a/gpcm/login.go
+++ b/gpcm/login.go
@@ -44,7 +44,7 @@ var msPublicKey = []byte{
0xF9, 0x5B, 0x4D, 0x11, 0x04, 0x44, 0x64, 0x35, 0xC0, 0xED, 0xA4, 0x2F,
}
-func verifySignature(authToken string, signature string) uint32 {
+func verifySignature(moduleName string, authToken string, signature string) uint32 {
sigBytes, err := common.Base64DwcEncoding.DecodeString(signature)
if err != nil || len(sigBytes) != 0x144 {
return 0
@@ -75,10 +75,10 @@ func verifySignature(authToken string, signature string) uint32 {
ngCertBlobHash := sha1.Sum(ngCertBlob)
if !verifyECDSA(msPublicKey, msSignature, ngCertBlobHash[:]) {
- logging.Error("GPCM", "NG cert verify failed")
+ logging.Error(moduleName, "NG cert verify failed")
return 0
}
- logging.Info("GPCM", "NG cert verified")
+ logging.Info(moduleName, "NG cert verified")
apIssuer := ngIssuer + "-" + ngName
apName := fmt.Sprintf("AP%02x%02x%02x%02x%02x%02x%02x%02x", apId[0], apId[1], apId[2], apId[3], apId[4], apId[5], apId[6], apId[7])
@@ -94,17 +94,17 @@ func verifySignature(authToken string, signature string) uint32 {
apCertBlobHash := sha1.Sum(apCertBlob)
if !verifyECDSA(ngPublicKey, ngSignature, apCertBlobHash[:]) {
- logging.Error("GPCM", "AP cert verify failed")
+ logging.Error(moduleName, "AP cert verify failed")
return 0
}
- logging.Info("GPCM", "AP cert verified")
+ logging.Info(moduleName, "AP cert verified")
authTokenHash := sha1.Sum([]byte(authToken))
if !verifyECDSA(apPublicKey, apSignature, authTokenHash[:]) {
- logging.Error("GPCM", "Auth token signature failed")
+ logging.Error(moduleName, "Auth token signature failed")
return 0
}
- logging.Notice("GPCM", "Auth token signature verified; NG ID:", aurora.Cyan(fmt.Sprintf("%08x", ngId)))
+ logging.Notice(moduleName, "Auth token signature verified; NG ID:", aurora.Cyan(fmt.Sprintf("%08x", ngId)))
return binary.BigEndian.Uint32(ngId)
}
@@ -161,7 +161,7 @@ func (g *GameSpySession) login(command common.GameSpyCommand) {
return
}
- if deviceId = verifySignature(authToken, signature); deviceId == 0 {
+ if deviceId = verifySignature(g.ModuleName, authToken, signature); deviceId == 0 {
g.replyError(GPError{
ErrorCode: ErrLogin.ErrorCode,
ErrorString: "The authentication signature is invalid.",
@@ -295,7 +295,7 @@ func (g *GameSpySession) exLogin(command common.GameSpyCommand) {
return
}
- if deviceId = verifySignature(g.AuthToken, signature); deviceId == 0 {
+ if deviceId = verifySignature(g.ModuleName, g.AuthToken, signature); deviceId == 0 {
g.replyError(GPError{
ErrorCode: ErrLogin.ErrorCode,
ErrorString: "The authentication signature is invalid.",
diff --git a/gpcm/main.go b/gpcm/main.go
index 32da9d5..d66033c 100644
--- a/gpcm/main.go
+++ b/gpcm/main.go
@@ -114,7 +114,7 @@ func handleRequest(conn net.Conn) {
session := &GameSpySession{
Conn: conn,
User: database.User{},
- ModuleName: "GPCM",
+ ModuleName: "GPCM:" + conn.RemoteAddr().String(),
LoggedIn: false,
Challenge: "",
Status: "",
@@ -130,7 +130,7 @@ func handleRequest(conn net.Conn) {
err := conn.(*net.TCPConn).SetKeepAlive(true)
if err != nil {
- logging.Notice(session.ModuleName, "Unable to set keepalive:", err.Error())
+ logging.Error(session.ModuleName, "Unable to set keepalive:", err.Error())
}
payload := common.CreateGameSpyMessage(common.GameSpyCommand{
@@ -153,7 +153,7 @@ func handleRequest(conn net.Conn) {
if err != nil {
if errors.Is(err, io.EOF) {
// Client closed connection, terminate.
- logging.Notice(session.ModuleName, "Client closed connection")
+ logging.Info(session.ModuleName, "Client closed connection")
return
}
@@ -207,7 +207,7 @@ func (g *GameSpySession) handleCommand(name string, commands []common.GameSpyCom
continue
}
- logging.Notice(g.ModuleName, "Command:", aurora.Yellow(command.Command))
+ logging.Info(g.ModuleName, "Command:", aurora.Yellow(command.Command))
handler(command)
}
diff --git a/gpcm/profile.go b/gpcm/profile.go
index 178809d..0fedbb1 100644
--- a/gpcm/profile.go
+++ b/gpcm/profile.go
@@ -1,11 +1,12 @@
package gpcm
import (
- "github.com/logrusorgru/aurora/v3"
"strconv"
"wwfc/common"
"wwfc/database"
"wwfc/logging"
+
+ "github.com/logrusorgru/aurora/v3"
)
func (g *GameSpySession) getProfile(command common.GameSpyCommand) {
@@ -17,7 +18,7 @@ func (g *GameSpySession) getProfile(command common.GameSpyCommand) {
return
}
- logging.Notice(g.ModuleName, "Looking up the profile of", aurora.Cyan(profileId).String())
+ logging.Info(g.ModuleName, "Looking up the profile of", aurora.Cyan(profileId).String())
user := database.User{}
locstring := ""
diff --git a/gpsp/main.go b/gpsp/main.go
index ae6398b..6058960 100644
--- a/gpsp/main.go
+++ b/gpsp/main.go
@@ -5,8 +5,6 @@ import (
"context"
"errors"
"fmt"
- "github.com/jackc/pgx/v4/pgxpool"
- "github.com/logrusorgru/aurora/v3"
"io"
"net"
"strconv"
@@ -14,6 +12,9 @@ import (
"wwfc/common"
"wwfc/database"
"wwfc/logging"
+
+ "github.com/jackc/pgx/v4/pgxpool"
+ "github.com/logrusorgru/aurora/v3"
)
var (
@@ -72,7 +73,7 @@ func handleRequest(conn net.Conn) {
logging.Notice(moduleName, "Unable to set keepalive:", err.Error())
}
- logging.Notice(moduleName, "Connection established from", aurora.BrightCyan(conn.RemoteAddr()))
+ logging.Info(moduleName, "Connection established from", aurora.BrightCyan(conn.RemoteAddr()))
// Here we go into the listening loop
for {
@@ -81,11 +82,11 @@ func handleRequest(conn net.Conn) {
if err != nil {
if errors.Is(err, io.EOF) {
// Client closed connection, terminate.
- logging.Notice(moduleName, "Client closed connection")
+ logging.Info(moduleName, "Client closed connection")
return
}
- logging.Notice(moduleName, "Connection lost")
+ logging.Error(moduleName, "Connection error:", err.Error())
return
}
@@ -96,7 +97,8 @@ func handleRequest(conn net.Conn) {
}
for _, command := range commands {
- logging.Notice(moduleName, "Command:", aurora.Yellow(command.Command))
+ logging.Info(moduleName, "Command:", aurora.Yellow(command.Command))
+
switch command.Command {
case "ka":
conn.Write([]byte(`\ka\\final\`))
@@ -123,7 +125,7 @@ func handleRequest(conn net.Conn) {
logging.Warn(moduleName, "Mismatched profile ID in otherslist:", aurora.Cyan(strProfileId))
}
- logging.Notice(moduleName, "Lookup otherslist for", aurora.Cyan(profileId))
+ logging.Info(moduleName, "Lookup otherslist for", aurora.Cyan(profileId))
conn.Write([]byte(handleOthersList(moduleName, uint32(profileId), command)))
break
}
@@ -188,7 +190,7 @@ func handleOthersList(moduleName string, _ uint32, command common.GameSpyCommand
// Also TODO: Check if the players are actually friends
user, ok := database.GetProfile(pool, ctx, uint32(otherId))
if !ok {
- logging.Error(moduleName, "Other ID doesn't exist:", aurora.Cyan(strOtherId))
+ logging.Warn(moduleName, "Other ID doesn't exist:", aurora.Cyan(strOtherId))
// If the profile doesn't exist then skip adding it
continue
}
diff --git a/logging/log.go b/logging/log.go
index a1313dd..d651cf6 100644
--- a/logging/log.go
+++ b/logging/log.go
@@ -2,11 +2,22 @@ package logging
import (
"fmt"
- "github.com/logrusorgru/aurora/v3"
"log"
+
+ "github.com/logrusorgru/aurora/v3"
)
+var logLevel = 0
+
+func SetLevel(level int) {
+ logLevel = level
+}
+
func Notice(module string, arguments ...any) {
+ if logLevel < 1 {
+ return
+ }
+
var finalStr string
for _, argument := range arguments {
finalStr += fmt.Sprint(argument)
@@ -17,6 +28,10 @@ func Notice(module string, arguments ...any) {
}
func Error(module string, arguments ...any) {
+ if logLevel < 2 {
+ return
+ }
+
var finalStr string
for _, argument := range arguments {
finalStr += fmt.Sprint(argument)
@@ -27,6 +42,10 @@ func Error(module string, arguments ...any) {
}
func Warn(module string, arguments ...any) {
+ if logLevel < 3 {
+ return
+ }
+
var finalStr string
for _, argument := range arguments {
finalStr += fmt.Sprint(argument)
@@ -37,6 +56,10 @@ func Warn(module string, arguments ...any) {
}
func Info(module string, arguments ...any) {
+ if logLevel < 4 {
+ return
+ }
+
var finalStr string
for _, argument := range arguments {
finalStr += fmt.Sprint(argument)
diff --git a/main.go b/main.go
index 51eacee..7864d04 100644
--- a/main.go
+++ b/main.go
@@ -2,8 +2,10 @@ package main
import (
"sync"
+ "wwfc/common"
"wwfc/gpcm"
"wwfc/gpsp"
+ "wwfc/logging"
"wwfc/nas"
"wwfc/natneg"
"wwfc/qr2"
@@ -12,6 +14,9 @@ import (
)
func main() {
+ config := common.GetConfig()
+ logging.SetLevel(config.LogLevel)
+
wg := &sync.WaitGroup{}
actions := []func(){nas.StartServer, gpcm.StartServer, qr2.StartServer, gpsp.StartServer, serverbrowser.StartServer, sake.StartServer, natneg.StartServer}
wg.Add(5)
diff --git a/nas/auth.go b/nas/auth.go
index 7a70f65..8aced28 100644
--- a/nas/auth.go
+++ b/nas/auth.go
@@ -240,6 +240,7 @@ func login(moduleName string, fields map[string]string, isLocalhost bool) map[st
}
authToken, challenge := common.MarshalNASAuthToken(gamecd, userId, gsbrcd, cfcInt, regionByte[0], langByte[0], fields["ingamesn"], isLocalhost)
+ logging.Notice(moduleName, "Login", aurora.Cyan(strconv.FormatUint(userId, 10)), aurora.Cyan(gsbrcd), "ingamesn:", aurora.Cyan(fields["ingamesn"]))
param["returncd"] = "001"
param["challenge"] = challenge
diff --git a/nas/https.go b/nas/https.go
index 2e7a0e8..f88255a 100644
--- a/nas/https.go
+++ b/nas/https.go
@@ -98,7 +98,7 @@ func startHTTPSProxy(address string, nasAddr string) {
panic(err)
}
- logging.Notice("NAS-TLS", "Receiving HTTPS request from", aurora.BrightCyan(conn.RemoteAddr()))
+ logging.Info("NAS-TLS", "Receiving HTTPS request from", aurora.BrightCyan(conn.RemoteAddr()))
moduleName := "NAS-TLS:" + conn.RemoteAddr().String()
go func() {
@@ -124,7 +124,7 @@ func startHTTPSProxy(address string, nasAddr string) {
0x00, 0x35, 0x00, 0x00, 0x2F, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x09, 0x00,
0x00, 0x05, 0x00, 0x00, 0x04,
}, buf[:min(index, 0x1D)]) {
- logging.Error(moduleName, "Invalid client hello:", aurora.Cyan(fmt.Sprintf("% X ", buf[:min(index, 0x1D)])))
+ logging.Info(moduleName, "Invalid client hello:", aurora.Cyan(fmt.Sprintf("% X ", buf[:min(index, 0x1D)])))
return
}
diff --git a/nas/main.go b/nas/main.go
index 5a81b7d..906c1e3 100644
--- a/nas/main.go
+++ b/nas/main.go
@@ -52,7 +52,6 @@ var regexSakeHost = regexp.MustCompile(`^([a-z\-]+\.)?sake\.gs\.`)
var regexStage1URL = regexp.MustCompile(`^/w([0-9])$`)
func handleRequest(w http.ResponseWriter, r *http.Request) {
- // TODO: Move this to its own server
// Check for *.sake.gs.* or sake.gs.*
if regexSakeHost.MatchString(r.Host) {
// Redirect to the sake server
@@ -60,18 +59,9 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
return
}
- logging.Notice("NAS", aurora.Yellow(r.Method), aurora.Cyan(r.URL), "via", aurora.Cyan(r.Host), "from", aurora.BrightCyan(r.RemoteAddr))
- moduleName := "NAS:" + r.RemoteAddr
-
- if r.URL.String() == "/ac" || r.URL.String() == "/pr" || r.URL.String() == "/download" {
- handleAuthRequest(moduleName, w, r)
- return
- }
-
- // TODO: Move this to its own server
- // Check for /payload
- if strings.HasPrefix(r.URL.String(), "/payload?") {
- handlePayloadRequest(moduleName, w, r)
+ // Handle conntest server
+ if strings.HasPrefix(r.Host, "conntest.") {
+ handleConnectionTest(w)
return
}
@@ -87,9 +77,18 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
return
}
- // Handle conntest server
- if strings.HasPrefix(r.Host, "conntest.") {
- handleConnectionTest(w)
+ logging.Info("NAS", aurora.Yellow(r.Method), aurora.Cyan(r.URL), "via", aurora.Cyan(r.Host), "from", aurora.BrightCyan(r.RemoteAddr))
+ moduleName := "NAS:" + r.RemoteAddr
+
+ if r.URL.String() == "/ac" || r.URL.String() == "/pr" || r.URL.String() == "/download" {
+ handleAuthRequest(moduleName, w, r)
+ return
+ }
+
+ // TODO: Move this to its own server
+ // Check for /payload
+ if strings.HasPrefix(r.URL.String(), "/payload?") {
+ handlePayloadRequest(moduleName, w, r)
return
}
diff --git a/natneg/main.go b/natneg/main.go
index 3184de0..591dd00 100644
--- a/natneg/main.go
+++ b/natneg/main.go
@@ -4,12 +4,13 @@ import (
"bytes"
"encoding/binary"
"fmt"
- "github.com/logrusorgru/aurora/v3"
"net"
"sync"
"time"
"wwfc/common"
"wwfc/logging"
+
+ "github.com/logrusorgru/aurora/v3"
)
const (
@@ -121,7 +122,7 @@ func handleConnection(conn net.PacketConn, addr net.Addr, buffer []byte) {
mutex.Lock()
session, exists := sessions[cookie]
if !exists {
- logging.Notice(moduleName, "Creating session")
+ logging.Info(moduleName, "Creating session")
session = &NATNEGSession{
Cookie: cookie,
Mutex: sync.RWMutex{},
@@ -149,7 +150,7 @@ func handleConnection(conn net.PacketConn, addr net.Addr, buffer []byte) {
break
case NNInitRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("NNInitRequest"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("NNInitRequest"))
session.handleInit(conn, addr, buffer[12:], moduleName, version)
break
@@ -162,11 +163,11 @@ func handleConnection(conn net.PacketConn, addr net.Addr, buffer []byte) {
break
case NNErtTestReply:
- logging.Notice(moduleName, "Command:", aurora.Yellow("NNErtReply"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("NNErtReply"))
break
case NNStateUpdate:
- logging.Notice(moduleName, "Command:", aurora.Yellow("NNStateUpdate"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("NNStateUpdate"))
break
case NNConnectRequest:
@@ -174,16 +175,16 @@ func handleConnection(conn net.PacketConn, addr net.Addr, buffer []byte) {
break
case NNConnectReply:
- logging.Notice(moduleName, "Command:", aurora.Yellow("NNConnectReply"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("NNConnectReply"))
// TODO: Set the client Connected value to true here
break
case NNConnectPing:
- logging.Notice(moduleName, "Command:", aurora.Yellow("NNConnectPing"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("NNConnectPing"))
break
case NNBackupTestRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("NNBackupTestRequest"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("NNBackupTestRequest"))
break
case NNBackupTestReply:
@@ -191,7 +192,7 @@ func handleConnection(conn net.PacketConn, addr net.Addr, buffer []byte) {
break
case NNAddressCheckRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("NNAddressCheckRequest"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("NNAddressCheckRequest"))
break
case NNAddressCheckReply:
@@ -199,11 +200,11 @@ func handleConnection(conn net.PacketConn, addr net.Addr, buffer []byte) {
break
case NNNatifyRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("NNNatifyRequest"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("NNNatifyRequest"))
break
case NNReportRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("NNReportRequest"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("NNReportRequest"))
session.handleReport(conn, addr, buffer[12:], moduleName, version)
break
@@ -212,7 +213,7 @@ func handleConnection(conn net.PacketConn, addr net.Addr, buffer []byte) {
break
case NNPreInitRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("NNPreInitRequest"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("NNPreInitRequest"))
break
case NNPreInitReply:
@@ -316,7 +317,7 @@ func (session *NATNEGSession) handleInit(conn net.PacketConn, addr net.Addr, buf
if !sender.isMapped() {
return
}
- logging.Notice(moduleName, "Mapped", aurora.BrightCyan(sender.NegotiateIP), aurora.BrightCyan(sender.LocalIP), aurora.BrightCyan(sender.ServerIP))
+ logging.Info(moduleName, "Mapped", aurora.BrightCyan(sender.NegotiateIP), aurora.BrightCyan(sender.LocalIP), aurora.BrightCyan(sender.ServerIP))
for id, destination := range session.Clients {
if id == clientIndex || destination.Connected || !destination.isMapped() {
diff --git a/qr2/group.go b/qr2/group.go
index a6482ef..db4c848 100644
--- a/qr2/group.go
+++ b/qr2/group.go
@@ -83,7 +83,7 @@ func processResvOK(moduleName string, matchVersion int, reservation common.Match
return true
}
- logging.Info(moduleName, "New player", aurora.BrightCyan(destination.Data["dwc_pid"]), "in group", aurora.Cyan(group.GroupName))
+ logging.Notice(moduleName, "New player", aurora.BrightCyan(destination.Data["dwc_pid"]), "in group", aurora.Cyan(group.GroupName))
group.LastJoinIndex++
destination.Data["+joinindex"] = strconv.Itoa(group.LastJoinIndex)
@@ -142,7 +142,7 @@ func ProcessGPStatusUpdate(profileID uint32, senderIP uint64, status string) {
login, exists := logins[profileID]
if !exists || login == nil {
- logging.Error(moduleName, "Received status update for non-existent profile ID", aurora.Cyan(profileID))
+ logging.Info(moduleName, "Received status update for non-existent profile ID", aurora.Cyan(profileID))
return
}
diff --git a/qr2/heartbeat.go b/qr2/heartbeat.go
index e68e86a..9b0a84d 100644
--- a/qr2/heartbeat.go
+++ b/qr2/heartbeat.go
@@ -50,22 +50,12 @@ func heartbeat(moduleName string, conn net.PacketConn, addr net.Addr, buffer []b
lookupAddr := makeLookupAddr(addr.String())
statechanged, ok := payload["statechanged"]
- if ok {
- if statechanged == "1" {
- // TODO: This would be a good place to run the server->client message exploit
- // for DNS patcher games that require code patches. The status code should be
- // set to 5 at this point (if publicip is not 0), which is required.
- logging.Notice(moduleName, "Client session update")
- // Fall through
- }
-
- if statechanged == "2" {
- logging.Notice(moduleName, "Client session shutdown")
- mutex.Lock()
- removeSession(lookupAddr)
- mutex.Unlock()
- return
- }
+ if ok && statechanged == "2" {
+ logging.Notice(moduleName, "Client session shutdown")
+ mutex.Lock()
+ removeSession(lookupAddr)
+ mutex.Unlock()
+ return
}
session, ok := setSessionData(moduleName, addr, sessionId, payload)
@@ -76,21 +66,20 @@ func heartbeat(moduleName string, conn net.PacketConn, addr net.Addr, buffer []b
if payload["gamename"] == "mariokartwii" && len(unknowns) > 0 {
// Try to login using the first unknown as a profile ID
// This makes it possible to execute the exploit on the client sooner
- profileId := unknowns[0]
- logging.Notice(moduleName, "Attempting to use unknown as profile ID", aurora.Cyan(profileId))
mutex.Lock()
session, sessionExists := sessions[lookupAddr]
if !sessionExists {
logging.Error(moduleName, "Session not found")
- } else {
+ } else if session.Login == nil {
+ profileId := unknowns[0]
+ logging.Info(moduleName, "Attempting to use unknown as profile ID", aurora.Cyan(profileId))
session.setProfileID(moduleName, profileId)
}
mutex.Unlock()
}
if !session.Authenticated {
- logging.Notice(moduleName, "Sending challenge")
sendChallenge(conn, addr, session, lookupAddr)
} else if !session.ExploitReceived && session.Login != nil && session.Login.NeedsExploit && statechanged == "1" {
logging.Notice(moduleName, "Sending SBCM exploit to DNS patcher client")
diff --git a/qr2/main.go b/qr2/main.go
index 385adba..6dd56a6 100644
--- a/qr2/main.go
+++ b/qr2/main.go
@@ -78,11 +78,11 @@ func handleConnection(conn net.PacketConn, addr net.Addr, buffer []byte) {
switch packetType {
case QueryRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("QUERY"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("QUERY"))
break
case ChallengeRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("CHALLENGE"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("CHALLENGE"))
mutex.Lock()
if session.Challenge != "" {
@@ -97,28 +97,28 @@ func handleConnection(conn net.PacketConn, addr net.Addr, buffer []byte) {
break
case EchoRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("ECHO"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("ECHO"))
break
case HeartbeatRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("HEARTBEAT"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("HEARTBEAT"))
heartbeat(moduleName, conn, addr, buffer)
break
case AddErrorRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("ADDERROR"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("ADDERROR"))
break
case EchoResponseRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("ECHO_RESPONSE"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("ECHO_RESPONSE"))
break
case ClientMessageRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("CLIENT_MESSAGE"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("CLIENT_MESSAGE"))
return
case ClientMessageAckRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("CLIENT_MESSAGE_ACK"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("CLIENT_MESSAGE_ACK"))
// In case ClientExploitReply is lost, this can be checked as well
// This would be sent either after the payload is downloaded, or the client is already patched
@@ -126,23 +126,23 @@ func handleConnection(conn net.PacketConn, addr net.Addr, buffer []byte) {
return
case KeepAliveRequest:
- logging.Notice(moduleName, "Command:", aurora.Yellow("KEEPALIVE"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("KEEPALIVE"))
mutex.Lock()
session.LastKeepAlive = time.Now().Unix()
mutex.Unlock()
return
case AvailableRequest:
- logging.Notice("QR2", "Command:", aurora.Yellow("AVAILABLE"))
+ logging.Info("QR2", "Command:", aurora.Yellow("AVAILABLE"))
conn.WriteTo(createResponseHeader(AvailableRequest, 0), addr)
return
case ClientRegisteredReply:
- logging.Notice(moduleName, "Command:", aurora.Yellow("CLIENT_REGISTERED"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("CLIENT_REGISTERED"))
break
case ClientExploitReply:
- logging.Notice(moduleName, "Command:", aurora.Yellow("CLIENT_EXPLOIT_ACK"))
+ logging.Info(moduleName, "Command:", aurora.Yellow("CLIENT_EXPLOIT_ACK"))
session.ExploitReceived = true
break
diff --git a/qr2/session.go b/qr2/session.go
index fca85f6..5232ca8 100644
--- a/qr2/session.go
+++ b/qr2/session.go
@@ -121,7 +121,7 @@ func setSessionData(moduleName string, addr net.Addr, sessionId uint32, payload
}
if !sessionExists {
- logging.Notice(moduleName, "Creating session", aurora.Cyan(sessionId).String())
+ logging.Info(moduleName, "Creating session", aurora.Cyan(sessionId).String())
// Set search ID
for {
diff --git a/sake/main.go b/sake/main.go
index 5ad84eb..9d11684 100644
--- a/sake/main.go
+++ b/sake/main.go
@@ -3,11 +3,12 @@ package sake
import (
"context"
"fmt"
- "github.com/jackc/pgx/v4/pgxpool"
- "github.com/logrusorgru/aurora/v3"
"net/http"
"wwfc/common"
"wwfc/logging"
+
+ "github.com/jackc/pgx/v4/pgxpool"
+ "github.com/logrusorgru/aurora/v3"
)
var (
@@ -35,7 +36,7 @@ func StartServer() {
}
func HandleRequest(w http.ResponseWriter, r *http.Request) {
- logging.Notice("SAKE", aurora.Yellow(r.Method), aurora.Cyan(r.URL), "via", aurora.Cyan(r.Host), "from", aurora.BrightCyan(r.RemoteAddr))
+ logging.Info("SAKE", aurora.Yellow(r.Method), aurora.Cyan(r.URL), "via", aurora.Cyan(r.Host), "from", aurora.BrightCyan(r.RemoteAddr))
switch r.URL.String() {
case "/SakeStorageServer/StorageServer.asmx":
diff --git a/sake/storage.go b/sake/storage.go
index 0fa5290..4567a4b 100644
--- a/sake/storage.go
+++ b/sake/storage.go
@@ -3,7 +3,6 @@ package sake
import (
"encoding/base64"
"encoding/xml"
- "github.com/logrusorgru/aurora/v3"
"io"
"net/http"
"regexp"
@@ -12,6 +11,8 @@ import (
"wwfc/common"
"wwfc/database"
"wwfc/logging"
+
+ "github.com/logrusorgru/aurora/v3"
)
const (
@@ -140,7 +141,7 @@ func handleStorageRequest(moduleName string, w http.ResponseWriter, r *http.Requ
xmlName := soap.Body.Data.XMLName.Space + "/" + soap.Body.Data.XMLName.Local
if headerAction == xmlName || headerAction == `"`+xmlName+`"` {
- logging.Notice(moduleName, "SOAPAction:", aurora.Yellow(soap.Body.Data.XMLName.Local))
+ logging.Info(moduleName, "SOAPAction:", aurora.Yellow(soap.Body.Data.XMLName.Local))
if profileId, gameInfo, ok := getRequestIdentity(moduleName, soap.Body.Data); ok {
switch xmlName {
@@ -268,7 +269,7 @@ func getMyRecords(moduleName string, profileId uint32, gameInfo common.GameInfo,
}
}
- logging.Notice(moduleName, "Wrote", aurora.Cyan(fieldCount), "field(s)")
+ logging.Info(moduleName, "Wrote", aurora.Cyan(fieldCount), "field(s)")
return &response
}
@@ -382,6 +383,6 @@ func searchForRecords(moduleName string, gameInfo common.GameInfo, request Stora
}
}
- logging.Notice(moduleName, "Wrote", aurora.BrightCyan(fieldCount), "field(s) across", aurora.BrightCyan(i), "record(s)")
+ logging.Info(moduleName, "Wrote", aurora.BrightCyan(fieldCount), "field(s) across", aurora.BrightCyan(i), "record(s)")
return &response
}
diff --git a/serverbrowser/main.go b/serverbrowser/main.go
index bbf40a3..5b308ca 100644
--- a/serverbrowser/main.go
+++ b/serverbrowser/main.go
@@ -6,13 +6,14 @@ import (
"encoding/binary"
"errors"
"fmt"
- "github.com/jackc/pgx/v4/pgxpool"
- "github.com/logrusorgru/aurora/v3"
"io"
"net"
"os"
"wwfc/common"
"wwfc/logging"
+
+ "github.com/jackc/pgx/v4/pgxpool"
+ "github.com/logrusorgru/aurora/v3"
)
var (
@@ -86,10 +87,10 @@ func handleRequest(conn net.Conn) {
err := conn.(*net.TCPConn).SetKeepAlive(true)
if err != nil {
- logging.Notice(ModuleName, "Unable to set keepalive", err.Error())
+ logging.Error(ModuleName, "Unable to set keepalive", err.Error())
}
- logging.Notice(ModuleName, "Connection established from", aurora.BrightCyan(conn.RemoteAddr()))
+ logging.Info(ModuleName, "Connection established from", aurora.BrightCyan(conn.RemoteAddr()))
// Here we go into the listening loop
bufferSize := 0
@@ -119,11 +120,11 @@ func handleRequest(conn net.Conn) {
readSize, err := bufio.NewReader(conn).Read(buffer[bufferSize:])
if err != nil {
if errors.Is(err, io.EOF) {
- logging.Notice(ModuleName, "Connection closed")
+ logging.Info(ModuleName, "Connection closed")
return
}
- logging.Error(ModuleName, "Connection error")
+ logging.Error(ModuleName, "Connection error:", err.Error())
return
}
@@ -132,29 +133,29 @@ func handleRequest(conn net.Conn) {
switch buffer[2] {
case ServerListRequest:
- logging.Notice(ModuleName, "Command:", aurora.Yellow("SERVER_LIST_REQUEST"))
+ logging.Info(ModuleName, "Command:", aurora.Yellow("SERVER_LIST_REQUEST"))
handleServerListRequest(conn, buffer[:packetSize])
break
case ServerInfoRequest:
- logging.Notice(ModuleName, "Command:", aurora.Yellow("SERVER_INFO_REQUEST"))
+ logging.Info(ModuleName, "Command:", aurora.Yellow("SERVER_INFO_REQUEST"))
break
case SendMessageRequest:
- logging.Notice(ModuleName, "Command:", aurora.Yellow("SEND_MESSAGE_REQUEST"))
+ logging.Info(ModuleName, "Command:", aurora.Yellow("SEND_MESSAGE_REQUEST"))
handleSendMessageRequest(conn, buffer[:packetSize])
break
case KeepaliveReply:
- logging.Notice(ModuleName, "Command:", aurora.Yellow("KEEPALIVE_REPLY"))
+ logging.Info(ModuleName, "Command:", aurora.Yellow("KEEPALIVE_REPLY"))
break
case MapLoopRequest:
- logging.Notice(ModuleName, "Command:", aurora.Yellow("MAPLOOP_REQUEST"))
+ logging.Info(ModuleName, "Command:", aurora.Yellow("MAPLOOP_REQUEST"))
break
case PlayerSearchRequest:
- logging.Notice(ModuleName, "Command:", aurora.Yellow("PLAYER_SEARCH_REQUEST"))
+ logging.Info(ModuleName, "Command:", aurora.Yellow("PLAYER_SEARCH_REQUEST"))
break
default: