#!/usr/bin/perl -w $xserv_welcome = " Welcome to \00312XServ 1.0 \00314- The \0032Premier\00314 XChat Fileserver Written by MadCoder (\0033thorie99\@yahoo.com\003) \00315______________________________________________________\n \0034Rules: \0034 - No warez (copyrighted music, software, etc) \0034 - No leeching (make sure you upload!)\n \0036Comments: \0036 - This fileserver is beta! Send comments to the author! \0036 - The file listings look better with a fixed width font \00315______________________________________________________\n \0032Commands: help dir ls stats queues sends credits top10 bye\n"; $xserv_root = "/home/kewl/filez"; $xserv_temp = "/home/kewl/temp"; $xserv_offset = 36; $xserv_trigger = "!filez"; $xserv_channel = "#perl"; $xserv_offer = "Cool gamez & appz"; $xserv_start_credits = "100000"; # A ratio of 3 means that for every 1 byte uploaded, the visitor # can download 3 bytes. $xserv_ratio = "3"; $xserv_maxusers = "4"; $xserv_maxdl = "4"; # DO NOT EDIT ANYTHING BELOW THIS LINE (Unless you know perl) # ----------------------------------------------------------------------- $xserv_version = "1.0 beta"; $xserv_online = "0"; $xserv_dl = "0"; $xserv_curr = $xserv_root; $logo = "14-15=1[12XS1]15=14-15"; $blit = "\00314-\00315-\0031-\00315-\00314-"; IRC::register ("XServ", "1.0", "unload_handler", ""); IRC::print "$logo $blit $blit $blit $blit $blit $blit $blit"; IRC::print "$logo Loading \00312XServ $xserv_version\00315 Fileserver Script\003\n"; IRC::print "$logo Written by MadCoder (thorie99\@yahoo.com)"; IRC::add_print_handler("DCC Connected", "connect_handler"); IRC::add_print_handler("DCC RECV Complete", "recv_handler"); IRC::add_message_handler("PRIVMSG", "privmsg_handler"); IRC::add_message_handler("DCC", "dccmsg_handler"); IRC::add_command_handler("settings", "settings_handler"); IRC::add_command_handler("advertise", "ad_handler"); IRC::add_command_handler("trig", "set_trig"); IRC::add_command_handler("offerchan", "set_offerchan"); IRC::add_command_handler("offerdir", "set_offerdir"); IRC::add_command_handler("tempdir", "set_tempdir"); IRC::add_command_handler("credits", "set_credits"); IRC::add_command_handler("ratio", "set_ratio"); IRC::add_command_handler("desc", "set_desc"); IRC::add_command_handler("maxusers", "set_maxusers"); IRC::add_command_handler("maxdl", "set_maxdl"); IRC::add_command_handler("saveall", "set_saveall"); IRC::print "$logo Type \0037/settings\00315 to configure XServ."; IRC::print "$logo $blit $blit $blit $blit $blit $blit $blit"; sub settings_handler { IRC::print "$logo $blit $blit --\00315=\0031[ \00312Configs\0031 ]\00315=\00314-- $blit $blit"; IRC::print "$logo Trigger : $xserv_trigger (\0037/trig\00315)"; IRC::print "$logo Channel : $xserv_channel (\0037/offerchan\00315)"; IRC::print "$logo Offer dir : $xserv_root (\0037/offerdir\00315)"; IRC::print "$logo Temp dir : $xserv_temp (\0037/tempdir\00315)"; IRC::print "$logo Start credit: $xserv_start_credits (\0037/credits\00315)"; IRC::print "$logo Ratio : $xserv_ratio byte(s) for one. (\0037/ratio\00315)"; IRC::print "$logo Description : $xserv_offer (\0037/desc\00315)"; IRC::print "$logo Max users : $xserv_maxusers (\0037/maxusers\00315)"; IRC::print "$logo Max d/l : $xserv_maxdl (\0037/maxdl\00315)"; IRC::print "$logo Type \0037/saveall\00315 to save your settings."; IRC::print "$logo Type \0037/advertise\00315 to advertise your fserve."; IRC::print "$logo Type \0037/restore\00315 to reload your settings."; IRC::print "$logo $blit $blit $blit $blit $blit $blit $blit"; return 1; } sub get_usercredits { } sub get_userpath { } sub get_userhasdownloadedbefore { } sub set_saveall { IRC::print "$logo Settings saved to $xserv_temp/config.txt"; return 1; } sub set_trig { my $line = shift(@_); if ($line ne "") { IRC::print "$logo New trigger set to\0033 $line\003."; $xserv_trigger = $line; } else { IRC::print "$logo \0034Please choose a trigger text."; } return 1; } sub set_offerchan { my $line = shift(@_); if ($line ne "") { IRC::print "$logo New channel set to\0033 $line\003."; $xserv_channel = $line; } else { IRC::print "$logo \0034Please choose a channel name."; } return 1; } sub set_offerdir { my $line = shift(@_); if ($line ne "") { IRC::print "$logo New offering directory set to\0033 $line\003."; $xserv_root = $line; } else { IRC::print "$logo \0034Please choose a directory name."; } return 1; } sub set_tempdir { my $line = shift(@_); if ($line ne "") { IRC::print "$logo Temp directory set to\0033 $line\003."; $xserv_temp = $line; } else { IRC::print "$logo \0034Please choose a directory name."; } return 1; } sub set_credits { my $line = shift(@_); if ($line ne "") { IRC::print "$logo Setting starting credits to:\0033 $line\003."; $xserv_start_credits = $line; } else { IRC::print "$logo \0034Please choose a number of credit."; } return 1; } sub set_ratio { my $line = shift(@_); if ($line ne "") { IRC::print "$logo Setting ratio to 1:\0033 $line\003."; $xserv_ratio = $line; } else { IRC::print "$logo \0034Please specify a number."; } return 1; } sub set_desc { my $line = shift(@_); if ($line ne "") { IRC::print "$logo The description has been set to:\0033 $line\003."; $xserv_offer = $line; } else { IRC::print "$logo \0034Please choose some description text."; } return 1; } sub set_maxusers { my $line = shift(@_); if ($line != 0) { IRC::print "$logo The max number of users on XServ at once has been set to:\0033 $line\003."; $xserv_maxusers = $line; } else { IRC::print "$logo \0034Please choose a number."; } return 1; } sub set_maxdl { my $line = shift(@_); if ($line ne "") { IRC::print "$logo The max number of downloads at a time has been set to:\0033 $line\003."; $xserv_maxdl = $line; } else { IRC::print "$logo \0034Please choose a number."; } return 1; } sub unload_handler { IRC::print "$logo \0035Shutting down XServ..."; } sub recv_handler { my $line = shift(@_); $nick = $line; $nick =~ s/ /A/c; $nick =~ s/ /A/c; $nick =~ / /g; $num = pos($nick); $nick =~ / /g; $num2 = pos($nick); $nick = substr($nick, $num, $num2-$num-1); #IRC::print("Hey look: $nick."); $filename = $line; $filename =~ s/ /A/c; $filename =~ / /g; $num3 = pos($filename); $filename =~ s/ /A/c; $filename =~ / /g; $num4 = pos($filename); $filename = substr($filename, $num3, $num4-$num3-1); #IRC::print("Hey look more: $filename."); @stuff = stat "$filename"; $credits = $stuff[7] * $xserv_ratio; IRC::command("/msg =$nick \0033 Your file has been received. You have been awarded $credits credits."); open(CREDITSFILE, "$xserv_temp/${nick}-credits"); while () { $curr_credits = $_; } close(CREDITSFILE); open(CREDITSFILE, ">$xserv_temp/${nick}-credits"); $curr_credits = $curr_credits + $credits; print CREDITSFILE $curr_credits; close(CREDITSFILE); return 0; } sub connect_handler { my $line = shift(@_); #IRC::print "--> $line"; $chat = substr($line, 1, 4); $line =~ s/ /A/c; $line =~ s/ /A/c; $line =~ / /g; $num = pos($line); $nick = substr($line, 6, $num-6); if ($chat eq "CHAT") { IRC::command("/msg =$nick $xserv_welcome"); open(PATHFILE, "$xserv_temp/${nick}-path"); while () { $xserv_curr = $_; } close(PATHFILE); IRC::command("/msg =$nick [$xserv_curr/]"); } return 0; } sub ad_handler { IRC::command("/msg $xserv_channel $logo \0031File Server is up! \00315Trigger:\0037 $xserv_trigger \00315Offering: \0031$xserv_offer \00315Start credits:\0031 $xserv_start_credits \00315Ratio:\0031 1:$xserv_ratio \00315Online:\0031 $xserv_online\00315/\0031 $xserv_maxusers \00315Downloads:\0031 $xserv_dl\00315/\0031 $xserv_maxdl $logo"); return 1; } sub privmsg_handler { my $line = shift(@_); $nick = $line; #IRC::print "$nick"; $nick =~ /!/g; $endofnick = pos($nick); #IRC::print "$endofnick"; $nick = substr($nick, 1, $endofnick-2); $line =~ s/:/A/c; $line =~ /:/g; $num = pos($line); $message = substr($line, $num); $checkchat = substr($line, $num+1, 8); $file = $message; $file =~ s/ /A/c; $file =~ s/ /A/c; $file =~ / /g; $num2 = pos($file); $file = substr($file, 10, $num2-11); #IRC::print "$message"; #IRC::print "\0035[Msg] $line -- $checkchat -- $nick ($endofnick)\003\n"; #if ($checkchat eq "DCC CHAT") #{ #IRC::print "[Wow] We got a hot one from $nick!!!!!!!!"; # IRC::command("/dialog $nick"); #} if ($checkchat eq "DCC SEND") { IRC::command("/msg =$nick \0033 Receiving file `$file'. Your credits will be awarded after the file transfer is complete."); } if ($message eq $xserv_trigger) { IRC::command("/dcc chat $nick"); } return 0; } sub dccmsg_handler { my $line = shift(@_); $line =~ s/ /A/c; $line =~ / /g; $num = pos($line); $shortenedline = substr($line, $num); $shortenedline =~ /:/g; $num2 = pos($shortenedline); $nick = substr($shortenedline, 0, $num2-1); $command = substr($shortenedline, $num2+1); @stuff = stat "$xserv_temp/${nick}-credits"; if (@stuff == "") { open(CREDITSFILE, ">$xserv_temp/${nick}-credits"); print CREDITSFILE $xserv_start_credits; close(CREDITSFILE); open(PATHFILE, ">$xserv_temp/${nick}-path"); print PATHFILE $xserv_root; close(PATHFILE); } # $line = substr($line, $num); #IRC::print "\0035[Duh] $line --> $nick\003\n"; #IRC::command("/msg =$nick [$line]"); if ($command eq "hello") { IRC::command("/msg =$nick $xserv_welcome"); } elsif (($command eq "dir") || ($command eq "ls")) { open (PATHFILE, "$xserv_temp/${nick}-path"); while () { $xserv_curr = $_; } close (PATHFILE); system("ls -lh $xserv_curr > $xserv_temp/${nick}"); open(FILE, "$xserv_temp/${nick}"); while () { $line = $_; chop($line); $firstchar = substr($line, 0, 1); $extension = substr($line, -4); $line = substr($line, $xserv_offset); if ($firstchar eq "d") { IRC::command("/msg =$nick \00312$line/"); } elsif ($extension eq ".txt") { IRC::command("/msg =$nick \0033$line"); } elsif ($line ne "") { IRC::command("/msg =$nick $line"); } } close(FILE); system("rm $xserv_temp/${nick}"); open (PATHFILE, "$xserv_temp/${nick}-path"); while () { $xserv_curr = $_; } close (PATHFILE); IRC::command("/msg =$nick [$xserv_curr/]"); } elsif (substr($command, 0, 2) eq "cd") { $nos = substr($command, 2); $nos =~ s/ //g; $nos =~ s/;//g; $nos =~ s/`//g; $nos =~ s/'//g; $nos =~ s/\///g; $nos =~ s/>//g; $nos =~ s/) { $xserv_curr = $_; } close (PATHFILE); system("cd $xserv_curr;cd $xserv_curr/$nos;pwd>$xserv_temp/${nick}"); open(FILE2, "$xserv_temp/${nick}"); while () { $newdir = $_; } close(FILE2); chop($newdir); #IRC::print "----> $newdir vs $xserv_curr"; open (PATHFILE, "$xserv_temp/${nick}-path"); while () { $xserv_curr = $_; } close (PATHFILE); if (($newdir eq $xserv_curr) || (substr($newdir,0,length($xserv_root)) ne $xserv_root)) { IRC::command("/msg =$nick \0034Failed to change directory."); return 0; } $xserv_curr = $newdir; open (PATHFILE, ">$xserv_temp/${nick}-path"); print PATHFILE $xserv_curr; close (PATHFILE); IRC::command("/msg =$nick \0033Successfully changed directory."); IRC::command("/msg =$nick [$xserv_curr/]"); } elsif (substr($command, 0, 3) eq "get") { $nos = substr($command, 4); $nos =~ s/ //g; $nos =~ s/\//-/g; open (PATHFILE, "$xserv_temp/${nick}-path"); while () { $xserv_curr = $_; } close (PATHFILE); @stuff = stat "$xserv_curr/$nos"; open(CREDITSFILE, "$xserv_temp/${nick}-credits"); while () { $credits = $_; } close(CREDITSFILE); if (($stuff[7] > 0) && ($credits > $stuff[7])) { $credits = $credits - $stuff[7]; open(CREDITSFILE, ">$xserv_temp/${nick}-credits"); print CREDITSFILE $credits; close(CREDITSFILE); IRC::command("/msg =$nick \0033Now sending you $nos. If the send does not complete, you may retry the get as many times as you want at no cost of more credits."); IRC::command("/msg =$nick \0033You have\0034 $credits\0033 credits remaining."); open (PATHFILE, "$xserv_temp/${nick}-path"); while () { $xserv_curr = $_; } close (PATHFILE); IRC::command("/dcc send $nick $xserv_curr/$nos"); } elsif ($credits < $stuff[7]) { IRC::command("/msg =$nick \0034Insufficient credits for file."); } else { IRC::command("/msg =$nick \0034File $nos not found."); } } elsif ($command eq "credits") { open(CREDITSFILE, "$xserv_temp/${nick}-credits"); while () { $credits = $_; } close(CREDITSFILE); IRC::command("/msg =$nick \0033You have $credits credits."); } elsif ($command eq "help") { IRC::command("/msg =$nick \0032Commands: help dir ls queues sends credits top10 bye"); } elsif (($command eq "bye") || ($command eq "exit") || ($command eq "quit")) { IRC::command("/msg =$nick \0034Command not implemented. Just close your DCC window when you are done."); #IRC::command("/dcc close chat $nick"); } elsif ($command eq "queues") { IRC::command("/msg =$nick \0034Command not implemented."); } elsif ($command eq "sends") { IRC::command("/msg =$nick \0034Command not implemented."); } elsif ($command eq "top10") { IRC::command("/msg =$nick \0034Command not implemented."); } elsif ($command eq "stats") { IRC::command("/msg =$nick \0034Command not implemented."); } return 0; }