phpFreeChat and SMF: User/Group Identifying

This post is a follow-up to a previous post I made regarding an (in my opinion) improved method of identifying users to be in certain groups for phpFreeChat when using user info from phpBB3 boards.

After doing some searching, I noticed that there wasn’t very much info about identifying users in phpFreeChat with SMF boards. At least not SMF 2.x. Maybe I missed something in my search. I don’t know. But I decided to use what I already had put together from getting user info in phpBB3 to help lead in the direction I needed to go – along with some tutorial info that the SMF guys have posted on the site for using the SSI stuff.

Surprisingly, the process of identifying someone to be logged into SMF and to be within a group (such as the Administrator group) was just as simple as what was used for phpBB.

First of all, you have to define the path to SMF’s SSI.php file and call it.

require_once('../forums/SSI.php');

In my case, I have my structure set up so that my chat and forums are within two separate sub-directories on my domain. Some people decide to place phpFreeChat on the domain as a sub-directory of their board’s directory.

Similar to what I did with my phpBB configuration, I decided to use a variable to alter whether or not guests could access the chat or be redirected to a login page.

$RequireLogin = false; // if true, will require chatter to be logged in on the SMF board
if ($context['user']['is_guest'])
{
	if($RequireLogin)
	{
		ssi_login();
		die();
	}
}

Either way, if the user isn’t a guest, we assign their SMF name as their phpFreeChat name.

if (!$context['user']['is_guest']) $params["nick"] = $user_info['name']; // SMF nick used

Lastly, we assign the board admin as administrator, along with anyone who is a member of any designated groups (based on group ID – as with the phpBB setup). In this step, I’m kind of being tedious (because the ‘is_admin’ and group 1 should both be returned true if the user is in the Administrator group), but it doesn’t cause any issues from what I’ve seen – and I feel it guarantees a board admin will be given admin authority in the chat, but you can leave out the group ID 1 if you wish.

// SMF groups:
// 1 = Administrator
// 2 = Global Moderator

if($context['user']['is_admin'])
{
	$params["isadmin"] = true;
}
else
{
	$allowed_groups = array(1, 2);
	foreach ($allowed_groups as $allowed)
	{
		if (in_array($allowed, $user_info['groups']))
		{
			$params["isadmin"] = true;
		}
	}
}

That’s all. 🙂