Jenosavel
06-24-2008, 01:59 AM
My vbulletin forum is going to be integrated along with a web game that has graphics intensive friends options. Because of this I need to be able to lower the maximum allowed friends a user can have. However, I can't seem to find any way to set this through the admin control panel, nor can I find any variables in the php code which control this.
I know in version 3.6.7 you could search for the "> 1000" bit of code and adjust the limit through that. However 3.7.1, what I'm working with now, doesn't seem to have that anymore.
Does anyone know if there's even a limit on the number of friends a user can have in 3.7.1? And if there is, how would one go about adjusting it?
Jenosavel
06-25-2008, 05:25 PM
Well, seeing as no one's responded, I'm going to assume no one knew a quick way to go about creating a friends cap. I ended up creating one, though it's not pretty and requires editing the profile.php file.
To start with, anywhere at the top of profile.php where the global variables are being declared, add one of your own to use as your maximum cap. Obviously set it to whatever you want your cap to be.
$friendlimit = 1000;
After that there are three sections of code we'll need to edit in various places: Request addlist, Post addlist, and Post updatelist. They each get used at different times, it seems, so there is quite a bit of code repetition.
$_REQUEST['do'] == 'addlist'
Near the top, just before
if ($vbulletin->GPC['userlist'] == 'buddy' OR $vbulletin->GPC['userlist'] == 'friend')
you'll need to add in
$numresult = $db->query_read("
SELECT COUNT(*) AS friendcount FROM " . TABLE_PREFIX . "userlist AS userlist
WHERE userlist.userid = " . $vbulletin->userinfo['userid'] . "
AND friend = 'yes'
");
$numarray = $db->fetch_array($numresult);
$myfriendcount = $numarray["friendcount"];
global $friendlimit;
Then a little further down, just inside of this if statement
if ($vbulletin->GPC['userlist'] == 'friend')
you need to add
if ($myfriendcount >= $friendlimit)
eval(print_standard_redirect("You cannot have more than $friendlimit friends.", false, true));
else
$_POST['do'] == 'doaddlist'
This code is almost identical to the previous section, and so are the pieces we're going to add.
At the beginning, just after this referrer check
if ($vbulletin->url == $vbulletin->options['forumhome'] . '.php')
{
$vbulletin->url = 'member.php?' . $vbulletin->session->vars['sessionurl'] . "u=$userinfo[userid]";
}
Add in the same query from above
$numresult = $db->query_read("
SELECT COUNT(*) AS friendcount FROM " . TABLE_PREFIX . "userlist AS userlist
WHERE userlist.userid = " . $vbulletin->userinfo['userid'] . "
AND friend = 'yes'
");
$numarray = $db->fetch_array($numresult);
$myfriendcount = $numarray["friendcount"];
global $friendlimit;
Then inside the 'friend' part of the case statement
switch ($vbulletin->GPC['userlist'])
{
case 'friend':
Add the count check again.
if ($myfriendcount >= $friendlimit)
eval(print_standard_redirect("You cannot have more than $friendlimit friends.", false, true));
$_POST['do'] == 'updatelist'
This one is a bit different than the previous two and requires more edits.
Pretty much right at the 'profile_updatelist_start' hook, add the query again:
$numresult = $db->query_read("
SELECT COUNT(*) AS friendcount FROM " . TABLE_PREFIX . "userlist AS userlist
WHERE userlist.userid = " . $vbulletin->userinfo['userid'] . "
AND friend = 'yes'
");
$numarray = $db->fetch_array($numresult);
$myfriendcount = $numarray["friendcount"];
global $friendlimit;
Then, after the last AND of this if statement, but before the closing parenthesis
if
(
$vbulletin->GPC_exists['makefriends']
AND $vbulletin->options['socnet'] & $vbulletin->bf_misc_socnet['enable_friends']
AND $vbulletin->userinfo['permissions']['genericpermissions2'] & $vbulletin->bf_ugp_genericpermissions2['canusefriends']
AND $userinfo['permissions']['genericpermissions2'] & $vbulletin->bf_ugp_genericpermissions2['canusefriends']
)
Add the line
AND $myfriendcount < $friendlimit
Now, right before this if statement
if
(
!($vbulletin->options['socnet'] & $vbulletin->bf_misc_socnet['enable_friends'])
OR !($vbulletin->userinfo['permissions']['genericpermissions2'] & $vbulletin->bf_ugp_genericpermissions2['canusefriends'])
OR !($userinfo['permissions']['genericpermissions2'] & $vbulletin->bf_ugp_genericpermissions2['canusefriends'])
OR $vbulletin->userinfo['userid'] == $userinfo['userid']
)
{
continue;
}
Add the following
if ($myfriendcount >= $friendlimit)
break;
else
Lastly, find the line
if ($vbulletin->GPC['incomingaction'] == 'accept')
And replace it with
if ($vbulletin->GPC['incomingaction'] == 'accept' && ($myfriendcount < $friendlimit))
That seems to be catching all paths to friend adding and filtering it appropriately.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.