Networking Code Design. Who knows about User Input? Server/client code sharing.

Lately I’ve been working on some very basic game code.

I’m designing it to be a networked game from the beginning on. The problem I currently have is the question: Where does the User input information belong?

Let’s assume we have a server and two clients. Both clients have player entities which exist on the server and all clients.

When client 1 presses a key, it sends it to the server. Should the server send it to the other client?

Also, my question is also a little about code design.
I want to have the same code running on the server and both clients. But when I have my PlayerEntity, it expects Mouse input. But on client 1 I have both PlayerEntities from both clients, and it only has mouse input for one of them - the Player they are actually ment to play.

A possible solution I thought of was this: Every client already has a unique connection ID. Whenever a client creates an entity, the entity will be dedicated to a connection ID, if it needs to have specific client input, or not, when it’s an enemy for example (spawned by the server).
The client sends it’s input to the server and the server sends Input Deltas in the form of: Connection ID -> Mouse Input. All clients know of the inputs of all other clients and therefore they can even predict the movement of a player.

My actual question is: How would you solve it? How did you solve it? How do AAA games solve this problem?

Have you even had this problem?

… I could continue forever ::slight_smile: