import java.net.*;
import java.io.*;
import java.lang.*; //for Runtime
public class ChatPt {
private static final int WAITING = 0;
private static final int SENTWELCOME = 1;
private static final int SENTLIST = 2;
private static final int BYE = 3;
private static final int LS = 4;
// private static final int NUMJOKES = 5;
private int state = WAITING;
private String[] files = { "Nothing"};
private String tempcommand;
Runtime tempRuntime;
Process tempProcess;
public String processInput(String theInput)
{
String theOutput = null;
if (state == WAITING)
{
theOutput = "Welcome to ChatServe .001";
state = SENTWELCOME;
}
else if (state == SENTWELCOME)
{
if(theInput.equalsIgnoreCase("LS"))
{
tempRuntime.getRuntime();
tempcommand = "dir";
try {
tempProcess = tempRuntime.exec("ls");
} catch (IOException e)
{
System.err.println("something's fucked up");
System.exit(1);
}
theOutput = tempProcess.getOutputStream();
// theOutput = files[0];
state = SENTLIST;
}
else
{
theOutput = "I can only list my files, type 'LS'";
}
}
else if (state == SENTLIST)
{
theOutput = "I already sent you the file list! now leave!";
state = BYE;
}
else
{
theOutput = "Bye.";
state = WAITING;
}
return theOutput;
}
}