From 5903bbbd53392310dca1f89f16d95b8dc57fcec7 Mon Sep 17 00:00:00 2001 From: shutterbug2000 Date: Thu, 12 Oct 2023 12:29:58 -0500 Subject: [PATCH 1/6] Move session creation and notification sending This helps reduce duplicate code and bugs that result from it --- globals/matchmaking_globals.go | 1 + globals/matchmaking_utils.go | 251 +++++++++++++++++- .../auto_matchmake_postpone.go | 86 ++---- .../auto_matchmake_with_param_postpone.go | 131 +++++++++ ...matchmake_with_search_criteria_postpone.go | 81 +----- .../create_matchmake_session.go | 30 +-- .../create_matchmake_session_with_param.go | 82 +----- matchmake-extension/join_matchmake_session.go | 57 +--- .../join_matchmake_session_with_param.go | 58 +--- matchmake-extension/protocol.go | 1 + 10 files changed, 418 insertions(+), 360 deletions(-) create mode 100644 matchmake-extension/auto_matchmake_with_param_postpone.go diff --git a/globals/matchmaking_globals.go b/globals/matchmaking_globals.go index 5ebcf2c..792a94e 100644 --- a/globals/matchmaking_globals.go +++ b/globals/matchmaking_globals.go @@ -14,3 +14,4 @@ type CommonMatchmakeSession struct { var Sessions map[uint32]*CommonMatchmakeSession var CurrentGatheringID = nex.NewCounter(0) +var CurrentMatchmakingCallID uint32 diff --git a/globals/matchmaking_utils.go b/globals/matchmaking_utils.go index 5a58c1b..0d338c4 100644 --- a/globals/matchmaking_utils.go +++ b/globals/matchmaking_utils.go @@ -5,6 +5,7 @@ import ( "math" "strconv" "strings" + "math/rand" nex "github.com/PretendoNetwork/nex-go" match_making "github.com/PretendoNetwork/nex-protocols-go/match-making" @@ -90,7 +91,8 @@ func RemoveClientFromAllSessions(client *nex.Client) { rmcMessage := nex.NewRMCRequest() rmcMessage.SetProtocolID(notifications.ProtocolID) - rmcMessage.SetCallID(0xffff0000) + rmcMessage.SetCallID(CurrentMatchmakingCallID) + CurrentMatchmakingCallID+=1 rmcMessage.SetMethodID(notifications.MethodProcessNotificationEvent) category := notifications.NotificationCategories.Participation @@ -103,8 +105,8 @@ func RemoveClientFromAllSessions(client *nex.Client) { oEvent.Param2 = client.PID() stream := nex.NewStreamOut(server) - oEventBytes := oEvent.Bytes(stream) - rmcMessage.SetParameters(oEventBytes) + stream.WriteStructure(oEvent) + rmcMessage.SetParameters(stream.Bytes()) rmcMessageBytes := rmcMessage.Bytes() @@ -140,6 +142,33 @@ func RemoveClientFromAllSessions(client *nex.Client) { } } +// CreateSessionByMatchmakeSession creates a gathering from a MatchmakeSession +func CreateSessionByMatchmakeSession(matchmakeSession *match_making_types.MatchmakeSession, searchMatchmakeSession *match_making_types.MatchmakeSession, hostPID uint32) (*CommonMatchmakeSession, error, uint32) { + sessionIndex := GetAvailableGatheringID() + // This should in theory be impossible, as there aren't enough PIDs creating sessions to fill the uint32 limit. + // If we ever get here, we must be not deleting sessions properly + if sessionIndex == 0 { + return &CommonMatchmakeSession{}, fmt.Errorf("No gatherings available!"), nex.Errors.RendezVous.LimitExceeded + } + + session := CommonMatchmakeSession{ + SearchMatchmakeSession: searchMatchmakeSession, + GameMatchmakeSession: matchmakeSession, + } + + Sessions[sessionIndex] = &session + Sessions[sessionIndex].GameMatchmakeSession.Gathering.ID = sessionIndex + Sessions[sessionIndex].GameMatchmakeSession.Gathering.OwnerPID = hostPID + Sessions[sessionIndex].GameMatchmakeSession.Gathering.HostPID = hostPID + + Sessions[sessionIndex].GameMatchmakeSession.StartedTime = nex.NewDateTime(0) + Sessions[sessionIndex].GameMatchmakeSession.StartedTime.UTC() + Sessions[sessionIndex].GameMatchmakeSession.SessionKey = make([]byte, 32) + rand.Read(Sessions[sessionIndex].GameMatchmakeSession.SessionKey) + + return Sessions[sessionIndex], nil, 0 +} + // FindSessionByMatchmakeSession finds a gathering that matches with a MatchmakeSession func FindSessionByMatchmakeSession(searchMatchmakeSession *match_making_types.MatchmakeSession) uint32 { // * This portion finds any sessions that match the search session @@ -168,6 +197,34 @@ func FindSessionByMatchmakeSession(searchMatchmakeSession *match_making_types.Ma return 0 } +// CreateSessionBySearchCriteria creates a gathering from MatchmakeSessionSearchCriteria +func CreateSessionBySearchCriteria(matchmakeSession *match_making_types.MatchmakeSession, lstSearchCriteria []*match_making_types.MatchmakeSessionSearchCriteria, hostPID uint32) (*CommonMatchmakeSession, error, uint32) { + sessionIndex := GetAvailableGatheringID() + + // * This should in theory be impossible, as there aren't enough PIDs creating sessions to fill the uint32 limit. + // * If we ever get here, we must be not deleting sessions properly + if sessionIndex == 0 { + return &CommonMatchmakeSession{}, fmt.Errorf("No gatherings available!"), nex.Errors.RendezVous.LimitExceeded + } + + session := CommonMatchmakeSession{ + SearchCriteria: lstSearchCriteria, + GameMatchmakeSession: matchmakeSession, + } + + Sessions[sessionIndex] = &session + Sessions[sessionIndex].GameMatchmakeSession.Gathering.ID = sessionIndex + Sessions[sessionIndex].GameMatchmakeSession.Gathering.OwnerPID = hostPID + Sessions[sessionIndex].GameMatchmakeSession.Gathering.HostPID = hostPID + + Sessions[sessionIndex].GameMatchmakeSession.StartedTime = nex.NewDateTime(0) + Sessions[sessionIndex].GameMatchmakeSession.StartedTime.UTC() + Sessions[sessionIndex].GameMatchmakeSession.SessionKey = make([]byte, 32) + rand.Read(Sessions[sessionIndex].GameMatchmakeSession.SessionKey) + + return Sessions[sessionIndex], nil, 0 +} + // FindSessionsByMatchmakeSessionSearchCriterias finds a gathering that matches with a MatchmakeSession func FindSessionsByMatchmakeSessionSearchCriterias(lstSearchCriteria []*match_making_types.MatchmakeSessionSearchCriteria, gameSpecificChecks func(requestSearchCriteria, sessionSearchCriteria *match_making_types.MatchmakeSessionSearchCriteria) bool) []*CommonMatchmakeSession { // * This portion finds any sessions that match the search session @@ -277,7 +334,7 @@ func FindSessionsByMatchmakeSessionSearchCriterias(lstSearchCriteria []*match_ma // AddPlayersToSession updates the given sessions state to include the provided connection IDs // Returns a NEX error code if failed -func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32) (error, uint32) { +func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32, initiatingClient *nex.Client) (error, uint32) { if (len(session.ConnectionIDs) + len(connectionIDs)) > int(session.GameMatchmakeSession.Gathering.MaximumParticipants) { return fmt.Errorf("Gathering %d is full", session.GameMatchmakeSession.Gathering.ID), nex.Errors.RendezVous.SessionFull } @@ -292,6 +349,185 @@ func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32 session.GameMatchmakeSession.ParticipationCount += 1 } + server := initiatingClient.Server() + + + for i := 0; i < len(session.ConnectionIDs); i++ { + target := server.FindClientFromConnectionID(session.ConnectionIDs[i]) + if target == nil { + // TODO - Error here? + //logger.Warning("Player not found") + continue + } + + notificationRequestMessage := nex.NewRMCRequest() + notificationRequestMessage.SetProtocolID(notifications.ProtocolID) + notificationRequestMessage.SetCallID(CurrentMatchmakingCallID) + CurrentMatchmakingCallID+=1 + notificationRequestMessage.SetMethodID(notifications.MethodProcessNotificationEvent) + + notificationCategory := notifications.NotificationCategories.Participation + notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant + + oEvent := notifications_types.NewNotificationEvent() + oEvent.PIDSource = initiatingClient.PID() + oEvent.Type = notifications.BuildNotificationType(notificationCategory, notificationSubtype) + oEvent.Param1 = session.GameMatchmakeSession.ID + oEvent.Param2 = target.PID() + oEvent.StrParam = "" + oEvent.Param3 = uint32(len(connectionIDs)) + + notificationStream := nex.NewStreamOut(server) + + notificationStream.WriteStructure(oEvent) + + notificationRequestMessage.SetParameters(notificationStream.Bytes()) + notificationRequestBytes := notificationRequestMessage.Bytes() + + var messagePacket nex.PacketInterface + + if server.PRUDPVersion() == 0 { + messagePacket, _ = nex.NewPacketV0(target, nil) + messagePacket.SetVersion(0) + } else { + messagePacket, _ = nex.NewPacketV1(target, nil) + messagePacket.SetVersion(1) + } + + messagePacket.SetSource(0xA1) + messagePacket.SetDestination(0xAF) + messagePacket.SetType(nex.DataPacket) + messagePacket.SetPayload(notificationRequestBytes) + + messagePacket.AddFlag(nex.FlagNeedsAck) + messagePacket.AddFlag(nex.FlagReliable) + + server.Send(messagePacket) + } + + //This appears to be correct. Tri-Force Heroes uses 3.9.0, and has issues if this is ran. + //Minecraft, however, requires this to be ran. + //TODO: Check other games both pre and post 3.10.0 and validate. + if server.MatchMakingProtocolVersion().GreaterOrEqual("3.10.0") { + for i := 0; i < len(session.ConnectionIDs); i++ { + target := server.FindClientFromConnectionID(session.ConnectionIDs[i]) + if target == nil { + // TODO - Error here? + //logger.Warning("Player not found") + continue + } + + notificationRequestMessage := nex.NewRMCRequest() + notificationRequestMessage.SetProtocolID(notifications.ProtocolID) + notificationRequestMessage.SetCallID(CurrentMatchmakingCallID) + CurrentMatchmakingCallID+=1 + notificationRequestMessage.SetMethodID(notifications.MethodProcessNotificationEvent) + + notificationCategory := notifications.NotificationCategories.Participation + notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant + + oEvent := notifications_types.NewNotificationEvent() + oEvent.PIDSource = initiatingClient.PID() + oEvent.Type = notifications.BuildNotificationType(notificationCategory, notificationSubtype) + oEvent.Param1 = session.GameMatchmakeSession.ID + oEvent.Param2 = target.PID() + oEvent.StrParam = "" + oEvent.Param3 = uint32(len(connectionIDs)) + + notificationStream := nex.NewStreamOut(server) + + notificationStream.WriteStructure(oEvent) + + notificationRequestMessage.SetParameters(notificationStream.Bytes()) + notificationRequestBytes := notificationRequestMessage.Bytes() + //fmt.Println(hex.EncodeToString(notificationRequestBytes)) + + var messagePacket nex.PacketInterface + + if server.PRUDPVersion() == 0 { + messagePacket, _ = nex.NewPacketV0(initiatingClient, nil) + messagePacket.SetVersion(0) + } else { + messagePacket, _ = nex.NewPacketV1(initiatingClient, nil) + messagePacket.SetVersion(1) + } + + messagePacket.SetSource(0xA1) + messagePacket.SetDestination(0xAF) + messagePacket.SetType(nex.DataPacket) + messagePacket.SetPayload(notificationRequestBytes) + + messagePacket.AddFlag(nex.FlagNeedsAck) + messagePacket.AddFlag(nex.FlagReliable) + + server.Send(messagePacket) + } + + notificationRequestMessage := nex.NewRMCRequest() + notificationRequestMessage.SetProtocolID(notifications.ProtocolID) + notificationRequestMessage.SetCallID(CurrentMatchmakingCallID) + CurrentMatchmakingCallID+=1 + notificationRequestMessage.SetMethodID(notifications.MethodProcessNotificationEvent) + + notificationCategory := notifications.NotificationCategories.Participation + notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant + + oEvent := notifications_types.NewNotificationEvent() + oEvent.PIDSource = initiatingClient.PID() + oEvent.Type = notifications.BuildNotificationType(notificationCategory, notificationSubtype) + oEvent.Param1 = session.GameMatchmakeSession.ID + oEvent.Param2 = initiatingClient.PID() + oEvent.StrParam = "" + oEvent.Param3 = uint32(len(connectionIDs)) + + notificationStream := nex.NewStreamOut(server) + + notificationStream.WriteStructure(oEvent) + + notificationRequestMessage.SetParameters(notificationStream.Bytes()) + notificationRequestBytes := notificationRequestMessage.Bytes() + + target := server.FindClientFromPID(uint32(session.GameMatchmakeSession.Gathering.OwnerPID)) + + var messagePacket nex.PacketInterface + + if server.PRUDPVersion() == 0 { + messagePacket, _ = nex.NewPacketV0(initiatingClient, nil) + messagePacket.SetVersion(0) + } else { + messagePacket, _ = nex.NewPacketV1(initiatingClient, nil) + messagePacket.SetVersion(1) + } + + messagePacket.SetSource(0xA1) + messagePacket.SetDestination(0xAF) + messagePacket.SetType(nex.DataPacket) + messagePacket.SetPayload(notificationRequestBytes) + + messagePacket.AddFlag(nex.FlagNeedsAck) + messagePacket.AddFlag(nex.FlagReliable) + + server.Send(messagePacket) + + if server.PRUDPVersion() == 0 { + messagePacket, _ = nex.NewPacketV0(target, nil) + messagePacket.SetVersion(0) + } else { + messagePacket, _ = nex.NewPacketV1(target, nil) + messagePacket.SetVersion(1) + } + + messagePacket.SetSource(0xA1) + messagePacket.SetDestination(0xAF) + messagePacket.SetType(nex.DataPacket) + messagePacket.SetPayload(notificationRequestBytes) + + messagePacket.AddFlag(nex.FlagNeedsAck) + messagePacket.AddFlag(nex.FlagReliable) + + server.Send(messagePacket) + } + return nil, 0 } @@ -316,7 +552,8 @@ func ChangeSessionOwner(ownerClient *nex.Client, gathering uint32) { rmcMessage := nex.NewRMCRequest() rmcMessage.SetProtocolID(notifications.ProtocolID) - rmcMessage.SetCallID(0xffff0000) + rmcMessage.SetCallID(CurrentMatchmakingCallID) + CurrentMatchmakingCallID+=1 rmcMessage.SetMethodID(notifications.MethodProcessNotificationEvent) category := notifications.NotificationCategories.OwnershipChanged @@ -334,8 +571,8 @@ func ChangeSessionOwner(ownerClient *nex.Client, gathering uint32) { // oEvent.StrParam = strconv.FormatInt(unixTime.UnixMicro(), 10) stream := nex.NewStreamOut(server) - oEventBytes := oEvent.Bytes(stream) - rmcMessage.SetParameters(oEventBytes) + stream.WriteStructure(oEvent) + rmcMessage.SetParameters(stream.Bytes()) rmcRequestBytes := rmcMessage.Bytes() diff --git a/matchmake-extension/auto_matchmake_postpone.go b/matchmake-extension/auto_matchmake_postpone.go index 1aea0c6..fc6889d 100644 --- a/matchmake-extension/auto_matchmake_postpone.go +++ b/matchmake-extension/auto_matchmake_postpone.go @@ -5,8 +5,6 @@ import ( common_globals "github.com/PretendoNetwork/nex-protocols-common-go/globals" match_making_types "github.com/PretendoNetwork/nex-protocols-go/match-making/types" matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/matchmake-extension" - notifications "github.com/PretendoNetwork/nex-protocols-go/notifications" - notifications_types "github.com/PretendoNetwork/nex-protocols-go/notifications/types" ) func autoMatchmake_Postpone(err error, client *nex.Client, callID uint32, anyGathering *nex.DataHolder, message string) uint32 { @@ -39,36 +37,29 @@ func autoMatchmake_Postpone(err error, client *nex.Client, callID uint32, anyGat searchMatchmakeSession := matchmakeSession.Copy().(*match_making_types.MatchmakeSession) commonMatchmakeExtensionProtocol.cleanupSearchMatchmakeSessionHandler(searchMatchmakeSession) sessionIndex := common_globals.FindSessionByMatchmakeSession(searchMatchmakeSession) - if sessionIndex == 0 { - sessionIndex = common_globals.GetAvailableGatheringID() - // This should in theory be impossible, as there aren't enough PIDs creating sessions to fill the uint32 limit. - // If we ever get here, we must be not deleting sessions properly - if sessionIndex == 0 { - logger.Critical("No gatherings available!") - return nex.Errors.RendezVous.LimitExceeded - } + var session *common_globals.CommonMatchmakeSession - session := common_globals.CommonMatchmakeSession{ - SearchMatchmakeSession: searchMatchmakeSession, - GameMatchmakeSession: matchmakeSession, + if sessionIndex == 0 { + var errCode uint32 + session, err, errCode = common_globals.CreateSessionByMatchmakeSession(matchmakeSession, searchMatchmakeSession, client.PID()) + if err != nil { + logger.Error(err.Error()) + return errCode } - - common_globals.Sessions[sessionIndex] = &session - common_globals.Sessions[sessionIndex].GameMatchmakeSession.Gathering.ID = sessionIndex - common_globals.Sessions[sessionIndex].GameMatchmakeSession.Gathering.OwnerPID = client.PID() - common_globals.Sessions[sessionIndex].GameMatchmakeSession.Gathering.HostPID = client.PID() - - common_globals.Sessions[sessionIndex].GameMatchmakeSession.StartedTime = nex.NewDateTime(0) - common_globals.Sessions[sessionIndex].GameMatchmakeSession.StartedTime.UTC() + }else{ + session = common_globals.Sessions[sessionIndex] } - common_globals.Sessions[sessionIndex].ConnectionIDs = append(common_globals.Sessions[sessionIndex].ConnectionIDs, client.ConnectionID()) - common_globals.Sessions[sessionIndex].GameMatchmakeSession.ParticipationCount = uint32(len(common_globals.Sessions[sessionIndex].ConnectionIDs)) + err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) + if err != nil { + logger.Error(err.Error()) + return errCode + } rmcResponseStream := nex.NewStreamOut(server) matchmakeDataHolder := nex.NewDataHolder() matchmakeDataHolder.SetTypeName("MatchmakeSession") - matchmakeDataHolder.SetObjectData(common_globals.Sessions[sessionIndex].GameMatchmakeSession) + matchmakeDataHolder.SetObjectData(session.GameMatchmakeSession) rmcResponseStream.WriteDataHolder(matchmakeDataHolder) rmcResponseBody := rmcResponseStream.Bytes() @@ -90,57 +81,12 @@ func autoMatchmake_Postpone(err error, client *nex.Client, callID uint32, anyGat responsePacket.SetSource(0xA1) responsePacket.SetDestination(0xAF) responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) + responsePacket.SetPayload(rmcResponseBytes) responsePacket.AddFlag(nex.FlagNeedsAck) responsePacket.AddFlag(nex.FlagReliable) server.Send(responsePacket) - rmcMessage := nex.NewRMCRequest() - rmcMessage.SetProtocolID(notifications.ProtocolID) - rmcMessage.SetCallID(0xffff0000 + callID) - rmcMessage.SetMethodID(notifications.MethodProcessNotificationEvent) - - category := notifications.NotificationCategories.Participation - subtype := notifications.NotificationSubTypes.Participation.NewParticipant - - oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = common_globals.Sessions[sessionIndex].GameMatchmakeSession.Gathering.HostPID - oEvent.Type = notifications.BuildNotificationType(category, subtype) - oEvent.Param1 = sessionIndex - oEvent.Param2 = client.PID() - oEvent.StrParam = message - - stream := nex.NewStreamOut(server) - oEventBytes := oEvent.Bytes(stream) - rmcMessage.SetParameters(oEventBytes) - rmcMessageBytes := rmcMessage.Bytes() - - targetClient := server.FindClientFromPID(uint32(common_globals.Sessions[sessionIndex].GameMatchmakeSession.Gathering.OwnerPID)) - if targetClient == nil { - logger.Warning("Owner client not found") - return 0 - } - - var messagePacket nex.PacketInterface - - if server.PRUDPVersion() == 0 { - messagePacket, _ = nex.NewPacketV0(targetClient, nil) - messagePacket.SetVersion(0) - } else { - messagePacket, _ = nex.NewPacketV1(targetClient, nil) - messagePacket.SetVersion(1) - } - messagePacket.SetSource(0xA1) - messagePacket.SetDestination(0xAF) - messagePacket.SetType(nex.DataPacket) - messagePacket.SetPayload(rmcMessageBytes) - - messagePacket.AddFlag(nex.FlagNeedsAck) - messagePacket.AddFlag(nex.FlagReliable) - - server.Send(messagePacket) - return 0 } diff --git a/matchmake-extension/auto_matchmake_with_param_postpone.go b/matchmake-extension/auto_matchmake_with_param_postpone.go new file mode 100644 index 0000000..fa613bf --- /dev/null +++ b/matchmake-extension/auto_matchmake_with_param_postpone.go @@ -0,0 +1,131 @@ +package matchmake_extension + +import ( + nex "github.com/PretendoNetwork/nex-go" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/match-making/types" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/matchmake-extension" +) + +func autoMatchmakeWithParam_Postpone(err error, client *nex.Client, callID uint32, autoMatchmakeParam *match_making_types.AutoMatchmakeParam) uint32 { + if commonMatchmakeExtensionProtocol.cleanupSearchMatchmakeSessionHandler == nil { + logger.Warning("MatchmakeExtension::AutoMatchmake_Postpone missing CleanupSearchMatchmakeSessionHandler!") + return nex.Errors.Core.NotImplemented + } + + if err != nil { + logger.Error(err.Error()) + return nex.Errors.Core.InvalidArgument + } + + server := commonMatchmakeExtensionProtocol.server + + // A client may disconnect from a session without leaving reliably, + // so let's make sure the client is removed from the session + common_globals.RemoveClientFromAllSessions(client) + + var matchmakeSession *match_making_types.MatchmakeSession + matchmakeSession = autoMatchmakeParam.SourceMatchmakeSession + + searchMatchmakeSession := matchmakeSession.Copy().(*match_making_types.MatchmakeSession) + commonMatchmakeExtensionProtocol.cleanupSearchMatchmakeSessionHandler(searchMatchmakeSession) + sessionIndex := common_globals.FindSessionByMatchmakeSession(searchMatchmakeSession) + var session *common_globals.CommonMatchmakeSession + + if sessionIndex == 0 { + var errCode uint32 + session, err, errCode = common_globals.CreateSessionByMatchmakeSession(matchmakeSession, searchMatchmakeSession, client.PID()) + if err != nil { + logger.Error(err.Error()) + return errCode + } + }else{ + session = common_globals.Sessions[sessionIndex] + } + /*sessionIndex = common_globals.GetAvailableGatheringID() + // This should in theory be impossible, as there aren't enough PIDs creating sessions to fill the uint32 limit. + // If we ever get here, we must be not deleting sessions properly + if sessionIndex == 0 { + logger.Critical("No gatherings available!") + return nex.Errors.RendezVous.LimitExceeded + } + + session := common_globals.CommonMatchmakeSession{ + SearchMatchmakeSession: searchMatchmakeSession, + GameMatchmakeSession: matchmakeSession, + } + + session = &session + session.GameMatchmakeSession.Gathering.ID = sessionIndex + session.GameMatchmakeSession.Gathering.OwnerPID = client.PID() + session.GameMatchmakeSession.Gathering.HostPID = client.PID() + + session.GameMatchmakeSession.StartedTime = nex.NewDateTime(0) + session.GameMatchmakeSession.StartedTime.UTC() + session.GameMatchmakeSession.SessionKey = make([]byte, 32) + + session.GameMatchmakeSession.MatchmakeParam.Parameters["@SR"] = nex.NewVariant() + session.GameMatchmakeSession.MatchmakeParam.Parameters["@SR"].TypeID = 3 + session.GameMatchmakeSession.MatchmakeParam.Parameters["@SR"].Bool = true + + session.GameMatchmakeSession.MatchmakeParam.Parameters["@GIR"] = nex.NewVariant() + session.GameMatchmakeSession.MatchmakeParam.Parameters["@GIR"].TypeID = 1 + session.GameMatchmakeSession.MatchmakeParam.Parameters["@GIR"].Int64 = 3 + + session.GameMatchmakeSession.MatchmakeParam.Parameters["@Lon"] = nex.NewVariant() + session.GameMatchmakeSession.MatchmakeParam.Parameters["@Lon"].TypeID = 2 + session.GameMatchmakeSession.MatchmakeParam.Parameters["@Lon"].Float64 = 0 + + session.GameMatchmakeSession.MatchmakeParam.Parameters["@Lat"] = nex.NewVariant() + session.GameMatchmakeSession.MatchmakeParam.Parameters["@Lat"].TypeID = 2 + session.GameMatchmakeSession.MatchmakeParam.Parameters["@Lat"].Float64 = 0 + + session.GameMatchmakeSession.MatchmakeParam.Parameters["@CC"] = nex.NewVariant() + session.GameMatchmakeSession.MatchmakeParam.Parameters["@CC"].TypeID = 4 + session.GameMatchmakeSession.MatchmakeParam.Parameters["@CC"].Str = "US" + + session.GameMatchmakeSession.MatchmakeParam.Parameters["@DR"] = nex.NewVariant() + session.GameMatchmakeSession.MatchmakeParam.Parameters["@DR"].TypeID = 1 + session.GameMatchmakeSession.MatchmakeParam.Parameters["@DR"].Int64 = 0 + }*/ + + err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) + if err != nil { + logger.Error(err.Error()) + return errCode + } + + rmcResponseStream := nex.NewStreamOut(server) + matchmakeDataHolder := nex.NewDataHolder() + matchmakeDataHolder.SetTypeName("MatchmakeSession") + matchmakeDataHolder.SetObjectData(session.GameMatchmakeSession) + rmcResponseStream.WriteStructure(session.GameMatchmakeSession) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCResponse(matchmake_extension.ProtocolID, callID) + rmcResponse.SetSuccess(matchmake_extension.MethodAutoMatchmakeWithParamPostpone, rmcResponseBody) + + rmcResponseBytes := rmcResponse.Bytes() + + var responsePacket nex.PacketInterface + + if server.PRUDPVersion() == 0 { + responsePacket, _ = nex.NewPacketV0(client, nil) + responsePacket.SetVersion(0) + } else { + responsePacket, _ = nex.NewPacketV1(client, nil) + responsePacket.SetVersion(1) + } + responsePacket.SetSource(0xA1) + responsePacket.SetDestination(0xAF) + responsePacket.SetType(nex.DataPacket) + responsePacket.SetPayload(rmcResponseBytes) + + responsePacket.AddFlag(nex.FlagNeedsAck) + responsePacket.AddFlag(nex.FlagReliable) + + server.Send(responsePacket) + + return 0 +} diff --git a/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go b/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go index bbd6e9e..0f3dbab 100644 --- a/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go +++ b/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go @@ -5,8 +5,6 @@ import ( common_globals "github.com/PretendoNetwork/nex-protocols-common-go/globals" match_making_types "github.com/PretendoNetwork/nex-protocols-go/match-making/types" matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/matchmake-extension" - notifications "github.com/PretendoNetwork/nex-protocols-go/notifications" - notifications_types "github.com/PretendoNetwork/nex-protocols-go/notifications/types" ) func autoMatchmakeWithSearchCriteria_Postpone(err error, client *nex.Client, callID uint32, lstSearchCriteria []*match_making_types.MatchmakeSessionSearchCriteria, anyGathering *nex.DataHolder, message string) uint32 { @@ -42,34 +40,21 @@ func autoMatchmakeWithSearchCriteria_Postpone(err error, client *nex.Client, cal var session *common_globals.CommonMatchmakeSession if len(sessions) == 0 { - gatheringID := common_globals.GetAvailableGatheringID() - - // * This should in theory be impossible, as there aren't enough PIDs creating sessions to fill the uint32 limit. - // * If we ever get here, we must be not deleting sessions properly - if gatheringID == 0 { - logger.Critical("No gatherings available!") - return nex.Errors.RendezVous.LimitExceeded - } - - session = &common_globals.CommonMatchmakeSession{ - SearchCriteria: lstSearchCriteria, - GameMatchmakeSession: matchmakeSession, + var errCode uint32 + session, err, errCode = common_globals.CreateSessionBySearchCriteria(matchmakeSession, lstSearchCriteria, client.PID()) + if err != nil { + logger.Error(err.Error()) + return errCode } - - session.GameMatchmakeSession.Gathering.ID = gatheringID - session.GameMatchmakeSession.Gathering.OwnerPID = client.PID() - session.GameMatchmakeSession.Gathering.HostPID = client.PID() - session.GameMatchmakeSession.StartedTime = nex.NewDateTime(0) - session.GameMatchmakeSession.StartedTime.UTC() - session.GameMatchmakeSession.SessionKey = make([]byte, 32) - - common_globals.Sessions[gatheringID] = session } else { session = sessions[0] } - session.ConnectionIDs = append(session.ConnectionIDs, client.ConnectionID()) - session.GameMatchmakeSession.ParticipationCount = uint32(len(session.ConnectionIDs)) + err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) + if err != nil { + logger.Error(err.Error()) + return errCode + } rmcResponseStream := nex.NewStreamOut(server) matchmakeDataHolder := nex.NewDataHolder() @@ -104,51 +89,5 @@ func autoMatchmakeWithSearchCriteria_Postpone(err error, client *nex.Client, cal server.Send(responsePacket) - rmcMessage := nex.NewRMCRequest() - rmcMessage.SetProtocolID(notifications.ProtocolID) - rmcMessage.SetCallID(0xffff0000 + callID) - rmcMessage.SetMethodID(notifications.MethodProcessNotificationEvent) - - category := notifications.NotificationCategories.Participation - subtype := notifications.NotificationSubTypes.Participation.NewParticipant - - oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = session.GameMatchmakeSession.Gathering.HostPID - oEvent.Type = notifications.BuildNotificationType(category, subtype) - oEvent.Param1 = session.GameMatchmakeSession.Gathering.ID - oEvent.Param2 = client.PID() - oEvent.StrParam = message - - stream := nex.NewStreamOut(server) - oEventBytes := oEvent.Bytes(stream) - rmcMessage.SetParameters(oEventBytes) - rmcMessageBytes := rmcMessage.Bytes() - - targetClient := server.FindClientFromPID(uint32(session.GameMatchmakeSession.Gathering.OwnerPID)) - if targetClient == nil { - logger.Warning("Owner client not found") - return 0 - } - - var messagePacket nex.PacketInterface - - if server.PRUDPVersion() == 0 { - messagePacket, _ = nex.NewPacketV0(targetClient, nil) - messagePacket.SetVersion(0) - } else { - messagePacket, _ = nex.NewPacketV1(targetClient, nil) - messagePacket.SetVersion(1) - } - - messagePacket.SetSource(0xA1) - messagePacket.SetDestination(0xAF) - messagePacket.SetType(nex.DataPacket) - messagePacket.SetPayload(rmcMessageBytes) - - messagePacket.AddFlag(nex.FlagNeedsAck) - messagePacket.AddFlag(nex.FlagReliable) - - server.Send(messagePacket) - return 0 } diff --git a/matchmake-extension/create_matchmake_session.go b/matchmake-extension/create_matchmake_session.go index 7606c45..ba11c2e 100644 --- a/matchmake-extension/create_matchmake_session.go +++ b/matchmake-extension/create_matchmake_session.go @@ -29,29 +29,13 @@ func createMatchmakeSession(err error, client *nex.Client, callID uint32, anyGat return nex.Errors.Core.InvalidArgument } - sessionIndex := common_globals.GetAvailableGatheringID() - // This should in theory be impossible, as there aren't enough PIDs creating sessions to fill the uint32 limit. - // If we ever get here, we must be not deleting sessions properly - if sessionIndex == 0 { - logger.Critical("No gatherings available!") - return nex.Errors.RendezVous.LimitExceeded - } - - session := common_globals.CommonMatchmakeSession{ - SearchCriteria: make([]*match_making_types.MatchmakeSessionSearchCriteria, 0), - GameMatchmakeSession: matchmakeSession, + session, err, errCode := common_globals.CreateSessionBySearchCriteria(matchmakeSession, make([]*match_making_types.MatchmakeSessionSearchCriteria, 0), client.PID()) + if err != nil { + logger.Error(err.Error()) + return errCode } - common_globals.Sessions[sessionIndex] = &session - common_globals.Sessions[sessionIndex].GameMatchmakeSession.Gathering.ID = sessionIndex - common_globals.Sessions[sessionIndex].GameMatchmakeSession.Gathering.OwnerPID = client.PID() - common_globals.Sessions[sessionIndex].GameMatchmakeSession.Gathering.HostPID = client.PID() - - common_globals.Sessions[sessionIndex].GameMatchmakeSession.StartedTime = nex.NewDateTime(0) - common_globals.Sessions[sessionIndex].GameMatchmakeSession.StartedTime.UTC() - common_globals.Sessions[sessionIndex].GameMatchmakeSession.SessionKey = make([]byte, 32) - - err, errCode := common_globals.AddPlayersToSession(common_globals.Sessions[sessionIndex], []uint32{client.ConnectionID()}) + err, errCode = common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) if err != nil { logger.Error(err.Error()) return errCode @@ -59,10 +43,10 @@ func createMatchmakeSession(err error, client *nex.Client, callID uint32, anyGat rmcResponseStream := nex.NewStreamOut(server) - rmcResponseStream.WriteUInt32LE(sessionIndex) + rmcResponseStream.WriteUInt32LE(session.GameMatchmakeSession.Gathering.ID) if server.MatchMakingProtocolVersion().GreaterOrEqual("3.0.0") { - rmcResponseStream.WriteBuffer(matchmakeSession.SessionKey) + rmcResponseStream.WriteBuffer(session.GameMatchmakeSession.SessionKey) } rmcResponseBody := rmcResponseStream.Bytes() diff --git a/matchmake-extension/create_matchmake_session_with_param.go b/matchmake-extension/create_matchmake_session_with_param.go index 3820a8a..14dfb26 100644 --- a/matchmake-extension/create_matchmake_session_with_param.go +++ b/matchmake-extension/create_matchmake_session_with_param.go @@ -5,8 +5,6 @@ import ( common_globals "github.com/PretendoNetwork/nex-protocols-common-go/globals" match_making_types "github.com/PretendoNetwork/nex-protocols-go/match-making/types" matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/matchmake-extension" - notifications "github.com/PretendoNetwork/nex-protocols-go/notifications" - notifications_types "github.com/PretendoNetwork/nex-protocols-go/notifications/types" ) func createMatchmakeSessionWithParam(err error, client *nex.Client, callID uint32, createMatchmakeSessionParam *match_making_types.CreateMatchmakeSessionParam) uint32 { @@ -22,37 +20,13 @@ func createMatchmakeSessionWithParam(err error, client *nex.Client, callID uint3 common_globals.RemoveClientFromAllSessions(client) joinedMatchmakeSession := createMatchmakeSessionParam.SourceMatchmakeSession.Copy().(*match_making_types.MatchmakeSession) - - sessionIndex := common_globals.GetAvailableGatheringID() - if sessionIndex == 0 { - logger.Critical("No gatherings available!") - return nex.Errors.RendezVous.LimitExceeded - } - - joinedMatchmakeSession.SetStructureVersion(3) - joinedMatchmakeSession.Gathering.ID = sessionIndex - joinedMatchmakeSession.Gathering.OwnerPID = client.PID() - joinedMatchmakeSession.Gathering.HostPID = client.PID() - joinedMatchmakeSession.StartedTime = nex.NewDateTime(0) - joinedMatchmakeSession.StartedTime.UTC() - joinedMatchmakeSession.SessionKey = make([]byte, 32) - - // TODO - Are these parameters game-specific? - - joinedMatchmakeSession.MatchmakeParam.Parameters["@SR"] = nex.NewVariant() - joinedMatchmakeSession.MatchmakeParam.Parameters["@SR"].TypeID = 3 - joinedMatchmakeSession.MatchmakeParam.Parameters["@SR"].Bool = true - - joinedMatchmakeSession.MatchmakeParam.Parameters["@GIR"] = nex.NewVariant() - joinedMatchmakeSession.MatchmakeParam.Parameters["@GIR"].TypeID = 1 - joinedMatchmakeSession.MatchmakeParam.Parameters["@GIR"].Int64 = 3 - - common_globals.Sessions[sessionIndex] = &common_globals.CommonMatchmakeSession{ - SearchCriteria: make([]*match_making_types.MatchmakeSessionSearchCriteria, 0), - GameMatchmakeSession: joinedMatchmakeSession, + session, err, errCode := common_globals.CreateSessionBySearchCriteria(joinedMatchmakeSession, make([]*match_making_types.MatchmakeSessionSearchCriteria, 0), client.PID()) + if err != nil { + logger.Error(err.Error()) + return errCode } - err, errCode := common_globals.AddPlayersToSession(common_globals.Sessions[sessionIndex], []uint32{client.ConnectionID()}) + err, errCode = common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) if err != nil { logger.Error(err.Error()) return errCode @@ -60,7 +34,7 @@ func createMatchmakeSessionWithParam(err error, client *nex.Client, callID uint3 rmcResponseStream := nex.NewStreamOut(server) - rmcResponseStream.WriteStructure(joinedMatchmakeSession) + rmcResponseStream.WriteStructure(session.GameMatchmakeSession) rmcResponseBody := rmcResponseStream.Bytes() @@ -89,49 +63,5 @@ func createMatchmakeSessionWithParam(err error, client *nex.Client, callID uint3 server.Send(responsePacket) - // * Works for Minecraft, not tried on anything else - notificationRequestMessage := nex.NewRMCRequest() - notificationRequestMessage.SetProtocolID(notifications.ProtocolID) - notificationRequestMessage.SetCallID(0xffff0000 + callID) - notificationRequestMessage.SetMethodID(notifications.MethodProcessNotificationEvent) - - notificationCategory := notifications.NotificationCategories.Participation - notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant - - oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = client.PID() - oEvent.Type = notifications.BuildNotificationType(notificationCategory, notificationSubtype) - oEvent.Param1 = sessionIndex - oEvent.Param2 = client.PID() - oEvent.StrParam = "" - oEvent.Param3 = 1 - - notificationStream := nex.NewStreamOut(server) - - notificationStream.WriteStructure(oEvent) - - notificationRequestMessage.SetParameters(notificationStream.Bytes()) - notificationRequestBytes := notificationRequestMessage.Bytes() - - var messagePacket nex.PacketInterface - - if server.PRUDPVersion() == 0 { - messagePacket, _ = nex.NewPacketV0(client, nil) - messagePacket.SetVersion(0) - } else { - messagePacket, _ = nex.NewPacketV1(client, nil) - messagePacket.SetVersion(1) - } - - messagePacket.SetSource(0xA1) - messagePacket.SetDestination(0xAF) - messagePacket.SetType(nex.DataPacket) - messagePacket.SetPayload(notificationRequestBytes) - - messagePacket.AddFlag(nex.FlagNeedsAck) - messagePacket.AddFlag(nex.FlagReliable) - - server.Send(messagePacket) - return 0 } diff --git a/matchmake-extension/join_matchmake_session.go b/matchmake-extension/join_matchmake_session.go index aca0a25..fe72652 100644 --- a/matchmake-extension/join_matchmake_session.go +++ b/matchmake-extension/join_matchmake_session.go @@ -4,8 +4,6 @@ import ( nex "github.com/PretendoNetwork/nex-go" common_globals "github.com/PretendoNetwork/nex-protocols-common-go/globals" matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/matchmake-extension" - notifications "github.com/PretendoNetwork/nex-protocols-go/notifications" - notifications_types "github.com/PretendoNetwork/nex-protocols-go/notifications/types" ) func joinMatchmakeSession(err error, client *nex.Client, callID uint32, gid uint32, strMessage string) uint32 { @@ -23,7 +21,7 @@ func joinMatchmakeSession(err error, client *nex.Client, callID uint32, gid uint // TODO - More checks here - err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}) + err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) if err != nil { logger.Error(err.Error()) return errCode @@ -64,58 +62,5 @@ func joinMatchmakeSession(err error, client *nex.Client, callID uint32, gid uint server.Send(responsePacket) - for i := 0; i < len(session.ConnectionIDs); i++ { - target := server.FindClientFromConnectionID(session.ConnectionIDs[i]) - if target == nil { - // TODO - Error here? - logger.Warning("Player not found") - continue - } - - // * Works for Minecraft, not tried on anything else - notificationRequestMessage := nex.NewRMCRequest() - notificationRequestMessage.SetProtocolID(notifications.ProtocolID) - notificationRequestMessage.SetCallID(0xffff0000 + callID + uint32(i)) - notificationRequestMessage.SetMethodID(notifications.MethodProcessNotificationEvent) - - notificationCategory := notifications.NotificationCategories.Participation - notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant - - oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = client.PID() - oEvent.Type = notifications.BuildNotificationType(notificationCategory, notificationSubtype) - oEvent.Param1 = joinedMatchmakeSession.ID - oEvent.Param2 = target.PID() - oEvent.StrParam = strMessage - oEvent.Param3 = 1 - - notificationStream := nex.NewStreamOut(server) - - notificationStream.WriteStructure(oEvent) - - notificationRequestMessage.SetParameters(notificationStream.Bytes()) - notificationRequestBytes := notificationRequestMessage.Bytes() - - var messagePacket nex.PacketInterface - - if server.PRUDPVersion() == 0 { - messagePacket, _ = nex.NewPacketV0(client, nil) - messagePacket.SetVersion(0) - } else { - messagePacket, _ = nex.NewPacketV1(client, nil) - messagePacket.SetVersion(1) - } - - messagePacket.SetSource(0xA1) - messagePacket.SetDestination(0xAF) - messagePacket.SetType(nex.DataPacket) - messagePacket.SetPayload(notificationRequestBytes) - - messagePacket.AddFlag(nex.FlagNeedsAck) - messagePacket.AddFlag(nex.FlagReliable) - - server.Send(messagePacket) - } - return 0 } diff --git a/matchmake-extension/join_matchmake_session_with_param.go b/matchmake-extension/join_matchmake_session_with_param.go index 7ea247d..e2cb4d6 100644 --- a/matchmake-extension/join_matchmake_session_with_param.go +++ b/matchmake-extension/join_matchmake_session_with_param.go @@ -5,8 +5,6 @@ import ( common_globals "github.com/PretendoNetwork/nex-protocols-common-go/globals" match_making_types "github.com/PretendoNetwork/nex-protocols-go/match-making/types" matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/matchmake-extension" - notifications "github.com/PretendoNetwork/nex-protocols-go/notifications" - notifications_types "github.com/PretendoNetwork/nex-protocols-go/notifications/types" ) func joinMatchmakeSessionWithParam(err error, client *nex.Client, callID uint32, joinMatchmakeSessionParam *match_making_types.JoinMatchmakeSessionParam) uint32 { @@ -23,8 +21,7 @@ func joinMatchmakeSessionWithParam(err error, client *nex.Client, callID uint32, } // TODO - More checks here - - err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}) + err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) if err != nil { logger.Error(err.Error()) return errCode @@ -63,58 +60,5 @@ func joinMatchmakeSessionWithParam(err error, client *nex.Client, callID uint32, server.Send(responsePacket) - for i := 0; i < len(session.ConnectionIDs); i++ { - target := server.FindClientFromConnectionID(session.ConnectionIDs[i]) - if target == nil { - // TODO - Error here? - logger.Warning("Player not found") - continue - } - - // * Works for Minecraft, not tried on anything else - notificationRequestMessage := nex.NewRMCRequest() - notificationRequestMessage.SetProtocolID(notifications.ProtocolID) - notificationRequestMessage.SetCallID(0xffff0000 + callID + uint32(i)) - notificationRequestMessage.SetMethodID(notifications.MethodProcessNotificationEvent) - - notificationCategory := notifications.NotificationCategories.Participation - notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant - - oEvent := notifications_types.NewNotificationEvent() - oEvent.PIDSource = client.PID() - oEvent.Type = notifications.BuildNotificationType(notificationCategory, notificationSubtype) - oEvent.Param1 = joinedMatchmakeSession.ID - oEvent.Param2 = target.PID() - oEvent.StrParam = "" - oEvent.Param3 = 1 - - notificationStream := nex.NewStreamOut(server) - - notificationStream.WriteStructure(oEvent) - - notificationRequestMessage.SetParameters(notificationStream.Bytes()) - notificationRequestBytes := notificationRequestMessage.Bytes() - - var messagePacket nex.PacketInterface - - if server.PRUDPVersion() == 0 { - messagePacket, _ = nex.NewPacketV0(client, nil) - messagePacket.SetVersion(0) - } else { - messagePacket, _ = nex.NewPacketV1(client, nil) - messagePacket.SetVersion(1) - } - - messagePacket.SetSource(0xA1) - messagePacket.SetDestination(0xAF) - messagePacket.SetType(nex.DataPacket) - messagePacket.SetPayload(notificationRequestBytes) - - messagePacket.AddFlag(nex.FlagNeedsAck) - messagePacket.AddFlag(nex.FlagReliable) - - server.Send(messagePacket) - } - return 0 } diff --git a/matchmake-extension/protocol.go b/matchmake-extension/protocol.go index 33d864f..ce25842 100644 --- a/matchmake-extension/protocol.go +++ b/matchmake-extension/protocol.go @@ -46,6 +46,7 @@ func initDefault(c *CommonMatchmakeExtensionProtocol) { c.DefaultProtocol.CreateMatchmakeSession(createMatchmakeSession) c.DefaultProtocol.GetSimplePlayingSession(getSimplePlayingSession) c.DefaultProtocol.AutoMatchmakePostpone(autoMatchmake_Postpone) + c.DefaultProtocol.AutoMatchmakeWithParamPostpone(autoMatchmakeWithParam_Postpone) c.DefaultProtocol.AutoMatchmakeWithSearchCriteriaPostpone(autoMatchmakeWithSearchCriteria_Postpone) c.DefaultProtocol.UpdateProgressScore(updateProgressScore) c.DefaultProtocol.CreateMatchmakeSessionWithParam(createMatchmakeSessionWithParam) From aa73a77404f378440fbbb65bdbb5dfbe4ab3dec5 Mon Sep 17 00:00:00 2001 From: shutterbug2000 Date: Thu, 12 Oct 2023 15:44:03 -0500 Subject: [PATCH 2/6] Code review fixes --- globals/matchmaking_globals.go | 2 +- globals/matchmaking_utils.go | 75 +++++++++---------- .../auto_matchmake_postpone.go | 6 +- .../auto_matchmake_with_param_postpone.go | 50 +------------ ...matchmake_with_search_criteria_postpone.go | 2 +- .../create_matchmake_session.go | 2 +- .../create_matchmake_session_with_param.go | 2 +- matchmake-extension/join_matchmake_session.go | 2 +- .../join_matchmake_session_with_param.go | 2 +- secure-connection/replace_url.go | 1 + 10 files changed, 46 insertions(+), 98 deletions(-) diff --git a/globals/matchmaking_globals.go b/globals/matchmaking_globals.go index 792a94e..9c4adf1 100644 --- a/globals/matchmaking_globals.go +++ b/globals/matchmaking_globals.go @@ -14,4 +14,4 @@ type CommonMatchmakeSession struct { var Sessions map[uint32]*CommonMatchmakeSession var CurrentGatheringID = nex.NewCounter(0) -var CurrentMatchmakingCallID uint32 +var CurrentMatchmakingCallID = nex.NewCounter(0) diff --git a/globals/matchmaking_utils.go b/globals/matchmaking_utils.go index 0d338c4..971712f 100644 --- a/globals/matchmaking_utils.go +++ b/globals/matchmaking_utils.go @@ -91,8 +91,7 @@ func RemoveClientFromAllSessions(client *nex.Client) { rmcMessage := nex.NewRMCRequest() rmcMessage.SetProtocolID(notifications.ProtocolID) - rmcMessage.SetCallID(CurrentMatchmakingCallID) - CurrentMatchmakingCallID+=1 + rmcMessage.SetCallID(CurrentMatchmakingCallID.Increment()) rmcMessage.SetMethodID(notifications.MethodProcessNotificationEvent) category := notifications.NotificationCategories.Participation @@ -145,10 +144,9 @@ func RemoveClientFromAllSessions(client *nex.Client) { // CreateSessionByMatchmakeSession creates a gathering from a MatchmakeSession func CreateSessionByMatchmakeSession(matchmakeSession *match_making_types.MatchmakeSession, searchMatchmakeSession *match_making_types.MatchmakeSession, hostPID uint32) (*CommonMatchmakeSession, error, uint32) { sessionIndex := GetAvailableGatheringID() - // This should in theory be impossible, as there aren't enough PIDs creating sessions to fill the uint32 limit. - // If we ever get here, we must be not deleting sessions properly if sessionIndex == 0 { - return &CommonMatchmakeSession{}, fmt.Errorf("No gatherings available!"), nex.Errors.RendezVous.LimitExceeded + CurrentGatheringID = nex.NewCounter(0) + sessionIndex = GetAvailableGatheringID() } session := CommonMatchmakeSession{ @@ -156,15 +154,16 @@ func CreateSessionByMatchmakeSession(matchmakeSession *match_making_types.Matchm GameMatchmakeSession: matchmakeSession, } - Sessions[sessionIndex] = &session - Sessions[sessionIndex].GameMatchmakeSession.Gathering.ID = sessionIndex - Sessions[sessionIndex].GameMatchmakeSession.Gathering.OwnerPID = hostPID - Sessions[sessionIndex].GameMatchmakeSession.Gathering.HostPID = hostPID + session.GameMatchmakeSession.Gathering.ID = sessionIndex + session.GameMatchmakeSession.Gathering.OwnerPID = hostPID + session.GameMatchmakeSession.Gathering.HostPID = hostPID + + session.GameMatchmakeSession.StartedTime = nex.NewDateTime(0) + session.GameMatchmakeSession.StartedTime.UTC() + session.GameMatchmakeSession.SessionKey = make([]byte, 32) + rand.Read(session.GameMatchmakeSession.SessionKey) - Sessions[sessionIndex].GameMatchmakeSession.StartedTime = nex.NewDateTime(0) - Sessions[sessionIndex].GameMatchmakeSession.StartedTime.UTC() - Sessions[sessionIndex].GameMatchmakeSession.SessionKey = make([]byte, 32) - rand.Read(Sessions[sessionIndex].GameMatchmakeSession.SessionKey) + Sessions[sessionIndex] = &session return Sessions[sessionIndex], nil, 0 } @@ -200,11 +199,9 @@ func FindSessionByMatchmakeSession(searchMatchmakeSession *match_making_types.Ma // CreateSessionBySearchCriteria creates a gathering from MatchmakeSessionSearchCriteria func CreateSessionBySearchCriteria(matchmakeSession *match_making_types.MatchmakeSession, lstSearchCriteria []*match_making_types.MatchmakeSessionSearchCriteria, hostPID uint32) (*CommonMatchmakeSession, error, uint32) { sessionIndex := GetAvailableGatheringID() - - // * This should in theory be impossible, as there aren't enough PIDs creating sessions to fill the uint32 limit. - // * If we ever get here, we must be not deleting sessions properly if sessionIndex == 0 { - return &CommonMatchmakeSession{}, fmt.Errorf("No gatherings available!"), nex.Errors.RendezVous.LimitExceeded + CurrentGatheringID = nex.NewCounter(0) + sessionIndex = GetAvailableGatheringID() } session := CommonMatchmakeSession{ @@ -212,15 +209,16 @@ func CreateSessionBySearchCriteria(matchmakeSession *match_making_types.Matchmak GameMatchmakeSession: matchmakeSession, } - Sessions[sessionIndex] = &session - Sessions[sessionIndex].GameMatchmakeSession.Gathering.ID = sessionIndex - Sessions[sessionIndex].GameMatchmakeSession.Gathering.OwnerPID = hostPID - Sessions[sessionIndex].GameMatchmakeSession.Gathering.HostPID = hostPID + session.GameMatchmakeSession.Gathering.ID = sessionIndex + session.GameMatchmakeSession.Gathering.OwnerPID = hostPID + session.GameMatchmakeSession.Gathering.HostPID = hostPID + + session.GameMatchmakeSession.StartedTime = nex.NewDateTime(0) + session.GameMatchmakeSession.StartedTime.UTC() + session.GameMatchmakeSession.SessionKey = make([]byte, 32) + rand.Read(session.GameMatchmakeSession.SessionKey) - Sessions[sessionIndex].GameMatchmakeSession.StartedTime = nex.NewDateTime(0) - Sessions[sessionIndex].GameMatchmakeSession.StartedTime.UTC() - Sessions[sessionIndex].GameMatchmakeSession.SessionKey = make([]byte, 32) - rand.Read(Sessions[sessionIndex].GameMatchmakeSession.SessionKey) + Sessions[sessionIndex] = &session return Sessions[sessionIndex], nil, 0 } @@ -334,7 +332,7 @@ func FindSessionsByMatchmakeSessionSearchCriterias(lstSearchCriteria []*match_ma // AddPlayersToSession updates the given sessions state to include the provided connection IDs // Returns a NEX error code if failed -func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32, initiatingClient *nex.Client) (error, uint32) { +func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32, initiatingClient *nex.Client, joinMessage string) (error, uint32) { if (len(session.ConnectionIDs) + len(connectionIDs)) > int(session.GameMatchmakeSession.Gathering.MaximumParticipants) { return fmt.Errorf("Gathering %d is full", session.GameMatchmakeSession.Gathering.ID), nex.Errors.RendezVous.SessionFull } @@ -362,8 +360,7 @@ func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32 notificationRequestMessage := nex.NewRMCRequest() notificationRequestMessage.SetProtocolID(notifications.ProtocolID) - notificationRequestMessage.SetCallID(CurrentMatchmakingCallID) - CurrentMatchmakingCallID+=1 + notificationRequestMessage.SetCallID(CurrentMatchmakingCallID.Increment()) notificationRequestMessage.SetMethodID(notifications.MethodProcessNotificationEvent) notificationCategory := notifications.NotificationCategories.Participation @@ -374,7 +371,7 @@ func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32 oEvent.Type = notifications.BuildNotificationType(notificationCategory, notificationSubtype) oEvent.Param1 = session.GameMatchmakeSession.ID oEvent.Param2 = target.PID() - oEvent.StrParam = "" + oEvent.StrParam = joinMessage oEvent.Param3 = uint32(len(connectionIDs)) notificationStream := nex.NewStreamOut(server) @@ -405,9 +402,9 @@ func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32 server.Send(messagePacket) } - //This appears to be correct. Tri-Force Heroes uses 3.9.0, and has issues if this is ran. - //Minecraft, however, requires this to be ran. - //TODO: Check other games both pre and post 3.10.0 and validate. + // This appears to be correct. Tri-Force Heroes uses 3.9.0, and has issues if these notifications are sent + // Minecraft, however, requires these to be sent + // TODO: Check other games both pre and post 3.10.0 and validate if server.MatchMakingProtocolVersion().GreaterOrEqual("3.10.0") { for i := 0; i < len(session.ConnectionIDs); i++ { target := server.FindClientFromConnectionID(session.ConnectionIDs[i]) @@ -419,8 +416,7 @@ func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32 notificationRequestMessage := nex.NewRMCRequest() notificationRequestMessage.SetProtocolID(notifications.ProtocolID) - notificationRequestMessage.SetCallID(CurrentMatchmakingCallID) - CurrentMatchmakingCallID+=1 + notificationRequestMessage.SetCallID(CurrentMatchmakingCallID.Increment()) notificationRequestMessage.SetMethodID(notifications.MethodProcessNotificationEvent) notificationCategory := notifications.NotificationCategories.Participation @@ -431,7 +427,7 @@ func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32 oEvent.Type = notifications.BuildNotificationType(notificationCategory, notificationSubtype) oEvent.Param1 = session.GameMatchmakeSession.ID oEvent.Param2 = target.PID() - oEvent.StrParam = "" + oEvent.StrParam = joinMessage oEvent.Param3 = uint32(len(connectionIDs)) notificationStream := nex.NewStreamOut(server) @@ -440,7 +436,6 @@ func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32 notificationRequestMessage.SetParameters(notificationStream.Bytes()) notificationRequestBytes := notificationRequestMessage.Bytes() - //fmt.Println(hex.EncodeToString(notificationRequestBytes)) var messagePacket nex.PacketInterface @@ -465,8 +460,7 @@ func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32 notificationRequestMessage := nex.NewRMCRequest() notificationRequestMessage.SetProtocolID(notifications.ProtocolID) - notificationRequestMessage.SetCallID(CurrentMatchmakingCallID) - CurrentMatchmakingCallID+=1 + notificationRequestMessage.SetCallID(CurrentMatchmakingCallID.Increment()) notificationRequestMessage.SetMethodID(notifications.MethodProcessNotificationEvent) notificationCategory := notifications.NotificationCategories.Participation @@ -477,7 +471,7 @@ func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32 oEvent.Type = notifications.BuildNotificationType(notificationCategory, notificationSubtype) oEvent.Param1 = session.GameMatchmakeSession.ID oEvent.Param2 = initiatingClient.PID() - oEvent.StrParam = "" + oEvent.StrParam = joinMessage oEvent.Param3 = uint32(len(connectionIDs)) notificationStream := nex.NewStreamOut(server) @@ -552,8 +546,7 @@ func ChangeSessionOwner(ownerClient *nex.Client, gathering uint32) { rmcMessage := nex.NewRMCRequest() rmcMessage.SetProtocolID(notifications.ProtocolID) - rmcMessage.SetCallID(CurrentMatchmakingCallID) - CurrentMatchmakingCallID+=1 + rmcMessage.SetCallID(CurrentMatchmakingCallID.Increment()) rmcMessage.SetMethodID(notifications.MethodProcessNotificationEvent) category := notifications.NotificationCategories.OwnershipChanged diff --git a/matchmake-extension/auto_matchmake_postpone.go b/matchmake-extension/auto_matchmake_postpone.go index fc6889d..f470754 100644 --- a/matchmake-extension/auto_matchmake_postpone.go +++ b/matchmake-extension/auto_matchmake_postpone.go @@ -46,11 +46,11 @@ func autoMatchmake_Postpone(err error, client *nex.Client, callID uint32, anyGat logger.Error(err.Error()) return errCode } - }else{ + } else { session = common_globals.Sessions[sessionIndex] } - err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) + err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client, message) if err != nil { logger.Error(err.Error()) return errCode @@ -81,7 +81,7 @@ func autoMatchmake_Postpone(err error, client *nex.Client, callID uint32, anyGat responsePacket.SetSource(0xA1) responsePacket.SetDestination(0xAF) responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) + responsePacket.SetPayload(rmcResponseBytes) responsePacket.AddFlag(nex.FlagNeedsAck) responsePacket.AddFlag(nex.FlagReliable) diff --git a/matchmake-extension/auto_matchmake_with_param_postpone.go b/matchmake-extension/auto_matchmake_with_param_postpone.go index fa613bf..b403148 100644 --- a/matchmake-extension/auto_matchmake_with_param_postpone.go +++ b/matchmake-extension/auto_matchmake_with_param_postpone.go @@ -39,57 +39,11 @@ func autoMatchmakeWithParam_Postpone(err error, client *nex.Client, callID uint3 logger.Error(err.Error()) return errCode } - }else{ + } else { session = common_globals.Sessions[sessionIndex] } - /*sessionIndex = common_globals.GetAvailableGatheringID() - // This should in theory be impossible, as there aren't enough PIDs creating sessions to fill the uint32 limit. - // If we ever get here, we must be not deleting sessions properly - if sessionIndex == 0 { - logger.Critical("No gatherings available!") - return nex.Errors.RendezVous.LimitExceeded - } - - session := common_globals.CommonMatchmakeSession{ - SearchMatchmakeSession: searchMatchmakeSession, - GameMatchmakeSession: matchmakeSession, - } - session = &session - session.GameMatchmakeSession.Gathering.ID = sessionIndex - session.GameMatchmakeSession.Gathering.OwnerPID = client.PID() - session.GameMatchmakeSession.Gathering.HostPID = client.PID() - - session.GameMatchmakeSession.StartedTime = nex.NewDateTime(0) - session.GameMatchmakeSession.StartedTime.UTC() - session.GameMatchmakeSession.SessionKey = make([]byte, 32) - - session.GameMatchmakeSession.MatchmakeParam.Parameters["@SR"] = nex.NewVariant() - session.GameMatchmakeSession.MatchmakeParam.Parameters["@SR"].TypeID = 3 - session.GameMatchmakeSession.MatchmakeParam.Parameters["@SR"].Bool = true - - session.GameMatchmakeSession.MatchmakeParam.Parameters["@GIR"] = nex.NewVariant() - session.GameMatchmakeSession.MatchmakeParam.Parameters["@GIR"].TypeID = 1 - session.GameMatchmakeSession.MatchmakeParam.Parameters["@GIR"].Int64 = 3 - - session.GameMatchmakeSession.MatchmakeParam.Parameters["@Lon"] = nex.NewVariant() - session.GameMatchmakeSession.MatchmakeParam.Parameters["@Lon"].TypeID = 2 - session.GameMatchmakeSession.MatchmakeParam.Parameters["@Lon"].Float64 = 0 - - session.GameMatchmakeSession.MatchmakeParam.Parameters["@Lat"] = nex.NewVariant() - session.GameMatchmakeSession.MatchmakeParam.Parameters["@Lat"].TypeID = 2 - session.GameMatchmakeSession.MatchmakeParam.Parameters["@Lat"].Float64 = 0 - - session.GameMatchmakeSession.MatchmakeParam.Parameters["@CC"] = nex.NewVariant() - session.GameMatchmakeSession.MatchmakeParam.Parameters["@CC"].TypeID = 4 - session.GameMatchmakeSession.MatchmakeParam.Parameters["@CC"].Str = "US" - - session.GameMatchmakeSession.MatchmakeParam.Parameters["@DR"] = nex.NewVariant() - session.GameMatchmakeSession.MatchmakeParam.Parameters["@DR"].TypeID = 1 - session.GameMatchmakeSession.MatchmakeParam.Parameters["@DR"].Int64 = 0 - }*/ - - err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) + err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client, "") if err != nil { logger.Error(err.Error()) return errCode diff --git a/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go b/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go index 0f3dbab..bda5a30 100644 --- a/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go +++ b/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go @@ -50,7 +50,7 @@ func autoMatchmakeWithSearchCriteria_Postpone(err error, client *nex.Client, cal session = sessions[0] } - err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) + err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client, message) if err != nil { logger.Error(err.Error()) return errCode diff --git a/matchmake-extension/create_matchmake_session.go b/matchmake-extension/create_matchmake_session.go index ba11c2e..fe6dcd0 100644 --- a/matchmake-extension/create_matchmake_session.go +++ b/matchmake-extension/create_matchmake_session.go @@ -35,7 +35,7 @@ func createMatchmakeSession(err error, client *nex.Client, callID uint32, anyGat return errCode } - err, errCode = common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) + err, errCode = common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client, message) if err != nil { logger.Error(err.Error()) return errCode diff --git a/matchmake-extension/create_matchmake_session_with_param.go b/matchmake-extension/create_matchmake_session_with_param.go index 14dfb26..f1b22c2 100644 --- a/matchmake-extension/create_matchmake_session_with_param.go +++ b/matchmake-extension/create_matchmake_session_with_param.go @@ -26,7 +26,7 @@ func createMatchmakeSessionWithParam(err error, client *nex.Client, callID uint3 return errCode } - err, errCode = common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) + err, errCode = common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client, "") if err != nil { logger.Error(err.Error()) return errCode diff --git a/matchmake-extension/join_matchmake_session.go b/matchmake-extension/join_matchmake_session.go index fe72652..4356686 100644 --- a/matchmake-extension/join_matchmake_session.go +++ b/matchmake-extension/join_matchmake_session.go @@ -21,7 +21,7 @@ func joinMatchmakeSession(err error, client *nex.Client, callID uint32, gid uint // TODO - More checks here - err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) + err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client, strMessage) if err != nil { logger.Error(err.Error()) return errCode diff --git a/matchmake-extension/join_matchmake_session_with_param.go b/matchmake-extension/join_matchmake_session_with_param.go index e2cb4d6..9d79da9 100644 --- a/matchmake-extension/join_matchmake_session_with_param.go +++ b/matchmake-extension/join_matchmake_session_with_param.go @@ -21,7 +21,7 @@ func joinMatchmakeSessionWithParam(err error, client *nex.Client, callID uint32, } // TODO - More checks here - err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client) + err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client, "") if err != nil { logger.Error(err.Error()) return errCode diff --git a/secure-connection/replace_url.go b/secure-connection/replace_url.go index 6670ffa..4f999ff 100644 --- a/secure-connection/replace_url.go +++ b/secure-connection/replace_url.go @@ -17,6 +17,7 @@ func replaceURL(err error, client *nex.Client, callID uint32, oldStation *nex.St for i := 0; i < len(stations); i++ { currentStation := stations[i] if currentStation.Address() == oldStation.Address() && currentStation.Port() == oldStation.Port() { + newStation.SetPID(client.PID()) //This fixes Minecraft, but is obviously incorrect. TODO: What are we really meant to do here? stations[i] = newStation } } From 76bb2e28185a3d663a73e2d18806cab7d6432c0c Mon Sep 17 00:00:00 2001 From: shutterbug2000 Date: Thu, 12 Oct 2023 16:42:35 -0500 Subject: [PATCH 3/6] Code review fixes --- globals/matchmaking_utils.go | 11 ++++++++--- .../create_matchmake_session_with_param.go | 2 +- .../join_matchmake_session_with_param.go | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/globals/matchmaking_utils.go b/globals/matchmaking_utils.go index 971712f..4f33f8d 100644 --- a/globals/matchmaking_utils.go +++ b/globals/matchmaking_utils.go @@ -5,7 +5,7 @@ import ( "math" "strconv" "strings" - "math/rand" + "crypto/rand" nex "github.com/PretendoNetwork/nex-go" match_making "github.com/PretendoNetwork/nex-protocols-go/match-making" @@ -481,8 +481,6 @@ func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32 notificationRequestMessage.SetParameters(notificationStream.Bytes()) notificationRequestBytes := notificationRequestMessage.Bytes() - target := server.FindClientFromPID(uint32(session.GameMatchmakeSession.Gathering.OwnerPID)) - var messagePacket nex.PacketInterface if server.PRUDPVersion() == 0 { @@ -503,6 +501,13 @@ func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32 server.Send(messagePacket) + target := server.FindClientFromPID(uint32(session.GameMatchmakeSession.Gathering.OwnerPID)) + if target == nil { + // TODO - Error here? + //logger.Warning("Player not found") + return nil, 0 + } + if server.PRUDPVersion() == 0 { messagePacket, _ = nex.NewPacketV0(target, nil) messagePacket.SetVersion(0) diff --git a/matchmake-extension/create_matchmake_session_with_param.go b/matchmake-extension/create_matchmake_session_with_param.go index f1b22c2..d816d2d 100644 --- a/matchmake-extension/create_matchmake_session_with_param.go +++ b/matchmake-extension/create_matchmake_session_with_param.go @@ -26,7 +26,7 @@ func createMatchmakeSessionWithParam(err error, client *nex.Client, callID uint3 return errCode } - err, errCode = common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client, "") + err, errCode = common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client, createMatchmakeSessionParam.JoinMessage) if err != nil { logger.Error(err.Error()) return errCode diff --git a/matchmake-extension/join_matchmake_session_with_param.go b/matchmake-extension/join_matchmake_session_with_param.go index 9d79da9..6629cb2 100644 --- a/matchmake-extension/join_matchmake_session_with_param.go +++ b/matchmake-extension/join_matchmake_session_with_param.go @@ -21,7 +21,7 @@ func joinMatchmakeSessionWithParam(err error, client *nex.Client, callID uint32, } // TODO - More checks here - err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client, "") + err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client, joinMatchmakeSessionParam.JoinMessage) if err != nil { logger.Error(err.Error()) return errCode From 26f22bab450e8cd94e5f202c1fa21cc89802ccd0 Mon Sep 17 00:00:00 2001 From: shutterbug2000 Date: Thu, 12 Oct 2023 16:44:14 -0500 Subject: [PATCH 4/6] Remove stray space --- globals/matchmaking_utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/globals/matchmaking_utils.go b/globals/matchmaking_utils.go index 4f33f8d..2fd9d9b 100644 --- a/globals/matchmaking_utils.go +++ b/globals/matchmaking_utils.go @@ -5,7 +5,7 @@ import ( "math" "strconv" "strings" - "crypto/rand" + "crypto/rand" nex "github.com/PretendoNetwork/nex-go" match_making "github.com/PretendoNetwork/nex-protocols-go/match-making" From 74e821b440aa65f2a05ce495db49a32bb972a0e5 Mon Sep 17 00:00:00 2001 From: shutterbug2000 Date: Fri, 13 Oct 2023 07:41:54 -0500 Subject: [PATCH 5/6] Use CurrentMatchmakingCallID in other protocols --- matchmaking-ext/end_participation.go | 2 +- matchmaking/unregister_gathering.go | 2 +- matchmaking/update_session_host.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/matchmaking-ext/end_participation.go b/matchmaking-ext/end_participation.go index 124d3e3..bd21378 100644 --- a/matchmaking-ext/end_participation.go +++ b/matchmaking-ext/end_participation.go @@ -76,7 +76,7 @@ func endParticipation(err error, client *nex.Client, callID uint32, idGathering rmcMessage := nex.NewRMCRequest() rmcMessage.SetProtocolID(notifications.ProtocolID) - rmcMessage.SetCallID(0xffff0000 + callID) + rmcMessage.SetCallID(common_globals.CurrentMatchmakingCallID.Increment()) rmcMessage.SetMethodID(notifications.MethodProcessNotificationEvent) category := notifications.NotificationCategories.Participation diff --git a/matchmaking/unregister_gathering.go b/matchmaking/unregister_gathering.go index 1426b5a..164cefb 100644 --- a/matchmaking/unregister_gathering.go +++ b/matchmaking/unregister_gathering.go @@ -57,7 +57,7 @@ func unregisterGathering(err error, client *nex.Client, callID uint32, idGatheri rmcMessage := nex.NewRMCRequest() rmcMessage.SetProtocolID(notifications.ProtocolID) - rmcMessage.SetCallID(0xffff0000 + callID) + rmcMessage.SetCallID(common_globals.CurrentMatchmakingCallID.Increment()) rmcMessage.SetMethodID(notifications.MethodProcessNotificationEvent) category := notifications.NotificationCategories.GatheringUnregistered diff --git a/matchmaking/update_session_host.go b/matchmaking/update_session_host.go index db34a08..670faa0 100644 --- a/matchmaking/update_session_host.go +++ b/matchmaking/update_session_host.go @@ -61,7 +61,7 @@ func updateSessionHost(err error, client *nex.Client, callID uint32, gid uint32, rmcMessage := nex.NewRMCRequest() rmcMessage.SetProtocolID(notifications.ProtocolID) - rmcMessage.SetCallID(0xffff0000 + callID) + rmcMessage.SetCallID(common_globals.CurrentMatchmakingCallID.Increment()) rmcMessage.SetMethodID(notifications.MethodProcessNotificationEvent) category := notifications.NotificationCategories.OwnershipChanged From 942f04defd17b574613281d780a0f62a8044708b Mon Sep 17 00:00:00 2001 From: shutterbug2000 Date: Sat, 14 Oct 2023 08:56:29 -0500 Subject: [PATCH 6/6] Change AutoMatchmakeWithParam_Postpone to use SearchCriteria This should allow for more precise matchmaking Also changes SearchMatchmakeSession to GameMatchmakeSession since a SearchCriteria session won't have a searchMatchmakeSession --- globals/matchmaking_utils.go | 8 ++++---- .../auto_matchmake_with_param_postpone.go | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/globals/matchmaking_utils.go b/globals/matchmaking_utils.go index 2fd9d9b..f96ee03 100644 --- a/globals/matchmaking_utils.go +++ b/globals/matchmaking_utils.go @@ -255,7 +255,7 @@ func FindSessionsByMatchmakeSessionSearchCriterias(lstSearchCriteria []*match_ma continue } - if session.SearchMatchmakeSession.MinimumParticipants < uint16(min) { + if session.GameMatchmakeSession.MinimumParticipants < uint16(min) { continue } } @@ -267,7 +267,7 @@ func FindSessionsByMatchmakeSessionSearchCriterias(lstSearchCriteria []*match_ma continue } - if session.SearchMatchmakeSession.MinimumParticipants > uint16(max) { + if session.GameMatchmakeSession.MinimumParticipants > uint16(max) { continue } } @@ -289,7 +289,7 @@ func FindSessionsByMatchmakeSessionSearchCriterias(lstSearchCriteria []*match_ma continue } - if session.SearchMatchmakeSession.MaximumParticipants < uint16(min) { + if session.GameMatchmakeSession.MaximumParticipants < uint16(min) { continue } } @@ -301,7 +301,7 @@ func FindSessionsByMatchmakeSessionSearchCriterias(lstSearchCriteria []*match_ma continue } - if session.SearchMatchmakeSession.MaximumParticipants > uint16(max) { + if session.GameMatchmakeSession.MaximumParticipants > uint16(max) { continue } } diff --git a/matchmake-extension/auto_matchmake_with_param_postpone.go b/matchmake-extension/auto_matchmake_with_param_postpone.go index b403148..9656c34 100644 --- a/matchmake-extension/auto_matchmake_with_param_postpone.go +++ b/matchmake-extension/auto_matchmake_with_param_postpone.go @@ -8,7 +8,7 @@ import ( ) func autoMatchmakeWithParam_Postpone(err error, client *nex.Client, callID uint32, autoMatchmakeParam *match_making_types.AutoMatchmakeParam) uint32 { - if commonMatchmakeExtensionProtocol.cleanupSearchMatchmakeSessionHandler == nil { + if commonMatchmakeExtensionProtocol.cleanupMatchmakeSessionSearchCriteriaHandler == nil { logger.Warning("MatchmakeExtension::AutoMatchmake_Postpone missing CleanupSearchMatchmakeSessionHandler!") return nex.Errors.Core.NotImplemented } @@ -27,20 +27,20 @@ func autoMatchmakeWithParam_Postpone(err error, client *nex.Client, callID uint3 var matchmakeSession *match_making_types.MatchmakeSession matchmakeSession = autoMatchmakeParam.SourceMatchmakeSession - searchMatchmakeSession := matchmakeSession.Copy().(*match_making_types.MatchmakeSession) - commonMatchmakeExtensionProtocol.cleanupSearchMatchmakeSessionHandler(searchMatchmakeSession) - sessionIndex := common_globals.FindSessionByMatchmakeSession(searchMatchmakeSession) + commonMatchmakeExtensionProtocol.cleanupMatchmakeSessionSearchCriteriaHandler(autoMatchmakeParam.LstSearchCriteria) + + sessions := common_globals.FindSessionsByMatchmakeSessionSearchCriterias(autoMatchmakeParam.LstSearchCriteria, commonMatchmakeExtensionProtocol.gameSpecificMatchmakeSessionSearchCriteriaChecksHandler) var session *common_globals.CommonMatchmakeSession - if sessionIndex == 0 { + if len(sessions) == 0 { var errCode uint32 - session, err, errCode = common_globals.CreateSessionByMatchmakeSession(matchmakeSession, searchMatchmakeSession, client.PID()) + session, err, errCode = common_globals.CreateSessionBySearchCriteria(matchmakeSession, autoMatchmakeParam.LstSearchCriteria, client.PID()) if err != nil { logger.Error(err.Error()) return errCode } } else { - session = common_globals.Sessions[sessionIndex] + session = sessions[0] } err, errCode := common_globals.AddPlayersToSession(session, []uint32{client.ConnectionID()}, client, "")