MyBB Tutorials

Steam Account Status

Submitted by Aoki, , Thread ID: 11924

Thread Closed
27-10-2015, 05:10 AM
#1
This modification will allow you to have users input their Steam ID as a profile field. The upgrade to that, and the modification, is that you will have a cron job automatically update the user's steam account status which will then be displayed on the user's postbit and profile information.

I would have made this as a plugin, but this is really my first time coming back into the forum suite in about 2 years, and even back then, I hardly knew how to make a plugin. If someone could help with that, or help me learn, that would be great.

Step One

You need to make a couple of new profile fields in MyBB for this to work. So, go to the Admin Panel -> Configuration -> Custom Profile Fields -> Add New Profile Field

[Image: Q7AIhAJ.png]

You will want to make two profile fields that match the images below. One is for the user to enter a Steam ID, the other the program will write to. The Steam ID is the editable and non-visible field while the Steam Account field is non-editable but visible. Regex is used to only allow numbers to be entered which creates less problems in securing the script. You can name these fields however you want with whatever descriptions and lengths you want. Just be mindful if you choose minimum / maximum lengths.

[Image: 5BFASoA.png]

[Image: 9NbHNZU.png]


Step Two

Create a PHP script that will find information based on the user's Steam ID.
You want to save the following code as a PHP file, with whatever name you want. The easiest way to secure the file is to have it put outside your public directory and run it with cron jobs. I created a folder named "cron" under /home/USER where I placed my PHP file.

Code:
<?php
define('IN_MYBB', 1);
require '../public_html/forum/global.php';
global $db;

$steamStat = array(
    '0' => 'Offline',
    '1' => 'Online',
    '2' => 'Busy',
    '3' => 'Away',
    '4' => 'Snooze',
    '5' => 'Looking to Trade',
    '6' => 'Looking to Play'
);

$steamCSS = array(
    '0' => 'steamOffline',
    '1' => 'steamOnline',
    '2' => 'steamBusy',
    '3' => 'steamAway',
    '4' => 'steamSnooze',
    '5' => 'steamTrade',
    '6' => 'steamPlay'
);
    
$select = $db->simple_select('userfields', 'ufid, fid4');
while ($result = $db->fetch_array($select)) {
    $steamID = $result['fid4'];
    if ($steamID != '') {
        $uid = $result['ufid'];
        $json_url = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=YOURSTEAMAPIKEY&steamids=' . $steamID;
        $json = file_get_contents($json_url);
        $data = json_decode($json, TRUE);
        $steamStatus = $data['response']['players'][0]['personastate'];
        $steamAcc = '<a href="http://steamcommunity.com/profiles/' . $steamID . '/" title="' . $data['response']['players'][0]['personaname'] . '" class="' . $steamCSS[$steamStatus] . '">' . $steamStat[$steamStatus] . '</a>';
        $update = $db->update_query('userfields', array('fid5' => $steamAcc), 'ufid=' . $uid . '');
    }
}
?>

[Image: 9A8acij.png]

Step Three

Now that you've uploaded the PHP file to your server, you need to run it via a cron job to indicate what the user's status is. The time period you choose is entirely up to you. Navigate to your cPanel or other software used to run your website. You'll want to find "Cron Jobs" and enter it to add a new one. For most, you simply choose a time period. The command line you will need is

Code:
/usr/bin/php -q /home/USER/cron/cron.php >/dev/null

This will run the script at every time period you tell the job to run at. For me, it's every 15 minutes. You're also limited to only 100,000 requests a day unless you get approved for more.

Step Four

The last thing you will need to do is add just a little bit of CSS to make the field look good, and different based on what the user's status is. You will need to navigate to the Themes & Templates -> Default -> Global.css -> Advanced Mode

[Image: gNoIsdF.png]

You will then want to add this code anywhere you want (I placed mine at the bottom). Of course, the colors don't have to be the ones I used, but they look decent on the default forum theme. I'll be changing them once my custom theme is done.

Code:
.steamOffline:hover, .steamOffline:active,
.steamOnline:hover, .steamOnline:active,
.steamBusy:hover, .steamBusy:active,
.steamAway:hover, .steamAway:active,
.steamSnooze:hover, .steamSnooze:active,
.steamTrade:hover, .steamTrade:active,
.steamPlay:hover, .steamPlay:active {
    text-decoration: none;
}

.steamOffline,
.steamOnline,
.steamBusy,
.steamAway,
.steamSnooze,
.steamTrade,
.steamPlay {
    text-decoration: none;
    font-weight: bold;
}

a.steamOffline {
    color: rgba(118, 143, 137, 0.95);    
}

a.steamOnline {
    color: rgba(16, 79, 24, 0.95);
}

a.steamBusy {
    color: rgba(130, 19, 16, 0.95);    
}

a.steamAway, a.steamSnooze {
    color: rgba(207, 92, 27, 0.95);    
}

a.steamTrade {
    color: rgba(71, 52, 143, 0.95);    
}

a.steamPlay {
    color: rgba(36, 93, 143, 0.95);    
}

That's it! You don't have to use the same colors, or place the CSS in the same spot, or even put the PHP folder in the same spot as long as you secure your cron jobs and link to everything properly. But, this should have been a pretty easy tutorial.

End Result

[Image: 3JJFUJ0.png]
2

RE: Steam Account Status

#2
Damn. I haven't seen something like this.

Thanks for the great share Aoki

RE: Steam Account Status

#3
great tutorial Aoki. :hurr:
Private Investigation Services
Pm / Contact me

RE: Steam Account Status

#4
Superbly detailed, kudos to you <3 <3 <3
Isn't this signature cool ? <3

RE: Steam Account Status

#5
Awesome tutorial, will be handy for my forum n.n

Thanks!

RE: Steam Account Status

#6
Pretty awesome, thanks mate. I never fiddled with custom inputs, I never saw it :cry:

RE: Steam Account Status

This post was last modified: 28-10-2015, 12:21 PM by H
#7
Great share and thorough tutorial Tongue. Thanks for this.
The Pengest Turkey

[Image: The-Chicken-Connoisseur-PENGEST-TURKEY-1-1.gif]


Users browsing this thread: 1 Guest(s)