A WebSocket-based programming interface for FiveM.
- Execute Native functions
- Call local and client events
- Register local and network events
- Register commands
- Execute code
- Function callbacks
- AES-256-CFB Encryption
- Clone this repository into your server's resources directory.
git clone https://github.com/ZeroDream-CN/zerodream_nativeapi
- Edit the
zerodream_nativeapi/config.js
file to set your AES key and IV (the key must be 32 characters, and the IV must be 16 characters).
var Config = {
LISTEN_HOST: '0.0.0.0',
LISTEN_PORT: 38080,
KEY: '0123456789abcdef0123456789abcdef', // <- Change this
IV: 'abcdef9876543210', // <- Also this
- Add the following to your
server.cfg
file.
ensure zerodream_nativeapi
- Restart your server.
Basic usage, not real code, you need to implement it yourself.
let host = '127.0.0.1';
let port = 38080;
let key = '0123456789abcdef0123456789abcdef';
let iv = 'abcdef9876543210';
let wsc = new WebSocketClient( host, port );
let aes = new AES( 'aes-256-cfb', key, iv );
let uuid = uuid();
let jsonText = JSON.stringify({
action: 'YOUR_ACTION',
data: 'YOUR_DATA',
eid: uuid
});
let encrypted = aes.encrypt( jsonText );
wsc.send( encrypted );
Server API
Authenticate the client
action | data |
---|---|
auth | (Map) { auth: 'any text' } |
Execute a server side native with arguments
action | data |
---|---|
executeNative | (Map) { name: 'NativeName', args: [ arg1, arg2, ... ] } |
Trigger a server side event with arguments
action | data |
---|---|
triggerEvent | (Map) { name: 'EventName', args: [ arg1, arg2, ... ] } |
Trigger a client side event with arguments
action | data |
---|---|
triggerClientEvent | (Map) { name: 'ClientEventName', args: [ arg1, arg2, ... ] } |
Register a server internal event
action | data |
---|---|
registerEvent | (Map) { name: 'EventName' } |
Register a network event
action | data |
---|---|
registerServerEvent | (Map) { name: 'ServerEventName' } |
Register a server side command
action | data |
---|---|
registerCommand | (Map) { name: 'CommandName', restricted: true/false } |
Evaluate JavaScript code on the server
action | data |
---|---|
eval | (Map) { code: 'JavaScriptCode' } |
Call a registered server side function with arguments
action | data |
---|---|
callFunction | (Map) { id: 'FunctionId', args: [ arg1, arg2, ... ] } |
This project is open-sourced under the MIT license.