Post Reply  Post Thread 
Auto activating games.
Author Message
brendgard
Moderator
*****


Posts: 88
Group: Moderators
Joined: Mar 2008
Status: Offline
Reputation: 2
Post: #1
Auto activating games.

The following is a reprint off my own site I thought I'd share. The original can be found on http://gamersgo.com in the script modifications page, and a file that is already set up to work with some scripts of the GAS family can be downloaded through there.
------------------------------------------------------


This helps to automaticaly "add" games to your arcade. The basic script was written for the GAS family of scripts(GHS, MAGS, GMOA, etc). It can be adapted to various other types of scripts though. The more advanced will not run on them unless they are modified by adding the fields gBanned and DateAdded to their SQL structure.

It does make the assumption that there are games already added to the database that are just not yet made active/visible. If there are none, it will most likely run correctly, but have no effect.


Variables:
--------------------------------
games: the name of the table.

gVisible: Sets whether the game is shown(active), or not shown(inactive). A "0" means not active/shown, a "1" means is active/shown.

DateAdded: The date the game was added or activated. A basic time stamp. A date stamp is also usable if your script prefers that.

gBanned: Set whether the game is allowed to to be activated or not. A "0" means is allowed to be activeated, a "1" means it is not allowed to be activated.

---------------------------------

First, create a new file. For the purposes of this, we will name it autoupdate.php.

Second, copy and paste one of the code snippets below into the file and edit the info as needed. The minimum needed will be username, database name, password, and path, to your database. Most likely you wll need to adjust the variables to fit your particular script as well as most scripts will not name their variables the same as the script this was done on.

Third, save it to your server. For the purposes of this we will assume that it is saved to the folder /home/hostingaccountname/public_html/

Forth, test it, adjust as needed.

Fifth, set up a cron job to run it. More on that below.

---------------------------------

Basic script:

Code:
<?php


//Set up SQL connection
$db_username ="username";
$db_name ="databasename";
$db_path ="localhost";
$db_password ="password";
$db = mysql_connect("$db_path","$db_username","$db_password");
mysql_select_db("$db_name",$db) or die(mysql_error());


//Execute SQL update. You may adjust the limit to suit your needs
$sq = "UPDATE games SET gVisible = 1  WHERE gVisible = 0 LIMIT 1;";
mysql_query($sq) or die(mysql_error());



?>




More advanced tweaking of script:

Code:
<?php


//Set up SQL connection - remains the same
$db_username ="username";
$db_name ="databasename";
$db_path ="localhost";
$db_password ="password";
$db = mysql_connect("$db_path","$db_username","$db_password");
mysql_select_db("$db_name",$db) or die(mysql_error());


//Execute SQL update.
$sq = "UPDATE games SET gVisible = 1, DateAdded = 'time()'  WHERE gVisible = 0 and gBanned = 0 LIMIT 1;";
mysql_query($sq) or die(mysql_error());

echo "1 game updated to visible" ;

?>


Notice that it also first checks to see if it is banned. You could use this to keep it from activiating adult games on a family friendly site for instance, or user submitted games that you have not checked out yet.

It also updates the DateAdded field. You would want this if you want to have a feed of newest games. You could do an SQL query based on this field in descending order.

It also includes a line to print out a line saying it made a game visible. You can, depending on your server, set it up so that the cron job e-mails the output of the script to you after it runs. If your server allows this, that is what it will e-mail to you. If nothing is set to print out, or your server is not set up to do so, it will not e-mail anything to you.


Cron jobs:
---------------------------------

As said before, once you get it set up to match your script, you set up a cron job to automaticaly run it for you. an example of this is

/usr/local/bin/php /home/hostingaccountname/public_html/autoupdate.php

Notice that there is a space in between /usr/local/bin/php and /home/hostingaccountname/public_html/autoupdate.php.

The first part is the pathway to the PHP command, the second is the pathway to your file you wish to run automaticaly. You might need to check with your hosting company to make sure that you get the correct info as it willn ot run otherwise.

Setting up times to run is also fairly simple. The command gives you 5 spots to input: minute, hour, day, month, weekday. setting up *, *, *, *, * would mean every minute. It would also mean you would probably get kicked off that host. Seting up a 0, 0, *, *, * would set it up for every day at midnight. Settings of 0, 3, *, *, * would set it up for every morning at 3am server time.


http://gamersgo.com
http://auntiefondy.com
http://script-place.com
http://altercoder.com
04-12-2008 09:32 AM
Find all posts by this user Quote this message in a reply
Peter
Your (un)Friendly Admin!
*******


Posts: 172
Group: Administrators
Joined: Mar 2008
Status: Offline
Reputation: 1
Post: #2
RE: Auto activating games.

Nice tutorial! Well Doen!


Arcade Banner Exchange
Free Flash Games
Arcade Resources
04-13-2008 05:10 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump:

Permissions
You cannot post new threads.
You cannot post replies.
You cannot post attachments.
You cannot edit your posts.
HTML is turned off.
MyCode is turned on.
Smilies are turned on.
[img] is turned on.