- Feb 13, 2003
- 26,255
- 403
- 126
A couple guys and myself are working on a web game (using ASP.NET 3.5 and SQL Server 2005) that has some functionality that is similar to the Ikariam web game that was posted in the OT forum awhile back. However, I was wondering if anyone here had any input on a specific task we are in the process of implementing.
For anyone unfamiliar with Ikariam, you have an outpost where there are empty spots where clicking on them allows you to build a structure there. After a structure is finished building, clicking it will allow you to upgrade it. When building or upgrading, a "under construction" image is displayed and a timer counts down to zero from the length of time the action requires.
This functionality is what we have in our game. We have the logic implemented to show the "under construction" image and have a timer counting down using JavaScript, which when it gets to zero refreshes the page and in Page_Load there is logic that checks a couple of database tables to see if any building/upgrading has completed; if so the construction records are deleted and new building records inserted, into their respective tables.
However, we have other functionality that needs to happen behind-the-scenes on a real-time basis (example: the player earns so much money per hour). So we were thinking of two options to implement this:
1. Have a SQL Server scheduled job execute a stored procedure that checks tables and does the necessary inserts/deletes/updates. This job would ideally run every second or maybe thirty seconds.
2. Create a Windows Service that does the logic and have this service trigger every second (or thirty).
Option 2 is my preferred way as implementing the logic using C#/LINQ would be much easier than doing it in a stored procedure using SQL. I'm just not sure how efficient either of these methods are. For each player, I don't think these building and construction tables will have more than a couple tens of records so the database should not be too big.
Has anyone implemented this timer "real-time behind-the-scenes" sort of thing in a web app before? What do you think about the options we came up with? I'd appreciate any suggestions.
For anyone unfamiliar with Ikariam, you have an outpost where there are empty spots where clicking on them allows you to build a structure there. After a structure is finished building, clicking it will allow you to upgrade it. When building or upgrading, a "under construction" image is displayed and a timer counts down to zero from the length of time the action requires.
This functionality is what we have in our game. We have the logic implemented to show the "under construction" image and have a timer counting down using JavaScript, which when it gets to zero refreshes the page and in Page_Load there is logic that checks a couple of database tables to see if any building/upgrading has completed; if so the construction records are deleted and new building records inserted, into their respective tables.
However, we have other functionality that needs to happen behind-the-scenes on a real-time basis (example: the player earns so much money per hour). So we were thinking of two options to implement this:
1. Have a SQL Server scheduled job execute a stored procedure that checks tables and does the necessary inserts/deletes/updates. This job would ideally run every second or maybe thirty seconds.
2. Create a Windows Service that does the logic and have this service trigger every second (or thirty).
Option 2 is my preferred way as implementing the logic using C#/LINQ would be much easier than doing it in a stored procedure using SQL. I'm just not sure how efficient either of these methods are. For each player, I don't think these building and construction tables will have more than a couple tens of records so the database should not be too big.
Has anyone implemented this timer "real-time behind-the-scenes" sort of thing in a web app before? What do you think about the options we came up with? I'd appreciate any suggestions.