|
From: OryNider <ory...@us...> - 2008-02-28 06:27:39
|
Update of /cvsroot/mxbb/mx_radio/includes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21483/mx_radio/includes Modified Files: common.php Log Message: cvs commit test Index: common.php =================================================================== RCS file: /cvsroot/mxbb/mx_radio/includes/common.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** common.php 8 Feb 2008 23:43:41 -0000 1.2 --- common.php 28 Feb 2008 06:26:35 -0000 1.3 *************** *** 8,13 **** * */ - - /*************************************************************************** * History: --- 8,11 ---- *************** *** 18,22 **** * ***************************************************************************/ - // // Security check --- 16,19 ---- *************** *** 30,41 **** // mx_radio version... // ! define('_radio_VERSION', "mx_radio v 1.0 RC 2"); // // Define table names. // ! define('RADIO_CONFIG_TABLE', $mx_table_prefix.'radio_config'); ! define('RADIO_SESSION_TABLE', $mx_table_prefix.'radio_session'); // --- 27,43 ---- // mx_radio version... // ! @define('_radio_VERSION', "mx_radio v 1.0.0"); // // Define table names. // + @define('RADIO_CONFIG_TABLE', $mx_table_prefix.'radio_config'); + @define('RADIO_SESSION_TABLE', $mx_table_prefix.'radio_session'); ! //Check for shotcast version ! if( file_exists($mx_root_path . "modules/mx_shotcast/includes/common.$phpEx") ) ! { ! !defined('SHOTCAST_SESSION_TABLE') ? define('SHOTCAST_SESSION_TABLE', $mx_table_prefix.'shotcast_session') : false; ! } // *************** *** 50,53 **** --- 52,56 ---- include($module_root_path . 'language/lang_english/lang_admin.' . $phpEx); } + //Load main laguage file if( file_exists($module_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx) ) { *************** *** 62,68 **** // Common definitions... // ! $cfg_radioname = $board_config['sitename'] . ' -> ' . 'radio'; // ================================================================================ --- 65,93 ---- // Common definitions... // ! $time = date("U"); $cfg_radioname = $board_config['sitename'] . ' -> ' . 'radio'; + if(empty($user_ip)) + { + $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : getenv('REMOTE_ADDR') ); + $user_ip = phpBB2::encode_ip($client_ip); + } + + $user_id = $userdata['user_id']; + $nick = str_replace(" ", "_", $userdata['username']); + $radio_bot_id = ANONYMOUS; + + if (($userdata['user_id'] != ANONYMOUS) && defined('ONLINE_ADV_SESSION_TABLE')) + { + if($this_agent) + { + $nick = $this_agent; + } + + if ($this_bot_id) + { + $radio_bot_id = $this_bot_id; + } + } // ================================================================================ *************** *** 81,89 **** if( !($result = $db->sql_query($sql)) ) { ! message_die(GENERAL_ERROR, "Couldn't query radio config table", "", __LINE__, __FILE__, $sql); } else { ! while( $row = $db->sql_fetchrow($result) ) { $radio_config[$row['config_name']] = $row['config_value']; --- 106,114 ---- if( !($result = $db->sql_query($sql)) ) { ! mx_message_die(GENERAL_ERROR, "Couldn't query radio config table", "", __LINE__, __FILE__, $sql); } else { ! while($row = $db->sql_fetchrow($result)) { $radio_config[$row['config_name']] = $row['config_value']; *************** *** 92,151 **** } // ================================================================================ // [ COMMON FUNCTIONS ] // ================================================================================ - $nick = str_replace(" ", "_", $userdata['username']); - function user_listen($nick) { ! global $radio_config, $db; ! $current_time=date("U"); ! $sql = "DELETE FROM ".RADIO_SESSION_TABLE." WHERE username = '".addslashes($nick)."'"; ! if( !$result = $db->sql_query($sql) ) { ! die("SQL Error in function user_listen(): DELETE<br />" . $sql); } ! $sql = "INSERT INTO ".RADIO_SESSION_TABLE." (username, time)" . ! " VALUES ('" .addslashes($nick). "', ".$current_time.")"; ! if( !$result = $db->sql_query($sql) ) { ! die("SQL Error in function user_listen(): INSERT<br />" . $sql); } } //Update user statue "listening/not listening" ! function update_radio_users($nick,$time) { ! global $radio_config, $board_config, $db, $lang; ! ! $sql="update ".RADIO_SESSION_TABLE." set time='$time' where username='$nick'"; ! if( !$result = $db->sql_query($sql) ) { ! die("SQL Error in function update_radio_users(): UPDATE<br />" . $sql); } } function drop_radio_users($period) { ! global $radio_config, $board_config, $db, $lang; ! $current_time=date("U"); //prevent delay ! $period=$period+2; // Calcul max_time ! $max_time=$current_time-$period; ! ! $sql="delete from ".RADIO_SESSION_TABLE." where time<'$max_time'"; ! if( !$result = $db->sql_query($sql) ) ! { ! die("SQL Error in function drop_radio_users()"); ! } } ! ?> \ No newline at end of file --- 117,205 ---- } + //read check period + $period = $radio_config['check_period'] * 1000; + // ================================================================================ // [ COMMON FUNCTIONS ] // ================================================================================ function user_listen($nick) { ! global $userdata, $radio_config, $db, $user_ip, $radio_bot_id; ! $current_time = date("U"); ! $user_id = $userdata['user_id']; ! ! $sql = "DELETE FROM " . RADIO_SESSION_TABLE . " ! WHERE session_ip = '" . $user_ip . "'"; ! if(!$result = $db->sql_query($sql)) { ! mx_message_die(CRITICAL_ERROR, 'SQL Error in function user_listen(): DELETE<br />', '', __LINE__, __FILE__, $sql); } ! ! $sql = "INSERT INTO " . RADIO_SESSION_TABLE . " ! (user_id, username, time, session_ip, bot_id) ! VALUES ('$user_id', '" . addslashes($nick) . "', '$current_time', '$user_ip', '$radio_bot_id')"; ! if(!$result = $db->sql_query($sql)) { ! mx_message_die(CRITICAL_ERROR, 'SQL Error in function user_listen(): INSERT INTO<br />', '', __LINE__, __FILE__, $sql); } } //Update user statue "listening/not listening" ! function update_radio_users($nick) { ! global $radio_config, $db, $lang, $user_ip, $radio_bot_id; ! ! $time = date("U"); ! $user_id = $userdata['user_id']; ! $sql = "UPDATE " . RADIO_SESSION_TABLE . " ! SET time = $time ! WHERE session_ip = '" . $user_ip . "'"; ! if(!$result = $db->sql_query($sql)) { ! $sql = "UPDATE " . RADIO_SESSION_TABLE . " ! SET time = $time ! WHERE username = '" . $nick . "'"; ! $db->sql_query($sql); } + /* + if(defined('SHOTCAST_SESSION_TABLE')) + { + $sql = "DELETE FROM " . SHOTCAST_SESSION_TABLE . " + WHERE user_id = '" . $user_id . "' + AND session_ip = '$user_ip'"; + $db->sql_query($sql); + $sql = "INSERT INTO " . SHOTCAST_SESSION_TABLE . " + (user_id, username, time, session_ip, bot_id) + VALUES ('$user_id', '" . addslashes($nick) . "', '$time', '$user_ip', '$radio_bot_id')"; + $db->sql_query($sql); + } + */ } function drop_radio_users($period) { ! global $radio_config, $db, $lang; ! $current_time = date("U"); //prevent delay ! $period = $period + 2; // Calcul max_time ! $max_time = $current_time - $period; ! $sql = "DELETE from " . RADIO_SESSION_TABLE . " ! WHERE time < '$max_time'"; ! if(!$result = $db->sql_query($sql)) ! { ! mx_message_die(CRITICAL_ERROR, 'SQL Error in function drop_radio_users()', '', __LINE__, __FILE__, $sql); ! } } ! ! // REMOVE OLD SESSIONS ! drop_radio_users($radio_config['check_period']); ! ?> |