09 Achievements Mod.

Started by MelvinMeow, July 21, 2012, 12:28:29 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


Upload achievements:

# Of Uploads.
takeupload.php find:
mysql_query("INSERT INTO files (torrent, filename, size) VALUES ".file_list($filelist,$id));

Add below:
@mysql_query("UPDATE users SET numuploads = numuploads + 1 WHERE id = ".sqlesc($CURUSER["id"])."") or sqlerr(__FILE__, __LINE__);

If your using seedbonus you would add it simply like this:
@mysql_query("UPDATE users SET numuploads = numuploads + 1, seedbonus = seedbonus+3.0 WHERE id = ".sqlesc($CURUSER["id"])."") or sqlerr(__FILE__, __LINE__);

Sticky Uploads
(Requires sticky mod to already be installed.)
We set our torrents to be sticky on the edit page...so to set this we need to do the following:

takeedit.php find:
$updateset[] = "category = " . (0 + $type);

Below we have:
$updateset[] = "sticky = '" . (isset($_POST["sticky"]) ? "yes" : "no") . "'";
$stick = (isset($_POST["sticky"]));
if ($stick == yes){
@mysql_query("UPDATE usersachiev SET stickyup = stickyup + 1 WHERE id = ".sqlesc($owner)."") or sqlerr(__FILE__, __LINE__);

Request Filler (Must have requests mod installed.)
req_filled.php find:

mysql_query("UPDATE requests SET torrentid = ".$torrentid.", filledby = $CURUSER[id] WHERE id = $id") or sqlerr(__FILE__, __LINE__);

Add Below:
mysql_query("UPDATE usersachiev SET reqfilled = reqfilled + 1 WHERE id = $CURUSER[id]") or sqlerr(__FILE__, __LINE__);

Shoutbox achievements.
Code should be auto run through the achievementclean.php you do not need to add anything.

Forum Achievements.
forum_user_options.php find:
//------- Delete post

Add below:
@mysql_query("UPDATE usersachiev SET forumposts = forumposts - 1 WHERE id = $posterid") or sqlerr(__FILE__, __LINE__);

forum_post.php find this section:
//---- Create topic

Youll see a query that looks similiar to this:
@mysql_query("INSERT INTO topics (userid, forumid, subject, anonymous) VALUES($userid, $forumid, $subject, ".sqlesc($anonymous).")") or sqlerr(__FILE__, __LINE__);

Add this line above that query:
@mysql_query("UPDATE usersachiev SET forumtopics = forumtopics + 1 WHERE id = ".sqlesc($CURUSER["id"])."") or sqlerr(__FILE__, __LINE__);

Still in the same file find:
//------ Insert post

Find in the same section the following:
$body = sqlesc($body);

Add just below the $body line the following:
@mysql_query("UPDATE usersachiev SET forumposts = forumposts + 1 WHERE id = ".sqlesc($CURUSER["id"])."") or sqlerr(__FILE__, __LINE__);

Snatched Torrents:
Should be auto calculated in achievementclean.php
(Requires snatched mod to already be installed.)

Avatar and Signature setting achievements:
takeprofedit.php find:
/////// do the avatar stuff

Look for the following lines in the same section:
        if($img_size[0] < 5 || $img_size[1] < 5)
          stderr('USER ERROR', 'Image is too small');

Add Below:
@mysql_query("UPDATE usersachiev SET avatarset = avatarset + 1 WHERE id = ".sqlesc($CURUSER["id"])." AND avatarset = '0'") or sqlerr(__FILE__, __LINE__);

Look for:
/////// do the signature stuff

In the same section as signature stuff look for:
        if($img_size[0] < 5 || $img_size[1] < 5)
          stderr('USER ERROR', 'Image is too small');

Add Below:
@mysql_query("UPDATE usersachiev SET sigset = sigset + 1 WHERE id = ".sqlesc($CURUSER["id"])." AND sigset = '0'") or sqlerr(__FILE__, __LINE__);

Invite achievements:
We do ours through the takesignup.php but if you use a seperate page you would use that pages take such as takeinvitesignup.php or whatever.

$id = mysql_insert_id();

mysql_query("INSERT INTO usersachiev (id, username) VALUES ('$id', '$wantusername' )") or die(mysql_error());

$psecret = md5($editsecret);

Add above:
@mysql_query("UPDATE usersachiev SET invited = invited + 1 WHERE id = $assoc[sender]") or sqlerr(__FILE__, __LINE__);


These files are for counting the totals. Works if your forums ect... have already been open on your site for a while prior to adding the mod. It allows the users to fetch accurate counts for the fields.

sql.txt is the sql needed to run the mod.

[attachment deleted by admin]


All files get uploaded to dir with exception to the following location.


achievementlist.php shows the users the full list of achievements they can earn as well as how many users have previously earned each achievement in the list.

achievementhistory.php shows the user all the achievements they have currently earned.

achievementbonus.php uses achievementbonus (Like bonus points.) and randomly gives the user a random prize.  (Page is based on code I received from retro a while back.)

Add the following function:
  function doachievementcleanup()
    global $TBDEV;
    $result = @mysql_query("show processlist") or sqlerr(__FILE__, __LINE__);
    while ($row = mysql_fetch_array($result)) {
    if (($row["Time"] > 100) || ($row["Command"] == "Sleep")) {
    $sql = "kill " . $row["Id"] . "";
    @mysql_query($sql) or sqlerr(__FILE__, __LINE__);
include "achievementclean.php";
write_log("Achievements Cleanup:  Achievements Cleanup Completed.","cleanup");

bittorrent.php  find:
function autoclean()

add to the list of functions the following:
else if ($row['arg'] == "lastachievementclean" && ($row['value_u'] + $TBDEV['autoachievementclean_interval']) < $now)
mysql_query("UPDATE avps SET value_u = '$now' WHERE arg = 'lastachievementclean'") or sqlerr(__FILE__, __LINE__);

For creating the usersachiev table from an already existing site I simply copied the users table with just the id and username field and simply inserted all that info into the usersachiev table.

[attachment deleted by admin]