View ¡m../sdba/./././bin/on_im.pl¡n
################################ # # # on_im(); # ################################ sub on_im { $victim = shift; $friend = shift; $msg = shift; $innerself = shift; $type = shift; #****************************** package Common; #****************************** local $victim = $main::victim; local $friend = $main::friend; local $msg = $main::msg; $continue = 1; #Filter the victim's screenname (Make it lowercase; remove spaces). $victim = lc($victim); $victim =~ s/ //g; #give it a better name $VISITOR = $victim; $VISITORNAME = $friend; #log it #Format the message the way you (should) want it, without HTML. $msg =~ s/<(.|\n)+?>//g; $IMNET = $main::imnet; $INCOMINGMSG = $msg; $NEXTPAGE = ""; $OUTMSG = ""; $main::reply=""; open (DAT, ">>logs/$VISITOR.log"); print DAT "$VISITORNAME: $INCOMINGMSG\n\n"; close (DAT); #Check for a new visitor if (not exists($visitors{$VISITOR})){ #put this in a sub in case we want to do more intialization stuff with visitors later $visitors{$VISITOR} = new_visitor($VISITOR); $visitors{$VISITOR}{currentpage} = "0"; $visitors{$VISITOR}{sessionend} = "0"; $visitors{$VISITOR}{sessionims} = "0"; #$main::reply = "new loop"; } #print "CURPAGE IS $visitors{$VISITOR}{currentpage}"; #check if current visitor's session is expired - if so reset pages and ims if ($visitors{$VISITOR}{sessionend} < time){ $visitors{$VISITOR}{currentpage} = "0"; $visitors{$VISITOR}{sessionend} = "0"; $visitors{$VISITOR}{sessionstart} = "0"; $visitors{$VISITOR}{sessionims} = "0"; #wipe these out too undef $visitors{$VISITOR}{sessionvars}; } #set global stuff - $VISITOR, $LASTPAGE, etc $visitors{$VISITOR}{lastpage} = $visitors{$VISITOR}{currentpage}; $visitors{$VISITOR}{sessionstart} = time; $visitors{$VISITOR}{sessionend} = time + $main::sessiontimeout; $visitors{$VISITOR}{lastinput} = $visitors{$VISITOR}{currentinput}; $visitors{$VISITOR}{currentinput} = $INCOMINGMSG; $visitors{$VISITOR}{totalims} ++; $visitors{$VISITOR}{sessionims} ++; #debug #$main::reply = "name = $visitors{$VISITOR}{name}, totalims= $visitors{$VISITOR}{totalims}, sessionims= $visitors{$VISITOR}{sessionims}, input = $visitors{$VISITOR}{currentinput}"; #ok, everything should be initialized now #check the session hash = which page to load? # if first time find the *.first file if ($visitors{$VISITOR}{currentpage} eq "0"){ @files =
; if ($#files == 0){ $visitors{$VISITOR}{currentpage} = $files[0]; $visitors{$VISITOR}{currentpage} =~ s/impages\///; $continue = 1; } #how to treat multiples? - see below #if none are there say so, or just error out else { #if multiples, find all *.first files $OUTMSG = "$main::multipleapptext\n"; $num = 1; foreach $first (@files){ $desc = $first; $continue = 0; open (FIRSTS, "$first"); while (
) { $curline = $_; #find the description of each in the file, if not set then print name of the file if ($curline =~ /#HEAD:/){ $first = $'; chomp $first; } } $OUTMSG .= "$num. $first\n"; $num++; close FIRSTS; $visitors{$VISITOR}{currentpage} = "-1"; } } } #more multiple pages - this is where we get their choice and set things appropriately if ($visitors{$VISITOR}{currentpage} eq "-1"){ @files =
; $num = 1; foreach $first (@files){ if ($num eq $INCOMINGMSG){ $visitors{$VISITOR}{currentpage} = $first; $visitors{$VISITOR}{currentpage} =~ s/impages\///; $continue = 1; } $num++; } #if they do not put in a number or miss the page, send em right back if ($visitors{$VISITOR}{currentpage} eq "-1"){$visitors{$VISITOR}{currentpage} = "0";} } #easy variables for the page scripting, in addition to $VISITOR and $INCOMINGMSG, defined above $CURRENTPAGE = $visitors{$VISITOR}{currentpage}; $LASTINPUT = $visitors{$VISITOR}{lastinput}; $LASTPAGE = $visitors{$VISITOR}{lastpage}; $TOTALIMS = $visitors{$VISITOR}{totalims}; $SESSIONIMS = $visitors{$VISITOR}{sessionims}; #commands - prefixed with a slash and non-whitespace if ($INCOMINGMSG =~ /^\//){ $SDBAcomm = $'; #everything after the slash $continue = 0; #split on the first space ($Commsub, $Commarg) = split (/ /,$SDBAcomm, 2); #send with arg, if any, result should populate $OUTMSG $prepage = "\&main::$Commsub(\$Commarg)"; #print "\n$prepage\n"; eval ($prepage); } #check for and read in their current page if ($continue){ if (-e "impages/$CURRENTPAGE"){ $OUTMSG = "Page $CURRENTPAGE exists! ($#files)totalims= $visitors{$VISITOR}{totalims}, sessionims= $visitors{$VISITOR}{sessionims}"; $codestart = 1; $OUTMSG = ""; $prepage = ""; #print "********\n**********\n About to call prepare- $CURRENTPAGE!\n*******\n"; prepare($CURRENTPAGE); if ($continue){ #print "\n*******_____********\n$prepage \n*********___*******\n"; eval($prepage); if (!$continue){$OUTMSG = $ERRORMSG;} } #debug #$OUTMSG = $prepage; #check for $@, send it instead if it is there, put in the current page if ($@) {$OUTMSG = $@; $OUTMSG =~ s/\(eval.*\)/$CURRENTPAGE/ig;} #reset $NEXTPAGE to start if it isn't set, "dead hole" or stoppage if ($NEXTPAGE eq "" || not $continue){ $NEXTPAGE = "0";} #set new CURRENTPAGE in session array #this is where this guy will go with his next message $visitors{$VISITOR}{currentpage} = $NEXTPAGE; #store some user-defined session variables, if any #i believe this is done } #if it doesnt exist say so else { $OUTMSG = "Page $CURRENTPAGE does not exist."; $continue = 0; $visitors{$VISITOR}{currentpage} = "0"; #set session array, pages } } else { if ($OUTMSG eq ""){$OUTMSG = "An error occured somewhere";} } #Artifacts..... #Check the victim against the warner list. #****************************************************************** #my $warner = warners("$victim"); #If the victim is a warner, warn him and block him. #Otherwise, continue. #if ($warner != 1) { #Check the message against the list of commands. #($isacommand,$reply) = commands($victim,$msg); #If it isn't a command... #if ($isacommand != 1) { #} package main; $reply = $Common::OUTMSG; #Send the reply. RSEND_IM ($victim, "$reply", $screenname, $msg, $innerself, $type); #Print to the DOS window that the sleep is finished. print " Done.\n\n"; #} } 1;