C++ Server - Architecture Questions

I am working on a C++ server. I already implemented some stuff as you can see below.
I am not using anything from unet.

The sending rate of my scripts in this video is set to 9.
https://gfycat.com/gifs/detail/CheapRegalConch

However, I am starting to code the nonplayer stuff. I have multiple questions. I would like to get some advice, like good practices, what should I do to easily scale my server, etc.

It is obvious that the server will be responsible to define where and when to spawn the nonplayers characters (monsters, etc.), however, how should I control the behavior of the NPC after spawned?

I thought something like:

  1. During the first time running the server, I would have to transfer to the server a bunch of data for each NPC.
  2. For that, I would make a separated build responsible to export in SQL the data of each NPC (location, id, slug, etc.).
  3. Based on that I would create the database of the server, and the server would know each NPC to control.
  4. I would send this information to the player when necessary, e.g., in range, other stuff, etc.

Here is the problem, after I detect each NPC and when to send, how could I control the behavior of the NPC? I mean, the server will not have access to the update method of the unity object.
In this way, one option would be:
5. All info of the NPC are registered in the server, started and then put to sleep.
6. When a condition related to the function that sends that information to the player is satisfied, the server sends to the player an action to instantiate the monster, and after that, this player would synchronize this monster actions with the server, and the server to the others.
7. When the monster dies, the server waits for the respawn time and return to state 5.

Another question, how could I implement something easy to sync variables?

I would appreciate some advice.
Thanks,
Willian

If your game is deterministic you can send the client a packet that says “NPC1, walk to the bathroom and take 10 seconds to do it” and that one tiny packet is enough. (like how Starcraft 2 only has to send where you clicked when a unit is moved, not every step of the way)

If the server detects anything that changes the situation (being hit, hearing a gunshot, etc) it should send new directions to the clients. The client can get the updated current position for the NPC (and smoothly lerp to it to avoid a visual glitch) as well as set the new action.

It’s possible to use a deterministic random number generator with a custom seed so your client and server can do “random” NPC behavior without wasting data on packets (like, he’ll randomly stop and look around on both machines) but due to sync issues it’s probably easier to just have the server do all the NPC thinking and send updates when something happens (like dies, or respawns), guess it depends on your project.