Skip to content

Commit

Permalink
Added MatchmakeExtension::CreateMatchmakeSessionWithParam
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow committed Apr 8, 2023
1 parent e36462c commit f1b0510
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
34 changes: 34 additions & 0 deletions match-making/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,37 @@ func (matchmakeParam *MatchmakeParam) ExtractFromStream(stream *nex.StreamIn) er
func NewMatchmakeParam() *MatchmakeParam {
return &MatchmakeParam{}
}

// MatchmakeParam holds parameters for a matchmake session
type CreateMatchmakeSessionParam struct {
SourceMatchmakeSession *MatchmakeSession
AdditionalParticipants []uint32
GIDForParticipationCheck uint32
CreateMatchmakeSessionOption uint32
JoinMessage string
ParticipationCount uint16

*nex.Structure
}

// ExtractFromStream extracts a CreateMatchmakeSessionParam structure from a stream
func (createMatchmakeSessionParam *CreateMatchmakeSessionParam) ExtractFromStream(stream *nex.StreamIn) error {
sourceMatchmakeSession, err := stream.ReadStructure(NewMatchmakeSession())
if err != nil {
return err
}

createMatchmakeSessionParam.SourceMatchmakeSession = sourceMatchmakeSession.(*MatchmakeSession)
createMatchmakeSessionParam.AdditionalParticipants = stream.ReadListUInt32LE()
createMatchmakeSessionParam.GIDForParticipationCheck = stream.ReadUInt32LE()
createMatchmakeSessionParam.CreateMatchmakeSessionOption = stream.ReadUInt32LE()
createMatchmakeSessionParam.JoinMessage, _ = stream.ReadString()
createMatchmakeSessionParam.ParticipationCount = stream.ReadUInt16LE()

return nil
}

// NewCreateMatchmakeSessionParam returns a new CreateMatchmakeSessionParam
func NewCreateMatchmakeSessionParam() *CreateMatchmakeSessionParam {
return &CreateMatchmakeSessionParam{}
}
36 changes: 36 additions & 0 deletions matchmake-extension/create_matchmake_session_with_param.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package matchmake_extension

import (
nex "github.com/PretendoNetwork/nex-go"
"github.com/PretendoNetwork/nex-protocols-go/globals"
match_making "github.com/PretendoNetwork/nex-protocols-go/match-making"
)

// CreateMatchmakeSessionWithParam sets the CreateMatchmakeSessionWithParam handler function
func (protocol *MatchmakeExtensionProtocol) CreateMatchmakeSessionWithParam(handler func(err error, client *nex.Client, callID uint32, createMatchmakeSessionParam *match_making.CreateMatchmakeSessionParam)) {
protocol.CreateMatchmakeSessionWithParamHandler = handler
}

func (protocol *MatchmakeExtensionProtocol) HandleCreateMatchmakeSessionWithParam(packet nex.PacketInterface) {
if protocol.CreateMatchmakeSessionWithParamHandler == nil {
globals.Logger.Warning("MatchmakeExtension::CreateMatchmakeSessionWithParam not implemented")
go globals.RespondNotImplemented(packet, ProtocolID)
return
}

client := packet.Sender()
request := packet.RMCRequest()

callID := request.CallID()
parameters := request.Parameters()

parametersStream := nex.NewStreamIn(parameters, protocol.Server)

createMatchmakeSessionParam, err := parametersStream.ReadStructure(match_making.NewCreateMatchmakeSessionParam())
if err != nil {
go protocol.CreateMatchmakeSessionWithParamHandler(err, client, callID, nil)
return
}

go protocol.CreateMatchmakeSessionWithParamHandler(nil, client, callID, createMatchmakeSessionParam.(*match_making.CreateMatchmakeSessionParam))
}
3 changes: 3 additions & 0 deletions matchmake-extension/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type MatchmakeExtensionProtocol struct {
JoinMatchmakeSessionExHandler func(err error, client *nex.Client, callID uint32, gid uint32, strMessage string, dontCareMyBlockList bool, participationCount uint16)
GetSimplePlayingSessionHandler func(err error, client *nex.Client, callID uint32, listPID []uint32, includeLoginUser bool)
UpdateProgressScoreHandler func(err error, client *nex.Client, callID uint32, GID uint32, progressScore uint8)
CreateMatchmakeSessionWithParamHandler func(err error, client *nex.Client, callID uint32, createMatchmakeSessionParam *match_making.CreateMatchmakeSessionParam)
}

// Setup initializes the protocol
Expand Down Expand Up @@ -108,6 +109,8 @@ func (protocol *MatchmakeExtensionProtocol) HandlePacket(packet nex.PacketInterf
go protocol.HandleGetSimplePlayingSession(packet)
case MethodUpdateProgressScore:
go protocol.HandleUpdateProgressScore(packet)
case MethodCreateMatchmakeSessionWithParam:
go protocol.HandleCreateMatchmakeSessionWithParam(packet)
default:
go globals.RespondNotImplemented(packet, ProtocolID)
fmt.Printf("Unsupported Matchmake Extension method ID: %#v\n", request.MethodID())
Expand Down

0 comments on commit f1b0510

Please sign in to comment.