Skip to content

Commit 991adb0

Browse files
authored
Merge pull request #56 from PretendoNetwork/feat/nex-4.x.x-fixes
2 parents 5a86458 + 2cce33f commit 991adb0

19 files changed

+183
-135
lines changed

globals/utils.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,15 @@ func SendNotificationEvent(endpoint *nex.PRUDPEndPoint, event notifications_type
167167

168168
var messagePacket nex.PRUDPPacketInterface
169169

170-
if target.DefaultPRUDPVersion == 0 {
170+
switch target.DefaultPRUDPVersion {
171+
case 0:
171172
messagePacket, _ = nex.NewPRUDPPacketV0(server, target, nil)
172-
} else {
173+
case 1:
173174
messagePacket, _ = nex.NewPRUDPPacketV1(server, target, nil)
175+
case 2:
176+
messagePacket, _ = nex.NewPRUDPPacketLite(server, target, nil)
177+
default:
178+
Logger.Errorf("PRUDP version %d is not supported", target.DefaultPRUDPVersion)
174179
}
175180

176181
messagePacket.SetType(constants.DataPacket)

match-making/database/disconnect_participant.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func DisconnectParticipant(manager *common_globals.MatchmakingManager, connectio
4949
// * If the gathering is a PersistentGathering and the gathering isn't set to leave when disconnecting, ignore and continue
5050
//
5151
// TODO - Is the match_making.GatheringFlags.PersistentGathering check correct here?
52-
if uint32(gathering.Flags) & match_making.GatheringFlags.PersistentGathering != 0 || (gatheringType == "PersistentGathering" && uint32(gathering.Flags) & match_making.GatheringFlags.PersistentGatheringLeaveParticipation == 0) {
52+
if uint32(gathering.Flags)&match_making.GatheringFlags.PersistentGathering != 0 || (gatheringType == "PersistentGathering" && uint32(gathering.Flags)&match_making.GatheringFlags.PersistentGatheringLeaveParticipation == 0) {
5353
continue
5454
}
5555

@@ -67,7 +67,7 @@ func DisconnectParticipant(manager *common_globals.MatchmakingManager, connectio
6767
}
6868

6969
// * If the gathering is a persistent gathering and allows zero users, only remove the participant from the gathering
70-
if uint32(gathering.Flags) & (match_making.GatheringFlags.PersistentGathering | match_making.GatheringFlags.PersistentGatheringAllowZeroUsers) != 0 {
70+
if uint32(gathering.Flags)&(match_making.GatheringFlags.PersistentGathering|match_making.GatheringFlags.PersistentGatheringAllowZeroUsers) != 0 {
7171
continue
7272
}
7373

@@ -87,7 +87,7 @@ func DisconnectParticipant(manager *common_globals.MatchmakingManager, connectio
8787
// * This flag tells the server to change the matchmake session owner if they disconnect
8888
// * If the flag is not set, delete the session
8989
// * More info: https://nintendo-wiki.pretendo.network/docs/nex/protocols/match-making/types#flags
90-
if uint32(gathering.Flags) & match_making.GatheringFlags.DisconnectChangeOwner == 0 {
90+
if uint32(gathering.Flags)&match_making.GatheringFlags.DisconnectChangeOwner == 0 {
9191
nexError = UnregisterGathering(manager, connection.PID(), uint32(gathering.ID))
9292
if nexError != nil {
9393
common_globals.Logger.Error(nexError.Error())
@@ -99,8 +99,8 @@ func DisconnectParticipant(manager *common_globals.MatchmakingManager, connectio
9999

100100
oEvent := notifications_types.NewNotificationEvent()
101101
oEvent.PIDSource = connection.PID().Copy().(types.PID)
102-
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
103-
oEvent.Param1 = gathering.ID
102+
oEvent.Type = types.UInt32(notifications.BuildNotificationType(category, subtype))
103+
oEvent.Param1 = types.UInt64(gathering.ID)
104104

105105
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, common_globals.RemoveDuplicates(participants))
106106

@@ -125,8 +125,8 @@ func DisconnectParticipant(manager *common_globals.MatchmakingManager, connectio
125125

126126
oEvent := notifications_types.NewNotificationEvent()
127127
oEvent.PIDSource = connection.PID().Copy().(types.PID)
128-
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
129-
oEvent.Param1 = gathering.ID
128+
oEvent.Type = types.UInt32(notifications.BuildNotificationType(category, subtype))
129+
oEvent.Param1 = types.UInt64(gathering.ID)
130130

131131
// TODO - Should the notification actually be sent to all participants?
132132
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, common_globals.RemoveDuplicates(participants))
@@ -144,14 +144,14 @@ func DisconnectParticipant(manager *common_globals.MatchmakingManager, connectio
144144

145145
oEvent := notifications_types.NewNotificationEvent()
146146
oEvent.PIDSource = connection.PID().Copy().(types.PID)
147-
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
148-
oEvent.Param1 = gathering.ID
149-
oEvent.Param2 = types.NewUInt32(uint32(connection.PID())) // TODO - This assumes a legacy client. Will not work on the Switch
147+
oEvent.Type = types.UInt32(notifications.BuildNotificationType(category, subtype))
148+
oEvent.Param1 = types.UInt64(gathering.ID)
149+
oEvent.Param2 = types.UInt64(connection.PID())
150150

151151
var participantEndedTargets []uint64
152152

153153
// * When the VerboseParticipants or VerboseParticipantsEx flags are set, all participant notification events are sent to everyone
154-
if uint32(gathering.Flags) & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 {
154+
if uint32(gathering.Flags)&(match_making.GatheringFlags.VerboseParticipants|match_making.GatheringFlags.VerboseParticipantsEx) != 0 {
155155
participantEndedTargets = common_globals.RemoveDuplicates(participants)
156156
} else {
157157
participantEndedTargets = []uint64{uint64(gathering.OwnerPID)}

match-making/database/end_gathering_participation.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func EndGatheringParticipation(manager *common_globals.MatchmakingManager, gathe
3535
}
3636

3737
// * If the gathering is a persistent gathering and allows zero users, only remove the participant from the gathering
38-
if uint32(gathering.Flags) & (match_making.GatheringFlags.PersistentGathering | match_making.GatheringFlags.PersistentGatheringAllowZeroUsers) != 0 {
38+
if uint32(gathering.Flags)&(match_making.GatheringFlags.PersistentGathering|match_making.GatheringFlags.PersistentGatheringAllowZeroUsers) != 0 {
3939
return nil
4040
}
4141

@@ -49,7 +49,7 @@ func EndGatheringParticipation(manager *common_globals.MatchmakingManager, gathe
4949
// * This flag tells the server to change the matchmake session owner if they disconnect
5050
// * If the flag is not set, delete the session
5151
// * More info: https://nintendo-wiki.pretendo.network/docs/nex/protocols/match-making/types#flags
52-
if uint32(gathering.Flags) & match_making.GatheringFlags.DisconnectChangeOwner == 0 {
52+
if uint32(gathering.Flags)&match_making.GatheringFlags.DisconnectChangeOwner == 0 {
5353
nexError = UnregisterGathering(manager, connection.PID(), gatheringID)
5454
if nexError != nil {
5555
return nexError
@@ -60,8 +60,8 @@ func EndGatheringParticipation(manager *common_globals.MatchmakingManager, gathe
6060

6161
oEvent := notifications_types.NewNotificationEvent()
6262
oEvent.PIDSource = connection.PID().Copy().(types.PID)
63-
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
64-
oEvent.Param1 = types.NewUInt32(gatheringID)
63+
oEvent.Type = types.UInt32(notifications.BuildNotificationType(category, subtype))
64+
oEvent.Param1 = types.UInt64(gatheringID)
6565

6666
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, common_globals.RemoveDuplicates(newParticipants))
6767

@@ -88,8 +88,8 @@ func EndGatheringParticipation(manager *common_globals.MatchmakingManager, gathe
8888

8989
oEvent := notifications_types.NewNotificationEvent()
9090
oEvent.PIDSource = connection.PID().Copy().(types.PID)
91-
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
92-
oEvent.Param1 = types.NewUInt32(gatheringID)
91+
oEvent.Type = types.UInt32(notifications.BuildNotificationType(category, subtype))
92+
oEvent.Param1 = types.UInt64(gatheringID)
9393

9494
// TODO - Should the notification actually be sent to all participants?
9595
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, common_globals.RemoveDuplicates(participants))
@@ -106,15 +106,15 @@ func EndGatheringParticipation(manager *common_globals.MatchmakingManager, gathe
106106

107107
oEvent := notifications_types.NewNotificationEvent()
108108
oEvent.PIDSource = connection.PID().Copy().(types.PID)
109-
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
110-
oEvent.Param1 = types.NewUInt32(gatheringID)
111-
oEvent.Param2 = types.NewUInt32(uint32((connection.PID()))) // TODO - This assumes a legacy client. Will not work on the Switch
109+
oEvent.Type = types.UInt32(notifications.BuildNotificationType(category, subtype))
110+
oEvent.Param1 = types.UInt64(gatheringID)
111+
oEvent.Param2 = types.UInt64(connection.PID())
112112
oEvent.StrParam = types.NewString(message)
113113

114114
var participationEndedTargets []uint64
115115

116116
// * When the VerboseParticipants or VerboseParticipantsEx flags are set, all participant notification events are sent to everyone
117-
if uint32(gathering.Flags) & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 {
117+
if uint32(gathering.Flags)&(match_making.GatheringFlags.VerboseParticipants|match_making.GatheringFlags.VerboseParticipantsEx) != 0 {
118118
participationEndedTargets = common_globals.RemoveDuplicates(participants)
119119
} else {
120120
participationEndedTargets = []uint64{uint64(gathering.OwnerPID)}

match-making/database/join_gathering.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func JoinGathering(manager *common_globals.MatchmakingManager, gatheringID uint3
3636
}
3737

3838
if maxParticipants != 0 {
39-
if uint32(len(participants)) + uint32(vacantParticipants) > maxParticipants {
39+
if uint32(len(participants))+uint32(vacantParticipants) > maxParticipants {
4040
return 0, nex.NewError(nex.ResultCodes.RendezVous.SessionFull, "change_error")
4141
}
4242
}
@@ -72,7 +72,7 @@ func JoinGathering(manager *common_globals.MatchmakingManager, gatheringID uint3
7272
var participantJoinedTargets []uint64
7373

7474
// * When the VerboseParticipants or VerboseParticipantsEx flags are set, all participant notification events are sent to everyone
75-
if flags & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 {
75+
if flags&(match_making.GatheringFlags.VerboseParticipants|match_making.GatheringFlags.VerboseParticipantsEx) != 0 {
7676
participantJoinedTargets = common_globals.RemoveDuplicates(totalParticipants)
7777
} else {
7878
// * If the new participant is the same as the owner, then we are creating a new gathering.
@@ -89,28 +89,28 @@ func JoinGathering(manager *common_globals.MatchmakingManager, gatheringID uint3
8989

9090
oEvent := notifications_types.NewNotificationEvent()
9191
oEvent.PIDSource = connection.PID()
92-
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
93-
oEvent.Param1 = types.NewUInt32(gatheringID)
94-
oEvent.Param2 = types.NewUInt32(uint32(connection.PID())) // TODO - This assumes a legacy client. Will not work on the Switch
92+
oEvent.Type = types.UInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
93+
oEvent.Param1 = types.UInt64(gatheringID)
94+
oEvent.Param2 = types.UInt64(connection.PID())
9595
oEvent.StrParam = types.NewString(joinMessage)
96-
oEvent.Param3 = types.NewUInt32(uint32(len(totalParticipants)))
96+
oEvent.Param3 = types.UInt64(len(totalParticipants))
9797

9898
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, participantJoinedTargets)
9999

100100
// * This flag also sends a recap of all currently connected players on the gathering to the participant that is connecting
101-
if flags & match_making.GatheringFlags.VerboseParticipantsEx != 0 {
101+
if flags&match_making.GatheringFlags.VerboseParticipantsEx != 0 {
102102
// TODO - Should this actually be deduplicated?
103103
for _, participant := range common_globals.RemoveDuplicates(participants) {
104104
notificationCategory := notifications.NotificationCategories.Participation
105105
notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant
106106

107107
oEvent := notifications_types.NewNotificationEvent()
108108
oEvent.PIDSource = connection.PID()
109-
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
110-
oEvent.Param1 = types.NewUInt32(gatheringID)
111-
oEvent.Param2 = types.NewUInt32(uint32(participant)) // TODO - This assumes a legacy client. Will not work on the Switch
109+
oEvent.Type = types.UInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
110+
oEvent.Param1 = types.UInt64(gatheringID)
111+
oEvent.Param2 = types.UInt64(participant)
112112
oEvent.StrParam = types.NewString(joinMessage)
113-
oEvent.Param3 = types.NewUInt32(uint32(len(totalParticipants)))
113+
oEvent.Param3 = types.UInt64(len(totalParticipants))
114114

115115
// * Send the notification to the joining participant
116116
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, []uint64{uint64(connection.PID())})

match-making/database/join_gathering_with_participants.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
"slices"
66

77
"github.com/PretendoNetwork/nex-go/v2"
8-
"github.com/PretendoNetwork/nex-protocols-go/v2/match-making/constants"
98
"github.com/PretendoNetwork/nex-go/v2/types"
109
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
1110
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/tracking"
1211
match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making"
12+
"github.com/PretendoNetwork/nex-protocols-go/v2/match-making/constants"
1313
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
1414
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
1515
pqextended "github.com/PretendoNetwork/pq-extended"
@@ -30,7 +30,7 @@ func JoinGatheringWithParticipants(manager *common_globals.MatchmakingManager, g
3030
}
3131
}
3232

33-
if uint32(len(oldParticipants) + 1 + len(additionalParticipants)) > maxParticipants {
33+
if uint32(len(oldParticipants)+1+len(additionalParticipants)) > maxParticipants {
3434
return 0, nex.NewError(nex.ResultCodes.RendezVous.SessionFull, "change_error")
3535
}
3636

@@ -71,7 +71,7 @@ func JoinGatheringWithParticipants(manager *common_globals.MatchmakingManager, g
7171
var participantJoinedTargets []uint64
7272

7373
// * When the VerboseParticipants or the VerboseParticipantsEx flags are set, all participant notification events are sent to everyone
74-
if flags & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 {
74+
if flags&(match_making.GatheringFlags.VerboseParticipants|match_making.GatheringFlags.VerboseParticipantsEx) != 0 {
7575
participantJoinedTargets = common_globals.RemoveDuplicates(participants)
7676
} else {
7777
participantJoinedTargets = []uint64{ownerPID}
@@ -89,9 +89,9 @@ func JoinGatheringWithParticipants(manager *common_globals.MatchmakingManager, g
8989

9090
oEvent := notifications_types.NewNotificationEvent()
9191
oEvent.PIDSource = connection.PID()
92-
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
93-
oEvent.Param1 = types.NewUInt32(gatheringID)
94-
oEvent.Param2 = types.NewUInt32(uint32(participant)) // TODO - This assumes a legacy client. Will not work on the Switch
92+
oEvent.Type = types.UInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
93+
oEvent.Param1 = types.UInt64(gatheringID)
94+
oEvent.Param2 = types.UInt64(participant)
9595

9696
// * Send the notification to the participant
9797
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, []uint64{participant})
@@ -100,35 +100,35 @@ func JoinGatheringWithParticipants(manager *common_globals.MatchmakingManager, g
100100
for _, participant := range newParticipants {
101101
// * If the new participant is the same as the owner, then we are creating a new gathering.
102102
// * We don't need to send the new participant notification event in that case
103-
if flags & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 || uint64(connection.PID()) != ownerPID {
103+
if flags&(match_making.GatheringFlags.VerboseParticipants|match_making.GatheringFlags.VerboseParticipantsEx) != 0 || uint64(connection.PID()) != ownerPID {
104104
notificationCategory := notifications.NotificationCategories.Participation
105105
notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant
106106

107107
oEvent := notifications_types.NewNotificationEvent()
108108
oEvent.PIDSource = connection.PID()
109-
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
110-
oEvent.Param1 = types.NewUInt32(gatheringID)
111-
oEvent.Param2 = types.NewUInt32(uint32(participant)) // TODO - This assumes a legacy client. Will not work on the Switch
109+
oEvent.Type = types.UInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
110+
oEvent.Param1 = types.UInt64(gatheringID)
111+
oEvent.Param2 = types.UInt64(participant)
112112
oEvent.StrParam = types.NewString(joinMessage)
113-
oEvent.Param3 = types.NewUInt32(uint32(len(participants)))
113+
oEvent.Param3 = types.UInt64(len(participants))
114114

115115
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, participantJoinedTargets)
116116
}
117117

118118
// * This flag also sends a recap of all currently connected players on the gathering to the participant that is connecting
119-
if flags & match_making.GatheringFlags.VerboseParticipantsEx != 0 {
119+
if flags&match_making.GatheringFlags.VerboseParticipantsEx != 0 {
120120
// TODO - Should this actually be deduplicated?
121121
for _, oldParticipant := range common_globals.RemoveDuplicates(oldParticipants) {
122122
notificationCategory := notifications.NotificationCategories.Participation
123123
notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant
124124

125125
oEvent := notifications_types.NewNotificationEvent()
126126
oEvent.PIDSource = connection.PID()
127-
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
128-
oEvent.Param1 = types.NewUInt32(gatheringID)
129-
oEvent.Param2 = types.NewUInt32(uint32(oldParticipant)) // TODO - This assumes a legacy client. Will not work on the Switch
127+
oEvent.Type = types.UInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
128+
oEvent.Param1 = types.UInt64(gatheringID)
129+
oEvent.Param2 = types.UInt64(oldParticipant)
130130
oEvent.StrParam = types.NewString(joinMessage)
131-
oEvent.Param3 = types.NewUInt32(uint32(len(participants)))
131+
oEvent.Param3 = types.UInt64(len(participants))
132132

133133
// * Send the notification to the joining participant
134134
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, []uint64{participant})

match-making/database/migrate_gathering_ownership.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func MigrateGatheringOwnership(manager *common_globals.MatchmakingManager, conne
3434

3535
oEvent := notifications_types.NewNotificationEvent()
3636
oEvent.PIDSource = connection.PID().Copy().(types.PID)
37-
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
38-
oEvent.Param1 = gathering.ID
37+
oEvent.Type = types.UInt32(notifications.BuildNotificationType(category, subtype))
38+
oEvent.Param1 = types.UInt64(gathering.ID)
3939

4040
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, uniqueParticipants)
4141
return 0, nil
@@ -62,8 +62,8 @@ func MigrateGatheringOwnership(manager *common_globals.MatchmakingManager, conne
6262
oEvent := notifications_types.NewNotificationEvent()
6363
oEvent.PIDSource = connection.PID().Copy().(types.PID)
6464
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
65-
oEvent.Param1 = gathering.ID
66-
oEvent.Param2 = types.NewUInt32(uint32(newOwner)) // TODO - This assumes a legacy client. Will not work on the Switch
65+
oEvent.Param1 = types.UInt64(gathering.ID)
66+
oEvent.Param2 = types.UInt64(newOwner)
6767

6868
// TODO - StrParam doesn't have this value on some servers
6969
// * https://github.com/kinnay/NintendoClients/issues/101

0 commit comments

Comments
 (0)