📄 ch19.htm
字号:
<B>$input{'handle'}</B> <FONT SIZE=-2>($id_snippet)</FONT></TD>
<BR>
<TD ALIGN=RIGHT VALIGN=CENTER><I>$time</I></TD></TR></TABLE>
<BR>
END<BR>
<BR>
if ( $input{'post_to'} ne 'everyone' ) {<BR>
print POST "<FONT
SIZE=+1><B>Private Message</B></FONT>\n";
<BR>
}<BR>
print POST "$input{'comments'}";<BR>
<BR>
close(POST);<BR>
}<BR>
<BR>
sub print_footer {<BR>
<BR>
print <<END;<BR>
<HR><BR>
<P><FONT SIZE=-1><B>This chat room is maintained
by<BR>
<A HREF="mailto:$admin_email">$admin_name</A></B></FONT>
<BR>
</BODY><BR>
</HTML><BR>
END<BR>
<BR>
}<BR>
<BR>
#<BR>
# this routine checks to see whether or not the ChatMaster is
blocking a<BR>
# given individual<BR>
#<BR>
sub cm_blocked {<BR>
<BR>
($temp_id) = @_;<BR>
<BR>
foreach ( @userdata ) {<BR>
@field = split(/\t/);<BR>
if ( ($temp_id eq $field[0])
&& ($field[3] eq 'BLOCKED') ) {<BR>
return 1;
<BR>
}<BR>
}<BR>
<BR>
return 0;<BR>
}<BR>
<BR>
#<BR>
# this routine returns true if the ID# passed to it is found within
the<BR>
# $input{'block'} string <BR>
#<BR>
sub blocked {<BR>
<BR>
($temp_id) = @_;<BR>
<BR>
#<BR>
# if the user isn't blocking anyone, return false<BR>
#<BR>
return 0 if $input{'block'} eq '';<BR>
<BR>
#<BR>
# check for a match between the ID# being checked up on and the
list of<BR>
# blocked ID#s. If there is a match, return true<BR>
#<BR>
@blocks = split(/$;/,$input{'block'});<BR>
foreach ( @blocks ) {<BR>
return 1 if $temp_id eq $_;
<BR>
}<BR>
<BR>
return 0;<BR>
}<BR>
<BR>
sub update_datafile {<BR>
<BR>
#<BR>
# don't proceed while $datafile is locked<BR>
#<BR>
while ( -e 'lock_file' ) {<BR>
sleep(1);<BR>
}<BR>
<BR>
#<BR>
# enable locking mechanism<BR>
#<BR>
open(LF,"> lock_file");<BR>
print LF "Locked!\n";<BR>
close(LF);<BR>
chmod 0660,'lock_file';<BR>
<BR>
foreach ( @userdata ) {<BR>
#<BR>
# if the particular element in the @userdata array pertains to
this user, <BR>
# updates this user's expiry time info (and handle, since that
too might<BR>
# change)<BR>
#<BR>
@field = split(/\t/);<BR>
if ($field[0] eq $input{'id'})
{<BR>
$found =
1;<BR>
$field[2]
= time + $reset_time;<BR>
$field[1]
= $input{'handle'};<BR>
}<BR>
#<BR>
# if current user is the ChatMaster, write appropriate blocking
info into<BR>
# @userdata array<BR>
#<BR>
if ($cmmode) {<BR>
if ( $field[0]
=~ /$input{'block'}/ ) {<BR>
if
($#field == 2) {push(@field,'BLOCKED'); }<BR>
}<BR>
}<BR>
$_ = join("\t",@field);
<BR>
}<BR>
<BR>
#<BR>
# if this is the first time a user is accessing the chat site,
add a new<BR>
# entry to the user data file (via the @userdata array) to that
effect<BR>
#<BR>
if (!($found)) {<BR>
push(@userdata,join("\t",$input{'id'},$input{'handle'},time+$reset_time));
<BR>
}<BR>
<BR>
#<BR>
# rewrite datafile with new info on expiry time and possibly blocking
info<BR>
#<BR>
open(DF,"> $datafile");<BR>
foreach(@userdata) {<BR>
print DF "$_\n";
<BR>
}<BR>
close(DF);<BR>
<BR>
unlink 'lock_file'</FONT></TT>;<BR>
<TT><FONT FACE="Courier">}</FONT></TT>
</BLOCKQUOTE>
<HR>
<H3><A NAME="OtherChatRoomFeaturesandExamples">Other Chat Room
Features and Examples</A></H3>
<P>
Chat rooms are a good example of a software system that suffers
from "creeping featurism." A lot of things can be added
to chat rooms, but it's questionable as to whether or not certain
features should be added. Before coding a new feature, ask yourself
a few questions: Is it needed? Is it understandable? Will people
actually use it?
<P>
For examples of every chat room feature imaginable, you can go
to Hulaboy's list of Web chat sites:
<BLOCKQUOTE>
<TT><FONT FACE="Courier"><A HREF="http://www.hula.net/~hulaboy/1_chtlnx.htm">http://www.hula.net/~hulaboy/1_chtlnx.htm</A></FONT></TT>
</BLOCKQUOTE>
<H4>Auto-Updates</H4>
<P>
In general, Web-based chat rooms require that users actively refresh
the stack themselves, either by submitting an entry to the stack
or by clicking on some sort of update link. With server-push/client-pull
mechanisms, this can be accomplished automatically. The HealthyChoice
Web site has a very nice chat system within it. You can see many
of the features I've created here and a few I haven't, including
auto-updates at their site:
<BLOCKQUOTE>
<TT><FONT FACE="Courier"><A HREF="http://chat.HealthyChoice.com/cgi-bin/Test.exe">http://chat.HealthyChoice.com/cgi-bin/Test.exe</A></FONT></TT>
</BLOCKQUOTE>
<H4>Frames</H4>
<P>
One of the problems with automatically updating chat rooms is
that your page might update while you're in the middle of typing
in a new posting-this is not good. One possibility is to combine
automatically updating pages with Netscape's frame feature. You
could program the room so that the form portion of the page doesn't
update, but the stack portion does.
<P>
The validity of frames as a feature is a hotly debated topic on
the Internet, and I don't mean this as an endorsement of frames
at all. Personally, I don't like them. Still, it's interesting
to consider them when planning a chat room.
<H4>Previous Postings</H4>
<P>
With the way chat.cgi and newchat.cgi are coded, postings beyond
the <TT><FONT FACE="Courier">$maxlines</FONT></TT> limit are deleted.
This isn't the only way to deal with these postings. Keeping them
around could be a good idea, too.
<P>
One feature I've seen that I really like is a page of previous
postings. The chat system at Bianca's Smut Shack keeps postings
around for several days. Rather than being deleted, old postings
are moved into a separate area and can be read with a different
CGI program. Strictly speaking, this isn't a "chat room"
feature, but it's certainly useful and could become part of your
chat system. For the brave at heart, you can find Bianca and her
"trolls" at
<BLOCKQUOTE>
<TT><FONT FACE="Courier"><A HREF="http://www.bianca.com/">http://www.bianca.com/</A></FONT></TT>
</BLOCKQUOTE>
<H4>Sign-Up Boards</H4>
<P>
Bianca's Smut Shack also attaches a sign-up board to each chat
room within. Again, this is not a chat room feature, but it's
a great idea. This way, people can leave messages for each other
to arrange times to chat, for example.
<H4>Dynamic Room Generation</H4>
<P>
Occasionally, chat room users might want to split off from the
main crowd and have a chat room all their own. This can be accomplished
with a mechanism very similar to private messaging. InfiNet's
popular Talker chat room does a good job in this regard:
<BLOCKQUOTE>
<TT><FONT FACE="Courier"><A HREF="http://www2.infi.net/talker/">http://www2.infi.net/talker/</A></FONT></TT>
</BLOCKQUOTE>
<H2><A NAME="AlternativestoCGIChatRooms"><FONT SIZE=5 COLOR=#FF0000>Alternatives
to CGI Chat Rooms</FONT></A></H2>
<P>
One of the things I find most remarkable about CGI chat rooms
is how popular they are given the superior alternatives. Yes,
you heard me correctly. CGI chat rooms aren't all that good. Here
are a few alternative schemes that do a great job of allowing
people to chat with each other.
<H3><A NAME="IRCInternetRelayChat">IRC-Internet Relay Chat</A>
</H3>
<P>
This isn't so much a program as a whole client/server (or peer-peer)
protocol on the Internet. There are a great number of IRC clients
and servers that allow countless net-heads to chat themselves
into an early grave. Winsock IRC clients can be found at Stroud's
Consummate Winsock Application List.
<H3><A NAME="PowWow">PowWow</A></H3>
<P>
This exceptional Winsock client allows many people to chat simultaneously,
each in their own window. While chatting, people can send pictures,
sounds, and other files to each other. Again, look for this at
Stroud's list.
<H3><A NAME="JavaChatRooms">Java Chat Rooms</A></H3>
<P>
I think this is where things are headed. Java is poised to become
nearly universally supported as part of the standard Web browser,
and Java-based chat rooms are technologically quite capable. The
Earthweb Java chat server is tops at this point in time:
<BLOCKQUOTE>
<TT><FONT FACE="Courier"><A HREF="http://www.earthweb.com/html/products.html">http://www.earthweb.com/html/products.html</A></FONT></TT>
</BLOCKQUOTE>
<H3><A NAME="talkandytalkOldUNIXStandbys"><TT><FONT SIZE=4 FACE="Courier">talk</FONT></TT><FONT SIZE=4>
and </FONT><TT><FONT SIZE=4 FACE="Courier">ytalk</FONT></TT><FONT SIZE=4>-Old
UNIX Standbys</FONT></A></H3>
<P>
The UNIX <TT><FONT FACE="Courier">talk</FONT></TT> command is
an oldie but a goodie. The talk protocol is quite respectable,
but the talk environment is limited to two users. <TT><FONT FACE="Courier">ytalk</FONT></TT>
is an extension of <TT><FONT FACE="Courier">talk</FONT></TT> that
uses the same protocol backbone but allows for multiple chatters.
Winsock <TT><FONT FACE="Courier">talk</FONT></TT> and <TT><FONT FACE="Courier">ytalk</FONT></TT>
clients can be found at Stroud's list.
<H3><A NAME="MUDMUSHandMOOSystems">MUD, MUSH, and MOO Systems</A>
</H3>
<P>
These are very nearly entire operating systems meant to be accessed
by the <TT><FONT FACE="Courier">telnet</FONT></TT> command. The
earliest of these was the MUD-Multi-User Dungeon-which started
as a role-playing game system. These environments are vast and
offer features far beyond any other chat system. However, their
telnet interfaces often leave much to be desired.
<H2><A NAME="Summary"><FONT SIZE=5 COLOR=#FF0000>Summary</FONT></A>
</H2>
<P>
As long as you have the system resources, I recommend putting
a chat room into your Web site. They're technically impressive,
they can promote a real feeling of community in your Web site,
and they tend to draw crowds-and hits are the name of the game
in this business.
<P>
When you plan out your chat room, try to keep the following things
in mind:
<UL>
<LI><FONT COLOR=#000000>Program with the end-user in mind. Make
the room as functional-yet-simple as possible.</FONT>
<LI><FONT COLOR=#000000>Plan a data structure for postings and
users that allows for flexible data management (for example, an
ID# scheme, embedded header fields within postings, and so on).</FONT>
<LI><FONT COLOR=#000000>Consider whether a multistate CGI or an
"entry page" scheme is more appropriate for what you're
trying to accomplish with your chat room.</FONT>
</UL>
<P>
You'll want to plan out a feature-set that best serves your users.
This might include blocking options or maybe schemes that prevent
people from using the same handle. You might want to build a "registered
user database" with a login system or maybe an http cookie
server instead. Remember that chat rooms are meant to be used
by many people simultaneously-you'll likely need to build a file-locking
mechanism. Maybe you'll want to be a ChatMaster in your own house.
Private messaging is always fun, too.
<P>
Chat rooms are an exceptionally rich field to explore in terms
of the thin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -