RateLimitService

Enables you to limit usage of scripts and native APIs.

# Methods

[{"index":"void SetServerFunctionRateLimitForComponent(string entityId, string componentName, string functionName, int32 maxToken, float tokenRefillPerSecond) (ServerOnly)","0":"Limits the amount of calls to the server execution control function for components belonging to a specific entity. Each time a user calls a function, 1 token is deducted. If all tokens are used, that user's function calls will be restricted. maxToken is the maximum number of tokens. tokenRefillPerSecond is the number of tokens recharged per second."}]

[{"index":"void SetServerFunctionRateLimitForLogic(string logicName, string functionName, int32 maxToken, float tokenRefillPerSecond) (ServerOnly)","0":"Limits the amount of server execution control function calls in the logic. Each time a user calls a function, 1 token is deducted. Users who have used all of their tokens cannot use calling functions. maxToken is the maximum number of tokens. tokenRefillPerSecond is the number of tokens recharged per second."}]

[{"index":"void SetServerFunctionRateLimitForService(string serviceName, string functionName, int32 maxToken, float tokenRefillPerSecond) (ServerOnly)","0":"Limits the amount of calls to the service's server execution control functions. Each time a user calls a function, 1 token is deducted. Users who have used all of their tokens cannot use calling functions. maxToken is the maximum number of tokens. tokenRefillPerSecond is the number of tokens recharged per second."}]

[{"index":"void SetTotalServerFunctionRateLimit(int32 maxToken, float tokenRefillPerSecond) (ServerOnly)","0":"Limits the total number of calls to server execution control functions. Each time a user calls the server function of a component, service, or logic, 1 token is deducted. Users who have used all of their tokens cannot use calling functions. maxToken is the maximum number of tokens. tokenRefillPerSecond is the number of tokens recharged per second."}]

##### inherited from Service:

[{"index":"EventHandlerBase ConnectEvent(string key, IScriptFunction eventHandler)","0":"Links events. When a key-type event occurs in this service, a handler is notified. The handler receives event parameters."}]

[{"index":"EventHandlerBase ConnectEvent(Type eventType, IScriptFunction eventHandler)","0":"Links events. This service notifies a handler when an eventType event occurs. The handler receives event parameters."}]

[{"index":"boolean DisconnectEvent(string key, EventHandlerBase eventHandler)","0":"Disconnects the event with the key-type event and the handler."}]

[{"index":"boolean DisconnectEvent(Type eventType, EventHandlerBase eventHandler)","0":"Disconnects the eventType event from its handler."}]

[{"index":"void SendEvent(EventType sendEvent)","0":"Generates an event."}]

# Events

[{"index":"ServerFunctionRateLimitEvent","0":"This event occurs when the number of calls to the server execution control function of a specific component, service, or logic exceeds the limit."}]

[{"index":"TotalServerFunctionRateLimitEvent","0":"This event occurs when the total number of calls to the server execution control function exceeds the limit."}]

# Examples

This is an example of setting server function limits. Because the set limit only works in that room, we recommend you manage it in Logic.
    
    
    @Component
    script RateLimitManager extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
        -- Sets the limit on the TeleportToEntityPath function of TeleportService.
        _RateLimitService:SetServerFunctionRateLimitForService("TeleportService", "TeleportToEntityPath", 3, 0.1)
    
        -- You can also set the limit in your own script.
        _RateLimitService:SetServerFunctionRateLimitForLogic("MyLogic", "MyFunction", 3, 0.1)
    
        -- You can also limit the amount of calls to all Server execution control functions rather than a specific function.
        _RateLimitService:SetTotalServerFunctionRateLimit(10, 1)
        end
    
        @ExecSpace("ServerOnly")
        @EventSender("Service", "UserService")
        handler HandleUserEnterEvent(UserEnterEvent event)
        --------------- Native Event Sender Info ----------------
        -- Sender: UserService
        -- Space: Server
        ---------------------------------------------------------
    
        -- Parameters
        local ProfileCode = event.ProfileCode
        local UserId = event.UserId
        ---------------------------------------------------------
    
        -- When the user enters, set the limit in the MoveToEntityByPath function of PlayerComponent.
        local userEntity = _UserService:GetUserEntityByUserId(UserId)
        _RateLimitService:SetServerFunctionRateLimitForComponent(userEntity.Id, "PlayerComponent", "MoveToEntityByPath", 3, 0.1)
        end
    end