Hunt The Wumpus
Problem this snippet solves: For all you "Hunt the Wumpus" fans out there, here's an iRule clone implemented on top of the FTP protocol. This is most likely the first game written as an iRule. For all you "Hunt the Wumpus" fans out there, here's a clone that is similar in nature to the Wumpus game, but implemented in an iRule on top of the FTP protocol. You will use a command line ftp client to play the game. How to use this snippet: The gist of the original "Hunt the Wumpus" game is as follows: Using a command line text interface, a player of Hunt the Wumpus enters commands to move through the rooms, or shoot arrows along crooked paths through several adjoining rooms. There are twenty rooms, each connecting to three others, arranged like the vertices of a dodecahedron (or the faces of an icosahedron). Hazards include bottomless pits, super bats (which drop the player in a random location) and the Wumpus itself. When the player has deduced from hints which chamber the Wumpus is in without entering it, he fires an arrow into the Wumpus' chamber to slay it. However, firing the arrow into the wrong chamber startles the Wumpus, which then devours the player. My iRule version isn't quite as complex but it does have the same feeling. Imagine you are on the hunt for the Wumpus. You start out in a square room with doors on each wall corresponding to it's direction (N, E, W, and S). If you hit the correct direction, you'll be one step closer to finding the Wumpus. After 5 correct choices, the Wumpus will be yours and all the fame that goes along with it! Create a virtual server on your BIG-IP listening on port 21 (FTP). Apply the following iRule to your Virtual Open a command line ftp client and connect to your FTP based virtual server. Login as "ftp" or "Anonymous" - The Wumpus doesn't care about authentication! Try CD'ing different directions until you find the Wumpus. Once you've found him, try it again. His location is different each time you play. Code : when RULE_INIT { set ::DEBUG 1 set ::DIRECTIONS [list "N" "E" "W" "S"] } when CLIENT_ACCEPTED { if { $::DEBUG } { log local0. "client accepted" } # build path to wumpus expr srand([clock clicks]) set PATH [list \ [lindex $::DIRECTIONS [expr int(4*rand())]] \ [lindex $::DIRECTIONS [expr int(4*rand())]] \ [lindex $::DIRECTIONS [expr int(4*rand())]] \ [lindex $::DIRECTIONS [expr int(4*rand())]] \ [lindex $::DIRECTIONS [expr int(4*rand())]] ] set LOCATION 0 TCP::respond "220 (Wumpus Game)\r\n" TCP::release TCP::collect } when CLIENT_DATA { set client_data [string trim [TCP::payload]] if { $::DEBUG } { log local0. "---------------------------" } if { $::DEBUG } { log local0. "payload '$client_data'" } set CURPATH "" for {set i 0} {$i<$LOCATION} {incr i} { if { [string length $CURPATH] == 0 } { set CURPATH "[lindex $PATH $i]" } else { set CURPATH "$CURPATH/[lindex $PATH $i]" } } set NEXTPATH $CURPATH if { $LOCATION < [llength $PATH] } { if { [string length $NEXTPATH] == 0 } { set NEXTPATH "[lindex $PATH [expr $LOCATION]]" } else { set NEXTPATH "$NEXTPATH/[lindex $PATH [expr $LOCATION]]" } } set cmd [string toupper [lindex [split $client_data " "] 0]] set cmd_arg [string toupper [lindex [split $client_data " "] 1]] #--------------------------------------------------- # Block or alert specific commands #--------------------------------------------------- switch $cmd { "USER" { if { !($cmd_arg equals "ANONYMOUS") && !($cmd_arg equals "FTP") } { TCP::respond "550 Come on, do think the Wumpus requires authentication? Please login as Anonymous...\r\n" } else { TCP::respond "230 Login successful. Welcome to the Wumpus game. The Wumpus is hidden in a series of directions. CD a direction (N,E,W,S) to start the hunt!\r\n" } } "PORT" { TCP::respond "500 The Wumpus doesn't know how to reply to PORT requests.\r\n" } "PASV" { TCP::respond "502 The Wumpus doesn't know how to reply to PASV requests.\r\n" } "LIST" { if { $LOCATION < [llength $PATH] } { TCP::respond "200 ($CURPATH) : Current Path. Pick a direction (N,E,W,S)!\r\n" } else { TCP::respond "200 ($CURPATH) : YOU FOUND THE WUMPUS!!!\r\n" } } "CWD" { if { $::DEBUG } { log local0. "Requested path: '$cmd_arg'" } if { $::DEBUG } { log local0. "Expected Path: '[lindex $PATH $LOCATION]'" } if { $cmd_arg eq [lindex $PATH $LOCATION] } { incr LOCATION if { $LOCATION < [llength $PATH] } { TCP::respond "200 ($NEXTPATH) : '$cmd_arg' is Correct. Please pick the next direction (N,E,W,S)!\r\n" } else { TCP::respond "200 WOOHOO - YOU FOUND THE WUMPUS! Come back again soon.\r\n" TCP::release return } } else { TCP::respond "200 ($CURPATH) : '$cmd_arg' Wrong Choice. Please pick a direction (N,E,W,S).\r\n" } } "PWD" { TCP::respond "200 ($CURPATH) Please pick the next direction (N,E,W,S)!\r\n" } "QUIT" { TCP::respond "200 The Wumpus says Bye Bye! Play again soon!\r\n" TCP::release return } "HELP" { TCP::respond "200 Welcome to the Wumpus game. The Wumpus is hidden in a series of directions. CD a direction (N,E,W,S) to start the hunt!\r\n" } default { if { $::DEBUG } { log local0. "Unknown Command '$cmd!" } TCP::respond "550 UNKNOWN command '$cmd'\r\n" } } if { $::DEBUG } { log local0. "Returning control to client" } TCP::payload replace 0 [string length [TCP::payload]] "" TCP::collect } when CLIENT_CLOSED { if { $::DEBUG } { log local0. "client closed" } }338Views0likes2Comments