Development, DIY, Homebrew, Networking, Raspberry Pi, Retro, Update, Vintage

Zork Telnet Server – Part II

August 22, 2018

While I was testing the Zork Telnet Server a thought came to me…

“I should write a menu into the rbash login script giving the user a choice between all of the different Infocom text adventure games.”

I decided that I would do just that, but I didn’t want to complicate the project and delay it’s launch. I decided to shelve the idea for a few weeks.

Two weeks later, I decided to take the idea off of the shelf and see where it took me. It was fairly easy to configure the Pi Zero W to allow a Telnet session, auto-run frotz and launch the game Zork I. It was even easy to find a shell script that would update the DNS records at GoDaddy for my static dns record to point to my dynamic IP. Would a bash login script for selecting a specific game file from a menu be just as easy? Would it work at all? I was determined to find out.

I’m not going to make this a long post, because frankly, it was relatively easy to make this happen. Here is the code that I used to display the list of games to choose from, and then read the input from the user:

echo Enter your preferred column width:
read COLWIDTH

echo
echo ########################################
echo List of games available:
echo [1] A Mind Forever Voyaging [2] Ballyhoo
echo [3] Beyond Zork [4] Border Zone
echo [5] Bureaucracy [6] Cutthroats
echo [7] Deadline [8] Enchanter
echo [9] Hitchhiker\’s Guide to the Galaxy
echo [10] Hollywood Hijinx [11] Infidel
echo [12] Journey
echo [13] Leather Goddesses of Phobos
echo [14] The Lurking Horror [15] Moonmist
echo [16] Nord and Bert
echo [17] Planetfall [18] Plundered Hearts
echo [19] Seastalker [20] Sherlock
echo [21] Shogun [22] Sorcerer
echo [23] Spellbreaker [24] Starcross
echo [25] Stationfall [26] Suspect
echo [27] Suspended [28] Trinity
echo [29] Wishbringer [30] Witness
echo [31] Zork I [32] Zork II
echo [33] Zork 3
echo
echo “Enter the number of the game you want to play:”
read gamenum

if [ $gamenum -eq 1 ]
        then exec firejail frotz -w $COLWIDTH ~/games/amfv.DAT
elif [ $gamenum -eq 2 ]
        then exec firejail frotz -w $COLWIDTH ~/games/ballyhoo.DAT
elif [ $gamenum -eq 3 ]
        then exec firejail frotz -w $COLWIDTH ~/games/beyondzork.DAT
elif [ $gamenum -eq 4 ]
        then exec firejail frotz -w $COLWIDTH ~/games/border_zone.DAT
elif [ $gamenum -eq 5 ]
        then exec firejail frotz -w $COLWIDTH ~/games/bureaucracy.DAT
elif [ $gamenum -eq 6 ]
        then exec firejail frotz -w $COLWIDTH ~/games/cutthroats.z5
elif [ $gamenum -eq 7 ]
        then exec firejail frotz -w $COLWIDTH ~/games/deadline.z5
elif [ $gamenum -eq 8 ]
        then exec firejail frotz -w $COLWIDTH ~/games/enchanter.z5
elif [ $gamenum -eq 9 ]
        then exec firejail frotz -w $COLWIDTH ~/games/hhgg.z5
elif [ $gamenum -eq 10 ]
        then exec firejail frotz -w $COLWIDTH ~/games/hollywood.DAT
elif [ $gamenum -eq 11 ]
        then exec firejail frotz -w $COLWIDTH ~/games/infidel.z5
elif [ $gamenum -eq 12 ]
        then exec firejail frotz -w $COLWIDTH ~/games/journey.ZIP
elif [ $gamenum -eq 13 ]
        then exec firejail frotz -w $COLWIDTH ~/games/leather_goddesses_of_phobos.z5
elif [ $gamenum -eq 14 ]
        then exec firejail frotz -w $COLWIDTH ~/games/lurking.DAT
elif [ $gamenum -eq 15 ]
        then exec firejail frotz -w $COLWIDTH ~/games/moonmist.z5
elif [ $gamenum -eq 16 ]
        then exec firejail frotz -w $COLWIDTH ~/games/nordbert.DAT
elif [ $gamenum -eq 17 ]
        then exec firejail frotz -w $COLWIDTH ~/games/planetfall.z5
elif [ $gamenum -eq 18 ]
        then exec firejail frotz -w $COLWIDTH ~/games/plundered_hearts.z5
elif [ $gamenum -eq 19 ]
        then exec firejail frotz -w $COLWIDTH ~/games/seastalker.z5
elif [ $gamenum -eq 20 ]
        then exec firejail frotz -w $COLWIDTH ~/games/sherlock.DAT
elif [ $gamenum -eq 21 ]
        then exec firejail frotz -w $COLWIDTH ~/games/shogun.ZIP
elif [ $gamenum -eq 22 ]
        then exec firejail frotz -w $COLWIDTH ~/games/sorcerer.z5
elif [ $gamenum -eq 23 ]
        then exec firejail frotz -w $COLWIDTH ~/games/spellbreaker.z5
elif [ $gamenum -eq 24 ]
        then exec firejail frotz -w $COLWIDTH ~/games/starcross.z5
elif [ $gamenum -eq 25 ]
        then exec firejail frotz -w $COLWIDTH ~/games/stationfall.DAT
elif [ $gamenum -eq 26 ]
        then exec firejail frotz -w $COLWIDTH ~/games/suspect.z5
elif [ $gamenum -eq 27 ]
        then exec firejail frotz -w $COLWIDTH ~/games/suspended.z5
elif [ $gamenum -eq 28 ]
        then exec firejail frotz -w $COLWIDTH ~/games/trinity.DAT
elif [ $gamenum -eq 29 ]
        then exec firejail frotz -w $COLWIDTH ~/games/WISHBRIN.DAT
elif [ $gamenum -eq 30 ]
        then exec firejail frotz -w $COLWIDTH ~/games/witness.z5
elif [ $gamenum -eq 31 ]
        then exec firejail frotz -w $COLWIDTH ~/games/ZORK1.DAT
elif [ $gamenum -eq 32 ]
        then exec firejail frotz -w $COLWIDTH ~/games/ZORK2.DAT
elif [ $gamenum -eq 33 ]
        then exec firejail frotz -w $COLWIDTH ~/games/ZORK3.DAT
fi
logout

Once I had this working, I worked a bit on trapping the various errors and exit codes that may occur so that the system logs out the user if an error occurs that would have dropped the user to an open prompt or if the user presses CTRL-C or CTRL-Break or something like that. That code goes just before this code in the script and looks like this:

# Our general exit handler

cleanup() {

err=$?

echo “Cleaning stuff up…”

trap ” EXIT INT TERM

exit $err

}

sig_cleanup() {

trap ” EXIT # some shells will call EXIT after the INT handler

false # sets $?

cleanup

}

trap cleanup EXIT

trap sig_cleanup INT QUIT TERM

With all of this working, I spent a few hours testing things and making sure that everything would work the way that I intended. So far, it is working very well. And with that, this update is complete. Please enjoy the Zork Telnet Server and send me feedback.

You Might Also Like

No Comments

Leave a Reply

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