Skip to content

Commit

Permalink
Added UpdateProgressScore
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow committed Aug 15, 2023
1 parent 1ff762d commit ef24684
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions matchmake-extension/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
58 changes: 58 additions & 0 deletions matchmake-extension/update_progress_score.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit ef24684

Please sign in to comment.