LibRPC: Difference between revisions
(11 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
*[[LibRPC_F|F]] | *[[LibRPC_F|F]] | ||
*[[LibRPC_RFC|RFC]] (click to see more complicated examples) | *[[LibRPC_RFC|RFC]] (click to see more complicated examples) | ||
*[[LibRPC_Fa|Fa]] | |||
*[[LibRPC_RFCa|RFCa]] | |||
*[[LibRPC_Z|Z]] (get) | |||
*[[LibRPC_S|S]] (set) | |||
==ServerData Identifier== | ==ServerData Identifier== | ||
Line 287: | Line 291: | ||
|} | |} | ||
^All Offsets relative to respective type buffers. | ^All Offsets relative to respective type buffers. | ||
===More added since API 1.4=== | |||
===='E' type function ==== | |||
E type functions are same as F type function with the exception that roottable will be the environment for the latter where as in 'E' type functions, any table( or class/instance) can be passed as environment by specifying its name as first parameter. On remote side, the sq_get of function name is performed after pushing first parameter and then if the resultant object is function, it is called with 'first parameter' as env. | |||
{| class="wikitable" | |||
|- | |||
! Offset^ | |||
! Type | |||
! Value | |||
|- | |||
| 0 | |||
| Character | |||
| 'E' | |||
|- | |||
| 1-4 | |||
| Unsigned Integer | |||
| size of the function buffer | |||
|- | |||
| 5-6 | |||
| unsigned short | |||
| length of the function name | |||
|- | |||
| 7 - 7+len(funcname)-1 | |||
| characters | |||
| Function Name | |||
|- style="text-align:center;" | |||
| style="text-align:left;" | 7+len - ... | |||
| ... | |||
| ... | |||
|} | |||
====D type function==== | |||
This is same as G type function with the exception that custom environment can be passed to the function. | |||
{| class="wikitable" | |||
|- | |||
! Offset^ | |||
! Type | |||
! Value | |||
|- | |||
| 0 | |||
| Character | |||
| 'D' | |||
|- | |||
| 1-4 | |||
| Unsigned Integer | |||
| size of the buffer | |||
|- | |||
| 5 | |||
| Character | |||
| 'G'/ 'F'/ 'E' or 'D' | |||
|- style="text-align:center;" | |||
| ... | |||
| ... | |||
| ... | |||
|} | |||
^Offset relative to this buffer and not relative to ServerData ( complete buffer. ) | |||
===='g' structure==== | |||
Used for sq_get operation | |||
{| class="wikitable" | |||
|- | |||
! Offset^ | |||
! Type | |||
! Value | |||
|- | |||
| 0 | |||
| Character | |||
| 'g' | |||
|- | |||
| 1-4 | |||
| Unsigned Integer | |||
| size of the buffer | |||
|- style="text-align:center;" | |||
| ... | |||
| ... | |||
| ... | |||
|} | |||
===='h' structure==== | |||
Used for sq_set operation on remote vm. Unlike other structures, this one can be send independently with RPC_STREAM_IDENTIFIER | |||
{| class="wikitable" | |||
|- | |||
! Offset^ | |||
! Type | |||
! Value | |||
|- | |||
| 0 | |||
| Character | |||
| 'h' | |||
|- | |||
| 1-4 | |||
| Unsigned Integer | |||
| size of the buffer | |||
|- style="text-align:center;" | |||
| ... | |||
| ... | |||
| ... | |||
|} | |||
==API Version== | ==API Version== | ||
1. | 1.4 (June 2023) | ||
==Downloads== | ==Downloads== | ||
These are old versions(1.2). New ones are available with npcclient. | |||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
Line 322: | Line 423: | ||
| 1.2 | | 1.2 | ||
|} | |} | ||
==See Also== | |||
*[[LibRPC_Examples|Examples]] |
Latest revision as of 10:44, 1 July 2023
Library used to execute functions or script send from server. For remotely executing functions of npcscripts from server, see function RFC available with plugin npc04relxx. For executing functions of server from npcscripts, continue reading.
Calling Functions of VCMP Server
From v1.6 beta 4 and rpclib(API 1.2) onwards, npc can remotely execute functions of server, provided the server runs squirrel gamemode and player.IsAdmin=true
for npc.
//npcscripts RFC("SetWeather")(5); RFC("SetHour")(12); RFC("SetDriveOnWater")(true);
The following functions are added to npcscripts:
ServerData Identifier
LibRPC when loaded works on server data whose first four bytes is the following:
Offset | Type | Value |
---|---|---|
0 | Integer | 0x40000000 |
ServerData structure
Offset | Type | Value | |
---|---|---|---|
4 | Character | 'F' or 'G' | Function |
Function structure
'F' type function
print(500)
F type functions are those functions to be called through a name, ( unlike to be called through other methods see 'G' type functions ). The function name is encoded from offset 7.
Offset^ | Type | Value |
---|---|---|
0 | Character | 'F' |
1-4 | Unsigned Integer | size of the function buffer |
5-6 | unsigned short | length of the function name |
7 - 7+len(funcname)-1 | characters | Function Name |
7+len - ... | ... | ... |
^Offset relative to this buffer and not relative to ServerData ( complete buffer. )
'G' type function
compilestring("print(500)")() //--second order
G type functions (The name G because character F already taken ). They are functions returned by another function. So the buffer of the G type function contain another function which is first called and its return value, if it is a function, is then called. They can be said to be second order functions.
Offset^ | Type | Value |
---|---|---|
0 | Character | 'G' |
1-4 | Unsigned Integer | size of the buffer |
5 | Character | 'G' or 'F' |
... | ... | ... |
^Offset relative to 'G' function buffer and not relative to complete buffer of ServerData. Functions of higher order can be called through this method.
Example
Offset | Value | Explanation |
---|---|---|
0-3 | 00 00 00 40 |
0x40000000 |
4 | 46 | F |
5-8 | 00 00 00 0f | len of func buffer |
9-10 | 00 05 | len of func name (11-15) |
11-15 | 70 72 69 6e 74 | p r i n t |
16 | 73 | s (for string) |
17 | 00 05 | len of string (19-23) |
19-23 | 48 65 6c 6c 6f | H e l l o |
Other structures
String
Offset^ | Type | Value |
---|---|---|
0 | char | 's' |
1-2 | unsigned short | len of string |
3 - 3+len of string-1 | char sequence | the string |
Integers
Offset^ | Type | Value |
---|---|---|
0 | char | 'i' |
1-4 | int | integer |
Float
Offset^ | Type | Value |
---|---|---|
0 | char | 'f' |
1-4 | float | floating point number |
null
Offset^ | Type | Value |
---|---|---|
0 | char | 'o' |
bool
Offset^ | Type | Value |
---|---|---|
0 | char | 'b' |
1 | unsigned char | 0 or 1 |
Vector
Offset^ | Type | Value |
---|---|---|
0 | char | 'v' |
1-4 | float | Vector.x |
5-8 | float | Vector.y |
9-12 | float | Vector.z |
Quaternion
Offset^ | Type | Value |
---|---|---|
0 | char | 'q' |
1-4 | float | Quaternion.x |
5-8 | float | Quaternion.y |
9-12 | float | Quaternion.z |
13-16 | float | Quaternion.w |
Arrays
Offset^ | Type | Value |
---|---|---|
0 | char | 'a' |
1-4 | unsigned int | length of the array stream |
5 | char | ... |
^All Offsets relative to respective type buffers.
More added since API 1.4
'E' type function
E type functions are same as F type function with the exception that roottable will be the environment for the latter where as in 'E' type functions, any table( or class/instance) can be passed as environment by specifying its name as first parameter. On remote side, the sq_get of function name is performed after pushing first parameter and then if the resultant object is function, it is called with 'first parameter' as env.
Offset^ | Type | Value |
---|---|---|
0 | Character | 'E' |
1-4 | Unsigned Integer | size of the function buffer |
5-6 | unsigned short | length of the function name |
7 - 7+len(funcname)-1 | characters | Function Name |
7+len - ... | ... | ... |
D type function
This is same as G type function with the exception that custom environment can be passed to the function.
Offset^ | Type | Value |
---|---|---|
0 | Character | 'D' |
1-4 | Unsigned Integer | size of the buffer |
5 | Character | 'G'/ 'F'/ 'E' or 'D' |
... | ... | ... |
^Offset relative to this buffer and not relative to ServerData ( complete buffer. )
'g' structure
Used for sq_get operation
Offset^ | Type | Value |
---|---|---|
0 | Character | 'g' |
1-4 | Unsigned Integer | size of the buffer |
... | ... | ... |
'h' structure
Used for sq_set operation on remote vm. Unlike other structures, this one can be send independently with RPC_STREAM_IDENTIFIER
Offset^ | Type | Value |
---|---|---|
0 | Character | 'h' |
1-4 | Unsigned Integer | size of the buffer |
... | ... | ... |
API Version
1.4 (June 2023)
Downloads
These are old versions(1.2). New ones are available with npcclient.
Operating system | bit | Link | Size | API |
---|---|---|---|---|
Windows | rpclib.dll | 16 KB | 1.2 | |
Linux | x64 | rpclib64.so | 25.58 KB | 1.2 |
Linux | x86 | rpclib32.so | 24.46 KB | 1.2 |
Source | - | LibRPC-master.zip | 18.65 KB | 1.2 |