ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!
Home
Upgrade
Credits
Help
Search
Awards
Achievements
 4631

Steam Account Status

by deverx - 03-05-2016 - 12:34 PM
#1
Introduction
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: 74fe2d0026df956d0892a110bb9fef66.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: attachment.php?aid=34622]
[Image: attachment.php?aid=34623]


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.
PHP 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($jsonTRUE);
        
$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: attachment.php?aid=34624]

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: attachment.php?aid=34626]

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 {.myb
    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: attachment.php?thumbnail=34625]
Credit goes Tyler. E from community.mybb
http://community.mybb.com/thread-173067.html
Reply
#2
i know thi but still saying thank you for sharing bcoz its appreciate OP(contributor).
Reply
#3
Very interesting didn't know you could do this with mybb and steam
Reply
#4
looks cool! thanks!
Reply
#5
thanks alot for the information
Reply
#6
ahe3aw2321321321312321132
This account is currently banned
Ban reason: Spamming and Advertising other forums.
Reply

Users browsing: 1 Guest(s)