Skip to content

Commit 4341293

Browse files
committed
Add cloning of reservation data
Fixes the bug where someone joining your lobby that you have on your friends list causing you to disconnect.
1 parent de6b2dc commit 4341293

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

common/match_command.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,3 +724,15 @@ func LogMatchCommand(moduleName string, dest string, command byte, data MatchCom
724724
logging.Notice(moduleName, "Reason:", aurora.BrightRed(data.ResvDeny.ReasonString), "("+aurora.Cyan(reasonByte).String()+")")
725725
}
726726
}
727+
728+
func CloneReservationData(data MatchCommandData) MatchCommandData {
729+
clone := MatchCommandData{
730+
Version: data.Version,
731+
Command: data.Command,
732+
}
733+
734+
reservationCopy := *data.Reservation
735+
clone.Reservation = &reservationCopy
736+
737+
return clone
738+
}

gpcm/message.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,17 @@ func (g *GameSpySession) bestieMessage(command common.GameSpyCommand) {
230230
msgMatchData.Reservation.LocalPort = 0
231231
}
232232
} else if cmd == common.MatchResvOK || cmd == common.MatchResvDeny || cmd == common.MatchResvWait {
233+
if toSession.ReservationPID != g.User.ProfileId || toSession.Reservation.Reservation == nil || toSession.Reservation.Version != msgMatchData.Version {
234+
if resvData, resvID, sessionKey, ok := qr2.GetReservationForProfile(toSession.User.ProfileId); ok {
235+
if qr2.GetSearchID(g.QR2IP) == 0 || resvID == 0 || qr2.GetSearchID(g.QR2IP) == resvID {
236+
toSession.Reservation, toSession.ReservationPID = resvData, g.User.ProfileId
237+
}
238+
if toSession.QR2IP == 0 && sessionKey != 0 {
239+
toSession.QR2IP = sessionKey
240+
}
241+
}
242+
}
243+
233244
if toSession.ReservationPID != g.User.ProfileId || toSession.Reservation.Reservation == nil {
234245
logging.Error(g.ModuleName, "Destination", aurora.Cyan(toProfileId), "has no reservation with the sender")
235246
// Allow the message through anyway to avoid a room deadlock

qr2/session.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,18 @@ func GetSearchID(addr uint64) uint64 {
324324
return 0
325325
}
326326

327+
func GetReservationForProfile(profileID uint32) (common.MatchCommandData, uint64, uint64, bool) {
328+
mutex.Lock()
329+
defer mutex.Unlock()
330+
331+
sessionKey := makeLookupAddr(logins[profileID].session.Addr.String())
332+
if logins[profileID].session.Reservation.Reservation == nil {
333+
return common.MatchCommandData{}, logins[profileID].session.ReservationID, sessionKey, false
334+
}
335+
336+
return common.CloneReservationData(logins[profileID].session.Reservation), logins[profileID].session.ReservationID, sessionKey, true
337+
}
338+
327339
// Save the sessions to a file. Expects the mutex to be locked.
328340
func saveSessions() error {
329341
file, err := os.OpenFile("state/qr2_sessions.gob", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)

0 commit comments

Comments
 (0)