Updating resources...

C++, C#, Java, PHP, ect...
Post Reply
User avatar
rockinliam
Posts: 466
Joined: Sun Jun 07, 2009 11:26 am

Updating resources...

Post 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?
Skillset: C/C++, OpenGL, C#, Lua, PHP, MySql, Web Dev etc.
Website: https://liam-griffiths.co.uk/
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Updating resources...

Post 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
}
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Updating resources...

Post 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.
The indelible lord of tl;dr
User avatar
rockinliam
Posts: 466
Joined: Sun Jun 07, 2009 11:26 am

Re: Updating resources...

Post 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*
Skillset: C/C++, OpenGL, C#, Lua, PHP, MySql, Web Dev etc.
Website: https://liam-griffiths.co.uk/
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Updating resources...

Post 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.
Post Reply

Return to “Coding”