MVC library
Part of Active UI
A small request and response layer between the client and the server, loosely modeled on
model-view-controller. Panels (the views) send named requests, and handlers on the server
(the controllers) act on them and can answer. On the server MVC.handler registers a
handler for a request name. Inside of a handler respond_to sends a response back to the
player who has made the request, and MVC.push sends data under a name to any player at any
time. On the client MVC.push sends a request, MVC.request sends one and calls a function
with the response, and MVC.listen receives everything the server pushes under a name.
Plugins usually keep their handlers in their controllers folder.
Summary
Functions
Functions
Registers a function that handles the requests clients send with MVC.push or MVC.request. Call respond_to inside the handler to send a response back. Serverside only.
MVC.handler('fl_create_character', function(actor, data)
local status = Characters.create(actor, data)
respond_to { success = status == CHAR_SUCCESS, status = status }
end)
Parameters
- name String name of the request
- handler Function receives the player who has sent the request, followed by the request's data
Registers a permanent callback for the data that the server pushes under the specified name.
Parameters
- name String name of the request
- handler Function receives the pushed values
Registers a callback for the data that the server pushes under the specified name. The callback is removed after the first response unless prevent_remove is set.
Parameters
- name String name of the request
- handler Function receives the pushed values
- prevent_remove Boolean optional, defaults to
falsekeep the callback for further responses
On the server
Sends data to the callbacks the clients have registered with MVC.pull, MVC.request or MVC.listen. Serverside variant.
Parameters
- target Player/List<Player> recipients, everyone if not a valid player
- name String name of the request
- ... Vararg data to pass to the callbacks
On the client
Sends a request to the server, where it is passed to the handlers registered with MVC.handler. Clientside variant.
MVC.push('SpawnMenu::GiveItem', PLAYER, item_obj.id, 1)
Parameters
- name String name of the request
- ... Vararg data to pass to the handlers
Defined in
Sends a request to the server and calls the handler once the server responds to it.
MVC.request('fl_create_character', function(response)
if response.success then
print('Character created!')
end
end, char_data)
Parameters
- name String name of the request
- handler Function receives the values of the response
- ... Vararg data to send with the request