diff --git a/datastore/change_meta.go b/datastore/change_meta.go index 002e65d..46eed38 100644 --- a/datastore/change_meta.go +++ b/datastore/change_meta.go @@ -7,7 +7,7 @@ import ( datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" ) -func (commonProtocol *CommonProtocol) changeMeta(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreChangeMetaParam) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) changeMeta(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreChangeMetaParam) (*nex.RMCMessage, *nex.Error) { if commonProtocol.GetObjectInfoByDataID == nil { common_globals.Logger.Warning("GetObjectInfoByDataID not defined") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -47,21 +47,21 @@ func (commonProtocol *CommonProtocol) changeMeta(err error, packet nex.PacketInt return nil, errCode } - if param.ModifiesFlag.PAND(0x08) != 0 { + if uint32(param.ModifiesFlag) & 0x08 != 0 { errCode = commonProtocol.UpdateObjectPeriodByDataIDWithPassword(param.DataID, param.Period, param.UpdatePassword) if errCode != nil { return nil, errCode } } - if param.ModifiesFlag.PAND(0x10) != 0 { + if uint32(param.ModifiesFlag) & 0x10 != 0 { errCode = commonProtocol.UpdateObjectMetaBinaryByDataIDWithPassword(param.DataID, param.MetaBinary, param.UpdatePassword) if errCode != nil { return nil, errCode } } - if param.ModifiesFlag.PAND(0x80) != 0 { + if uint32(param.ModifiesFlag) & 0x80 != 0 { errCode = commonProtocol.UpdateObjectDataTypeByDataIDWithPassword(param.DataID, param.DataType, param.UpdatePassword) if errCode != nil { return nil, errCode diff --git a/datastore/complete_post_object.go b/datastore/complete_post_object.go index 0c0bfe6..e0d1e6c 100644 --- a/datastore/complete_post_object.go +++ b/datastore/complete_post_object.go @@ -9,7 +9,7 @@ import ( datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" ) -func (commonProtocol *CommonProtocol) completePostObject(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParam) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) completePostObject(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreCompletePostParam) (*nex.RMCMessage, *nex.Error) { if commonProtocol.minIOClient == nil { common_globals.Logger.Warning("MinIOClient not defined") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -51,8 +51,8 @@ func (commonProtocol *CommonProtocol) completePostObject(err error, packet nex.P // * If GetObjectInfoByDataID returns data then that means // * the object has already been marked as uploaded. So do // * nothing - objectInfo, _ := commonProtocol.GetObjectInfoByDataID(param.DataID) - if objectInfo != nil { + _, errCode := commonProtocol.GetObjectInfoByDataID(param.DataID) + if errCode == nil { return nil, nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error") } @@ -62,14 +62,14 @@ func (commonProtocol *CommonProtocol) completePostObject(err error, packet nex.P return nil, errCode } - if ownerPID != connection.PID().LegacyValue() { + if ownerPID != uint32(connection.PID()) { return nil, nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error") } bucket := commonProtocol.S3Bucket key := fmt.Sprintf("%s/%d.bin", commonProtocol.s3DataKeyBase, param.DataID) - if param.IsSuccess.Value { + if param.IsSuccess { objectSizeS3, err := commonProtocol.S3ObjectSize(bucket, key) if err != nil { common_globals.Logger.Error(err.Error()) diff --git a/datastore/complete_post_objects.go b/datastore/complete_post_objects.go index e1b4d61..0382249 100644 --- a/datastore/complete_post_objects.go +++ b/datastore/complete_post_objects.go @@ -9,7 +9,7 @@ import ( datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" ) -func (commonProtocol *CommonProtocol) completePostObjects(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) completePostObjects(err error, packet nex.PacketInterface, callID uint32, dataIDs types.List[types.UInt64]) (*nex.RMCMessage, *nex.Error) { if commonProtocol.minIOClient == nil { common_globals.Logger.Warning("MinIOClient not defined") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -35,7 +35,7 @@ func (commonProtocol *CommonProtocol) completePostObjects(err error, packet nex. var errorCode *nex.Error - dataIDs.Each(func(_ int, dataID *types.PrimitiveU64) bool { + for _, dataID := range dataIDs { bucket := commonProtocol.S3Bucket key := fmt.Sprintf("%s/%d.bin", commonProtocol.s3DataKeyBase, dataID) @@ -43,34 +43,28 @@ func (commonProtocol *CommonProtocol) completePostObjects(err error, packet nex. if err != nil { common_globals.Logger.Error(err.Error()) errorCode = nex.NewError(nex.ResultCodes.DataStore.NotFound, "change_error") - - return true + break } objectSizeDB, errCode := commonProtocol.GetObjectSizeByDataID(dataID) if errCode != nil { errorCode = errCode - - return true + break } if objectSizeS3 != uint64(objectSizeDB) { common_globals.Logger.Errorf("Object with DataID %d did not upload correctly! Mismatched sizes", dataID) // TODO - Is this a good error? errorCode = nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") - - return true + break } errCode = commonProtocol.UpdateObjectUploadCompletedByDataID(dataID, true) if errCode != nil { errorCode = errCode - - return true + break } - - return false - }) + } if errorCode != nil { return nil, errorCode diff --git a/datastore/delete_object.go b/datastore/delete_object.go index 8decd2f..a2fa073 100644 --- a/datastore/delete_object.go +++ b/datastore/delete_object.go @@ -7,7 +7,7 @@ import ( datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" ) -func (commonProtocol *CommonProtocol) deleteObject(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreDeleteParam) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) deleteObject(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreDeleteParam) (*nex.RMCMessage, *nex.Error) { if commonProtocol.GetObjectInfoByDataID == nil { common_globals.Logger.Warning("GetObjectInfoByDataID not defined") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") diff --git a/datastore/get_meta.go b/datastore/get_meta.go index f99b1b4..17a69f8 100644 --- a/datastore/get_meta.go +++ b/datastore/get_meta.go @@ -7,7 +7,7 @@ import ( datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" ) -func (commonProtocol *CommonProtocol) getMeta(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) getMeta(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) { if commonProtocol.GetObjectInfoByPersistenceTargetWithPassword == nil { common_globals.Logger.Warning("GetObjectInfoByPersistenceTargetWithPassword not defined") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -26,11 +26,11 @@ func (commonProtocol *CommonProtocol) getMeta(err error, packet nex.PacketInterf connection := packet.Sender() endpoint := connection.Endpoint() - var pMetaInfo *datastore_types.DataStoreMetaInfo + var pMetaInfo datastore_types.DataStoreMetaInfo var errCode *nex.Error // * Real server ignores PersistenceTarget if DataID is set - if param.DataID.Value == 0 { + if param.DataID == 0 { pMetaInfo, errCode = commonProtocol.GetObjectInfoByPersistenceTargetWithPassword(param.PersistenceTarget, param.AccessPassword) } else { pMetaInfo, errCode = commonProtocol.GetObjectInfoByDataIDWithPassword(param.DataID, param.AccessPassword) diff --git a/datastore/get_metas.go b/datastore/get_metas.go index 54b8c3c..69cb54d 100644 --- a/datastore/get_metas.go +++ b/datastore/get_metas.go @@ -8,7 +8,7 @@ import ( datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" ) -func (commonProtocol *CommonProtocol) getMetas(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], param *datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) getMetas(err error, packet nex.PacketInterface, callID uint32, dataIDs types.List[types.UInt64], param datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) { if commonProtocol.GetObjectInfoByDataID == nil { common_globals.Logger.Warning("GetObjectInfoByDataID not defined") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -24,41 +24,36 @@ func (commonProtocol *CommonProtocol) getMetas(err error, packet nex.PacketInter // TODO - Verify if param.PersistenceTarget is respected? It wouldn't make sense here but who knows - pMetaInfo := types.NewList[*datastore_types.DataStoreMetaInfo]() - pResults := types.NewList[*types.QResult]() - - pMetaInfo.Type = datastore_types.NewDataStoreMetaInfo() - pResults.Type = types.NewQResult(0) + pMetaInfo := types.NewList[datastore_types.DataStoreMetaInfo]() + pResults := types.NewList[types.QResult]() // * param has an AccessPassword, but it goes unchecked here. // * The password would need to be the same for every object // * in the input array, which doesn't make any sense. Assuming // * it's unused until proven otherwise - dataIDs.Each(func(_ int, dataID *types.PrimitiveU64) bool { + for _, dataID := range dataIDs { objectInfo, errCode := commonProtocol.GetObjectInfoByDataID(dataID) if errCode != nil { objectInfo = datastore_types.NewDataStoreMetaInfo() - pResults.Append(types.NewQResultError(errCode.ResultCode)) + pResults = append(pResults, types.NewQResultError(errCode.ResultCode)) } else { errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission) if errCode != nil { objectInfo = datastore_types.NewDataStoreMetaInfo() - pResults.Append(types.NewQResultError(errCode.ResultCode)) + pResults = append(pResults, types.NewQResultError(errCode.ResultCode)) } else { - pResults.Append(types.NewQResultSuccess(nex.ResultCodes.DataStore.Unknown)) + pResults = append(pResults, types.NewQResultSuccess(nex.ResultCodes.DataStore.Unknown)) } objectInfo.FilterPropertiesByResultOption(param.ResultOption) } - pMetaInfo.Append(objectInfo) - - return false - }) + pMetaInfo = append(pMetaInfo, objectInfo) + } rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/datastore/get_metas_multiple_param.go b/datastore/get_metas_multiple_param.go index c7c1eb1..f241b4e 100644 --- a/datastore/get_metas_multiple_param.go +++ b/datastore/get_metas_multiple_param.go @@ -8,7 +8,7 @@ import ( datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" ) -func (commonProtocol *CommonProtocol) getMetasMultipleParam(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_types.DataStoreGetMetaParam]) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) getMetasMultipleParam(err error, packet nex.PacketInterface, callID uint32, params types.List[datastore_types.DataStoreGetMetaParam]) (*nex.RMCMessage, *nex.Error) { if commonProtocol.GetObjectInfoByPersistenceTargetWithPassword == nil { common_globals.Logger.Warning("GetObjectInfoByPersistenceTargetWithPassword not defined") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -27,18 +27,15 @@ func (commonProtocol *CommonProtocol) getMetasMultipleParam(err error, packet ne connection := packet.Sender() endpoint := connection.Endpoint() - pMetaInfo := types.NewList[*datastore_types.DataStoreMetaInfo]() - pResults := types.NewList[*types.QResult]() + pMetaInfo := types.NewList[datastore_types.DataStoreMetaInfo]() + pResults := types.NewList[types.QResult]() - pMetaInfo.Type = datastore_types.NewDataStoreMetaInfo() - pResults.Type = types.NewQResult(0) - - params.Each(func(_ int, param *datastore_types.DataStoreGetMetaParam) bool { - var objectInfo *datastore_types.DataStoreMetaInfo + for _, param := range params { + var objectInfo datastore_types.DataStoreMetaInfo var errCode *nex.Error // * Real server ignores PersistenceTarget if DataID is set - if param.DataID.Value == 0 { + if param.DataID == 0 { objectInfo, errCode = commonProtocol.GetObjectInfoByPersistenceTargetWithPassword(param.PersistenceTarget, param.AccessPassword) } else { objectInfo, errCode = commonProtocol.GetObjectInfoByDataIDWithPassword(param.DataID, param.AccessPassword) @@ -47,24 +44,22 @@ func (commonProtocol *CommonProtocol) getMetasMultipleParam(err error, packet ne if errCode != nil { objectInfo = datastore_types.NewDataStoreMetaInfo() - pResults.Append(types.NewQResultError(errCode.ResultCode)) + pResults = append(pResults, types.NewQResultError(errCode.ResultCode)) } else { errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission) if errCode != nil { objectInfo = datastore_types.NewDataStoreMetaInfo() - pResults.Append(types.NewQResultError(errCode.ResultCode)) + pResults = append(pResults, types.NewQResultError(errCode.ResultCode)) } else { - pResults.Append(types.NewQResultSuccess(nex.ResultCodes.DataStore.Unknown)) + pResults = append(pResults, types.NewQResultSuccess(nex.ResultCodes.DataStore.Unknown)) } objectInfo.FilterPropertiesByResultOption(param.ResultOption) } - pMetaInfo.Append(objectInfo) - - return false - }) + pMetaInfo = append(pMetaInfo, objectInfo) + } rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/datastore/post_meta_binary.go b/datastore/post_meta_binary.go index 3ab4ffd..132e8df 100644 --- a/datastore/post_meta_binary.go +++ b/datastore/post_meta_binary.go @@ -7,7 +7,7 @@ import ( datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" ) -func (commonProtocol *CommonProtocol) postMetaBinary(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) postMetaBinary(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) { // * This method looks to function identically to DataStore::PreparePostObject, // * except the only difference being it doesn't return an S3 upload URL. This // * needs to be verified though, as there are other methods in the family such @@ -41,15 +41,13 @@ func (commonProtocol *CommonProtocol) postMetaBinary(err error, packet nex.Packe } // TODO - Should this be moved to InitializeObjectByPreparePostParam? - param.RatingInitParams.Each(func(_ int, ratingInitParamWithSlot *datastore_types.DataStoreRatingInitParamWithSlot) bool { + for _ , ratingInitParamWithSlot := range param.RatingInitParams { errCode = commonProtocol.InitializeObjectRatingWithSlot(dataID, ratingInitParamWithSlot) if errCode != nil { common_globals.Logger.Errorf("Error code on rating init: %s", errCode.Error()) - return true + break } - - return false - }) + } if errCode != nil { return nil, errCode @@ -57,7 +55,7 @@ func (commonProtocol *CommonProtocol) postMetaBinary(err error, packet nex.Packe rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) - rmcResponseStream.WritePrimitiveUInt64LE(dataID) + rmcResponseStream.WriteUInt64LE(dataID) rmcResponseBody := rmcResponseStream.Bytes() diff --git a/datastore/prepare_get_object.go b/datastore/prepare_get_object.go index 1ab9254..bb9085b 100644 --- a/datastore/prepare_get_object.go +++ b/datastore/prepare_get_object.go @@ -11,7 +11,7 @@ import ( datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" ) -func (commonProtocol *CommonProtocol) prepareGetObject(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareGetParam) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) prepareGetObject(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStorePrepareGetParam) (*nex.RMCMessage, *nex.Error) { if commonProtocol.GetObjectInfoByDataID == nil { common_globals.Logger.Warning("GetObjectInfoByDataID not defined") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -57,13 +57,11 @@ func (commonProtocol *CommonProtocol) prepareGetObject(err error, packet nex.Pac pReqGetInfo := datastore_types.NewDataStoreReqGetInfo() pReqGetInfo.URL = types.NewString(url.String()) - pReqGetInfo.RequestHeaders = types.NewList[*datastore_types.DataStoreKeyValue]() - pReqGetInfo.Size = objectInfo.Size.Copy().(*types.PrimitiveU32) + pReqGetInfo.RequestHeaders = types.NewList[datastore_types.DataStoreKeyValue]() + pReqGetInfo.Size = objectInfo.Size.Copy().(types.UInt32) pReqGetInfo.RootCACert = types.NewBuffer(commonProtocol.RootCACert) pReqGetInfo.DataID = param.DataID - - pReqGetInfo.RequestHeaders.Type = datastore_types.NewDataStoreKeyValue() - pReqGetInfo.RequestHeaders.SetFromData(requestHeaders) + pReqGetInfo.RequestHeaders = requestHeaders rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/datastore/prepare_post_object.go b/datastore/prepare_post_object.go index 9e4f7f5..a99af9a 100644 --- a/datastore/prepare_post_object.go +++ b/datastore/prepare_post_object.go @@ -11,7 +11,7 @@ import ( datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" ) -func (commonProtocol *CommonProtocol) preparePostObject(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) preparePostObject(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) { if commonProtocol.InitializeObjectByPreparePostParam == nil { common_globals.Logger.Warning("InitializeObjectByPreparePostParam not defined") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -43,16 +43,13 @@ func (commonProtocol *CommonProtocol) preparePostObject(err error, packet nex.Pa } // TODO - Should this be moved to InitializeObjectByPreparePostParam? - param.RatingInitParams.Each(func(_ int, ratingInitParamWithSlot *datastore_types.DataStoreRatingInitParamWithSlot) bool { + for _ , ratingInitParamWithSlot := range param.RatingInitParams { errCode = commonProtocol.InitializeObjectRatingWithSlot(dataID, ratingInitParamWithSlot) if errCode != nil { common_globals.Logger.Errorf("Error on rating init: %s", errCode.Error()) - - return true + break } - - return false - }) + } if errCode != nil { return nil, errCode @@ -74,23 +71,19 @@ func (commonProtocol *CommonProtocol) preparePostObject(err error, packet nex.Pa pReqPostInfo := datastore_types.NewDataStoreReqPostInfo() - pReqPostInfo.DataID = types.NewPrimitiveU64(dataID) + pReqPostInfo.DataID = types.NewUInt64(dataID) pReqPostInfo.URL = types.NewString(URL.String()) - pReqPostInfo.RequestHeaders = types.NewList[*datastore_types.DataStoreKeyValue]() - pReqPostInfo.FormFields = types.NewList[*datastore_types.DataStoreKeyValue]() + pReqPostInfo.RequestHeaders = types.NewList[datastore_types.DataStoreKeyValue]() + pReqPostInfo.FormFields = types.NewList[datastore_types.DataStoreKeyValue]() pReqPostInfo.RootCACert = types.NewBuffer(commonProtocol.RootCACert) - - pReqPostInfo.RequestHeaders.Type = datastore_types.NewDataStoreKeyValue() - pReqPostInfo.RequestHeaders.SetFromData(requestHeaders) - - pReqPostInfo.FormFields.Type = datastore_types.NewDataStoreKeyValue() + pReqPostInfo.RequestHeaders = requestHeaders for key, value := range formData { field := datastore_types.NewDataStoreKeyValue() field.Key = types.NewString(key) field.Value = types.NewString(value) - pReqPostInfo.FormFields.Append(field) + pReqPostInfo.FormFields = append(pReqPostInfo.FormFields, field) } rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/datastore/protocol.go b/datastore/protocol.go index 4bb9fd9..784b049 100644 --- a/datastore/protocol.go +++ b/datastore/protocol.go @@ -22,36 +22,36 @@ type CommonProtocol struct { minIOClient *minio.Client S3Presigner S3PresignerInterface GetUserFriendPIDs func(pid uint32) []uint32 - GetObjectInfoByDataID func(dataID *types.PrimitiveU64) (*datastore_types.DataStoreMetaInfo, *nex.Error) - UpdateObjectPeriodByDataIDWithPassword func(dataID *types.PrimitiveU64, dataType *types.PrimitiveU16, password *types.PrimitiveU64) *nex.Error - UpdateObjectMetaBinaryByDataIDWithPassword func(dataID *types.PrimitiveU64, metaBinary *types.QBuffer, password *types.PrimitiveU64) *nex.Error - UpdateObjectDataTypeByDataIDWithPassword func(dataID *types.PrimitiveU64, period *types.PrimitiveU16, password *types.PrimitiveU64) *nex.Error - GetObjectSizeByDataID func(dataID *types.PrimitiveU64) (uint32, *nex.Error) - UpdateObjectUploadCompletedByDataID func(dataID *types.PrimitiveU64, uploadCompleted bool) *nex.Error - GetObjectInfoByPersistenceTargetWithPassword func(persistenceTarget *datastore_types.DataStorePersistenceTarget, password *types.PrimitiveU64) (*datastore_types.DataStoreMetaInfo, *nex.Error) - GetObjectInfoByDataIDWithPassword func(dataID *types.PrimitiveU64, password *types.PrimitiveU64) (*datastore_types.DataStoreMetaInfo, *nex.Error) - S3GetRequestHeaders func() ([]*datastore_types.DataStoreKeyValue, *nex.Error) - S3PostRequestHeaders func() ([]*datastore_types.DataStoreKeyValue, *nex.Error) - InitializeObjectByPreparePostParam func(ownerPID *types.PID, param *datastore_types.DataStorePreparePostParam) (uint64, *nex.Error) - InitializeObjectRatingWithSlot func(dataID uint64, param *datastore_types.DataStoreRatingInitParamWithSlot) *nex.Error - RateObjectWithPassword func(dataID *types.PrimitiveU64, slot *types.PrimitiveU8, ratingValue *types.PrimitiveS32, accessPassword *types.PrimitiveU64) (*datastore_types.DataStoreRatingInfo, *nex.Error) - DeleteObjectByDataIDWithPassword func(dataID *types.PrimitiveU64, password *types.PrimitiveU64) *nex.Error - DeleteObjectByDataID func(dataID *types.PrimitiveU64) *nex.Error - GetObjectInfosByDataStoreSearchParam func(param *datastore_types.DataStoreSearchParam, pid *types.PID) ([]*datastore_types.DataStoreMetaInfo, uint32, *nex.Error) - GetObjectOwnerByDataID func(dataID *types.PrimitiveU64) (uint32, *nex.Error) - OnAfterDeleteObject func(packet nex.PacketInterface, param *datastore_types.DataStoreDeleteParam) - OnAfterGetMeta func(packet nex.PacketInterface, param *datastore_types.DataStoreGetMetaParam) - OnAfterGetMetas func(packet nex.PacketInterface, dataIDs *types.List[*types.PrimitiveU64], param *datastore_types.DataStoreGetMetaParam) - OnAfterSearchObject func(packet nex.PacketInterface, param *datastore_types.DataStoreSearchParam) - OnAfterRateObject func(packet nex.PacketInterface, target *datastore_types.DataStoreRatingTarget, param *datastore_types.DataStoreRateObjectParam, fetchRatings *types.PrimitiveBool) - OnAfterPostMetaBinary func(packet nex.PacketInterface, param *datastore_types.DataStorePreparePostParam) - OnAfterPreparePostObject func(packet nex.PacketInterface, param *datastore_types.DataStorePreparePostParam) - OnAfterPrepareGetObject func(packet nex.PacketInterface, param *datastore_types.DataStorePrepareGetParam) - OnAfterCompletePostObject func(packet nex.PacketInterface, param *datastore_types.DataStoreCompletePostParam) - OnAfterGetMetasMultipleParam func(packet nex.PacketInterface, params *types.List[*datastore_types.DataStoreGetMetaParam]) - OnAfterCompletePostObjects func(packet nex.PacketInterface, dataIDs *types.List[*types.PrimitiveU64]) - OnAfterChangeMeta func(packet nex.PacketInterface, param *datastore_types.DataStoreChangeMetaParam) - OnAfterRateObjects func(packet nex.PacketInterface, targets *types.List[*datastore_types.DataStoreRatingTarget], params *types.List[*datastore_types.DataStoreRateObjectParam], transactional *types.PrimitiveBool, fetchRatings *types.PrimitiveBool) + GetObjectInfoByDataID func(dataID types.UInt64) (datastore_types.DataStoreMetaInfo, *nex.Error) + UpdateObjectPeriodByDataIDWithPassword func(dataID types.UInt64, dataType types.UInt16, password types.UInt64) *nex.Error + UpdateObjectMetaBinaryByDataIDWithPassword func(dataID types.UInt64, metaBinary types.QBuffer, password types.UInt64) *nex.Error + UpdateObjectDataTypeByDataIDWithPassword func(dataID types.UInt64, period types.UInt16, password types.UInt64) *nex.Error + GetObjectSizeByDataID func(dataID types.UInt64) (uint32, *nex.Error) + UpdateObjectUploadCompletedByDataID func(dataID types.UInt64, uploadCompleted bool) *nex.Error + GetObjectInfoByPersistenceTargetWithPassword func(persistenceTarget datastore_types.DataStorePersistenceTarget, password types.UInt64) (datastore_types.DataStoreMetaInfo, *nex.Error) + GetObjectInfoByDataIDWithPassword func(dataID types.UInt64, password types.UInt64) (datastore_types.DataStoreMetaInfo, *nex.Error) + S3GetRequestHeaders func() ([]datastore_types.DataStoreKeyValue, *nex.Error) + S3PostRequestHeaders func() ([]datastore_types.DataStoreKeyValue, *nex.Error) + InitializeObjectByPreparePostParam func(ownerPID types.PID, param datastore_types.DataStorePreparePostParam) (uint64, *nex.Error) + InitializeObjectRatingWithSlot func(dataID uint64, param datastore_types.DataStoreRatingInitParamWithSlot) *nex.Error + RateObjectWithPassword func(dataID types.UInt64, slot types.UInt8, ratingValue types.Int32, accessPassword types.UInt64) (datastore_types.DataStoreRatingInfo, *nex.Error) + DeleteObjectByDataIDWithPassword func(dataID types.UInt64, password types.UInt64) *nex.Error + DeleteObjectByDataID func(dataID types.UInt64) *nex.Error + GetObjectInfosByDataStoreSearchParam func(param datastore_types.DataStoreSearchParam, pid types.PID) ([]datastore_types.DataStoreMetaInfo, uint32, *nex.Error) + GetObjectOwnerByDataID func(dataID types.UInt64) (uint32, *nex.Error) + OnAfterDeleteObject func(packet nex.PacketInterface, param datastore_types.DataStoreDeleteParam) + OnAfterGetMeta func(packet nex.PacketInterface, param datastore_types.DataStoreGetMetaParam) + OnAfterGetMetas func(packet nex.PacketInterface, dataIDs types.List[types.UInt64], param datastore_types.DataStoreGetMetaParam) + OnAfterSearchObject func(packet nex.PacketInterface, param datastore_types.DataStoreSearchParam) + OnAfterRateObject func(packet nex.PacketInterface, target datastore_types.DataStoreRatingTarget, param datastore_types.DataStoreRateObjectParam, fetchRatings types.Bool) + OnAfterPostMetaBinary func(packet nex.PacketInterface, param datastore_types.DataStorePreparePostParam) + OnAfterPreparePostObject func(packet nex.PacketInterface, param datastore_types.DataStorePreparePostParam) + OnAfterPrepareGetObject func(packet nex.PacketInterface, param datastore_types.DataStorePrepareGetParam) + OnAfterCompletePostObject func(packet nex.PacketInterface, param datastore_types.DataStoreCompletePostParam) + OnAfterGetMetasMultipleParam func(packet nex.PacketInterface, params types.List[datastore_types.DataStoreGetMetaParam]) + OnAfterCompletePostObjects func(packet nex.PacketInterface, dataIDs types.List[types.UInt64]) + OnAfterChangeMeta func(packet nex.PacketInterface, param datastore_types.DataStoreChangeMetaParam) + OnAfterRateObjects func(packet nex.PacketInterface, targets types.List[datastore_types.DataStoreRatingTarget], params types.List[datastore_types.DataStoreRateObjectParam], transactional types.Bool, fetchRatings types.Bool) } func (c *CommonProtocol) S3StatObject(bucket, key string) (minio.ObjectInfo, error) { @@ -67,8 +67,8 @@ func (c *CommonProtocol) S3ObjectSize(bucket, key string) (uint64, error) { return uint64(info.Size), nil } -func (c *CommonProtocol) VerifyObjectPermission(ownerPID, accessorPID *types.PID, permission *datastore_types.DataStorePermission) *nex.Error { - if permission.Permission.Value > 3 { +func (c *CommonProtocol) VerifyObjectPermission(ownerPID, accessorPID types.PID, permission datastore_types.DataStorePermission) *nex.Error { + if permission.Permission > 3 { return nex.NewError(nex.ResultCodes.DataStore.InvalidArgument, "change_error") } @@ -78,29 +78,29 @@ func (c *CommonProtocol) VerifyObjectPermission(ownerPID, accessorPID *types.PID } // * Allow anyone - if permission.Permission.Value == 0 { + if permission.Permission == 0 { return nil } // * Allow only friends of the owner - if permission.Permission.Value == 1 { + if permission.Permission == 1 { // TODO - This assumes a legacy client. Will not work on the Switch - friendsList := c.GetUserFriendPIDs(ownerPID.LegacyValue()) + friendsList := c.GetUserFriendPIDs(uint32(ownerPID)) - if !slices.Contains(friendsList, accessorPID.LegacyValue()) { + if !slices.Contains(friendsList, uint32(accessorPID)) { return nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error") } } // * Allow only users whose PIDs are defined in permission.RecipientIDs - if permission.Permission.Value == 2 { + if permission.Permission == 2 { if !permission.RecipientIDs.Contains(accessorPID) { return nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error") } } // * Allow only the owner - if permission.Permission.Value == 3 { + if permission.Permission == 3 { if !ownerPID.Equals(accessorPID) { return nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error") } @@ -137,11 +137,11 @@ func NewCommonProtocol(protocol datastore.Interface) *CommonProtocol { endpoint: protocol.Endpoint(), protocol: protocol, RootCACert: []byte{}, - S3GetRequestHeaders: func() ([]*datastore_types.DataStoreKeyValue, *nex.Error) { - return []*datastore_types.DataStoreKeyValue{}, nil + S3GetRequestHeaders: func() ([]datastore_types.DataStoreKeyValue, *nex.Error) { + return []datastore_types.DataStoreKeyValue{}, nil }, - S3PostRequestHeaders: func() ([]*datastore_types.DataStoreKeyValue, *nex.Error) { - return []*datastore_types.DataStoreKeyValue{}, nil + S3PostRequestHeaders: func() ([]datastore_types.DataStoreKeyValue, *nex.Error) { + return []datastore_types.DataStoreKeyValue{}, nil }, } diff --git a/datastore/rate_object.go b/datastore/rate_object.go index b146a80..082e1d6 100644 --- a/datastore/rate_object.go +++ b/datastore/rate_object.go @@ -8,7 +8,7 @@ import ( datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" ) -func (commonProtocol *CommonProtocol) rateObject(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, param *datastore_types.DataStoreRateObjectParam, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) rateObject(err error, packet nex.PacketInterface, callID uint32, target datastore_types.DataStoreRatingTarget, param datastore_types.DataStoreRateObjectParam, fetchRatings types.Bool) (*nex.RMCMessage, *nex.Error) { if commonProtocol.GetObjectInfoByDataIDWithPassword == nil { common_globals.Logger.Warning("GetObjectInfoByDataIDWithPassword not defined") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -46,7 +46,7 @@ func (commonProtocol *CommonProtocol) rateObject(err error, packet nex.PacketInt // * the rating by default, so we check if // * the client DOESN'T want it and then just // * zero it out - if !fetchRatings.Value { + if !fetchRatings { pRating = datastore_types.NewDataStoreRatingInfo() } diff --git a/datastore/rate_objects.go b/datastore/rate_objects.go index d077d7a..df476d4 100644 --- a/datastore/rate_objects.go +++ b/datastore/rate_objects.go @@ -8,7 +8,7 @@ import ( datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" ) -func (commonProtocol *CommonProtocol) rateObjects(err error, packet nex.PacketInterface, callID uint32, targets *types.List[*datastore_types.DataStoreRatingTarget], params *types.List[*datastore_types.DataStoreRateObjectParam], transactional *types.PrimitiveBool, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) rateObjects(err error, packet nex.PacketInterface, callID uint32, targets types.List[datastore_types.DataStoreRatingTarget], params types.List[datastore_types.DataStoreRateObjectParam], transactional types.Bool, fetchRatings types.Bool) (*nex.RMCMessage, *nex.Error) { if commonProtocol.GetObjectInfoByDataIDWithPassword == nil { common_globals.Logger.Warning("GetObjectInfoByDataIDWithPassword not defined") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -27,53 +27,45 @@ func (commonProtocol *CommonProtocol) rateObjects(err error, packet nex.PacketIn connection := packet.Sender() endpoint := connection.Endpoint() - pRatings := types.NewList[*datastore_types.DataStoreRatingInfo]() - pResults := types.NewList[*types.QResult]() - - pRatings.Type = datastore_types.NewDataStoreRatingInfo() - pResults.Type = types.NewQResult(0) + pRatings := types.NewList[datastore_types.DataStoreRatingInfo]() + pResults := types.NewList[types.QResult]() // * Real DataStore does not actually check this. // * I just didn't feel like working out the // * logic for differing sized lists. So force // * them to always be the same - if targets.Length() != params.Length() { + if len(targets) != len(params) { return nil, nex.NewError(nex.ResultCodes.DataStore.InvalidArgument, "change_error") } var errorCode *nex.Error - targets.Each(func(i int, target *datastore_types.DataStoreRatingTarget) bool { - param, err := params.Get(i) - if err != nil { - errorCode = nex.NewError(nex.ResultCodes.DataStore.InvalidArgument, "change_error") - return true - } + for i, target := range targets { + // * We already checked that targets and params will have the same length + param := params[i] objectInfo, errCode := commonProtocol.GetObjectInfoByDataIDWithPassword(target.DataID, param.AccessPassword) if errCode != nil { errorCode = errCode - return true + break } errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission) if errCode != nil { errorCode = errCode - return true + break } rating, errCode := commonProtocol.RateObjectWithPassword(target.DataID, target.Slot, param.RatingValue, param.AccessPassword) if errCode != nil { errorCode = errCode - return true + break } - if fetchRatings.Value { - pRatings.Append(rating) + if fetchRatings { + pRatings = append(pRatings, rating) } - - return false - }) + } if errorCode != nil { return nil, errorCode diff --git a/datastore/search_object.go b/datastore/search_object.go index 2f9f96e..9035dff 100644 --- a/datastore/search_object.go +++ b/datastore/search_object.go @@ -8,7 +8,7 @@ import ( datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" ) -func (commonProtocol *CommonProtocol) searchObject(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) searchObject(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreSearchParam) (*nex.RMCMessage, *nex.Error) { if commonProtocol.GetObjectInfosByDataStoreSearchParam == nil { common_globals.Logger.Warning("GetObjectInfosByDataStoreSearchParam not defined") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -36,8 +36,7 @@ func (commonProtocol *CommonProtocol) searchObject(err error, packet nex.PacketI pSearchResult := datastore_types.NewDataStoreSearchResult() - pSearchResult.Result = types.NewList[*datastore_types.DataStoreMetaInfo]() - pSearchResult.Result.Type = datastore_types.NewDataStoreMetaInfo() + pSearchResult.Result = types.NewList[datastore_types.DataStoreMetaInfo]() for _, object := range objects { errCode = commonProtocol.VerifyObjectPermission(object.OwnerID, connection.PID(), object.Permission) @@ -50,7 +49,7 @@ func (commonProtocol *CommonProtocol) searchObject(err error, packet nex.PacketI object.FilterPropertiesByResultOption(param.ResultOption) - pSearchResult.Result.Append(object) + pSearchResult.Result = append(pSearchResult.Result, object) } var totalCountType uint8 @@ -59,7 +58,7 @@ func (commonProtocol *CommonProtocol) searchObject(err error, packet nex.PacketI // * the permissions checks in the // * previous loop will mutate the data // * returned from the database - if totalCount == uint32(pSearchResult.Result.Length()) { + if totalCount == uint32(len(pSearchResult.Result)) { totalCountType = 0 // * Has no more data. All possible results were returned } else { totalCountType = 1 // * Has more data. Not all possible results were returned @@ -70,14 +69,14 @@ func (commonProtocol *CommonProtocol) searchObject(err error, packet nex.PacketI // * Only seen in struct revision 3 or // * NEX 4.0+ if param.StructureVersion >= 3 || endpoint.LibraryVersions().DataStore.GreaterOrEqual("4.0.0") { - if !param.TotalCountEnabled.Value { + if !param.TotalCountEnabled { totalCount = 0 totalCountType = 3 } } - pSearchResult.TotalCount = types.NewPrimitiveU32(totalCount) - pSearchResult.TotalCountType = types.NewPrimitiveU8(totalCountType) + pSearchResult.TotalCount = types.NewUInt32(totalCount) + pSearchResult.TotalCountType = types.NewUInt8(totalCountType) rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/globals/utils.go b/globals/utils.go index 123bad2..c5b367c 100644 --- a/globals/utils.go +++ b/globals/utils.go @@ -34,8 +34,8 @@ func RemoveDuplicates[T comparable](sliceList []T) []T { } // CheckValidGathering checks if a Gathering is valid -func CheckValidGathering(gathering *match_making_types.Gathering) bool { - if len(gathering.Description.Value) > 256 { +func CheckValidGathering(gathering match_making_types.Gathering) bool { + if len(gathering.Description) > 256 { return false } @@ -43,34 +43,34 @@ func CheckValidGathering(gathering *match_making_types.Gathering) bool { } // CheckValidMatchmakeSession checks if a MatchmakeSession is valid -func CheckValidMatchmakeSession(matchmakeSession *match_making_types.MatchmakeSession) bool { +func CheckValidMatchmakeSession(matchmakeSession match_making_types.MatchmakeSession) bool { if !CheckValidGathering(matchmakeSession.Gathering) { return false } - if matchmakeSession.Attributes.Length() != 6 { + if len(matchmakeSession.Attributes) != 6 { return false } - if matchmakeSession.ProgressScore.Value > 100 { + if matchmakeSession.ProgressScore > 100 { return false } - if len(matchmakeSession.UserPassword.Value) > 32 { + if len(matchmakeSession.UserPassword) > 32 { return false } // * Except for UserPassword, all strings must have a length lower than 256 - if len(matchmakeSession.CodeWord.Value) > 256 { + if len(matchmakeSession.CodeWord) > 256 { return false } // * All buffers must have a length lower than 512 - if len(matchmakeSession.ApplicationBuffer.Value) > 512 { + if len(matchmakeSession.ApplicationBuffer) > 512 { return false } - if len(matchmakeSession.SessionKey.Value) > 512 { + if len(matchmakeSession.SessionKey) > 512 { return false } @@ -78,22 +78,22 @@ func CheckValidMatchmakeSession(matchmakeSession *match_making_types.MatchmakeSe } // CanJoinMatchmakeSession checks if a PID is allowed to join a matchmake session -func CanJoinMatchmakeSession(manager *MatchmakingManager, pid *types.PID, matchmakeSession *match_making_types.MatchmakeSession) *nex.Error { +func CanJoinMatchmakeSession(manager *MatchmakingManager, pid types.PID, matchmakeSession match_making_types.MatchmakeSession) *nex.Error { // TODO - Is this the right error? - if !matchmakeSession.OpenParticipation.Value { + if !matchmakeSession.OpenParticipation { return nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } // * Only allow friends // TODO - This won't work on Switch! - if matchmakeSession.ParticipationPolicy.Value == 98 { + if matchmakeSession.ParticipationPolicy == 98 { if manager.GetUserFriendPIDs == nil { Logger.Warning("Missing GetUserFriendPIDs!") return nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") } - friendList := manager.GetUserFriendPIDs(pid.LegacyValue()) - if !slices.Contains(friendList, matchmakeSession.OwnerPID.LegacyValue()) { + friendList := manager.GetUserFriendPIDs(uint32(pid)) + if !slices.Contains(friendList, uint32(matchmakeSession.OwnerPID)) { return nex.NewError(nex.ResultCodes.RendezVous.NotFriend, "change_error") } } @@ -102,7 +102,7 @@ func CanJoinMatchmakeSession(manager *MatchmakingManager, pid *types.PID, matchm } // SendNotificationEvent sends a notification event to the specified targets -func SendNotificationEvent(endpoint *nex.PRUDPEndPoint, event *notifications_types.NotificationEvent, targets []uint64) { +func SendNotificationEvent(endpoint *nex.PRUDPEndPoint, event notifications_types.NotificationEvent, targets []uint64) { server := endpoint.Server stream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/go.mod b/go.mod index dc82455..1d166e5 100644 --- a/go.mod +++ b/go.mod @@ -5,36 +5,36 @@ go 1.22.1 toolchain go1.22.4 require ( - github.com/PretendoNetwork/nex-go/v2 v2.0.5 - github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.4 + github.com/PretendoNetwork/nex-go/v2 v2.1.0 + github.com/PretendoNetwork/nex-protocols-go/v2 v2.1.0 github.com/PretendoNetwork/plogger-go v1.0.4 github.com/PretendoNetwork/pq-extended v1.0.0 - github.com/minio/minio-go/v7 v7.0.70 + github.com/minio/minio-go/v7 v7.0.83 ) require ( github.com/dolthub/maphash v0.1.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect - github.com/fatih/color v1.17.0 // indirect - github.com/goccy/go-json v0.10.2 // indirect + github.com/fatih/color v1.18.0 // indirect + github.com/go-ini/ini v1.67.0 // indirect + github.com/goccy/go-json v0.10.4 // indirect github.com/google/uuid v1.6.0 // indirect github.com/jwalton/go-supportscolor v1.2.0 // indirect - github.com/klauspost/compress v1.17.8 // indirect - github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/klauspost/compress v1.17.11 // indirect + github.com/klauspost/cpuid/v2 v2.2.9 // indirect github.com/lib/pq v1.10.9 // indirect - github.com/lxzan/gws v1.8.3 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect + github.com/lxzan/gws v1.8.8 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/minio/md5-simd v1.1.2 // indirect github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e // indirect - github.com/rs/xid v1.5.0 // indirect + github.com/rs/xid v1.6.0 // indirect github.com/superwhiskers/crunch/v3 v3.5.7 // indirect - golang.org/x/crypto v0.23.0 // indirect - golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect - golang.org/x/mod v0.17.0 // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/term v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect - gopkg.in/ini.v1 v1.67.0 // indirect + golang.org/x/crypto v0.31.0 // indirect + golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect + golang.org/x/mod v0.22.0 // indirect + golang.org/x/net v0.33.0 // indirect + golang.org/x/sys v0.29.0 // indirect + golang.org/x/term v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect ) diff --git a/go.sum b/go.sum index dc7620b..4e80059 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ -github.com/PretendoNetwork/nex-go/v2 v2.0.5 h1:S/bYPb2SNUb9MSzai4wlqj/9J1JIiLuMtZcAAbBughM= -github.com/PretendoNetwork/nex-go/v2 v2.0.5/go.mod h1:iW1xjbg/vl2c3uheitUFxGcrt0sxaDxeXR5QqDcyLpI= -github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.4 h1:7Vb/jV/cO6c8XcGzGCoowSNXjZDLb/D1lYkLk8rxm7c= -github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.4/go.mod h1:2UN8khoMDNaeJ4GcIG7ez7MqqmbLfLzbVS6hSa+kGnk= +github.com/PretendoNetwork/nex-go/v2 v2.1.0 h1:MP3MO3KTDJZedKCToS+eLvHJ+07a5VsHQpuNw8N3RlA= +github.com/PretendoNetwork/nex-go/v2 v2.1.0/go.mod h1:3LyJzsv3AataJW8D0binp15Q8ZH22MWTYly1VNtXi64= +github.com/PretendoNetwork/nex-protocols-go/v2 v2.1.0 h1:cUsyHuluOBUg5AIlMl3LHbE2y5VLPyqj5IXAzD2wVks= +github.com/PretendoNetwork/nex-protocols-go/v2 v2.1.0/go.mod h1:+soBHmwX6ixGxj6cphLuCvfJqxcZPuowc/5e7Qi9Bz0= github.com/PretendoNetwork/plogger-go v1.0.4 h1:PF7xHw9eDRHH+RsAP9tmAE7fG0N0p6H4iPwHKnsoXwc= github.com/PretendoNetwork/plogger-go v1.0.4/go.mod h1:7kD6M4vPq1JL4LTuPg6kuB1OvUBOwQOtAvTaUwMbwvU= github.com/PretendoNetwork/pq-extended v1.0.0 h1:GHZ0hLvCvmYKQPTV9I9XtTx8J1iB5Z9CEnfW2tUpsYg= @@ -12,10 +12,12 @@ github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= -github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= -github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= -github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= +github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= +github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A= +github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= +github.com/goccy/go-json v0.10.4 h1:JSwxQzIqKfmFX1swYPpUThQZp/Ka4wzJdK0LWVytLPM= +github.com/goccy/go-json v0.10.4/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -24,55 +26,50 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jwalton/go-supportscolor v1.2.0 h1:g6Ha4u7Vm3LIsQ5wmeBpS4gazu0UP1DRDE8y6bre4H8= github.com/jwalton/go-supportscolor v1.2.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs= -github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= -github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= +github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= -github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY= +github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/lxzan/gws v1.8.3 h1:umX2VLhXj7oVV4Sd2gCuqzrzpVWtqkKMy0tjHBBxXg0= -github.com/lxzan/gws v1.8.3/go.mod h1:FcGeRMB7HwGuTvMLR24ku0Zx0p6RXqeKASeMc4VYgi4= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/lxzan/gws v1.8.8 h1:st193ZG8qN8sSw8/g/UituFhs7etmKzS7jUqhijg5wM= +github.com/lxzan/gws v1.8.8/go.mod h1:FcGeRMB7HwGuTvMLR24ku0Zx0p6RXqeKASeMc4VYgi4= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= -github.com/minio/minio-go/v7 v7.0.70 h1:1u9NtMgfK1U42kUxcsl5v0yj6TEOPR497OAQxpJnn2g= -github.com/minio/minio-go/v7 v7.0.70/go.mod h1:4yBA8v80xGA30cfM3fz0DKYMXunWl/AV/6tWEs9ryzo= +github.com/minio/minio-go/v7 v7.0.83 h1:W4Kokksvlz3OKf3OqIlzDNKd4MERlC2oN8YptwJ0+GA= +github.com/minio/minio-go/v7 v7.0.83/go.mod h1:57YXpvc5l3rjPdhqNrDsvVlY0qPI6UTk1bflAe+9doY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e h1:dCWirM5F3wMY+cmRda/B1BiPsFtmzXqV9b0hLWtVBMs= github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e/go.mod h1:9leZcVcItj6m9/CfHY5Em/iBrCz7js8LcRQGTKEEv2M= -github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= -github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU= +github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/superwhiskers/crunch/v3 v3.5.7 h1:N9RLxaR65C36i26BUIpzPXGy2f6pQ7wisu2bawbKNqg= github.com/superwhiskers/crunch/v3 v3.5.7/go.mod h1:4ub2EKgF1MAhTjoOCTU4b9uLMsAweHEa89aRrfAypXA= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= -golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= -golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= -golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= +golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 h1:yqrTHse8TCMW1M1ZCP+VAR/l0kKxwaAIqN/il7x4voA= +golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU= +golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= +golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= +golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= +golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= -golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= -gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg= +golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/match-making-ext/end_participation.go b/match-making-ext/end_participation.go index 87e6076..b8397a9 100644 --- a/match-making-ext/end_participation.go +++ b/match-making-ext/end_participation.go @@ -8,13 +8,13 @@ import ( match_making_ext "github.com/PretendoNetwork/nex-protocols-go/v2/match-making-ext" ) -func (commonProtocol *CommonProtocol) endParticipation(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) endParticipation(err error, packet nex.PacketInterface, callID uint32, idGathering types.UInt32, strMessage types.String) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } - if len(strMessage.Value) > 256 { + if len(strMessage) > 256 { return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } @@ -23,7 +23,7 @@ func (commonProtocol *CommonProtocol) endParticipation(err error, packet nex.Pac connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) - nexError := database.EndGatheringParticipation(commonProtocol.manager, idGathering.Value, connection, strMessage.Value) + nexError := database.EndGatheringParticipation(commonProtocol.manager, uint32(idGathering), connection, string(strMessage)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -31,7 +31,7 @@ func (commonProtocol *CommonProtocol) endParticipation(err error, packet nex.Pac commonProtocol.manager.Mutex.Unlock() - retval := types.NewPrimitiveBool(true) + retval := types.NewBool(true) rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/match-making-ext/protocol.go b/match-making-ext/protocol.go index 86cc46e..d8faf4a 100644 --- a/match-making-ext/protocol.go +++ b/match-making-ext/protocol.go @@ -11,7 +11,7 @@ type CommonProtocol struct { endpoint nex.EndpointInterface protocol match_making_ext.Interface manager *common_globals.MatchmakingManager - OnAfterEndParticipation func(acket nex.PacketInterface, idGathering *types.PrimitiveU32, strMessage *types.String) + OnAfterEndParticipation func(acket nex.PacketInterface, idGathering types.UInt32, strMessage types.String) } // SetManager defines the matchmaking manager to be used by the common protocol diff --git a/match-making/database/disconnect_participant.go b/match-making/database/disconnect_participant.go index b48410a..c106cf0 100644 --- a/match-making/database/disconnect_participant.go +++ b/match-making/database/disconnect_participant.go @@ -16,7 +16,7 @@ import ( func DisconnectParticipant(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection) { var nexError *nex.Error - rows, err := manager.Database.Query(`SELECT id, owner_pid, host_pid, min_participants, max_participants, participation_policy, policy_argument, flags, state, description, type, participants FROM matchmaking.gatherings WHERE $1 = ANY(participants) AND registered=true`, connection.PID().Value()) + rows, err := manager.Database.Query(`SELECT id, owner_pid, host_pid, min_participants, max_participants, participation_policy, policy_argument, flags, state, description, type, participants FROM matchmaking.gatherings WHERE $1 = ANY(participants) AND registered=true`, connection.PID()) if err != nil { common_globals.Logger.Critical(err.Error()) return @@ -61,19 +61,19 @@ func DisconnectParticipant(manager *common_globals.MatchmakingManager, connectio } gathering := match_making_types.NewGathering() - gathering.ID.Value = gatheringID + gathering.ID = types.NewUInt32(gatheringID) gathering.OwnerPID = types.NewPID(ownerPID) gathering.HostPID = types.NewPID(hostPID) - gathering.MinimumParticipants.Value = minParticipants - gathering.MaximumParticipants.Value = maxParticipants - gathering.ParticipationPolicy.Value = participationPolicy - gathering.PolicyArgument.Value = policyArgument - gathering.Flags.Value = flags - gathering.State.Value = state - gathering.Description.Value = description + gathering.MinimumParticipants = types.NewUInt16(minParticipants) + gathering.MaximumParticipants = types.NewUInt16(maxParticipants) + gathering.ParticipationPolicy = types.NewUInt32(participationPolicy) + gathering.PolicyArgument = types.NewUInt32(policyArgument) + gathering.Flags = types.NewUInt32(flags) + gathering.State = types.NewUInt32(state) + gathering.Description = types.NewString(description) // * Since the participant is leaving, override the participant list to avoid sending notifications to them - participants, nexError = RemoveParticipantFromGathering(manager, gatheringID, connection.PID().Value()) + participants, nexError = RemoveParticipantFromGathering(manager, gatheringID, uint64(connection.PID())) if nexError != nil { common_globals.Logger.Error(nexError.Error()) continue @@ -100,7 +100,7 @@ func DisconnectParticipant(manager *common_globals.MatchmakingManager, connectio // * This flag tells the server to change the matchmake session owner if they disconnect // * If the flag is not set, delete the session // * More info: https://nintendo-wiki.pretendo.network/docs/nex/protocols/match-making/types#flags - if gathering.Flags.PAND(match_making.GatheringFlags.DisconnectChangeOwner) == 0 { + if uint32(gathering.Flags) & match_making.GatheringFlags.DisconnectChangeOwner == 0 { nexError = UnregisterGathering(manager, connection.PID(), gatheringID) if nexError != nil { common_globals.Logger.Error(nexError.Error()) @@ -111,9 +111,9 @@ func DisconnectParticipant(manager *common_globals.MatchmakingManager, connectio subtype := notifications.NotificationSubTypes.GatheringUnregistered.None oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = connection.PID().Copy().(*types.PID) - oEvent.Type.Value = notifications.BuildNotificationType(category, subtype) - oEvent.Param1.Value = gatheringID + oEvent.PIDSource = connection.PID().Copy().(types.PID) + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = types.NewUInt32(gatheringID) common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, common_globals.RemoveDuplicates(participants)) @@ -137,9 +137,9 @@ func DisconnectParticipant(manager *common_globals.MatchmakingManager, connectio subtype := notifications.NotificationSubTypes.HostChanged.None oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = connection.PID().Copy().(*types.PID) - oEvent.Type.Value = notifications.BuildNotificationType(category, subtype) - oEvent.Param1.Value = gatheringID + oEvent.PIDSource = connection.PID().Copy().(types.PID) + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = types.NewUInt32(gatheringID) // TODO - Should the notification actually be sent to all participants? common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, common_globals.RemoveDuplicates(participants)) @@ -156,18 +156,18 @@ func DisconnectParticipant(manager *common_globals.MatchmakingManager, connectio subtype := notifications.NotificationSubTypes.Participation.Disconnected oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = connection.PID().Copy().(*types.PID) - oEvent.Type = types.NewPrimitiveU32(notifications.BuildNotificationType(category, subtype)) - oEvent.Param1.Value = gatheringID - oEvent.Param2.Value = connection.PID().LegacyValue() // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.PIDSource = connection.PID().Copy().(types.PID) + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = types.NewUInt32(gatheringID) + oEvent.Param2 = types.NewUInt32(uint32(connection.PID())) // TODO - This assumes a legacy client. Will not work on the Switch var participantEndedTargets []uint64 // * When the VerboseParticipants or VerboseParticipantsEx flags are set, all participant notification events are sent to everyone - if gathering.Flags.PAND(match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 { + if uint32(gathering.Flags) & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 { participantEndedTargets = common_globals.RemoveDuplicates(participants) } else { - participantEndedTargets = []uint64{gathering.OwnerPID.Value()} + participantEndedTargets = []uint64{uint64(gathering.OwnerPID)} } // * Only send the notification event to the owner diff --git a/match-making/database/end_gathering_participation.go b/match-making/database/end_gathering_participation.go index cc5d28c..9f8d26f 100644 --- a/match-making/database/end_gathering_participation.go +++ b/match-making/database/end_gathering_participation.go @@ -20,17 +20,17 @@ func EndGatheringParticipation(manager *common_globals.MatchmakingManager, gathe } // TODO - Is this the right error? - if !slices.Contains(participants, connection.PID().Value()) { + if !slices.Contains(participants, uint64(connection.PID())) { return nex.NewError(nex.ResultCodes.RendezVous.NotParticipatedGathering, "change_error") } // * If the gathering is a PersistentGathering, only remove the participant from the gathering if gatheringType == "PersistentGathering" { - _, nexError = RemoveParticipantFromGathering(manager, gatheringID, connection.PID().Value()) + _, nexError = RemoveParticipantFromGathering(manager, gatheringID, uint64(connection.PID())) return nexError } - newParticipants, nexError := RemoveParticipantFromGathering(manager, gatheringID, connection.PID().Value()) + newParticipants, nexError := RemoveParticipantFromGathering(manager, gatheringID, uint64(connection.PID())) if nexError != nil { return nexError } @@ -45,12 +45,12 @@ func EndGatheringParticipation(manager *common_globals.MatchmakingManager, gathe return UnregisterGathering(manager, connection.PID(), gatheringID) } - var ownerPID uint64 = gathering.OwnerPID.Value() + var ownerPID uint64 = uint64(gathering.OwnerPID) if connection.PID().Equals(gathering.OwnerPID) { // * This flag tells the server to change the matchmake session owner if they disconnect // * If the flag is not set, delete the session // * More info: https://nintendo-wiki.pretendo.network/docs/nex/protocols/match-making/types#flags - if gathering.Flags.PAND(match_making.GatheringFlags.DisconnectChangeOwner) == 0 { + if uint32(gathering.Flags) & match_making.GatheringFlags.DisconnectChangeOwner == 0 { nexError = UnregisterGathering(manager, connection.PID(), gatheringID) if nexError != nil { return nexError @@ -60,9 +60,9 @@ func EndGatheringParticipation(manager *common_globals.MatchmakingManager, gathe subtype := notifications.NotificationSubTypes.GatheringUnregistered.None oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = connection.PID().Copy().(*types.PID) - oEvent.Type.Value = notifications.BuildNotificationType(category, subtype) - oEvent.Param1.Value = gatheringID + oEvent.PIDSource = connection.PID().Copy().(types.PID) + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = types.NewUInt32(gatheringID) common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, common_globals.RemoveDuplicates(newParticipants)) @@ -88,9 +88,9 @@ func EndGatheringParticipation(manager *common_globals.MatchmakingManager, gathe subtype := notifications.NotificationSubTypes.HostChanged.None oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = connection.PID().Copy().(*types.PID) - oEvent.Type.Value = notifications.BuildNotificationType(category, subtype) - oEvent.Param1.Value = gatheringID + oEvent.PIDSource = connection.PID().Copy().(types.PID) + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = types.NewUInt32(gatheringID) // TODO - Should the notification actually be sent to all participants? common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, common_globals.RemoveDuplicates(participants)) @@ -106,19 +106,19 @@ func EndGatheringParticipation(manager *common_globals.MatchmakingManager, gathe subtype := notifications.NotificationSubTypes.Participation.Ended oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = connection.PID().Copy().(*types.PID) - oEvent.Type = types.NewPrimitiveU32(notifications.BuildNotificationType(category, subtype)) - oEvent.Param1.Value = gatheringID - oEvent.Param2.Value = connection.PID().LegacyValue() // TODO - This assumes a legacy client. Will not work on the Switch - oEvent.StrParam.Value = message + oEvent.PIDSource = connection.PID().Copy().(types.PID) + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = types.NewUInt32(gatheringID) + oEvent.Param2 = types.NewUInt32(uint32((connection.PID()))) // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.StrParam = types.NewString(message) var participationEndedTargets []uint64 // * When the VerboseParticipants or VerboseParticipantsEx flags are set, all participant notification events are sent to everyone - if gathering.Flags.PAND(match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 { + if uint32(gathering.Flags) & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 { participationEndedTargets = common_globals.RemoveDuplicates(participants) } else { - participationEndedTargets = []uint64{gathering.OwnerPID.Value()} + participationEndedTargets = []uint64{uint64(gathering.OwnerPID)} } common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, participationEndedTargets) diff --git a/match-making/database/find_gathering_by_id.go b/match-making/database/find_gathering_by_id.go index 2d633e3..9d71232 100644 --- a/match-making/database/find_gathering_by_id.go +++ b/match-making/database/find_gathering_by_id.go @@ -12,7 +12,7 @@ import ( ) // FindGatheringByID finds a gathering on a database with the given ID. Returns the gathering, its type, the participant list and the started time -func FindGatheringByID(manager *common_globals.MatchmakingManager, id uint32) (*match_making_types.Gathering, string, []uint64, *types.DateTime, *nex.Error) { +func FindGatheringByID(manager *common_globals.MatchmakingManager, id uint32) (match_making_types.Gathering, string, []uint64, types.DateTime, *nex.Error) { row := manager.Database.QueryRow(`SELECT owner_pid, host_pid, min_participants, max_participants, participation_policy, policy_argument, flags, state, description, type, participants, started_time FROM matchmaking.gatherings WHERE id=$1 AND registered=true`, id) var ownerPID uint64 @@ -28,6 +28,8 @@ func FindGatheringByID(manager *common_globals.MatchmakingManager, id uint32) (* var participants []uint64 var startedTime time.Time + gathering := match_making_types.NewGathering() + err := row.Scan( &ownerPID, &hostPID, @@ -44,23 +46,22 @@ func FindGatheringByID(manager *common_globals.MatchmakingManager, id uint32) (* ) if err != nil { if err == sql.ErrNoRows { - return nil, "", nil, nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, err.Error()) + return gathering, "", nil, types.NewDateTime(0), nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, err.Error()) } else { - return nil, "", nil, nil, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) + return gathering, "", nil, types.NewDateTime(0), nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } } - gathering := match_making_types.NewGathering() - gathering.ID.Value = id + gathering.ID = types.NewUInt32(id) gathering.OwnerPID = types.NewPID(ownerPID) gathering.HostPID = types.NewPID(hostPID) - gathering.MinimumParticipants.Value = minParticipants - gathering.MaximumParticipants.Value = maxParticipants - gathering.ParticipationPolicy.Value = participationPolicy - gathering.PolicyArgument.Value = policyArgument - gathering.Flags.Value = flags - gathering.State.Value = state - gathering.Description.Value = description + gathering.MinimumParticipants = types.NewUInt16(minParticipants) + gathering.MaximumParticipants = types.NewUInt16(maxParticipants) + gathering.ParticipationPolicy = types.NewUInt32(participationPolicy) + gathering.PolicyArgument = types.NewUInt32(policyArgument) + gathering.Flags = types.NewUInt32(flags) + gathering.State = types.NewUInt32(state) + gathering.Description = types.NewString(description) return gathering, gatheringType, participants, types.NewDateTime(0).FromTimestamp(startedTime), nil } diff --git a/match-making/database/join_gathering.go b/match-making/database/join_gathering.go index 667b593..79a191f 100644 --- a/match-making/database/join_gathering.go +++ b/match-making/database/join_gathering.go @@ -5,6 +5,7 @@ import ( "slices" "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/tracking" match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" @@ -38,7 +39,7 @@ func JoinGathering(manager *common_globals.MatchmakingManager, gatheringID uint3 return 0, nex.NewError(nex.ResultCodes.RendezVous.SessionFull, "change_error") } - if slices.Contains(participants, connection.PID().Value()) { + if slices.Contains(participants, uint64(connection.PID())) { return 0, nex.NewError(nex.ResultCodes.RendezVous.AlreadyParticipatedGathering, "change_error") } @@ -46,7 +47,7 @@ func JoinGathering(manager *common_globals.MatchmakingManager, gatheringID uint3 // * Additional participants are represented by duplicating the main participant PID on the array for range vacantParticipants { - newParticipants = append(newParticipants, connection.PID().Value()) + newParticipants = append(newParticipants, uint64(connection.PID())) } var totalParticipants []uint64 = append(newParticipants, participants...) @@ -74,7 +75,7 @@ func JoinGathering(manager *common_globals.MatchmakingManager, gatheringID uint3 } else { // * If the new participant is the same as the owner, then we are creating a new gathering. // * We don't need to send notification events in that case - if connection.PID().Value() == ownerPID { + if uint64(connection.PID()) == ownerPID { return uint32(len(totalParticipants)), nil } @@ -86,11 +87,11 @@ func JoinGathering(manager *common_globals.MatchmakingManager, gatheringID uint3 oEvent := notifications_types.NewNotificationEvent() oEvent.PIDSource = connection.PID() - oEvent.Type.Value = notifications.BuildNotificationType(notificationCategory, notificationSubtype) - oEvent.Param1.Value = gatheringID - oEvent.Param2.Value = uint32(connection.PID().LegacyValue()) // TODO - This assumes a legacy client. Will not work on the Switch - oEvent.StrParam.Value = joinMessage - oEvent.Param3.Value = uint32(len(totalParticipants)) + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype)) + oEvent.Param1 = types.NewUInt32(gatheringID) + oEvent.Param2 = types.NewUInt32(uint32(connection.PID())) // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.StrParam = types.NewString(joinMessage) + oEvent.Param3 = types.NewUInt32(uint32(len(totalParticipants))) common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, participantJoinedTargets) @@ -103,14 +104,14 @@ func JoinGathering(manager *common_globals.MatchmakingManager, gatheringID uint3 oEvent := notifications_types.NewNotificationEvent() oEvent.PIDSource = connection.PID() - oEvent.Type.Value = notifications.BuildNotificationType(notificationCategory, notificationSubtype) - oEvent.Param1.Value = gatheringID - oEvent.Param2.Value = uint32(participant) // TODO - This assumes a legacy client. Will not work on the Switch - oEvent.StrParam.Value = joinMessage - oEvent.Param3.Value = uint32(len(totalParticipants)) + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype)) + oEvent.Param1 = types.NewUInt32(gatheringID) + oEvent.Param2 = types.NewUInt32(uint32(participant)) // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.StrParam = types.NewString(joinMessage) + oEvent.Param3 = types.NewUInt32(uint32(len(totalParticipants))) // * Send the notification to the joining participant - common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, []uint64{connection.PID().Value()}) + common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, []uint64{uint64(connection.PID())}) } } diff --git a/match-making/database/join_gathering_with_participants.go b/match-making/database/join_gathering_with_participants.go index 3d32ce7..f40984a 100644 --- a/match-making/database/join_gathering_with_participants.go +++ b/match-making/database/join_gathering_with_participants.go @@ -16,7 +16,7 @@ import ( ) // JoinGatheringWithParticipants joins participants into a gathering. Returns the new number of participants -func JoinGatheringWithParticipants(manager *common_globals.MatchmakingManager, gatheringID uint32, connection *nex.PRUDPConnection, additionalParticipants []*types.PID, joinMessage string, joinMatchmakeSessionBehavior constants.JoinMatchmakeSessionBehavior) (uint32, *nex.Error) { +func JoinGatheringWithParticipants(manager *common_globals.MatchmakingManager, gatheringID uint32, connection *nex.PRUDPConnection, additionalParticipants []types.PID, joinMessage string, joinMatchmakeSessionBehavior constants.JoinMatchmakeSessionBehavior) (uint32, *nex.Error) { var ownerPID uint64 var maxParticipants uint32 var flags uint32 @@ -38,20 +38,20 @@ func JoinGatheringWithParticipants(manager *common_globals.MatchmakingManager, g // * If joinMatchmakeSessionBehavior is set to 1, we check if the caller is already joined into the session if joinMatchmakeSessionBehavior == constants.JoinMatchmakeSessionBehaviorImAlreadyJoined { - if !slices.Contains(oldParticipants, connection.PID().Value()) { + if !slices.Contains(oldParticipants, uint64(connection.PID())) { return 0, nex.NewError(nex.ResultCodes.RendezVous.NotParticipatedGathering, "change_error") } } else { - if slices.Contains(oldParticipants, connection.PID().Value()) { + if slices.Contains(oldParticipants, uint64(connection.PID())) { return 0, nex.NewError(nex.ResultCodes.RendezVous.AlreadyParticipatedGathering, "change_error") } // * Only include the caller as a new participant when they aren't joined - newParticipants = []uint64{connection.PID().Value()} + newParticipants = []uint64{uint64(connection.PID())} } for _, participant := range additionalParticipants { - newParticipants = append(newParticipants, participant.Value()) + newParticipants = append(newParticipants, uint64(participant)) } participants := append(oldParticipants, newParticipants...) @@ -80,7 +80,7 @@ func JoinGatheringWithParticipants(manager *common_globals.MatchmakingManager, g // * Send the switch SwitchGathering to the new participants first for _, participant := range common_globals.RemoveDuplicates(newParticipants) { // * Don't send the SwitchGathering notification to the participant that requested the join - if connection.PID().Value() == uint64(participant) { + if uint64(connection.PID()) == participant { continue } @@ -89,9 +89,9 @@ func JoinGatheringWithParticipants(manager *common_globals.MatchmakingManager, g oEvent := notifications_types.NewNotificationEvent() oEvent.PIDSource = connection.PID() - oEvent.Type.Value = notifications.BuildNotificationType(notificationCategory, notificationSubtype) - oEvent.Param1.Value = gatheringID - oEvent.Param2.Value = uint32(participant) // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype)) + oEvent.Param1 = types.NewUInt32(gatheringID) + oEvent.Param2 = types.NewUInt32(uint32(participant)) // TODO - This assumes a legacy client. Will not work on the Switch // * Send the notification to the participant common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, []uint64{participant}) @@ -100,17 +100,17 @@ func JoinGatheringWithParticipants(manager *common_globals.MatchmakingManager, g for _, participant := range newParticipants { // * If the new participant is the same as the owner, then we are creating a new gathering. // * We don't need to send the new participant notification event in that case - if flags & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 || connection.PID().Value() != ownerPID { + if flags & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 || uint64(connection.PID()) != ownerPID { notificationCategory := notifications.NotificationCategories.Participation notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant oEvent := notifications_types.NewNotificationEvent() oEvent.PIDSource = connection.PID() - oEvent.Type.Value = notifications.BuildNotificationType(notificationCategory, notificationSubtype) - oEvent.Param1.Value = gatheringID - oEvent.Param2.Value = uint32(participant) // TODO - This assumes a legacy client. Will not work on the Switch - oEvent.StrParam.Value = joinMessage - oEvent.Param3.Value = uint32(len(participants)) + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype)) + oEvent.Param1 = types.NewUInt32(gatheringID) + oEvent.Param2 = types.NewUInt32(uint32(participant)) // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.StrParam = types.NewString(joinMessage) + oEvent.Param3 = types.NewUInt32(uint32(len(participants))) common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, participantJoinedTargets) } @@ -124,11 +124,11 @@ func JoinGatheringWithParticipants(manager *common_globals.MatchmakingManager, g oEvent := notifications_types.NewNotificationEvent() oEvent.PIDSource = connection.PID() - oEvent.Type.Value = notifications.BuildNotificationType(notificationCategory, notificationSubtype) - oEvent.Param1.Value = gatheringID - oEvent.Param2.Value = uint32(oldParticipant) // TODO - This assumes a legacy client. Will not work on the Switch - oEvent.StrParam.Value = joinMessage - oEvent.Param3.Value = uint32(len(participants)) + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype)) + oEvent.Param1 = types.NewUInt32(gatheringID) + oEvent.Param2 = types.NewUInt32(uint32(oldParticipant)) // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.StrParam = types.NewString(joinMessage) + oEvent.Param3 = types.NewUInt32(uint32(len(participants))) // * Send the notification to the joining participant common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, []uint64{participant}) diff --git a/match-making/database/migrate_gathering_ownership.go b/match-making/database/migrate_gathering_ownership.go index 8aecfb3..ff1c573 100644 --- a/match-making/database/migrate_gathering_ownership.go +++ b/match-making/database/migrate_gathering_ownership.go @@ -11,12 +11,12 @@ import ( ) // MigrateGatheringOwnership switches the owner of the gathering with a different one -func MigrateGatheringOwnership(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection, gathering *match_making_types.Gathering, participants []uint64) (uint64, *nex.Error) { +func MigrateGatheringOwnership(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection, gathering match_making_types.Gathering, participants []uint64) (uint64, *nex.Error) { var nexError *nex.Error var uniqueParticipants []uint64 = common_globals.RemoveDuplicates(participants) var newOwner uint64 for _, participant := range uniqueParticipants { - if participant != gathering.OwnerPID.Value() { + if participant != uint64(gathering.OwnerPID) { newOwner = participant break } @@ -24,7 +24,7 @@ func MigrateGatheringOwnership(manager *common_globals.MatchmakingManager, conne // * We couldn't find a new owner, so we unregister the gathering if newOwner == 0 { - nexError = UnregisterGathering(manager, connection.PID(), gathering.ID.Value) + nexError = UnregisterGathering(manager, connection.PID(), uint32(gathering.ID)) if nexError != nil { return 0, nexError } @@ -33,25 +33,25 @@ func MigrateGatheringOwnership(manager *common_globals.MatchmakingManager, conne subtype := notifications.NotificationSubTypes.GatheringUnregistered.None oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = connection.PID().Copy().(*types.PID) - oEvent.Type.Value = notifications.BuildNotificationType(category, subtype) - oEvent.Param1.Value = gathering.ID.Value + oEvent.PIDSource = connection.PID().Copy().(types.PID) + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = gathering.ID common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, uniqueParticipants) return 0, nil } - oldOwner := gathering.OwnerPID.Copy().(*types.PID) + oldOwner := gathering.OwnerPID.Copy().(types.PID) // * Set the new owner gathering.OwnerPID = types.NewPID(newOwner) - nexError = UpdateSessionHost(manager, gathering.ID.Value, gathering.OwnerPID, gathering.HostPID) + nexError = UpdateSessionHost(manager, uint32(gathering.ID), gathering.OwnerPID, gathering.HostPID) if nexError != nil { return 0, nexError } - nexError = tracking.LogChangeOwner(manager.Database, connection.PID(), gathering.ID.Value, oldOwner, gathering.OwnerPID) + nexError = tracking.LogChangeOwner(manager.Database, connection.PID(), uint32(gathering.ID), oldOwner, gathering.OwnerPID) if nexError != nil { return 0, nexError } @@ -60,10 +60,10 @@ func MigrateGatheringOwnership(manager *common_globals.MatchmakingManager, conne subtype := notifications.NotificationSubTypes.OwnershipChanged.None oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = connection.PID().Copy().(*types.PID) - oEvent.Type.Value = notifications.BuildNotificationType(category, subtype) - oEvent.Param1.Value = gathering.ID.Value - oEvent.Param2.Value = uint32(newOwner) // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.PIDSource = connection.PID().Copy().(types.PID) + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = gathering.ID + oEvent.Param2 = types.NewUInt32(uint32(newOwner)) // TODO - This assumes a legacy client. Will not work on the Switch // TODO - StrParam doesn't have this value on some servers // * https://github.com/kinnay/NintendoClients/issues/101 diff --git a/match-making/database/register_gathering.go b/match-making/database/register_gathering.go index 43610f9..8178050 100644 --- a/match-making/database/register_gathering.go +++ b/match-making/database/register_gathering.go @@ -9,8 +9,9 @@ import ( ) // RegisterGathering registers a new gathering on the databse. No participants are added -func RegisterGathering(manager *common_globals.MatchmakingManager, pid *types.PID, gathering *match_making_types.Gathering, gatheringType string) (*types.DateTime, *nex.Error) { +func RegisterGathering(manager *common_globals.MatchmakingManager, pid types.PID, gathering *match_making_types.Gathering, gatheringType string) (types.DateTime, *nex.Error) { startedTime := types.NewDateTime(0).Now() + var gatheringID uint32 err := manager.Database.QueryRow(`INSERT INTO matchmaking.gatherings ( owner_pid, @@ -37,29 +38,31 @@ func RegisterGathering(manager *common_globals.MatchmakingManager, pid *types.PI $10, $11 ) RETURNING id`, - pid.Value(), - pid.Value(), - gathering.MinimumParticipants.Value, - gathering.MaximumParticipants.Value, - gathering.ParticipationPolicy.Value, - gathering.PolicyArgument.Value, - gathering.Flags.Value, - gathering.State.Value, - gathering.Description.Value, + pid, + pid, + uint16(gathering.MinimumParticipants), + uint16(gathering.MaximumParticipants), + uint32(gathering.ParticipationPolicy), + uint32(gathering.PolicyArgument), + uint32(gathering.Flags), + uint32(gathering.State), + string(gathering.Description), gatheringType, startedTime.Standard(), - ).Scan(&gathering.ID.Value) + ).Scan(&gatheringID) if err != nil { - return nil, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) + return types.NewDateTime(0), nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } - nexError := tracking.LogRegisterGathering(manager.Database, pid, gathering.ID.Value) + gathering.ID = types.NewUInt32(gatheringID) + + nexError := tracking.LogRegisterGathering(manager.Database, pid, uint32(gathering.ID)) if nexError != nil { - return nil, nexError + return types.NewDateTime(0), nexError } - gathering.OwnerPID = pid.Copy().(*types.PID) - gathering.HostPID = pid.Copy().(*types.PID) + gathering.OwnerPID = pid + gathering.HostPID = pid return startedTime, nil } diff --git a/match-making/database/unregister_gathering.go b/match-making/database/unregister_gathering.go index 4696a4b..58a00b4 100644 --- a/match-making/database/unregister_gathering.go +++ b/match-making/database/unregister_gathering.go @@ -8,7 +8,7 @@ import ( ) // UnregisterGathering unregisters a given gathering on a database -func UnregisterGathering(manager *common_globals.MatchmakingManager, sourcePID *types.PID, id uint32) *nex.Error { +func UnregisterGathering(manager *common_globals.MatchmakingManager, sourcePID types.PID, id uint32) *nex.Error { result, err := manager.Database.Exec(`UPDATE matchmaking.gatherings SET registered=false WHERE id=$1`, id) if err != nil { return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) diff --git a/match-making/database/update_session_host.go b/match-making/database/update_session_host.go index 2871408..d5b46cf 100644 --- a/match-making/database/update_session_host.go +++ b/match-making/database/update_session_host.go @@ -7,8 +7,8 @@ import ( ) // UpdateSessionHost updates the owner and host PID of the session -func UpdateSessionHost(manager *common_globals.MatchmakingManager, gatheringID uint32, ownerPID *types.PID, hostPID *types.PID) *nex.Error { - result, err := manager.Database.Exec(`UPDATE matchmaking.gatherings SET owner_pid=$1, host_pid=$2 WHERE id=$3`, ownerPID.Value(), hostPID.Value(), gatheringID) +func UpdateSessionHost(manager *common_globals.MatchmakingManager, gatheringID uint32, ownerPID types.PID, hostPID types.PID) *nex.Error { + result, err := manager.Database.Exec(`UPDATE matchmaking.gatherings SET owner_pid=$1, host_pid=$2 WHERE id=$3`, ownerPID, hostPID, gatheringID) if err != nil { return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } diff --git a/match-making/find_by_single_id.go b/match-making/find_by_single_id.go index f21bfc8..101f8f4 100644 --- a/match-making/find_by_single_id.go +++ b/match-making/find_by_single_id.go @@ -5,9 +5,10 @@ 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.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) findBySingleID(err error, packet nex.PacketInterface, callID uint32, id types.UInt32) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -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, id.Value) + gathering, _, nexError := commonProtocol.manager.GetDetailedGatheringByID(commonProtocol.manager, uint32(id)) if nexError != nil { commonProtocol.manager.Mutex.RUnlock() return nil, nexError @@ -26,11 +27,9 @@ func (commonProtocol *CommonProtocol) findBySingleID(err error, packet nex.Packe commonProtocol.manager.Mutex.RUnlock() - bResult := types.NewPrimitiveBool(true) - pGathering := types.NewAnyDataHolder() - - pGathering.TypeName = types.NewString(gatheringType) - pGathering.ObjectData = gathering.Copy() + bResult := types.NewBool(true) + pGathering := match_making_types.NewGatheringHolder() + pGathering.Object = gathering.Copy().(match_making_types.GatheringInterface) rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/match-making/get_session_urls.go b/match-making/get_session_urls.go index ba98df2..038d835 100644 --- a/match-making/get_session_urls.go +++ b/match-making/get_session_urls.go @@ -10,14 +10,14 @@ import ( match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" ) -func (commonProtocol *CommonProtocol) getSessionURLs(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) getSessionURLs(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } commonProtocol.manager.Mutex.RLock() - gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, gid.Value) + gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, uint32(gid)) if nexError != nil { commonProtocol.manager.Mutex.RUnlock() return nil, nexError @@ -26,12 +26,12 @@ func (commonProtocol *CommonProtocol) getSessionURLs(err error, packet nex.Packe connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) - if !slices.Contains(participants, connection.PID().Value()) { + if !slices.Contains(participants, uint64(connection.PID())) { commonProtocol.manager.Mutex.RUnlock() return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } - host := endpoint.FindConnectionByPID(gathering.HostPID.Value()) + host := endpoint.FindConnectionByPID(uint64(gathering.HostPID)) commonProtocol.manager.Mutex.RUnlock() @@ -40,8 +40,7 @@ func (commonProtocol *CommonProtocol) getSessionURLs(err error, packet nex.Packe // * If no host was found, return an empty list of station URLs if host == nil { common_globals.Logger.Error("Host client not found") - stationURLs := types.NewList[*types.StationURL]() - stationURLs.Type = types.NewStationURL("") + stationURLs := types.NewList[types.StationURL]() stationURLs.WriteTo(rmcResponseStream) } else { host.StationURLs.WriteTo(rmcResponseStream) diff --git a/match-making/protocol.go b/match-making/protocol.go index a6c923e..fb94a38 100644 --- a/match-making/protocol.go +++ b/match-making/protocol.go @@ -13,12 +13,12 @@ type CommonProtocol struct { endpoint *nex.PRUDPEndPoint protocol match_making.Interface manager *common_globals.MatchmakingManager - OnAfterUnregisterGathering func(packet nex.PacketInterface, idGathering *types.PrimitiveU32) - OnAfterFindBySingleID func(packet nex.PacketInterface, id *types.PrimitiveU32) - OnAfterUpdateSessionURL func(packet nex.PacketInterface, idGathering *types.PrimitiveU32, strURL *types.String) - OnAfterUpdateSessionHostV1 func(packet nex.PacketInterface, gid *types.PrimitiveU32) - OnAfterGetSessionURLs func(packet nex.PacketInterface, gid *types.PrimitiveU32) - OnAfterUpdateSessionHost func(packet nex.PacketInterface, gid *types.PrimitiveU32, isMigrateOwner *types.PrimitiveBool) + OnAfterUnregisterGathering func(packet nex.PacketInterface, idGathering types.UInt32) + OnAfterFindBySingleID func(packet nex.PacketInterface, id types.UInt32) + OnAfterUpdateSessionURL func(packet nex.PacketInterface, idGathering types.UInt32, strURL types.String) + OnAfterUpdateSessionHostV1 func(packet nex.PacketInterface, gid types.UInt32) + OnAfterGetSessionURLs func(packet nex.PacketInterface, gid types.UInt32) + OnAfterUpdateSessionHost func(packet nex.PacketInterface, gid types.UInt32, isMigrateOwner types.Bool) } // SetManager defines the matchmaking manager to be used by the common protocol diff --git a/match-making/tracking/log_change_host.go b/match-making/tracking/log_change_host.go index 44b3278..14e9af6 100644 --- a/match-making/tracking/log_change_host.go +++ b/match-making/tracking/log_change_host.go @@ -9,7 +9,7 @@ import ( ) // LogChangeHost logs a host change event on the given database -func LogChangeHost(db *sql.DB, sourcePID *types.PID, gatheringID uint32, oldHostPID *types.PID, newHostPID *types.PID) *nex.Error { +func LogChangeHost(db *sql.DB, sourcePID types.PID, gatheringID uint32, oldHostPID types.PID, newHostPID types.PID) *nex.Error { eventTime := time.Now().UTC() _, err := db.Exec(`INSERT INTO tracking.change_host ( @@ -24,7 +24,7 @@ func LogChangeHost(db *sql.DB, sourcePID *types.PID, gatheringID uint32, oldHost $3, $4, $5 - )`, eventTime, sourcePID.Value(), gatheringID, oldHostPID.Value(), newHostPID.Value()) + )`, eventTime, sourcePID, gatheringID, oldHostPID, newHostPID) if err != nil { return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } diff --git a/match-making/tracking/log_change_owner.go b/match-making/tracking/log_change_owner.go index 8555056..d050725 100644 --- a/match-making/tracking/log_change_owner.go +++ b/match-making/tracking/log_change_owner.go @@ -9,7 +9,7 @@ import ( ) // LogChangeOwner logs an owner change event on the given database -func LogChangeOwner(db *sql.DB, sourcePID *types.PID, gatheringID uint32, oldOwnerPID *types.PID, newOwnerPID *types.PID) *nex.Error { +func LogChangeOwner(db *sql.DB, sourcePID types.PID, gatheringID uint32, oldOwnerPID types.PID, newOwnerPID types.PID) *nex.Error { eventTime := time.Now().UTC() _, err := db.Exec(`INSERT INTO tracking.change_owner ( @@ -24,7 +24,7 @@ func LogChangeOwner(db *sql.DB, sourcePID *types.PID, gatheringID uint32, oldOwn $3, $4, $5 - )`, eventTime, sourcePID.Value(), gatheringID, oldOwnerPID.Value(), newOwnerPID.Value()) + )`, eventTime, sourcePID, gatheringID, oldOwnerPID, newOwnerPID) if err != nil { return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } diff --git a/match-making/tracking/log_disconnect_gathering.go b/match-making/tracking/log_disconnect_gathering.go index 284bb47..cfb1c96 100644 --- a/match-making/tracking/log_disconnect_gathering.go +++ b/match-making/tracking/log_disconnect_gathering.go @@ -10,7 +10,7 @@ import ( ) // LogDisconnectGathering logs a gathering disconnect event on the given database -func LogDisconnectGathering(db *sql.DB, pid *types.PID, gatheringID uint32, totalParticipants []uint64) *nex.Error { +func LogDisconnectGathering(db *sql.DB, pid types.PID, gatheringID uint32, totalParticipants []uint64) *nex.Error { eventTime := time.Now().UTC() _, err := db.Exec(`INSERT INTO tracking.disconnect_gathering ( @@ -23,7 +23,7 @@ func LogDisconnectGathering(db *sql.DB, pid *types.PID, gatheringID uint32, tota $2, $3, $4 - )`, eventTime, pid.Value(), gatheringID, pqextended.Array(totalParticipants)) + )`, eventTime, pid, gatheringID, pqextended.Array(totalParticipants)) if err != nil { return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } diff --git a/match-making/tracking/log_join_gathering.go b/match-making/tracking/log_join_gathering.go index 7fb8de4..afdd041 100644 --- a/match-making/tracking/log_join_gathering.go +++ b/match-making/tracking/log_join_gathering.go @@ -10,7 +10,7 @@ import ( ) // LogJoinGathering logs a gathering join event on the given database -func LogJoinGathering(db *sql.DB, sourcePID *types.PID, gatheringID uint32, newParticipants []uint64, totalParticipants []uint64) *nex.Error { +func LogJoinGathering(db *sql.DB, sourcePID types.PID, gatheringID uint32, newParticipants []uint64, totalParticipants []uint64) *nex.Error { eventTime := time.Now().UTC() _, err := db.Exec(`INSERT INTO tracking.join_gathering ( @@ -25,7 +25,7 @@ func LogJoinGathering(db *sql.DB, sourcePID *types.PID, gatheringID uint32, newP $3, $4, $5 - )`, eventTime, sourcePID.Value(), gatheringID, pqextended.Array(newParticipants), pqextended.Array(totalParticipants)) + )`, eventTime, sourcePID, gatheringID, pqextended.Array(newParticipants), pqextended.Array(totalParticipants)) if err != nil { return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } diff --git a/match-making/tracking/log_leave_gathering.go b/match-making/tracking/log_leave_gathering.go index 28bc2f5..6c4f666 100644 --- a/match-making/tracking/log_leave_gathering.go +++ b/match-making/tracking/log_leave_gathering.go @@ -10,7 +10,7 @@ import ( ) // LogLeaveGathering logs a gathering leave event on the given database -func LogLeaveGathering(db *sql.DB, pid *types.PID, gatheringID uint32, totalParticipants []uint64) *nex.Error { +func LogLeaveGathering(db *sql.DB, pid types.PID, gatheringID uint32, totalParticipants []uint64) *nex.Error { eventTime := time.Now().UTC() _, err := db.Exec(`INSERT INTO tracking.leave_gathering ( @@ -23,7 +23,7 @@ func LogLeaveGathering(db *sql.DB, pid *types.PID, gatheringID uint32, totalPart $2, $3, $4 - )`, eventTime, pid.Value(), gatheringID, pqextended.Array(totalParticipants)) + )`, eventTime, pid, gatheringID, pqextended.Array(totalParticipants)) if err != nil { return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } diff --git a/match-making/tracking/log_register_gathering.go b/match-making/tracking/log_register_gathering.go index c3790c4..4cb1ec4 100644 --- a/match-making/tracking/log_register_gathering.go +++ b/match-making/tracking/log_register_gathering.go @@ -9,7 +9,7 @@ import ( ) // LogRegisterGathering logs a gathering registration event on the given database -func LogRegisterGathering(db *sql.DB, sourcePID *types.PID, gatheringID uint32) *nex.Error { +func LogRegisterGathering(db *sql.DB, sourcePID types.PID, gatheringID uint32) *nex.Error { eventTime := time.Now().UTC() _, err := db.Exec(`INSERT INTO tracking.register_gathering ( @@ -20,7 +20,7 @@ func LogRegisterGathering(db *sql.DB, sourcePID *types.PID, gatheringID uint32) $1, $2, $3 - )`, eventTime, sourcePID.Value(), gatheringID) + )`, eventTime, sourcePID, gatheringID) if err != nil { return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } diff --git a/match-making/tracking/log_unregister_gathering.go b/match-making/tracking/log_unregister_gathering.go index b046294..15117fe 100644 --- a/match-making/tracking/log_unregister_gathering.go +++ b/match-making/tracking/log_unregister_gathering.go @@ -9,7 +9,7 @@ import ( ) // LogUnregisterGathering logs a gathering registration event on the given database -func LogUnregisterGathering(db *sql.DB, sourcePID *types.PID, gatheringID uint32) *nex.Error { +func LogUnregisterGathering(db *sql.DB, sourcePID types.PID, gatheringID uint32) *nex.Error { eventTime := time.Now().UTC() _, err := db.Exec(`INSERT INTO tracking.unregister_gathering ( @@ -20,7 +20,7 @@ func LogUnregisterGathering(db *sql.DB, sourcePID *types.PID, gatheringID uint32 $1, $2, $3 - )`, eventTime, sourcePID.Value(), gatheringID) + )`, eventTime, sourcePID, gatheringID) if err != nil { return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } diff --git a/match-making/unregister_gathering.go b/match-making/unregister_gathering.go index 84368b9..421fc68 100644 --- a/match-making/unregister_gathering.go +++ b/match-making/unregister_gathering.go @@ -10,14 +10,14 @@ import ( notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" ) -func (commonProtocol *CommonProtocol) unregisterGathering(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) unregisterGathering(err error, packet nex.PacketInterface, callID uint32, idGathering types.UInt32) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } commonProtocol.manager.Mutex.Lock() - gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, idGathering.Value) + gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, uint32(idGathering)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -31,7 +31,7 @@ func (commonProtocol *CommonProtocol) unregisterGathering(err error, packet nex. return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } - nexError = database.UnregisterGathering(commonProtocol.manager, connection.PID(), idGathering.Value) + nexError = database.UnregisterGathering(commonProtocol.manager, connection.PID(), uint32(idGathering)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -41,15 +41,15 @@ func (commonProtocol *CommonProtocol) unregisterGathering(err error, packet nex. subtype := notifications.NotificationSubTypes.GatheringUnregistered.None oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = connection.PID().Copy().(*types.PID) - oEvent.Type.Value = notifications.BuildNotificationType(category, subtype) - oEvent.Param1.Value = idGathering.Value + oEvent.PIDSource = connection.PID().Copy().(types.PID) + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = idGathering common_globals.SendNotificationEvent(endpoint, oEvent, common_globals.RemoveDuplicates(participants)) commonProtocol.manager.Mutex.Unlock() - retval := types.NewPrimitiveBool(true) + retval := types.NewBool(true) rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/match-making/update_session_host.go b/match-making/update_session_host.go index 5303876..24e6744 100644 --- a/match-making/update_session_host.go +++ b/match-making/update_session_host.go @@ -13,14 +13,14 @@ import ( notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" ) -func (commonProtocol *CommonProtocol) updateSessionHost(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, isMigrateOwner *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) updateSessionHost(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32, isMigrateOwner types.Bool) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } commonProtocol.manager.Mutex.Lock() - gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, gid.Value) + gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, uint32(gid)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -29,42 +29,42 @@ func (commonProtocol *CommonProtocol) updateSessionHost(err error, packet nex.Pa connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) - if !slices.Contains(participants, connection.PID().Value()) { + if !slices.Contains(participants, uint64(connection.PID())) { commonProtocol.manager.Mutex.Unlock() return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } - if !isMigrateOwner.Value { - nexError = database.UpdateSessionHost(commonProtocol.manager, gid.Value, gathering.OwnerPID, connection.PID()) + if !isMigrateOwner { + nexError = database.UpdateSessionHost(commonProtocol.manager, uint32(gid), gathering.OwnerPID, connection.PID()) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } - nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), gid.Value, gathering.HostPID, connection.PID()) + nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), uint32(gid), gathering.HostPID, connection.PID()) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } } else { - if gathering.Flags.PAND(match_making.GatheringFlags.ParticipantsChangeOwner) == 0 { + if uint32(gathering.Flags) & match_making.GatheringFlags.ParticipantsChangeOwner == 0 { commonProtocol.manager.Mutex.Unlock() return nil, nex.NewError(nex.ResultCodes.RendezVous.InvalidOperation, "change_error") } - nexError = database.UpdateSessionHost(commonProtocol.manager, gid.Value, connection.PID(), connection.PID()) + nexError = database.UpdateSessionHost(commonProtocol.manager, uint32(gid), connection.PID(), connection.PID()) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } - nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), gid.Value, gathering.HostPID, connection.PID()) + nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), uint32(gid), gathering.HostPID, connection.PID()) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } - nexError = tracking.LogChangeOwner(commonProtocol.manager.Database, connection.PID(), gid.Value, gathering.OwnerPID, connection.PID()) + nexError = tracking.LogChangeOwner(commonProtocol.manager.Database, connection.PID(), uint32(gid), gathering.OwnerPID, connection.PID()) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -75,9 +75,9 @@ func (commonProtocol *CommonProtocol) updateSessionHost(err error, packet nex.Pa oEvent := notifications_types.NewNotificationEvent() oEvent.PIDSource = connection.PID() - oEvent.Type.Value = notifications.BuildNotificationType(category, subtype) - oEvent.Param1.Value = gid.Value - oEvent.Param2.Value = connection.PID().LegacyValue() // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = gid + oEvent.Param2 = types.NewUInt32(uint32(connection.PID())) // TODO - This assumes a legacy client. Will not work on the Switch // TODO - StrParam doesn't have this value on some servers // * https://github.com/kinnay/NintendoClients/issues/101 diff --git a/match-making/update_session_host_v1.go b/match-making/update_session_host_v1.go index a6e3722..3cfa1b8 100644 --- a/match-making/update_session_host_v1.go +++ b/match-making/update_session_host_v1.go @@ -13,7 +13,7 @@ import ( notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" ) -func (commonProtocol *CommonProtocol) updateSessionHostV1(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) updateSessionHostV1(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -21,7 +21,7 @@ func (commonProtocol *CommonProtocol) updateSessionHostV1(err error, packet nex. commonProtocol.manager.Mutex.Lock() - gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, gid.Value) + gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, uint32(gid)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -30,37 +30,37 @@ func (commonProtocol *CommonProtocol) updateSessionHostV1(err error, packet nex. connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) - if !slices.Contains(participants, connection.PID().Value()) { + if !slices.Contains(participants, uint64(connection.PID())) { commonProtocol.manager.Mutex.Unlock() return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } - if gathering.Flags.PAND(match_making.GatheringFlags.ParticipantsChangeOwner) == 0 { - nexError = database.UpdateSessionHost(commonProtocol.manager, gid.Value, gathering.OwnerPID, connection.PID()) + if uint32(gathering.Flags) & match_making.GatheringFlags.ParticipantsChangeOwner == 0 { + nexError = database.UpdateSessionHost(commonProtocol.manager, uint32(gid), gathering.OwnerPID, connection.PID()) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } - nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), gid.Value, gathering.HostPID, connection.PID()) + nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), uint32(gid), gathering.HostPID, connection.PID()) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } } else { - nexError = database.UpdateSessionHost(commonProtocol.manager, gid.Value, connection.PID(), connection.PID()) + nexError = database.UpdateSessionHost(commonProtocol.manager, uint32(gid), connection.PID(), connection.PID()) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } - nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), gid.Value, gathering.HostPID, connection.PID()) + nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), uint32(gid), gathering.HostPID, connection.PID()) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } - nexError = tracking.LogChangeOwner(commonProtocol.manager.Database, connection.PID(), gid.Value, gathering.OwnerPID, connection.PID()) + nexError = tracking.LogChangeOwner(commonProtocol.manager.Database, connection.PID(), uint32(gid), gathering.OwnerPID, connection.PID()) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -71,9 +71,9 @@ func (commonProtocol *CommonProtocol) updateSessionHostV1(err error, packet nex. oEvent := notifications_types.NewNotificationEvent() oEvent.PIDSource = connection.PID() - oEvent.Type.Value = notifications.BuildNotificationType(category, subtype) - oEvent.Param1.Value = gid.Value - oEvent.Param2.Value = connection.PID().LegacyValue() // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = gid + oEvent.Param2 = types.NewUInt32(uint32(connection.PID())) // TODO - This assumes a legacy client. Will not work on the Switch // TODO - StrParam doesn't have this value on some servers // * https://github.com/kinnay/NintendoClients/issues/101 diff --git a/match-making/update_session_url.go b/match-making/update_session_url.go index e4e66c0..7a516f1 100644 --- a/match-making/update_session_url.go +++ b/match-making/update_session_url.go @@ -11,14 +11,14 @@ import ( match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" ) -func (commonProtocol *CommonProtocol) updateSessionURL(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strURL *types.String) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) updateSessionURL(err error, packet nex.PacketInterface, callID uint32, idGathering types.UInt32, strURL types.String) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } commonProtocol.manager.Mutex.Lock() - gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, idGathering.Value) + gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, uint32(idGathering)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -27,7 +27,7 @@ func (commonProtocol *CommonProtocol) updateSessionURL(err error, packet nex.Pac connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) - if !slices.Contains(participants, connection.PID().Value()) { + if !slices.Contains(participants, uint64(connection.PID())) { commonProtocol.manager.Mutex.Unlock() return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } @@ -35,13 +35,13 @@ func (commonProtocol *CommonProtocol) updateSessionURL(err error, packet nex.Pac // TODO - Mario Kart 7 seems to set an empty strURL. What does that do if it's actually set? // * Only update the host - nexError = database.UpdateSessionHost(commonProtocol.manager, idGathering.Value, gathering.OwnerPID, connection.PID()) + nexError = database.UpdateSessionHost(commonProtocol.manager, uint32(idGathering), gathering.OwnerPID, connection.PID()) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } - nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), idGathering.Value, gathering.HostPID, connection.PID()) + nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), uint32(idGathering), gathering.HostPID, connection.PID()) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -49,7 +49,7 @@ func (commonProtocol *CommonProtocol) updateSessionURL(err error, packet nex.Pac commonProtocol.manager.Mutex.Unlock() - retval := types.NewPrimitiveBool(true) + retval := types.NewBool(true) rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/matchmake-extension/auto_matchmake_postpone.go b/matchmake-extension/auto_matchmake_postpone.go index 9b1e2cb..39dd7f7 100644 --- a/matchmake-extension/auto_matchmake_postpone.go +++ b/matchmake-extension/auto_matchmake_postpone.go @@ -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") @@ -21,7 +21,7 @@ func (commonProtocol *CommonProtocol) autoMatchmakePostpone(err error, packet ne return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } - if len(message.Value) > 256 { + if len(message) > 256 { return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } @@ -34,11 +34,10 @@ func (commonProtocol *CommonProtocol) autoMatchmakePostpone(err error, packet ne // * so let's make sure the client is removed from the session database.EndMatchmakeSessionsParticipation(commonProtocol.manager, connection) - var matchmakeSession *match_making_types.MatchmakeSession - anyGatheringDataType := anyGathering.TypeName + var matchmakeSession match_making_types.MatchmakeSession - if anyGatheringDataType.Value == "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() @@ -50,8 +49,8 @@ func (commonProtocol *CommonProtocol) autoMatchmakePostpone(err error, packet ne return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } - searchMatchmakeSession := matchmakeSession.Copy().(*match_making_types.MatchmakeSession) - commonProtocol.CleanupSearchMatchmakeSession(searchMatchmakeSession) + searchMatchmakeSession := matchmakeSession.Copy().(match_making_types.MatchmakeSession) + commonProtocol.CleanupSearchMatchmakeSession(&searchMatchmakeSession) resultSession, nexError := database.FindMatchmakeSession(commonProtocol.manager, connection, searchMatchmakeSession) if nexError != nil { commonProtocol.manager.Mutex.Unlock() @@ -59,7 +58,8 @@ func (commonProtocol *CommonProtocol) autoMatchmakePostpone(err error, packet ne } if resultSession == nil { - resultSession = searchMatchmakeSession.Copy().(*match_making_types.MatchmakeSession) + newMatchmakeSession := searchMatchmakeSession.Copy().(match_making_types.MatchmakeSession) + resultSession = &newMatchmakeSession nexError = database.CreateMatchmakeSession(commonProtocol.manager, connection, resultSession) if nexError != nil { common_globals.Logger.Error(nexError.Error()) @@ -68,20 +68,18 @@ func (commonProtocol *CommonProtocol) autoMatchmakePostpone(err error, packet ne } } - participants, nexError := match_making_database.JoinGathering(commonProtocol.manager, resultSession.Gathering.ID.Value, connection, 1, message.Value) + participants, nexError := match_making_database.JoinGathering(commonProtocol.manager, uint32(resultSession.Gathering.ID), connection, 1, string(message)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } - resultSession.ParticipationCount.Value = participants + resultSession.ParticipationCount = types.NewUInt32(participants) 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()) diff --git a/matchmake-extension/auto_matchmake_with_param_postpone.go b/matchmake-extension/auto_matchmake_with_param_postpone.go index d1469f7..97d3ffb 100644 --- a/matchmake-extension/auto_matchmake_with_param_postpone.go +++ b/matchmake-extension/auto_matchmake_with_param_postpone.go @@ -11,7 +11,7 @@ import ( matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func (commonProtocol *CommonProtocol) autoMatchmakeWithParamPostpone(err error, packet nex.PacketInterface, callID uint32, autoMatchmakeParam *match_making_types.AutoMatchmakeParam) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) autoMatchmakeWithParamPostpone(err error, packet nex.PacketInterface, callID uint32, autoMatchmakeParam match_making_types.AutoMatchmakeParam) (*nex.RMCMessage, *nex.Error) { if commonProtocol.CleanupMatchmakeSessionSearchCriterias == nil { common_globals.Logger.Warning("MatchmakeExtension::AutoMatchmakeWithParam_Postpone missing CleanupMatchmakeSessionSearchCriterias!") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -26,7 +26,7 @@ func (commonProtocol *CommonProtocol) autoMatchmakeWithParamPostpone(err error, return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } - if len(autoMatchmakeParam.JoinMessage.Value) > 256 { + if len(autoMatchmakeParam.JoinMessage) > 256 { return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } @@ -35,9 +35,9 @@ func (commonProtocol *CommonProtocol) autoMatchmakeWithParamPostpone(err error, commonProtocol.manager.Mutex.Lock() - if autoMatchmakeParam.GIDForParticipationCheck.Value != 0 { + if autoMatchmakeParam.GIDForParticipationCheck != 0 { // * Check that all new participants are participating in the specified gathering ID - nexError := database.CheckGatheringForParticipation(commonProtocol.manager, autoMatchmakeParam.GIDForParticipationCheck.Value, append(autoMatchmakeParam.AdditionalParticipants.Slice(), connection.PID())) + nexError := database.CheckGatheringForParticipation(commonProtocol.manager, uint32(autoMatchmakeParam.GIDForParticipationCheck), append(autoMatchmakeParam.AdditionalParticipants, connection.PID())) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -51,17 +51,17 @@ func (commonProtocol *CommonProtocol) autoMatchmakeWithParamPostpone(err error, commonProtocol.CleanupMatchmakeSessionSearchCriterias(autoMatchmakeParam.LstSearchCriteria) resultRange := types.NewResultRange() - resultRange.Length.Value = 1 - resultSessions, nexError := database.FindMatchmakeSessionBySearchCriteria(commonProtocol.manager, connection, autoMatchmakeParam.LstSearchCriteria.Slice(), resultRange, autoMatchmakeParam.SourceMatchmakeSession) + resultRange.Length = 1 + resultSessions, nexError := database.FindMatchmakeSessionBySearchCriteria(commonProtocol.manager, connection, autoMatchmakeParam.LstSearchCriteria, resultRange, &autoMatchmakeParam.SourceMatchmakeSession) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } - var resultSession *match_making_types.MatchmakeSession + var resultSession match_making_types.MatchmakeSession if len(resultSessions) == 0 { - resultSession = autoMatchmakeParam.SourceMatchmakeSession.Copy().(*match_making_types.MatchmakeSession) - nexError = database.CreateMatchmakeSession(commonProtocol.manager, connection, resultSession) + resultSession = autoMatchmakeParam.SourceMatchmakeSession.Copy().(match_making_types.MatchmakeSession) + nexError = database.CreateMatchmakeSession(commonProtocol.manager, connection, &resultSession) if nexError != nil { common_globals.Logger.Error(nexError.Error()) commonProtocol.manager.Mutex.Unlock() @@ -71,19 +71,19 @@ func (commonProtocol *CommonProtocol) autoMatchmakeWithParamPostpone(err error, resultSession = resultSessions[0] // TODO - What should really happen here? - if resultSession.UserPasswordEnabled.Value || resultSession.SystemPasswordEnabled.Value { + if resultSession.UserPasswordEnabled || resultSession.SystemPasswordEnabled { commonProtocol.manager.Mutex.Unlock() return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } } - participants, nexError := match_making_database.JoinGatheringWithParticipants(commonProtocol.manager, resultSession.ID.Value, connection, autoMatchmakeParam.AdditionalParticipants.Slice(), autoMatchmakeParam.JoinMessage.Value, constants.JoinMatchmakeSessionBehaviorJoinMyself) + participants, nexError := match_making_database.JoinGatheringWithParticipants(commonProtocol.manager, uint32(resultSession.ID), connection, autoMatchmakeParam.AdditionalParticipants, string(autoMatchmakeParam.JoinMessage), constants.JoinMatchmakeSessionBehaviorJoinMyself) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } - resultSession.ParticipationCount.Value = participants + resultSession.ParticipationCount = types.NewUInt32(participants) commonProtocol.manager.Mutex.Unlock() diff --git a/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go b/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go index 238c9ee..b37d09f 100644 --- a/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go +++ b/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go @@ -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") @@ -21,11 +21,11 @@ func (commonProtocol *CommonProtocol) autoMatchmakeWithSearchCriteriaPostpone(er return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } - if len(strMessage.Value) > 256 { + if len(strMessage) > 256 { return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } - if lstSearchCriteria.Length() > 2 { + if len(lstSearchCriteria) > 2 { return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } @@ -38,10 +38,10 @@ func (commonProtocol *CommonProtocol) autoMatchmakeWithSearchCriteriaPostpone(er // * so let's make sure the client is removed from the session database.EndMatchmakeSessionsParticipation(commonProtocol.manager, connection) - var matchmakeSession *match_making_types.MatchmakeSession + var matchmakeSession match_making_types.MatchmakeSession - if anyGathering.TypeName.Value == "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() @@ -56,17 +56,17 @@ func (commonProtocol *CommonProtocol) autoMatchmakeWithSearchCriteriaPostpone(er commonProtocol.CleanupMatchmakeSessionSearchCriterias(lstSearchCriteria) resultRange := types.NewResultRange() - resultRange.Length.Value = 1 - resultSessions, nexError := database.FindMatchmakeSessionBySearchCriteria(commonProtocol.manager, connection, lstSearchCriteria.Slice(), resultRange, matchmakeSession) + resultRange.Length = 1 + resultSessions, nexError := database.FindMatchmakeSessionBySearchCriteria(commonProtocol.manager, connection, lstSearchCriteria, resultRange, &matchmakeSession) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } - var resultSession *match_making_types.MatchmakeSession + var resultSession match_making_types.MatchmakeSession if len(resultSessions) == 0 { - resultSession = matchmakeSession.Copy().(*match_making_types.MatchmakeSession) - nexError = database.CreateMatchmakeSession(commonProtocol.manager, connection, resultSession) + resultSession = matchmakeSession.Copy().(match_making_types.MatchmakeSession) + nexError = database.CreateMatchmakeSession(commonProtocol.manager, connection, &resultSession) if nexError != nil { common_globals.Logger.Error(nexError.Error()) commonProtocol.manager.Mutex.Unlock() @@ -76,31 +76,29 @@ func (commonProtocol *CommonProtocol) autoMatchmakeWithSearchCriteriaPostpone(er resultSession = resultSessions[0] // TODO - What should really happen here? - if resultSession.UserPasswordEnabled.Value || resultSession.SystemPasswordEnabled.Value { + if resultSession.UserPasswordEnabled || resultSession.SystemPasswordEnabled { commonProtocol.manager.Mutex.Unlock() return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } } var vacantParticipants uint16 = 1 - if searchCriteria, err := lstSearchCriteria.Get(0); err == nil { - vacantParticipants = searchCriteria.VacantParticipants.Value + if len(lstSearchCriteria) > 0 { + vacantParticipants = uint16(lstSearchCriteria[0].VacantParticipants) } - participants, nexError := match_making_database.JoinGathering(commonProtocol.manager, resultSession.Gathering.ID.Value, connection, vacantParticipants, strMessage.Value) + participants, nexError := match_making_database.JoinGathering(commonProtocol.manager, uint32(resultSession.Gathering.ID), connection, vacantParticipants, string(strMessage)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } - resultSession.ParticipationCount.Value = participants + resultSession.ParticipationCount = types.NewUInt32(participants) 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()) diff --git a/matchmake-extension/browse_matchmake_session.go b/matchmake-extension/browse_matchmake_session.go index 7e31600..761de69 100644 --- a/matchmake-extension/browse_matchmake_session.go +++ b/matchmake-extension/browse_matchmake_session.go @@ -9,7 +9,7 @@ import ( matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func (commonProtocol *CommonProtocol) browseMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) browseMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, searchCriteria match_making_types.MatchmakeSessionSearchCriteria, resultRange types.ResultRange) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -20,11 +20,10 @@ func (commonProtocol *CommonProtocol) browseMatchmakeSession(err error, packet n commonProtocol.manager.Mutex.RLock() - searchCriterias := []*match_making_types.MatchmakeSessionSearchCriteria{searchCriteria} + searchCriterias := []match_making_types.MatchmakeSessionSearchCriteria{searchCriteria} - lstSearchCriteria := types.NewList[*match_making_types.MatchmakeSessionSearchCriteria]() - lstSearchCriteria.Type = match_making_types.NewMatchmakeSessionSearchCriteria() - lstSearchCriteria.SetFromData(searchCriterias) + lstSearchCriteria := types.NewList[match_making_types.MatchmakeSessionSearchCriteria]() + lstSearchCriteria = searchCriterias if commonProtocol.CleanupMatchmakeSessionSearchCriterias != nil { commonProtocol.CleanupMatchmakeSessionSearchCriterias(lstSearchCriteria) @@ -36,19 +35,17 @@ func (commonProtocol *CommonProtocol) browseMatchmakeSession(err error, packet n return nil, nexError } - lstGathering := types.NewList[*types.AnyDataHolder]() - lstGathering.Type = types.NewAnyDataHolder() + lstGathering := types.NewList[match_making_types.GatheringHolder]() for _, session := range sessions { // * Scrap session key and user password - session.SessionKey.Value = make([]byte, 0) - session.UserPassword.Value = "" + 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(matchmakeSessionDataHolder) + lstGathering = append(lstGathering, matchmakeSessionDataHolder) } commonProtocol.manager.Mutex.RUnlock() diff --git a/matchmake-extension/close_participation.go b/matchmake-extension/close_participation.go index 28bdb04..22d2462 100644 --- a/matchmake-extension/close_participation.go +++ b/matchmake-extension/close_participation.go @@ -8,7 +8,7 @@ import ( matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func (commonProtocol *CommonProtocol) closeParticipation(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) closeParticipation(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -19,7 +19,7 @@ func (commonProtocol *CommonProtocol) closeParticipation(err error, packet nex.P commonProtocol.manager.Mutex.Lock() - session, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, gid.Value) + session, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, uint32(gid)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -30,7 +30,7 @@ func (commonProtocol *CommonProtocol) closeParticipation(err error, packet nex.P return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } - nexError = database.UpdateParticipation(commonProtocol.manager, gid.Value, false) + nexError = database.UpdateParticipation(commonProtocol.manager, uint32(gid), false) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError diff --git a/matchmake-extension/create_matchmake_session.go b/matchmake-extension/create_matchmake_session.go index 8d46a13..4111838 100644 --- a/matchmake-extension/create_matchmake_session.go +++ b/matchmake-extension/create_matchmake_session.go @@ -10,13 +10,13 @@ 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.PrimitiveU16) (*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") } - if len(message.Value) > 256 { + if len(message) > 256 { return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } @@ -30,10 +30,10 @@ func (commonProtocol *CommonProtocol) createMatchmakeSession(err error, packet n // * so let's make sure the client is removed from the session database.EndMatchmakeSessionsParticipation(commonProtocol.manager, connection) - var matchmakeSession *match_making_types.MatchmakeSession + var matchmakeSession match_making_types.MatchmakeSession - if anyGathering.TypeName.Value == "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() @@ -45,21 +45,21 @@ func (commonProtocol *CommonProtocol) createMatchmakeSession(err error, packet n return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } - nexError := database.CreateMatchmakeSession(commonProtocol.manager, connection, matchmakeSession) + nexError := database.CreateMatchmakeSession(commonProtocol.manager, connection, &matchmakeSession) if nexError != nil { common_globals.Logger.Error(nexError.Error()) commonProtocol.manager.Mutex.Unlock() return nil, nexError } - participants, nexError := match_making_database.JoinGathering(commonProtocol.manager, matchmakeSession.Gathering.ID.Value, connection, participationCount.Value, message.Value) + participants, nexError := match_making_database.JoinGathering(commonProtocol.manager, uint32(matchmakeSession.Gathering.ID), connection, uint16(participationCount), string(message)) if nexError != nil { common_globals.Logger.Error(nexError.Error()) commonProtocol.manager.Mutex.Unlock() return nil, nexError } - matchmakeSession.ParticipationCount.Value = participants + matchmakeSession.ParticipationCount = types.NewUInt32(participants) commonProtocol.manager.Mutex.Unlock() diff --git a/matchmake-extension/create_matchmake_session_with_param.go b/matchmake-extension/create_matchmake_session_with_param.go index e76f959..c3934ea 100644 --- a/matchmake-extension/create_matchmake_session_with_param.go +++ b/matchmake-extension/create_matchmake_session_with_param.go @@ -2,6 +2,7 @@ package matchmake_extension import ( "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" match_making_database "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database" "github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database" @@ -10,7 +11,7 @@ import ( matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func (commonProtocol *CommonProtocol) createMatchmakeSessionWithParam(err error, packet nex.PacketInterface, callID uint32, createMatchmakeSessionParam *match_making_types.CreateMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) createMatchmakeSessionWithParam(err error, packet nex.PacketInterface, callID uint32, createMatchmakeSessionParam match_making_types.CreateMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -23,15 +24,15 @@ func (commonProtocol *CommonProtocol) createMatchmakeSessionWithParam(err error, return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } - if len(createMatchmakeSessionParam.JoinMessage.Value) > 256 { + if len(createMatchmakeSessionParam.JoinMessage) > 256 { return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } commonProtocol.manager.Mutex.Lock() - if createMatchmakeSessionParam.GIDForParticipationCheck.Value != 0 { + if createMatchmakeSessionParam.GIDForParticipationCheck != 0 { // * Check that all new participants are participating in the specified gathering ID - nexError := database.CheckGatheringForParticipation(commonProtocol.manager, createMatchmakeSessionParam.GIDForParticipationCheck.Value, append(createMatchmakeSessionParam.AdditionalParticipants.Slice(), connection.PID())) + nexError := database.CheckGatheringForParticipation(commonProtocol.manager, uint32(createMatchmakeSessionParam.GIDForParticipationCheck), append(createMatchmakeSessionParam.AdditionalParticipants, connection.PID())) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -42,15 +43,15 @@ func (commonProtocol *CommonProtocol) createMatchmakeSessionWithParam(err error, // * so let's make sure the client is removed from all sessions database.EndMatchmakeSessionsParticipation(commonProtocol.manager, connection) - joinedMatchmakeSession := createMatchmakeSessionParam.SourceMatchmakeSession.Copy().(*match_making_types.MatchmakeSession) - nexError := database.CreateMatchmakeSession(commonProtocol.manager, connection, joinedMatchmakeSession) + joinedMatchmakeSession := createMatchmakeSessionParam.SourceMatchmakeSession.Copy().(match_making_types.MatchmakeSession) + nexError := database.CreateMatchmakeSession(commonProtocol.manager, connection, &joinedMatchmakeSession) if nexError != nil { common_globals.Logger.Error(nexError.Error()) commonProtocol.manager.Mutex.Unlock() return nil, nexError } - participants, nexError := match_making_database.JoinGatheringWithParticipants(commonProtocol.manager, joinedMatchmakeSession.Gathering.ID.Value, connection, createMatchmakeSessionParam.AdditionalParticipants.Slice(), createMatchmakeSessionParam.JoinMessage.Value, constants.JoinMatchmakeSessionBehaviorJoinMyself) + participants, nexError := match_making_database.JoinGatheringWithParticipants(commonProtocol.manager, uint32(joinedMatchmakeSession.Gathering.ID), connection, createMatchmakeSessionParam.AdditionalParticipants, string(createMatchmakeSessionParam.JoinMessage), constants.JoinMatchmakeSessionBehaviorJoinMyself) if nexError != nil { common_globals.Logger.Error(nexError.Error()) commonProtocol.manager.Mutex.Unlock() @@ -59,7 +60,7 @@ func (commonProtocol *CommonProtocol) createMatchmakeSessionWithParam(err error, commonProtocol.manager.Mutex.Unlock() - joinedMatchmakeSession.ParticipationCount.Value = participants + joinedMatchmakeSession.ParticipationCount = types.NewUInt32(participants) rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/matchmake-extension/database/check_gathering_for_participation.go b/matchmake-extension/database/check_gathering_for_participation.go index 2d3361d..a53386e 100644 --- a/matchmake-extension/database/check_gathering_for_participation.go +++ b/matchmake-extension/database/check_gathering_for_participation.go @@ -10,14 +10,14 @@ import ( ) // CheckGatheringForParticipation checks that the given PIDs are participating on the gathering ID -func CheckGatheringForParticipation(manager *common_globals.MatchmakingManager, gatheringID uint32, participantsCheck []*types.PID) *nex.Error { +func CheckGatheringForParticipation(manager *common_globals.MatchmakingManager, gatheringID uint32, participantsCheck []types.PID) *nex.Error { _, _, participants, _, err := database.FindGatheringByID(manager, gatheringID) if err != nil { return err } for _, participant := range participantsCheck { - if !slices.Contains(participants, participant.Value()) { + if !slices.Contains(participants, uint64(participant)) { return nex.NewError(nex.ResultCodes.RendezVous.NotParticipatedGathering, "change_error") } } diff --git a/matchmake-extension/database/create_matchmake_session.go b/matchmake-extension/database/create_matchmake_session.go index 813ebea..67d5155 100644 --- a/matchmake-extension/database/create_matchmake_session.go +++ b/matchmake-extension/database/create_matchmake_session.go @@ -13,14 +13,14 @@ import ( // CreateMatchmakeSession creates a new MatchmakeSession on the database. No participants are added func CreateMatchmakeSession(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection, matchmakeSession *match_making_types.MatchmakeSession) *nex.Error { - startedTime, nexError := match_making_database.RegisterGathering(manager, connection.PID(), matchmakeSession.Gathering, "MatchmakeSession") + startedTime, nexError := match_making_database.RegisterGathering(manager, connection.PID(), &matchmakeSession.Gathering, "MatchmakeSession") if nexError != nil { return nexError } - attribs := make([]uint32, matchmakeSession.Attributes.Length()) - for i, value := range matchmakeSession.Attributes.Slice() { - attribs[i] = value.Value + attribs := make([]uint32, len(matchmakeSession.Attributes)) + for i, value := range matchmakeSession.Attributes { + attribs[i] = uint32(value) } endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) @@ -28,20 +28,20 @@ func CreateMatchmakeSession(manager *common_globals.MatchmakingManager, connecti matchmakeParam := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) srVariant := types.NewVariant() - srVariant.TypeID.Value = 3 - srVariant.Type = types.NewPrimitiveBool(true) - matchmakeSession.MatchmakeParam.Params.Set(types.NewString("@SR"), srVariant) + srVariant.TypeID = 3 + srVariant.Type = types.NewBool(true) + matchmakeSession.MatchmakeParam.Params["@SR"] = srVariant girVariant := types.NewVariant() - girVariant.TypeID.Value = 1 - girVariant.Type = types.NewPrimitiveS64(3) - matchmakeSession.MatchmakeParam.Params.Set(types.NewString("@GIR"), srVariant) + girVariant.TypeID = 1 + girVariant.Type = types.NewInt64(3) + matchmakeSession.MatchmakeParam.Params["@GIR"] = girVariant matchmakeSession.MatchmakeParam.WriteTo(matchmakeParam) matchmakeSession.StartedTime = startedTime - matchmakeSession.SessionKey.Value = make([]byte, 32) - matchmakeSession.SystemPasswordEnabled.Value = false - rand.Read(matchmakeSession.SessionKey.Value) + matchmakeSession.SessionKey = make([]byte, 32) + matchmakeSession.SystemPasswordEnabled = false + rand.Read(matchmakeSession.SessionKey) _, err := manager.Database.Exec(`INSERT INTO matchmaking.matchmake_sessions ( id, @@ -76,21 +76,21 @@ func CreateMatchmakeSession(manager *common_globals.MatchmakingManager, connecti $14, $15 )`, - matchmakeSession.Gathering.ID.Value, - matchmakeSession.GameMode.Value, + uint32(matchmakeSession.Gathering.ID), + uint32(matchmakeSession.GameMode), pqextended.Array(attribs), - matchmakeSession.OpenParticipation.Value, - matchmakeSession.MatchmakeSystemType.Value, - matchmakeSession.ApplicationBuffer.Value, - matchmakeSession.ProgressScore.Value, - matchmakeSession.SessionKey.Value, - matchmakeSession.Option.Value, + bool(matchmakeSession.OpenParticipation), + uint32(matchmakeSession.MatchmakeSystemType), + []byte(matchmakeSession.ApplicationBuffer), + uint32(matchmakeSession.ProgressScore), + []byte(matchmakeSession.SessionKey), + uint32(matchmakeSession.Option), matchmakeParam.Bytes(), - matchmakeSession.UserPassword.Value, - matchmakeSession.ReferGID.Value, - matchmakeSession.UserPasswordEnabled.Value, - matchmakeSession.SystemPasswordEnabled.Value, - matchmakeSession.CodeWord.Value, + string(matchmakeSession.UserPassword), + uint32(matchmakeSession.ReferGID), + bool(matchmakeSession.UserPasswordEnabled), + bool(matchmakeSession.SystemPasswordEnabled), + string(matchmakeSession.CodeWord), ) if err != nil { return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) diff --git a/matchmake-extension/database/end_matchmake_sessions_participation.go b/matchmake-extension/database/end_matchmake_sessions_participation.go index 85febf7..e90411a 100644 --- a/matchmake-extension/database/end_matchmake_sessions_participation.go +++ b/matchmake-extension/database/end_matchmake_sessions_participation.go @@ -8,7 +8,7 @@ import ( // EndMatchmakeSessionsParticipation ends participation on all matchmake sessions func EndMatchmakeSessionsParticipation(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection) { - rows, err := manager.Database.Query(`SELECT id FROM matchmaking.gatherings WHERE type='MatchmakeSession' AND $1=ANY(participants)`, connection.PID().Value()) + rows, err := manager.Database.Query(`SELECT id FROM matchmaking.gatherings WHERE type='MatchmakeSession' AND $1=ANY(participants)`, connection.PID()) if err != nil { common_globals.Logger.Error(err.Error()) return diff --git a/matchmake-extension/database/find_matchmake_session.go b/matchmake-extension/database/find_matchmake_session.go index b0d8daf..5b691de 100644 --- a/matchmake-extension/database/find_matchmake_session.go +++ b/matchmake-extension/database/find_matchmake_session.go @@ -12,10 +12,10 @@ import ( ) // FindMatchmakeSession finds a matchmake session with the given search matchmake session -func FindMatchmakeSession(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection, searchMatchmakeSession *match_making_types.MatchmakeSession) (*match_making_types.MatchmakeSession, *nex.Error) { - attribs := make([]uint32, searchMatchmakeSession.Attributes.Length()) - for i, value := range searchMatchmakeSession.Attributes.Slice() { - attribs[i] = value.Value +func FindMatchmakeSession(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection, searchMatchmakeSession match_making_types.MatchmakeSession) (*match_making_types.MatchmakeSession, *nex.Error) { + attribs := make([]uint32, len(searchMatchmakeSession.Attributes)) + for i, value := range searchMatchmakeSession.Attributes { + attribs[i] = uint32(value) } endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) @@ -72,57 +72,77 @@ func FindMatchmakeSession(manager *common_globals.MatchmakingManager, connection var friendList []uint32 // * Prevent access to friend rooms if not implemented if manager.GetUserFriendPIDs != nil { - friendList = manager.GetUserFriendPIDs(connection.PID().LegacyValue()) + friendList = manager.GetUserFriendPIDs(uint32(connection.PID())) } - resultMatchmakeSession := match_making_types.NewMatchmakeSession() + var gatheringID uint32 var ownerPID uint64 var hostPID uint64 + var minimumParticipants uint16 + var maximumParticipants uint16 + var participationPolicy uint32 + var policyArgument uint32 + var flags uint32 + var state uint32 + var description string + var participationCount uint32 var startedTime time.Time + var gameMode uint32 var resultAttribs []uint32 + var openParticipation bool + var matchmakeSystemType uint32 + var applicationBuffer []byte + var progressScore uint8 + var sessionKey []byte + var option uint32 var resultMatchmakeParam []byte + var userPassword string + var referGID uint32 + var userPasswordEnabled bool + var systemPasswordEnabled bool + var codeWord string // * For simplicity, we will only compare the values that exist on a MatchmakeSessionSearchCriteria err := manager.Database.QueryRow(searchStatement, - searchMatchmakeSession.Gathering.MaximumParticipants.Value, - searchMatchmakeSession.Gathering.MinimumParticipants.Value, - searchMatchmakeSession.GameMode.Value, + uint16(searchMatchmakeSession.Gathering.MaximumParticipants), + uint16(searchMatchmakeSession.Gathering.MinimumParticipants), + uint32(searchMatchmakeSession.GameMode), attribs[0], attribs[1], attribs[2], attribs[3], attribs[4], attribs[5], - searchMatchmakeSession.MatchmakeSystemType.Value, - searchMatchmakeSession.CodeWord.Value, + uint32(searchMatchmakeSession.MatchmakeSystemType), + string(searchMatchmakeSession.CodeWord), pqextended.Array(friendList), ).Scan( - &resultMatchmakeSession.Gathering.ID.Value, + &gatheringID, &ownerPID, &hostPID, - &resultMatchmakeSession.Gathering.MinimumParticipants.Value, - &resultMatchmakeSession.Gathering.MaximumParticipants.Value, - &resultMatchmakeSession.Gathering.ParticipationPolicy.Value, - &resultMatchmakeSession.Gathering.PolicyArgument.Value, - &resultMatchmakeSession.Gathering.Flags.Value, - &resultMatchmakeSession.Gathering.State.Value, - &resultMatchmakeSession.Gathering.Description.Value, - &resultMatchmakeSession.ParticipationCount.Value, + &minimumParticipants, + &maximumParticipants, + &participationPolicy, + &policyArgument, + &flags, + &state, + &description, + &participationCount, &startedTime, - &resultMatchmakeSession.GameMode.Value, + &gameMode, pqextended.Array(&resultAttribs), - &resultMatchmakeSession.OpenParticipation.Value, - &resultMatchmakeSession.MatchmakeSystemType.Value, - &resultMatchmakeSession.ApplicationBuffer.Value, - &resultMatchmakeSession.ProgressScore.Value, - &resultMatchmakeSession.SessionKey.Value, - &resultMatchmakeSession.Option.Value, + &openParticipation, + &matchmakeSystemType, + &applicationBuffer, + &progressScore, + &sessionKey, + &option, &resultMatchmakeParam, - &resultMatchmakeSession.UserPassword.Value, - &resultMatchmakeSession.ReferGID.Value, - &resultMatchmakeSession.UserPasswordEnabled.Value, - &resultMatchmakeSession.SystemPasswordEnabled.Value, - &resultMatchmakeSession.CodeWord.Value, + &userPassword, + &referGID, + &userPasswordEnabled, + &systemPasswordEnabled, + &codeWord, ) if err != nil { if err == sql.ErrNoRows { @@ -132,18 +152,43 @@ func FindMatchmakeSession(manager *common_globals.MatchmakingManager, connection } } + resultMatchmakeSession := match_making_types.NewMatchmakeSession() + + resultMatchmakeSession.Gathering.ID = types.NewUInt32(gatheringID) resultMatchmakeSession.OwnerPID = types.NewPID(ownerPID) resultMatchmakeSession.HostPID = types.NewPID(hostPID) + resultMatchmakeSession.Gathering.MinimumParticipants = types.NewUInt16(minimumParticipants) + resultMatchmakeSession.Gathering.MaximumParticipants = types.NewUInt16(maximumParticipants) + resultMatchmakeSession.Gathering.ParticipationPolicy = types.NewUInt32(participationPolicy) + resultMatchmakeSession.Gathering.PolicyArgument = types.NewUInt32(policyArgument) + resultMatchmakeSession.Gathering.Flags = types.NewUInt32(flags) + resultMatchmakeSession.Gathering.State = types.NewUInt32(state) + resultMatchmakeSession.Gathering.Description = types.NewString(description) + resultMatchmakeSession.ParticipationCount = types.NewUInt32(participationCount) resultMatchmakeSession.StartedTime = resultMatchmakeSession.StartedTime.FromTimestamp(startedTime) + resultMatchmakeSession.GameMode = types.NewUInt32(gameMode) - attributesSlice := make([]*types.PrimitiveU32, len(resultAttribs)) + attributesSlice := make([]types.UInt32, len(resultAttribs)) for i, value := range resultAttribs { - attributesSlice[i] = types.NewPrimitiveU32(value) + attributesSlice[i] = types.NewUInt32(value) } - resultMatchmakeSession.Attributes.SetFromData(attributesSlice) + resultMatchmakeSession.Attributes = attributesSlice + + resultMatchmakeSession.OpenParticipation = types.NewBool(openParticipation) + resultMatchmakeSession.MatchmakeSystemType = types.NewUInt32(matchmakeSystemType) + resultMatchmakeSession.ApplicationBuffer = applicationBuffer + resultMatchmakeSession.ProgressScore = types.NewUInt8(progressScore) + resultMatchmakeSession.SessionKey = sessionKey + resultMatchmakeSession.Option = types.UInt32(option) matchmakeParamBytes := nex.NewByteStreamIn(resultMatchmakeParam, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) resultMatchmakeSession.MatchmakeParam.ExtractFrom(matchmakeParamBytes) - return resultMatchmakeSession, nil + resultMatchmakeSession.UserPassword = types.NewString(userPassword) + resultMatchmakeSession.ReferGID = types.NewUInt32(referGID) + resultMatchmakeSession.UserPasswordEnabled = types.NewBool(userPasswordEnabled) + resultMatchmakeSession.SystemPasswordEnabled = types.NewBool(systemPasswordEnabled) + resultMatchmakeSession.CodeWord = types.String(codeWord) + + return &resultMatchmakeSession, nil } diff --git a/matchmake-extension/database/find_matchmake_session_by_search_criteria.go b/matchmake-extension/database/find_matchmake_session_by_search_criteria.go index 56e274e..d1082b4 100644 --- a/matchmake-extension/database/find_matchmake_session_by_search_criteria.go +++ b/matchmake-extension/database/find_matchmake_session_by_search_criteria.go @@ -17,18 +17,18 @@ import ( ) // FindMatchmakeSessionBySearchCriteria finds matchmake sessions with the given search criterias -func FindMatchmakeSessionBySearchCriteria(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection, searchCriterias []*match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange, sourceMatchmakeSession *match_making_types.MatchmakeSession) ([]*match_making_types.MatchmakeSession, *nex.Error) { - resultMatchmakeSessions := make([]*match_making_types.MatchmakeSession, 0) +func FindMatchmakeSessionBySearchCriteria(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection, searchCriterias []match_making_types.MatchmakeSessionSearchCriteria, resultRange types.ResultRange, sourceMatchmakeSession *match_making_types.MatchmakeSession) ([]match_making_types.MatchmakeSession, *nex.Error) { + resultMatchmakeSessions := make([]match_making_types.MatchmakeSession, 0) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) var friendList []uint32 if manager.GetUserFriendPIDs != nil { - friendList = manager.GetUserFriendPIDs(connection.PID().LegacyValue()) + friendList = manager.GetUserFriendPIDs(uint32(connection.PID())) } - if resultRange.Offset.Value == math.MaxUint32 { - resultRange.Offset.Value = 0 + if resultRange.Offset == math.MaxUint32 { + resultRange.Offset = 0 } for _, searchCriteria := range searchCriterias { @@ -74,14 +74,14 @@ func FindMatchmakeSessionBySearchCriteria(manager *common_globals.MatchmakingMan (CASE WHEN $8=true THEN ms.system_password_enabled=false ELSE true END)` var valid bool = true - for i, attrib := range searchCriteria.Attribs.Slice() { + for i, attrib := range searchCriteria.Attribs { // * Ignore attribute 1 here, reserved for the selection method if i == 1 { continue; } - if attrib.Value != "" { - before, after, found := strings.Cut(attrib.Value, ",") + if attrib != "" { + before, after, found := strings.Cut(string(attrib), ",") if found { min, err := strconv.ParseUint(before, 10, 32) if err != nil { @@ -113,8 +113,8 @@ func FindMatchmakeSessionBySearchCriteria(manager *common_globals.MatchmakingMan continue } - if searchCriteria.MaxParticipants.Value != "" { - before, after, found := strings.Cut(searchCriteria.MaxParticipants.Value, ",") + if searchCriteria.MaxParticipants != "" { + before, after, found := strings.Cut(string(searchCriteria.MaxParticipants), ",") if found { min, err := strconv.ParseUint(before, 10, 16) if err != nil { @@ -137,8 +137,8 @@ func FindMatchmakeSessionBySearchCriteria(manager *common_globals.MatchmakingMan } } - if searchCriteria.MinParticipants.Value != "" { - before, after, found := strings.Cut(searchCriteria.MinParticipants.Value, ",") + if searchCriteria.MinParticipants != "" { + before, after, found := strings.Cut(string(searchCriteria.MinParticipants), ",") if found { min, err := strconv.ParseUint(before, 10, 16) if err != nil { @@ -161,8 +161,8 @@ func FindMatchmakeSessionBySearchCriteria(manager *common_globals.MatchmakingMan } } - if searchCriteria.GameMode.Value != "" { - before, after, found := strings.Cut(searchCriteria.GameMode.Value, ",") + if searchCriteria.GameMode != "" { + before, after, found := strings.Cut(string(searchCriteria.GameMode), ",") if found { min, err := strconv.ParseUint(before, 10, 32) if err != nil { @@ -185,8 +185,8 @@ func FindMatchmakeSessionBySearchCriteria(manager *common_globals.MatchmakingMan } } - if searchCriteria.MatchmakeSystemType.Value != "" { - before, after, found := strings.Cut(searchCriteria.MatchmakeSystemType.Value, ",") + if searchCriteria.MatchmakeSystemType != "" { + before, after, found := strings.Cut(string(searchCriteria.MatchmakeSystemType), ",") if found { min, err := strconv.ParseUint(before, 10, 32) if err != nil { @@ -210,22 +210,22 @@ func FindMatchmakeSessionBySearchCriteria(manager *common_globals.MatchmakingMan } // * Filter full sessions if necessary - if searchCriteria.VacantOnly.Value { + if searchCriteria.VacantOnly { // * Account for the VacantParticipants when searching for sessions (if given) - if searchCriteria.VacantParticipants.Value == 0 { + if searchCriteria.VacantParticipants == 0 { searchStatement += ` AND array_length(g.participants, 1) + 1 <= g.max_participants` } else { - searchStatement += fmt.Sprintf(` AND array_length(g.participants, 1) + %d <= g.max_participants`, searchCriteria.VacantParticipants.Value) + searchStatement += fmt.Sprintf(` AND array_length(g.participants, 1) + %d <= g.max_participants`, searchCriteria.VacantParticipants) } } - switch constants.SelectionMethod(searchCriteria.SelectionMethod.Value) { + switch constants.SelectionMethod(searchCriteria.SelectionMethod) { case constants.SelectionMethodRandom: // * Random global searchStatement += ` ORDER BY RANDOM()` case constants.SelectionMethodNearestNeighbor: // * Closest attribute - attribute1, err := strconv.ParseUint(searchCriteria.Attribs.Slice()[1].Value, 10, 32) + attribute1, err := strconv.ParseUint(string(searchCriteria.Attribs[1]), 10, 32) if err != nil { globals.Logger.Error(err.Error()) continue @@ -236,7 +236,7 @@ func FindMatchmakeSessionBySearchCriteria(manager *common_globals.MatchmakingMan // * Ranked // TODO - Actually implement ranked matchmaking, using closest attribute at the moment - attribute1, err := strconv.ParseUint(searchCriteria.Attribs.Slice()[1].Value, 10, 32) + attribute1, err := strconv.ParseUint(string(searchCriteria.Attribs[1]), 10, 32) if err != nil { globals.Logger.Error(err.Error()) continue @@ -251,7 +251,7 @@ func FindMatchmakeSessionBySearchCriteria(manager *common_globals.MatchmakingMan continue } - searchStatement += fmt.Sprintf(` ORDER BY abs(%d - ms.progress_score)`, sourceMatchmakeSession.ProgressScore.Value) + searchStatement += fmt.Sprintf(` ORDER BY abs(%d - ms.progress_score)`, sourceMatchmakeSession.ProgressScore) case constants.SelectionMethodBroadenRangeWithProgressScore: // * Ranked + Progress @@ -262,36 +262,36 @@ func FindMatchmakeSessionBySearchCriteria(manager *common_globals.MatchmakingMan continue } - attribute1, err := strconv.ParseUint(searchCriteria.Attribs.Slice()[1].Value, 10, 32) + attribute1, err := strconv.ParseUint(string(searchCriteria.Attribs[1]), 10, 32) if err != nil { globals.Logger.Error(err.Error()) continue } // TODO - Should the attribute and the progress score actually weigh the same? - searchStatement += fmt.Sprintf(` ORDER BY abs(%d - ms.attribs[2] + %d - ms.progress_score)`, attribute1, sourceMatchmakeSession.ProgressScore.Value) + searchStatement += fmt.Sprintf(` ORDER BY abs(%d - ms.attribs[2] + %d - ms.progress_score)`, attribute1, sourceMatchmakeSession.ProgressScore) // case constants.SelectionMethodScoreBased: // * According to notes this is related with the MatchmakeParam. TODO - Implement this } // * If the ResultRange inside the MatchmakeSessionSearchCriteria is valid (only present on NEX 4.0+), use that // * Otherwise, use the one given as argument - if searchCriteria.ResultRange.Length.Value != 0 { - searchStatement += fmt.Sprintf(` LIMIT %d OFFSET %d`, searchCriteria.ResultRange.Length.Value, searchCriteria.ResultRange.Offset.Value) + if searchCriteria.ResultRange.Length != 0 { + searchStatement += fmt.Sprintf(` LIMIT %d OFFSET %d`, uint32(searchCriteria.ResultRange.Length), uint32(searchCriteria.ResultRange.Offset)) } else { // * Since we use one ResultRange for all searches, limit the total length to the one specified // * but apply the same offset to all queries - searchStatement += fmt.Sprintf(` LIMIT %d OFFSET %d`, resultRange.Length.Value - uint32(len(resultMatchmakeSessions)), resultRange.Offset.Value) + searchStatement += fmt.Sprintf(` LIMIT %d OFFSET %d`, uint32(resultRange.Length) - uint32(len(resultMatchmakeSessions)), uint32(resultRange.Offset)) } rows, err := manager.Database.Query(searchStatement, - searchCriteria.ReferGID.Value, - searchCriteria.CodeWord.Value, - searchCriteria.Attribs.Length(), + uint32(searchCriteria.ReferGID), + string(searchCriteria.CodeWord), + len(searchCriteria.Attribs), pqextended.Array(friendList), - searchCriteria.ExcludeLocked.Value, - searchCriteria.ExcludeNonHostPID.Value, - searchCriteria.ExcludeUserPasswordSet.Value, - searchCriteria.ExcludeSystemPasswordSet.Value, + bool(searchCriteria.ExcludeLocked), + bool(searchCriteria.ExcludeNonHostPID), + bool(searchCriteria.ExcludeUserPasswordSet), + bool(searchCriteria.ExcludeSystemPasswordSet), ) if err != nil { globals.Logger.Critical(err.Error()) @@ -299,59 +299,104 @@ func FindMatchmakeSessionBySearchCriteria(manager *common_globals.MatchmakingMan } for rows.Next() { - resultMatchmakeSession := match_making_types.NewMatchmakeSession() + var gatheringID uint32 var ownerPID uint64 var hostPID uint64 + var minimumParticipants uint16 + var maximumParticipants uint16 + var participationPolicy uint32 + var policyArgument uint32 + var flags uint32 + var state uint32 + var description string + var participationCount uint32 var startedTime time.Time + var gameMode uint32 var resultAttribs []uint32 + var openParticipation bool + var matchmakeSystemType uint32 + var applicationBuffer []byte + var progressScore uint8 + var sessionKey []byte + var option uint32 var resultMatchmakeParam []byte + var userPassword string + var referGID uint32 + var userPasswordEnabled bool + var systemPasswordEnabled bool + var codeWord string err = rows.Scan( - &resultMatchmakeSession.Gathering.ID.Value, + &gatheringID, &ownerPID, &hostPID, - &resultMatchmakeSession.Gathering.MinimumParticipants.Value, - &resultMatchmakeSession.Gathering.MaximumParticipants.Value, - &resultMatchmakeSession.Gathering.ParticipationPolicy.Value, - &resultMatchmakeSession.Gathering.PolicyArgument.Value, - &resultMatchmakeSession.Gathering.Flags.Value, - &resultMatchmakeSession.Gathering.State.Value, - &resultMatchmakeSession.Gathering.Description.Value, - &resultMatchmakeSession.ParticipationCount.Value, + &minimumParticipants, + &maximumParticipants, + &participationPolicy, + &policyArgument, + &flags, + &state, + &description, + &participationCount, &startedTime, - &resultMatchmakeSession.GameMode.Value, + &gameMode, pqextended.Array(&resultAttribs), - &resultMatchmakeSession.OpenParticipation.Value, - &resultMatchmakeSession.MatchmakeSystemType.Value, - &resultMatchmakeSession.ApplicationBuffer.Value, - &resultMatchmakeSession.ProgressScore.Value, - &resultMatchmakeSession.SessionKey.Value, - &resultMatchmakeSession.Option.Value, + &openParticipation, + &matchmakeSystemType, + &applicationBuffer, + &progressScore, + &sessionKey, + &option, &resultMatchmakeParam, - &resultMatchmakeSession.UserPassword.Value, - &resultMatchmakeSession.ReferGID.Value, - &resultMatchmakeSession.UserPasswordEnabled.Value, - &resultMatchmakeSession.SystemPasswordEnabled.Value, - &resultMatchmakeSession.CodeWord.Value, + &userPassword, + &referGID, + &userPasswordEnabled, + &systemPasswordEnabled, + &codeWord, ) if err != nil { globals.Logger.Critical(err.Error()) continue } + resultMatchmakeSession := match_making_types.NewMatchmakeSession() + + resultMatchmakeSession.Gathering.ID = types.NewUInt32(gatheringID) resultMatchmakeSession.OwnerPID = types.NewPID(ownerPID) resultMatchmakeSession.HostPID = types.NewPID(hostPID) + resultMatchmakeSession.Gathering.MinimumParticipants = types.NewUInt16(minimumParticipants) + resultMatchmakeSession.Gathering.MaximumParticipants = types.NewUInt16(maximumParticipants) + resultMatchmakeSession.Gathering.ParticipationPolicy = types.NewUInt32(participationPolicy) + resultMatchmakeSession.Gathering.PolicyArgument = types.NewUInt32(policyArgument) + resultMatchmakeSession.Gathering.Flags = types.NewUInt32(flags) + resultMatchmakeSession.Gathering.State = types.NewUInt32(state) + resultMatchmakeSession.Gathering.Description = types.NewString(description) + resultMatchmakeSession.ParticipationCount = types.NewUInt32(participationCount) resultMatchmakeSession.StartedTime = resultMatchmakeSession.StartedTime.FromTimestamp(startedTime) + resultMatchmakeSession.GameMode = types.NewUInt32(gameMode) - attributesSlice := make([]*types.PrimitiveU32, len(resultAttribs)) + attributesSlice := make([]types.UInt32, len(resultAttribs)) for i, value := range resultAttribs { - attributesSlice[i] = types.NewPrimitiveU32(value) + attributesSlice[i] = types.NewUInt32(value) } - resultMatchmakeSession.Attributes.SetFromData(attributesSlice) + resultMatchmakeSession.Attributes = attributesSlice + + resultMatchmakeSession.OpenParticipation = types.NewBool(openParticipation) + resultMatchmakeSession.MatchmakeSystemType = types.NewUInt32(matchmakeSystemType) + resultMatchmakeSession.ApplicationBuffer = applicationBuffer + resultMatchmakeSession.ProgressScore = types.NewUInt8(progressScore) + resultMatchmakeSession.SessionKey = sessionKey + resultMatchmakeSession.Option = types.UInt32(option) matchmakeParamBytes := nex.NewByteStreamIn(resultMatchmakeParam, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) resultMatchmakeSession.MatchmakeParam.ExtractFrom(matchmakeParamBytes) + resultMatchmakeSession.UserPassword = types.NewString(userPassword) + resultMatchmakeSession.ReferGID = types.NewUInt32(referGID) + resultMatchmakeSession.UserPasswordEnabled = types.NewBool(userPasswordEnabled) + resultMatchmakeSession.SystemPasswordEnabled = types.NewBool(systemPasswordEnabled) + resultMatchmakeSession.CodeWord = types.String(codeWord) + resultMatchmakeSessions = append(resultMatchmakeSessions, resultMatchmakeSession) } diff --git a/matchmake-extension/database/get_detailed_gathering_by_id.go b/matchmake-extension/database/get_detailed_gathering_by_id.go index 600fb4a..399699e 100644 --- a/matchmake-extension/database/get_detailed_gathering_by_id.go +++ b/matchmake-extension/database/get_detailed_gathering_by_id.go @@ -29,8 +29,8 @@ func GetDetailedGatheringByID(manager *common_globals.MatchmakingManager, gather } // * Scrap session key and user password - matchmakeSession.SessionKey.Value = make([]byte, 0) - matchmakeSession.UserPassword.Value = "" + matchmakeSession.SessionKey = make([]byte, 0) + matchmakeSession.UserPassword = "" return matchmakeSession, gatheringType, nil } diff --git a/matchmake-extension/database/get_matchmake_session_by_gathering.go b/matchmake-extension/database/get_matchmake_session_by_gathering.go index f256eff..c180077 100644 --- a/matchmake-extension/database/get_matchmake_session_by_gathering.go +++ b/matchmake-extension/database/get_matchmake_session_by_gathering.go @@ -11,10 +11,21 @@ import ( ) // GetMatchmakeSessionByGathering gets a matchmake session with the given gathering data -func GetMatchmakeSessionByGathering(manager *common_globals.MatchmakingManager, endpoint *nex.PRUDPEndPoint, gathering *match_making_types.Gathering, participationCount uint32, startedTime *types.DateTime) (*match_making_types.MatchmakeSession, *nex.Error) { - resultMatchmakeSession := match_making_types.NewMatchmakeSession() +func GetMatchmakeSessionByGathering(manager *common_globals.MatchmakingManager, endpoint *nex.PRUDPEndPoint, gathering match_making_types.Gathering, participationCount uint32, startedTime types.DateTime) (match_making_types.MatchmakeSession, *nex.Error) { + var gameMode uint32 var resultAttribs []uint32 + var openParticipation bool + var matchmakeSystemType uint32 + var applicationBuffer []byte + var progressScore uint8 + var sessionKey []byte + var option uint32 var resultMatchmakeParam []byte + var userPassword string + var referGID uint32 + var userPasswordEnabled bool + var systemPasswordEnabled bool + var codeWord string err := manager.Database.QueryRow(`SELECT game_mode, @@ -32,43 +43,59 @@ func GetMatchmakeSessionByGathering(manager *common_globals.MatchmakingManager, system_password_enabled, codeword FROM matchmaking.matchmake_sessions WHERE id=$1`, - gathering.ID.Value, + uint32(gathering.ID), ).Scan( - &resultMatchmakeSession.GameMode.Value, + &gameMode, pqextended.Array(&resultAttribs), - &resultMatchmakeSession.OpenParticipation.Value, - &resultMatchmakeSession.MatchmakeSystemType.Value, - &resultMatchmakeSession.ApplicationBuffer.Value, - &resultMatchmakeSession.ProgressScore.Value, - &resultMatchmakeSession.SessionKey.Value, - &resultMatchmakeSession.Option.Value, + &openParticipation, + &matchmakeSystemType, + &applicationBuffer, + &progressScore, + &sessionKey, + &option, &resultMatchmakeParam, - &resultMatchmakeSession.UserPassword.Value, - &resultMatchmakeSession.ReferGID.Value, - &resultMatchmakeSession.UserPasswordEnabled.Value, - &resultMatchmakeSession.SystemPasswordEnabled.Value, - &resultMatchmakeSession.CodeWord.Value, + &userPassword, + &referGID, + &userPasswordEnabled, + &systemPasswordEnabled, + &codeWord, ) if err != nil { if err == sql.ErrNoRows { - return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + return match_making_types.NewMatchmakeSession(), nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") } else { - return nil, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) + return match_making_types.NewMatchmakeSession(), nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } } + resultMatchmakeSession := match_making_types.NewMatchmakeSession() + resultMatchmakeSession.Gathering = gathering - resultMatchmakeSession.ParticipationCount.Value = participationCount + resultMatchmakeSession.ParticipationCount = types.NewUInt32(participationCount) resultMatchmakeSession.StartedTime = startedTime + resultMatchmakeSession.GameMode = types.NewUInt32(gameMode) - attributesSlice := make([]*types.PrimitiveU32, len(resultAttribs)) + attributesSlice := make([]types.UInt32, len(resultAttribs)) for i, value := range resultAttribs { - attributesSlice[i] = types.NewPrimitiveU32(value) + attributesSlice[i] = types.NewUInt32(value) } - resultMatchmakeSession.Attributes.SetFromData(attributesSlice) + resultMatchmakeSession.Attributes = attributesSlice + + resultMatchmakeSession.OpenParticipation = types.NewBool(openParticipation) + resultMatchmakeSession.MatchmakeSystemType = types.NewUInt32(matchmakeSystemType) + resultMatchmakeSession.ApplicationBuffer = applicationBuffer + resultMatchmakeSession.ProgressScore = types.NewUInt8(progressScore) + resultMatchmakeSession.SessionKey = sessionKey + resultMatchmakeSession.Option = types.UInt32(option) matchmakeParamBytes := nex.NewByteStreamIn(resultMatchmakeParam, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) resultMatchmakeSession.MatchmakeParam.ExtractFrom(matchmakeParamBytes) + resultMatchmakeSession.UserPassword = types.NewString(userPassword) + resultMatchmakeSession.ReferGID = types.NewUInt32(referGID) + resultMatchmakeSession.UserPasswordEnabled = types.NewBool(userPasswordEnabled) + resultMatchmakeSession.SystemPasswordEnabled = types.NewBool(systemPasswordEnabled) + resultMatchmakeSession.CodeWord = types.String(codeWord) + return resultMatchmakeSession, nil } diff --git a/matchmake-extension/database/get_matchmake_session_by_id.go b/matchmake-extension/database/get_matchmake_session_by_id.go index 47d3ef5..2ffc694 100644 --- a/matchmake-extension/database/get_matchmake_session_by_id.go +++ b/matchmake-extension/database/get_matchmake_session_by_id.go @@ -12,13 +12,32 @@ import ( ) // GetMatchmakeSessionByID gets a matchmake session with the given gathering ID and the system password -func GetMatchmakeSessionByID(manager *common_globals.MatchmakingManager, endpoint *nex.PRUDPEndPoint, gatheringID uint32) (*match_making_types.MatchmakeSession, string, *nex.Error) { - resultMatchmakeSession := match_making_types.NewMatchmakeSession() +func GetMatchmakeSessionByID(manager *common_globals.MatchmakingManager, endpoint *nex.PRUDPEndPoint, gatheringID uint32) (match_making_types.MatchmakeSession, string, *nex.Error) { var ownerPID uint64 var hostPID uint64 + var minimumParticipants uint16 + var maximumParticipants uint16 + var participationPolicy uint32 + var policyArgument uint32 + var flags uint32 + var state uint32 + var description string + var participationCount uint32 var startedTime time.Time + var gameMode uint32 var resultAttribs []uint32 + var openParticipation bool + var matchmakeSystemType uint32 + var applicationBuffer []byte + var progressScore uint8 + var sessionKey []byte + var option uint32 var resultMatchmakeParam []byte + var userPassword string + var referGID uint32 + var userPasswordEnabled bool + var systemPasswordEnabled bool + var codeWord string var systemPassword string // * For simplicity, we will only compare the values that exist on a MatchmakeSessionSearchCriteria @@ -58,54 +77,79 @@ func GetMatchmakeSessionByID(manager *common_globals.MatchmakingManager, endpoin g.id=$1`, gatheringID, ).Scan( - &resultMatchmakeSession.Gathering.ID.Value, + &gatheringID, &ownerPID, &hostPID, - &resultMatchmakeSession.Gathering.MinimumParticipants.Value, - &resultMatchmakeSession.Gathering.MaximumParticipants.Value, - &resultMatchmakeSession.Gathering.ParticipationPolicy.Value, - &resultMatchmakeSession.Gathering.PolicyArgument.Value, - &resultMatchmakeSession.Gathering.Flags.Value, - &resultMatchmakeSession.Gathering.State.Value, - &resultMatchmakeSession.Gathering.Description.Value, - &resultMatchmakeSession.ParticipationCount.Value, + &minimumParticipants, + &maximumParticipants, + &participationPolicy, + &policyArgument, + &flags, + &state, + &description, + &participationCount, &startedTime, - &resultMatchmakeSession.GameMode.Value, + &gameMode, pqextended.Array(&resultAttribs), - &resultMatchmakeSession.OpenParticipation.Value, - &resultMatchmakeSession.MatchmakeSystemType.Value, - &resultMatchmakeSession.ApplicationBuffer.Value, - &resultMatchmakeSession.ProgressScore.Value, - &resultMatchmakeSession.SessionKey.Value, - &resultMatchmakeSession.Option.Value, + &openParticipation, + &matchmakeSystemType, + &applicationBuffer, + &progressScore, + &sessionKey, + &option, &resultMatchmakeParam, - &resultMatchmakeSession.UserPassword.Value, - &resultMatchmakeSession.ReferGID.Value, - &resultMatchmakeSession.UserPasswordEnabled.Value, - &resultMatchmakeSession.SystemPasswordEnabled.Value, - &resultMatchmakeSession.CodeWord.Value, + &userPassword, + &referGID, + &userPasswordEnabled, + &systemPasswordEnabled, + &codeWord, &systemPassword, ) if err != nil { if err == sql.ErrNoRows { - return nil, "", nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + return match_making_types.NewMatchmakeSession(), "", nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") } else { - return nil, "", nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) + return match_making_types.NewMatchmakeSession(), "", nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } } + resultMatchmakeSession := match_making_types.NewMatchmakeSession() + + resultMatchmakeSession.Gathering.ID = types.NewUInt32(gatheringID) resultMatchmakeSession.OwnerPID = types.NewPID(ownerPID) resultMatchmakeSession.HostPID = types.NewPID(hostPID) + resultMatchmakeSession.Gathering.MinimumParticipants = types.NewUInt16(minimumParticipants) + resultMatchmakeSession.Gathering.MaximumParticipants = types.NewUInt16(maximumParticipants) + resultMatchmakeSession.Gathering.ParticipationPolicy = types.NewUInt32(participationPolicy) + resultMatchmakeSession.Gathering.PolicyArgument = types.NewUInt32(policyArgument) + resultMatchmakeSession.Gathering.Flags = types.NewUInt32(flags) + resultMatchmakeSession.Gathering.State = types.NewUInt32(state) + resultMatchmakeSession.Gathering.Description = types.NewString(description) + resultMatchmakeSession.ParticipationCount = types.NewUInt32(participationCount) resultMatchmakeSession.StartedTime = resultMatchmakeSession.StartedTime.FromTimestamp(startedTime) + resultMatchmakeSession.GameMode = types.NewUInt32(gameMode) - attributesSlice := make([]*types.PrimitiveU32, len(resultAttribs)) + attributesSlice := make([]types.UInt32, len(resultAttribs)) for i, value := range resultAttribs { - attributesSlice[i] = types.NewPrimitiveU32(value) + attributesSlice[i] = types.NewUInt32(value) } - resultMatchmakeSession.Attributes.SetFromData(attributesSlice) + resultMatchmakeSession.Attributes = attributesSlice + + resultMatchmakeSession.OpenParticipation = types.NewBool(openParticipation) + resultMatchmakeSession.MatchmakeSystemType = types.NewUInt32(matchmakeSystemType) + resultMatchmakeSession.ApplicationBuffer = applicationBuffer + resultMatchmakeSession.ProgressScore = types.NewUInt8(progressScore) + resultMatchmakeSession.SessionKey = sessionKey + resultMatchmakeSession.Option = types.UInt32(option) matchmakeParamBytes := nex.NewByteStreamIn(resultMatchmakeParam, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) resultMatchmakeSession.MatchmakeParam.ExtractFrom(matchmakeParamBytes) + resultMatchmakeSession.UserPassword = types.NewString(userPassword) + resultMatchmakeSession.ReferGID = types.NewUInt32(referGID) + resultMatchmakeSession.UserPasswordEnabled = types.NewBool(userPasswordEnabled) + resultMatchmakeSession.SystemPasswordEnabled = types.NewBool(systemPasswordEnabled) + resultMatchmakeSession.CodeWord = types.String(codeWord) + return resultMatchmakeSession, systemPassword, nil } diff --git a/matchmake-extension/database/get_simple_playing_session.go b/matchmake-extension/database/get_simple_playing_session.go index e4724e5..a9bb1c7 100644 --- a/matchmake-extension/database/get_simple_playing_session.go +++ b/matchmake-extension/database/get_simple_playing_session.go @@ -10,10 +10,13 @@ import ( ) // GetSimplePlayingSession returns the simple playing sessions of the given PIDs -func GetSimplePlayingSession(manager *common_globals.MatchmakingManager, listPID []*types.PID) ([]*match_making_types.SimplePlayingSession, *nex.Error) { - simplePlayingSessions := make([]*match_making_types.SimplePlayingSession, 0) +func GetSimplePlayingSession(manager *common_globals.MatchmakingManager, listPID []types.PID) ([]match_making_types.SimplePlayingSession, *nex.Error) { + simplePlayingSessions := make([]match_making_types.SimplePlayingSession, 0) for _, pid := range listPID { - simplePlayingSession := match_making_types.NewSimplePlayingSession() + var gatheringID uint32 + var attribute0 uint32 + var gameMode uint32 + err := manager.Database.QueryRow(`SELECT g.id, ms.attribs[1], @@ -23,10 +26,10 @@ func GetSimplePlayingSession(manager *common_globals.MatchmakingManager, listPID WHERE g.registered=true AND g.type='MatchmakeSession' AND - $1=ANY(g.participants)`, pid.Value()).Scan( - &simplePlayingSession.GatheringID.Value, - &simplePlayingSession.Attribute0.Value, - &simplePlayingSession.GameMode.Value) + $1=ANY(g.participants)`, uint64(pid)).Scan( + &gatheringID, + &attribute0, + &gameMode) if err != nil { if err != sql.ErrNoRows { common_globals.Logger.Critical(err.Error()) @@ -34,7 +37,12 @@ func GetSimplePlayingSession(manager *common_globals.MatchmakingManager, listPID continue } + simplePlayingSession := match_making_types.NewSimplePlayingSession() + simplePlayingSession.PrincipalID = pid + simplePlayingSession.GatheringID = types.NewUInt32(gatheringID) + simplePlayingSession.Attribute0 = types.NewUInt32(attribute0) + simplePlayingSession.GameMode = types.NewUInt32(gameMode) simplePlayingSessions = append(simplePlayingSessions, simplePlayingSession) } diff --git a/matchmake-extension/database/update_application_buffer.go b/matchmake-extension/database/update_application_buffer.go index 357d3ed..c97e495 100644 --- a/matchmake-extension/database/update_application_buffer.go +++ b/matchmake-extension/database/update_application_buffer.go @@ -7,8 +7,8 @@ import ( ) // UpdateApplicationBuffer updates the application buffer of a matchmake session -func UpdateApplicationBuffer(manager *common_globals.MatchmakingManager, gatheringID uint32, applicationBuffer *types.Buffer) *nex.Error { - result, err := manager.Database.Exec(`UPDATE matchmaking.matchmake_sessions SET application_buffer=$1 WHERE id=$2`, applicationBuffer.Value, gatheringID) +func UpdateApplicationBuffer(manager *common_globals.MatchmakingManager, gatheringID uint32, applicationBuffer types.Buffer) *nex.Error { + result, err := manager.Database.Exec(`UPDATE matchmaking.matchmake_sessions SET application_buffer=$1 WHERE id=$2`, []byte(applicationBuffer), gatheringID) if err != nil { return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } diff --git a/matchmake-extension/get_simple_playing_session.go b/matchmake-extension/get_simple_playing_session.go index aa5c9bd..d0c4108 100644 --- a/matchmake-extension/get_simple_playing_session.go +++ b/matchmake-extension/get_simple_playing_session.go @@ -1,6 +1,8 @@ package matchmake_extension import ( + "slices" + "github.com/PretendoNetwork/nex-go/v2" "github.com/PretendoNetwork/nex-go/v2/types" common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" @@ -9,7 +11,7 @@ import ( matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func (commonProtocol *CommonProtocol) getSimplePlayingSession(err error, packet nex.PacketInterface, callID uint32, listPID *types.List[*types.PID], includeLoginUser *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) getSimplePlayingSession(err error, packet nex.PacketInterface, callID uint32, listPID types.List[types.PID], includeLoginUser types.Bool) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -19,15 +21,17 @@ func (commonProtocol *CommonProtocol) getSimplePlayingSession(err error, packet endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) // * Does nothing if element is not present in the List - listPID.Remove(connection.PID()) + listPID = slices.DeleteFunc(listPID, func(pid types.PID) bool { + return pid == connection.PID() + }) - if includeLoginUser.Value && !listPID.Contains(connection.PID()) { - listPID.Append(connection.PID().Copy().(*types.PID)) + if includeLoginUser { + listPID = append(listPID, connection.PID()) } commonProtocol.manager.Mutex.RLock() - simplePlayingSessions, nexError := database.GetSimplePlayingSession(commonProtocol.manager, listPID.Slice()) + simplePlayingSessions, nexError := database.GetSimplePlayingSession(commonProtocol.manager, listPID) if nexError != nil { commonProtocol.manager.Mutex.RUnlock() return nil, nexError @@ -35,8 +39,8 @@ func (commonProtocol *CommonProtocol) getSimplePlayingSession(err error, packet commonProtocol.manager.Mutex.RUnlock() - lstSimplePlayingSession := types.NewList[*match_making_types.SimplePlayingSession]() - lstSimplePlayingSession.SetFromData(simplePlayingSessions) + lstSimplePlayingSession := types.NewList[match_making_types.SimplePlayingSession]() + lstSimplePlayingSession = simplePlayingSessions rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/matchmake-extension/join_matchmake_session.go b/matchmake-extension/join_matchmake_session.go index bc9c976..ff8d27c 100644 --- a/matchmake-extension/join_matchmake_session.go +++ b/matchmake-extension/join_matchmake_session.go @@ -9,13 +9,13 @@ import ( matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func (commonProtocol *CommonProtocol) joinMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) joinMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32, strMessage types.String) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } - if len(strMessage.Value) > 256 { + if len(strMessage) > 256 { return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } @@ -25,7 +25,7 @@ func (commonProtocol *CommonProtocol) joinMatchmakeSession(err error, packet nex endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) server := endpoint.Server - joinedMatchmakeSession, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, gid.Value) + joinedMatchmakeSession, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, uint32(gid)) if nexError != nil { common_globals.Logger.Error(nexError.Error()) commonProtocol.manager.Mutex.Unlock() @@ -33,7 +33,7 @@ func (commonProtocol *CommonProtocol) joinMatchmakeSession(err error, packet nex } // TODO - Is this the correct error code? - if joinedMatchmakeSession.UserPasswordEnabled.Value || joinedMatchmakeSession.SystemPasswordEnabled.Value { + if joinedMatchmakeSession.UserPasswordEnabled || joinedMatchmakeSession.SystemPasswordEnabled { commonProtocol.manager.Mutex.Unlock() return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } @@ -49,7 +49,7 @@ func (commonProtocol *CommonProtocol) joinMatchmakeSession(err error, packet nex return nil, nexError } - _, nexError = match_making_database.JoinGathering(commonProtocol.manager, joinedMatchmakeSession.Gathering.ID.Value, connection, 1, strMessage.Value) + _, nexError = match_making_database.JoinGathering(commonProtocol.manager, uint32(joinedMatchmakeSession.Gathering.ID), connection, 1, string(strMessage)) if nexError != nil { common_globals.Logger.Error(nexError.Error()) commonProtocol.manager.Mutex.Unlock() diff --git a/matchmake-extension/join_matchmake_session_ex.go b/matchmake-extension/join_matchmake_session_ex.go index 7deb01b..6b472e2 100644 --- a/matchmake-extension/join_matchmake_session_ex.go +++ b/matchmake-extension/join_matchmake_session_ex.go @@ -9,13 +9,13 @@ import ( matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func (commonProtocol *CommonProtocol) joinMatchmakeSessionEx(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, strMessage *types.String, dontCareMyBlockList *types.PrimitiveBool, participationCount *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) joinMatchmakeSessionEx(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32, strMessage types.String, dontCareMyBlockList types.Bool, 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") } - if len(strMessage.Value) > 256 { + if len(strMessage) > 256 { return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } @@ -25,7 +25,7 @@ func (commonProtocol *CommonProtocol) joinMatchmakeSessionEx(err error, packet n endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) server := endpoint.Server - joinedMatchmakeSession, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, gid.Value) + joinedMatchmakeSession, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, uint32(gid)) if nexError != nil { common_globals.Logger.Error(nexError.Error()) commonProtocol.manager.Mutex.Unlock() @@ -33,7 +33,7 @@ func (commonProtocol *CommonProtocol) joinMatchmakeSessionEx(err error, packet n } // TODO - Is this the correct error code? - if joinedMatchmakeSession.UserPasswordEnabled.Value || joinedMatchmakeSession.SystemPasswordEnabled.Value { + if joinedMatchmakeSession.UserPasswordEnabled || joinedMatchmakeSession.SystemPasswordEnabled { commonProtocol.manager.Mutex.Unlock() return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } @@ -49,7 +49,7 @@ func (commonProtocol *CommonProtocol) joinMatchmakeSessionEx(err error, packet n return nil, nexError } - _, nexError = match_making_database.JoinGathering(commonProtocol.manager, joinedMatchmakeSession.Gathering.ID.Value, connection, participationCount.Value, strMessage.Value) + _, nexError = match_making_database.JoinGathering(commonProtocol.manager, uint32(joinedMatchmakeSession.Gathering.ID), connection, uint16(participationCount), string(strMessage)) if nexError != nil { common_globals.Logger.Error(nexError.Error()) commonProtocol.manager.Mutex.Unlock() diff --git a/matchmake-extension/join_matchmake_session_with_param.go b/matchmake-extension/join_matchmake_session_with_param.go index a43d808..b688e37 100644 --- a/matchmake-extension/join_matchmake_session_with_param.go +++ b/matchmake-extension/join_matchmake_session_with_param.go @@ -10,13 +10,13 @@ import ( matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func (commonProtocol *CommonProtocol) joinMatchmakeSessionWithParam(err error, packet nex.PacketInterface, callID uint32, joinMatchmakeSessionParam *match_making_types.JoinMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) joinMatchmakeSessionWithParam(err error, packet nex.PacketInterface, callID uint32, joinMatchmakeSessionParam match_making_types.JoinMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } - if len(joinMatchmakeSessionParam.JoinMessage.Value) > 256 { + if len(joinMatchmakeSessionParam.JoinMessage) > 256 { return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } @@ -25,16 +25,16 @@ func (commonProtocol *CommonProtocol) joinMatchmakeSessionWithParam(err error, p connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) - if joinMatchmakeSessionParam.GIDForParticipationCheck.Value != 0 { + if joinMatchmakeSessionParam.GIDForParticipationCheck != 0 { // * Check that all new participants are participating in the specified gathering ID - nexError := database.CheckGatheringForParticipation(commonProtocol.manager, joinMatchmakeSessionParam.GIDForParticipationCheck.Value, append(joinMatchmakeSessionParam.AdditionalParticipants.Slice(), connection.PID())) + nexError := database.CheckGatheringForParticipation(commonProtocol.manager, uint32(joinMatchmakeSessionParam.GIDForParticipationCheck), append(joinMatchmakeSessionParam.AdditionalParticipants, connection.PID())) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } } - joinedMatchmakeSession, systemPassword, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, joinMatchmakeSessionParam.GID.Value) + joinedMatchmakeSession, systemPassword, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, uint32(joinMatchmakeSessionParam.GID)) if nexError != nil { common_globals.Logger.Error(nexError.Error()) commonProtocol.manager.Mutex.Unlock() @@ -42,12 +42,12 @@ func (commonProtocol *CommonProtocol) joinMatchmakeSessionWithParam(err error, p } // TODO - Are these the correct error codes? - if joinedMatchmakeSession.UserPasswordEnabled.Value && !joinMatchmakeSessionParam.StrUserPassword.Equals(joinedMatchmakeSession.UserPassword) { + if bool(joinedMatchmakeSession.UserPasswordEnabled) && !joinMatchmakeSessionParam.StrUserPassword.Equals(joinedMatchmakeSession.UserPassword) { commonProtocol.manager.Mutex.Unlock() return nil, nex.NewError(nex.ResultCodes.RendezVous.InvalidPassword, "change_error") } - if joinedMatchmakeSession.SystemPasswordEnabled.Value && joinMatchmakeSessionParam.StrSystemPassword.Value != systemPassword { + if bool(joinedMatchmakeSession.SystemPasswordEnabled) && string(joinMatchmakeSessionParam.StrSystemPassword) != systemPassword { commonProtocol.manager.Mutex.Unlock() return nil, nex.NewError(nex.ResultCodes.RendezVous.InvalidPassword, "change_error") } @@ -63,7 +63,7 @@ func (commonProtocol *CommonProtocol) joinMatchmakeSessionWithParam(err error, p return nil, nexError } - _, nexError = match_making_database.JoinGatheringWithParticipants(commonProtocol.manager, joinedMatchmakeSession.Gathering.ID.Value, connection, joinMatchmakeSessionParam.AdditionalParticipants.Slice(), joinMatchmakeSessionParam.JoinMessage.Value, constants.JoinMatchmakeSessionBehavior(joinMatchmakeSessionParam.JoinMatchmakeSessionBehavior.Value)) + _, nexError = match_making_database.JoinGatheringWithParticipants(commonProtocol.manager, uint32(joinedMatchmakeSession.Gathering.ID), connection, joinMatchmakeSessionParam.AdditionalParticipants, string(joinMatchmakeSessionParam.JoinMessage), constants.JoinMatchmakeSessionBehavior(joinMatchmakeSessionParam.JoinMatchmakeSessionBehavior)) if nexError != nil { common_globals.Logger.Error(nexError.Error()) commonProtocol.manager.Mutex.Unlock() diff --git a/matchmake-extension/modify_current_game_attribute.go b/matchmake-extension/modify_current_game_attribute.go index d669126..7be095a 100644 --- a/matchmake-extension/modify_current_game_attribute.go +++ b/matchmake-extension/modify_current_game_attribute.go @@ -8,7 +8,7 @@ import ( matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func (commonProtocol *CommonProtocol) modifyCurrentGameAttribute(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, attribIndex *types.PrimitiveU32, newValue *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) modifyCurrentGameAttribute(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32, attribIndex types.UInt32, newValue types.UInt32) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -19,7 +19,7 @@ func (commonProtocol *CommonProtocol) modifyCurrentGameAttribute(err error, pack commonProtocol.manager.Mutex.Lock() - session, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, gid.Value) + session, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, uint32(gid)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -30,14 +30,14 @@ func (commonProtocol *CommonProtocol) modifyCurrentGameAttribute(err error, pack return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } - index := int(attribIndex.Value) + index := int(attribIndex) - if index >= session.Attributes.Length() { + if index >= len(session.Attributes) { commonProtocol.manager.Mutex.Unlock() return nil, nex.NewError(nex.ResultCodes.Core.InvalidIndex, "change_error") } - nexError = database.UpdateGameAttribute(commonProtocol.manager, gid.Value, attribIndex.Value, newValue.Value) + nexError = database.UpdateGameAttribute(commonProtocol.manager, uint32(gid), uint32(attribIndex), uint32(newValue)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError diff --git a/matchmake-extension/open_participation.go b/matchmake-extension/open_participation.go index dcdf319..5c25cfb 100644 --- a/matchmake-extension/open_participation.go +++ b/matchmake-extension/open_participation.go @@ -8,7 +8,7 @@ import ( matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func (commonProtocol *CommonProtocol) openParticipation(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) openParticipation(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -20,7 +20,7 @@ func (commonProtocol *CommonProtocol) openParticipation(err error, packet nex.Pa commonProtocol.manager.Mutex.Lock() - session, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, gid.Value) + session, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, uint32(gid)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -31,7 +31,7 @@ func (commonProtocol *CommonProtocol) openParticipation(err error, packet nex.Pa return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } - nexError = database.UpdateParticipation(commonProtocol.manager, gid.Value, true) + nexError = database.UpdateParticipation(commonProtocol.manager, uint32(gid), true) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError diff --git a/matchmake-extension/protocol.go b/matchmake-extension/protocol.go index 4ad9b2b..2dda14e 100644 --- a/matchmake-extension/protocol.go +++ b/matchmake-extension/protocol.go @@ -14,24 +14,24 @@ type CommonProtocol struct { endpoint nex.EndpointInterface protocol matchmake_extension.Interface manager *common_globals.MatchmakingManager - CanJoinMatchmakeSession func(manager *common_globals.MatchmakingManager, pid *types.PID, matchmakeSession *match_making_types.MatchmakeSession) *nex.Error + CanJoinMatchmakeSession func(manager *common_globals.MatchmakingManager, pid types.PID, matchmakeSession match_making_types.MatchmakeSession) *nex.Error CleanupSearchMatchmakeSession func(matchmakeSession *match_making_types.MatchmakeSession) - CleanupMatchmakeSessionSearchCriterias func(searchCriterias *types.List[*match_making_types.MatchmakeSessionSearchCriteria]) - OnAfterOpenParticipation func(packet nex.PacketInterface, gid *types.PrimitiveU32) - OnAfterCloseParticipation func(packet nex.PacketInterface, gid *types.PrimitiveU32) - OnAfterCreateMatchmakeSession func(packet nex.PacketInterface, anyGathering *types.AnyDataHolder, message *types.String, participationCount *types.PrimitiveU16) - OnAfterGetSimplePlayingSession func(packet nex.PacketInterface, listPID *types.List[*types.PID], includeLoginUser *types.PrimitiveBool) - OnAfterAutoMatchmakePostpone func(packet nex.PacketInterface, anyGathering *types.AnyDataHolder, 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) - OnAfterUpdateProgressScore func(packet nex.PacketInterface, gid *types.PrimitiveU32, progressScore *types.PrimitiveU8) - OnAfterCreateMatchmakeSessionWithParam func(packet nex.PacketInterface, createMatchmakeSessionParam *match_making_types.CreateMatchmakeSessionParam) - OnAfterUpdateApplicationBuffer func(packet nex.PacketInterface, gid *types.PrimitiveU32, applicationBuffer *types.Buffer) - OnAfterJoinMatchmakeSession func(packet nex.PacketInterface, gid *types.PrimitiveU32, strMessage *types.String) - OnAfterJoinMatchmakeSessionWithParam func(packet nex.PacketInterface, joinMatchmakeSessionParam *match_making_types.JoinMatchmakeSessionParam) - OnAfterModifyCurrentGameAttribute func(packet nex.PacketInterface, gid *types.PrimitiveU32, attribIndex *types.PrimitiveU32, newValue *types.PrimitiveU32) - OnAfterBrowseMatchmakeSession func(packet nex.PacketInterface, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) - OnAfterJoinMatchmakeSessionEx func(packet nex.PacketInterface, gid *types.PrimitiveU32, strMessage *types.String, dontCareMyBlockList *types.PrimitiveBool, participationCount *types.PrimitiveU16) + 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 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 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 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) + OnAfterJoinMatchmakeSession func(packet nex.PacketInterface, gid types.UInt32, strMessage types.String) + OnAfterJoinMatchmakeSessionWithParam func(packet nex.PacketInterface, joinMatchmakeSessionParam match_making_types.JoinMatchmakeSessionParam) + OnAfterModifyCurrentGameAttribute func(packet nex.PacketInterface, gid types.UInt32, attribIndex types.UInt32, newValue types.UInt32) + OnAfterBrowseMatchmakeSession func(packet nex.PacketInterface, searchCriteria match_making_types.MatchmakeSessionSearchCriteria, resultRange types.ResultRange) + OnAfterJoinMatchmakeSessionEx func(packet nex.PacketInterface, gid types.UInt32, strMessage types.String, dontCareMyBlockList types.Bool, participationCount types.UInt16) } // SetDatabase defines the matchmaking manager to be used by the common protocol diff --git a/matchmake-extension/update_application_buffer.go b/matchmake-extension/update_application_buffer.go index 3b597a9..73da8b8 100644 --- a/matchmake-extension/update_application_buffer.go +++ b/matchmake-extension/update_application_buffer.go @@ -8,7 +8,7 @@ import ( matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func (commonProtocol *CommonProtocol) updateApplicationBuffer(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, applicationBuffer *types.Buffer) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) updateApplicationBuffer(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32, applicationBuffer types.Buffer) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -19,7 +19,7 @@ func (commonProtocol *CommonProtocol) updateApplicationBuffer(err error, packet commonProtocol.manager.Mutex.Lock() - session, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, gid.Value) + session, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, uint32(gid)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -30,7 +30,7 @@ func (commonProtocol *CommonProtocol) updateApplicationBuffer(err error, packet return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } - nexError = database.UpdateApplicationBuffer(commonProtocol.manager, gid.Value, applicationBuffer) + nexError = database.UpdateApplicationBuffer(commonProtocol.manager, uint32(gid), applicationBuffer) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError diff --git a/matchmake-extension/update_progress_score.go b/matchmake-extension/update_progress_score.go index cb45711..66c21eb 100644 --- a/matchmake-extension/update_progress_score.go +++ b/matchmake-extension/update_progress_score.go @@ -8,7 +8,7 @@ import ( matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func (commonProtocol *CommonProtocol) updateProgressScore(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, progressScore *types.PrimitiveU8) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) updateProgressScore(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32, progressScore types.UInt8) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -17,13 +17,13 @@ func (commonProtocol *CommonProtocol) updateProgressScore(err error, packet nex. connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) - if progressScore.Value > 100 { + if progressScore > 100 { return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } commonProtocol.manager.Mutex.Lock() - session, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, gid.Value) + session, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, uint32(gid)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError @@ -34,7 +34,7 @@ func (commonProtocol *CommonProtocol) updateProgressScore(err error, packet nex. return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } - nexError = database.UpdateProgressScore(commonProtocol.manager, gid.Value, progressScore.Value) + nexError = database.UpdateProgressScore(commonProtocol.manager, uint32(gid), uint8(progressScore)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError diff --git a/nat-traversal/get_relay_signature_key.go b/nat-traversal/get_relay_signature_key.go index 135021a..783dab3 100644 --- a/nat-traversal/get_relay_signature_key.go +++ b/nat-traversal/get_relay_signature_key.go @@ -16,12 +16,12 @@ func (commonProtocol *CommonProtocol) getRelaySignatureKey(err error, packet nex connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) - relayMode := types.NewPrimitiveS32(0) // * Relay mode? No idea what this means + relayMode := types.NewInt32(0) // * Relay mode? No idea what this means currentUTCTime := types.NewDateTime(0).Now() // * Current time for the relay server, UTC address := types.NewString("") // * Relay server address. We don't have one, so for now this is empty. - port := types.NewPrimitiveU16(0) // * Relay server port. We don't have one, so for now this is empty. - relayAddressType := types.NewPrimitiveS32(0) // * Relay address type? No idea what this means - gameServerID := types.NewPrimitiveU32(0) // * Game Server ID. I don't know if this is checked (it doesn't appear to be though). + port := types.NewUInt16(0) // * Relay server port. We don't have one, so for now this is empty. + relayAddressType := types.NewInt32(0) // * Relay address type? No idea what this means + gameServerID := types.NewUInt32(0) // * Game Server ID. I don't know if this is checked (it doesn't appear to be though). rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/nat-traversal/protocol.go b/nat-traversal/protocol.go index 81a23f5..1864d35 100644 --- a/nat-traversal/protocol.go +++ b/nat-traversal/protocol.go @@ -9,11 +9,11 @@ import ( type CommonProtocol struct { endpoint nex.EndpointInterface protocol nat_traversal.Interface - OnAfterRequestProbeInitiationExt func(packet nex.PacketInterface, targetList *types.List[*types.String], stationToProbe *types.String) - OnAfterReportNATProperties func(packet nex.PacketInterface, natmapping *types.PrimitiveU32, natfiltering *types.PrimitiveU32, rtt *types.PrimitiveU32) - OnAfterReportNATTraversalResult func(packet nex.PacketInterface, cid *types.PrimitiveU32, result *types.PrimitiveBool, rtt *types.PrimitiveU32) + OnAfterRequestProbeInitiationExt func(packet nex.PacketInterface, targetList types.List[types.String], stationToProbe types.String) + OnAfterReportNATProperties func(packet nex.PacketInterface, natmapping types.UInt32, natfiltering types.UInt32, rtt types.UInt32) + OnAfterReportNATTraversalResult func(packet nex.PacketInterface, cid types.UInt32, result types.Bool, rtt types.UInt32) OnAfterGetRelaySignatureKey func(packet nex.PacketInterface) - OnAfterReportNATTraversalResultDetail func(packet nex.PacketInterface, cid *types.PrimitiveU32, result *types.PrimitiveBool, detail *types.PrimitiveS32, rtt *types.PrimitiveU32) + OnAfterReportNATTraversalResultDetail func(packet nex.PacketInterface, cid types.UInt32, result types.Bool, detail types.Int32, rtt types.UInt32) } // NewCommonProtocol returns a new CommonProtocol diff --git a/nat-traversal/report_nat_properties.go b/nat-traversal/report_nat_properties.go index fb0bc6c..8dfff1a 100644 --- a/nat-traversal/report_nat_properties.go +++ b/nat-traversal/report_nat_properties.go @@ -8,7 +8,7 @@ import ( nat_traversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" ) -func (commonProtocol *CommonProtocol) reportNATProperties(err error, packet nex.PacketInterface, callID uint32, natmapping *types.PrimitiveU32, natfiltering *types.PrimitiveU32, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) reportNATProperties(err error, packet nex.PacketInterface, callID uint32, natmapping types.UInt32, natfiltering types.UInt32, rtt types.UInt32) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -17,10 +17,10 @@ func (commonProtocol *CommonProtocol) reportNATProperties(err error, packet nex. connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) - for _, station := range connection.StationURLs.Slice() { + for _, station := range connection.StationURLs { if !station.IsPublic() { - station.SetNATMapping(constants.NATMappingProperties(natmapping.Value)) - station.SetNATFiltering(constants.NATFilteringProperties(natfiltering.Value)) + station.SetNATMapping(constants.NATMappingProperties(natmapping)) + station.SetNATFiltering(constants.NATFilteringProperties(natfiltering)) } station.SetRVConnectionID(connection.ID) diff --git a/nat-traversal/report_nat_traversal_result.go b/nat-traversal/report_nat_traversal_result.go index 54bd2ff..aa2ca0f 100644 --- a/nat-traversal/report_nat_traversal_result.go +++ b/nat-traversal/report_nat_traversal_result.go @@ -7,7 +7,7 @@ import ( nat_traversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" ) -func (commonProtocol *CommonProtocol) reportNATTraversalResult(err error, packet nex.PacketInterface, callID uint32, cid *types.PrimitiveU32, result *types.PrimitiveBool, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) reportNATTraversalResult(err error, packet nex.PacketInterface, callID uint32, cid types.UInt32, result types.Bool, rtt types.UInt32) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") diff --git a/nat-traversal/report_nat_traversal_result_detail.go b/nat-traversal/report_nat_traversal_result_detail.go index cd38b03..0d151d5 100644 --- a/nat-traversal/report_nat_traversal_result_detail.go +++ b/nat-traversal/report_nat_traversal_result_detail.go @@ -7,7 +7,7 @@ import ( nat_traversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" ) -func (commonProtocol *CommonProtocol) reportNATTraversalResultDetail(err error, packet nex.PacketInterface, callID uint32, cid *types.PrimitiveU32, result *types.PrimitiveBool, detail *types.PrimitiveS32, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) reportNATTraversalResultDetail(err error, packet nex.PacketInterface, callID uint32, cid types.UInt32, result types.Bool, detail types.Int32, rtt types.UInt32) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") diff --git a/nat-traversal/request_probe_initiation_ext.go b/nat-traversal/request_probe_initiation_ext.go index 1a6ae0c..c94def2 100644 --- a/nat-traversal/request_probe_initiation_ext.go +++ b/nat-traversal/request_probe_initiation_ext.go @@ -8,7 +8,7 @@ import ( nat_traversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" ) -func (commonProtocol *CommonProtocol) requestProbeInitiationExt(err error, packet nex.PacketInterface, callID uint32, targetList *types.List[*types.String], stationToProbe *types.String) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) requestProbeInitiationExt(err error, packet nex.PacketInterface, callID uint32, targetList types.List[types.String], stationToProbe types.String) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -37,8 +37,8 @@ func (commonProtocol *CommonProtocol) requestProbeInitiationExt(err error, packe rmcRequestBytes := rmcRequest.Bytes() - for _, target := range targetList.Slice() { - targetStation := types.NewStationURL(target.Value) + for _, target := range targetList { + targetStation := types.NewStationURL(target) if connectionID, ok := targetStation.RVConnectionID(); ok { target := endpoint.FindConnectionByID(connectionID) diff --git a/ranking/get_cached_top_x_ranking.go b/ranking/get_cached_top_x_ranking.go index 2605201..b69ac24 100644 --- a/ranking/get_cached_top_x_ranking.go +++ b/ranking/get_cached_top_x_ranking.go @@ -10,7 +10,7 @@ import ( ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" ) -func (commonProtocol *CommonProtocol) getCachedTopXRanking(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) getCachedTopXRanking(err error, packet nex.PacketInterface, callID uint32, category types.UInt32, orderParam ranking_types.RankingOrderParam) (*nex.RMCMessage, *nex.Error) { if commonProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam == nil { common_globals.Logger.Warning("Ranking::GetCachedTopXRanking missing GetRankingsAndCountByCategoryAndRankingOrderParam!") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -30,14 +30,14 @@ func (commonProtocol *CommonProtocol) getCachedTopXRanking(err error, packet nex return nil, nex.NewError(nex.ResultCodes.Ranking.Unknown, "change_error") } - if totalCount == 0 || rankDataList.Length() == 0 { + if totalCount == 0 || len(rankDataList) == 0 { return nil, nex.NewError(nex.ResultCodes.Ranking.NotFound, "change_error") } pResult := ranking_types.NewRankingCachedResult() pResult.RankingResult.RankDataList = rankDataList - pResult.RankingResult.TotalCount = types.NewPrimitiveU32(totalCount) + pResult.RankingResult.TotalCount = types.NewUInt32(totalCount) pResult.RankingResult.SinceTime = types.NewDateTime(0x1F40420000) // * 2000-01-01T00:00:00.000Z, this is what the real server sends back pResult.CreatedTime = types.NewDateTime(0).Now() @@ -48,7 +48,7 @@ func (commonProtocol *CommonProtocol) getCachedTopXRanking(err error, packet nex pResult.ExpiredTime = types.NewDateTime(0).FromTimestamp(time.Now().UTC().Add(time.Minute * time.Duration(5))) // * This is the length Ultimate NES Remix uses // TODO - Does this matter? and are other games different? - pResult.MaxLength = types.NewPrimitiveU8(10) + pResult.MaxLength = types.NewUInt8(10) rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/ranking/get_cached_top_x_rankings.go b/ranking/get_cached_top_x_rankings.go index c610e7d..3caf00b 100644 --- a/ranking/get_cached_top_x_rankings.go +++ b/ranking/get_cached_top_x_rankings.go @@ -10,7 +10,7 @@ import ( ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" ) -func (commonProtocol *CommonProtocol) getCachedTopXRankings(err error, packet nex.PacketInterface, callID uint32, categories *types.List[*types.PrimitiveU32], orderParams *types.List[*ranking_types.RankingOrderParam]) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) getCachedTopXRankings(err error, packet nex.PacketInterface, callID uint32, categories types.List[types.UInt32], orderParams types.List[ranking_types.RankingOrderParam]) (*nex.RMCMessage, *nex.Error) { if commonProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam == nil { common_globals.Logger.Warning("Ranking::GetCachedTopXRankings missing GetRankingsAndCountByCategoryAndRankingOrderParam!") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -22,23 +22,18 @@ func (commonProtocol *CommonProtocol) getCachedTopXRankings(err error, packet ne } // TODO - Is this true? - if categories.Length() != orderParams.Length() { + if len(categories) != len(orderParams) { return nil, nex.NewError(nex.ResultCodes.Ranking.InvalidArgument, "change_error") } connection := packet.Sender() endpoint := connection.Endpoint() - pResult := types.NewList[*ranking_types.RankingCachedResult]() + pResult := types.NewList[ranking_types.RankingCachedResult]() - pResult.Type = ranking_types.NewRankingCachedResult() - - for i, category := range categories.Slice() { - orderParam, err := orderParams.Get(i) - if err != nil { - common_globals.Logger.Error(err.Error()) - return nil, nex.NewError(nex.ResultCodes.Ranking.InvalidArgument, "change_error") - } + for i, category := range categories { + // * We already checked that categories and orderParams have the same length + orderParam := orderParams[i] rankDataList, totalCount, err := commonProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam(category, orderParam) if err != nil { @@ -46,14 +41,14 @@ func (commonProtocol *CommonProtocol) getCachedTopXRankings(err error, packet ne return nil, nex.NewError(nex.ResultCodes.Ranking.Unknown, "change_error") } - if totalCount == 0 || rankDataList.Length() == 0 { + if totalCount == 0 || len(rankDataList) == 0 { return nil, nex.NewError(nex.ResultCodes.Ranking.NotFound, "change_error") } result := ranking_types.NewRankingCachedResult() result.RankingResult.RankDataList = rankDataList - result.RankingResult.TotalCount = types.NewPrimitiveU32(totalCount) + result.RankingResult.TotalCount = types.NewUInt32(totalCount) result.RankingResult.SinceTime = types.NewDateTime(0x1F40420000) // * 2000-01-01T00:00:00.000Z, this is what the real server sends back result.CreatedTime = types.NewDateTime(0).Now() @@ -64,9 +59,9 @@ func (commonProtocol *CommonProtocol) getCachedTopXRankings(err error, packet ne result.ExpiredTime = types.NewDateTime(0).FromTimestamp(time.Now().UTC().Add(time.Minute * time.Duration(5))) // * This is the length Ultimate NES Remix uses // TODO - Does this matter? and are other games different? - result.MaxLength = types.NewPrimitiveU8(10) + result.MaxLength = types.NewUInt8(10) - pResult.Append(result) + pResult = append(pResult, result) } rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/ranking/get_common_data.go b/ranking/get_common_data.go index e6b07f0..77cc091 100644 --- a/ranking/get_common_data.go +++ b/ranking/get_common_data.go @@ -7,7 +7,7 @@ import ( ranking "github.com/PretendoNetwork/nex-protocols-go/v2/ranking" ) -func (commonProtocol *CommonProtocol) getCommonData(err error, packet nex.PacketInterface, callID uint32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) getCommonData(err error, packet nex.PacketInterface, callID uint32, uniqueID types.UInt64) (*nex.RMCMessage, *nex.Error) { if commonProtocol.GetCommonData == nil { common_globals.Logger.Warning("Ranking::GetCommonData missing GetCommonData!") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") diff --git a/ranking/get_ranking.go b/ranking/get_ranking.go index 3e97628..013f5ad 100644 --- a/ranking/get_ranking.go +++ b/ranking/get_ranking.go @@ -8,7 +8,7 @@ import ( ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" ) -func (commonProtocol *CommonProtocol) getRanking(err error, packet nex.PacketInterface, callID uint32, rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64, principalID *types.PID) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) getRanking(err error, packet nex.PacketInterface, callID uint32, rankingMode types.UInt8, category types.UInt32, orderParam ranking_types.RankingOrderParam, uniqueID types.UInt64, principalID types.PID) (*nex.RMCMessage, *nex.Error) { if commonProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam == nil { common_globals.Logger.Warning("Ranking::GetRanking missing GetRankingsAndCountByCategoryAndRankingOrderParam!") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") @@ -28,14 +28,14 @@ func (commonProtocol *CommonProtocol) getRanking(err error, packet nex.PacketInt return nil, nex.NewError(nex.ResultCodes.Ranking.Unknown, "change_error") } - if totalCount == 0 || rankDataList.Length() == 0 { + if totalCount == 0 || len(rankDataList) == 0 { return nil, nex.NewError(nex.ResultCodes.Ranking.NotFound, "change_error") } pResult := ranking_types.NewRankingResult() pResult.RankDataList = rankDataList - pResult.TotalCount = types.NewPrimitiveU32(totalCount) + pResult.TotalCount = types.NewUInt32(totalCount) pResult.SinceTime = types.NewDateTime(0x1F40420000) // * 2000-01-01T00:00:00.000Z, this is what the real server sends back rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/ranking/protocol.go b/ranking/protocol.go index de02f11..733901e 100644 --- a/ranking/protocol.go +++ b/ranking/protocol.go @@ -10,16 +10,16 @@ import ( type CommonProtocol struct { endpoint nex.EndpointInterface protocol ranking.Interface - GetCommonData func(uniqueID *types.PrimitiveU64) (*types.Buffer, error) - UploadCommonData func(pid *types.PID, uniqueID *types.PrimitiveU64, commonData *types.Buffer) error - InsertRankingByPIDAndRankingScoreData func(pid *types.PID, rankingScoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64) error - GetRankingsAndCountByCategoryAndRankingOrderParam func(category *types.PrimitiveU32, rankingOrderParam *ranking_types.RankingOrderParam) (*types.List[*ranking_types.RankingRankData], uint32, error) - OnAfterGetCachedTopXRanking func(packet nex.PacketInterface, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam) - OnAfterGetCachedTopXRankings func(packet nex.PacketInterface, categories *types.List[*types.PrimitiveU32], orderParams *types.List[*ranking_types.RankingOrderParam]) - OnAfterGetCommonData func(packet nex.PacketInterface, uniqueID *types.PrimitiveU64) - OnAfterGetRanking func(packet nex.PacketInterface, rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64, principalID *types.PID) - OnAfterUploadCommonData func(packet nex.PacketInterface, commonData *types.Buffer, uniqueID *types.PrimitiveU64) - OnAfterUploadScore func(packet nex.PacketInterface, scoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64) + GetCommonData func(uniqueID types.UInt64) (types.Buffer, error) + UploadCommonData func(pid types.PID, uniqueID types.UInt64, commonData types.Buffer) error + InsertRankingByPIDAndRankingScoreData func(pid types.PID, rankingScoreData ranking_types.RankingScoreData, uniqueID types.UInt64) error + GetRankingsAndCountByCategoryAndRankingOrderParam func(category types.UInt32, rankingOrderParam ranking_types.RankingOrderParam) (types.List[ranking_types.RankingRankData], uint32, error) + OnAfterGetCachedTopXRanking func(packet nex.PacketInterface, category types.UInt32, orderParam ranking_types.RankingOrderParam) + OnAfterGetCachedTopXRankings func(packet nex.PacketInterface, categories types.List[types.UInt32], orderParams types.List[ranking_types.RankingOrderParam]) + OnAfterGetCommonData func(packet nex.PacketInterface, uniqueID types.UInt64) + OnAfterGetRanking func(packet nex.PacketInterface, rankingMode types.UInt8, category types.UInt32, orderParam ranking_types.RankingOrderParam, uniqueID types.UInt64, principalID types.PID) + OnAfterUploadCommonData func(packet nex.PacketInterface, commonData types.Buffer, uniqueID types.UInt64) + OnAfterUploadScore func(packet nex.PacketInterface, scoreData ranking_types.RankingScoreData, uniqueID types.UInt64) } // NewCommonProtocol returns a new CommonProtocol diff --git a/ranking/upload_common_data.go b/ranking/upload_common_data.go index c30d51a..cc77d24 100644 --- a/ranking/upload_common_data.go +++ b/ranking/upload_common_data.go @@ -7,7 +7,7 @@ import ( ranking "github.com/PretendoNetwork/nex-protocols-go/v2/ranking" ) -func (commonProtocol *CommonProtocol) uploadCommonData(err error, packet nex.PacketInterface, callID uint32, commonData *types.Buffer, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) uploadCommonData(err error, packet nex.PacketInterface, callID uint32, commonData types.Buffer, uniqueID types.UInt64) (*nex.RMCMessage, *nex.Error) { if commonProtocol.UploadCommonData == nil { common_globals.Logger.Warning("Ranking::UploadCommonData missing UploadCommonData!") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") diff --git a/ranking/upload_score.go b/ranking/upload_score.go index 65d22c9..e426b27 100644 --- a/ranking/upload_score.go +++ b/ranking/upload_score.go @@ -8,7 +8,7 @@ import ( ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" ) -func (commonProtocol *CommonProtocol) uploadScore(err error, packet nex.PacketInterface, callID uint32, scoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) uploadScore(err error, packet nex.PacketInterface, callID uint32, scoreData ranking_types.RankingScoreData, uniqueID types.UInt64) (*nex.RMCMessage, *nex.Error) { if commonProtocol.InsertRankingByPIDAndRankingScoreData == nil { common_globals.Logger.Warning("Ranking::UploadScore missing InsertRankingByPIDAndRankingScoreData!") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") diff --git a/secure-connection/protocol.go b/secure-connection/protocol.go index 36a445d..e724447 100644 --- a/secure-connection/protocol.go +++ b/secure-connection/protocol.go @@ -9,12 +9,12 @@ import ( type CommonProtocol struct { endpoint nex.EndpointInterface protocol secure_connection.Interface - CreateReportDBRecord func(pid *types.PID, reportID *types.PrimitiveU32, reportData *types.QBuffer) error - OnAfterRegister func(packet nex.PacketInterface, vecMyURLs *types.List[*types.StationURL]) - OnAfterRequestURLs func(packet nex.PacketInterface, cidTarget *types.PrimitiveU32, pidTarget *types.PID) - OnAfterRegisterEx func(packet nex.PacketInterface, vecMyURLs *types.List[*types.StationURL], hCustomData *types.AnyDataHolder) - OnAfterReplaceURL func(packet nex.PacketInterface, target *types.StationURL, url *types.StationURL) - OnAfterSendReport func(packet nex.PacketInterface, reportID *types.PrimitiveU32, reportData *types.QBuffer) + 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.DataHolder) + OnAfterReplaceURL func(packet nex.PacketInterface, target types.StationURL, url types.StationURL) + OnAfterSendReport func(packet nex.PacketInterface, reportID types.UInt32, reportData types.QBuffer) } // NewCommonProtocol returns a new CommonProtocol diff --git a/secure-connection/register.go b/secure-connection/register.go index 00e3574..2b592ec 100644 --- a/secure-connection/register.go +++ b/secure-connection/register.go @@ -11,7 +11,7 @@ import ( common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" ) -func (commonProtocol *CommonProtocol) register(err error, packet nex.PacketInterface, callID uint32, vecMyURLs *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) register(err error, packet nex.PacketInterface, callID uint32, vecMyURLs types.List[types.StationURL]) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -24,7 +24,7 @@ func (commonProtocol *CommonProtocol) register(err error, packet nex.PacketInter var localStation *types.StationURL var publicStation *types.StationURL - for _, stationURL := range vecMyURLs.Slice() { + for _, stationURL := range vecMyURLs { natf, ok := stationURL.NATFiltering() if !ok { continue @@ -37,16 +37,16 @@ func (commonProtocol *CommonProtocol) register(err error, packet nex.PacketInter // * Station reports itself as being non-public (local) if localStation == nil && !stationURL.IsPublic() { - localStation = stationURL.Copy().(*types.StationURL) + localStation = &stationURL } // * Still did not find the station, trying heuristics if localStation == nil && natf == constants.UnknownNATFiltering && natm == constants.UnknownNATMapping { - localStation = stationURL.Copy().(*types.StationURL) + localStation = &stationURL } if publicStation == nil && stationURL.IsPublic() { - publicStation = stationURL.Copy().(*types.StationURL) + publicStation = &stationURL } } @@ -56,7 +56,7 @@ func (commonProtocol *CommonProtocol) register(err error, packet nex.PacketInter } if publicStation == nil { - publicStation = localStation.Copy().(*types.StationURL) + publicStation = localStation var address string var port uint16 @@ -84,12 +84,12 @@ func (commonProtocol *CommonProtocol) register(err error, packet nex.PacketInter localStation.SetRVConnectionID(connection.ID) publicStation.SetRVConnectionID(connection.ID) - connection.StationURLs.Append(localStation) - connection.StationURLs.Append(publicStation) + connection.StationURLs = append(connection.StationURLs, *localStation) + connection.StationURLs = append(connection.StationURLs, *publicStation) retval := types.NewQResultSuccess(nex.ResultCodes.Core.Unknown) - pidConnectionID := types.NewPrimitiveU32(connection.ID) - urlPublic := types.NewString(publicStation.EncodeToString()) + pidConnectionID := types.NewUInt32(connection.ID) + urlPublic := types.NewString(publicStation.URL()) rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/secure-connection/register_ex.go b/secure-connection/register_ex.go index b718283..a579580 100644 --- a/secure-connection/register_ex.go +++ b/secure-connection/register_ex.go @@ -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") @@ -26,7 +26,7 @@ func (commonProtocol *CommonProtocol) registerEx(err error, packet nex.PacketInt var localStation *types.StationURL var publicStation *types.StationURL - for _, stationURL := range vecMyURLs.Slice() { + for _, stationURL := range vecMyURLs { natf, ok := stationURL.NATFiltering() if !ok { continue @@ -39,16 +39,16 @@ func (commonProtocol *CommonProtocol) registerEx(err error, packet nex.PacketInt // * Station reports itself as being non-public (local) if localStation == nil && !stationURL.IsPublic() { - localStation = stationURL.Copy().(*types.StationURL) + localStation = &stationURL } // * Still did not find the station, trying heuristics if localStation == nil && natf == constants.UnknownNATFiltering && natm == constants.UnknownNATMapping { - localStation = stationURL.Copy().(*types.StationURL) + localStation = &stationURL } if publicStation == nil && stationURL.IsPublic() { - publicStation = stationURL.Copy().(*types.StationURL) + publicStation = &stationURL } } @@ -58,7 +58,7 @@ func (commonProtocol *CommonProtocol) registerEx(err error, packet nex.PacketInt } if publicStation == nil { - publicStation = localStation.Copy().(*types.StationURL) + publicStation = localStation var address string var port uint16 @@ -86,12 +86,12 @@ func (commonProtocol *CommonProtocol) registerEx(err error, packet nex.PacketInt localStation.SetRVConnectionID(connection.ID) publicStation.SetRVConnectionID(connection.ID) - connection.StationURLs.Append(localStation) - connection.StationURLs.Append(publicStation) + connection.StationURLs = append(connection.StationURLs, *localStation) + connection.StationURLs = append(connection.StationURLs, *publicStation) retval := types.NewQResultSuccess(nex.ResultCodes.Core.Unknown) - pidConnectionID := types.NewPrimitiveU32(connection.ID) - urlPublic := types.NewString(publicStation.EncodeToString()) + pidConnectionID := types.NewUInt32(connection.ID) + urlPublic := types.NewString(publicStation.URL()) rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) diff --git a/secure-connection/replace_url.go b/secure-connection/replace_url.go index 4676c9a..722b22b 100644 --- a/secure-connection/replace_url.go +++ b/secure-connection/replace_url.go @@ -8,7 +8,7 @@ import ( common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" ) -func (commonProtocol *CommonProtocol) replaceURL(err error, packet nex.PacketInterface, callID uint32, target *types.StationURL, url *types.StationURL) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) replaceURL(err error, packet nex.PacketInterface, callID uint32, target types.StationURL, url types.StationURL) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -17,7 +17,7 @@ func (commonProtocol *CommonProtocol) replaceURL(err error, packet nex.PacketInt connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint() - connection.StationURLs.Each(func(i int, station *types.StationURL) bool { + for i, station := range connection.StationURLs { currentStationAddress, currentStationAddressOk := station.Address() currentStationPort, currentStationPortOk := station.PortNumber() oldStationAddress, oldStationAddressOk := target.Address() @@ -27,16 +27,14 @@ func (commonProtocol *CommonProtocol) replaceURL(err error, packet nex.PacketInt if currentStationAddress == oldStationAddress && currentStationPort == oldStationPort { // * This fixes Minecraft, but is obviously incorrect // TODO - What are we really meant to do here? - newStation := url.Copy().(*types.StationURL) + newStation := url.Copy().(types.StationURL) newStation.SetPrincipalID(connection.PID()) - connection.StationURLs.SetIndex(i, newStation) + connection.StationURLs[i] = newStation } } - - return false - }) + } rmcResponse := nex.NewRMCSuccess(endpoint, nil) rmcResponse.ProtocolID = secure_connection.ProtocolID diff --git a/secure-connection/request_urls.go b/secure-connection/request_urls.go index ddc57d7..f60283a 100644 --- a/secure-connection/request_urls.go +++ b/secure-connection/request_urls.go @@ -8,7 +8,7 @@ import ( common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" ) -func (commonProtocol *CommonProtocol) requestURLs(err error, packet nex.PacketInterface, callID uint32, cidTarget *types.PrimitiveU32, pidTarget *types.PID) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) requestURLs(err error, packet nex.PacketInterface, callID uint32, cidTarget types.UInt32, pidTarget types.PID) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") @@ -18,9 +18,9 @@ func (commonProtocol *CommonProtocol) requestURLs(err error, packet nex.PacketIn endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) // TODO - Is this correct? - requestedConnection := endpoint.FindConnectionByID(cidTarget.Value) + requestedConnection := endpoint.FindConnectionByID(uint32(cidTarget)) if requestedConnection == nil { - requestedConnection = endpoint.FindConnectionByPID(pidTarget.Value()) + requestedConnection = endpoint.FindConnectionByPID(uint64(pidTarget)) } if requestedConnection == nil { @@ -29,7 +29,7 @@ func (commonProtocol *CommonProtocol) requestURLs(err error, packet nex.PacketIn rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) - retval := types.NewPrimitiveBool(true) + retval := types.NewBool(true) retval.WriteTo(rmcResponseStream) plstURLs := requestedConnection.StationURLs diff --git a/secure-connection/send_report.go b/secure-connection/send_report.go index 31c3150..c95f1cc 100644 --- a/secure-connection/send_report.go +++ b/secure-connection/send_report.go @@ -8,7 +8,7 @@ import ( common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" ) -func (commonProtocol *CommonProtocol) sendReport(err error, packet nex.PacketInterface, callID uint32, reportID *types.PrimitiveU32, reportData *types.QBuffer) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) sendReport(err error, packet nex.PacketInterface, callID uint32, reportID types.UInt32, reportData types.QBuffer) (*nex.RMCMessage, *nex.Error) { if commonProtocol.CreateReportDBRecord == nil { common_globals.Logger.Warning("SecureConnection::SendReport missing CreateReportDBRecord!") return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") diff --git a/ticket-granting/login.go b/ticket-granting/login.go index 5d00cfb..f3f864e 100644 --- a/ticket-granting/login.go +++ b/ticket-granting/login.go @@ -7,7 +7,7 @@ import ( ticket_granting "github.com/PretendoNetwork/nex-protocols-go/v2/ticket-granting" ) -func (commonProtocol *CommonProtocol) login(err error, packet nex.PacketInterface, callID uint32, strUserName *types.String) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) login(err error, packet nex.PacketInterface, callID uint32, strUserName types.String) (*nex.RMCMessage, *nex.Error) { if !commonProtocol.allowInsecureLoginMethod { return nil, nex.NewError(nex.ResultCodes.Authentication.ValidationFailed, "change_error") } @@ -20,7 +20,7 @@ func (commonProtocol *CommonProtocol) login(err error, packet nex.PacketInterfac connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) - sourceAccount, errorCode := endpoint.AccountDetailsByUsername(strUserName.Value) + sourceAccount, errorCode := endpoint.AccountDetailsByUsername(string(strUserName)) if errorCode != nil && errorCode.ResultCode != nex.ResultCodes.RendezVous.InvalidUsername { // * Some other error happened return nil, errorCode @@ -39,7 +39,7 @@ func (commonProtocol *CommonProtocol) login(err error, packet nex.PacketInterfac return nil, errorCode } - var retval *types.QResult + var retval types.QResult pidPrincipal := types.NewPID(0) pbufResponse := types.NewBuffer([]byte{}) pConnectionData := types.NewRVConnectionData() @@ -55,12 +55,10 @@ func (commonProtocol *CommonProtocol) login(err error, packet nex.PacketInterfac retval = types.NewQResultSuccess(nex.ResultCodes.Core.Unknown) pidPrincipal = sourceAccount.PID pbufResponse = types.NewBuffer(encryptedTicket) - strReturnMsg = commonProtocol.BuildName.Copy().(*types.String) + strReturnMsg = commonProtocol.BuildName.Copy().(types.String) - specialProtocols := types.NewList[*types.PrimitiveU8]() - - specialProtocols.Type = types.NewPrimitiveU8(0) - specialProtocols.SetFromData(commonProtocol.SpecialProtocols) + specialProtocols := types.NewList[types.UInt8]() + specialProtocols = commonProtocol.SpecialProtocols pConnectionData.StationURL = commonProtocol.SecureStationURL pConnectionData.SpecialProtocols = specialProtocols diff --git a/ticket-granting/login_ex.go b/ticket-granting/login_ex.go index 8a99d14..e960481 100644 --- a/ticket-granting/login_ex.go +++ b/ticket-granting/login_ex.go @@ -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") @@ -18,7 +18,7 @@ func (commonProtocol *CommonProtocol) loginEx(err error, packet nex.PacketInterf connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) - sourceAccount, errorCode := endpoint.AccountDetailsByUsername(strUserName.Value) + sourceAccount, errorCode := endpoint.AccountDetailsByUsername(string(strUserName)) if errorCode != nil && errorCode.ResultCode != nex.ResultCodes.RendezVous.InvalidUsername { // * Some other error happened return nil, errorCode @@ -37,7 +37,7 @@ func (commonProtocol *CommonProtocol) loginEx(err error, packet nex.PacketInterf return nil, errorCode } - var retval *types.QResult + var retval types.QResult pidPrincipal := types.NewPID(0) pbufResponse := types.NewBuffer([]byte{}) pConnectionData := types.NewRVConnectionData() @@ -53,12 +53,10 @@ func (commonProtocol *CommonProtocol) loginEx(err error, packet nex.PacketInterf retval = types.NewQResultSuccess(nex.ResultCodes.Core.Unknown) pidPrincipal = sourceAccount.PID pbufResponse = types.NewBuffer(encryptedTicket) - strReturnMsg = commonProtocol.BuildName.Copy().(*types.String) + strReturnMsg = commonProtocol.BuildName.Copy().(types.String) - specialProtocols := types.NewList[*types.PrimitiveU8]() - - specialProtocols.Type = types.NewPrimitiveU8(0) - specialProtocols.SetFromData(commonProtocol.SpecialProtocols) + specialProtocols := types.NewList[types.UInt8]() + specialProtocols = commonProtocol.SpecialProtocols pConnectionData.StationURL = commonProtocol.SecureStationURL pConnectionData.SpecialProtocols = specialProtocols diff --git a/ticket-granting/protocol.go b/ticket-granting/protocol.go index 647a5e9..78fb980 100644 --- a/ticket-granting/protocol.go +++ b/ticket-granting/protocol.go @@ -11,16 +11,16 @@ import ( type CommonProtocol struct { protocol ticket_granting.Interface - SecureStationURL *types.StationURL - SpecialProtocols []*types.PrimitiveU8 - StationURLSpecialProtocols *types.StationURL - BuildName *types.String + SecureStationURL types.StationURL + SpecialProtocols []types.UInt8 + StationURLSpecialProtocols types.StationURL + BuildName types.String allowInsecureLoginMethod bool 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) - OnAfterRequestTicket func(packet nex.PacketInterface, idSource *types.PID, idTarget *types.PID) + OnAfterLogin func(packet nex.PacketInterface, strUserName types.String) + OnAfterLoginEx func(packet nex.PacketInterface, strUserName types.String, oExtraData types.DataHolder) + OnAfterRequestTicket func(packet nex.PacketInterface, idSource types.PID, idTarget types.PID) } func (commonProtocol *CommonProtocol) DisableInsecureLogin() { @@ -37,7 +37,7 @@ func NewCommonProtocol(protocol ticket_granting.Interface) *CommonProtocol { commonProtocol := &CommonProtocol{ protocol: protocol, SecureStationURL: types.NewStationURL("prudp:/"), - SpecialProtocols: make([]*types.PrimitiveU8, 0), + SpecialProtocols: make([]types.UInt8, 0), StationURLSpecialProtocols: types.NewStationURL(""), BuildName: types.NewString(""), allowInsecureLoginMethod: false, diff --git a/ticket-granting/request_ticket.go b/ticket-granting/request_ticket.go index 973ad71..ed4caa6 100644 --- a/ticket-granting/request_ticket.go +++ b/ticket-granting/request_ticket.go @@ -7,7 +7,7 @@ import ( ticket_granting "github.com/PretendoNetwork/nex-protocols-go/v2/ticket-granting" ) -func (commonProtocol *CommonProtocol) requestTicket(err error, packet nex.PacketInterface, callID uint32, idSource *types.PID, idTarget *types.PID) (*nex.RMCMessage, *nex.Error) { +func (commonProtocol *CommonProtocol) requestTicket(err error, packet nex.PacketInterface, callID uint32, idSource types.PID, idTarget types.PID) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") diff --git a/utility/acquire_nex_unique_id.go b/utility/acquire_nex_unique_id.go index cf7a9f9..9496e92 100644 --- a/utility/acquire_nex_unique_id.go +++ b/utility/acquire_nex_unique_id.go @@ -21,7 +21,7 @@ func (commonProtocol *CommonProtocol) acquireNexUniqueID(err error, packet nex.P connection := packet.Sender() endpoint := connection.Endpoint() - pNexUniqueID := types.NewPrimitiveU64(commonProtocol.GenerateNEXUniqueID()) + pNexUniqueID := types.NewUInt64(commonProtocol.GenerateNEXUniqueID()) rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())