*/ /* * File: /_inc/chat.php * Description: * This file control everything regarding actual chatting. * It is included from a chat. */ require_once('_inc/inc.php'); require_once('_inc/data/chattheme.default'); if (isset($GLOBALS['chat']['theme']) && file_exists("_inc/data/chattheme.{$GLOBALS['chat']['theme']}")) include_once("_inc/data/chattheme.{$GLOBALS['chat']['theme']}"); if (empty($_SESSION['chats'][$GLOBALS['id']]['username']) && ($_REQUEST['a'] != 'logout') && !empty($_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['autologin']) && !empty($_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['handle']) && empty($_REQUEST['handle']) && empty($_REQUEST['password'])) { $_REQUEST['handle'] = $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['handle']; $_REQUEST['password'] = $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['password']; $_REQUEST['prefs']['symbol'] = $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['symbol']; $_REQUEST['prefs']['reload'] = $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['reload']; $_REQUEST['prefs']['image'] = $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['image']; $_REQUEST['prefs']['color'] = $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['color']; $_REQUEST['prefs']['link'] = $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['link']; $_REQUEST['prefs']['icon'] = $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['icon']; $_REQUEST['autologin'] = 1; } if (!empty($_REQUEST['handle'])) CheckLogin($_REQUEST['handle'], $_REQUEST['password'], $GLOBALS['id']); $_SESSION['chats'][$GLOBALS['id']]['oldname'] = $_SESSION['chats'][$GLOBALS['id']]['username']; if (!empty($_SESSION['chats'][$GLOBALS['id']]['username']) && ($_REQUEST['p'] == 'login') && ($_REQUEST['a'] != 'logout')) { $_REQUEST['message'] = '/enter'; $_REQUEST['p'] = 'console'; } if (CheckBan()) { echo PrettyParse($GLOBALS['chattheme']['banpage']); die(); } else if (!CheckMemberOfChat() && CheckFlags($GLOBALS['chat']['flags'], 'R')) { echo PrettyParse($GLOBALS['chattheme']['notamember']); die(); } else if ( !(empty($GLOBALS['chat']['write_access']) || CheckFlags('*', $GLOBALS['chat']['write_access'].'M')) && (!empty($GLOBALS['chat']['read_access']) && !CheckFlags('*', $GLOBALS['chat']['read_access'].'M')) ) { echo PrettyParse($GLOBALS['chattheme']['notaccess']); die(); } if ($_REQUEST['prefs']['reload']) { $_REQUEST['prefs']['symbol'] = PChoose($_SESSION['chats'][$GLOBALS['id']]['saved']['symbol'], $_REQUEST['prefs']['symbol']); $_REQUEST['prefs']['image'] = PChoose($_SESSION['chats'][$GLOBALS['id']]['saved']['image'], $_REQUEST['prefs']['image']); $_REQUEST['prefs']['icon'] = PChoose($_SESSION['chats'][$GLOBALS['id']]['saved']['icon'], $_REQUEST['prefs']['icon']); $_REQUEST['prefs']['link'] = PChoose($_SESSION['chats'][$GLOBALS['id']]['saved']['link'], $_REQUEST['prefs']['link']); $_REQUEST['prefs']['color'] = PChoose($_SESSION['chats'][$GLOBALS['id']]['saved']['color'], $_REQUEST['prefs']['color']); } if (is_array($_REQUEST['prefs'])) { $uid = $_SESSION['chats'][$GLOBALS['id']]['id'] ? $_SESSION['chats'][$GLOBALS['id']]['id'] : $_SESSION['chats'][0]['id']; if (!empty($uid)) { $do = array(); if ($_SESSION['chats'][$GLOBALS['id']]['saved']['status'] != $_REQUEST['prefs']['status']) { if (empty($_REQUEST['prefs']['status'])) $do[] = 'visual_status=null'; else $do[] = "visual_status='".SQL_EscapeString($_REQUEST['prefs']['status'])."'"; $_SESSION['chats'][$GLOBALS['id']]['saved']['status'] = $_REQUEST['prefs']['status']; } if ($_SESSION['chats'][$GLOBALS['id']]['saved']['symbol'] != $_REQUEST['prefs']['symbol']) { if (empty($_REQUEST['prefs']['symbol'])) $do[] = 'visual_symbol=null'; else $do[] = "visual_symbol='".SQL_EscapeString($_REQUEST['prefs']['symbol'])."'"; $_SESSION['chats'][$GLOBALS['id']]['saved']['symbol'] = $_REQUEST['prefs']['symbol']; } if ($_SESSION['chats'][$GLOBALS['id']]['saved']['image'] != $_REQUEST['prefs']['image']) { if (empty($_REQUEST['prefs']['image'])) $do[] = 'visual_image=null'; else $do[] = "visual_image='".SQL_EscapeString($_REQUEST['prefs']['image'])."'"; $_SESSION['chats'][$GLOBALS['id']]['saved']['image'] = $_REQUEST['prefs']['image']; } if ($_SESSION['chats'][$GLOBALS['id']]['saved']['link'] != $_REQUEST['prefs']['link']) { if (empty($_REQUEST['prefs']['link'])) $do[] = 'visual_link=null'; else $do[] = "visual_link='".SQL_EscapeString($_REQUEST['prefs']['link'])."'"; $_SESSION['chats'][$GLOBALS['id']]['saved']['link'] = $_REQUEST['prefs']['link']; } if ($_SESSION['chats'][$GLOBALS['id']]['saved']['icon'] != $_REQUEST['prefs']['icon']) { if (empty($_REQUEST['prefs']['icon'])) $do[] = 'visual_icon=null'; else $do[] = "visual_icon='".SQL_EscapeString($_REQUEST['prefs']['icon'])."'"; $_SESSION['chats'][$GLOBALS['id']]['saved']['icon'] = $_REQUEST['prefs']['icon']; } if ($_SESSION['chats'][$GLOBALS['id']]['saved']['color'] != $_REQUEST['prefs']['color']) { if (empty($_REQUEST['prefs']['color'])) $do[] = 'visual_color=null'; else $do[] = "visual_color='".SQL_EscapeString($_REQUEST['prefs']['color'])."'"; $_SESSION['chats'][$GLOBALS['id']]['saved']['color'] = $_REQUEST['prefs']['color']; } if (!empty($do)) { $do = implode(',', $do); $sqlchat = $GLOBALS['id']+0; if (!empty($GLOBALS['chat']['parent'])) $sqlchat = $GLOBALS['chat']['parent']+0; SQL_EmptyQuery("UPDATE {$GLOBALS['sql_prefix']}userassoc SET {$do} WHERE id={$uid} AND chat={$sqlchat}", __FILE__.' : '.__LINE__.' : '.__FUNCTION__); } } foreach($_REQUEST['prefs'] as $key => $val) $_SESSION['chats'][$GLOBALS['id']][$key] = $val; } $_SESSION['chats'][$GLOBALS['id']]['style'] = PChoose($_SESSION['chats'][$GLOBALS['id']]['style'], $_SESSION['chats'][0]['style']); if (!is_array($_REQUEST['style'])) $_REQUEST['style'] = array(); if (!empty($_REQUEST['message']) || count($_REQUEST['style'])) { $old = $_SESSION['chats'][$GLOBALS['id']]['style']; $_SESSION['chats'][$GLOBALS['id']]['style'] = ''; foreach($_REQUEST['style'] as $key => $val) { switch($key) { case 'strike': $_SESSION['chats'][$GLOBALS['id']]['style'] .= 'S'; break; case 'bold': $_SESSION['chats'][$GLOBALS['id']]['style'] .= 'B'; break; case 'italic': $_SESSION['chats'][$GLOBALS['id']]['style'] .= 'I'; break; case 'underlined': $_SESSION['chats'][$GLOBALS['id']]['style'] .= 'U'; break; case 'fixed': $_SESSION['chats'][$GLOBALS['id']]['style'] .= 'T'; break; case 'reverse': $_SESSION['chats'][$GLOBALS['id']]['style'] .= 'R'; break; case 'no_color': $_SESSION['chats'][$GLOBALS['id']]['style'] .= 'C'; break; } } $uid = $_SESSION['chats'][$GLOBALS['id']]['id'] ? $_SESSION['chats'][$GLOBALS['id']]['id'] : $_SESSION['chats'][0]['id']; if ($uid && strcmp($old,$_SESSION['chats'][$GLOBALS['id']]['style'])) { if (!empty($_SESSION['chats'][$GLOBALS['id']]['style'])) $style = "'".SQL_EscapeString($_SESSION['chats'][$GLOBALS['id']]['style'])."'"; else $style = 'null'; SQL_EmptyQuery("UPDATE {$GLOBALS['sql_prefix']}users SET style={$style} WHERE id={$uid}", __FILE__.' : '.__LINE__.' : '.__FUNCTION__); } } $_SESSION['chats'][$GLOBALS['id']]['lasthit'] = time(); if (isset($_REQUEST['chan'])) { $_SESSION['chats'][$GLOBALS['id']]['chan'] = $_REQUEST['chan']; } $cx = count($GLOBALS['chan']); $found = false; for ($cc=0;$cc<$cx;$cc++) { if ($GLOBALS['chan'][$cc]['id'] == $_SESSION['chats'][$GLOBALS['id']]['chan']) { if (!empty($GLOBALS['chan'][$cc]['read_access']) && !CheckFlags('*', $GLOBALS['chan'][$cc]['read_access'].'M')) continue; if (!(empty($GLOBALS['chan'][$cc]['write_access']) || CheckFlags('*', $GLOBALS['chan'][$cc]['write_access'].'M'))) continue; $found = true; break; } } if (!$found) $_SESSION['chats'][$GLOBALS['id']]['chan'] = 0; // Remove expired ignores. if (is_array($_SESSION['chats'][$GLOBALS['id']]['ignore'])) { $time = time(); $cnt = count($_SESSION['chats'][$GLOBALS['id']]['ignore']); $found = false; for($cc=0;$cc<$cnt;$cc++) { if ($_SESSION['chats'][$GLOBALS['id']]['ignore'][$cc]['expire'] <= $time) { unset($_SESSION['chats'][$GLOBALS['id']]['ignore'][$cc]); $found = true; } } if ($found) sort($_SESSION['chats'][$GLOBALS['id']]['ignore']); } else { $_SESSION['chats'][$GLOBALS['id']]['ignore'] = array(); } $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['setcookie'] = true; $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['lasthit'] = ceil(time()/86400)*86400; if (is_array($_REQUEST['prefs'])) { foreach($_REQUEST['prefs'] as $key => $val) $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']][$key] = $val; } $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['handle'] = PChoose($_REQUEST['handle'], $_SESSION['chats'][$GLOBALS['id']]['username'], $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['handle'], $_SESSION['chats'][0]['username']); if (!empty($_REQUEST['autologin'])) { $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['password'] = PChoose($_SESSION['chats'][$GLOBALS['id']]['password'], $_SESSION['chats'][0]['password']); $_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['autologin'] = 'CHECKED'; if (empty($_REQUEST['prefs']['reload'])) unset($_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['reload']); } else if (!empty($_REQUEST['password'])) { unset($_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['password']); unset($_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['autologin']); unset($_COOKIE[$GLOBALS['chat_cookie_name']][$GLOBALS['id']]['reload']); } foreach($_COOKIE[$GLOBALS['chat_cookie_name']] as $key => $val) { if ($key == 0) continue; else if ($val['lasthit'] <= time()-2592000) unset($_COOKIE[$GLOBALS['chat_cookie_name']][$key]); } Cookie_Set(); // Fix ident. /* if ($_SESSION['chats'][0]['id']) { $_SESSION['chats'][$GLOBALS['id']]['ident'] = md5($_SESSION['chats'][0]['id'].'c'.$GLOBALS['id']); } else if ($_SESSION['chats'][$GLOBALS['id']]['id']) { $_SESSION['chats'][$GLOBALS['id']]['ident'] = md5($_SESSION['chats'][$GLOBALS['id']]['id'].'c'.$GLOBALS['id']); } else { $_SESSION['chats'][$GLOBALS['id']]['ident'] = md5($_SESSION['session_id'].$GLOBALS['id']); } */ $_SESSION['chats'][$GLOBALS['id']]['ident'] = substr(md5($_SESSION['session_id'].$GLOBALS['id']), 0, 8); if ($GLOBALS['chat']['s_identlength']) $_SESSION['chats'][$GLOBALS['id']]['ident'] = substr($_SESSION['chats'][$GLOBALS['id']]['ident'], 0, $GLOBALS['chat']['s_identlength']); if ($_REQUEST['a'] == 'logout') { $_REQUEST['message'] = '/exit'; } if (!empty($_REQUEST['message'])) { PostMessage(); } if (!isset($_SESSION['chats'][$GLOBALS['id']]['noimg'])) { $_SESSION['chats'][$GLOBALS['id']]['noimg'] = CheckFlags($_SESSION['chats'][$GLOBALS['id']]['prefs'], 'i'); } if (!empty($_REQUEST['noimg'])) { if ($_REQUEST['noimg'] == 'true') $_SESSION['chats'][$GLOBALS['id']]['noimg'] = true; else $_SESSION['chats'][$GLOBALS['id']]['noimg'] = false; } if (empty($_REQUEST['p'])) { echo PrettyParse($GLOBALS['chattheme']['index']); } else if (($_REQUEST['p'] == 'login') || ($_REQUEST['p'] == 'logout')) { echo PrettyParse($GLOBALS['chattheme']['login']); } else if ($_REQUEST['p'] == 'console') { echo PrettyParse($GLOBALS['chattheme']['console']); } else if ($_REQUEST['p'] == 'text') { echo PrettyParse($GLOBALS['chattheme']['textwindow']); } else if ($_REQUEST['p'] == 'userlist') { echo PrettyParse($GLOBALS['chattheme']['userlist']); } else if ($_REQUEST['p'] == 'css') { header('Content-Type: text/css'); HeaderCache(); echo PrettyParse($GLOBALS['chat']['s_css']); header('Content-Type: text/css'); } else if (preg_match('/^user[0-9]+$/', $_REQUEST['p'])) { if ($GLOBALS['chattheme'][$_REQUEST['p']]) echo PrettyParse($GLOBALS['chattheme'][$_REQUEST['p']]); } echo PrettyParse(ob_get_clean()); ?>