Beguinner questions on runtime code and basic questions of how networks work

Hey, I’m very new to all things networking. I have some questions about how I should do some things.

To give some context, the project I’m working on is server-authoritative, where almost all the logic is computed on the server. Using Godot Engine. I’m going to describe what would be a “short game” against a bot.

First the client receives information about an enemy (which enemy it is and its stats). And now I want to do damage to him, so I send a signal that I have pressed the attack button and the server takes care of subtracting the enemy’s life and send me his update.

Here appears my first doubt, how can I create an AI inside the server? I need the server to create games and match a player with a bot. Where would I program the bot? What would happen if there were several players against several different bots each in their own sessions? How do I create parallel processes for each of the sessions?

I have seen that all this logic can be done through typescript, but is that (adding the files to the nakama modules) how it should be done? Or should I create a server with the godot headless that takes care of all that?

Another simpler question is, if I first register the user with the Device ID, and inside the game I create an option to link that Device ID with an Email+Password. There shouldn’t be any problem, right? (Giving preference to the email if there is another new device?)

And another question about performance, with the basic setup of nakama + docker. When would the database reads start to slow down? (requests per minute?) And does it take the same time to send a short json fragment than a much longer one?

Sorry if this is a lot of questions, I really can’t find many resources that talk about these topics and I thought I’d ask through here. Thanks for reading everything!

Hi @MaximoTG98 welcome :wave:

I’ll try and answer your questions in order as best I can.

so I send a signal that I have pressed the attack button and the server takes care of subtracting the enemy’s life and send me his update.

In most multiplayer netcode this is usually called a “command message” and is common to most games.

Here appears my first doubt, how can I create an AI inside the server? I need the server to create games and match a player with a bot. Where would I program the bot?

This depends on the complexity of your bot logic. I’ll assume your bot logic is to look at the opponents (real player) health and determine based on some rules the best counter attack to make to the opponent. This code would be written inside the authoritative multiplayer engine as part of the match handler logic and can be written in Lua, Go, TypeScript, or JavaScript. Have a look at the authoritative multiplayer engine docs here: Authoritative Multiplayer - Nakama server

What would happen if there were several players against several different bots each in their own sessions? How do I create parallel processes for each of the sessions?

You would create separate matches for each player who plays against the bot opponent. You can create bot logic which is as complex as you want (ideally to simulate as much as possible a real opponent who would make decisions).

I have seen that all this logic can be done through typescript, but is that (adding the files to the nakama modules) how it should be done? Or should I create a server with the godot headless that takes care of all that?

I would avoid coordinating with a Godot headless instance unless you really need the physics engine in Godot to form part of the logic used to express the bot behaviour. This depends on the game but is often not needed.

There shouldn’t be any problem, right? (Giving preference to the email if there is another new device?)

You can definitely authenticate with device ID and link an email account or other social providers to that user account later. These additional “links” become other ways for the user to log back into the game.

And another question about performance, with the basic setup of nakama + docker. When would the database reads start to slow down? (requests per minute?)

This is a huge topic to try and ask about with some questions. The only answer I can give is to ask you more questions:

  • How much hardware would you give to the game server and the database server?
  • Would you run both the database server and game server on the same physical hardware? (This is not ideal because they will compete for system resources).
  • What disk IOPS have you allocated to the database server to give it the IO performance needed to keep up with your usage?

And does it take the same time to send a short json fragment than a much longer one?

It can’t possibly take the same amount of time to send a larger input payload as a smaller one because you simply are sending more data over the network. It may take a negligible difference in time (msec) but there’s no way there could be no difference in time because this is just how the internet works.

I can help with other questions you have as follow up but its best to try and scope the questions to specific topics because otherwise it’s too vague to give detailed responses on. Hope this helps.