User impl update
This commit is contained in:
parent
c51f1847ca
commit
58e5eaaa94
|
|
@ -2,10 +2,32 @@
|
||||||
|
|
||||||
namespace Alphaland\Users {
|
namespace Alphaland\Users {
|
||||||
|
|
||||||
|
use Alphaland\Assets\Asset;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
|
public static function UserExists(int $userid)
|
||||||
|
{
|
||||||
|
$get = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM users WHERE id = :i");
|
||||||
|
$get->bindParam(":i", $userid, PDO::PARAM_INT);
|
||||||
|
$get->execute();
|
||||||
|
if($get->fetchColumn() > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function GetUserInfo(int $userid)
|
||||||
|
{
|
||||||
|
$user = $GLOBALS['pdo']->prepare("SELECT * FROM users WHERE id = :u");
|
||||||
|
$user->bindParam(":u", $userid, PDO::PARAM_STR);
|
||||||
|
$user->execute();
|
||||||
|
if($user->rowCount() > 0) {
|
||||||
|
return $user->fetch(PDO::FETCH_OBJ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function ValidatePassword(int $userid, string $password)
|
public static function ValidatePassword(int $userid, string $password)
|
||||||
{
|
{
|
||||||
$userpassword = $GLOBALS['pdo']->prepare("SELECT pwd FROM users WHERE id = :i");
|
$userpassword = $GLOBALS['pdo']->prepare("SELECT pwd FROM users WHERE id = :i");
|
||||||
|
|
@ -66,5 +88,90 @@ namespace Alphaland\Users {
|
||||||
}
|
}
|
||||||
return $wearingassets;
|
return $wearingassets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function SetCanJoinUser(int $userid, int $status)
|
||||||
|
{
|
||||||
|
if ($status <= 2) {
|
||||||
|
$setstatus = $GLOBALS['pdo']->prepare("UPDATE users SET canJoin = :c WHERE id = :u");
|
||||||
|
$setstatus->bindParam(":c", $status, PDO::PARAM_INT);
|
||||||
|
$setstatus->bindParam(":u", $userid, PDO::PARAM_INT);
|
||||||
|
$setstatus->execute();
|
||||||
|
if ($setstatus->rowCount() > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function CanJoinUser(int $targetuser) //TODO: fix when friends class is implemented
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
0 = no one
|
||||||
|
1 = friends
|
||||||
|
2 = everyone
|
||||||
|
*/
|
||||||
|
|
||||||
|
$canjoin = User::GetUserInfo($targetuser)->canJoin;
|
||||||
|
if($canjoin == 1) {
|
||||||
|
if (friendsWith($targetuser)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if ($canjoin == 2) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function SiteStatus(int $userid)
|
||||||
|
{
|
||||||
|
$p = $GLOBALS['pdo']->prepare("SELECT * FROM game_presence WHERE uid = :i AND (lastPing + 50) > UNIX_TIMESTAMP()");
|
||||||
|
$p->bindParam(":i", $userid, PDO::PARAM_INT);
|
||||||
|
$p->execute();
|
||||||
|
$userinfo = User::GetUserInfo($userid);
|
||||||
|
|
||||||
|
if($p->rowCount() > 0) {
|
||||||
|
if (User::CanJoinUser($userinfo->id)) {
|
||||||
|
return cleanOutput(Asset::GetAssetInfo($p->fetch(PDO::FETCH_OBJ)->placeid)->Name);
|
||||||
|
} else {
|
||||||
|
return 'In-Game';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (($userinfo->lastseen + 120) > time()) {
|
||||||
|
return 'Online';
|
||||||
|
} else {
|
||||||
|
return 'Offline';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function UserPlaying(int $userid)
|
||||||
|
{
|
||||||
|
$p = $GLOBALS['pdo']->prepare("SELECT * FROM game_presence WHERE uid = :i AND (lastPing + 50) > UNIX_TIMESTAMP()");
|
||||||
|
$p->bindParam(":i", $userid, PDO::PARAM_INT);
|
||||||
|
$p->execute();
|
||||||
|
|
||||||
|
if($p->rowCount() > 0) {
|
||||||
|
if (User::CanJoinUser($userid)) {
|
||||||
|
$playingInfo = $p->fetch(PDO::FETCH_OBJ);
|
||||||
|
return array (
|
||||||
|
"placeid" => $playingInfo->placeid,
|
||||||
|
"jobid" => $playingInfo->jobid
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array (
|
||||||
|
"placeid" => null,
|
||||||
|
"jobid" => null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function IsInventoryPrivate(int $userid)
|
||||||
|
{
|
||||||
|
if (User::GetUserInfo($userid)->privateInventory && !$GLOBALS['user']->IsAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2073,40 +2073,6 @@ function playerOwnsAsset($id, $userid=NULL)
|
||||||
|
|
||||||
//user functions
|
//user functions
|
||||||
|
|
||||||
function userPlaying($userid)
|
|
||||||
{
|
|
||||||
$p = $GLOBALS['pdo']->prepare("SELECT * FROM game_presence WHERE uid = :i AND (lastPing + 50) > UNIX_TIMESTAMP()");
|
|
||||||
$p->bindParam(":i", $userid, PDO::PARAM_INT);
|
|
||||||
$p->execute();
|
|
||||||
|
|
||||||
if($p->rowCount() > 0) //if the ingame check has any results
|
|
||||||
{
|
|
||||||
if (canJoinUser($userid))
|
|
||||||
{
|
|
||||||
$playingInfo = $p->fetch(PDO::FETCH_OBJ);
|
|
||||||
$info = array (
|
|
||||||
"placeid" => $playingInfo->placeid,
|
|
||||||
"jobid" => $playingInfo->jobid
|
|
||||||
);
|
|
||||||
return $info;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$info = array (
|
|
||||||
"placeid" => null,
|
|
||||||
"jobid" => null
|
|
||||||
);
|
|
||||||
return $info;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isUserInventoryPrivate($userid)
|
|
||||||
{
|
|
||||||
if(userInfo($userid)->privateInventory && !$GLOBALS['user']->IsAdmin())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function chatFilterInfractionLimit($userid, $limit, $seconds)
|
function chatFilterInfractionLimit($userid, $limit, $seconds)
|
||||||
{
|
{
|
||||||
$infractions = $GLOBALS['pdo']->prepare("SELECT * FROM chat_logs WHERE whoSent = :uid AND (whenSent + :seconds) > UNIX_TIMESTAMP() AND trippedFilter = 1");
|
$infractions = $GLOBALS['pdo']->prepare("SELECT * FROM chat_logs WHERE whoSent = :uid AND (whenSent + :seconds) > UNIX_TIMESTAMP() AND trippedFilter = 1");
|
||||||
|
|
@ -2132,50 +2098,6 @@ function kickUserIfInGame($userid, $message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function siteStatus($userid)
|
|
||||||
{
|
|
||||||
$p = $GLOBALS['pdo']->prepare("SELECT * FROM game_presence WHERE uid = :i AND (lastPing + 50) > UNIX_TIMESTAMP()");
|
|
||||||
$p->bindParam(":i", $userid, PDO::PARAM_INT);
|
|
||||||
$p->execute();
|
|
||||||
|
|
||||||
$userinfo = $GLOBALS['pdo']->prepare('SELECT * FROM `users` WHERE id = :uid');
|
|
||||||
$userinfo->bindParam(':uid', $userid, PDO::PARAM_INT);
|
|
||||||
$userinfo->execute();
|
|
||||||
$userinfo = $userinfo->fetch(PDO::FETCH_OBJ);
|
|
||||||
|
|
||||||
if($p->rowCount() > 0) //if the ingame check has any results
|
|
||||||
{
|
|
||||||
$serverInfo = $p->fetch(PDO::FETCH_OBJ);
|
|
||||||
|
|
||||||
$g = $GLOBALS['pdo']->prepare("SELECT * FROM assets WHERE id = :i");
|
|
||||||
$g->bindParam(":i", $serverInfo->placeid, PDO::PARAM_INT);
|
|
||||||
$g->execute();
|
|
||||||
|
|
||||||
$gameInfo = $g->fetch(PDO::FETCH_OBJ);
|
|
||||||
|
|
||||||
if (canJoinUser($userinfo->id)) //depending on the user's settings, show what game they are playing (might wanna also pass the userID variable if there are options such as everyone, friends only, etc)
|
|
||||||
{
|
|
||||||
//user viewing profile has permission to see what game they are in
|
|
||||||
return cleanOutput($gameInfo->Name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//no perms
|
|
||||||
return 'In-Game';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else //if no ingame result, check if the user has pinged the site in a while
|
|
||||||
{
|
|
||||||
if (($userinfo->lastseen + 120) > time())
|
|
||||||
{
|
|
||||||
return 'Online';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 'Offline';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
//friend request button check
|
//friend request button check
|
||||||
|
|
@ -2258,23 +2180,6 @@ function placeAssetComment($aid, $comment) //1 = comment placed, 2 = cooldown, 3
|
||||||
|
|
||||||
//canjoin stuff {
|
//canjoin stuff {
|
||||||
|
|
||||||
function setCanJoinUser($status)
|
|
||||||
{
|
|
||||||
$localuser = $GLOBALS['user']->id;
|
|
||||||
$maxcanjoinstatus = 2;
|
|
||||||
|
|
||||||
if ($status <= $maxcanjoinstatus)
|
|
||||||
{
|
|
||||||
$setstatus = $GLOBALS['pdo']->prepare("UPDATE users SET canJoin = :c WHERE id = :u");
|
|
||||||
$setstatus->bindParam(":c", $status, PDO::PARAM_INT);
|
|
||||||
$setstatus->bindParam(":u", $localuser, PDO::PARAM_INT);
|
|
||||||
$setstatus->execute();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function canJoinUser($uid) //
|
function canJoinUser($uid) //
|
||||||
{
|
{
|
||||||
$canjoinstatusquery = $GLOBALS['pdo']->prepare("SELECT canJoin FROM users WHERE id = :i");
|
$canjoinstatusquery = $GLOBALS['pdo']->prepare("SELECT canJoin FROM users WHERE id = :i");
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@ Alphaland 2021
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//headers
|
//headers
|
||||||
|
|
||||||
|
use Alphaland\Users\User;
|
||||||
|
|
||||||
header("Access-Control-Allow-Origin: https://www.alphaland.cc");
|
header("Access-Control-Allow-Origin: https://www.alphaland.cc");
|
||||||
|
|
||||||
header("access-control-allow-credentials: true");
|
header("access-control-allow-credentials: true");
|
||||||
|
|
@ -19,5 +22,5 @@ else
|
||||||
{
|
{
|
||||||
$privacy = $data->preference;
|
$privacy = $data->preference;
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
echo json_encode(array("success" => setCanJoinUser($privacy)));
|
echo json_encode(array("success" => User::SetCanJoinUser($user->id, $privacy)));
|
||||||
}
|
}
|
||||||
|
|
@ -6,6 +6,9 @@ Alphaland 2021
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//headers
|
//headers
|
||||||
|
|
||||||
|
use Alphaland\Users\User;
|
||||||
|
|
||||||
header("Access-Control-Allow-Origin: https://www.alphaland.cc");
|
header("Access-Control-Allow-Origin: https://www.alphaland.cc");
|
||||||
|
|
||||||
header("access-control-allow-credentials: true");
|
header("access-control-allow-credentials: true");
|
||||||
|
|
@ -84,7 +87,7 @@ foreach($shouts as $shout)
|
||||||
//{
|
//{
|
||||||
$whenshout = date("m/d/Y", $timestamp);
|
$whenshout = date("m/d/Y", $timestamp);
|
||||||
//}
|
//}
|
||||||
$sitestatus = siteStatus($userid);
|
$sitestatus = User::SiteStatus($user->id);
|
||||||
|
|
||||||
$shoutInfo = array(
|
$shoutInfo = array(
|
||||||
"userid" => $userid,
|
"userid" => $userid,
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@ Alphaland 2021
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//headers
|
//headers
|
||||||
|
|
||||||
|
use Alphaland\Users\User;
|
||||||
|
|
||||||
header("Access-Control-Allow-Origin: https://www.alphaland.cc");
|
header("Access-Control-Allow-Origin: https://www.alphaland.cc");
|
||||||
|
|
||||||
header("access-control-allow-credentials: true");
|
header("access-control-allow-credentials: true");
|
||||||
|
|
@ -37,14 +40,14 @@ $usershout = userShout($userquery->id);
|
||||||
$blurb = cleanOutput($userquery->blurb);
|
$blurb = cleanOutput($userquery->blurb);
|
||||||
$joindate = date("m/d/Y", $userquery->joindate);
|
$joindate = date("m/d/Y", $userquery->joindate);
|
||||||
$placevisits = userPlaceVisits($userquery->id);
|
$placevisits = userPlaceVisits($userquery->id);
|
||||||
$privateinventory = isUserInventoryPrivate($userquery->id);
|
$privateinventory = User::IsInventoryPrivate($userquery->id);
|
||||||
$playerender = getPlayerRender($userquery->id);
|
$playerender = getPlayerRender($userquery->id);
|
||||||
$playingInfo = userPlaying($userquery->id);
|
$playingInfo = User::UserPlaying($userquery->id);
|
||||||
|
|
||||||
$userInfo = array (
|
$userInfo = array (
|
||||||
array(
|
array(
|
||||||
"userid" => $userquery->id,
|
"userid" => $userquery->id,
|
||||||
"siteStatus" => siteStatus($userquery->id),
|
"siteStatus" => User::SiteStatus($userquery->id),
|
||||||
"gameAssetId" => $playingInfo['placeid'],
|
"gameAssetId" => $playingInfo['placeid'],
|
||||||
"gameJobId" => $playingInfo['jobid'],
|
"gameJobId" => $playingInfo['jobid'],
|
||||||
"username" => $username,
|
"username" => $username,
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@ TODO: UNGHETTO
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//headers
|
//headers
|
||||||
|
|
||||||
|
use Alphaland\Users\User;
|
||||||
|
|
||||||
header("Access-Control-Allow-Origin: https://www.alphaland.cc");
|
header("Access-Control-Allow-Origin: https://www.alphaland.cc");
|
||||||
header("access-control-allow-credentials: true");
|
header("access-control-allow-credentials: true");
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
|
@ -88,7 +91,7 @@ foreach($items as $item)
|
||||||
}
|
}
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
if (!isUserInventoryPrivate($userid)) {
|
if (!User::IsInventoryPrivate($userid)) {
|
||||||
die(json_encode($jsonData));
|
die(json_encode($jsonData));
|
||||||
} else {
|
} else {
|
||||||
die(json_encode(["message"=>"User's inventory is private"]));
|
die(json_encode(["message"=>"User's inventory is private"]));
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@ Alphaland 2021
|
||||||
|
|
||||||
|
|
||||||
//headers
|
//headers
|
||||||
|
|
||||||
|
use Alphaland\Users\User;
|
||||||
|
|
||||||
header("Access-Control-Allow-Origin: https://www.alphaland.cc");
|
header("Access-Control-Allow-Origin: https://www.alphaland.cc");
|
||||||
|
|
||||||
header("access-control-allow-credentials: true");
|
header("access-control-allow-credentials: true");
|
||||||
|
|
@ -70,7 +73,7 @@ foreach($users as $user)
|
||||||
$id = $user['id'];
|
$id = $user['id'];
|
||||||
$username = $user['username'];
|
$username = $user['username'];
|
||||||
$blurb = cleanOutput($user['blurb'], false); //pass false to not add html linebreaks
|
$blurb = cleanOutput($user['blurb'], false); //pass false to not add html linebreaks
|
||||||
$sitestatus = siteStatus($id);
|
$sitestatus = User::SiteStatus($id);
|
||||||
$lastseen = date("m/d/Y", $user['lastseen']);
|
$lastseen = date("m/d/Y", $user['lastseen']);
|
||||||
$thumbnail = getPlayerRender($user['id']);
|
$thumbnail = getPlayerRender($user['id']);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue