SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Tutorials (https://forum.sa-mp.com/forumdisplay.php?f=70)
-   -   [Tutorial] RPC - Pawn.RakNet (https://forum.sa-mp.com/showthread.php?t=644857)

Jelly23 15/11/2017 02:26 PM

RPC - Pawn.RakNet
 
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.

Zeth 15/11/2017 02:34 PM

Re: RPC - Pawn.RakNet
 
Finally People out there gonna understand the usage of Pawn.Raknet!

StrikerZ 15/11/2017 02:35 PM

Re: RPC - Pawn.RakNet
 
Didn't knew about that, thanks for the kind info Jelly.

HydraHumza 15/11/2017 02:45 PM

Re: RPC - Pawn.RakNet
 
Quote:

Originally Posted by Sunehildeep (Post 3955791)
Didn't knew about that, thanks for the kind info Jelly.

know*

O.T Great tutorial very useful information.

DeitY 15/11/2017 04:47 PM

Re: RPC - Pawn.RakNet
 
GOD OF PAWNO

Logic_ 15/11/2017 05:15 PM

Re: RPC - Pawn.RakNet
 
My man back on the game! Welcome back Jelly.

Eoussama 15/11/2017 06:42 PM

Re: RPC - Pawn.RakNet
 
Yes, I was waiting for a tutorial like this, thanks a lot!
+REP.

RIDE2DAY 15/11/2017 07:52 PM

Re: RPC - Pawn.RakNet
 
You wrote some nice stuff there, I hope you'll translate the second part also. These guides are very useful.

Jelly23 18/11/2017 05:04 PM

Re: RPC - Pawn.RakNet
 
Will be updating the RPC list soon.

Dayrion 18/11/2017 08:10 PM

Re: RPC - Pawn.RakNet
 
Very nice.
Can you provide more details when we should do that or that in which circunstances. I mean, let's take messages priorities. In your example, why do you set to PR_LOW_PRIORITY? Isn't important to renew the actor when a player see it? Or I missunderstood something? :x


All times are GMT. The time now is 03:26 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.