Steam Account Status

by Aoki - 27-10-2015, 04:10 AM
oldfag
Administrators
Posts:
6,257
Joined:
Jan 2015
Likes:
1,767
Credits:
5,082
Reputation:
275
3 Years of Service
#1
OP
Posted: 27-10-2015, 04:10 AM
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]
Send me a message for help. (Read the help docs first)
Steam Wishlist - Anime Watchlist
H
28-10-2015, 11:21 AM
nostafu
18-12-2015, 02:11 PM
­
Divine
Posts:
4,322
Joined:
Jan 2015
Likes:
126
Credits:
6,079
Reputation:
105
3 Years of Service
#2
Posted: 27-10-2015, 04:12 AM
Damn. I haven't seen something like this.

Thanks for the great share Aoki
Web Development and Security
Posts:
915
Joined:
Oct 2015
Likes:
66
Credits:
52
Reputation:
103
2 Years of Service
#3
Posted: 27-10-2015, 04:14 AM
great tutorial Aoki. :hurr:
Private Investigation Services
Pm / Contact me


[Image: tumblr_n3rp4ou8M31sat2doo1_500.gif]
Active Member
Posts:
214
Joined:
Jul 2015
Likes:
14
Credits:
373
Reputation:
3
2 Years of Service
#4
Posted: 27-10-2015, 05:01 AM
Superbly detailed, kudos to you Heart Heart Heart
Isn't this signature cool ? Heart
Junior Member
Posts:
79
Joined:
Aug 2015
Likes:
2
Credits:
2
Reputation:
0
2 Years of Service
#5
Posted: 27-10-2015, 06:13 AM
Awesome tutorial, will be handy for my forum n.n

Thanks!
@Believer rocks
Cinema
Posts:
1,340
Joined:
May 2015
Likes:
51
Credits:
3
Reputation:
54
2 Years of Service
#6
Posted: 28-10-2015, 11:16 AM
Pretty awesome, thanks mate. I never fiddled with custom inputs, I never saw it :cry:
y u so shit
Posts:
6,599
Joined:
Feb 2015
Likes:
143
Credits:
5,879
Reputation:
93
3 Years of Service
#7
Posted: 28-10-2015, 11:21 AM (This post was last modified: 28-10-2015, 11:21 AM by H.)
Great share and thorough tutorial Tongue. Thanks for this.
The Pengest Turkey

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

The last reply on this thread is older than a month. Please do not unnecessarily bump it.
Register an account or login to reply
Create an account
Create a free account today and start posting right away. It only takes a few seconds.
Login
Log into an existing account.
1 Guest(s)