Skip to main content
GameDev.net gamedev.net
🔒 Locked

[web] web based rpg, automating tasks

Started by Oniviper Oct 20, 2009 at 11:15 PM 4 replies 1.4k views
Original Post
Oniviper
Oniviper
hey, my friend and i are designing a web based rpg (who isn't these days lol). what i'm trying to do is set up a standard user profile with the basic hp, mp, etc. what i want is for the hp and mp to regenerate automatically whether the user is logged in or not. lets say 1 hp every 5 minutes, but only if their hp is below their max hp limit. how would something like this be automated for a database of users, considering different users may have different timers or even upgrades that would reduce the amount of time needed to regenerate? thanks.
josh1billion
josh1billion
Write a single PHP script that, whenever the page is loaded (in a web browser for example), everything you want to happen (on that hourly basis or whatever) happens once.

Then, look into something called cron jobs. Somewhere in your web host's control panel, you should find cron access - some way to set up cron jobs. A "cron job" is basically an automated task to run a page at a certain time each day/week/month (or at a certain interval). So you'll be able to set up a cron job to automatically "load" your page once per hour.

Just be sure that your users don't have access to the page, otherwise they'd be able to load the page whenever they want by simply typing the URL into their web browser. You can prevent this a number of ways, the best being to put your PHP file outside ("above") your public_html directory.

Good luck!
Website (with downloads of my games)
Blog (updates on current projects)
Seeds of Time Online has returned!
Codeka
Codeka
You don't need to run anything on a timer for that. All you do is, whenever you query a player's health, you check how long it's been since the last update, and apply your formula.
Oniviper
Oniviper
thank you codeka and josh1billion. your responses have been most helpful. i had considered each of those ideas before my original post, but wasn't sure if there was a more "official" way to achieve my goal. but after reviewing your proposals i think i have decided on a combination of the two. in particular, updating a data table that'll keep track of those whose profiles need updated according to each's unique update-time interval, and then using "cron jobs" to query the data table for updating on a set time interval (every 5 seconds or whatever). i'm particularly worried about the server being bogged down, especially if i one day (with some luck) have millions of people playing. so if anyone has a better idea about how to go about this, i would love to hear it.

i currently do not have a web host, but have installed iis and sql express so i can use my computer as a server during the developmental process. i assume i can use sql server agent in place of the "cron jobs" of which you speak josh, but i'm uncertain how to place the php file "above" the public html directory. i've tried searching this in google, but i must not be using the correct search parameters to find any tutorials about how to do this because all i've found is how to make my php files more secure (which has been worthwhile itself, here's a particularly good 4 part article i've found... http://www.addedbytes.com/php/writing-secure-php/). can anyone elaborate about how to do this? thanks.
josh1billion
josh1billion
Quote:
Original post by Oniviper
and then using "cron jobs" to query the data table for updating on a set time interval (every 5 seconds or whatever). i'm particularly worried about the server being bogged down, especially if i one day (with some luck) have millions of people playing. so if anyone has a better idea about how to go about this, i would love to hear it.

Every 5 seconds? Yikes! That's a bad idea, and most web hosts have rules against executing crons so frequently. The most frequently you would want to do this sort of thing is every 1 minute, but even that is quite a bit-- I wouldn't set a particular cron to execute more than once every 10 minutes if you can get away with it. Most tick-based browser games "tick" every hour, so you probably only need to have your cron execute once per hour unless you're specifically designing your game to tick more frequently.

Quote:
Original post by Oniviperi currently do not have a web host, but have installed iis and sql express so i can use my computer as a server during the developmental process. i assume i can use sql server agent in place of the "cron jobs" of which you speak josh

I'm not positive, but IIS probably does have some alternative to cron. Keep in mind that cron is a Linux service, not specifically a web hosting software.

Quote:
Original post by Oniviper, but i'm uncertain how to place the php file "above" the public html directory.

When you upload your files to your webhost's server via your FTP client, the directory structure should be something like this..

/
/public_html
/something else..
/something else still..

Normally, you would upload your files into the public_html directory (sometimes displayed also as "www"). In this case, however, you would upload just to the root ("/") directory, because your users can potentially access anything that you put into public_html (while they cannot access anything outside of it in most cases).
Website (with downloads of my games)
Blog (updates on current projects)
Seeds of Time Online has returned!
taijianT
taijianT
I think it's much safer to stick with codeka's solution.

You only need to update the information when it is used. Even if this happens more frequently than just when the player is acting (e.g. because that players information affects other players) it is likely to be simpler and probably more efficient.

The only reason not to use this approach would be if you frequently need access to many players updated data. In this case instead of a cron job I would probably write a server side daemon (in C, Java, whatever) that handles this.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.