|
From: Lo?c C. <lo...@us...> - 2001-05-22 20:40:37
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/commands
In directory usw-pr-cvs1:/tmp/cvs-serv30745/chat/lib/commands
Modified Files:
join.cmd.php3
Log Message:
Too many changes to detail...
Index: join.cmd.php3
===================================================================
RCS file: /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/commands/join.cmd.php3,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** join.cmd.php3 2001/04/19 21:05:04 1.4
--- join.cmd.php3 2001/05/22 20:40:34 1.5
***************
*** 32,39 ****
*/
if (C_NO_SWEAR == 1)
include('./lib/swearing.lib.' . C_EXTENSION);
! $targetRoomType = ($cmd[2] != '') ? $cmd[2] : 1;
! $targetRoom = $cmd[3];
! $slashedTarget = pmcSlashSingleQuotes($cmd[3]);
--- 32,41 ----
*/
if (C_NO_SWEAR == 1)
+ {
include('./lib/swearing.lib.' . C_EXTENSION);
! }
! $targetRoomType = ($cmd[2] != '') ? $cmd[2] : 1;
! $targetRoom = $cmd[3];
! $slashedTargetRoomName = pmcSlashSingleQuotes($cmd[3]);
***************
*** 47,54 ****
if (C_VERSION == 1)
{
! if (pmcIsInto($targetRoom, $defaultChatRooms) >= 0)
! $isCommand = true;
! else
$error = L_ERR_USR_17;
}
--- 49,56 ----
if (C_VERSION == 1)
{
! if (pmcIsInto($targetRoom, $defaultChatRooms) < 0)
! {
$error = L_ERR_USR_17;
+ }
}
***************
*** 70,121 ****
$error = L_ERR_ROM_2;
}
! // Ensure there is no existing room with the same name but a different type
! // among reserved name for private/public (default) rooms
else
{
$toCheck = ($targetRoomType == 1) ? $defaultPrivateRooms : $defaultChatRooms;
if (pmcIsInto($targetRoom, $toCheck) >= 0)
! $error = ($targetRoomType == 0) ? L_ERR_ROM_3 : L_ERR_ROM_4;
! else
! $isCommand = true;
unset($toCheck);
}
/**
! * If the target room has valid name and type, do the work
*
! * The 'pmcIsInto()' function is defined in the 'chat/lib/common.lib.php3'
! * library
*/
! if ($isCommand)
{
! $found = false;
! // Get the case sensitive name of the target room
! // 1. Among default rooms
! $toCheck = ($targetRoomType == 1) ? $defaultChatRooms : $defaultPrivateRooms;
! $pos = pmcIsInto($targetRoom, $toCheck);
if ($pos >= 0)
{
! $targetRoom = $toCheck[$pos];
! $found = true;
}
unset($toCheck);
! // 2. Among other existing rooms with the same type
! if (!$found)
{
! $dbLink->query("SELECT type, room FROM " . C_MSG_TBL . " WHERE room = '$slashedTarget' LIMIT 1");
! $roomExist = (list($trueTargetType, $trueTargetName) = $dbLink->nextRecord());
! if ($roomExist && $targetRoomType == $trueTargetType)
! {
! $targetRoom = pmcHandleMagicQuotes($trueTargetName, '', 1, 'del');
! $found = true;
! }
! $dbLink->cleanResults();
}
! // Room should be created
! // 1. ensure the user is registered
if (!$found || $targetRoomType == 0)
{
--- 72,128 ----
$error = L_ERR_ROM_2;
}
! // Ensure there is no existing room with the same name but a different type...
else
{
+ // ...neither among reserved name for private/public (default) rooms
$toCheck = ($targetRoomType == 1) ? $defaultPrivateRooms : $defaultChatRooms;
if (pmcIsInto($targetRoom, $toCheck) >= 0)
! {
! $error = ($targetRoomType == 0) ? L_ERR_ROM_3 : L_ERR_ROM_4;
! }
unset($toCheck);
+ // ...neither among other rooms created by users
+ $dbLink->query("SELECT type, room FROM " . C_MSG_TBL . " WHERE room = '$slashedTargetRoomName' LIMIT 1");
+ $roomExist = (list($trueTargetType, $trueTargetName) = $dbLink->nextRecord());
+ if ($roomExist && $targetRoomType != $trueTargetType)
+ {
+ $error = ($targetRoomType == 0) ? L_ERR_ROM_3 : L_ERR_ROM_4;
+ }
+ $dbLink->cleanResults();
}
/**
! * If the target room has valid name and type -> ensure the user is allowed to
! * enter in and prepare the work
*
! * The 'pmcIsInto()' and the 'pmcHandleMagicQuotes()' functions are defined in
! * the 'chat/lib/common.lib.php3' library
*/
! if (empty($error))
{
! $found = false;
! $isCreateRoom = false;
! // 1. Get the case sensitive name of the target room
! // 1.1 Among default rooms
! $toCheck = ($targetRoomType == 1) ? $defaultChatRooms : $defaultPrivateRooms;
! $pos = pmcIsInto($targetRoom, $toCheck);
if ($pos >= 0)
{
! $targetRoom = $toCheck[$pos];
! $slashedTargetRoomName = pmcSlashSingleQuotes($targetRoom);
! $found = true;
}
unset($toCheck);
! // 1.2 Among other existing rooms with the same type
! if (!$found && $roomExist)
{
! $targetRoom = pmcHandleMagicQuotes($trueTargetName, '', 1, 'del');
! $slashedTargetRoomName = pmcSlashSingleQuotes($targetRoom);
! $found = true;
}
! // 2. Room should be created, ensure the user is registered
if (!$found || $targetRoomType == 0)
{
***************
*** 125,174 ****
&& $dbSessionVars['status'] != 'r')
{
! $error = L_ERR_USR_13;
! $found = false;
}
! }
! // 2. ensure there is no existing room with the same name but a different
! // type among rooms created by users
! if (!$found && $roomExist && empty($error))
! {
! $error = ($targetRoomType == 0) ? L_ERR_ROM_3 : L_ERR_ROM_4;
! }
! else if (empty($error))
! {
! $found = true;
}
! // Ensure the user is not banished from the room he wants to enter in
! if ($found && C_BANISH && $dbSessionVars['status'] != 'a')
{
! $enterOtherRoomName = $targetRoom;
! include('./lib/banish.lib.' . C_EXTENSION);
! if ($isBanished)
{
! $found = false;
! $error = L_ERR_USR_20;
}
! unset($enterOtherRoomName);
}
! // If the room can't be created
! if (!$found)
! {
! $isCommand = false;
! }
! // Log into the new room
! else
! {
! $exitUrl = $dbSessionVars['from']
! . '?' . dbSessionSID('GET')
! . $pmcQueryArgSeparator . 'exitMessage=1'
! . $pmcQueryArgSeparator . 'reloading=joinCmd'
! . $pmcQueryArgSeparator . 'newTargetRoom=' . $targetRoomType . urlencode($targetRoom);
! $dbLink->close();
! include('./lib/move_to_start.lib.' . C_EXTENSION);
! exit();
}
}
?>
--- 132,245 ----
&& $dbSessionVars['status'] != 'r')
{
! $error = L_ERR_USR_13;
! $found = false;
}
! else
! {
! $found = true;
! $isCreateRoom = true;
! }
}
! // 3. Ensure the user is not banished from the room he wants to enter in
! if (empty($error) && C_BANISH && $dbSessionVars['status'] != 'a')
{
! if (!function_exists('pmcCheckBanish'))
{
! include('./lib/get_user_infos.lib.' . C_EXTENSION);
}
! $ip = pmcGetIp();
! if (pmcCheckBanish())
! {
! $error = L_ERR_USR_20;
! }
}
! // 4. Define the right level the user will be granted in the room he/she is
! // going to enter in
! if (empty($error))
! {
! $regUserPerms = ($dbSessionVars['status'] == 'a') ? 'admin' : 'noreg';
! $regUserModeratedRooms = '';
! // Get data from the registered users table if required
! if ($regUserPerms != 'admin')
! {
! $dbLink->query("SELECT perms, rooms FROM " . C_REG_TBL . " WHERE username = '$slashedNick' LIMIT 1");
! $isRegUser = (list($regUserPerms, $regUserModeratedRooms) = $dbLink->nextRecord());
! if ($isRegUser)
! {
! $regUserModeratedRooms = pmcHandleMagicQuotes($regUserModeratedRooms, '', 1, 'del');
! }
! $dbLink->cleanResults();
! }
! if (!function_exists('pmcRightLevel'))
! {
! include('./lib/get_user_infos.lib.' . C_EXTENSION);
! }
! $status = pmcRightLevel();
}
}
+
+
+ /**
+ * All validation tests have been successfully passed -> do the work
+ *
+ * The 'pmcIsInto()' function is defined in the 'chat/lib/common.lib.php3'
+ * library
+ */
+ if (empty($error))
+ {
+ $isCommand = true;
+ $currentTime = time();
+ $nickForNotifications = pmcSlashSingleQuotes(pmcSpecialChars($slashedNick, $latin1), 2);
+
+ // Update cookies
+ $cookieRoom = urlencode($targetRoom);
+ setcookie('cookieRoom', $cookieRoom, time() + 60*60*24*365);
+ setcookie('cookieRoomType', $targetRoomType, time() + 60*60*24*365);
+
+ // Update tables
+ $queries[] = 'UPDATE ' . C_USR_TBL . ' '
+ . "SET u_time = $currentTime , room = '$slashedTargetRoomName', status = '$status' "
+ . "WHERE session_id = '$dbSessionId'";
+ $queries[] = 'INSERT INTO ' . C_MSG_TBL . ' '
+ . '(type, room, username, latin1, m_time, address, color, msg_original, msg_enhanced) '
+ . 'VALUES '
+ . "($currentRoomType, '$slashedCurrentRoomName', 'SYS exit', '', $currentTime, NULL, '#666699', 'sprintf(L_EXIT_ROM, \'$nickForNotifications\')', 'sprintf(L_EXIT_ROM, \'$nickForNotifications\')')";
+ $queries[] = 'INSERT INTO ' . C_MSG_TBL . ' '
+ . '(type, room, username, latin1, m_time, address, color, msg_original, msg_enhanced) '
+ . 'VALUES '
+ . "($targetRoomType, '$slashedTargetRoomName', 'SYS enter', '', $currentTime, NULL, '#666699', 'sprintf(L_ENTER_ROM, \'$nickForNotifications\')', 'sprintf(L_ENTER_ROM, \'$nickForNotifications\')')";
+ if (C_WELCOME)
+ {
+ // ensures the welcome msg is the last one
+ $currentTimePlus = $currentTime + 1;
+ // Insert a new welcome message in the messages table
+ include('./lib/welcome.lib.' . C_EXTENSION);
+ $slashedWelcomeMsg = pmcSlashSingleQuotes(WELCOME_MSG);
+ // Delete the old welcome messages sent to the current user
+ $queries[] = 'DELETE FROM ' . C_MSG_TBL . ' '
+ . 'WHERE username = \'SYS welcome\' AND address = \'' . $slashedNick . '\'';
+ $queries[] = 'INSERT INTO ' . C_MSG_TBL . ' '
+ . '(type, room, username, latin1, m_time, address, color, msg_original, msg_enhanced) '
+ . 'VALUES '
+ . "($targetRoomType, '$slashedTargetRoomName', 'SYS welcome', '', $currentTimePlus, '$slashedNick', '#666699', '$slashedWelcomeMsg', '$slashedWelcomeMsg')";
+ }
+ $queriesCnt = count($queries);
+ reset($queries);
+ for ($i = 0; $i < $queriesCnt; $i++)
+ {
+ $dbLink->query($queries[$i]);
+ }
+
+ // Update session data and enforce a complete refresh of the
+ // 'users' and the 'messages' frames
+ $dbSessionVars['roomType'] = $targetRoomType;
+ $dbSessionVars['currentRoom'] = $targetRoom;
+ $dbSessionVars['status'] = $status;
+ $dbSessionVars['noKickTest'] = true;
+ $enforceFirstLoad = 1;
+ $doRefreshMessages = true;
+ } // end of 'do the work'
?>
|