From f1b0510ac8c96bcc38c1e9eaa9257cfcece117be Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Sat, 8 Apr 2023 19:11:46 -0400 Subject: [PATCH] Added MatchmakeExtension::CreateMatchmakeSessionWithParam --- match-making/types.go | 34 ++++++++++++++++++ .../create_matchmake_session_with_param.go | 36 +++++++++++++++++++ matchmake-extension/protocol.go | 3 ++ 3 files changed, 73 insertions(+) create mode 100644 matchmake-extension/create_matchmake_session_with_param.go diff --git a/match-making/types.go b/match-making/types.go index 271d140a..44752c84 100644 --- a/match-making/types.go +++ b/match-making/types.go @@ -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{} +} diff --git a/matchmake-extension/create_matchmake_session_with_param.go b/matchmake-extension/create_matchmake_session_with_param.go new file mode 100644 index 00000000..d57af257 --- /dev/null +++ b/matchmake-extension/create_matchmake_session_with_param.go @@ -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)) +} diff --git a/matchmake-extension/protocol.go b/matchmake-extension/protocol.go index c16bd1f5..953ad253 100644 --- a/matchmake-extension/protocol.go +++ b/matchmake-extension/protocol.go @@ -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 @@ -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())