simplify parse_sessions() and write_new_session()
This commit is contained in:
71
chat.php
71
chat.php
@ -2000,27 +2000,28 @@ function create_session($setup){
|
|||||||
|
|
||||||
function write_new_session(){
|
function write_new_session(){
|
||||||
global $I, $P, $U, $db;
|
global $I, $P, $U, $db;
|
||||||
$lines=parse_sessions();
|
parse_sessions();
|
||||||
$sids; $reentry=false;
|
$stmt=$db->prepare('SELECT * FROM ' . PREFIX . 'sessions WHERE nickname=?;');
|
||||||
foreach($lines as $temp){
|
$stmt->execute(array($U['nickname']));
|
||||||
$sids[$temp['session']]=true;// collect all existing ids
|
if($temp=$stmt->fetch(PDO::FETCH_ASSOC)){
|
||||||
if($temp['nickname']===$U['nickname']){// nick already here?
|
if($U['passhash']===$temp['passhash']){
|
||||||
if($U['passhash']===$temp['passhash']){
|
$U=$temp;
|
||||||
$U=$temp;
|
if($U['status']==0){
|
||||||
if($U['status']==0){
|
setcookie(COOKIENAME, false);
|
||||||
setcookie(COOKIENAME, false);
|
send_error("$I[kicked]<br>$U[kickmessage]");
|
||||||
send_error("$I[kicked]<br>$U[kickmessage]");
|
|
||||||
}
|
|
||||||
setcookie(COOKIENAME, $U['session']);
|
|
||||||
$reentry=true;
|
|
||||||
break;
|
|
||||||
}else{
|
|
||||||
send_error("$I[userloggedin]<br>$I[wrongpass]");
|
|
||||||
}
|
}
|
||||||
|
setcookie(COOKIENAME, $U['session']);
|
||||||
|
$reentry=true;
|
||||||
|
}else{
|
||||||
|
send_error("$I[userloggedin]<br>$I[wrongpass]");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$sids=[];
|
||||||
|
// create new session
|
||||||
|
$stmt=$db->query('SELECT session FROM ' . PREFIX . 'sessions;');
|
||||||
|
while($temp=$stmt->fetch(PDO::FETCH_ASSOC)){
|
||||||
|
$sids[$temp['session']]=true;// collect all existing ids
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// create new session:
|
|
||||||
if(!$reentry){
|
|
||||||
do{
|
do{
|
||||||
$U['session']=md5(time().mt_rand().$U['nickname']);
|
$U['session']=md5(time().mt_rand().$U['nickname']);
|
||||||
}while(isSet($sids[$U['session']]));// check for hash collision
|
}while(isSet($sids[$U['session']]));// check for hash collision
|
||||||
@ -2234,6 +2235,7 @@ function get_nowchatting(){
|
|||||||
|
|
||||||
function parse_sessions(){
|
function parse_sessions(){
|
||||||
global $P, $U, $countmods, $db;
|
global $P, $U, $countmods, $db;
|
||||||
|
// delete old sessions
|
||||||
$guestexpire=time()-60*get_setting('guestexpire');
|
$guestexpire=time()-60*get_setting('guestexpire');
|
||||||
$memberexpire=time()-60*get_setting('memberexpire');
|
$memberexpire=time()-60*get_setting('memberexpire');
|
||||||
$result=$db->prepare('SELECT nickname, status FROM ' . PREFIX . 'sessions WHERE (status<=2 AND lastpost<?) OR (status>2 AND lastpost<?);');
|
$result=$db->prepare('SELECT nickname, status FROM ' . PREFIX . 'sessions WHERE (status<=2 AND lastpost<?) OR (status>2 AND lastpost<?);');
|
||||||
@ -2253,31 +2255,26 @@ function parse_sessions(){
|
|||||||
}
|
}
|
||||||
$db->exec('DELETE FROM ' . PREFIX . "messages WHERE poster='' AND recipient='' AND poststatus=9;");
|
$db->exec('DELETE FROM ' . PREFIX . "messages WHERE poster='' AND recipient='' AND poststatus=9;");
|
||||||
}
|
}
|
||||||
$result=$db->query('SELECT * FROM ' . PREFIX . 'sessions ORDER BY status DESC, lastpost DESC;');
|
// look for our session
|
||||||
if(!$lines=$result->fetchAll(PDO::FETCH_ASSOC)){
|
|
||||||
$lines=array();
|
|
||||||
}
|
|
||||||
if(isSet($_REQUEST['session'])){
|
if(isSet($_REQUEST['session'])){
|
||||||
foreach($lines as $temp){
|
$stmt=$db->prepare('SELECT * FROM ' . PREFIX . 'sessions WHERE session=?;');
|
||||||
if($temp['session']===$_REQUEST['session']){
|
$stmt->execute(array($_REQUEST['session']));
|
||||||
$U=$temp;
|
if($tmp=$stmt->fetch(PDO::FETCH_ASSOC)){
|
||||||
break;
|
$U=$tmp;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// load other sessions
|
||||||
$countmods=0;
|
$countmods=0;
|
||||||
$P=array();
|
$P=array();
|
||||||
foreach($lines as $temp){
|
$stmt=$db->query('SELECT nickname, style, status, incognito FROM ' . PREFIX . 'sessions WHERE entry!=0 AND status>0 ORDER BY status DESC, lastpost DESC;');
|
||||||
if($temp['entry']!=0 && $temp['status']>0){
|
while($temp=$stmt->fetch(PDO::FETCH_ASSOC)){
|
||||||
if(!$temp['incognito']){
|
if(!$temp['incognito']){
|
||||||
$P[$temp['nickname']]=[$temp['nickname'], $temp['style'], $temp['status']];
|
$P[$temp['nickname']]=[$temp['nickname'], $temp['style'], $temp['status']];
|
||||||
}
|
}
|
||||||
if($temp['status']>=5){
|
if($temp['status']>=5){
|
||||||
++$countmods;
|
++$countmods;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $lines;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// member handling
|
// member handling
|
||||||
|
Reference in New Issue
Block a user