From 75d247ceb19af70ab5810674eb00d3f03de959a9 Mon Sep 17 00:00:00 2001 From: Ash Logan Date: Sat, 10 Aug 2024 16:56:52 +1000 Subject: [PATCH] feat!(secure): Use new MatchmakingManager code Port to the nex-protocols-common-go/matchmaking-rewrite staging branch. This has better notification behaviour, among other improvements. --- globals/globals.go | 5 +++++ init.go | 9 +++++++++ nex/register_common_secure_server_protocols.go | 7 +++++-- nex/secure.go | 3 +++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/globals/globals.go b/globals/globals.go index 4fafd7c..d1b26bf 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" @@ -17,6 +19,9 @@ var AuthenticationEndpoint *nex.PRUDPEndPoint var SecureServer *nex.PRUDPServer var SecureEndpoint *nex.PRUDPEndPoint +var Postgres *sql.DB +var MatchmakingManager *common_globals.MatchmakingManager + var GRPCAccountClientConnection *grpc.ClientConn var GRPCAccountClient pb.AccountClient var GRPCAccountCommonMetadata metadata.MD diff --git a/init.go b/init.go index e632f6a..f06998a 100644 --- a/init.go +++ b/init.go @@ -1,6 +1,7 @@ package main import ( + "database/sql" "fmt" "os" "strconv" @@ -104,4 +105,12 @@ func init() { globals.GRPCAccountCommonMetadata = metadata.Pairs( "X-API-Key", accountGRPCAPIKey, ) + + globals.Postgres, err = sql.Open("postgres", os.Getenv("PN_MINECRAFT_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 de53e30..679c51c 100644 --- a/nex/register_common_secure_server_protocols.go +++ b/nex/register_common_secure_server_protocols.go @@ -82,15 +82,18 @@ 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) + commonMatchmakeExtensionProtocol.SetManager(globals.MatchmakingManager) commonMatchmakeExtensionProtocol.CleanupSearchMatchmakeSession = cleanupSearchMatchmakeSessionHandler if os.Getenv("PN_MINECRAFT_ALLOW_PUBLIC_MATCHMAKING") != "1" { diff --git a/nex/secure.go b/nex/secure.go index df26bf3..e0b899d 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" @@ -38,6 +39,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_MINECRAFT_SECURE_SERVER_PORT"))