From a20b87320110778425981561614dc26d18d83382 Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Sat, 8 Apr 2023 19:29:57 -0400 Subject: [PATCH] Added MatchmakeExtension::JoinMatchmakeSessionWithParam --- match-making/types.go | 68 ++++++++++++++++++- .../join_matchmake_session_with_param.go | 36 ++++++++++ matchmake-extension/protocol.go | 3 + 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 matchmake-extension/join_matchmake_session_with_param.go diff --git a/match-making/types.go b/match-making/types.go index 44752c84..534a316f 100644 --- a/match-making/types.go +++ b/match-making/types.go @@ -329,7 +329,7 @@ func NewMatchmakeParam() *MatchmakeParam { return &MatchmakeParam{} } -// MatchmakeParam holds parameters for a matchmake session +// CreateMatchmakeSessionParam holds parameters for a matchmake session type CreateMatchmakeSessionParam struct { SourceMatchmakeSession *MatchmakeSession AdditionalParticipants []uint32 @@ -362,3 +362,69 @@ func (createMatchmakeSessionParam *CreateMatchmakeSessionParam) ExtractFromStrea func NewCreateMatchmakeSessionParam() *CreateMatchmakeSessionParam { return &CreateMatchmakeSessionParam{} } + +// JoinMatchmakeSessionParam holds parameters for a matchmake session +type JoinMatchmakeSessionParam struct { + GID uint32 + AdditionalParticipants []uint32 + GIDForParticipationCheck uint32 + JoinMatchmakeSessionOption uint32 + JoinMatchmakeSessionBehavior uint8 + StrUserPassword string + StrSystemPassword string + JoinMessage string + ParticipationCount uint16 + ExtraParticipants uint16 + BlockListParam *MatchmakeBlockListParam + + *nex.Structure +} + +// ExtractFromStream extracts a JoinMatchmakeSessionParam structure from a stream +func (joinMatchmakeSessionParam *JoinMatchmakeSessionParam) ExtractFromStream(stream *nex.StreamIn) error { + // TODO - Check errors + + joinMatchmakeSessionParam.GID = stream.ReadUInt32LE() + joinMatchmakeSessionParam.AdditionalParticipants = stream.ReadListUInt32LE() + joinMatchmakeSessionParam.GIDForParticipationCheck = stream.ReadUInt32LE() + joinMatchmakeSessionParam.JoinMatchmakeSessionOption = stream.ReadUInt32LE() + joinMatchmakeSessionParam.JoinMatchmakeSessionBehavior = stream.ReadUInt8() + joinMatchmakeSessionParam.StrUserPassword, _ = stream.ReadString() + joinMatchmakeSessionParam.StrSystemPassword, _ = stream.ReadString() + joinMatchmakeSessionParam.JoinMessage, _ = stream.ReadString() + joinMatchmakeSessionParam.ParticipationCount = stream.ReadUInt16LE() + joinMatchmakeSessionParam.ExtraParticipants = stream.ReadUInt16LE() + + blockListParam, err := stream.ReadStructure(NewMatchmakeBlockListParam()) + if err != nil { + return err + } + + joinMatchmakeSessionParam.BlockListParam = blockListParam.(*MatchmakeBlockListParam) + + return nil +} + +// NewJoinMatchmakeSessionParam returns a new JoinMatchmakeSessionParam +func NewJoinMatchmakeSessionParam() *JoinMatchmakeSessionParam { + return &JoinMatchmakeSessionParam{} +} + +// MatchmakeBlockListParam holds parameters for a matchmake session +type MatchmakeBlockListParam struct { + OptionFlag uint32 + + *nex.Structure +} + +// ExtractFromStream extracts a MatchmakeBlockListParam structure from a stream +func (matchmakeBlockListParam *MatchmakeBlockListParam) ExtractFromStream(stream *nex.StreamIn) error { + matchmakeBlockListParam.OptionFlag = stream.ReadUInt32LE() + + return nil +} + +// NewMatchmakeBlockListParam returns a new MatchmakeBlockListParam +func NewMatchmakeBlockListParam() *MatchmakeBlockListParam { + return &MatchmakeBlockListParam{} +} diff --git a/matchmake-extension/join_matchmake_session_with_param.go b/matchmake-extension/join_matchmake_session_with_param.go new file mode 100644 index 00000000..d972ff16 --- /dev/null +++ b/matchmake-extension/join_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" +) + +// JoinMatchmakeSessionWithParam sets the JoinMatchmakeSessionWithParam handler function +func (protocol *MatchmakeExtensionProtocol) JoinMatchmakeSessionWithParam(handler func(err error, client *nex.Client, callID uint32, joinMatchmakeSessionParam *match_making.JoinMatchmakeSessionParam)) { + protocol.JoinMatchmakeSessionWithParamHandler = handler +} + +func (protocol *MatchmakeExtensionProtocol) HandleJoinMatchmakeSessionWithParam(packet nex.PacketInterface) { + if protocol.JoinMatchmakeSessionWithParamHandler == nil { + globals.Logger.Warning("MatchmakeExtension::JoinMatchmakeSessionWithParam 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) + + joinMatchmakeSessionParam, err := parametersStream.ReadStructure(match_making.NewJoinMatchmakeSessionParam()) + if err != nil { + go protocol.JoinMatchmakeSessionWithParamHandler(err, client, callID, nil) + return + } + + go protocol.JoinMatchmakeSessionWithParamHandler(nil, client, callID, joinMatchmakeSessionParam.(*match_making.JoinMatchmakeSessionParam)) +} diff --git a/matchmake-extension/protocol.go b/matchmake-extension/protocol.go index 953ad253..af2255b1 100644 --- a/matchmake-extension/protocol.go +++ b/matchmake-extension/protocol.go @@ -70,6 +70,7 @@ type MatchmakeExtensionProtocol struct { 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) + JoinMatchmakeSessionWithParamHandler func(err error, client *nex.Client, callID uint32, joinMatchmakeSessionParam *match_making.JoinMatchmakeSessionParam) } // Setup initializes the protocol @@ -111,6 +112,8 @@ func (protocol *MatchmakeExtensionProtocol) HandlePacket(packet nex.PacketInterf go protocol.HandleUpdateProgressScore(packet) case MethodCreateMatchmakeSessionWithParam: go protocol.HandleCreateMatchmakeSessionWithParam(packet) + case MethodJoinMatchmakeSessionWithParam: + go protocol.HandleJoinMatchmakeSessionWithParam(packet) default: go globals.RespondNotImplemented(packet, ProtocolID) fmt.Printf("Unsupported Matchmake Extension method ID: %#v\n", request.MethodID())