LibRPC: Difference between revisions

From NPC for VCMP 0.4 Servers
Jump to navigation Jump to search
No edit summary
Line 322: Line 322:
| 1.2
| 1.2
|}
|}
==See Also==
*[[LibRPC_Examples|Examples]]

Revision as of 23:52, 7 June 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:

  • F
  • RFC (click to see more complicated examples)

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.

API Version

1.2

Downloads

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

See Also