Skip to content

Commit

Permalink
feat: Save pia connection reports to database
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ashquarky committed Dec 6, 2024
1 parent 8e52c67 commit ef521ae
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
10 changes: 10 additions & 0 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
19 changes: 16 additions & 3 deletions nex/register_common_secure_server_protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ef521ae

Please sign in to comment.