Sock Chat extensions

This commit is contained in:
Pachira 2015-04-28 15:53:53 +00:00
parent a83f19d245
commit 9341f904d8
5 changed files with 138 additions and 53 deletions

View file

@ -18,6 +18,7 @@ require_once $sockSakuraPath .'/sakura.php';
use sockchat\Auth;
use Sakura\Session;
use Sakura\Users;
use Sakura\SockChat;
if(Auth::getPageType() == AUTH_FETCH) {
@ -45,7 +46,7 @@ if(Auth::getPageType() == AUTH_FETCH) {
$rank = Users::getRank($user['rank_main']);
// Deny group and user id 0
if($user['id'] == 0 || $rank['id'] == 0) {
if($user['id'] == 0 || $rank['id'] == 0 || $user['password_algo'] == 'nologin') {
Auth::Deny();
Auth::Serve();
@ -53,62 +54,34 @@ if(Auth::getPageType() == AUTH_FETCH) {
}
// Set the user's data
Auth::SetUserData(
$user['id'],
$user['username'],
$user['name_colour'] == null ? $rank['colour'] : $user['name_colour']
);
switch($rank['id']) {
// Get the user's permissions
$perms = SockChat::getUserPermissions($user['id']);
default: // Fallback
case 2: // Regular User
Auth::SetCommonPermissions(
0,
USER_NORMAL,
LOGS_DISABLED,
NICK_DISABLED,
CHANNEL_CREATE_DISABLED
);
break;
case 6: // Bot
case 8: // Tenshi
case 9: // Alumni
Auth::SetCommonPermissions(
1,
USER_NORMAL,
LOGS_ENABLED,
NICK_ENABLED,
CHANNEL_CREATE_TEMP
);
break;
case 3: // Site Moderator
case 5: // Developer
case 6: // Chat Moderator
Auth::SetCommonPermissions(
($rank['id'] == 2 ? 3 : 2), // Site moderators are 3, rest is 2
USER_MODERATOR,
LOGS_ENABLED,
NICK_ENABLED,
CHANNEL_CREATE_TEMP
);
break;
case 4: // Administrator
Auth::SetCommonPermissions(
4,
USER_MODERATOR,
LOGS_ENABLED,
NICK_ENABLED,
CHANNEL_CREATE_PERM
);
break;
// Check if they can access the chat
if(!$perms['access']) {
Auth::Deny();
Auth::Serve();
exit;
}
// Set the common permissions
Auth::SetCommonPermissions(
$perms['rank'],
$perms['type'],
$perms['logs'],
$perms['nick'],
$perms['channel']
);
Auth::Accept();
} else

View file

@ -16,7 +16,8 @@
"20150427.5",
"20150427.6",
"20150427.7",
"20150427.8"
"20150427.8",
"20150428"
]
@ -804,6 +805,23 @@
"change": "Abyss'd user's names still showing up in the title of the profile."
}
],
"20150428": [
{
"type": "ADD",
"change": "Add base Sock Chat extensions."
},
{
"type": "REM",
"change": "Removed remains of old templating system."
},
{
"type": "UPD",
"change": "Move Sock Chat permissioning to database as opposed to a static file."
}
]
}

View file

@ -7,9 +7,8 @@ namespace Sakura;
class Main {
public static $_TPL;
public static $_MD;
public static $_IN_MANAGE = false;
public static $_MD; // Markdown class container
public static $_IN_MANAGE = false; // Manage thing
// Constructor
public static function init($config) {

View file

@ -2,11 +2,105 @@
/*
* Sock Chat extensions
*/
namespace Sakura;
class SockChat {
// Permission indexes
public static $_PERMS_ACCESS_INDEX = 0;
public static $_PERMS_RANK_INDEX = 1;
public static $_PERMS_TYPE_INDEX = 2;
public static $_PERMS_LOGS_INDEX = 3;
public static $_PERMS_NICK_INDEX = 4;
public static $_PERMS_CHANNEL_INDEX = 5;
// Fallback permission row
public static $_PERMS_FALLBACK = [1, 0, 0, 0, 0, 0];
// Get all permission data
public static function getAllPermissions() {
// Get all data from the permissions table
$perms = Database::fetch('sock_perms');
// Parse permission string
foreach($perms as $id => $perm)
$perms[$id]['perms'] = self::parsePerms($perm['perms']);
// Return the permission data
return $perms;
}
// Get permission data for a specific rank
public static function getRankPermissions($rid) {
// Get data by rank id from permissions table
$perms = Database::fetch('sock_perms', false, ['rid' => [$rid, '='], 'uid' => [0, '=']]);
// Check if we got a row back
if(empty($perms)) {
$perms = [
'rid' => 0,
'uid' => 0,
'perms' => self::$_PERMS_FALLBACK
];
}
// Parse permission string
$perms = self::parsePerms($perms['perms']);
// Return the permission data
return $perms;
}
// Get all rank permission data
public static function getUserPermissions($uid) {
// Get data by user id from permissions table
$perms = Database::fetch('sock_perms', false, ['uid' => [$uid, '='], 'rid' => [0, '=']]);
// Check if we got a row back
if(empty($perms)) {
// If we didn't get the user's rank account row
$user = Users::getUser($uid);
// Then return the data for their rank
return self::getRankPermissions($user['rank_main']);
}
// Parse permission string
$perms = self::parsePerms($perms['perms']);
// Return the permission data
return $perms;
}
// Parse permission string
public static function parsePerms($perms) {
// Explode the commas
$exploded = is_array($perms) ? $perms : explode(',', $perms);
// "Reset" $perms
$perms = array();
// Put the data in the correct order
$perms['access'] = $exploded[ self::$_PERMS_ACCESS_INDEX ];
$perms['rank'] = $exploded[ self::$_PERMS_RANK_INDEX ];
$perms['type'] = $exploded[ self::$_PERMS_TYPE_INDEX ];
$perms['logs'] = $exploded[ self::$_PERMS_LOGS_INDEX ];
$perms['nick'] = $exploded[ self::$_PERMS_NICK_INDEX ];
$perms['channel'] = $exploded[ self::$_PERMS_CHANNEL_INDEX ];
// Return formatted permissions array
return $perms;
}
}

View file

@ -8,7 +8,7 @@
namespace Sakura;
// Define Sakura version
define('SAKURA_VERSION', '20150427.8');
define('SAKURA_VERSION', '20150428');
define('SAKURA_VLABEL', 'Heliotrope');
define('SAKURA_VTYPE', 'Development');
define('SAKURA_COLOUR', '#DF73FF');
@ -36,6 +36,7 @@ require_once ROOT .'_sakura/components/Templates.php';
require_once ROOT .'_sakura/components/Sessions.php';
require_once ROOT .'_sakura/components/Users.php';
require_once ROOT .'_sakura/components/Whois.php';
require_once ROOT .'_sakura/components/SockChat.php';
// Generate path to database driver
$_DBNGNPATH = ROOT .'_sakura/components/database/'. $sakuraConf['db']['driver'] .'.php';