Skip to content

Commit

Permalink
Added MatchmakeExtension::AutoMatchmakeWithParam_Postpone
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow committed Apr 9, 2023
1 parent a20b873 commit c16608e
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
44 changes: 44 additions & 0 deletions match-making/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,47 @@ func (matchmakeBlockListParam *MatchmakeBlockListParam) ExtractFromStream(stream
func NewMatchmakeBlockListParam() *MatchmakeBlockListParam {
return &MatchmakeBlockListParam{}
}

// AutoMatchmakeParam holds parameters for a matchmake session
type AutoMatchmakeParam struct {
SourceMatchmakeSession *MatchmakeSession
AdditionalParticipants []uint32
GIDForParticipationCheck uint32
AutoMatchmakeOption uint32
JoinMessage string
ParticipationCount uint16
LstSearchCriteria []*MatchmakeSessionSearchCriteria
TargetGIDs []uint32

*nex.Structure
}

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

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

lstSearchCriteria, err := stream.ReadListStructure(NewMatchmakeSessionSearchCriteria())
if err != nil {
return err
}

autoMatchmakeParam.LstSearchCriteria = lstSearchCriteria.([]*MatchmakeSessionSearchCriteria)
autoMatchmakeParam.TargetGIDs = stream.ReadListUInt32LE()

return nil
}

// NewAutoMatchmakeParam returns a new AutoMatchmakeParam
func NewAutoMatchmakeParam() *AutoMatchmakeParam {
return &AutoMatchmakeParam{}
}
36 changes: 36 additions & 0 deletions matchmake-extension/auto_matchmake_with_param_postpone.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"
)

// AutoMatchmakeWithParam_Postpone sets the AutoMatchmakeWithParam_Postpone handler function
func (protocol *MatchmakeExtensionProtocol) AutoMatchmakeWithParam_Postpone(handler func(err error, client *nex.Client, callID uint32, autoMatchmakeParam *match_making.AutoMatchmakeParam)) {
protocol.AutoMatchmakeWithParam_PostponeHandler = handler
}

func (protocol *MatchmakeExtensionProtocol) HandleAutoMatchmakeWithParam_Postpone(packet nex.PacketInterface) {
if protocol.AutoMatchmakeWithParam_PostponeHandler == nil {
globals.Logger.Warning("MatchmakeExtension::AutoMatchmakeWithParam_Postpone 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)

autoMatchmakeParam, err := parametersStream.ReadStructure(match_making.NewAutoMatchmakeParam())
if err != nil {
go protocol.AutoMatchmakeWithParam_PostponeHandler(err, client, callID, nil)
return
}

go protocol.AutoMatchmakeWithParam_PostponeHandler(nil, client, callID, autoMatchmakeParam.(*match_making.AutoMatchmakeParam))
}
3 changes: 3 additions & 0 deletions matchmake-extension/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type MatchmakeExtensionProtocol struct {
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)
AutoMatchmakeWithParam_PostponeHandler func(err error, client *nex.Client, callID uint32, autoMatchmakeParam *match_making.AutoMatchmakeParam)
}

// Setup initializes the protocol
Expand Down Expand Up @@ -114,6 +115,8 @@ func (protocol *MatchmakeExtensionProtocol) HandlePacket(packet nex.PacketInterf
go protocol.HandleCreateMatchmakeSessionWithParam(packet)
case MethodJoinMatchmakeSessionWithParam:
go protocol.HandleJoinMatchmakeSessionWithParam(packet)
case MethodAutoMatchmakeWithParam_Postpone:
go protocol.HandleAutoMatchmakeWithParam_Postpone(packet)
default:
go globals.RespondNotImplemented(packet, ProtocolID)
fmt.Printf("Unsupported Matchmake Extension method ID: %#v\n", request.MethodID())
Expand Down

0 comments on commit c16608e

Please sign in to comment.