Meteor Reactive Server Variable

Hi All, I have a space game. I need to:

  • Scan every player, 7,000 records
  • See if their shields need to increase as they’ve taken damage, and update their health

Seems simple right? But I want this to run while the user is AFK and computer offline. This all has to be done on the server.

Right now, I have a Meteor.SetInterval( find.("all_starships)) and process that data, but it is not scalable.

So I’d like to at startup, load a reactive variable in to memory on the server. Then, when someones shields change as they’ve taken damage, I will be able to take an action on that paticular player.

How can this be achieved?

Many ways to do it I suppose.

The less bad way: query only players with shields “$lt” whatever max is, like shields: { $lt: 100 }.

Efficient but more difficult way: don’t update players who are not online. Update players when they get online, making up for the “missing updates”.

Ideally, you don’t do any of these interval things. They won’t “scale” no matter what. You can be clever when you have a start time, start shield amount and the shield increase rate, and fake the updates on the client side. Only calculate the actual value when something happens, like an attack.

1 Like

This is what the players love about my game though.

But, players may be attacked while offline in un-safe zones in an ever persistent state. So, in your case, this will not work. What would you suggest?

You fake it for all players looking. Say I am looking at your ship. I see that last time you were updated you looked like this:

shields: 50
shieldUpdateRate: +1 / h
timeUpdated: 31/3/2019-21:20

So, my client then calculates what your current shield is showing 52 for example, which updates every hour on my client as well (regularly re-render this). If I decide to attack you, your actual shield is calculated server side, then subtracted with my attack.

Get where I am going with this roughly?

Okay, so let’s say the users starship is now destroyed. How do I send a notification to that user?

It would be bad practise to have a client send a signal to the server to do a calculation, wouldn’t it? To confirm the player really is dead, and send an email “You’ve died”?

Wouldn’t the damage and/or destruction be in response to an attack?
You could use that as the cue to update shield/health and notify a user