« Home « Kết quả tìm kiếm

WEBCHAT


Tóm tắt Xem thử

- chat.cgi is the main CGI script that performs all the chat room functions, including displaying and posting new chat messages.
- chat.setup is the setup file for the chat.cgi script.
- The Sessions subdirectory is used by the chat script to store the files related to each user’s session after he or she first logs on to the chat room.
- The Chat_open subdirectory is used by chat.cgi to store messages for the Open Forum chat room.
- This is one of the chat rooms set up in the default chat.setup file.
- @chat_rooms is a list of chat room names.
- This variable should be equal to the name in the @chat_variable array.
- Each element of this array corresponds to each chat room listed in the @chat_rooms array.
- $chat_script is the chat.cgi script name.
- Who files are refreshed whenever a user refreshes the chat messages or submits a message to the chat room..
- The following is an example of all the setup variables in the chat.setup file..
- @chat_room_directories = ("Chat_CGI Chat_Open");.
- @chat_room_variable = ("cgi open");.
- chat.setup is always loaded by the chat.cgi script.
- the user to log on to a chat room.
- Figure 26.5 Example of chat room logon..
- In the chat room logon screen shown in Figure 26.5, there are several form variables that the user is asked to fill out.
- Username is the alias that the user will be referred to in the chat room.
- If the user chooses to fill in this variable, a MAILTO hypertext reference tag will be displayed whenever the user’s name is shown in the chat room..
- If the user chooses to give the home page URL, a hypertext ref- erence will be displayed whenever the user’s name is shown in the chat room..
- The chat room variable allows the user to select the chat room to enter..
- require "./chat.setup";.
- require "./chat-html.pl";.
- $frames is set to on if the user has chosen to use Netscape-style frames for interacting with other users in the chat room.
- $user_last_read stores the last read message relative to each user in the chat room.
- $chat_room is set to the current chat room variable name.
- $setup is set to an alternative chat room setup filename.
- $chat_room = $in{'chat_room'};.
- The chat script name is placed in the $chat_script variable.
- $enter_chat is set to the value of the Enter Chat Room button on the initial login HTML form.
- This value will be used later by chat.cgi to see whether the user has just entered the chat room and must be set up by the script..
- $chat_message is the chat message itself..
- If the user has seen the chat room logon screen, a session is created and the script continues processing.
- If the user has not yet seen the chat room logon screen, this HTML form is printed..
- $enter_chat has a value but $chat_username has none, the script prints the chat room logon screen using the PrintChatEntrance subroutine.
- Otherwise, the logon screen for the chat is simply displayed to the user..
- In other words, the user’s session is initialized so that all the messages in the chat room are currently “new.”.
- $chat_message = "Automatic Message: $user_name Joined Chat Room";.
- If the logoff button was pressed, an automatic message is generated let- ting everyone know that the user has left the chat room.
- However, the logoff button exists to help make it clear who is in the chat room..
- is used to define the message as being posted to everyone in the chat room.
- In the chat script, "%6d".
- open(MSGFILE, ">$chat_room_dir/$high_number.msg");.
- The chat room directory is opened, and all the files ending in who are read to the @files array using grep to filter the results of the readdir command..
- The next part of the chat script processes the chat messages for display to the user.
- $whofile = "$chat_room_dir/$session.who";.
- Whenever a user reads all the mes- sages in the chat room directory, the current highest message number is set to the user’s last read message number.
- Remember that in the chat room logon screen, the user chooses how many old messages to display with new ones..
- This is done because the messages are stored in the chat room directory as six-digit numbers with leading zeros..
- if (-e "$chat_room_dir/$x.msg").
- open(MSG,"$chat_room_dir/$x.msg").
- The GetSessionInfo subroutine in the chat script retrieves information about the user’s current session.
- $high_message is set to the highest message number in the current chat room.
- Because the user’s last read message number is set to $high_mes- sage , there is a chance that more messages might be posted to the chat room while this script is processing the messages to display..
- First, $chat_room_dir is opened and all the files are read.
- If there are no files with msg in the chat room directory, $last_file is set to zero.
- The chat room directory is opened for reading by using the value stored in $chat_room_dir , a global variable that corresponds to the current chat room directory..
- If the file in the $chat_room_dir directory is older than $chat_who_length , the file is deleted using the unlink command.
- if (-M "$chat_room_dir/$file".
- sub GetChatRoomInfo { local($chat_room.
- Initially, $chat_room_number is set to –1.
- At the end of the routine, the script will know that the name was not found in the list of chat room names if $chat_room_number is still –1.
- $chat_room_number will be set to the number of the element in the @ chat_room_variable array in which the name of the chat room is defined if it exists..
- $chat_room_number = -1;.
- The body of the GetChatRoomInfo routine uses a for loop to step through each element in the @chat_room_variable array..
- $x <= @chat_room_variable.
- If the current element is equal to the contents of $chat_room , then.
- $chat_room_number is set to the number of the current element in the array and the loop exits when it encounters the command..
- $chat_room_number = $x - 1;.
- End of FOR chat_room_variables.
- if ($chat_room_number >.
- $chat_room_name = $chat_rooms[$chat_room_number];.
- $chat_room_dir = $chat_room_directories[$chat_room_number];.
- To generate a better error message, $chat_room is set to "None.
- if $chat_room is an empty string.
- $error is set to a message telling the user that the $chat_room was not available Then PrintChatError sends the error message to the user, and the program exits with the die command..
- $chat_room_name .
- $chat_room_dir .
- $chat_room = "None Given".
- if ($chat_room eq .
- $chat_room_dir is the only parameter that is sent to PruneOldMessages .
- local($chat_room_dir.
- The first major part of the routine reads all the filenames in the supplied chat room directory.
- $prunefile = "$chat_room_dir/$files[$x - 1]";.
- PrintChatEntrance prints the original HTML form that logs the user into a chat room.
- $chat_room_options is declared as a local variable.
- tags that go along with each chat room name..
- $chat_room_options .
- $chat_room_options.
- "<OPTION VALUE=$chat_room_variable[$_]>".
- if ($chat_room_options eq .
- "<OPTION>Chat Room Not Set Up\n";.
- The $setup and $chat_room_options variables are included in the output..
- <TD ALIGHT=RIGHT>Chat Room</TD>.
- <TD><SELECT NAME=chat_room>.
- <INPUT TYPE=SUBMIT NAME=enter_chat VALUE="Enter The Chat Room">.
- $chat_room is the current chat room name.
- "&chat_room=$chat_room".
- <TITLE>$chat_room_name</TITLE>.
- <INPUT TYPE=HIDDEN NAME=chat_room VALUE=$chat_room>

Xem thử không khả dụng, vui lòng xem tại trang nguồn
hoặc xem Tóm tắt