x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Passing client set variable into Run on server RPC

Hey everyone, I've had this little thought that's been on my mind about RPCs. Is it a good idea to pass client set variables into a Run on Server RPC? Part of me says no because the client can then just pass in any value they want and the RPC will take it. But the other part of me isn't sure. Any opinions? Thanks!

Product Version: UE 4.12
Tags:
more ▼

asked Dec 27 '16 at 12:15 AM in C++ Programming

avatar image

RadiantWings
66 13 15 18

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Yes, you are exactly right. Sending in a value to an RPC and then just having the server accept that value will make your game prone to cheating. You have to remember that the client is capable of manipulating anything that the client has control of. In fact it is possible the client that is connected to your game might not even be UE4 (this is an extreme case, but is not impossible).

Here is an example to think about. Let's say that you are programming an attack action for your game where your player character swings a sword at an opponent.

A bad way to handle this would be to have the client swing the sword and see if it hits the enemy. Then if it does, send an RPC to update the health of the enemy. While this might give you the result you desire, it would be easy to cheat. I would hack this by just changing the number that is sent for the health in the RPC call to either a really large number or zero and then your game would be broken.

A better way to handle this would be to send an RPC call from the client to the server when the client presses the attack key. Then handle all of the collision checking and health deducting on the server side. If you do it this way, it is much harder for a player to cheat, since all they can cheat with is a key press, which is something they were allowed to do anyway (unless there are cooldowns, but you can check for that on the server when you validate their RPC request).

When it comes to RPC's in multiplayer games, think of them as requests to ASK the server to do something, instead of commands to tell the server what to do.

more ▼

answered Dec 27 '16 at 04:56 AM

avatar image

Dartanlla
2.6k 62 26 281

avatar image RadiantWings Dec 27 '16 at 06:32 PM

Okay good so now I know that what I'm doing for one of my functions is wrong. I've been trying to implement this movement ability which is pretty much like an aerial glide.

The way it was supposed to work was that the game would check for a boolean to see if the player was trying to do the glide and then it would set the velocity of the character to move in a certain direction for a period of time. The issue I was having was that I think the server was constantly correcting the client when I tried to activate the ability on the client's side.

I tried doing a server RPC without passing in any variables and it didn't work still, then when I passed in variables, it worked. But again that solution has some pretty major flaws. Do you happen to know the reason why my Server RPC without variables wasn't working. If you need more details I would glad to elaborate. Thanks!

avatar image Dartanlla Dec 27 '16 at 07:40 PM

RPC's do not have to have parameters to be replicated. But they do need to be set to "Run at Server" and in your case you want the "Reliable" checkbox checked. Also, the RPC call should be made from an Actor owned by a Player Controller (I am assuming you are using a class derived from ACharacter). I found out the hard way after a lot of frustration that RPC calls from un-owned actors do not replicate.

It sounds like you should be able to call a server side RPC from the client when the Glide key is pressed (or whatever other action starts a glide). Then on the client side, set the velocity of the character. Let the server side movement replicate back to the client. Don't set the velocity on the client side at all or they will fight like you noticed.

One of the things that there isn't a lot of documentation about is the network movement prediction system. This is part of the Character Movement component that comes as part of the Character class, but not the Pawn class. This always confuses a lot of people. The network prediction system is fairly complex and allows movement to be synched up between the server and the client in a way the appears smooth on the screen. However, it also means that if you try to move your character on the server and the client, you will often run into jittering or stuttering.

avatar image RadiantWings Dec 27 '16 at 08:16 PM

Yeah I was implementing the glide function within a custom CharacterMovementComponent after finding a guide on the UE4 Wiki. Had to do a few modifications but it was helpful. But it would be nice to get some official instructions from the UE4 devs just to make things clear.

Just to be sure though, in your second paragraph, you said "Then on the client side, set the velocity of the character." By that do you mean set the client's velocity within the server RPC? Or did I miss something?

avatar image Dartanlla Dec 27 '16 at 09:30 PM

Sorry that is a typo.

"Then on the client side, set the velocity of the character."

should be

Then on the server side, set the velocity of the character.

avatar image RadiantWings Dec 27 '16 at 10:26 PM

Oh alright that's good. I'll take what you said into consideration when I get back to the issue. Thanks a lot! Have a great new year!

EDIT: In case anyone else wants to chip in, feel free to comment on the post!

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question