package matchmake_extension import ( "github.com/PretendoNetwork/nex-go/v2" "github.com/PretendoNetwork/nex-go/v2/types" common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" "github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database" matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) func (commonProtocol *CommonProtocol) modifyCurrentGameAttribute(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32, attribIndex types.UInt32, newValue types.UInt32) (*nex.RMCMessage, *nex.Error) { if err != nil { common_globals.Logger.Error(err.Error()) return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } connection := packet.Sender().(*nex.PRUDPConnection) endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) commonProtocol.manager.Mutex.Lock() session, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, uint32(gid)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } if !session.Gathering.OwnerPID.Equals(connection.PID()) { commonProtocol.manager.Mutex.Unlock() return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") } index := int(attribIndex) if index >= len(session.Attributes) { commonProtocol.manager.Mutex.Unlock() return nil, nex.NewError(nex.ResultCodes.Core.InvalidIndex, "change_error") } nexError = database.UpdateGameAttribute(commonProtocol.manager, uint32(gid), uint32(attribIndex), uint32(newValue)) if nexError != nil { commonProtocol.manager.Mutex.Unlock() return nil, nexError } commonProtocol.manager.Mutex.Unlock() rmcResponse := nex.NewRMCSuccess(endpoint, nil) rmcResponse.ProtocolID = matchmake_extension.ProtocolID rmcResponse.MethodID = matchmake_extension.MethodModifyCurrentGameAttribute rmcResponse.CallID = callID if commonProtocol.OnAfterModifyCurrentGameAttribute != nil { go commonProtocol.OnAfterModifyCurrentGameAttribute(packet, gid, attribIndex, newValue) } return rmcResponse, nil }