diff --git a/nex/register_common_secure_server_protocols.go b/nex/register_common_secure_server_protocols.go index 1780c47..b5f7c21 100644 --- a/nex/register_common_secure_server_protocols.go +++ b/nex/register_common_secure_server_protocols.go @@ -26,9 +26,37 @@ import ( matchmakingtypes "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" - common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + commonglobals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" ) +func MatchmakeExtensionCloseParticipation(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session, ok := commonglobals.Sessions[gid.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + // * PUYOPUYOTETRIS has everyone send CloseParticipation here, not just the owner of the room. + // * So, if a non-owner asks, just lie and claim success without actually changing anything. + if !session.GameMatchmakeSession.Gathering.OwnerPID.Equals(connection.PID()) { + session.GameMatchmakeSession.OpenParticipation = types.NewPrimitiveBool(false) + } + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = matchmakeextension.ProtocolID + rmcResponse.MethodID = matchmakeextension.MethodCloseParticipation + rmcResponse.CallID = callID + + return rmcResponse, nil +} + func CreateReportDBRecord(_ *types.PID, _ *types.PrimitiveU32, _ *types.QBuffer) error { return nil } @@ -86,9 +114,17 @@ func registerCommonSecureServerProtocols() { matchmakeExtensionProtocol := matchmakeextension.NewProtocol() globals.SecureEndpoint.RegisterServiceProtocol(matchmakeExtensionProtocol) commonMatchmakeExtensionProtocol := commonmatchmakeextension.NewCommonProtocol(matchmakeExtensionProtocol) + // * Handle custom CloseParticipation behaviour + matchmakeExtensionProtocol.SetHandlerCloseParticipation(MatchmakeExtensionCloseParticipation) commonMatchmakeExtensionProtocol.OnAfterAutoMatchmakeWithSearchCriteriaPostpone = func(packet nex.PacketInterface, lstSearchCriteria *types.List[*matchmakingtypes.MatchmakeSessionSearchCriteria], anyGathering *types.AnyDataHolder, strMessage *types.String) { - for _, session := range common_globals.Sessions { + globals.Logger.Info("Matchmake search criteria:") + for _, criteria := range lstSearchCriteria.Slice() { + globals.Logger.Info(criteria.FormatToString(1)) + } + + globals.Logger.Info("Active matchmaking sessions:") + for _, session := range commonglobals.Sessions { globals.Logger.Info(session.GameMatchmakeSession.FormatToString(1)) } }