Skip to content

Commit

Permalink
feat: Add extension point for CanJoinMatchmakeSession
Browse files Browse the repository at this point in the history
Useful for games with custom behaviours, like Minecraft's friends-of-friends feature
and Splatoon's fests
  • Loading branch information
ashquarky committed Aug 25, 2024
1 parent 9639ab6 commit ff20935
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion matchmake-extension/join_matchmake_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion matchmake-extension/join_matchmake_session_ex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion matchmake-extension/join_matchmake_session_with_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions matchmake-extension/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ff20935

Please sign in to comment.