0: Okay yes, this is very ugly. I had it kind of nice and then
1: I decided to go all out and compact it a lot. So here is a
2: fully-functional CGI script that allows anyone to come in,
3: enter any name they want (yes, even multiple instances of
4: the same nick are allowed) and chat together. It does use
5: two small pieces of javascript: one to refresh the chat
6: messages (because inserting that meta tag in the HTML
7: headers would have taken more space) and one that sets focus
8: to the chat box when you put your mouse over it.
9:
10: It doesn't really fit in the category of obfu, but it will
11: look better here than anywhere else. Code is for reusable
12: stuff, same with Snippets. I don't think anyone'll want to
13: use this!
14:
15: Features of the program? Only one: URL's are turned into
16: links ONLY when used in the perlmonks way (using square
17: brackets). And even then, it must be a URL between the
18: brackets and nothing else. No vertical bar to name the
19: link!
20:
21: So here it is. All in 19 lines:<br>
22:
23: <readmore>
24:
25: #!c:/perl/bin/perl
26: use strict;use CGI':Vars';use Data::Dumper;use Fcntl':flock';
27: use IO::Scalar;my%i=CGI::Vars;my($a,$b,$d,$f,$r,$s,$g)=($ENV{
28: 'SCRIPT_NAME'},$i{a},$i{u},$i{m});open L,">2.2"or die;flock L
29: ,LOCK_EX or die;our%c;do"1.1";$.=new IO::Scalar \$s;select$.;unless(
30: $b){print qq{<frameset rows="*,75"><frame src=$a?a=e><frame src=
31: $a?a=c&u=$d></frameset>};}if($b eq"e"){print qq{<script>
32: setTimeout('history.go(0)',8000);</script>};my$e;while(++$e){last if!
33: $c{$e};print qq{<strong>$c{$e}[0]</strong>: $c{$e}[1]<br>}if$c{$e};}}
34: if($b eq"c"){if(!$d){print qq{<form action=$a><input type=hidden name=a
35: value=c>Nickname:<input type=text name=u><input type=submit value=Start>
36: </form>};++$g;}if($f){$f=~s/</\</g;$f=~s/\[(.*?)\]/<a href='$1'
37: target=_blank>$1<\/a>/g;$c{++$c{n}}=[$d,$f];delete$c{$c{n}-15};}if(!$g){
38: print qq{<form action=$a><input type=hidden name=u value="$d"><input
39: type=hidden name=a value=c>Message:<input type=text name=m size=50
40: onmouseover=focus()><input type=submit value=Chat></form>};}}open A,">1.1"
41: or die;flock A,LOCK_EX or die;print A Data::Dumper->Dump([\%c], ['*c']);
42: print$b?"</body></html>":"</html>";select STDOUT;
43: print"Content-type: text/html\n\n";print$b?"<html><body>":"<html>";print$s; In reply to CGI Chat In 19 lines by mt2k
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |