Skip to content

Update constants/magic numbers #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
d0fa7d1
feat(messaging): add MaxStringLength and MaxBinarySize constants
jonbarrow Jul 8, 2025
055591a
feat(match-making): add missing constant values
jonbarrow Jul 9, 2025
d298534
feat(match-making): add MatchmakeGeoIpResult enum
jonbarrow Jul 9, 2025
203ef4f
chore(match-making): make MatchmakeSelectionMethod enum consistent wi…
jonbarrow Jul 9, 2025
a2a58bf
feat(match-making): add GatheringFlags enum
jonbarrow Jul 9, 2025
22653a5
feat(match-making): add MatchmakeSessionOption0 enum
jonbarrow Jul 9, 2025
eba96db
feat(match-making): add MatchmakeOption enum
jonbarrow Jul 9, 2025
c66ee65
feat(match-making): add AutoMatchmakeOption enum
jonbarrow Jul 9, 2025
9b9e2c5
chore(match-making): add usage details to JoinMatchmakeSessionBehavio…
jonbarrow Jul 9, 2025
3c813d8
fix(match-making): MatchmakeSessionOption0 are flags not enum
jonbarrow Jul 9, 2025
6844477
feat(match-making): add FindMatchmakeSessionResultOption flags
jonbarrow Jul 9, 2025
cbdb0b3
feat(match-making): add MatchmakeSessionModificationFlag flags
jonbarrow Jul 9, 2025
3513902
chore(match-making): expand MatchmakeSelectionMethod Godoc comments
jonbarrow Jul 9, 2025
e6e7436
feat(match-making): add AnybodyParticipationPolicyArgument enum
jonbarrow Jul 9, 2025
59183ed
feat(match-making): add ParticipationPolicy types
jonbarrow Jul 9, 2025
133cafb
fix(match-making): fix typo in MatchmakeSessionOption0None Godoc comment
jonbarrow Jul 9, 2025
a09b042
fix(match-making): fix AnybodyParticipationPolicyArgument typos
jonbarrow Jul 9, 2025
f432772
feat(notifications): add NotificationEvents types
jonbarrow Jul 12, 2025
b809493
feat(notifications): add NotificationEvents.Build() method
jonbarrow Jul 12, 2025
a753fb4
fix(notifications): add protocol to UpdateNotificationData mentions
jonbarrow Jul 12, 2025
a5e83f3
feat(notifications): add ParticipationEvents
jonbarrow Jul 12, 2025
57169f2
fix(notifications): add Godoc comment to NotificationEvents.Build()
jonbarrow Jul 12, 2025
7b1d19e
fix(notifications): fix ParticipationEventsParticipate name
jonbarrow Jul 12, 2025
ad2f935
fix(notifications): fix ParticipationEventsParticipate comment
jonbarrow Jul 12, 2025
23caa16
feat(notifications): add SubscriptionEvents
jonbarrow Jul 12, 2025
216c009
feat(notifications): remove old category/subtype handling
jonbarrow Jul 12, 2025
abff4f7
feat(match-making): add HasFlag and HasFlags methods to flag types
jonbarrow Jul 12, 2025
85e9e91
fix(notifications): make NotificationEvents.Build() return types.UInt32
jonbarrow Jul 12, 2025
fde236b
feat(match-making): change AutoMatchmakeParam to use AutoMatchmakeOption
jonbarrow Jul 12, 2025
72fe2cb
feat(match-making): add IsValid method to all enum types
jonbarrow Jul 13, 2025
9678fc7
chore(match-making): add PolicyArgument type
jonbarrow Aug 5, 2025
041e423
feat(match-making): add GatheringState type
jonbarrow Aug 5, 2025
eb731a0
chore(match-making): remove IsValid method from AnybodyParticipationP…
jonbarrow Aug 5, 2025
23fbe4e
feat(match-making): make FindMatchmakeSessionByParticipantParam use F…
jonbarrow Aug 5, 2025
51b81d7
feat(match-making): make Gathering uses new constants
jonbarrow Aug 5, 2025
3188a13
feat(match-making): make JoinMatchmakeSessionParam use JoinMatchmakeS…
jonbarrow Aug 5, 2025
89bd749
chore(match-making): rename GatheringStateClosed to GatheringStateLocked
jonbarrow Aug 5, 2025
e8e84a3
feat(match-making): make MatchmakeSessionSearchCriteria uses new cons…
jonbarrow Aug 5, 2025
4d755ab
chore(match-making): add ExtractFrom and WriteTo methods to add const…
jonbarrow Aug 5, 2025
e0955e9
feat(match-making): make MatchmakeSession uses new constants
jonbarrow Aug 5, 2025
8553249
feat(match-making): make UpdateMatchmakeSessionParam uses new constants
jonbarrow Aug 5, 2025
545c76a
chore(match-making): remove IsValid methods from constants
jonbarrow Aug 6, 2025
374cb36
feat(match-making): make SetState use GatheringState constant
jonbarrow Aug 6, 2025
3b1af2e
feat(notifications): add NotificationEvent.MapParam
jonbarrow Aug 6, 2025
48bb56c
feat(notifications): make NotificationEvent use NotificationEvents co…
jonbarrow Aug 6, 2025
d8468a8
feat(notifications): add NotificationEventsEagleAddress
jonbarrow Aug 6, 2025
d0cc42c
chore(match-making): remove legacy GatheringFlags file
jonbarrow Aug 8, 2025
8e46be7
chore(subscriber): update unknown param/type names
jonbarrow Aug 22, 2025
1bb3d8f
feat(subscriber): add constants
jonbarrow Aug 22, 2025
4c26949
feat(ranking): add missing ranking constants
jonbarrow Aug 22, 2025
db46dd5
feat(ranking): make ranking protocol use new constants/enums
jonbarrow Aug 22, 2025
d1a9468
feat(ranking2): add all constants
jonbarrow Aug 23, 2025
02c11f2
feat(ranking2): make ranking2 protocol use new constants/enums
jonbarrow Aug 23, 2025
2e35b3a
chore(matchmake-extension): use notifications constants in DebugNotif…
jonbarrow Aug 23, 2025
8b7fd51
fix(datastore): GetObjectInfos takes in a types.List[types.UInt64]
jonbarrow Aug 23, 2025
3fa4fc7
feat(datastore): make datastore protocol use new constants/enums
jonbarrow Aug 23, 2025
b7bf4f5
feat(notifications): split notification event and category
jonbarrow Aug 24, 2025
e59c9c0
feat(notifications): create NotificationCategorySigned
jonbarrow Aug 24, 2025
14495d6
fix(datastore): ResetRatings takes in a types.List[types.UInt64]
jonbarrow Aug 24, 2025
4b028e1
fix(subscriber): add proper Godoc comments to SubscriberUserStatusParam
jonbarrow Aug 24, 2025
d579bce
feat(ranking2): add bespoke Ranking2ResetDay
jonbarrow Aug 24, 2025
cf676e6
feat(ranking2): add bespoke Ranking2ResetMonth
jonbarrow Aug 24, 2025
b462290
feat(nintendo-notifications): add NintendoNotificationEventProfile
jonbarrow Aug 24, 2025
f2663cc
feat(nintendo-notifications): add bespoke NotificationType type
jonbarrow Aug 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions notifications/constants/notification_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,33 @@ type NotificationEvents uint32
// to NotificationEvents.Build()
type subType uint32

// WriteTo writes the NotificationEvents to the given writable
func (ne NotificationEvents) WriteTo(writable types.Writable) {
writable.WriteUInt32LE(uint32(ne))
}

// ExtractFrom extracts the NotificationEvents value from the given readable
func (ne *NotificationEvents) ExtractFrom(readable types.Readable) error {
value, err := readable.ReadUInt32LE()
if err != nil {
return err
}

*ne = NotificationEvents(value)
return nil
}

// Build creates the final notification type ID used in NotificationEvent.m_uiType.
//
// Takes an optional subtype. Only the first subtype defined is used.
func (ne NotificationEvents) Build(subtype ...subType) types.UInt32 {
category := types.UInt32(ne * 1000)
func (ne NotificationEvents) Build(subtype ...subType) NotificationEvents {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should split the type into the categories and the full type with the subtype. Mixing these types together is counter-intuitive

Copy link
Member Author

@jonbarrow jonbarrow Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean? This was done because NotificationEvent.Type is now of type constants.NotificationEvents. So when we build the NotificationEvent instance we would do this directly:

notification := notifications_types.NewNotificationEvent()
notification.Type = notifications_constants.NotificationEventsSessionLaunched.Build()

If it was kept as a types.UInt32 then we would have to explicitly cast the return value every time:

notification := notifications_types.NewNotificationEvent()
notification.Type = notifications_constants.NotificationEvents(notifications_constants.NotificationEventsSessionLaunched.Build())

I'm not sure what you mean by counter-intuitive, or where this splitting should be done? The types are already split by category and subtype, and the usage of the method seems intuitive to me?

Copy link
Member

@DaniElectra DaniElectra Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion was to split the NotificationEvents type, NotificationCategory for the actual category and NotificationEvents for the category + subtype. The Build function would look like this:

func (nc NotificationCategory) Build(subtype ...SubType) NotificationEvents

This way we wouldn't have to cast into the notification.Type and the separation between "category" and "category + subtype" is more intuitive

Copy link
Member Author

@jonbarrow jonbarrow Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only issue with that is that NotificationEvents is the official name of these category types https://github.com/tech-ticks/RTDXTools/blob/232a7797e01369e9c12704f58fdde65dd3ac1c32/Assets/Scripts/Stubs/Generated/Assembly-CSharp/NexPlugin/Common.cs#L35-L53, so we would have to intentionally not use the correct official name and instead repurpose the official name for our own definition

We have changed official names before, but that was due to technical issues (see RatingLockPeriodDay, which is officially named RatingLockPeriod but that conflicts with RatingLockPeriod in RatingLockType)

Though I do agree that that sounds more intuitive, especially since I had added these types to the MatchmakeExtension protocol (see 2e35b3a). I ran into a snag there because there's 3 methods that take in notification data:

  • UpdateNotificationData - Takes in uiType types.UInt32, uiParam1 types.UInt64, uiParam2 types.UInt64, strParam types.String
  • GetFriendNotificationData - Takes in uiType types.Int32
  • DebugNotifyEvent - pid types.PID, mainType types.UInt32, subType types.UInt32, param1 types.UInt64, param2 types.UInt64, stringParam types.String

I only ended up changing DebugNotifyEvent to take in mainType notifications_constants.NotificationEvents, subType notifications_constants.SubType because the other 2 made this a bit annoying. UpdateNotificationData seems to expect the fully finished built type (which isn't something we have types for at all) and GetFriendNotificationData wants a signed version of this?

Renaming NotificationEvents to NotificationCategory would make handling UpdateNotificationData a bit better since like you said it splits the final built type from the category, but it still has the issue of "we don't have types for these built values", and it doesn't help GetFriendNotificationData at all

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdateNotificationData seems to expect the fully finished built type (which isn't something we have types for at all)

That isn't the case, UpdateNotificationData only uses the category as input

GetFriendNotificationData being signed is an issue though, huh. I guess we can just leave things as is, no big deal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdateNotificationData seems to expect the fully finished built type (which isn't something we have types for at all)

That isn't the case, UpdateNotificationData only uses the category as input

GetFriendNotificationData being signed is an issue though, huh. I guess we can just leave things as is, no big deal

That actually makes things easier then tbh. We can definitely still do this if you want, we just have to:

  1. Accept that the official name for the categories type will be misused
  2. Create a signed version of the categories

We can make the signed part a bit easier tbh by just creating a 2nd type for it. Like:

package constants

type NotificationCategory uint32
type NotificationCategorySigned int32

func (nc NotificationCategory) ToSigned() NotificationCategorySigned {
    return NotificationCategorySigned(nc)
}

func (ncs NotificationCategorySigned) ToUnsigned() NotificationCategory {
    return NotificationCategory(ncs)
}

const (
	NotificationCategorySessionLaunched NotificationCategory = 2
	NotificationCategoryParticipationEvent NotificationCategory = 3
	NotificationCategoryOwnershipChangeEvent NotificationCategory = 4
	NotificationCategoryGameNotification1 NotificationCategory = 101
	NotificationCategoryGameNotification2 NotificationCategory = 102
	NotificationCategoryGameNotification3 NotificationCategory = 103
	NotificationCategoryGameNotification4 NotificationCategory = 104
	NotificationCategoryGameNotification5 NotificationCategory = 105
	NotificationCategoryGameNotification6 NotificationCategory = 106
	NotificationCategoryGameNotification7 NotificationCategory = 107
	NotificationCategoryGameNotification8 NotificationCategory = 108
	NotificationCategoryGatheringUnregistered NotificationCategory = 109
	NotificationCategoryHostChangeEvent NotificationCategory = 110
	NotificationCategoryGameNotificationLogout NotificationCategory = 111
	NotificationCategorySubscriptionEvent NotificationCategory = 112
	NotificationCategoryGameServerMaintenance NotificationCategory = 113
	NotificationCategoryMaintenanceAnnouncement NotificationCategory = 114
	NotificationCategoryServiceItemRequestCompleted NotificationCategory = 115
	NotificationCategoryRoundStarted NotificationCategory = 116
	NotificationCategoryFirstRoundReportReceived NotificationCategory = 117
	NotificationCategoryRoundSummarized NotificationCategory = 118
	NotificationCategoryMatchmakeSystemConfigurationNotification NotificationCategory = 119
	NotificationCategoryMatchmakeSessionSystemPasswordSet NotificationCategory = 120
	NotificationCategoryMatchmakeSessionSystemPasswordClear NotificationCategory = 121
	NotificationCategoryAddedToGathering NotificationCategory = 122
	NotificationCategoryUserStatusUpdatedEvent NotificationCategory = 128
	NotificationCategoryEagleAddress NotificationCategory = 200
)

GetFriendNotificationData would just take in NotificationCategorySigned and we could call ToUnsigned in the implementation handler (or just directly cast)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good to me 👍

category := ne * 1000

if len(subtype) == 0 {
return category
}

return category + types.UInt32(subtype[0])
return category + NotificationEvents(subtype[0])
}

const (
Expand Down
9 changes: 5 additions & 4 deletions notifications/types/notification_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (

"github.com/PretendoNetwork/nex-go/v2"
"github.com/PretendoNetwork/nex-go/v2/types"
"github.com/PretendoNetwork/nex-protocols-go/v2/notifications/constants"
)

// NotificationEvent is a type within the Notifications protocol
type NotificationEvent struct {
types.Structure
PIDSource types.PID
Type types.UInt32
Type constants.NotificationEvents
Param1 types.UInt64 // * In NEX 3 this field is a UInt32. Storing as a UInt64
Param2 types.UInt64 // * In NEX 3 this field is a UInt32. Storing as a UInt64
StrParam types.String
Expand Down Expand Up @@ -147,7 +148,7 @@ func (ne NotificationEvent) Copy() types.RVType {

copied.StructureVersion = ne.StructureVersion
copied.PIDSource = ne.PIDSource.Copy().(types.PID)
copied.Type = ne.Type.Copy().(types.UInt32)
copied.Type = ne.Type
copied.Param1 = ne.Param1.Copy().(types.UInt64)
copied.Param2 = ne.Param2.Copy().(types.UInt64)
copied.StrParam = ne.StrParam.Copy().(types.String)
Expand All @@ -173,7 +174,7 @@ func (ne NotificationEvent) Equals(o types.RVType) bool {
return false
}

if !ne.Type.Equals(other.Type) {
if ne.Type != other.Type {
return false
}

Expand Down Expand Up @@ -239,7 +240,7 @@ func (ne NotificationEvent) FormatToString(indentationLevel int) string {
func NewNotificationEvent() NotificationEvent {
return NotificationEvent{
PIDSource: types.NewPID(0),
Type: types.NewUInt32(0),
Type: constants.NotificationEvents(0), // TODO - Unsure what this default actually is
Param1: types.NewUInt64(0),
Param2: types.NewUInt64(0),
StrParam: types.NewString(""),
Expand Down