diff --git a/.gitignore b/.gitignore index 70b6edb..f00ccba 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,7 @@ log *.pem *.key *.pcap -*.pcapng \ No newline at end of file +*.pcapng + +# misc +.DS_Store \ No newline at end of file diff --git a/globals/globals.go b/globals/globals.go index 4fafd7c..ad10bdd 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -1,8 +1,10 @@ package globals import ( + "database/sql" pb "github.com/PretendoNetwork/grpc-go/account" "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" "github.com/PretendoNetwork/plogger-go" "google.golang.org/grpc" "google.golang.org/grpc/metadata" @@ -20,3 +22,6 @@ var SecureEndpoint *nex.PRUDPEndPoint var GRPCAccountClientConnection *grpc.ClientConn var GRPCAccountClient pb.AccountClient var GRPCAccountCommonMetadata metadata.MD + +var Postgres *sql.DB +var MatchmakingManager *common_globals.MatchmakingManager diff --git a/go.mod b/go.mod index 5f2693c..c24c3ff 100644 --- a/go.mod +++ b/go.mod @@ -1,25 +1,25 @@ module github.com/PretendoNetwork/splatoon -go 1.21 - -toolchain go1.21.9 +go 1.22.1 require ( github.com/PretendoNetwork/grpc-go v1.0.2 - github.com/PretendoNetwork/nex-go/v2 v2.0.2 - github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.0.5 - github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.3 + github.com/PretendoNetwork/nex-go/v2 v2.0.5 + github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.0.6 + github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.4 github.com/PretendoNetwork/plogger-go v1.0.4 github.com/joho/godotenv v1.5.1 google.golang.org/grpc v1.63.2 ) require ( + github.com/PretendoNetwork/pq-extended v1.0.0 // indirect github.com/dolthub/maphash v0.1.0 // indirect github.com/fatih/color v1.17.0 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/jwalton/go-supportscolor v1.2.0 // indirect github.com/klauspost/compress v1.17.9 // indirect + github.com/lib/pq v1.10.9 // indirect github.com/lxzan/gws v1.8.5 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect diff --git a/go.sum b/go.sum index 8e971a2..e90c2cc 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,15 @@ github.com/PretendoNetwork/grpc-go v1.0.2 h1:9TvKmX7dCOANyoHEra1MMYqS1N/RGav66TRG4SHInvo= github.com/PretendoNetwork/grpc-go v1.0.2/go.mod h1:XZjEsij9lL7HJBNkH6JPbBIkUSq/1rjflvjGdv+DAj0= -github.com/PretendoNetwork/nex-go/v2 v2.0.2 h1:mPp27Ero3Rr28nekuKg4f0tdp28NzmCJXgupt2paT18= -github.com/PretendoNetwork/nex-go/v2 v2.0.2/go.mod h1:O5v200Ro8bdrmqSAmzV0cqQsG7cdmwLHAet5X7Jxz20= -github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.0.5 h1:17b7vA8wjWLW9JdJTHeOoX2g2e4S/EwA32m9AuPEA80= -github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.0.5/go.mod h1:0wDEYxDYbUOjsKjsTUjU0/f3pL1MT54h+tGn4UyeB+A= -github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.3 h1:80CG7f9w/34MN1vAZ1XP3ec4LJ4mqKlkests+HQzrvc= -github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.3/go.mod h1:2UN8khoMDNaeJ4GcIG7ez7MqqmbLfLzbVS6hSa+kGnk= +github.com/PretendoNetwork/nex-go/v2 v2.0.5 h1:S/bYPb2SNUb9MSzai4wlqj/9J1JIiLuMtZcAAbBughM= +github.com/PretendoNetwork/nex-go/v2 v2.0.5/go.mod h1:iW1xjbg/vl2c3uheitUFxGcrt0sxaDxeXR5QqDcyLpI= +github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.0.6 h1:8nNJvJi5aTmGBRtEGVYAI6cjNK1WyIiF+AnGD1QyD+E= +github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.0.6/go.mod h1:Mngar0XMLs7oG9KfeyVJBBhYNCNRXxDcucJTthpP9GY= +github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.4 h1:7Vb/jV/cO6c8XcGzGCoowSNXjZDLb/D1lYkLk8rxm7c= +github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.4/go.mod h1:2UN8khoMDNaeJ4GcIG7ez7MqqmbLfLzbVS6hSa+kGnk= github.com/PretendoNetwork/plogger-go v1.0.4 h1:PF7xHw9eDRHH+RsAP9tmAE7fG0N0p6H4iPwHKnsoXwc= github.com/PretendoNetwork/plogger-go v1.0.4/go.mod h1:7kD6M4vPq1JL4LTuPg6kuB1OvUBOwQOtAvTaUwMbwvU= +github.com/PretendoNetwork/pq-extended v1.0.0 h1:GHZ0hLvCvmYKQPTV9I9XtTx8J1iB5Z9CEnfW2tUpsYg= +github.com/PretendoNetwork/pq-extended v1.0.0/go.mod h1:bq6Ai+3lG4/M0iamUBt2Uzi5vL/nYy1a1Ar2ow9NDF0= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ= @@ -24,6 +26,8 @@ github.com/jwalton/go-supportscolor v1.2.0 h1:g6Ha4u7Vm3LIsQ5wmeBpS4gazu0UP1DRDE github.com/jwalton/go-supportscolor v1.2.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs= github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lxzan/gws v1.8.5 h1:6x+wW3EHtoGFNeCtZP1OVZ1IHrpZZzDaEjQGg1lUJqU= github.com/lxzan/gws v1.8.5/go.mod h1:FcGeRMB7HwGuTvMLR24ku0Zx0p6RXqeKASeMc4VYgi4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= diff --git a/init.go b/init.go index 134b7a2..1361ac5 100644 --- a/init.go +++ b/init.go @@ -1,6 +1,7 @@ package main import ( + "database/sql" "fmt" "os" "strconv" @@ -104,4 +105,9 @@ func init() { globals.GRPCAccountCommonMetadata = metadata.Pairs( "X-API-Key", accountGRPCAPIKey, ) + globals.Postgres, err = sql.Open("postgres", os.Getenv("PN_SPLATOON_POSTGRES_URI")) + if err != nil { + globals.Logger.Critical(err.Error()) + } + globals.Logger.Success("Connected to Postgres!") } diff --git a/nex/register_common_secure_server_protocols.go b/nex/register_common_secure_server_protocols.go index 2b1e81a..9c29c49 100644 --- a/nex/register_common_secure_server_protocols.go +++ b/nex/register_common_secure_server_protocols.go @@ -3,21 +3,20 @@ package nex import ( "github.com/PretendoNetwork/nex-go/v2" "github.com/PretendoNetwork/nex-go/v2/types" - commonnattraversal "github.com/PretendoNetwork/nex-protocols-common-go/v2/nat-traversal" - commonsecure "github.com/PretendoNetwork/nex-protocols-common-go/v2/secure-connection" - nattraversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" - secure "github.com/PretendoNetwork/nex-protocols-go/v2/secure-connection" - "github.com/PretendoNetwork/splatoon/globals" - "strconv" - "strings" - commonmatchmaking "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making" commonmatchmakingext "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making-ext" commonmatchmakeextension "github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension" + commonnattraversal "github.com/PretendoNetwork/nex-protocols-common-go/v2/nat-traversal" + commonranking "github.com/PretendoNetwork/nex-protocols-common-go/v2/ranking" + commonsecure "github.com/PretendoNetwork/nex-protocols-common-go/v2/secure-connection" matchmaking "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" matchmakingext "github.com/PretendoNetwork/nex-protocols-go/v2/match-making-ext" - matchmakingtypes "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" matchmakeextension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" + nattraversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" + ranking "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/splatoon" + secure "github.com/PretendoNetwork/nex-protocols-go/v2/secure-connection" + "github.com/PretendoNetwork/splatoon/globals" ) func CreateReportDBRecord(_ *types.PID, _ *types.PrimitiveU32, _ *types.QBuffer) error { @@ -33,12 +32,7 @@ func stubGetPlayingSession(err error, packet nex.PacketInterface, callID uint32, connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) - lstPlayingSession := types.NewList[*matchmakingtypes.PlayingSession]() - - // * There are no sessions, I tell you! - //for _, playingSession := range playingSessions { - // lstPlayingSession.Append(playingSession) - //} + lstPlayingSession := types.NewList[*match_making_types.PlayingSession]() rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) @@ -54,56 +48,21 @@ func stubGetPlayingSession(err error, packet nex.PacketInterface, callID uint32, return rmcResponse, nil } -// from nex-protocols-common-go/matchmaking_utils.go -func compareSearchCriteria[T ~uint16 | ~uint32](original T, search string) bool { - if search == "" { // * Accept any value - return true - } - - before, after, found := strings.Cut(search, ",") - if found { - min, err := strconv.ParseUint(before, 10, 64) - if err != nil { - return false - } - - max, err := strconv.ParseUint(after, 10, 64) - if err != nil { - return false - } - - return min <= uint64(original) && max >= uint64(original) - } else { - searchNum, err := strconv.ParseUint(before, 10, 64) - if err != nil { - return false - } - - return searchNum == uint64(original) +func cleanupMatchmakeSessionSearchCriteriasHandler(searchCriterias *types.List[*match_making_types.MatchmakeSessionSearchCriteria]) { + for _, searchCriteria := range searchCriterias.Slice() { + _ = searchCriteria.Attribs.SetIndex(4, types.NewString("")) } } -func gameSpecificMatchmakeSessionSearchCriteriaChecksHandler(searchCriteria *matchmakingtypes.MatchmakeSessionSearchCriteria, matchmakeSession *matchmakingtypes.MatchmakeSession) bool { - original := matchmakeSession.Attributes.Slice() - search := searchCriteria.Attribs.Slice() - if len(original) != len(search) { - return false - } +func onAfterAutoMatchmakeWithParamPostpone(_ nex.PacketInterface, _ *match_making_types.AutoMatchmakeParam) { + globals.MatchmakingManager.Mutex.Lock() - for index, originalAttribute := range original { - // ignore dummy criterias for matchmaking - // everyone ends up in different rooms if you don't skip these - if index == 1 || index == 4 { - continue - } - searchAttribute := search[index] - - if !compareSearchCriteria(originalAttribute.Value, searchAttribute.Value) { - return false - } + _, err := globals.MatchmakingManager.Database.Exec(`UPDATE matchmaking.matchmake_sessions SET open_participation=true WHERE game_mode=12`) + if err != nil { + globals.Logger.Error(err.Error()) } - return true + globals.MatchmakingManager.Mutex.Unlock() } func registerCommonSecureServerProtocols() { @@ -119,15 +78,23 @@ func registerCommonSecureServerProtocols() { matchMakingProtocol := matchmaking.NewProtocol() globals.SecureEndpoint.RegisterServiceProtocol(matchMakingProtocol) - commonmatchmaking.NewCommonProtocol(matchMakingProtocol) + commonMatchMakingProtocol := commonmatchmaking.NewCommonProtocol(matchMakingProtocol) + commonMatchMakingProtocol.SetManager(globals.MatchmakingManager) matchMakingExtProtocol := matchmakingext.NewProtocol() globals.SecureEndpoint.RegisterServiceProtocol(matchMakingExtProtocol) - commonmatchmakingext.NewCommonProtocol(matchMakingExtProtocol) + commonMatchMakingExtProtocol := commonmatchmakingext.NewCommonProtocol(matchMakingExtProtocol) + commonMatchMakingExtProtocol.SetManager(globals.MatchmakingManager) matchmakeExtensionProtocol := matchmakeextension.NewProtocol() globals.SecureEndpoint.RegisterServiceProtocol(matchmakeExtensionProtocol) commonMatchmakeExtensionProtocol := commonmatchmakeextension.NewCommonProtocol(matchmakeExtensionProtocol) matchmakeExtensionProtocol.SetHandlerGetPlayingSession(stubGetPlayingSession) - commonMatchmakeExtensionProtocol.GameSpecificMatchmakeSessionSearchCriteriaChecks = gameSpecificMatchmakeSessionSearchCriteriaChecksHandler + commonMatchmakeExtensionProtocol.CleanupMatchmakeSessionSearchCriterias = cleanupMatchmakeSessionSearchCriteriasHandler + commonMatchmakeExtensionProtocol.OnAfterAutoMatchmakeWithParamPostpone = onAfterAutoMatchmakeWithParamPostpone + commonMatchmakeExtensionProtocol.SetManager(globals.MatchmakingManager) + + rankingProtocol := ranking.NewProtocol(globals.SecureEndpoint) + globals.SecureEndpoint.RegisterServiceProtocol(rankingProtocol) + commonranking.NewCommonProtocol(rankingProtocol) } diff --git a/nex/secure.go b/nex/secure.go index 48e4c8f..38451de 100644 --- a/nex/secure.go +++ b/nex/secure.go @@ -2,6 +2,7 @@ package nex import ( "fmt" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" "os" "strconv" @@ -36,6 +37,8 @@ func StartSecureServer() { globals.Logger.Errorf("Secure: %v", err) }) + globals.MatchmakingManager = common_globals.NewMatchmakingManager(globals.SecureEndpoint, globals.Postgres) + registerCommonSecureServerProtocols() port, _ := strconv.Atoi(os.Getenv("PN_SPLATOON_SECURE_SERVER_PORT")) diff --git a/splatoon b/splatoon new file mode 100755 index 0000000..83c8725 Binary files /dev/null and b/splatoon differ