www.pudn.com > coolchat.zip > chatenter.pl


sub chatenter 
{ 
	my($qry_string) = @_; 
	($user_id,$randnum)=split(/\*/,$qry_string); 
                $randnum =~ s/\D//g; 
 
        $timefile=time; 
        $Nickname = $user_id; 
        if(&checkrand(lc($user_id),$randnum) ne 0) 
        { 
              &somerror("Sorry, your online info is out of date!"); 
              return; 
        } 
 
        $forbidfile = $ChaTempFilePath."main.out"; 
        if(open(FORBID, "<$forbidfile")) 
        { 
              @lines=; 
              close(FORBID); 
              foreach $line(@lines) 
              {  	 
                   ($theusername,$thetime,$nouse)=split(/:/,$line); 
                   if($theusername eq lc($user_id)) 
                   { 
                       if($thetime + 1800 > $timefile) 
                       { 
                            &somerror("对不起, 你现在不能进入我们的聊天室.\\n因为你的ID已被管理员暂时关闭,请等下再试!"); 
                       	    exit 0; 
                        } 
                        last; 
               	   } 
               } 
        } 
 
        $randnum=int(rand(10000)); 
        &addonlineuser($user_id); #Notes: If a chater donot quit last time, then he will the old room! 
 
        if($insertsite >= 0) 
        { #A new chater enter the room 
          if(open(ROOMLIST, "<$ChatRoomListFile")) 
          { 
	      @roomlines=;  
              close ROOMLIST; 
              if(open(ROOMLIST, ">$ChatRoomListFile")) 
              { 
                foreach $roomline(@roomlines) 
                { 
               	   ($roomname,$usernum,$master,$visible,$nouse)=split(/:/,$roomline); 
               	   if(lc($roomname) eq "$main") 
               	   { 
                        if($usernum eq 0) 
                        { 
                           $master = lc($user_id); 
                        } 
                        $usernum ++; 
               		print ROOMLIST "$main:$usernum:$master:$visible:1\n"; 
                   } 
                   else 
                   { 
                	print ROOMLIST $roomline; 
                   } 
                } 
                close ROOMLIST;                 
              } 
           } 
        } 
         
	#Get curent time 
	$now_string = localtime; 
	@thetime = split(/ +/,$now_string); 
	@theclock = split(/:/,$thetime[3]); 
 
        $newmessage = "$Nickname: 大家好!我来啦。 ($thetime[0] $theclock[0]:$theclock[1])[$ENV{'REMOTE_ADDR'}] [$user_id]
\n"; $ChatMessagePathroom = $ChatMessagePath."$main"; $ChatURL_pathroom = $ChatURL_path."$main"; if(open (ALL, "<$ChatMessagePathroom$ChatMessageAll$HTMLFilext")) { close ALL; open (ALL, ">>$ChatMessagePathroom$ChatMessageAll$HTMLFilext"); print ALL $newmessage; close ALL; } else { open (ALL, ">$ChatMessagePathroom$ChatMessageAll$HTMLFilext"); print ALL ''; print ALL "\n
中文极酷 $main 聊天室
\n"; print ALL $newmessage; close ALL; } if(open(HTMLOLD, "<$ChatMessagePathroom$HTMLFilext")) { @lines=; close(HTMLOLD); $linesnum=@lines; $hasoldroom = 1; } else { $hasoldroom = 0; $linesnum = 0; } if(open(NEW, ">$ChatMessagePathroom$HTMLFilext")) { if($hasoldroom eq 0) { print NEW ""; print NEW "
中文极酷 $main 聊天室
\n"; print NEW $newmessage; } else { print NEW "$lines[0]"; print NEW "$lines[1]"; print NEW $newmessage; for ($i = 2; ($i < 20 && $i < $linesnum) ; $i++) { print NEW "$lines[$i]"; } } close(NEW); } print "Content-type: text/html\n\n"; print "主题聊天室\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print ""; } sub addonlineuser { my($username) = @_; $username=lc($username); if(open(USERLIST,"<$ChatUserListFile")) { @userlines=; close(USERLIST); $usernum=@userlines; } else { $usernum = 0; } $insertsite = finduser($username,$usernum); if(($insertsite eq $usernum)&&($insertsite >= 0)) {#Do not find the user, so add at the tail if(open(USERLIST,">>$ChatUserListFile")) { $main = "main"; print USERLIST "$timefile:$user_id:$randnum:$timefile:$main:$Nickname:$ENV{'REMOTE_ADDR'}:1\n"; close USERLIST; return; } } if(open(USERLIST,">$ChatUserListFile")) { for($i = 0;$i<$mid;$i++) { print USERLIST "$userlines[$i]"; } if($insertsite < 0) { $forbidfile = $ChaTempFilePath.$oldroom.".out"; if(open(FORBID, "<$forbidfile")) {#Has the right to enter: @lines=; close(FORBID); foreach $line(@lines) { ($theusername,$thetime)=split(/:/,$line); if($theusername eq $username) { if($thetime + 1800 > $timefile) {#cannot enter the room,so enter main room $oldroom = "main"; } last; } } } $mid ++; $main = $oldroom; } else { $main = "main"; } print USERLIST "$timefile:$user_id:$randnum:$timefile:$main:$Nickname:$ENV{'REMOTE_ADDR'}:1\n"; for( $i = $mid; $i < $usernum; $i++ ) { print USERLIST "$userlines[$i]"; } close USERLIST; } } sub finduser { my($username,$total_size) = @_; $hi=$total_size - 1; $low=0; while($low <= $hi) { $mid=int(($low+$hi)/2); ($lastime,$oldname,$therandnum,$idnum,$oldroom)=split(/:/,$userlines[$mid]); $cmp = lc($oldname) cmp $username; if($cmp == 0) { unlink("$ChaTempFilePath$idnum$HTMLFilext"); return -1; } if($cmp>0) { $hi=$mid-1; } else { $low=$mid+1; } } if( $cmp < 0) { return $mid + 1; } return $mid; } sub getidpath { my($theid) = @_; $lowid=lc($theid); $first_id='!'; $iddirpath=$LOGOpath.$first_id."/".".".$lowid."/"; return $iddirpath; } sub checkrand { my($lowid,$keynum) = @_; if($lowid eq "guest") { return 1; } $entertime = time; $idpath = getidpath($lowid); $datapath = $idpath.$DATA; if(open(DATA,"<$datapath")) { @lines=; close DATA; ($visit_state,$crykey,$lastvistime,$loginip)=split(/:/,$lines[2]); chop($loginip); if((($lastvistime + 1800) > $entertime)&&($loginip eq $ENV{'REMOTE_ADDR'})) { $crypass=crypt($keynum,$CryKey); if($crykey ne $crypass) { return 2; } ($nickname)=split(/:/,$lines[3]); $nickname =~ s/\n|\r//g; $Nickname = $nickname if($nickname ne ""); return 0; } } return 3; } 1; #return true