From: Lo?c C. <lo...@us...> - 2001-04-04 23:52:40
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/commands In directory usw-pr-cvs1:/tmp/cvs-serv23458/lib/commands Added Files: whois.cmd.php3 history.cmd.php3 banish.cmd.php3 announce.cmd.php3 Log Message: First working commands :) --- NEW FILE --- <?php // // +--------------------------------------------------------------------------+ // | phpMyChat version 0.15.0 | // +--------------------------------------------------------------------------+ // | Copyright (c) 2000-2001 The phpHeaven-team | // +--------------------------------------------------------------------------+ // | This library does the work associated to the 'whois' command. | // | | // | It is called by the 'commands.lib.php3' script. | // +--------------------------------------------------------------------------+ // | From the phpMyChat project: | // | http://www.phpheaven.net/projects/phpMyChat/ | // | | // | Authors: the phpHeaven-team <php...@ya...> | // +--------------------------------------------------------------------------+ // // $Id: whois.cmd.php3,v 1.1 2001/04/04 23:52:33 loic1 Exp $ // // The work for the 'whois' command. // /** * Check for invalid characters in the target user name */ if (ereg('[\, ]', $cmd[1])) { $error = L_ERR_USR_16; } /** * Do the work */ else { $isCommand = true; $slashedTarget = pmcSlashSingleQuotes($cmd[1]); // Check if the user whose profile is required is a registered one $dbLink->query("SELECT COUNT(*) FROM " . C_REG_TBL . " WHERE username='" . $slashedTarget . "' LIMIT 1"); list($isProfile) = $dbLink->nextRecord(); $dbLink->cleanResults(); // Not a registered users -> show IP if the current user is administrator // or moderator of the current room if (!$isProfile) { $error = sprintf(L_NONREG_USER, $cmd[1]); if ($dbSessionVars['status'] == 'a' || $dbSessionVars['status'] == 'm') { $dbLink->query("SELECT ip FROM " . C_USR_TBL . " WHERE username='" . $slashedTarget . "' LIMIT 1"); list($ip) = $dbLink->nextRecord(); if ($ip != '') { if (substr($ip, 0, 1) == 'p') $ip = substr($ip, 1) . ' (proxy)'; $error .= '\n' . sprintf(L_NONREG_USER_IP, $ip); } $dbLink->cleanResults(); } } // end of 'not a registered user' // It's a registered user -> define the script to launch the 'whois' popup else { $isPopup = true; $winName = 'whois_popup_' . uniqid(''); $whoisUrl = 'whois_popup.' . C_EXTENSION . '?' . dbSessionSID('GET') . $pmcQueryArgSeparator . 'whoisTarget=' . $cmd[1]; $jsToRun = array( '<script type="text/javascript" language="javascript">', '<!--', '// Lauch the whois popup', 'window.open(\'' . $whoisUrl . '\', \'' . $winName . '\', \'width=420,height=240,resizable=yes,scrollbars=yes\');', '// -->', '</script>' ); } } ?> --- NEW FILE --- <?php // // +--------------------------------------------------------------------------+ // | phpMyChat version 0.15.0 | // +--------------------------------------------------------------------------+ // | Copyright (c) 2000-2001 The phpHeaven-team | // +--------------------------------------------------------------------------+ // | This library does the work associated to the 'history' command. | // | | // | It is called by the 'commands.lib.php3' script. | // +--------------------------------------------------------------------------+ // | From the phpMyChat project: | // | http://www.phpheaven.net/projects/phpMyChat/ | // | | // | Authors: the phpHeaven-team <php...@ya...> | // +--------------------------------------------------------------------------+ // // $Id: history.cmd.php3,v 1.1 2001/04/04 23:52:33 loic1 Exp $ // // The work for the 'history' command. // /** * Just modify some variables */ $isCommand = true; $displayMessage = true; ?> --- NEW FILE --- <?php // // +--------------------------------------------------------------------------+ // | phpMyChat version 0.15.0 | // +--------------------------------------------------------------------------+ // | Copyright (c) 2000-2001 The phpHeaven-team | // +--------------------------------------------------------------------------+ // | This library does the work associated to the 'banish' command. | // | | // | It is called by the 'commands.lib.php3' script. | // +--------------------------------------------------------------------------+ // | From the phpMyChat project: | // | http://www.phpheaven.net/projects/phpMyChat/ | // | | // | Authors: the phpHeaven-team <php...@ya...> | // +--------------------------------------------------------------------------+ // // $Id: banish.cmd.php3,v 1.1 2001/04/04 23:52:33 loic1 Exp $ // // The work for the 'banish' command. // /** * Check for invalid characters in the target user name */ if (ereg('[\, ]', $cmd[2])) { $error = L_ERR_USR_16; } /** * Ensure the current user is allowed to use the 'banish' command */ else if ($dbSessionVars['status'] != 'a' && $dbSessionVars['status'] != 'm') { $error = L_NO_MODERATOR; } /** * Ensure the current user is allowed to 'banish' the target user before doing * the work */ else { $slashedTarget = pmcSlashSingleQuotes($cmd[2]); // Define an additional condition for moderators so they can only banish an // user from their current room $queryRoomPart = ($dbSessionVars['status'] == 'm') ? 'room = \'' . pmcSlashSingleQuotes($dbSessionVars['targetRoom']) . '\' AND ' : ''; // Ensure the user to be banished is logged in (into the current room for moderators) $dbLink->query("SELECT latin1, room, status, ip FROM " . C_USR_TBL . " WHERE " . $queryRoomPart . "username = '$slashedTarget' LIMIT 1"); $isChatting = (list($targetLatin1, $targetCurrentRoom, $targetStatus, $targetIp) = $dbLink->nextRecord()); $dbLink->cleanResults(); // He/she is not chatting -> send an error message if (!$isChatting) { $error = sprintf(L_NONEXIST_USER, $cmd[2]); } // He/she is chatting else { // Ensure the user to be banished is not a more powerfull user // (admin > moderator) if ($targetStatus == 'a' || ($targetStatus == 'm' && $dbSessionVars['status'] != 'a')) { $error = sprintf(L_NO_BANISHED, $cmd[2]); } else { if ($cmd[1] == '* ' && $dbSessionVars['status'] != 'a') $cmd[1] = ''; // Define the duration of the banishment $banUntil = ($cmd[1] == '* ') ? 2147483647 : time() + round(C_BANISH * 60 * 60 * 24); if ($banUntil > 2147483647) $banUntil = 2147483647; // Check if the target user is already banished from some rooms $dbLink->query("SELECT ip, rooms FROM " . C_BAN_TBL . " WHERE username = '$slashedTarget' LIMIT 1"); $isBanished = (list($targetOldIp, $targetOldBanRooms) = $dbLink->nextRecord()); $dbLink->cleanResults(); // User is already banished from some rooms -> Update the banished table if ($isBanished) { // Define rooms that the user will be banished from (if they are more // than 3, user will be banished from the whole chat) if ($cmd[1] == '* ') { $targetNewBanRooms = '*'; } else { $tmpArray = explode(',', $targetOldBanRooms); if (pmcIsInto($targetCurrentRoom, $tmpArray) < 0) $targetNewBanRooms = (count($tmpArray) > 2) ? '*' : pmcSlashSingleQuotes($targetOldBanRooms . ',' . $targetCurrentRoom); else $targetNewBanRooms = pmcSlashSingleQuotes($targetOldBanRooms); unset($tmpArray); } // IP needs to be updated? if (substr($targetIp, 0, 1) == 'p' && substr($targetOldIp, 0, 1) != 'p') $targetIp = $targetOldIp; // Update the table $dbLink->query("UPDATE " . C_BAN_TBL . " SET ip = '$targetIp', rooms = '$targetNewBanRooms', ban_until = '$banUntil' WHERE username = '$slashedTarget'"); } // end of user already banished // User isn't already banished from any room -> Insert into the banished table else { $targetNewBanRooms = ($cmd[1] == '* ') ? '*' : pmcSlashSingleQuotes($targetCurrentRoom); $dbLink->query("INSERT INTO " . C_BAN_TBL . " VALUES ('$slashedTarget', '$targetLatin1', '$targetIp', '$targetNewBanRooms', '$banUntil')"); } // end of 'first banishment for the target user' // Modify the status of the banished user in the connected users table $dbLink->query("UPDATE " . C_USR_TBL . " SET u_time='" . time() . "', status='b' WHERE username = '$slashedTarget'"); // banishment confirmation message $error = sprintf(L_BANISHED, $cmd[2]); $isCommand = true; $doRefreshMessages = true; } // end of 'banishment allowed' } // end of 'target user is chatting' } ?> --- NEW FILE --- <?php // // +--------------------------------------------------------------------------+ // | phpMyChat version 0.15.0 | // +--------------------------------------------------------------------------+ // | Copyright (c) 2000-2001 The phpHeaven-team | // +--------------------------------------------------------------------------+ // | This library does the work associated to the 'announce' command. | // | | // | It is called by the 'commands.lib.php3' script. | // +--------------------------------------------------------------------------+ // | From the phpMyChat project: | // | http://www.phpheaven.net/projects/phpMyChat/ | // | | // | Authors: the phpHeaven-team <php...@ya...> | // +--------------------------------------------------------------------------+ // // $Id: announce.cmd.php3,v 1.1 2001/04/04 23:52:33 loic1 Exp $ // // The work for the 'announce' command. // /** * The current user is adminsitrator -> insert the message in the 'messages' * table */ if ($dbSessionVars['status'] == 'a') { // Format original message and set enhanced one (with graphical smilies) $originalMessage = formatMessage($cmd[1]); $enhancedMessage = $originalMessage; if (C_USE_SMILIES) { include('./lib/smilies.lib.' . C_EXTENSION); checkForSmilies($enhancedMessage, $smilies); unset($smilies); } // Put the message in the 'messages' table $msgQuery = 'INSERT INTO ' . C_MSG_TBL . ' ' . 'VALUES (' . $currentRoomType . ', ' . '\'' . $slashedCurrentRoomName . '\', ' . '\'SYS announce\', ' . $latin1 . ', ' . time() . ', ' . '\' *\', ' . '\'' . $color . '\', ' . '\'' . pmcSlashSingleQuotes($originalMessage) . '\', ' . '\'' . pmcSlashSingleQuotes($enhancedMessage) . '\'' . ')'; $dbLink->query($msgQuery); $isCommand = true; $doRefreshMessages = true; } /** * The current user is not adminsitrator -> set an error message */ else { $error = L_NO_ADMIN; } ?> |