import java.net.*;
import java.io.*;
import java.lang.*; //for Runtime
import java.util.*; //for BufferedReader
public class ChatPt2 {
private static final int WAITING = 0;
private static final int ENTERNAME = 1;
private static final int CHATTING = 2;
private static final int BYE = 3;
private static final int WHOIS = 4;
private int state = WAITING;
private String[] files = { "Nothing"};
private String temp;
public String processInput(String theInput) throws IOException
{
String theOutput = null;
if (state == WAITING)
{
theOutput = "Welcome to ChatServe .002, Type in your Chat Name:";
state = ENTERNAME;
}
else if(state == WHOIS)
{
theOutput = "not implemented yet";
state = CHATTING;
/* int eof;
File userlistFile = new File("userlist.txt");
FileReader userlistin = new FileReader(userlistFile);
while ((eof = userlistin.read()) != -1)
out.write(c);
*/
}
else if (state == ENTERNAME)
{
//Check Name against userlist
File userlistFile = null;
FileWriter outFile = null;
/* try{
userlistFile = new File("userlist.txt");
} catch (IOException e) {
System.err.println("error opening userlist");
System.exit(1);
}
try {
outFile = new FileWriter("userlist.txt");
} catch (FileNotFoundException e) {
System.err.println("Could not open user file.");
System.exit(1);
}
*/
// FileWriter userlistOut = new FileWriter(userlistFile);
// userlistOut.write(theInput);
state = CHATTING;
}
else if (state == CHATTING)
{
if(theInput.equalsIgnoreCase("LOGOFF"))
{
state = BYE;
}
else if(theInput.equalsIgnoreCase("WHOIS"))
{
state = WHOIS;
}
else
{
theOutput = "testing";
}
}
else
{
theOutput = "Bye.";
state = WAITING;
}
return theOutput;
}//processInput method close brace
}//ChatPt2 Class close brace