diff --git a/matchmake-extension/protocol.go b/matchmake-extension/protocol.go index 610f2ad..2307e71 100644 --- a/matchmake-extension/protocol.go +++ b/matchmake-extension/protocol.go @@ -37,6 +37,7 @@ func initDefault(c *CommonMatchmakeExtensionProtocol) { c.DefaultProtocol.GetSimplePlayingSession(getSimplePlayingSession) c.DefaultProtocol.AutoMatchmakePostpone(autoMatchmake_Postpone) c.DefaultProtocol.AutoMatchmakeWithSearchCriteriaPostpone(autoMatchmakeWithSearchCriteria_Postpone) + c.DefaultProtocol.UpdateProgressScore(updateProgressScore) } func initMarioKart8(c *CommonMatchmakeExtensionProtocol) { @@ -46,6 +47,7 @@ func initMarioKart8(c *CommonMatchmakeExtensionProtocol) { c.MarioKart8Protocol.GetSimplePlayingSession(getSimplePlayingSession) c.MarioKart8Protocol.AutoMatchmakePostpone(autoMatchmake_Postpone) c.MarioKart8Protocol.AutoMatchmakeWithSearchCriteriaPostpone(autoMatchmakeWithSearchCriteria_Postpone) + c.MarioKart8Protocol.UpdateProgressScore(updateProgressScore) } // NewCommonMatchmakeExtensionProtocol returns a new CommonMatchmakeExtensionProtocol diff --git a/matchmake-extension/update_progress_score.go b/matchmake-extension/update_progress_score.go new file mode 100644 index 0000000..7575813 --- /dev/null +++ b/matchmake-extension/update_progress_score.go @@ -0,0 +1,58 @@ +package matchmake_extension + +import ( + nex "github.com/PretendoNetwork/nex-go" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/matchmake-extension" +) + +func updateProgressScore(err error, client *nex.Client, callID uint32, gid uint32, progressScore uint8) uint32 { + if err != nil { + logger.Error(err.Error()) + return nex.Errors.Core.InvalidArgument + } + + session := common_globals.Sessions[gid] + if session == nil { + return nex.Errors.RendezVous.SessionVoid + } + + if progressScore > 100 { + return nex.Errors.Core.InvalidArgument + } + + if session.GameMatchmakeSession.Gathering.OwnerPID != client.PID() { + return nex.Errors.RendezVous.PermissionDenied + } + + session.GameMatchmakeSession.ProgressScore += progressScore + + server := commonMatchmakeExtensionProtocol.server + + rmcResponse := nex.NewRMCResponse(matchmake_extension.ProtocolID, callID) + rmcResponse.SetSuccess(matchmake_extension.MethodUpdateProgressScore, nil) + + rmcResponseBytes := rmcResponse.Bytes() + + var responsePacket nex.PacketInterface + + if server.PRUDPVersion() == 0 { + responsePacket, _ = nex.NewPacketV0(client, nil) + responsePacket.SetVersion(0) + } else { + responsePacket, _ = nex.NewPacketV1(client, nil) + responsePacket.SetVersion(1) + } + + responsePacket.SetSource(0xA1) + responsePacket.SetDestination(0xAF) + responsePacket.SetType(nex.DataPacket) + responsePacket.SetPayload(rmcResponseBytes) + + responsePacket.AddFlag(nex.FlagNeedsAck) + responsePacket.AddFlag(nex.FlagReliable) + + server.Send(responsePacket) + + return 0 +}