That is a lot of questions.
It’s best to make everything happens on server and then just replicate to clients right?
When possible yes.
The player controller represents the client, and the game state the server?
Yes the player controller represents a client. It works exactly like a console controller giving the client a way to send input “privately” to the server without interference from other players. The server can also privately send information back to the individual clients.
The Game State is where the server communicates events to all clients mostly originating from the GameMode which only exists on the server.
I once read that the less you let the client do things on its own, harder it is to hack or cheat on the game, is this true?
Yes every time you allow a client to do something on the server the server has to validate that the client isn’t trying to cheat, however avoiding cheaters can only be done when you deploy a dedicated server since you can’t trust a player host.
If so, how do I make this happen if the player controller can’t cast to game mode?
Server-side PlayerController can “get” and cast to the GameMode but GameMode should only be used for changes within the overall state of the game. Validation can happen anywhere server-side.
If I choose to replicate the event from server to clients (multicast), even if the event itself is on the player controller, I’m I protecting the game from hackers?
No. Protection from hackers is purely done by the server validating the input from the clients. If the input doesn’t make sense the server can decide to kick the player. Note that a Multicast RPC on a PlayerController is pointless since each client only have access to their own PlayerController.
On the multicast type of replication what does it means that the server will execute the event locally too, isn’t the server only hosting the game?
Yes the server is hosting the game which means it is keeping track of everything to keep itself updated. A dedicated server doesn’t of course run any graphical, audio or input events, it just serves the clients.
Whats does the “Reliable” bool does?
If an event never reaches the client (if Multicast) and it is set to reliable it will retry until the client gets the event. Before you go and make every event Reliable just note that a lot of events can safely be dropped to help the server recover from network congestion. If you make everything Reliable nothing can be dropped and the network congestion could get a lot worse and frequent.
I’ve been testing some stuff, and when I run the game on editor, running a dedicated server, with more than one player, it seems to only spawn one player controller, I mean I can only see one on the world Outliner , even thought multiple player states appear, shouldn’t also appear one player controller for each player?
Each client only see their own PlayerController. The server see all PlayerControllers. If you make a Multicast RPC on a PlayerController only the owning client will get the event.
How do I define what is the server and what is the client, so that I can execute the server on my server machine, and let it running, and then distribute only the client to the players?
You need the source code from github and build the editor first using Visual Studio or something else. You can’t build a dedicated server or client only with an installed engine and Blueprint. Then you can package a dedicated server and a client build separately.
How to make a lobby for player looking for a match wait for the minimum amount of players required?
This can be done by 3. party plugins like Steam where a Matchmaking server is responsible for handling lobbies and/or matching players. The plugin then returns a server/host IP and Port for the players to join.
Any other tips or things that I should know?
Making a multiplayer game is harder than you might initially think. If you have made a single player game you can probably multiply the difficulty of every feature you develop by 5 when making it multiplayer. Guessing how things work is the road to disaster, you need to make a deep dive into how things actually work or you will be debugging your life away.