Apple II, Classic, Development, DIY, Homebrew, IIgs, Networking, Raspberry Pi, Retro

Zork Telnet Server

August 1, 2018

When I was a kid, I read a ton of books. In about 1987, my mom brought me home two new books to read and she was very excited about them. They were called “Choose your own adventure” books. You would read a chapter or two, and then the book would ask you a question, and if the answer was “a” then you would turn to a certain page number, or if the answer was “b” then you would turn to a different page number. Your choices decided the story, and you would thus choose how the story ended. Also, you could go back and make the other choice, just to see how your decision changed things. Needless to say, this new book format was a huge hit for me! I loved these “interactive fiction” stories. I read a ton of them. I bet I read over a hundred of these books.

How does this relate to computers, and retro computers in particular, one may ask oneself? You see, the entire time I was reading these “interactive fiction” books, I was thinking about how cool it would be if someone made this into a video game. A reading video game where you chose what the players did? What a concept! That would be groundbreaking! When I learned how to code, I would write them, and they would rule the galaxy! It wasn’t until 1993 when I purchased the game ‘Return To Zork’ for my PC that I really learned about the vast library of Interactive Fiction games that Infocom had created. Since I had missed the original games in the height of their glory, and didn’t have any way to get a copy of them at the time, I moved on and played other, more modern games, built PC systems, learn to design and code web pages, etc. But I never lost that idea that if given the chance, I would love to play these games. I just thought that the idea of Interactive fiction video games would be so cool. And I was right!

The story of Infocom is a great one. A couple of guys from MIT named Mark Blank and Dave Lebling played a game called ‘Colossal Cave Adventure’ on a PDP-10 mainframe computer. This game was unlike anything anyone in computers had ever imagined. It was an adventure game. An RPG! In the game, players control the character through simple text commands, typed into the terminal, in order to explore a cave that is rumored to be riddled with treasures. Mark and Dave were inspired by this game, the first text adventure game (and as far as I know, the first RPG) and wanted to write one of their own. Their game, Zork, would be much larger, and would have much more depth and content than Colossal Cave Adventure ever did. The game, when finished, was so large that they had to split it up into three parts in order to fit into the mainframe’s memory, and that (according to wikipedia) was despite the fact that they used a revolutionary new virtual memory system to maximize the memory available to the game. If you want to know the complete story behind Infocom, Colossal Cave Adventure, or Interactive Fiction in general, I highly recommend watching the Jason Scott documentary, Get Lamp: The Text Adventure Documentary.

Fast forward to today, and I have copies of all of the original Infocom games, in the form of a game titled “The Lost Treasures of Infocom” on my Apple IIgs. Last week, I decided to sit down and play through the first Zork game, all the way to the end. Now I had tried to do this many, MANY, times before and I always got stuck, lost, eaten by a grue in the dark because I used up all of my lamp light, etc. So I did what any honest, hard-working adventure game player would do – I cheated. I asked my good friend Google for a walk-through. I know, shame upon my family for generations to come, right? Well, I bet that doesn’t even make the first page on the list of things I have to answer for someday so I’m ok with it and you should be too. If you think that you can get through this game without hints or a guidebook or some other form of cheating, have I got a deal for you! As Tom Sawyer once said to the kids in his neighborhood “Whitewashin’s fun!”

I played all the way through the game, and because I had played it several times before, I didn’t feel like a walk-through would be too spoilery for me (yes, that is a word, spellcheck!) I have been listening to the podcast “Eaten By A Grue” by Kevin Savetz and Carrington Vanston and they both said that a.) the Zork games are nearly impossible without a hint or guide book or walk-through or something, and b.) If you play more and more of them, you start to develop a skill or a knack for knowing what to do or how to think your way through a puzzle in these games. I was not disappointed in my decision either. For me, it was about finally seeing what the secret was that to some of the puzzles that I could not figure out, all of those times before. I finally got to read the story through to the end. I played the game on my IIgs, not the original version mind you, but certainly a retro experience.

While I was playing the game, I got an idea that someone surely already had though of and acted upon. The idea was that since this game is 100% text, why can’t we serve it via a telnet session and turn it into an ‘online interactive fiction game’? It was so simple that I knew someone had to have a server online running this. I searched google and sure enough, there were several references to Zork servers online with, sure enough, telnet access. Most (or all) of the servers that I found were no longer up, and the ones that were still online, were no longer serving Zork. I decided it would be fun to build my own. I started by asking Skip Thompson about the idea of turning it into a BBS game. Skip is the admin of the BBS site Dura-Europas, (telnet: dura-bbs.net:6359) and is considered the Patriarch of GBBS configurations and ACOS programming, the language that GBBS uses for it’s development. Skip loved the idea, but didn’t really know how hard it would be to convert the game to ACOS. My idea was that maybe GBBS could call the game up in it’s native format, but Skip is not sure this is possible. So I decided to do the next best thing: I would install an emulator on a Raspberry Pi to serve the game. I bought a Raspberry Pi Zero W for the job, and while I waited for it to arrive, I used my Pi 3b to begin to develop my Zork Telnet Server. The first thing I had to do was to find an emulator that would run in a Linux CLI environment that could run the game. I read about playing Zork in Linux and decided that ‘frotz‘ was the best answer. Frotz is a Z-machine interpreter, that is, it is a program written to interpret all of the games that are written using the Infocom Z-Machine, the virtual machine that Infocom developed for playing these “massive” games. To install frotz on Raspbian OS, all you have to do is type

sudo apt-get install frotz

and the package will download and install. That’s it. Now, when you run frotz without any parameters, this is what you see:

FROTZ V2.43 curses interface.
An interpreter for all Infocom and other Z-Machine games.
Complies with standard 1.0 of Graham Nelson’s specification.

Syntax: frotz [options] story-file
-a watch attribute setting -O watch object locating
-A watch attribute testing -p plain ASCII output only
-b # background color-P alter piracy opcode
-c # context lines -r # right margin
-d disable color -q quiet (disable sound effects)
-e enable sound-Q use old-style save format
-f # foreground color-s # random number seed value
-F Force color mode-S # transscript width
-h # screen height -t set Tandy bit
-i ignore fatal errors -u # slots for multiple undo
-l # left margin -w # screen width
-o watch object movement -x expand abbreviations g/x/z
-Z # error checking mode (default = 1)
0 = don’t report errors 1 = report first error
2 = report all errors 3 = exit after any error

So all I need to do is get the DAT file from the game and run it, simple enough. I searched online and found that the original three Zork games have been released by Infocom free to the public, and were readily available to download. I downloaded the Zork I zip package from http://www.infocom-if.org/downloads/downloads.html, extracted the DAT file and copied it over to my Pi. I typed in ‘frotz ZORK1.DAT’ and just like that, it worked! As Hannibal Smith would say in the 80s TV series The A-Team, I love it when a plan comes together!

Now that I had the game working, it was time to configure telnet. In modern times, with security and encryption being so important, telnet has largely been replaced with SSH, or secure shell, which is to say that it is encrypted and thus not as easy to use a man-in-the-middle style attack to gain access to one’s credentials, etc. I could have used SSH, however, none of my retro computers support SSH because the encryption/decryption takes too many resources to process. I wanted people to be able to play this game on their retro machines, so telnet it is. This is why I bought the Pi Zero, so that if I got hacked, Zork would be the only thing I have on the machine. None-the-less, I wanted to take some precautions. Enter rbash and firejail. Rbash is a restricted bash shell, used to lock a user of a linux machine into a limited shell with restrictions on what that user can do. I configured it using the guide at https://veliovgroup.com/article/BmtWycSfZL37zXMZc/how-to-rbash. I won’t repeat the process, but follow that guide and you will be good to go. I set it up so that my user only has access to its home folder and only has access to the commands ‘clear’ and ‘frotz’ and nothing else. Once this was accomplished, I installed another security tool that I had always wanted a reason to try – firejail. Firejail is a sandbox application, made to isolate the program that you are running into a sandbox environment. This tries to prevent an attacker from getting access to restricted parts of your system by crashing the app in use or somehow using that program’s access to the system to gain unauthorized access. Does it work? I don’t know, but I am taking all the precautions that I can. rbash is already installed in Raspbian OS, and firejail is as simple as frotz, just use apt-get to install it. Make sure that you create the symbolic link to firejail for your user to be able to run it. (ln -s /usr/bin/firejail /home/{$user}/usr/bin/firejail) With rbash and firejail configured, my command to run Zork has now become:

firejail frotz -w 80 ZORK1.DAT

This will call the Zork game with the columns set to 80 wide in a sandbox environment, which happens to be a great configuration for running it on a terminal application from an Apple II or Macintosh computer. I still needed to configure the server to call the game automatically before I was ready to give it a try. I had created a .bashrc and a .bash_profile for my user when I configured rbash, and I know that these are ran when the user logged in. I added the following line to the end of each file:

exec firejail frotz -w 80 games/ZORK1.DAT

I also added this line at the beginning:

export TERM=vt100

which sets the terminal emulation to vt100, something that most all terminal clients can use. Before I tried it out, I wanted to do one more configuration change. I wanted to change the default port that telnet runs on, so that someone scanning my IP address would not immediately know what I was running on the server. I edited /etc/services and changed the port for telnet from 23 to 6502. After a restart of inetd, it was time to give it a try:

telnet (zorkserver IP address) 6502

After I realized that while telnetd – the server – may be installed, telnet – the client – was not. Apt-get that, and try again and… it worked! I logged in as my new user, ‘zork’ and the screen cleared and quicker than I could follow along, I was ‘standing in front of a house…’ and frotz was waiting my next command! I quit the game, which automatically logged me out. Perfect.

Next, I needed to configure port forwarding on my home Internet router for port 6502, so that the service could be accessed from the Internet. My home network uses NAT, like 99.9% of all of yours do. My Netgear router made this easy, just tell it the port and the internal IP address that you want to forward that traffic to. Once I did this, I thought that it would be nice if I could use my retroadventures.net domain hosted by GoDaddy to serve a dynamic DNS record to point to my router’s public address. Another trip to the Google machine and yes, someone has written a linux script for updating your GoDaddy DNS records via their API key. I created the key in the GoDaddy web portal, downloaded and configured go daddy_ddns.py from https://github.com/CarlEdman/godaddy-ddns to use my GoDaddy API key, and then I created a crontab entry on my Pi to run the script every hour, updating my DNS record for zork.retroadventures.net to point to my router’s public IP.

After testing that I could in fact login to the server from the Internet using zork.retroadventures.net, I posted to Skip’s BBS and told the group there of my results and invited them to login and check it out. The results were good. Some users had some issues with Syncterm in Windows, but other than that, things worked for them as well as they worked for me. A few days later the Pi Zero W came in and I redid the entire process on that machine, gave it a static IP address, and retested everything.

And with that, I am pleased to announce that you are all welcome to login via telnet to my Zork Telnet Server!

Server: zork.retroadventures.net
Port: 6502
User: zork
Pass: 2018Zork

As soon as I can get to it, I will be posting a web form here on the blog site, that will allow you to register for your own login account, which will allow you to save your progress in the game. I may add other games in the future, but for now, let’s play some Zork!

You Might Also Like

3 Comments

  • Reply John August 1, 2018 at 1:02 pm

    Simply awesome. Thank you!

  • Reply arrThar September 20, 2018 at 7:04 pm

    Thanks! I used to play zork at CMU in the 70’s.

    • Reply Jeff Ramsey September 20, 2018 at 7:40 pm

      You’re welcome. I had a blast making it.

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.