Skip to content

Commit

Permalink
feat!(secure): Use new MatchmakingManager code
Browse files Browse the repository at this point in the history
Port to the nex-protocols-common-go/matchmaking-rewrite staging branch. This has better notification behaviour, among other improvements.
  • Loading branch information
ashquarky committed Aug 10, 2024
1 parent 8a30e47 commit 75d247c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions globals/globals.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
9 changes: 9 additions & 0 deletions init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"database/sql"
"fmt"
"os"
"strconv"
Expand Down Expand Up @@ -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!")

}
7 changes: 5 additions & 2 deletions nex/register_common_secure_server_protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
3 changes: 3 additions & 0 deletions nex/secure.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nex

import (
"fmt"
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
"os"
"strconv"

Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit 75d247c

Please sign in to comment.