Initially I was thinking that there would be some sort of timer on the server that would periodically query for all the users and update their credits total. But this has some problems:
race conditions could happen. While we are updating the totals, a region might be transferred from one user to another, leading to problems
We can only query 1000 users at a time. There is a datastore limitation that restricts query result size.
Fortunately, I thought of a clever solution. Whenever a user is accessed or a region transfers from one user to another, we will at that time update the credits based on the users current locations (that existed since last access) and the previous time updated. The amount to increment will be the incomes for all regions owned times the number of elapsed time periods. We can even do a fractional time period so the bookkeeping is precise.
Initially I was thinking that there would be some sort of timer on the server that would periodically query for all the users and update their credits total. But this has some problems:
Fortunately, I thought of a clever solution. Whenever a user is accessed or a region transfers from one user to another, we will at that time update the credits based on the users current locations (that existed since last access) and the previous time updated. The amount to increment will be the incomes for all regions owned times the number of elapsed time periods. We can even do a fractional time period so the bookkeeping is precise.