From ff20935c8cef431071a7ec12e3dd537596b0e0b2 Mon Sep 17 00:00:00 2001 From: Ash Logan Date: Mon, 12 Aug 2024 14:31:59 +1000 Subject: [PATCH] feat: Add extension point for CanJoinMatchmakeSession Useful for games with custom behaviours, like Minecraft's friends-of-friends feature and Splatoon's fests --- matchmake-extension/join_matchmake_session.go | 7 ++++++- matchmake-extension/join_matchmake_session_ex.go | 7 ++++++- matchmake-extension/join_matchmake_session_with_param.go | 7 ++++++- matchmake-extension/protocol.go | 1 + 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/matchmake-extension/join_matchmake_session.go b/matchmake-extension/join_matchmake_session.go index ba46880..bc9c976 100644 --- a/matchmake-extension/join_matchmake_session.go +++ b/matchmake-extension/join_matchmake_session.go @@ -38,7 +38,12 @@ func (commonProtocol *CommonProtocol) joinMatchmakeSession(err error, packet nex return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } - nexError = common_globals.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession) + // * Allow game servers to do their own permissions checks + if commonProtocol.CanJoinMatchmakeSession != nil { + nexError = commonProtocol.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession) + } else { + nexError = common_globals.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession) + } if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError diff --git a/matchmake-extension/join_matchmake_session_ex.go b/matchmake-extension/join_matchmake_session_ex.go index b7d0645..7deb01b 100644 --- a/matchmake-extension/join_matchmake_session_ex.go +++ b/matchmake-extension/join_matchmake_session_ex.go @@ -38,7 +38,12 @@ func (commonProtocol *CommonProtocol) joinMatchmakeSessionEx(err error, packet n return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } - nexError = common_globals.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession) + // * Allow game servers to do their own permissions checks + if commonProtocol.CanJoinMatchmakeSession != nil { + nexError = commonProtocol.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession) + } else { + nexError = common_globals.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession) + } if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError diff --git a/matchmake-extension/join_matchmake_session_with_param.go b/matchmake-extension/join_matchmake_session_with_param.go index 535842c..7e32c1e 100644 --- a/matchmake-extension/join_matchmake_session_with_param.go +++ b/matchmake-extension/join_matchmake_session_with_param.go @@ -42,7 +42,12 @@ func (commonProtocol *CommonProtocol) joinMatchmakeSessionWithParam(err error, p return nil, nex.NewError(nex.ResultCodes.RendezVous.InvalidPassword, "change_error") } - nexError = common_globals.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession) + // * Allow game servers to do their own permissions checks + if commonProtocol.CanJoinMatchmakeSession != nil { + nexError = commonProtocol.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession) + } else { + nexError = common_globals.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession) + } if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError diff --git a/matchmake-extension/protocol.go b/matchmake-extension/protocol.go index 298b172..4ad9b2b 100644 --- a/matchmake-extension/protocol.go +++ b/matchmake-extension/protocol.go @@ -14,6 +14,7 @@ type CommonProtocol struct { endpoint nex.EndpointInterface protocol matchmake_extension.Interface manager *common_globals.MatchmakingManager + CanJoinMatchmakeSession func(manager *common_globals.MatchmakingManager, pid *types.PID, matchmakeSession *match_making_types.MatchmakeSession) *nex.Error CleanupSearchMatchmakeSession func(matchmakeSession *match_making_types.MatchmakeSession) CleanupMatchmakeSessionSearchCriterias func(searchCriterias *types.List[*match_making_types.MatchmakeSessionSearchCriteria]) OnAfterOpenParticipation func(packet nex.PacketInterface, gid *types.PrimitiveU32)