├── README.md ├── install └── mudsh-1.2.perl /README.md: -------------------------------------------------------------------------------- 1 | # mud-shell 2 | A MUD based shell, rescued from [the pages of time](https://web.archive.org/web/20080509092838/http://www.xirium.com/tech/mud-shell/download/mudsh). The original hosting site, xirium.com, seems to be dead since ~2008. 3 | 4 | Is there any reason why a shell (or command line) cannot be as tolerant or as intelligent as a text adventure game like Zork, or a MUD [Multi User Dungeon]? Is there any reason why a shell cannot work like such a game? ("Go North", etc.) Actually, no and we have the implementation to prove it. Have fun, and don't get eaten by a Grue! 5 | 6 | - [The Idea](https://web.archive.org/web/20080509122938/http://www.xirium.com/tech/mud-shell/idea/index.html) 7 | 8 | ## Example Use 9 | 10 | @@@\ /@@@ Version 1.0: @@@ o@@@@@o @@@ (C)2001 Xirium @@@ @@@ 11 | @@@@\ /@@@@ BonsaiWumpus @@@ /@@@@@@@@@\ @@@ and Dean Swift @@@ @@@ 12 | @@@@@\ /@@@@@ @@@ @@@' `@@@ @@@ @@@ @@@ 13 | @@@@@@\ /@@@@@@ @@@ @@@ o@@@b@@@ @@@. @@@ @@@d@@@o o@@@@o @@@ @@@ 14 | @@@\@@@V@@@/@@@ @@@ @@@ /@@@@@@@@@ \@@@o. @@@@@@@@@\ /@@@@@@@@\ @@@ @@@ 15 | @@@ \@@@@@/ @@@ @@@ @@@ @@@' `@@@ *@@@@@o @@@' `@@@ @@@' `@@@ @@@ @@@ 16 | @@@ \@@@/ @@@ @@@ @@@ @@@ @@@ `*@@@\ @@@ @@@ @@@@@@@@@@ @@@ @@@ 17 | @@@ @@@ @@@ @@@ @@@ @@@ @@@ `@@@ @@@ @@@ @@@@@@@@@@ @@@ @@@ 18 | @@@ @@@ @@@. ,@@@ @@@. ,@@@ @@@. ,@@@ @@@ @@@ @@@. @@@ @@@ 19 | @@@ @@@ \@@@@@@@@@ \@@@@@@@@@ \@@@@@@@@@/ @@@ @@@ \@@@@@@@@ @@@ @@@ 20 | @@@ @@@ *@@@P@@@ *@@@P@@@ *@@@@@* @@@ @@@ *@@@@@@ @@@ @@@ 21 | 22 | You are logged in as Guest. 23 | 24 | You are in the home directory of the MUD Shell demo account. You are 25 | feeling curious and want to explore. You are particularly curious about 26 | the shimmering portal to the South. If you get lost, type "go home" 27 | (without the quotes) to return here. 28 | 29 | xirium@ 30 | 31 | Exits: North East South West. 32 | 33 | mudsh - /home/mudsh > Go north, look and then go east 34 | 35 | This is the home of the lesser gurus and the neophytes. You see pasty 36 | people sleeping. Some have a keyboard pattern imprinted on one side of 37 | their faces. These people need to get out more. 38 | 39 | admin/ gandalf/ httpd/ mudsh/ richard/ 40 | andre/ herve/ luser-template/ power-template/ usr/ 41 | 42 | Exits: North East South West. 43 | 44 | mudsh - /lib > Go west, west again and look. 45 | 46 | You are in a junkyard. Well, you think it is a junkyard. Scrap metal 47 | and wood is piled conically all around you. You see crude, fearsome 48 | machines but you are unsure of their purpose. A stone tablet of names 49 | and encrypted passwords hangs from a crane. This rubble was once an 50 | important building. 51 | 52 | DIR_COLORS csh.login initlog.conf mime.types rpm/ 53 | HOSTNAME default/ inittab motd securetty 54 | X11/ exports inputrc mtab security/ 55 | adjtime fdprm ioctl.save nsswitch.conf sendmail.cf 56 | aliases filesystems isapnp.gone pam.d/ sendmail.cw 57 | aliases.db fstab issue passwd sendmail.mc 58 | anacrontab gettydefs issue.net passwd- services 59 | at.deny gpm-root.conf issue.net0 passwd.OLD shadow 60 | bashrc group ld.so.cache pcmcia/ shadow- 61 | conf.linuxconf group- ld.so.conf ppp/ shells 62 | conf.modules gshadow lilo.conf printcap skel/ 63 | conf.modules~ gshadow- localtime profile smrsh/ 64 | cron.d/ gtk/ login.defs profile.d/ sysconfig/ 65 | cron.daily/ host.conf logrotate.conf protocols sysctl.conf 66 | cron.fortly/ hosts logrotate.d/ pwdb.conf syslog.conf 67 | cron.hourly/ hosts.allow mail/ rc.d/ termcap 68 | cron.monthly/ hosts.deny mail.rc redhat-release wgetrc 69 | cron.weekly/ httpd/ mailcap resolv.conf 70 | crontab inetd.conf mailcap.vga rmt@ 71 | csh.cshrc info-dir man.config rpc 72 | 73 | Exits: North East South West. 74 | 75 | mudsh - /etc > Go /tmp look then go home. 76 | 77 | You are in a large deserted marketplace. The weather is overcast and 78 | you feel cold. The flagstones are uneven and newspaper soaks in a small 79 | puddle. Occasionally, useful information can be found here. 80 | 81 | (Empty directory) 82 | 83 | Exits: North East West. 84 | 85 | mudsh - /home/mudsh > drop all files 86 | 87 | You are not carrying anything. 88 | 89 | mudsh - /home/mudsh > !sh 90 | 91 | A wizard prevents your action. 92 | mudsh - /home/mudsh > kill /dev/fd0 93 | 94 | You are not strong enough to kill fd0. 95 | mudsh - /home/mudsh > kill zzz 96 | 97 | File zzz not found. 98 | mudsh - /home/mudsh > quit 99 | 100 | Experience points gained this session: 9. Experience points are earned 101 | by actions, but mostly by killing things. 102 | 103 | ## Installation 104 | 105 | ### Dependencies 106 | - PERL 5 107 | 108 | ### Using Install Script 109 | 110 | $ ./install 111 | 112 | This will generate a proper #! header for your system using `which perl` and install mudsh to the same directory. Then, 113 | 114 | $ mudsh 115 | 116 | If for some reason this does not work for your system, you'll need to edit the files yourself. See ./install for instructions. 117 | 118 | ### Using mudsh as the Default Login Shell 119 | 120 | If you want to use mudsh as a default login shell, you may need to edit /etc/shells. In summary: 121 | 122 | $ sudo su 123 | password: 124 | # mv ~user/download/mudsh /bin/mudsh 125 | # whereis perl 126 | perl: /usr/bin/perl5.00503 /usr/bin/perl /usr/man/man1/perl.1.gz 127 | # vi /bin/mudsh 128 | # chown bin.bin /bin/mudsh 129 | # chmod 755 /bin/mudsh 130 | # echo /bin/mudsh >> /etc/shells 131 | # exit 132 | $ /bin/mudsh 133 | 134 | If you want to change or add descriptions, edit the source or litter .mudshrc files in your filing system. Any improvements improve the program or automate the install are welcome. Feel free to make a pull request. 135 | -------------------------------------------------------------------------------- /install: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PERLPATH="`which perl`" 4 | echo "#!$PERLPATH" > mudsh.build 5 | cat mudsh-1.2.perl >> mudsh.build 6 | chmod +x mudsh.build 7 | sudo cp mudsh.build `dirname $PERLPATH`/mudsh 8 | -------------------------------------------------------------------------------- /mudsh-1.2.perl: -------------------------------------------------------------------------------- 1 | #MUD Shell 2 | #(C)2001 Dean "Gandalf" Swift and Xirium 3 | # 4 | #20010209 Gandalf: idea taken from comments on SlashDot.Org 5 | #20010210 Gandalf: start 6 | #20010211 Gandalf: save 7 | #20010212 Gandalf: save test 8 | #20010213 Gandalf: save 9 | #20010214 Gandalf: save test 10 | #20010218 Gandalf: save 11 | #20010302 Gandalf: save fix spacing, add comments 12 | # Examine command contributed by Ron Broberg 13 | # Stat command fixed by Bernard Yap 14 | #20010307 Gandalf: start themes 15 | 16 | #This subroutine, &disp, formats text to 72 columns. 17 | #This is done by using a ruler, $width, to copy the first 72 characters from $in to $line. 18 | #The last space is located and surplus from the next character is returned by prepending it to $in. 19 | #There are exceptions for strings containing "\n", although these are not tested. 20 | #Very long words have undefined results and hyphenation is not implemented. 21 | 22 | sub disp 23 | { 24 | $width="."x72; 25 | $in=shift; 26 | if($in ne "") 27 | { 28 | print("\n"); 29 | } 30 | while(length($in)>length($width)) 31 | { 32 | $in=~s/^($width)//s; 33 | $line=$1; 34 | if($line=~/\n/s) 35 | { 36 | $line=~s/^(.*)\n(.*)$/$1/s; 37 | $in=$2.$in; 38 | } 39 | else 40 | { 41 | $line=~s/^(.*) (.*)$/$1/s; 42 | $in=$2.$in; 43 | } 44 | print("$line\n"); 45 | } 46 | print("$in\n"); 47 | $disp_flag=1; 48 | } 49 | 50 | #For non null input, &disp, outputs a blank line before any other output. 51 | #&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. 52 | #&disp_space only outputs a blank line if &disp has been called then the flag is cleared. 53 | 54 | sub disp_space 55 | { 56 | if($disp_flag==1) 57 | { 58 | print "\n"; 59 | $disp_flag=0; 60 | } 61 | } 62 | 63 | sub inv_add 64 | { 65 | } 66 | 67 | sub inv_sub 68 | { 69 | } 70 | 71 | #-Message inv-empty You are carrying nothing and you have no weapons. 72 | 73 | sub inv_disp 74 | { 75 | &disp($message{"inv-empty"}); 76 | } 77 | 78 | #read configuration file specified as only parameter. 79 | #currently collected configuration information is stored in @alias, @des and @message. 80 | #aliases are not case sensitive, descriptions and messages are case sensitive. 81 | 82 | sub conf_read 83 | { 84 | $temp0=shift; 85 | if(-r $temp0) 86 | { 87 | open(FILE,$temp0); 88 | while(defined($line=)) 89 | { 90 | $line=~s/^\#\-//; 91 | $line=~s/[\n\r]*$//; 92 | if($line!~/^\#/) 93 | { 94 | ($temp0,$temp1,$temp2)=split(/[ \t]+/,$line,3); 95 | $temp0=~tr/[a-z]/[A-Z]/; 96 | if($temp0 eq "ALIAS") 97 | { 98 | $temp1=~tr/[a-z]/[A-Z]/; 99 | $temp2=~tr/[a-z]/[A-Z]/; 100 | $alias{$temp1}=$temp2; 101 | } 102 | elsif($temp0 eq "DESCRIBE") 103 | { 104 | $temp2=~s/\\n/\n/g; 105 | $temp2=~s/\\\\/\\/g; 106 | $des{$temp1}=$temp2; 107 | } 108 | elsif($temp0 eq "MESSAGE") 109 | { 110 | $message{$temp1}=$temp2; 111 | } 112 | else 113 | { 114 | #should output error here 115 | } 116 | } 117 | } 118 | close(FILE); 119 | } 120 | } 121 | 122 | #The following comments form part of the default theme. 123 | #The comments are stored in @des when the prog reads itself as configuration. 124 | #Directives in this format can be added to separate "theme" configuration files. 125 | #In theme files, directives must not be preceded with "#-". 126 | #This is for upward compatibility. 127 | 128 | #-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. 129 | #-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! 130 | #-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. 131 | #-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. 132 | #-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. 133 | #-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. 134 | #-Describe /usr/local You are in a modern town. 135 | #-Describe /var You are in the lobby of a hotel. 136 | #-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. 137 | #-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? 138 | #-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. 139 | #-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."); 140 | #-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. 141 | #-Describe /boot You are in a cave. This place was the beginning of civilisation. 142 | #-Describe /site You are in a trendy suburb. Residential and commercial properties are intermixed."); 143 | 144 | #&describe checks for a description previously read from a theme. 145 | #If none is found, an attempt is made to read ".mudshrc" in the current directory. 146 | #If this is not the case, one of the defaults is tried. 147 | #Descriptions in the theme take precedence. 148 | #This is followed by descriptions in the filing system, although for some directories, such as /proc and /tmp , this is not practical. 149 | 150 | #-Message directory-empty (Empty Directory) 151 | #-Message exits Exits 152 | #-Message direction-north North 153 | #-Message direction-east East 154 | #-Message direction-south South 155 | #-Message direction-west West 156 | #-Message direction-up Up 157 | #-Message direction-home Home 158 | #-Message direction-none (None) 159 | 160 | sub describe 161 | { 162 | if(defined($des{$cwd})) 163 | { 164 | #use description from theme 165 | &disp($des{$cwd}); 166 | } 167 | elsif(-r ".mudshrc") 168 | { 169 | #print description found in .mudshrc in current directory 170 | local($/); 171 | open(FILE,".mudshrc"); 172 | $buffer=; 173 | $buffer=~s/\n\r/\n/gm; 174 | $buffer=~s/\r\n/\n/gm; 175 | $buffer=~s/\r/\n/gm; 176 | $buffer=~s/\n$//gm; 177 | &disp($buffer); 178 | close(FILE); 179 | } 180 | else 181 | { 182 | #use default 183 | if(($cwd eq "/usr/local/bin")||($cwd eq "/usr/bin")) 184 | { 185 | &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."); 186 | } 187 | elsif(($cwd eq "/usr/local/lib")||($cwd eq "/usr/lib")) 188 | { 189 | &disp("You are in workshop. You see many interesting tools. Some are general purpose and some are for highly specialised uses."); 190 | } 191 | elsif(($cwd eq "/usr/local/man")||($cwd eq "/usr/man")) 192 | { 193 | &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\"."); 194 | } 195 | elsif(($cwd eq "/var/spool/mail")||($cwd eq "/var/mail")) 196 | { 197 | &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."); 198 | } 199 | elsif(($cwd eq "/usr/tmp")||($cwd eq "/var/tmp")) 200 | { 201 | &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."); 202 | } 203 | elsif($cwd=~/\/lost\+found$/) 204 | { 205 | &disp("You are in a lost property office."); 206 | } 207 | elsif($cwd eq "/mnt") 208 | { 209 | &disp("You are at an airport."); 210 | } 211 | elsif($cwd=~/\/mnt\/[^\/]+$/) 212 | { 213 | &disp("You are in an airplane."); 214 | } 215 | elsif(($cwd eq "/home")||($cwd=~/^\/[^\/]*\/home$/)) 216 | { 217 | &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."); 218 | } 219 | elsif($cwd=~/\/home[^\/]*\/gandalf/) 220 | { 221 | &disp("You are in a disorganised room."); 222 | } 223 | elsif(($cwd eq "/www")||($cwd eq "/home/httpd/html")) 224 | { 225 | &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."); 226 | } 227 | elsif((($cwd=~/^\/www\//)&&($cwd=~/\/cgi-bin$/))||($cwd eq "/home/httpd/cgi-bin")) 228 | { 229 | &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."); 230 | } 231 | elsif(($cwd eq "/www-log")||($cwd eq "/home/httpd/logs")||($cwd eq "/usr/local/apache/logs")) 232 | { 233 | &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."); 234 | } 235 | elsif($cwd=~/^\/site\/[^\/]+\/www$/) 236 | { 237 | &disp("You are in a small office."); 238 | } 239 | } 240 | print "\n"; 241 | $temp0=`ls -CF`; 242 | if($temp0 eq "") 243 | { 244 | $temp0=$message{"directory-empty"}."\n"; 245 | } 246 | print $temp0; 247 | $temp0=""; 248 | if($dir_n ne "") 249 | { 250 | $temp0.=" ".$message{"direction-north"}; 251 | } 252 | if($dir_e ne "") 253 | { 254 | $temp0.=" ".$message{"direction-east"}; 255 | } 256 | if($dir_s ne "") 257 | { 258 | $temp0.=" ".$message{"direction-south"}; 259 | } 260 | if($dir_w ne "") 261 | { 262 | $temp0.=" ".$message{"direction-west"}; 263 | } 264 | if($temp0 eq "") 265 | { 266 | $temp0=" ".$message{"direction-none"}; 267 | } 268 | &disp($message{"exits"}.":$temp0."); 269 | } 270 | 271 | #&scout identifies target directories for navigation. 272 | #(Replace this bit to *really* confuse your users.) 273 | #If not in root directory, you can go North. 274 | #If not in root directory, obtain the names of the items in the parent directory in alphabetical order. 275 | #For all of the readable directories found in the parent directory, create a window of three items. 276 | #Terminate loop if current directory is middle element of window. 277 | #First and last elements of window are East and West. 278 | #Obtain the names of the items in the current directory in alphabetical order. 279 | #The first readable directory is South. 280 | #A null string indicates that an exit is not available. 281 | #(This algorithm will change so that North and South are consistant and Up works how North currently does.) 282 | 283 | sub scout 284 | { 285 | $dir_w=""; 286 | $dir_e=""; 287 | $dir_s=""; 288 | if($cwd eq "/") 289 | { 290 | $dir_n=""; 291 | } 292 | else 293 | { 294 | $dir_n=".."; 295 | #scout West and East: search for sibling directories here 296 | @temp0=glob("../*"); 297 | $temp1=$cwd; 298 | $temp1=~s/.*\///; 299 | $temp1=~s/([^0-9A-Za-z])/\\$1/g; 300 | $flag=0; 301 | $x=0; 302 | for($x=0;($x<@temp0)&&($flag==0);$x++) 303 | { 304 | if(((((stat($temp0[$x]))[2])&040000)!=0)&&(-r $temp0[$x])) 305 | { 306 | if($temp0[$x]=~/$temp1$/) 307 | { 308 | $flag=1; 309 | } 310 | else 311 | { 312 | $dir_w=$temp0[$x]; 313 | } 314 | } 315 | } 316 | for(;($x<@temp0)&&($dir_e eq "");$x++) 317 | { 318 | if(((((stat($temp0[$x]))[2])&040000)!=0)&&(-r $temp0[$x])) 319 | { 320 | $dir_e=$temp0[$x]; 321 | } 322 | } 323 | } 324 | #scout South: search for first child directory here 325 | @temp0=glob("*"); 326 | for($x=0;($x<@temp0)&&($dir_s eq "");$x++) 327 | { 328 | if(((((stat($temp0[$x]))[2])&040000)!=0)&&(-r $temp0[$x])) 329 | { 330 | $dir_s=$temp0[$x]; 331 | } 332 | } 333 | } 334 | 335 | #Attempt to change directory. 336 | #This routine reports an error to output if directory change is not possible. 337 | 338 | #-Message cd-cannot You cannot go in that direction. 339 | #-Message cd-deny A force field is blocking you. Your face is squashed and it tingles. 340 | #-Message cd-unknown This exit does not exist. You feel confused. 341 | 342 | sub cd 343 | { 344 | $dir=shift; 345 | if($dir eq "") 346 | { 347 | &disp($message{"cd-cannot"}); 348 | } 349 | else 350 | { 351 | if(chdir($dir)) 352 | { 353 | $cwd=`pwd`; 354 | $cwd=~s/\n//; 355 | &scout(); 356 | $xp++; 357 | } 358 | else 359 | { 360 | if(-e $dir) 361 | { 362 | &disp($message{"cd-deny"}); 363 | } 364 | else 365 | { 366 | &disp($message{"cd-unknown"}); 367 | } 368 | } 369 | } 370 | return(1); 371 | } 372 | 373 | #&go maps directions to directory names found by &scout before calling &cd. 374 | #Not sure if use of glob here has a bug. 375 | 376 | sub go 377 | { 378 | if(($c eq "NORTH")||($c eq "N")||($c eq "UP")||($c eq "..")) 379 | { 380 | return(&cd($dir_n)); 381 | } 382 | elsif(($c eq "WEST")||($c eq "W")) 383 | { 384 | return(&cd($dir_w)); 385 | } 386 | elsif(($c eq "EAST")||($c eq "E")) 387 | { 388 | return(&cd($dir_e)); 389 | } 390 | elsif(($c eq "SOUTH")||($c eq "S")) 391 | { 392 | return(&cd($dir_s)); 393 | } 394 | elsif(($c eq "HOME")||($c eq "H")) 395 | { 396 | $temp=glob("~"); 397 | return(&cd($temp)); 398 | } 399 | return(0); 400 | } 401 | 402 | #Array of words is passed to &parse. 403 | #Words are decoded from the beginning and discarded as they are interpreted. 404 | #$c should always be capitalised, with trailing punctuation removed, which speeds and simplifies decode. 405 | #(Ensuring the consistancy of $c when the array is shifted should be the action of a subroutine.) 406 | #Some commands grab the whole line, others allow further commands to be appended. 407 | #Glue words, such as "and" are ignored but unknown words halt decode, possibly after partial decode. 408 | 409 | #-Message direction-ambiguous This direction is ambiguous. 410 | #-Message directory-ambiguous This directory is ambiguous. 411 | #-Message demo-move This is the demo version of MUDShell. You cannot move files. 412 | #-Message demo-read This is the demo version of MUDShell. You cannot view files. 413 | #-Message demo-edit This is the demo version of MUDShell. You cannot edit files. 414 | 415 | sub parse 416 | { 417 | *command=shift; 418 | while(@command) 419 | { 420 | $c=$command[0]; 421 | $c=~tr/[a-z]/[A-Z]/; 422 | $c=~s/([0-9A-Z])[^0-9A-Z]$/$1/; 423 | if(defined($alias{$c})) 424 | { 425 | $c=$alias{$c}; 426 | } 427 | if(($c eq "HELP")||($c eq "H")||($c eq "?")||($c eq "MAN")) 428 | { 429 | &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."); 430 | if($exec_flag==1) 431 | { 432 | $temp="currently enabled"; 433 | } 434 | else 435 | { 436 | $temp="not available from this login shell"; 437 | } 438 | &disp("Prefix an explanation mark (\"!\") to execute proper shell commands. (This feature is $temp.)"); 439 | shift(@command); 440 | } 441 | elsif($c eq "GO") 442 | { 443 | shift(@command); 444 | $c=$command[0]; 445 | $c=~tr/[a-z]/[A-Z]/; 446 | $c=~s/([0-9A-Z])[^0-9A-Z]$/$1/; 447 | if(!&go()) 448 | { 449 | @temp=glob($command[0]); 450 | if(@temp>1) 451 | { 452 | &disp($message{"direction-ambiguous"}); 453 | } 454 | else 455 | { 456 | &cd($temp[0]); 457 | } 458 | } 459 | shift(@command); 460 | } 461 | elsif(&go()) 462 | { 463 | shift(@command); 464 | } 465 | elsif($c eq "CD") 466 | { 467 | shift(@command); 468 | @temp=glob($command[0]); 469 | if(@temp>1) 470 | { 471 | &disp($message{"directory-ambiguous"}); 472 | } 473 | else 474 | { 475 | &cd($temp[0]); 476 | } 477 | shift(@command); 478 | } 479 | elsif($c eq "LOOK") 480 | { 481 | &describe(); 482 | $xp++; 483 | shift(@command); 484 | } 485 | elsif($c eq "INV") 486 | { 487 | &inv_disp(); 488 | $xp++; 489 | shift(@command); 490 | } 491 | elsif($c eq "TAKE") 492 | { 493 | &disp($message{"demo-move"}); 494 | return(1); 495 | } 496 | elsif($c eq "DROP") 497 | { 498 | &disp("You are not carrying anything."); 499 | return(1); 500 | } 501 | elsif(($c eq "TALK")||($c eq "SAY")||($c eq "SHOUT")) 502 | { 503 | shift(@command); 504 | write(join(@command," ")); 505 | return(1); 506 | } 507 | elsif($c eq "EMOTE") 508 | { 509 | shift(@command); 510 | write("Guest ".join(@command," ")); 511 | return(1); 512 | } 513 | elsif($c eq "WHISPER") 514 | { 515 | &disp("Other users are not logged in."); 516 | return(1); 517 | } 518 | elsif($c eq "EXAMINE") { 519 | shift(@command); 520 | while($command[0] ne "") { 521 | if($command[0]!~/^and$/i) { 522 | $temp=$command[0]; 523 | $temp=~s/^.*\/([^\/]*)$/$1/; 524 | if("$temp" eq "") { 525 | &disp("No such object"); 526 | } elsif(!-e $temp) { 527 | &disp("Object $temp not found here."); 528 | } else { 529 | $examfile=`file $temp`; 530 | $examfile=~s/^.*: //; 531 | chomp($examfile); 532 | &disp("$temp is a $examfile"); 533 | $xp++; 534 | } 535 | } 536 | shift(@command); 537 | } 538 | } 539 | elsif($c eq "READ") 540 | { 541 | &disp($message{"demo-read"}); 542 | return(1); 543 | } 544 | elsif($c eq "EDIT") 545 | { 546 | &disp($message{"demo-edit"}); 547 | return(1); 548 | } 549 | elsif($c eq "KILL") 550 | { 551 | shift(@command); 552 | mkdir("~/Trash",0600); #fix this 553 | while($command[0] ne "") 554 | { 555 | if($command[0]!~/^and$/i) 556 | { 557 | $temp=$command[0]; 558 | $temp=~s/^.*\/([^\/]*)$/$1/; 559 | if(!-e $command[0]) 560 | { 561 | &disp("File $temp not found."); 562 | } 563 | else 564 | { 565 | $len=(stat($temp))[7]; 566 | if(rename($command[0],"~/Trash/$temp")) #fix this 567 | { 568 | &disp("You killed $temp."); 569 | $xp+=$len; 570 | } 571 | else 572 | { 573 | &disp("You are not strong enough to kill $temp."); 574 | } 575 | } 576 | } 577 | shift(@command); 578 | } 579 | } 580 | elsif($c eq "STAT") 581 | { 582 | &disp("You have $xp experience points."); 583 | shift(@command); 584 | } 585 | elsif($c eq "EXIT") 586 | { 587 | return(0); 588 | } 589 | elsif($c=~/^\#/) 590 | { 591 | #shell comment 592 | return(1); 593 | } 594 | elsif(($c ne "AND")&&($c ne "THEN")&&($c ne "THE")&&($c ne "OF")&&($c ne "AGAIN")) 595 | { 596 | print("Eh?\n"); 597 | return(1); 598 | } 599 | else 600 | { 601 | shift(@command); 602 | $c=$command[0]; 603 | $c=~tr/[a-z]/[A-Z]/; 604 | $c=~s/([0-9A-Z])[^0-9A-Z]$/$1/; 605 | if(defined($alias{$c})) 606 | { 607 | $c=$alias{$c}; 608 | } 609 | } 610 | } 611 | return(1); 612 | } 613 | 614 | #Aliases are defined here. 615 | #These aliases are added to @alias when the program reads itself as configuration. 616 | #Aliases are substituted before commands are interpreted. 617 | #Currently, you can only substitute one word for another. 618 | 619 | #-Alias g go 620 | #-Alias l look 621 | #-Alias ls look 622 | #-Alias inventory inv 623 | #-Alias i inv 624 | #-Alias exam examine 625 | #-Alias ex examine 626 | #-Alias open edit 627 | #-Alias view read 628 | #-Alias more read 629 | #-Alias less read 630 | #-Alias stats stat 631 | #-Alias quit exit 632 | #-Alias qui exit 633 | #-Alias qu exit 634 | #-Alias q exit 635 | #-Alias logout exit 636 | #-Alias logoff exit 637 | 638 | #Main program is here. 639 | #Display banner, check for login shell, check safeguard then enter decode loop. 640 | #Lines are checked for shell escapes before being sent to the parser. 641 | #If an exit command is encountered, &parse returns an exit value. 642 | #Accumulated experience points are displayed before termination. 643 | 644 | print("\@\@\@\\ /\@\@\@ Version 1.2: \@\@\@ o\@\@\@\@\@o \@\@\@ (C)2001 Xirium \@\@\@ \@\@\@\n"); 645 | print("\@\@\@\@\\ /\@\@\@\@ PointyStick \@\@\@ /\@\@\@\@\@\@\@\@\@\\ \@\@\@ and Dean Swift \@\@\@ \@\@\@\n"); 646 | print("\@\@\@\@\@\\ /\@\@\@\@\@ \@\@\@ \@\@\@' `\@\@\@ \@\@\@ \@\@\@ \@\@\@\n"); 647 | print("\@\@\@\@\@\@\\ /\@\@\@\@\@\@ \@\@\@ \@\@\@ o\@\@\@b\@\@\@ \@\@\@. \@\@\@ \@\@\@d\@\@\@o o\@\@\@\@o \@\@\@ \@\@\@\n"); 648 | print("\@\@\@\\\@\@\@V\@\@\@/\@\@\@ \@\@\@ \@\@\@ /\@\@\@\@\@\@\@\@\@ \\\@\@\@o. \@\@\@\@\@\@\@\@\@\\ /\@\@\@\@\@\@\@\@\\ \@\@\@ \@\@\@\n"); 649 | print("\@\@\@ \\\@\@\@\@\@/ \@\@\@ \@\@\@ \@\@\@ \@\@\@' `\@\@\@ *\@\@\@\@\@o \@\@\@' `\@\@\@ \@\@\@' `\@\@\@ \@\@\@ \@\@\@\n"); 650 | print("\@\@\@ \\\@\@\@/ \@\@\@ \@\@\@ \@\@\@ \@\@\@ \@\@\@ `*\@\@\@\\ \@\@\@ \@\@\@ \@\@\@\@\@\@\@\@\@\@ \@\@\@ \@\@\@\n"); 651 | print("\@\@\@ \@\@\@ \@\@\@ \@\@\@ \@\@\@ \@\@\@ \@\@\@ `\@\@\@ \@\@\@ \@\@\@ \@\@\@\@\@\@\@\@\@\@ \@\@\@ \@\@\@\n"); 652 | print("\@\@\@ \@\@\@ \@\@\@. ,\@\@\@ \@\@\@. ,\@\@\@ \@\@\@. ,\@\@\@ \@\@\@ \@\@\@ \@\@\@. \@\@\@ \@\@\@\n"); 653 | print("\@\@\@ \@\@\@ \\\@\@\@\@\@\@\@\@\@ \\\@\@\@\@\@\@\@\@\@ \\\@\@\@\@\@\@\@\@\@/ \@\@\@ \@\@\@ \\\@\@\@\@\@\@\@\@ \@\@\@ \@\@\@\n"); 654 | print("\@\@\@ \@\@\@ *\@\@\@P\@\@\@ *\@\@\@P\@\@\@ *\@\@\@\@\@* \@\@\@ \@\@\@ *\@\@\@\@\@\@ \@\@\@ \@\@\@\n"); 655 | &disp("You are logged in as Guest."); 656 | if($0!~/^\-/) 657 | { 658 | #this is not a login shell therefore allows external commands to be run 659 | $exec_flag=1; 660 | } 661 | @temp=`ps`; 662 | if(scalar(@temp)<=3) 663 | { 664 | #there are too few tasks for this not to be a login shell 665 | $exec_flag=0; 666 | } 667 | &conf_read($0); #reads self for configuration 668 | &conf_read("/etc/mudshrc"); 669 | &conf_read("/opt/xirium/mudsh/conf"); 670 | &conf_read(glob("~/.mudshrc")); 671 | $xp=0; 672 | $cwd=`pwd`; 673 | $cwd=~s/\n//; 674 | &scout(); 675 | &describe(); 676 | $continue=1; 677 | while($continue) 678 | { 679 | &disp_space(); 680 | print("mudsh - $cwd > "); 681 | $buffer=<>; 682 | $buffer=~s/[\n\r]*$//g; 683 | $buffer=~s/\t/ /g; 684 | $buffer=~s/ +/ /g; 685 | $buffer=~s/^ //; 686 | $buffer=~s/ $//; 687 | if($buffer=~/^!/) 688 | { 689 | if($exec_flag!=1) 690 | { 691 | &disp("A wizard prevents your action."); 692 | } 693 | else 694 | { 695 | $buffer=~s/^!//; 696 | system($buffer); 697 | } 698 | } 699 | else 700 | { 701 | @line=split(/ /,$buffer); 702 | $continue=&parse(\@line); 703 | } 704 | } 705 | &disp("Experience points gained this session: $xp. Experience points are earned by actions, but mostly by killing things."); 706 | --------------------------------------------------------------------------------