8 Replies - 3041 Views - Last Post: 16 November 2011 - 03:13 AM

Where to put the server timers

Posted 15 November 2011 - 07:35 AM

Hello all,

I am still a novice in MVC ASP.Net development, but just to give you an idea of what I'm trying to build for learning purposes and more is a text-based browser game.
The problem I have is that I'm trying to make more sense out of the background architecture, and where should go what.

Quick example:
- Player A starts production of Barracks.
- Javascript shows Player A production is in order.
- C# server code handles the requests and creates a timer object
- When the timer hits 0 (on server? or console?) the function would be called to set Barracks boolean to true in the database.

This is a rough scetch and I would appreciate if people can tell me if what I think is right.
However, I also thought I had to write a console application too which, will accept a timer request and handle it in a console rather than the actual website, or am I really confused now?

Any help is much appreciated! I have been strugling with understanding websites under the hood.
John.

Replies To: Where to put the server timers

Re: Where to put the server timers

You could use a timer of some sort; but I wouldn't. Rather, each resource has a construction start and end time. If the time is past the end time, it's done.

When the browser asks the server about the resource, it just gives the current state based on current time.

So:
- Player A starts production of Barracks.
-- A record for the production of a barracks is created. Done.
- Javascript shows Player A production is in order.
-- A request on the status of barracks from the server. The status of objects is based on server time.
- C# server code handles the requests and creates a timer object
-- Server code handles requests, but there are no timers
- When the timer hits 0 (on server? or console?) the function would be called to set Barracks boolean to true in the database.
-- Leave the database alone. It already has a perfectly good barracks entry

What you might do is have a list of user notifications. If the user was never told that the barracks was finished, and it is, let them know about it and record that you did so you don't keep telling them the same thing.

Re: Where to put the server timers

Posted 15 November 2011 - 08:24 AM

I can see how your approach would work on offline gameplay, but if let's say.. you have to execute a command at end-time, to calculate a new rank within the multiplayer world, or save your Barrack's level to the DB.
(The boolean was a bad example of me sorry, Rank would fit better, wouldn't this be stored?)

And if I were to apply your method, where would all those requests be saved?
Could they actually be saved on 1 server even if there were hundred to thousands of players creating requests?

Re: Where to put the server timers

but if let's say.. you have to execute a command at end-time, to calculate a new rank within the multiplayer world

You don't have to, you can determine that from the state.

Cyclopses, on 15 November 2011 - 11:24 AM, said:

, or save your Barrack's level to the DB.

Also known based on stored information.

Cyclopses, on 15 November 2011 - 11:24 AM, said:

And if I were to apply your method, where would all those requests be saved?

You need a database. The more people, the more you need it. A single database can handle thousands of simultaneous requests. A good architecture can scale it infinitely, limited only by your resources.

As to the freshness of data, keep in mind that you're dealing with a "tree falls in woods" scenario. Until some asks for a particular piece of information, it doesn't matter what state it's in.

You can use the quantity of requests as you timer, if you like. Upon each request, you might preform update tasks that relate to that request. Again, if no one is asking, it doesn't matter. When you do regular backups, you can run all updates together.

Re: Where to put the server timers

Posted 16 November 2011 - 03:13 AM

And I presume you wouldnt save a Player's said Iron ores count on the database either and apply the auto-increment every second?
Instead the same tactic must be applied and use said Tree falls in woods scenario where you would calculate a player's current ores by doing some math on date-end till now times the number of increment per sec. minus the amount of used and sold ores?
In theory I see this work, but Im afraid of the stress it would shred on the server and retrieving the information highly indirrect.

Do you (or anyone else) use the same approach or would this be any different.
P.s. Should I move this question to the games forum section or would it do fine here?