--- loncom/lond 2002/08/08 13:45:21 1.86 +++ loncom/lond 2002/08/09 10:05:00 1.87 @@ -2,7 +2,7 @@ # The LearningOnline Network # lond "LON Daemon" Server (port "LOND" 5663) # -# $Id: lond,v 1.86 2002/08/08 13:45:21 www Exp $ +# $Id: lond,v 1.87 2002/08/09 10:05:00 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1570,18 +1570,27 @@ sub addline { sub getchat { my ($cdom,$cname)=@_; - my @entries; - if (open(CHATIN,&propath($cdom,$cname).'/chatroom.txt')) { - while ($line=) { push(@entries,$line); } - close(CHATIN); - return @entries; + my %hash; + my $proname=&propath($cdom,$cname); + my @entries=(); + if + (tie(%hash,'GDBM_File',"$proname/nohist_chatroom.db",&GDBM_READER(),0640)) + { + @entries=map { $_.':'.$hash{$_} } sort keys %hash; + untie %hash; } - return (); + return @entries; } sub chatadd { - my ($cdom,$cname,$newchat)=@_; - my @entries=&getchat($cdom,$cname); + my ($cdom,$cname,$newchat)=@_; + my %hash; + my $proname=&propath($cdom,$cname); + my @entries=(); + if + (tie(%hash,'GDBM_File',"$proname/nohist_chatroom.db",&GDBM_WRCREAT(),0640)) + { + @entries=map { $_.':'.$hash{$_} } sort keys %hash; my $time=time; my ($lastid)=($entries[$#entries]=~/^(\w+)\:/); my ($thentime,$idnum)=split(/\_/,$lastid); @@ -1592,16 +1601,16 @@ sub chatadd { $idnum=substr('000000'.$idnum,-6,6); $newid=$time.'_'.$idnum; } - push (@entries,$newid.':'.$newchat."\n"); + $hash{$newid}=$newchat; my $expired=$time-3600; - open(CHATOUT,'>'.&propath($cdom,$cname).'/chatroom.txt'); - foreach (@entries) { + foreach (keys %hash) { my ($thistime)=($_=~/(\d+)\_/); - if ($thistime>$expired) { - print CHATOUT $_; + if ($thistime<$expired) { + undef $hash{$_}; } } - close(CHATOUT); + untie %hash; + } } sub unsub {