Skip to content

Commit

Permalink
Added MatchmakeExtension::JoinMatchmakeSessionWithParam
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow committed Apr 8, 2023
1 parent f1b0510 commit a20b873
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
68 changes: 67 additions & 1 deletion match-making/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{}
}
36 changes: 36 additions & 0 deletions matchmake-extension/join_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"
)

// 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))
}
3 changes: 3 additions & 0 deletions matchmake-extension/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit a20b873

Please sign in to comment.