Skip to content

Commit

Permalink
feat(secure): Use custom CloseHandler for matchmake-extension
Browse files Browse the repository at this point in the history
PUYOPUYOTETRIS has all participants send CloseParticipation when the match starts. The underlying -common library sets an error here which terminates the match.

Upstream -common decided not to take a workaround for this, so instead set our own handler to ignore the error condition.
  • Loading branch information
ashquarky committed Jul 1, 2024
1 parent 3b322f3 commit b108eaf
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions nex/register_common_secure_server_protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
}
}
Expand Down

0 comments on commit b108eaf

Please sign in to comment.