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.


All cleanups re-written mate - Now they are using buffered arrays, one query awards them all so thats perfect, I'm also testing code putyn wrote which is an even further optimized version of what i had written. achievementlist.php is now left joined also so the query counts dropped from 77 which is the amount of entrys down to one single query with count intact. So I'm just about ready to repost, probably today some point.


CREATE TABLE `ach_bonus` (
  `bonus_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
  `bonus_desc` text NOT NULL,
  `bonus_type` tinyint(4) NOT NULL DEFAULT '0',
  `bonus_do` text NOT NULL,
  PRIMARY KEY (`bonus_id`)

-- Dumping data for table `ach_bonus`

INSERT INTO `ach_bonus` VALUES (1,'Subtract 10GB From Your Download.',1,'10737418240'),(2,'Subtract 1GB From Your Download.',1,'1073741824'),(3,'Subtract 3GB From Your Download.',1,'3221225472'),(4,'Subtract 5GB From Your Download.',1,'5368709120'),(5,'Subtract 100MB From Your Download.',1,'107374182'),(6,'Subtract 300MB From Your Download.',1,'322122547'),(7,'Subtract 500MB From Your Download.',1,'536870910'),(8,'Subtract 1MB From Your Download.',1,'1073741'),(9,'Add 1GB to your Upload.',2,'1073741824'),(10,'Add 10GB to your Upload.',2,'10737418240'),(11,'Add 3GB to your Upload.',2,'3221225472'),(12,'Add 5GB to your Upload.',2,'5368709120'),(13,'Add 100MB to your Upload.',2,'107374182'),(14,'Add 300MB to your Upload.',2,'322122547'),(15,'Add 500MB to your Upload.',2,'536870910'),(16,'Add 1MB to your Upload.',2,'1073741'),(17,'Add 1 Invite.',3,'1'),(18,'Add 2 Invites.',3,'2'),(19,'Add 100 Bonus Points to your Total.',4,'100'),(20,'Add 200 Bonus Points to your Total.',4,'200'),(21,'Add 500 Bonus Points to your Total.',4,'500'),(22,'Add 750 Bonus Points to your Total.',4,'750'),(23,'Add 1000 Bonus Points to your Total.',4,'1000'),(24,'Add 50 Bonus Points to your Total.',4,'50'),(25,'Add 25 Bonus Points to your Total.',4,'25'),(26,'Add 75 Bonus Points to your Total.',4,'75'),(27,'Add 10 Bonus Points to your Total.',4,'10'),(28,'Nothing',5,'0'),(29,'Nothing',5,'0'),(30,'Nothing',5,'0'),(31,'Nothing',5,'0'),(32,'Nothing',5,'0');

Sorry for the wait been having issues with our server so had to dig through some backups to find it.

While the pics can be used by other sites... My graffic skills aren't the best and some of them are for a comical side as well. But feel free to use the images if you like, though I'm sure users could submit better ones ;)

And yes corrupt should be included in the peers table as well.

[attachment deleted by admin]


Sorted - putyn corrected my left join, job done there only missing bonus sql as above post, images can be made so biggie there. Everything else i have under control and complete, no far from being ready to post.


Run that avatar code - seems fine - so tried the bonus link tonight from achievementshistory.php mate and theres another table

Code (php) Select
$get_bonus = sql_query("SELECT * FROM ach_bonus WHERE bonus_id

ach_bonus ? no in the posts, that and image folder is all i see - i'll redo the cleanups i can with buffered arrays then post.


All done my end, somethings telling me corrupt has to be in peers table cos using $self['corrupt'] in $corruptthis line, but I'm still messing with that part, notice an undefined index corrupt coming from the $_GET x so maybe no all clients send it - need to dig for my own curiosity; Ran all the cleanups there all good - pms all sent ect, all work fine, all tables updated correct, all achievements updated correct - images folder must be missing lol, i was wondering what all the apache error log entries were for at first then it clicked, apart ffrom that its in superb shape mate, will post it up real soon, I'm going to have a crack at optimizing those cleanups first i think :P

Heres Avatar setter - well i just fired it together no tested, so i think i can manage shit here

Code (php) Select
// Avatar Setter Achievement
   $res = sql_query("SELECT id, avatarset FROM usersachiev WHERE avatarset = '1' AND avatarach = '0'") or sqlerr(__FILE__, __LINE__);
   $msg_buffer = $usersachiev_buffer = $achievement_buffer = array();
if (mysqli_num_rows($res) > 0){
   $subject = sqlesc("New Achievement Earned!");
$msg = sqlesc("Congratulations, you have just earned the [b]Avatar Setter[/b] achievement. :)\n[img={$INSTALLER09['pic_base_url']}achievements/piratesheep.png]");
while ($arr = mysqli_fetch_assoc($res)){
   $dt = TIME_NOW;
   $points = rand(1,3);
   $msgs_buffer[] = '(0,' . $arr['id'] . ','. TIME_NOW .', ' . sqlesc($msg) . ', ' . sqlesc($subject) . ')';
   $achievements_buffer[] = '(' . $arr['id'] . ', '.TIME_NOW.', \'Avatar Setter\', \'piratesheep.png\' , \'User has successfully set an avatar on profile settings.\')';
   $usersachiev_buffer[] = '(' . $arr['id'] . ',1, ' . $points . ')';
   $count = count($achievements_buffer);
   if ($count > 0){
   sql_query("INSERT INTO messages (sender,receiver,added,msg,subject) VALUES " . implode(', ', $msgs_buffer)) or sqlerr(__FILE__, __LINE__);
   sql_query("INSERT INTO achievements (userid, date, achievement, icon, description) VALUES " . implode(', ', $achievements_buffer) . " ON DUPLICATE key UPDATE date=values(date),achievement=values(achievement),icon=values(icon),description=values(description)") or sqlerr(__FILE__, __LINE__);
   sql_query("INSERT INTO usersachiev (id, avatarach, achpoints) VALUES " . implode(', ', $usersachiev_buffer). " ON DUPLICATE key UPDATE avatarach=values(avatarach), achpoints=achpoints+values(achpoints)") or sqlerr(__FILE__, __LINE__);
   write_log("Achievements Cleanup:  Avatar Achievements awarded to - ".$count." Member(s)");


Love it MM, great work  :)


that why you get the you've been caught touching the sheep. lol

oh i almost forgot nice work mm. i loved from the start of it.


The sheep one is actually just a floating icon we have on the side nav bar. When you click it, it brings you back to the home page basically. I track how many times users click it and we give achievements based on that.

This is an example of the code in the index page:
    if (isset($_GET["sheep"]))
@mysql_query("UPDATE usersachiev SET sheepyset = sheepyset + 1 WHERE id = ".sqlesc($CURUSER["id"])."") or sqlerr(__FILE__, __LINE__);

With a simple link to access it like this:
<a href='index.php?sheep=1' alt='Home' title='Home' class='firefox'></a>
I have to say of all the mods I have revised and edited over the years... this is one of the ones I had the most fun with ;)
I even have an option to add custom achievements for individual users...to make it even more funny.

As for the corrupt portion heres some snippets that should clue you in better how I do it.
foreach (array("port","downloaded","uploaded","left","corrupt") as $x) {
$GLOBALS[$x] = 0 + $_GET[$x];

foreach (array("passkey","info_hash","peer_id","port","downloaded","uploaded","left","corrupt") as $x)
if (!isset($x)) err("Missing key: $x");

foreach (array("info_hash","peer_id") as $x)

if (strlen($GLOBALS[$x]) != 20){
err("Invalid $x (" . strlen($GLOBALS[$x]) . " - " . urlencode($GLOBALS[$x]) . ")");
$port = 0 + $port;
$downloaded = 0 + $downloaded;
$uploaded = 0 + $uploaded;
$left = 0 + $left;
$corrupt = 0 + $corrupt;
$rsize = 50;

$user_query = mysql_query("SELECT username, id, uploaded, downloaded, corrupt, ratiolock, class, enabled, downloadpos, badtorrentnum FROM users WHERE passkey=".sqlesc($passkey)) or err("Tracker error 2");

$corruptthis = max(0, $corrupt - $self["corrupt"]);
$upthis = max(0, $uploaded - $self["uploaded"]);
$downthis = max(0, $downloaded - $self["downloaded"]);

mysql_query("UPDATE users SET uploaded = uploaded + $upthis, downloaded = downloaded + $downthis, corrupt = corrupt + $corruptthis WHERE id=$userid") or err("Tracker error 3");


Knew it lol - just edited and thought i had fucked that part lol - love the mod =]


At the moment yes Im updating them in the shoutbox.php
mysql_query( "INSERT INTO shoutbox (id, userid, date, text, text_parsed) VALUES ('id'," . sqlesc( $userid ) . ", $date, " . sqlesc( $text ) . ",".sqlesc( $text_parsed ) .")" ) or sqlerr( __FILE__, __LINE__ );
Below I added this:
mysql_query("UPDATE usersachiev SET dailyshouts = dailyshouts+1, weeklyshouts = weeklyshouts+1, monthlyshouts = monthlyshouts+1, totalshouts = totalshouts+1 WHERE id = $userid") or sqlerr(__FILE__, __LINE__);
As you can tell based on the query I started working on other shout achievements as well.

I eventually will make it run through the cleanup to add the counts instead of adding an extra query to each shout post.
I have my cleanup split into 4 cats. It runs at 4 differant times per day. This is an older version of the mod. :) But yeah you get the idea. As its coded here it only runs the code once per day which is why I didn't feel so bad about it having so many queries running.. you should have seen the original method I was doing.

As for the corrupt thats easy to track since most torrent clients have that field in the announce strings already. Its just a matter of adding the field to the users table and having the announce check it. When I coded that portion of the achievement I took it a little farther so when you have corrupt data it removes it from your downloaded total on the torrents as well. I am always tinkering with stuff like this in code... Its just been a while since I posted mods.  :o


Got it all done - im splitting every single award section in cleanup to its own file so can stagger them all, nice work man, notice corruption and dailyshouts - both user fields ? How you updating that - because as posted no way to update shout acheivement - so i added a entry to shoutbox dailyshouts and used a left join at cleanup - wrong approach im guessing your updating and incrementing dailyshouts from shoutbox.php ? And what sets corruption and the sheep one - guess they can be removed i dont mean to bust your balls over such a huge mod, i will try to rewrite some of cleanup as well over next few days and if you want to use it yourself you can - i love it MM

Code (php) Select
$res = sql_query("SELECT shoutbox.userid, shoutbox.dailyshouts, usersachiev.dailyshoutlvl FROM shoutbox LEFT JOIN usersachiev ON shoutbox.userid = usersachiev.id WHERE dailyshouts >= '10'") or sqlerr(__FILE__, __LINE__);
//$res = sql_query("SELECT id, dailyshouts, dailyshoutlvl FROM usersachiev WHERE dailyshouts >= '10'") or sqlerr(__FILE__, __LINE__);

SO that was late last night and im updating dailyshout field in shoutbox table, then im like ffs thats so wrong - should just put another query in shoutbox.php and update usersachiev table - increment the dailyshouts there ?


i've been working on this with my v3 test site. nothing to report yet as i'm still going over everything. and working alot. lol


You can delete the post that didnt have all the full mod whenever you get a chance.

Been working on this for about 6 months or so. I add new stuff to it on occasion.
I have a few more updates for it eventually but none of the new achievements are 100% finished yet.


Thank MM for this full mod :)
Never fall to those that just sit there.. Always look for the way to the top even if you have to code it your self and mistakes and all... quote from BonZO...


That looks a fair modification mate, thanks a lot for posting it, i have taken your posts to doc, will work on it offline for those with V3 then repost in V3 Mods, nice work indeed.