1

I was wondering how a real time browser game work like ogame?

How do you constantly update stuff like resources?

My only suggestion is having a computer turned on 24-7 but that can't be it.

NicklasF
  • 863
  • 3
  • 10
  • 26
  • 1
    Servers run 24x7 of course. – Barmar Apr 03 '15 at 20:30
  • 2
    `My only suggestion is having a computer turned on 24-7 but that can't be it. ` That's how every website works. Where do you think all the resources for any website come from? – Sam I am says Reinstate Monica Apr 03 '15 at 20:31
  • ^- regarding the comments above: Of course the client computer viewing the website doesn't usually run 24/7, and doesn't need to. However, the website is provided (well, it has to come from somewhere right?) by one or multiple server machines, which do generally run 24/7. – Cubic Apr 03 '15 at 20:35

2 Answers2

2

Usually, while people are not interacting with a game, they have pretty steady flow of resources. So between events that change this flow you don't need to update amounts, but calculate it instead.

For example. Suppose in some game there is a stone resource. Player starts with 0 stones and is able to build stone quarry that will produce 1 stone per hour, which then can be upgraded to say level 2 so it can produce 2 stones per hour. Initially, we know that player does not have stone quarry so his stone income is 0 per hour. Then player builds stone quarry and we make following log entry:

at time T0 player P build stone quarry. He had 0 stones at that moment and stone income is now 1 stone per hour.

Starting from this moment, if nothing happens we can simply calculate the amount of stones at any moment, we don't need to keep it updated.

If player spends stones on something we add following log entry:

at time T1 player P spent X stones on <something>. He now has S1 stones and stone income is 1 stone per hour.

again after that we have full information for calculating number of stones at any moment even if our servers crash (assuming logs are hardened in some way)

then player upgrades stone quarry:

at time T2 player P upgraded stone quarry to level 2. He had S2 stones at that moment and stone income is now 2 stones per hour.

So the idea is to log timestamp, resource amount and resource income rate whenever amount or income changes. Then you would have all the data to calculate amount of resource at any point of time in future.

n0rd
  • 11,850
  • 5
  • 35
  • 56
1

One possible situation:
There is a http server (24x7 of course!) and some web sockets between the server and the clients, any changes are immediately sent through the sockets to the clients, so the page updates quickly.
Nothing strange is happening actually.

Hamid Mohayeji
  • 3,977
  • 3
  • 43
  • 55