W
Will Shattuck
Thanks for all the suggestions in the previous email about getting
started. I looked at a lot of resources today and thought I would
just get started.
The first thing I have to do is get connected and logged in. However
nethack.alt.org doesn't use a traditional telnet login prompt. it
uses a menu displayed with a =3D> prompt waiting for user input. So
here is what I have so far. it does connect but I can't get logged
in
<code>
require 'net/telnet'
# Telnet into the Nethack server and login
# The Nethack server doesn't have a traditional telnet login. It used
a "=3D> " prompt where you enter
# a letter from a menu displayed
#
host =3D Net::Telnet::new("Host" =3D> "nethack.alt.org",
=09=09=09=09 "Port" =3D> 23,
=09=09=09=09 "Timeout" =3D> 10) { |str| print str }
host.telnetmode=3Dtrue
host.waitfor('=3D>') { |str| print str }
host.puts("l") { |str| print str }
</code>
Here is the output:
<output>
E:\Ruby\mkNethackbot>ruby mkNethackbot.rb
Trying nethack.alt.org...
Connected to nethack.alt.org.
Debian GNU/Linux 3.0 zaphod.alt.org
Error opening terminal: network.
c:/ruby/lib/ruby/1.8/net/telnet.rb:551:in `waitfor': timed out while waitin=
g for
more data (Timeout::Error)
from mkNethackbot.rb:20
</output>
I found the code "{ |str| print str }" on another site using Ruby's
net/telnet, but I don't yet know exactly what it means, but I think it
waits for any strings sent ( |str |) and then displays it ( print str
).
Thanks,
Will
started. I looked at a lot of resources today and thought I would
just get started.
The first thing I have to do is get connected and logged in. However
nethack.alt.org doesn't use a traditional telnet login prompt. it
uses a menu displayed with a =3D> prompt waiting for user input. So
here is what I have so far. it does connect but I can't get logged
in
<code>
require 'net/telnet'
# Telnet into the Nethack server and login
# The Nethack server doesn't have a traditional telnet login. It used
a "=3D> " prompt where you enter
# a letter from a menu displayed
#
host =3D Net::Telnet::new("Host" =3D> "nethack.alt.org",
=09=09=09=09 "Port" =3D> 23,
=09=09=09=09 "Timeout" =3D> 10) { |str| print str }
host.telnetmode=3Dtrue
host.waitfor('=3D>') { |str| print str }
host.puts("l") { |str| print str }
</code>
Here is the output:
<output>
E:\Ruby\mkNethackbot>ruby mkNethackbot.rb
Trying nethack.alt.org...
Connected to nethack.alt.org.
Debian GNU/Linux 3.0 zaphod.alt.org
Error opening terminal: network.
c:/ruby/lib/ruby/1.8/net/telnet.rb:551:in `waitfor': timed out while waitin=
g for
more data (Timeout::Error)
from mkNethackbot.rb:20
</output>
I found the code "{ |str| print str }" on another site using Ruby's
net/telnet, but I don't yet know exactly what it means, but I think it
waits for any strings sent ( |str |) and then displays it ( print str
).
Thanks,
Will