mirror of
https://github.com/PretendoNetwork/nex-protocols-common-go.git
synced 2025-04-02 11:02:13 -04:00
Implement methods that are needed for Mario Kart 7 communities to work. Note that support for communities on MK7 is partial since the community statistics don't load because legacy Ranking isn't implemented. Aside from that, players can create communities and join others without issues. Other games which use persistent gatherings may or may not work. In order to support the `ParticipationCount`, we replace matchmake session joins with a wrapper which checks if the session is attached to a community, and if it is, it will increment the participation count of the player in a new table named `community_participations`. The `MatchmakeSessionCount` is handled more easily by checking the sessions that belong to the corresponding community. A new parameter is also added named `PersistentGatheringCreationMax` with a default value of 4, as reported and tested on various games. This allows game servers to change the maximum number of active persistent gatherings that a player can create. For example, Mario Kart 7 supports up to 8 persistent gatherings instead of the default of 4. In Mario Kart 7 there is no limitation on the number of players that can "join" to a community. That is because they don't really join to it but they create matchmake sessions linked to the persistent gathering (in fact, the `MaximumParticipants` parameter on persistent gatherings is set to 0). Thus, the `participants` parameter is unused in communities (at least on MK7) and we instead log community participations with a new tracking table `tracking.participate_community`. Some changes also had to be done in other places like participant disconnection handling or gathering registrations in order to implement persistent gatherings accurately.
55 lines
2 KiB
Go
55 lines
2 KiB
Go
package matchmake_extension
|
|
|
|
import (
|
|
"github.com/PretendoNetwork/nex-go/v2"
|
|
"github.com/PretendoNetwork/nex-go/v2/types"
|
|
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
|
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
|
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
|
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
|
)
|
|
|
|
func (commonProtocol *CommonProtocol) getSimpleCommunity(err error, packet nex.PacketInterface, callID uint32, gatheringIDList types.List[types.UInt32]) (*nex.RMCMessage, *nex.Error) {
|
|
if err != nil {
|
|
common_globals.Logger.Error(err.Error())
|
|
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
|
}
|
|
|
|
connection := packet.Sender().(*nex.PRUDPConnection)
|
|
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
|
|
|
var gatheringIDs []uint32
|
|
for _, gatheringID := range gatheringIDList {
|
|
gatheringIDs = append(gatheringIDs, uint32(gatheringID))
|
|
}
|
|
|
|
commonProtocol.manager.Mutex.RLock()
|
|
|
|
simpleCommunities, nexError := database.GetSimpleCommunities(commonProtocol.manager, gatheringIDs)
|
|
if nexError != nil {
|
|
commonProtocol.manager.Mutex.RUnlock()
|
|
return nil, nexError
|
|
}
|
|
|
|
commonProtocol.manager.Mutex.RUnlock()
|
|
|
|
lstSimpleCommunityList := types.NewList[match_making_types.SimpleCommunity]()
|
|
lstSimpleCommunityList = simpleCommunities
|
|
|
|
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
|
|
|
lstSimpleCommunityList.WriteTo(rmcResponseStream)
|
|
|
|
rmcResponseBody := rmcResponseStream.Bytes()
|
|
|
|
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
|
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
|
rmcResponse.MethodID = matchmake_extension.MethodGetSimpleCommunity
|
|
rmcResponse.CallID = callID
|
|
|
|
if commonProtocol.OnAfterGetSimpleCommunity != nil {
|
|
go commonProtocol.OnAfterGetSimpleCommunity(packet, gatheringIDList)
|
|
}
|
|
|
|
return rmcResponse, nil
|
|
}
|