[Tutorial] RPC - Pawn.RakNet
#1

• Introduction
I'll be explaining what RPCs are and providing their parameters and IDs for use, including some example at the end of the topic.

Some RPCs have the same parameters as the function they are usually related to, while others don't, making their usage complicated.
• What RPC stands for?
RPC is an acronym for Remote Procedure Call, a protocol used to request a service from a client located on another computer on a network without having to understand the details of the network. As you already know, SA-MP uses RakNet network engine.

Say you exploded a player. The server will send an RPC (0x47 - RPC_CreateExplosion) to the client, requesting that explosion to be created.

The client also sends remote procedure calls back. Let's say you entered a vehicle, your client will send an incoming RPC to the server, informing that event (RPC_EnterVehicle).

RPC Types:
-Outcoming RPCs: RPCs sent by the server to the client.
-Incoming RPCs: RPCs sent by the client to the server.
Priorities:
-SYSTEM_PRIORITY: Internal Used by RakNet to send above-high priority messages.

-HIGH_PRIORITY: High priority messages are sent before medium priority messages.

-MEDIUM_PRIORITY: Medium priority messages are sent before low priority messages.

-LOW_PRIORITY: Low priority messages are only sent when no other messages are waiting.
Reliabilities:
-RELIABLE_SEQUENCED: Reliable sequenced packets are UDP packets monitored by a reliability layer to ensure they arrive at the destination and are sequenced at the destination.
Advantages - You get the reliability of UDP packets, the ordering of ordered packets, yet don't have to wait for old packets. More packets will arrive with this method than with the unreliable sequenced method, and they will be distributed more evenly. The most important advantage however is that the latest packet sent will arrive, where with unreliable sequenced the latest packet sent may not arrive.
Disadvantages - Wasteful of bandwidth because it uses the overhead of reliable UDP packets to ensure late packets arrive that just get ignored anyway.

-RELIABLE_ORDERED: Reliable ordered packets are UDP packets monitored by a reliability layer to ensure they arrive at the destination and are ordered at the destination. Advantages - The packet will get there and in the order it was sent. These are by far the easiest to program for because you don't have to worry about strange behavior due to out of order or lost packets.
Disadvantages - Retransmissions and acknowledgments can add significant bandwidth requirements. Packets may arrive very late if the network is busy. One late packet can delay many packets that arrived sooner, resulting in significant lag spikes. However, this disadvantage can be mitigated by the clever use of ordering streams.

-RELIABLE: Reliable packets are UDP packets monitored by a reliablilty layer to ensure they arrive at the destination.
Advantages - You know the packet will get there. Eventually...
Disadvantages - Retransmissions and acknowledgments can add significant bandwidth requirements. Packets may arrive very late if the network is busy. No packet ordering.

-UNRELIABLE_SEQUENCED: Unreliable sequenced packets are the same as unreliable packets, except that only the newest packet is ever accepted. Older packets are ignored. Advantages - Same low overhead as unreliable packets, and you don't have to worry about older packets changing your data to old values.
Disadvantages - A LOT of packets will be dropped since they may never arrive because of UDP and may be dropped even when they do arrive. These packets are the first to get dropped if the send buffer is full. The last packet sent may never arrive, which can be a problem if you stop sending packets at some particular point.

-UNRELIABLE: Unreliable packets are sent by straight UDP. They may arrive out of order, or not at all. This is best for data that is unimportant, or data that you send very frequently so even if some packets are missed newer packets will compensate.
Advantages - These packets don't need to be acknowledged by the network, saving the size of a UDP header in acknowledgment (about 50 bytes or so). The savings can really add up.
Disadvantages - No packet ordering, packets may never arrive, these packets are the first to get dropped if the send buffer is full.
• Examples
RPC_ShowActor
ID: 171
Parameters: WORD wActorID, DWORD dSkinID, float x, float y, float z, float angle, float health

Plugin (Example taken from my YSF fork)
PHP Code:
RakNet::BitStream bs;
bs.Write((WORD)5); //Actor ID.
bs.Write((DWORD)287); //The actor's skin ID.
bs.Write((float)0.0); //X.
bs.Write((float)0.0); //Y.
bs.Write((float)0.0); //Z.
bs.Write((float)50.0); //Angle.
bs.Write((float)100.0); //Actor's Health.
pRakServer->RPC(&RPC_ShowActor, &bsLOW_PRIORITYRELIABLE_ORDERED0pRakServer->GetPlayerIDFromIndex(23), 00); 
&RPC_ShowActor: Integer with the RPC id.
&bs: Contains the data written above (packed bits).
LOW_PRIORITY: RPC's priority.
RELIABLE_ORDERED: RPC's reliablity.
pRakServer->GetPlayerIDFromIndex(23): The player about to receive the RPC.
Pawn.RakNet
PHP Code:
new BitStream:bs BS_New();
BS_WriteValue(
    
bs,
    
PR_UINT165//Actor ID.
    
PR_UINT32287//The actor's skin ID.
    
PR_FLOAT0.0//X.
    
PR_FLOAT0.0//Y.
    
PR_FLOAT0.0//Z.
    
PR_FLOAT50.0//Angle.
    
PR_FLOAT100.0 //Actor's Health.
);
BS_RPC(bs23171PR_LOW_PRIORITYPR_RELIABLE_ORDERED);
BS_Delete(bs); 
bs: BitStream with the data above (packed bits).
23: The player about to receive the RPC.
171: RPC_ShowActor's ID.
PR_LOW_PRIORITY: RPC's priority.
PR_RELIABLE_ORDERED: RPC's reliability
• RPC List with parameters
Github

The list isn't entirely done, but has a considerable amount of RPCs with proper information.
Reply


Messages In This Thread
RPC - Pawn.RakNet - by Jelly23 - 15.11.2017, 14:26
Re: RPC - Pawn.RakNet - by Zeth - 15.11.2017, 14:34
Re: RPC - Pawn.RakNet - by StrikerZ - 15.11.2017, 14:35
Re: RPC - Pawn.RakNet - by HydraHumza - 15.11.2017, 14:45
Re: RPC - Pawn.RakNet - by DeitY - 15.11.2017, 16:47
Re: RPC - Pawn.RakNet - by Logic_ - 15.11.2017, 17:15
Re: RPC - Pawn.RakNet - by Eoussama - 15.11.2017, 18:42
Re: RPC - Pawn.RakNet - by RIDE2DAY - 15.11.2017, 19:52
Re: RPC - Pawn.RakNet - by Jelly23 - 18.11.2017, 17:04
Re: RPC - Pawn.RakNet - by Dayrion - 18.11.2017, 20:10
Re: RPC - Pawn.RakNet - by Jelly23 - 19.11.2017, 14:41
Re: RPC - Pawn.RakNet - by Marllun - 20.11.2017, 13:51
Re: RPC - Pawn.RakNet - by Dayrion - 20.11.2017, 14:08
Re: RPC - Pawn.RakNet - by Jelly23 - 20.11.2017, 15:43
Re: RPC - Pawn.RakNet - by TiW - 20.11.2017, 15:46
Re: RPC - Pawn.RakNet - by Jelly23 - 20.11.2017, 15:51
Re: RPC - Pawn.RakNet - by Dayrion - 20.11.2017, 22:26
Re: RPC - Pawn.RakNet - by Manyula - 24.11.2017, 21:16
Re: RPC - Pawn.RakNet - by Jelly23 - 28.11.2017, 20:38
Re: RPC - Pawn.RakNet - by Marllun - 02.12.2017, 14:27
Re: RPC - Pawn.RakNet - by Aliassassin123456 - 09.12.2017, 06:20
Re: RPC - Pawn.RakNet - by Jelly23 - 13.12.2017, 21:51
Re: RPC - Pawn.RakNet - by PRoleplay - 05.05.2020, 16:24
Re: RPC - Pawn.RakNet - by JasonTheMan - 12.05.2020, 08:57

Forum Jump:


Users browsing this thread: 1 Guest(s)