![Old](entertainage/statusicon/post_old.gif)
03-13-2011, 04:41 AM
|
Dev Staff
|
|
Join Date: Jan 2010
Posts: 501
Gender: Male
Credits: 35,211
|
|
Secure Random Adoption V2
This mod is intended for people who already or wanted to have a random adoption process on their adoptables site.
Compatibility: Mys V1.2.x
NOTE:Please make a backup of your files before installing this mod!
1. Open your adopt.php and find
PHP Code:
$query = "SELECT * FROM ".$prefix."adoptables";
replace it with the code below to fetch only 1 random adoptables from the database
PHP Code:
$query = "SELECT * FROM ".$prefix."adoptables ORDER BY RAND() LIMIT 1";
2. A few lines after that, find
PHP Code:
$article_content .= "<form name='form1' method='get' action='doadopt.php'>
replace it with this
PHP Code:
$article_content .= "<form name='form1' method='post' action='adopt.php'>
3. And then, go find this code
PHP Code:
if($canadopt == "yes"){ //If we can adopt the adoptable, show the image and adoption link... $article_content .= "<tr> <td><input type='radio' name='id' id='id' value='{$aid}' /></td> <td style='text-align: center'><img src='".$eggimage."' /></td>
<td><strong>{$type}</strong> - {$row['cost']} {$GLOBALS['settings']['cost']}.<br />{$description}</td></tr>"; }
Since we only want to show 1 adoptables and obviously without any information for randomness, replace that code with
PHP Code:
if($canadopt == "yes"){ //If we can adopt the adoptable, show the image and adoption link... $article_content .= "<tr> <td style='text-align: center'><img src='".$eggimage."' /></td>"; } else{ $eresult = runquery("SELECT * FROM ".$prefix."adoptables WHERE whenisavail='always' ORDER BY RAND() LIMIT 1"); while($erow = mysql_fetch_array($eresult)){ $aid=$erow['id']; //The adoptable's ID $type=$erow['type']; $description=$erow['description']; $eggimage=$erow['eggimage']; $article_content .= "<tr>
<td style='text-align: center'><img src='".$eggimage."' /></td>"; }
}
You may notice that I put an else statement. The else statement is used in case the first query fetch an adoptables that you can't adopt because you haven't met the necessary requirement. It will fetch an adoptables with the always available condition.
Anyway, let's move on.
4. Find the following
PHP Code:
$query = "SELECT * FROM ".$prefix."adoptables WHERE id='$id' LIMIT 1";
and replace it with
PHP Code:
$query = "SELECT * FROM ".$prefix."adoptables WHERE id='$id' AND whenisavail='promo' LIMIT 1";
Restrict the GET method only for adopting adoptables with promo code
5. Finally, find the last closing curly bracket
PHP Code:
} // This bracket ends the else statements for whether or not an ID was entered
and below that add this code
PHP Code:
if($_POST) { $id = $aid; $name = $_POST["name"];
if($isloggedin == "yes"){ // I guess the first thing to do is see if we have a valid adoptable ID submitted... if($id == "" or !is_numeric($id)){ $article_title = $err_idnoexist; $article_content = $err_idnoexist_text; } else{ // The adoptable ID appears to be valid, so we need to double check that it is valid by pulling up the adoptable in the DB
$query = "SELECT * FROM ".$prefix."adoptables WHERE id='$id'"; $result = runquery($query);
$result = runquery($query); $row = mysql_fetch_array($result);
$aid = $row['id']; $type=$row['type']; $description=$row['description']; $eggimage=$row['eggimage'];
if($id == $aid){ // The ID submitted matches an existing adoptable type $canadopt = canadopt($aid, "adopting", $promocode, $row);
// If we can adopt this creature, do the adoption if($canadopt == "yes") { if (changecash(-$row['cost'], $GLOBALS['loggedinname'], $GLOBALS['money'])==true) { // BEGIN the actual adoption process
// First we see if we have a custom name; if not, we use the default name if($name == ""){ $name = "Mystery Egg"; }
// Now we determine if we are using alternate images or not
$alts = getaltstatus($id, 0, 0);
// We need a unique code for the adoptable so we can show it to the user when we're done here...
$code = rand(1, 20000); $genders = array('f', 'm'); $rand = rand(0,1); runquery("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$name','$loggedinname','0','0', '$code', '','$alts','fortrade','no', '$genders[$rand]','0')");
// Adoption complete, show the user a confirmation screen...
$query = "SELECT * FROM ".$prefix."owned_adoptables WHERE code='$code' and owner='$loggedinname'"; $result = runquery($query); $num = mysql_numrows($result); $id=@mysql_result($result,0,"aid");
$article_title = $name." adopted successfully"; $article_content = "<img src='".$eggimage."'><br>".$congrats1." ".$name.". You can now manage ".$name." on the <a href='myadopts.php'>My Adopts</a> page.<br><br><b><a href='myadopts.php?act=manage&id=".$id."'>Click Here to Manage ".$name."</a><br> <a href='myadopts.php?act=bbcode&id=".$id."'>Click Here to get BBCodes / HTML Codes for ".$name."</a></b><br><br> Be sure and <a href='levelup.php?id=".$id."'>feed</a> ".$name." with clicks so that they grow!";
// END the actual adoption process } else { $article_title = "Not enough money."; $article_content = "You don't have enough {$GLOBALS['settings']['cost']} to buy this adoptable. Earn some money and then try again."; } } else { $article_title = $accden; $article_content = $adoptnoper; } } // End the if for if $id == $aid else { // Adoptable does not exist, show an error.
$article_title = $err_idnoexist; $article_content = $err_idnoexist_text; } // End the else for if $id == $aid } // End the valid ID input else test statement (bulk of code goes above here) } // End the log in check IF else { // Guests cannot adopt pets, so why bother... $article_title = $guesttitleerror; $article_content = $guesterror; } // End the log in check ELSE }
6. Now, to prevent some users from cheating. Open your doadopt.php, we'll just do a slight query modification.
Find this query
PHP Code:
$query = "SELECT * FROM ".$prefix."adoptables WHERE id='$id'";
replace that query with this one
PHP Code:
$query = "SELECT * FROM ".$prefix."adoptables WHERE id='$id' AND whenisavail = 'promo'";
We just restricted the doadopt.php file to only work with adoptables with promo code.
Done!
Let me know if there's any problem with this mod. :)
|