01 Sep, 2013, THUFIR wrote in the 1st comment:
Votes: 0
I'm beginning work on a MUD client using Apache TelnetClient. I seem to have, I think, gotten the threading and InputStream problems fixed. Right now I just want to script a response to the weather server at rainmaker.wunderground.com 3000 by sending a, I think, LF ("\n" in Java?) as a an "enter" key.

I don't think my logic and character parsing is quite correct, but by rook or crook I managed to send a LF, char value 10, as a command to the weather server and got back the response. However, it seems to run way too quickly:

output:

thufir@dur:~$ 
thufir@dur:~$
thufir@dur:~$ java -jar NetBeansProjects/Telnet/dist/Telnet.jar
print..
——————————————————————————
* Welcome to THE WEATHER UNDERGROUND telnet service! *
——————————————————————————
* *
* National Weather Service information provided by Alden Electronics, Inc. *
* and updated each minute as reports come in over our data feed. *
* *
* **Note: If you cannot get past this opening screen, you must use a *
* different version of the "telnet" program–some of the ones for IBM *
* compatible PC's have a bug that prevents proper connection. *
* *
* comments: jmasters@wunderground.com *
——————————————————————————

Press Return to continue:updated…



sent command: 10
sent command: 10

Press Return for menu
or enter 3 letter forecast city code–
WEATHER UNDERGROUND MAIN MENU
******************************
1) U.S. forecasts and climate data
2) Canadian forecasts
3) Current weather observations
4) Ski conditions
5) Long-range forecasts
6) Latest earthquake reports
7) Severe weather
8) Hurricane advisories
9) Weather summary for the past month
10) International data
11) Marine forecasts and observations
12) Ultraviolet light forecast
X) Exit program
C) Change scrolling to screen
H) Help and information for new users
?) Answers to all your questions
Selection:updated…



sent command: 10
sent command: 10

Not a valid option. Type a number 1 to 12.

WEATHER UNDERGROUND MAIN MENU
******************************
1) U.S. forecasts and climate data



some Controller code:

public final class Controller implements Observer {

private TelnetClient telnetClient = new TelnetClient();
private Printer telnetPrinter = new Printer();
private DataProcessor telnetDataProcessor = new DataProcessor();
private CommandGenerator commandGenerator = new CommandGenerator();
private final ConcurrentLinkedQueue<Character> telnetData = new ConcurrentLinkedQueue();

public void readPrintParse(final InputStream inputStream) throws SocketException, IOException {
telnetPrinter.print(inputStream, telnetData);
telnetPrinter.addObserver(this);
telnetDataProcessor.read(telnetData);
telnetDataProcessor.addObserver(this);
commandGenerator.addObserver(this);
}

private void sendCommand(String string) throws IOException {
String stringCommand = string + "\n";
System.out.println(stringCommand);
byte[] bytes = stringCommand.getBytes();
byte command = 13;
for (int i = 0; i < bytes.length; i++) {
command = bytes[i];
telnetClient.sendCommand(command);
System.out.println("sent command: " + command);
}
}

@Override
public void update(Observable o, Object arg) {
System.out.println("updated…");
String s = telnetDataProcessor.getString();
String command = commandGenerator.parse(s);
try {
sendCommand(command);
} catch (IOException ex) {
}
}

public Controller() throws SocketException, IOException {
Properties props = PropertiesReader.getProps();
InetAddress host = InetAddress.getByName(props.getProperty("host"));
int port = Integer.parseInt(props.getProperty("port"));
telnetClient.connect(host, port);
readPrintParse(telnetClient.getInputStream());
}

public static void main(String[] args) throws SocketException, IOException {
new Controller();
}
}


What's a good approach to slowing down the commands until *after* it's time to send a command, and not before?


thanks,


Thufir
01 Sep, 2013, plamzi wrote in the 2nd comment:
Votes: 0
You need to wait until you see a certain string, then send a certain response. Anything else, like inserting arbitrary delays, is gimmicky and will not work 100% of the time.

Basically, you'll be writing code that supports a simple trigger, which should be useful in a MUD client.

By the way, is there any reason why you're not pointing your code to an actual MUD?
01 Sep, 2013, quixadhal wrote in the 3rd comment:
Votes: 0
I don't know how easy or ugly it is in Java, but you might as well look up regular expressions now, rather than later. You'll want to support them, as triggers on fixed strings are only marginally useful for most games.
02 Sep, 2013, THUFIR wrote in the 4th comment:
Votes: 0
quixadhal said:
I don't know how easy or ugly it is in Java, but you might as well look up regular expressions now, rather than later. You'll want to support them, as triggers on fixed strings are only marginally useful for most games.


I'm doing regex now. It's, so far, just for me, and it's only a few files so it's all hardcoded. They shouldn't be, but it's just easier for now. Once I get a few functional triggers, I'm doing the Oracle trail tutorial on regex, I might fix that. They would have to be stored in in some sort file. More convenient to just rebuild, takes 2 seconds or something, for now.
0.0/4