home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / linux / system / mudsh < prev    next >
Text File  |  2001-03-07  |  21KB  |  708 lines

  1. #!/usr/local/bin/perl
  2.  
  3. #MUD Shell
  4. #(C)2001 Dean "Gandalf" Swift and Xirium
  5. #
  6. #20010209 Gandalf: idea taken from comments on SlashDot.Org
  7. #20010210 Gandalf: start
  8. #20010211 Gandalf: save
  9. #20010212 Gandalf: save test
  10. #20010213 Gandalf: save
  11. #20010214 Gandalf: save test
  12. #20010218 Gandalf: save
  13. #20010302 Gandalf: save fix spacing, add comments
  14. # Examine command contributed by Ron Broberg
  15. # Stat command fixed by Bernard Yap
  16. #20010307 Gandalf: start themes
  17.  
  18. #This subroutine, &disp, formats text to 72 columns.
  19. #This is done by using a ruler, $width, to copy the first 72 characters from $in to $line.
  20. #The last space is located and surplus from the next character is returned by prepending it to $in.
  21. #There are exceptions for strings containing "\n", although these are not tested.
  22. #Very long words have undefined results and hyphenation is not implemented.
  23.  
  24. sub disp
  25.  {
  26.  $width="."x72;
  27.  $in=shift;
  28.  if($in ne "")
  29.   {
  30.   print("\n");
  31.   }
  32.  while(length($in)>length($width))
  33.   {
  34.   $in=~s/^($width)//s;
  35.   $line=$1;
  36.   if($line=~/\n/s)
  37.    {
  38.    $line=~s/^(.*)\n(.*)$/$1/s;
  39.    $in=$2.$in;
  40.    }
  41.   else
  42.    {
  43.    $line=~s/^(.*) (.*)$/$1/s;
  44.    $in=$2.$in;
  45.    }
  46.   print("$line\n");
  47.   }
  48.  print("$in\n");
  49.  $disp_flag=1;
  50.  }
  51.  
  52. #For non null input, &disp, outputs a blank line before any other output.
  53. #&disp can be called multiple times, so, to ensure single blank lines between uses of &disp and to ensure a blank after the final use, a flag, $disp_flag is set.
  54. #&disp_space only outputs a blank line if &disp has been called then the flag is cleared.
  55.  
  56. sub disp_space
  57.  {
  58.  if($disp_flag==1)
  59.   {
  60.   print "\n";
  61.   $disp_flag=0;
  62.   }
  63.  }
  64.  
  65. sub inv_add
  66.  {
  67.  }
  68.  
  69. sub inv_sub
  70.  {
  71.  }
  72.  
  73. #-Message    inv-empty    You are carrying nothing and you have no weapons.
  74.  
  75. sub inv_disp
  76.  {
  77.  &disp($message{"inv-empty"});
  78.  }
  79.  
  80. #read configuration file specified as only parameter.
  81. #currently collected configuration information is stored in @alias, @des and @message.
  82. #aliases are not case sensitive, descriptions and messages are case sensitive.
  83.  
  84. sub conf_read
  85.  {
  86.  $temp0=shift;
  87.  if(-r $temp0)
  88.   {
  89.   open(FILE,$temp0);
  90.   while(defined($line=<FILE>))
  91.    {
  92.    $line=~s/^\#\-//;
  93.    $line=~s/[\n\r]*$//;
  94.    if($line!~/^\#/)
  95.     {
  96.     ($temp0,$temp1,$temp2)=split(/[ \t]+/,$line,3);
  97.     $temp0=~tr/[a-z]/[A-Z]/;
  98.     if($temp0 eq "ALIAS")
  99.      {
  100.      $temp1=~tr/[a-z]/[A-Z]/;
  101.      $temp2=~tr/[a-z]/[A-Z]/;
  102.      $alias{$temp1}=$temp2;
  103.      }
  104.     elsif($temp0 eq "DESCRIBE")
  105.      {
  106.      $temp2=~s/\\n/\n/g;
  107.      $temp2=~s/\\\\/\\/g;
  108.      $des{$temp1}=$temp2;
  109.      }
  110.     elsif($temp0 eq "MESSAGE")
  111.      {
  112.      $message{$temp1}=$temp2;
  113.      }
  114.     else
  115.      {
  116.      #should output error here
  117.      }
  118.     }
  119.    }
  120.   close(FILE);
  121.   }
  122.  }
  123.  
  124. #The following comments form part of the default theme.
  125. #The comments are stored in @des when the prog reads itself as configuration.
  126. #Directives in this format can be added to separate "theme" configuration files.
  127. #In theme files, directives must not be preceded with "#-".
  128. #This is for upward compatibility.
  129.  
  130. #-Describe    /    You are in a desert. A tumbleweed passes. You see a signpost but the words are obscure and abbreviated. Footprints indicate that the gurus have passed here many times before. If you stay here long enough, you will grow a beard.
  131. #-Describe    /dev    You are in the vast engine room of an alien spacecraft. Or it might be a holographic projection room. There are many exotic instruments, gauges, blinking lights and a sign in another language. Do not touch!
  132. #-Describe    /etc    You are in a junkyard. Well, you think it is a junkyard. Scrap metal and wood is piled conically all around you. You see crude, fearsome machines but you are unsure of their purpose. A stone tablet of names and encrypted passwords hangs from a crane. This rubble was once an important building.
  133. #-Describe    /bin    You are in the reference section of an old library. It is extremely dusty and hard to read the book titles. You can tell that this was once a place of profound discovery in golden era. You feel that this place may be useful in an emergency.
  134. #-Describe    /tmp    You are in a large deserted marketplace. The weather is overcast and you feel cold. The flagstones are uneven and newspaper soaks in a small puddle. Occasionally, useful information can be found here.
  135. #-Describe    /usr    You are in a tall, sparkling glass building. The building is curved and clear except for the light green turrets. A flying car passes.
  136. #-Describe    /usr/local    You are in a modern town.
  137. #-Describe    /var    You are in the lobby of a hotel.
  138. #-Describe    /var/spool    You are in the lounge of a hotel. You hear tasteful music playing quietly. Low comfy seating is arranged around palm trees and ferns. Soft lighting shines from the white ceiling. You would feel uneasy staying here too long.
  139. #-Describe    /root    You see a vast cavern with no quota limit. There might be treasure here but it is too dark to see. The walls by the entrance are scorched. A wise old dragon lives here. The dragon is subtle and quick to anger. Should you be here?
  140. #-Describe    /proc    You are in an office. You see many cubicles and hear a humming noise from the nearby supercomputer. Or maybe the hum is the air conditioning.
  141. #-Describe    /opt    You see a newly created cavern. Two gurus are arguing over the usefulness of this new area. Bugs and bloatware have already infested the area. You see some vendorware in the distance.");
  142. #-Describe    /opt/xirium    You are not sure why this room is here. A bell rings as you open the glass door. You see an arrangement of scrolls and a quaint photocopier, which is free to use. There is a generic desk with a generic sign that says "tech@xirium.com". You see an assortment of gadgets, some unfinished. Finally, you see some bones. A wumpus has eaten the shopkeeper.
  143. #-Describe    /boot    You are in a cave. This place was the beginning of civilisation.
  144. #-Describe    /site    You are in a trendy suburb. Residential and commercial properties are intermixed.");
  145.  
  146. #&describe checks for a description previously read from a theme.
  147. #If none is found, an attempt is made to read ".mudshrc" in the current directory.
  148. #If this is not the case, one of the defaults is tried.
  149. #Descriptions in the theme take precedence.
  150. #This is followed by descriptions in the filing system, although for some directories, such as /proc and /tmp , this is not practical.
  151.  
  152. #-Message    directory-empty    (Empty Directory)
  153. #-Message    exits    Exits
  154. #-Message    direction-north    North
  155. #-Message    direction-east    East
  156. #-Message    direction-south    South
  157. #-Message    direction-west    West
  158. #-Message    direction-up    Up
  159. #-Message    direction-home    Home
  160. #-Message    direction-none    (None)
  161.  
  162. sub describe
  163.  {
  164.  if(defined($des{$cwd}))
  165.   {
  166.   #use description from theme
  167.   &disp($des{$cwd});
  168.   }
  169.  elsif(-r ".mudshrc")
  170.   {
  171.   #print description found in .mudshrc in current directory
  172.   local($/);
  173.   open(FILE,".mudshrc");
  174.   $buffer=<FILE>;
  175.   $buffer=~s/\n\r/\n/gm;
  176.   $buffer=~s/\r\n/\n/gm;
  177.   $buffer=~s/\r/\n/gm;
  178.   $buffer=~s/\n$//gm;
  179.   &disp($buffer);
  180.   close(FILE);
  181.   }
  182.  else
  183.   {
  184.   #use default
  185.   if(($cwd eq "/usr/local/bin")||($cwd eq "/usr/bin"))
  186.    {
  187.    &disp("You are in a modern factory. Many of the machines form a single automated production line. Occasionally, a machine makes a loud noise, but there is no pattern.");
  188.    }
  189.   elsif(($cwd eq "/usr/local/lib")||($cwd eq "/usr/lib"))
  190.    {
  191.    &disp("You are in workshop. You see many interesting tools. Some are general purpose and some are for highly specialised uses.");
  192.    }
  193.   elsif(($cwd eq "/usr/local/man")||($cwd eq "/usr/man"))
  194.    {
  195.    &disp("You are standing by an information kiosk. The kiosk has a curved front and is painted in white, dark green and purple. It is quite gaudy. You see many leaflets on exotic subjects. The leaflets are written in a strange, terse language, but are extensively cross referenced. No one is present, but you see a sign that says \"Please take a leaflet or five\".");
  196.    }
  197.   elsif(($cwd eq "/var/spool/mail")||($cwd eq "/var/mail"))
  198.    {
  199.    &disp("You are in an oak panel room with plush carpet. You see pigeon holes for people's mail. You are curious and want to read. There are tubes to deliver mail and tubes to send mail. A mangle sits in the corner.");
  200.    }
  201.   elsif(($cwd eq "/usr/tmp")||($cwd eq "/var/tmp"))
  202.    {
  203.    &disp("You squeeze past a tall metal gate with a notice that reads \"Property left here at owners risk\". You see a concrete yard with a large bin. People don't come here any more, not since the machines replaced the workers.");
  204.    }
  205.   elsif($cwd=~/\/lost\+found$/)
  206.    {
  207.    &disp("You are in a lost property office.");
  208.    }
  209.   elsif($cwd eq "/mnt")
  210.    {
  211.    &disp("You are at an airport.");
  212.    }
  213.   elsif($cwd=~/\/mnt\/[^\/]+$/)
  214.    {
  215.    &disp("You are in an airplane.");
  216.    }
  217.   elsif(($cwd eq "/home")||($cwd=~/^\/[^\/]*\/home$/))
  218.    {
  219.    &disp("This is the home of the lesser gurus and the neophytes. You see pasty people sleeping. Some have a keyboard pattern imprinted on one side of their faces. These people need to get out more.");
  220.    }
  221.   elsif($cwd=~/\/home[^\/]*\/gandalf/)
  222.    {
  223.    &disp("You are in a disorganised room.");
  224.    }
  225.   elsif(($cwd eq "/www")||($cwd eq "/home/httpd/html"))
  226.    {
  227.    &disp("You are in the centre of a vast printing room. Loud machines surround you and they are producing thousands of informative magazines every minute. The noise is deafening.");
  228.    }
  229.   elsif((($cwd=~/^\/www\//)&&($cwd=~/\/cgi-bin$/))||($cwd eq "/home/httpd/cgi-bin"))
  230.    {
  231.    &disp("You are standing in a custom printing room. The most bizarrely designed machines are brought from miles around to work in this room. Steam prevents you seeing clearly.");
  232.    }
  233.   elsif(($cwd eq "/www-log")||($cwd eq "/home/httpd/logs")||($cwd eq "/usr/local/apache/logs"))
  234.    {
  235.    &disp("You are in the accounting room of the printers. Open ledgers can be found on elf size wooden desks. You wish the elves would write more clearly and spend less time getting drunk.");
  236.    }
  237.   elsif($cwd=~/^\/site\/[^\/]+\/www$/)
  238.    {
  239.    &disp("You are in a small office.");
  240.    }
  241.   }
  242.  print "\n";
  243.  $temp0=`ls -CF`;
  244.  if($temp0 eq "")
  245.   {
  246.   $temp0=$message{"directory-empty"}."\n";
  247.   }
  248.  print $temp0;
  249.  $temp0="";
  250.  if($dir_n ne "")
  251.   {
  252.   $temp0.=" ".$message{"direction-north"};
  253.   }
  254.  if($dir_e ne "")
  255.   {
  256.   $temp0.=" ".$message{"direction-east"};
  257.   }
  258.  if($dir_s ne "")
  259.   {
  260.   $temp0.=" ".$message{"direction-south"};
  261.   }
  262.  if($dir_w ne "")
  263.   {
  264.   $temp0.=" ".$message{"direction-west"};
  265.   }
  266.  if($temp0 eq "")
  267.   {
  268.   $temp0=" ".$message{"direction-none"};
  269.   }
  270.  &disp($message{"exits"}.":$temp0.");
  271.  }
  272.  
  273. #&scout identifies target directories for navigation.
  274. #(Replace this bit to *really* confuse your users.)
  275. #If not in root directory, you can go North.
  276. #If not in root directory, obtain the names of the items in the parent directory in alphabetical order.
  277. #For all of the readable directories found in the parent directory, create a window of three items.
  278. #Terminate loop if current directory is middle element of window.
  279. #First and last elements of window are East and West.
  280. #Obtain the names of the items in the current directory in alphabetical order.
  281. #The first readable directory is South.
  282. #A null string indicates that an exit is not available.
  283. #(This algorithm will change so that North and South are consistant and Up works how North currently does.)
  284.  
  285. sub scout
  286.  {
  287.  $dir_w="";
  288.  $dir_e="";
  289.  $dir_s="";
  290.  if($cwd eq "/")
  291.   {
  292.   $dir_n="";
  293.   }
  294.  else
  295.   {
  296.   $dir_n="..";
  297.   #scout West and East: search for sibling directories here
  298.   @temp0=glob("../*");
  299.   $temp1=$cwd;
  300.   $temp1=~s/.*\///;
  301.   $temp1=~s/([^0-9A-Za-z])/\\$1/g;
  302.   $flag=0;
  303.   $x=0;
  304.   for($x=0;($x<@temp0)&&($flag==0);$x++)
  305.    {
  306.    if(((((stat($temp0[$x]))[2])&040000)!=0)&&(-r $temp0[$x]))
  307.     {
  308.     if($temp0[$x]=~/$temp1$/)
  309.      {
  310.      $flag=1;
  311.      }
  312.     else
  313.      {
  314.      $dir_w=$temp0[$x];
  315.      }
  316.     }
  317.    }
  318.   for(;($x<@temp0)&&($dir_e eq "");$x++)
  319.    {
  320.    if(((((stat($temp0[$x]))[2])&040000)!=0)&&(-r $temp0[$x]))
  321.     {
  322.     $dir_e=$temp0[$x];
  323.     }
  324.    }
  325.   }
  326.  #scout South: search for first child directory here
  327.  @temp0=glob("*");
  328.  for($x=0;($x<@temp0)&&($dir_s eq "");$x++)
  329.   {
  330.   if(((((stat($temp0[$x]))[2])&040000)!=0)&&(-r $temp0[$x]))
  331.    {
  332.    $dir_s=$temp0[$x];
  333.    }
  334.   }
  335.  }
  336.  
  337. #Attempt to change directory.
  338. #This routine reports an error to output if directory change is not possible.
  339.  
  340. #-Message    cd-cannot    You cannot go in that direction.
  341. #-Message    cd-deny    A force field is blocking you. Your face is squashed and it tingles.
  342. #-Message    cd-unknown    This exit does not exist. You feel confused.
  343.  
  344. sub cd
  345.  {
  346.  $dir=shift;
  347.  if($dir eq "")
  348.   {
  349.   &disp($message{"cd-cannot"});
  350.   }
  351.  else
  352.   {
  353.   if(chdir($dir))
  354.    {
  355.    $cwd=`pwd`;
  356.    $cwd=~s/\n//;
  357.    &scout();
  358.    $xp++;
  359.    }
  360.   else
  361.    {
  362.    if(-e $dir)
  363.     {
  364.     &disp($message{"cd-deny"});
  365.     }
  366.    else
  367.     {
  368.     &disp($message{"cd-unknown"});
  369.     }
  370.    }
  371.   }
  372.  return(1);
  373.  }
  374.  
  375. #&go maps directions to directory names found by &scout before calling &cd.
  376. #Not sure if use of glob here has a bug.
  377.  
  378. sub go
  379.  {
  380.  if(($c eq "NORTH")||($c eq "N")||($c eq "UP")||($c eq ".."))
  381.   {
  382.   return(&cd($dir_n));
  383.   }
  384.  elsif(($c eq "WEST")||($c eq "W"))
  385.   {
  386.   return(&cd($dir_w));
  387.   }
  388.  elsif(($c eq "EAST")||($c eq "E"))
  389.   {
  390.   return(&cd($dir_e));
  391.   }
  392.  elsif(($c eq "SOUTH")||($c eq "S"))
  393.   {
  394.   return(&cd($dir_s));
  395.   }
  396.  elsif(($c eq "HOME")||($c eq "H"))
  397.   {
  398.   $temp=glob("~");
  399.   return(&cd($temp));
  400.   }
  401.  return(0);
  402.  }
  403.  
  404. #Array of words is passed to &parse.
  405. #Words are decoded from the beginning and discarded as they are interpreted.
  406. #$c should always be capitalised, with trailing punctuation removed, which speeds and simplifies decode.
  407. #(Ensuring the consistancy of $c when the array is shifted should be the action of a subroutine.)
  408. #Some commands grab the whole line, others allow further commands to be appended.
  409. #Glue words, such as "and" are ignored but unknown words halt decode, possibly after partial decode.
  410.  
  411. #-Message    direction-ambiguous    This direction is ambiguous.
  412. #-Message    directory-ambiguous    This directory is ambiguous.
  413. #-Message    demo-move    This is the demo version of MUDShell. You cannot move files.
  414. #-Message    demo-read    This is the demo version of MUDShell. You cannot view files.
  415. #-Message    demo-edit    This is the demo version of MUDShell. You cannot edit files.
  416.  
  417. sub parse
  418.  {
  419.  *command=shift;
  420.  while(@command)
  421.   {
  422.   $c=$command[0];
  423.   $c=~tr/[a-z]/[A-Z]/;
  424.   $c=~s/([0-9A-Z])[^0-9A-Z]$/$1/;
  425.   if(defined($alias{$c}))
  426.    {
  427.    $c=$alias{$c};
  428.    }
  429.   if(($c eq "HELP")||($c eq "H")||($c eq "?")||($c eq "MAN"))
  430.    {
  431.    &disp("MUDShell Help\n\nAvailable commands are: GO direction, CD directory, LOOK, EXAMINE object, INVENTORY or INV, TAKE objects, DROP objects, TALK, SHOUT, WHISPER, EMOTE gesture, READ files or VIEW files, EDIT files or OPEN files, KILL files, STAT, EXIT. Warning: KILL may remove files permanantly.");
  432.    if($exec_flag==1)
  433.     {
  434.     $temp="currently enabled";
  435.     }
  436.    else
  437.     {
  438.     $temp="not available from this login shell";
  439.     }
  440.    &disp("Prefix an explanation mark (\"!\") to execute proper shell commands. (This feature is $temp.)");
  441.    shift(@command);
  442.    }
  443.   elsif($c eq "GO")
  444.    {
  445.    shift(@command);
  446.    $c=$command[0];
  447.    $c=~tr/[a-z]/[A-Z]/;
  448.    $c=~s/([0-9A-Z])[^0-9A-Z]$/$1/;
  449.    if(!&go())
  450.     {
  451.     @temp=glob($command[0]);
  452.     if(@temp>1)
  453.      {
  454.      &disp($message{"direction-ambiguous"});
  455.      }
  456.     else
  457.      {
  458.      &cd($temp[0]);
  459.      }
  460.     }
  461.    shift(@command);
  462.    }
  463.   elsif(&go())
  464.    {
  465.    shift(@command);
  466.    }
  467.   elsif($c eq "CD")
  468.    {
  469.    shift(@command);
  470.    @temp=glob($command[0]);
  471.    if(@temp>1)
  472.     {
  473.     &disp($message{"directory-ambiguous"});
  474.     }
  475.    else
  476.     {
  477.     &cd($temp[0]);
  478.     }
  479.    shift(@command);
  480.    }
  481.   elsif($c eq "LOOK")
  482.    {
  483.    &describe();
  484.    $xp++;
  485.    shift(@command);
  486.    }
  487.   elsif($c eq "INV")
  488.    {
  489.    &inv_disp();
  490.    $xp++;
  491.    shift(@command);
  492.    }
  493.   elsif($c eq "TAKE")
  494.    {
  495.    &disp($message{"demo-move"});
  496.    return(1);
  497.    }
  498.   elsif($c eq "DROP")
  499.    {
  500.    &disp("You are not carrying anything.");
  501.    return(1);
  502.    }
  503.   elsif(($c eq "TALK")||($c eq "SAY")||($c eq "SHOUT"))
  504.    {
  505.    shift(@command);
  506.    write(join(@command," "));
  507.    return(1);
  508.    }
  509.   elsif($c eq "EMOTE")
  510.    {
  511.    shift(@command);
  512.    write("Guest ".join(@command," "));
  513.    return(1);
  514.    }
  515.   elsif($c eq "WHISPER")
  516.    {
  517.    &disp("Other users are not logged in.");
  518.    return(1);
  519.    }
  520.   elsif($c eq "EXAMINE") {
  521.     shift(@command);
  522.     while($command[0] ne "") {
  523.       if($command[0]!~/^and$/i) {
  524.         $temp=$command[0];
  525.         $temp=~s/^.*\/([^\/]*)$/$1/;
  526.         if("$temp" eq "") {
  527.           &disp("No such object");
  528.         } elsif(!-e $temp) {
  529.           &disp("Object $temp not found here.");
  530.         } else {
  531.           $examfile=`file $temp`;
  532.           $examfile=~s/^.*: //;
  533.           chomp($examfile);
  534.           &disp("$temp is a $examfile");
  535.           $xp++;
  536.         }
  537.       }
  538.     shift(@command);
  539.     }
  540.   }
  541.   elsif($c eq "READ")
  542.    {
  543.    &disp($message{"demo-read"});
  544.    return(1);
  545.    }
  546.   elsif($c eq "EDIT")
  547.    {
  548.    &disp($message{"demo-edit"});
  549.    return(1);
  550.    }
  551.   elsif($c eq "KILL")
  552.    {
  553.    shift(@command);
  554.    mkdir("~/Trash",0600); #fix this
  555.    while($command[0] ne "")
  556.     {
  557.     if($command[0]!~/^and$/i)
  558.      {
  559.      $temp=$command[0];
  560.      $temp=~s/^.*\/([^\/]*)$/$1/;
  561.      if(!-e $command[0])
  562.       {
  563.       &disp("File $temp not found.");
  564.       }
  565.      else
  566.       {
  567.       $len=(stat($temp))[7];
  568.       if(rename($command[0],"~/Trash/$temp")) #fix this
  569.        {
  570.        &disp("You killed $temp.");
  571.        $xp+=$len;
  572.        }
  573.       else
  574.        {
  575.        &disp("You are not strong enough to kill $temp.");
  576.        }
  577.       }
  578.      }
  579.     shift(@command);
  580.     }
  581.    }
  582.   elsif($c eq "STAT")
  583.    {
  584.    &disp("You have $xp experience points.");
  585.    shift(@command);
  586.    }
  587.   elsif($c eq "EXIT")
  588.    {
  589.    return(0);
  590.    }
  591.   elsif($c=~/^\#/)
  592.    {
  593.    #shell comment
  594.    return(1);
  595.    }
  596.   elsif(($c ne "AND")&&($c ne "THEN")&&($c ne "THE")&&($c ne "OF")&&($c ne "AGAIN"))
  597.    {
  598.    print("Eh?\n");
  599.    return(1);
  600.    }
  601.   else
  602.    {
  603.    shift(@command);
  604.    $c=$command[0];
  605.    $c=~tr/[a-z]/[A-Z]/;
  606.    $c=~s/([0-9A-Z])[^0-9A-Z]$/$1/;
  607.    if(defined($alias{$c}))
  608.     {
  609.     $c=$alias{$c};
  610.     }
  611.    }
  612.   }
  613.  return(1);
  614.  }
  615.  
  616. #Aliases are defined here.
  617. #These aliases are added to @alias when the program reads itself as configuration.
  618. #Aliases are substituted before commands are interpreted.
  619. #Currently, you can only substitute one word for another.
  620.  
  621. #-Alias    g    go
  622. #-Alias    l    look
  623. #-Alias    ls    look
  624. #-Alias    inventory    inv
  625. #-Alias    i    inv
  626. #-Alias    exam    examine
  627. #-Alias    ex    examine
  628. #-Alias    open    edit
  629. #-Alias    view    read
  630. #-Alias    more    read
  631. #-Alias    less    read
  632. #-Alias    stats    stat
  633. #-Alias    quit    exit
  634. #-Alias    qui    exit
  635. #-Alias    qu    exit
  636. #-Alias    q    exit
  637. #-Alias    logout    exit
  638. #-Alias    logoff    exit
  639.  
  640. #Main program is here.
  641. #Display banner, check for login shell, check safeguard then enter decode loop.
  642. #Lines are checked for shell escapes before being sent to the parser.
  643. #If an exit command is encountered, &parse returns an exit value.
  644. #Accumulated experience points are displayed before termination.
  645.  
  646. print("\@\@\@\\       /\@\@\@  Version 1.2:     \@\@\@   o\@\@\@\@\@o   \@\@\@  (C)2001 Xirium   \@\@\@ \@\@\@\n");
  647. print("\@\@\@\@\\     /\@\@\@\@  PointyStick      \@\@\@ /\@\@\@\@\@\@\@\@\@\\ \@\@\@  and Dean Swift   \@\@\@ \@\@\@\n");
  648. print("\@\@\@\@\@\\   /\@\@\@\@\@                   \@\@\@ \@\@\@'   `\@\@\@ \@\@\@                   \@\@\@ \@\@\@\n");
  649. print("\@\@\@\@\@\@\\ /\@\@\@\@\@\@ \@\@\@    \@\@\@   o\@\@\@b\@\@\@ \@\@\@.    \@\@\@ \@\@\@d\@\@\@o     o\@\@\@\@o   \@\@\@ \@\@\@\n");
  650. print("\@\@\@\\\@\@\@V\@\@\@/\@\@\@ \@\@\@    \@\@\@ /\@\@\@\@\@\@\@\@\@ \\\@\@\@o.      \@\@\@\@\@\@\@\@\@\\ /\@\@\@\@\@\@\@\@\\ \@\@\@ \@\@\@\n");
  651. print("\@\@\@ \\\@\@\@\@\@/ \@\@\@ \@\@\@    \@\@\@ \@\@\@'  `\@\@\@   *\@\@\@\@\@o   \@\@\@'  `\@\@\@ \@\@\@'  `\@\@\@ \@\@\@ \@\@\@\n");
  652. print("\@\@\@  \\\@\@\@/  \@\@\@ \@\@\@    \@\@\@ \@\@\@    \@\@\@      `*\@\@\@\\ \@\@\@    \@\@\@ \@\@\@\@\@\@\@\@\@\@ \@\@\@ \@\@\@\n");
  653. print("\@\@\@         \@\@\@ \@\@\@    \@\@\@ \@\@\@    \@\@\@ \@\@\@    `\@\@\@ \@\@\@    \@\@\@ \@\@\@\@\@\@\@\@\@\@ \@\@\@ \@\@\@\n");
  654. print("\@\@\@         \@\@\@ \@\@\@.  ,\@\@\@ \@\@\@.  ,\@\@\@ \@\@\@.   ,\@\@\@ \@\@\@    \@\@\@ \@\@\@.       \@\@\@ \@\@\@\n");
  655. print("\@\@\@         \@\@\@ \\\@\@\@\@\@\@\@\@\@ \\\@\@\@\@\@\@\@\@\@ \\\@\@\@\@\@\@\@\@\@/ \@\@\@    \@\@\@ \\\@\@\@\@\@\@\@\@  \@\@\@ \@\@\@\n");
  656. print("\@\@\@         \@\@\@   *\@\@\@P\@\@\@   *\@\@\@P\@\@\@   *\@\@\@\@\@*   \@\@\@    \@\@\@   *\@\@\@\@\@\@  \@\@\@ \@\@\@\n");
  657. &disp("You are logged in as Guest.");
  658. if($0!~/^\-/)
  659.  {
  660.  #this is not a login shell therefore allows external commands to be run
  661.  $exec_flag=1;
  662.  }
  663. @temp=`ps`;
  664. if(scalar(@temp)<=3)
  665.  {
  666.  #there are too few tasks for this not to be a login shell
  667.  $exec_flag=0;
  668.  }
  669. &conf_read($0); #reads self for configuration
  670. &conf_read("/etc/mudshrc");
  671. &conf_read("/opt/xirium/mudsh/conf");
  672. &conf_read(glob("~/.mudshrc"));
  673. $xp=0;
  674. $cwd=`pwd`;
  675. $cwd=~s/\n//;
  676. &scout();
  677. &describe();
  678. $continue=1;
  679. while($continue)
  680.  {
  681.  &disp_space();
  682.  print("mudsh - $cwd > ");
  683.  $buffer=<>;
  684.  $buffer=~s/[\n\r]*$//g;
  685.  $buffer=~s/\t/ /g;
  686.  $buffer=~s/ +/ /g;
  687.  $buffer=~s/^ //;
  688.  $buffer=~s/ $//;
  689.  if($buffer=~/^!/)
  690.   {
  691.   if($exec_flag!=1)
  692.    {
  693.    &disp("A wizard prevents your action.");
  694.    }
  695.   else
  696.    {
  697.    $buffer=~s/^!//;
  698.    system($buffer);
  699.    }
  700.   }
  701.  else
  702.   {
  703.   @line=split(/ /,$buffer);
  704.   $continue=&parse(\@line);
  705.   }
  706.  }
  707. &disp("Experience points gained this session: $xp. Experience points are earned by actions, but mostly by killing things.");
  708.