Skip to content

Commit

Permalink
refactor: Replace AnyDataHolder with AnyObjectHolder
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniElectra committed Jan 9, 2025
1 parent d7f8b58 commit 21fdc47
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 34 deletions.
9 changes: 4 additions & 5 deletions match-making/find_by_single_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/PretendoNetwork/nex-go/v2/types"
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making"
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
)

func (commonProtocol *CommonProtocol) findBySingleID(err error, packet nex.PacketInterface, callID uint32, id types.UInt32) (*nex.RMCMessage, *nex.Error) {
Expand All @@ -18,7 +19,7 @@ func (commonProtocol *CommonProtocol) findBySingleID(err error, packet nex.Packe

commonProtocol.manager.Mutex.RLock()

gathering, gatheringType, nexError := commonProtocol.manager.GetDetailedGatheringByID(commonProtocol.manager, uint32(id))
gathering, _, nexError := commonProtocol.manager.GetDetailedGatheringByID(commonProtocol.manager, uint32(id))
if nexError != nil {
commonProtocol.manager.Mutex.RUnlock()
return nil, nexError
Expand All @@ -27,10 +28,8 @@ func (commonProtocol *CommonProtocol) findBySingleID(err error, packet nex.Packe
commonProtocol.manager.Mutex.RUnlock()

bResult := types.NewBool(true)
pGathering := types.NewAnyDataHolder()

pGathering.TypeName = types.NewString(gatheringType)
pGathering.ObjectData = gathering.Copy()
pGathering := match_making_types.NewGatheringHolder()
pGathering.Object = gathering.Copy().(match_making_types.GatheringInterface)

rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())

Expand Down
13 changes: 5 additions & 8 deletions matchmake-extension/auto_matchmake_postpone.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
database "github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
)

func (commonProtocol *CommonProtocol) autoMatchmakePostpone(err error, packet nex.PacketInterface, callID uint32, anyGathering types.AnyDataHolder, message types.String) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) autoMatchmakePostpone(err error, packet nex.PacketInterface, callID uint32, anyGathering match_making_types.GatheringHolder, message types.String) (*nex.RMCMessage, *nex.Error) {
if commonProtocol.CleanupSearchMatchmakeSession == nil {
common_globals.Logger.Warning("MatchmakeExtension::AutoMatchmake_Postpone missing CleanupSearchMatchmakeSession!")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
Expand All @@ -35,10 +35,9 @@ func (commonProtocol *CommonProtocol) autoMatchmakePostpone(err error, packet ne
database.EndMatchmakeSessionsParticipation(commonProtocol.manager, connection)

var matchmakeSession match_making_types.MatchmakeSession
anyGatheringDataType := anyGathering.TypeName

if anyGatheringDataType == "MatchmakeSession" {
matchmakeSession = anyGathering.ObjectData.(match_making_types.MatchmakeSession)
if anyGathering.Object.ObjectID().Equals(types.NewString("MatchmakeSession")) {
matchmakeSession = anyGathering.Object.(match_making_types.MatchmakeSession)
} else {
common_globals.Logger.Critical("Non-MatchmakeSession DataType?!")
commonProtocol.manager.Mutex.Unlock()
Expand Down Expand Up @@ -79,10 +78,8 @@ func (commonProtocol *CommonProtocol) autoMatchmakePostpone(err error, packet ne

commonProtocol.manager.Mutex.Unlock()

matchmakeDataHolder := types.NewAnyDataHolder()

matchmakeDataHolder.TypeName = types.NewString("MatchmakeSession")
matchmakeDataHolder.ObjectData = resultSession.Copy()
matchmakeDataHolder := match_making_types.NewGatheringHolder()
matchmakeDataHolder.Object = resultSession.Copy().(match_making_types.GatheringInterface)

rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
)

func (commonProtocol *CommonProtocol) autoMatchmakeWithSearchCriteriaPostpone(err error, packet nex.PacketInterface, callID uint32, lstSearchCriteria types.List[match_making_types.MatchmakeSessionSearchCriteria], anyGathering types.AnyDataHolder, strMessage types.String) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) autoMatchmakeWithSearchCriteriaPostpone(err error, packet nex.PacketInterface, callID uint32, lstSearchCriteria types.List[match_making_types.MatchmakeSessionSearchCriteria], anyGathering match_making_types.GatheringHolder, strMessage types.String) (*nex.RMCMessage, *nex.Error) {
if commonProtocol.CleanupMatchmakeSessionSearchCriterias == nil {
common_globals.Logger.Warning("MatchmakeExtension::AutoMatchmakeWithSearchCriteria_Postpone missing CleanupMatchmakeSessionSearchCriterias!")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
Expand Down Expand Up @@ -40,8 +40,8 @@ func (commonProtocol *CommonProtocol) autoMatchmakeWithSearchCriteriaPostpone(er

var matchmakeSession match_making_types.MatchmakeSession

if anyGathering.TypeName == "MatchmakeSession" {
matchmakeSession = anyGathering.ObjectData.(match_making_types.MatchmakeSession)
if anyGathering.Object.GatheringObjectID().Equals(types.NewString("MatchmakeSession")) {
matchmakeSession = anyGathering.Object.(match_making_types.MatchmakeSession)
} else {
common_globals.Logger.Critical("Non-MatchmakeSession DataType?!")
commonProtocol.manager.Mutex.Unlock()
Expand Down Expand Up @@ -97,10 +97,8 @@ func (commonProtocol *CommonProtocol) autoMatchmakeWithSearchCriteriaPostpone(er

commonProtocol.manager.Mutex.Unlock()

matchmakeDataHolder := types.NewAnyDataHolder()

matchmakeDataHolder.TypeName = types.NewString("MatchmakeSession")
matchmakeDataHolder.ObjectData = resultSession.Copy()
matchmakeDataHolder := match_making_types.NewGatheringHolder()
matchmakeDataHolder.Object = resultSession.Copy().(match_making_types.GatheringInterface)

rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())

Expand Down
7 changes: 3 additions & 4 deletions matchmake-extension/browse_matchmake_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ func (commonProtocol *CommonProtocol) browseMatchmakeSession(err error, packet n
return nil, nexError
}

lstGathering := types.NewList[types.AnyDataHolder]()
lstGathering := types.NewList[match_making_types.GatheringHolder]()

for _, session := range sessions {
// * Scrap session key and user password
session.SessionKey = make([]byte, 0)
session.UserPassword = ""

matchmakeSessionDataHolder := types.NewAnyDataHolder()
matchmakeSessionDataHolder.TypeName = types.NewString("MatchmakeSession")
matchmakeSessionDataHolder.ObjectData = session.Copy()
matchmakeSessionDataHolder := match_making_types.NewGatheringHolder()
matchmakeSessionDataHolder.Object = session.Copy().(match_making_types.GatheringInterface)

lstGathering = append(lstGathering, matchmakeSessionDataHolder)
}
Expand Down
6 changes: 3 additions & 3 deletions matchmake-extension/create_matchmake_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
)

func (commonProtocol *CommonProtocol) createMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, anyGathering types.AnyDataHolder, message types.String, participationCount types.UInt16) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) createMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, anyGathering match_making_types.GatheringHolder, message types.String, participationCount types.UInt16) (*nex.RMCMessage, *nex.Error) {
if err != nil {
common_globals.Logger.Error(err.Error())
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
Expand All @@ -32,8 +32,8 @@ func (commonProtocol *CommonProtocol) createMatchmakeSession(err error, packet n

var matchmakeSession match_making_types.MatchmakeSession

if anyGathering.TypeName == "MatchmakeSession" {
matchmakeSession = anyGathering.ObjectData.(match_making_types.MatchmakeSession)
if anyGathering.Object.GatheringObjectID().Equals(types.NewString("MatchmakeSession")) {
matchmakeSession = anyGathering.Object.(match_making_types.MatchmakeSession)
} else {
common_globals.Logger.Critical("Non-MatchmakeSession DataType?!")
commonProtocol.manager.Mutex.Unlock()
Expand Down
6 changes: 3 additions & 3 deletions matchmake-extension/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ type CommonProtocol struct {
CleanupMatchmakeSessionSearchCriterias func(searchCriterias types.List[match_making_types.MatchmakeSessionSearchCriteria])
OnAfterOpenParticipation func(packet nex.PacketInterface, gid types.UInt32)
OnAfterCloseParticipation func(packet nex.PacketInterface, gid types.UInt32)
OnAfterCreateMatchmakeSession func(packet nex.PacketInterface, anyGathering types.AnyDataHolder, message types.String, participationCount types.UInt16)
OnAfterCreateMatchmakeSession func(packet nex.PacketInterface, anyGathering match_making_types.GatheringHolder, message types.String, participationCount types.UInt16)
OnAfterGetSimplePlayingSession func(packet nex.PacketInterface, listPID types.List[types.PID], includeLoginUser types.Bool)
OnAfterAutoMatchmakePostpone func(packet nex.PacketInterface, anyGathering types.AnyDataHolder, message types.String)
OnAfterAutoMatchmakePostpone func(packet nex.PacketInterface, anyGathering match_making_types.GatheringHolder, message types.String)
OnAfterAutoMatchmakeWithParamPostpone func(packet nex.PacketInterface, autoMatchmakeParam match_making_types.AutoMatchmakeParam)
OnAfterAutoMatchmakeWithSearchCriteriaPostpone func(packet nex.PacketInterface, lstSearchCriteria types.List[match_making_types.MatchmakeSessionSearchCriteria], anyGathering types.AnyDataHolder, strMessage types.String)
OnAfterAutoMatchmakeWithSearchCriteriaPostpone func(packet nex.PacketInterface, lstSearchCriteria types.List[match_making_types.MatchmakeSessionSearchCriteria], anyGathering match_making_types.GatheringHolder, strMessage types.String)
OnAfterUpdateProgressScore func(packet nex.PacketInterface, gid types.UInt32, progressScore types.UInt8)
OnAfterCreateMatchmakeSessionWithParam func(packet nex.PacketInterface, createMatchmakeSessionParam match_making_types.CreateMatchmakeSessionParam)
OnAfterUpdateApplicationBuffer func(packet nex.PacketInterface, gid types.UInt32, applicationBuffer types.Buffer)
Expand Down
2 changes: 1 addition & 1 deletion secure-connection/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type CommonProtocol struct {
CreateReportDBRecord func(pid types.PID, reportID types.UInt32, reportData types.QBuffer) error
OnAfterRegister func(packet nex.PacketInterface, vecMyURLs types.List[types.StationURL])
OnAfterRequestURLs func(packet nex.PacketInterface, cidTarget types.UInt32, pidTarget types.PID)
OnAfterRegisterEx func(packet nex.PacketInterface, vecMyURLs types.List[types.StationURL], hCustomData types.AnyDataHolder)
OnAfterRegisterEx func(packet nex.PacketInterface, vecMyURLs types.List[types.StationURL], hCustomData types.DataHolder)
OnAfterReplaceURL func(packet nex.PacketInterface, target types.StationURL, url types.StationURL)
OnAfterSendReport func(packet nex.PacketInterface, reportID types.UInt32, reportData types.QBuffer)
}
Expand Down
2 changes: 1 addition & 1 deletion secure-connection/register_ex.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
)

func (commonProtocol *CommonProtocol) registerEx(err error, packet nex.PacketInterface, callID uint32, vecMyURLs types.List[types.StationURL], hCustomData types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) registerEx(err error, packet nex.PacketInterface, callID uint32, vecMyURLs types.List[types.StationURL], hCustomData types.DataHolder) (*nex.RMCMessage, *nex.Error) {
if err != nil {
common_globals.Logger.Error(err.Error())
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
Expand Down
2 changes: 1 addition & 1 deletion ticket-granting/login_ex.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
ticket_granting "github.com/PretendoNetwork/nex-protocols-go/v2/ticket-granting"
)

func (commonProtocol *CommonProtocol) loginEx(err error, packet nex.PacketInterface, callID uint32, strUserName types.String, oExtraData types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) loginEx(err error, packet nex.PacketInterface, callID uint32, strUserName types.String, oExtraData types.DataHolder) (*nex.RMCMessage, *nex.Error) {
if err != nil {
common_globals.Logger.Error(err.Error())
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
Expand Down
2 changes: 1 addition & 1 deletion ticket-granting/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type CommonProtocol struct {
SessionKeyLength int // TODO - Use server SessionKeyLength?
SecureServerAccount *nex.Account
OnAfterLogin func(packet nex.PacketInterface, strUserName types.String)
OnAfterLoginEx func(packet nex.PacketInterface, strUserName types.String, oExtraData types.AnyDataHolder)
OnAfterLoginEx func(packet nex.PacketInterface, strUserName types.String, oExtraData types.DataHolder)
OnAfterRequestTicket func(packet nex.PacketInterface, idSource types.PID, idTarget types.PID)
}

Expand Down

0 comments on commit 21fdc47

Please sign in to comment.