feat: Save pia connection reports to database

I would have liked to save the gathering info too but I couldn't work out how to extract that from MatchmakingManager
you can kinda reverse-engineer it from the tracking logs anyway
This commit is contained in:
Ash Logan 2024-12-06 16:02:56 +11:00
parent 8e52c6714c
commit ef521aea15
2 changed files with 26 additions and 3 deletions

10
init.go
View File

@ -110,4 +110,14 @@ func init() {
globals.Logger.Critical(err.Error())
}
globals.Logger.Success("Connected to Postgres!")
_, err = globals.Postgres.Exec(`CREATE TABLE IF NOT EXISTS reports (
id bigserial PRIMARY KEY,
ts timestamp,
report_id integer,
report bytea
)`)
if err != nil {
globals.Logger.Error(err.Error())
}
}

View File

@ -19,8 +19,21 @@ import (
"github.com/PretendoNetwork/splatoon/globals"
)
func CreateReportDBRecord(_ *types.PID, _ *types.PrimitiveU32, _ *types.QBuffer) error {
return nil
// that's right boys it's a FACTORY METHOD IN GO LET'S GOOOO
func fCreateReportDBRecord() func(*types.PID, *types.PrimitiveU32, *types.QBuffer) error {
createReportStmt, err := globals.Postgres.Prepare(`INSERT INTO reports (ts, report_id, report) VALUES (NOW(), $1, $2)`)
if err != nil {
globals.Logger.Error(err.Error())
}
return func(pid *types.PID, id *types.PrimitiveU32, report *types.QBuffer) error {
if createReportStmt == nil {
return nil // Just drop the report in case of DB error - no need to freak out the client with a reported err
}
_, err := createReportStmt.Exec(id.Value, report.Value)
return err // consider not reporting this error to the client
}
}
func stubGetPlayingSession(err error, packet nex.PacketInterface, callID uint32, _ *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) {
@ -70,7 +83,7 @@ func registerCommonSecureServerProtocols() {
globals.SecureEndpoint.RegisterServiceProtocol(secureProtocol)
commonSecureProtocol := commonsecure.NewCommonProtocol(secureProtocol)
commonSecureProtocol.CreateReportDBRecord = CreateReportDBRecord
commonSecureProtocol.CreateReportDBRecord = fCreateReportDBRecord()
natTraversalProtocol := nattraversal.NewProtocol()
globals.SecureEndpoint.RegisterServiceProtocol(natTraversalProtocol)