Page 1 of 1

Updating resources...

Posted: Wed Jul 07, 2010 9:40 pm
by rockinliam
How would i go about updating the resources of all the players in a database? Could i do it via a php script and a cronjob? If so what would be in the php script to update every user according to the level of their buildings and how would i make it safe to not be run by the player?

Re: Updating resources...

Posted: Wed Jul 07, 2010 10:22 pm
by hallsofvallhalla
do it via cron job,

just run the query and a while statement

query = Select lumber, metal from players
while query
{
query[lumber] = query[lumber]+5;
update players lumber=query[lumber] where name=query[name]

}


as far as keeping the script safe you could put a passcode in it

run the cron like www.mygame\cronjob1.php?code=23453443

then in the script
if ($_GET

Code: Select all

 = 23453443)
{
do cron
}
else
{
leave blank
}

Re: Updating resources...

Posted: Wed Jul 07, 2010 11:59 pm
by Jackolantern
For added security, if you only run the cron every couple of minutes, you can store the last time it was run in the database, and add logic to the script to check the last time it was run and ensure it is not running prematurely. Besides foiling exploiters, this could also help prevent disastrous system glitches. If you run it many times per minute, the added overhead could be a problem, though.

Re: Updating resources...

Posted: Thu Jul 08, 2010 12:11 am
by rockinliam
Ok guys thanks for the ideas, its too late at night for me to do this now, but il write it out tommorrow, and tell you if i work :D *fingers crossed*

Re: Updating resources...

Posted: Thu Jul 08, 2010 12:12 am
by hallsofvallhalla
good idea, just set a timer in the database and have it check if a hour has went by or whatever time you have set.