Nakama server maintenance mode

Hi, I’m creating a mobile game (strategy, like clash of clans), and at one point encountered, that I need to create a maintenance mode for my game. I’ve looked for ‘cron’ implementation in nakama, but there really isn’t. In documentation I can find about ‘after hooks’, but I do want to implement some ‘cron’ functionality for such not scaling from user count features as, how I mentioned before ‘maintenance’ mode (server selects all scheduled maintenances and checks whether it’s start time one of them, if it is, then server gently kicks players out and sets the ‘maintenance_status’ value in nakama local storage to ‘true’. So in ‘after login hook’ function checks that ‘maintenance_status’, if it’s ‘true’ - than connection will be restricted and declined. So it is not player quantity scalable feature so ‘cron’ approach will be ok there) or resupply restricted amount of game resources (for example if there are restricted resources on map and game server must one time an hour restart them so there will not be run out of them). So I already had my custom admin panel for nakama, because I can’t find a way to make some changes in original nakama admin panel, so I can add any feature that in my opinion should have UI my custom admin panel, for example custom SQL query constructor, or maintenance creator, so I can schedule maintenances and control them with UI instead of just console and begging for gods sake. So this custom admin panel is just API with views so I implemented cron there, and this API waits for an hour and calls checkMaintenanceBreakRpc from nakama every hour. What do you think about that approach?)

Hello @DoniShon,

Your post is a bit difficult to read, next time please try to break it out into smaller paragraphs.

Nakama does not have scheduled tasks built in, your approach of using an external CRON and invoking a custom RPC is what we recommend for running some tasks.

We’re considering adding a Nakama Console page where you could run some custom SQL in the future but we don’t have a timeline yet.

As part of your custom RPC, if you want to logout users you should call SessionLogout without the token and refreshToken params to invalidate all session tokens (so they’ll need to reauthenticate). If your game is using socket connections, you’ll also need to disconnect them, you have two options:

  1. Use streams to go over all connected users, and call sessionDisconnect for each session ID.
  2. Use the notifications API to send a message to the clients which will prompt them to disconnect themselves.

Your login hook that prevents users from authenticating should be done in a before-hook, not the after-hook.

Hope this helps.