import java.net.*;
import java.io.*;
import java.lang.;
public class Horchen extends Thread {
Socket client = null;
PrintWriter out;
BufferedReader input;
Server parent;
String nickname = "Nick";
boolean active = true;
public Horchen(Socket socket, Server argParent) {
client = socket;
parent = argParent;
}
public void run() {
try {
input = new BufferedReader(
new InputStreamReader(
client.getInputStream()
));
out = new PrintWriter(client.getOutputStream(), true);
gruessGott();
while (active)
{
String s = input.readLine();
if(s == null) {aufWiedersehen();} else {
if(s.startsWith("/", 0)) {
parseCmd(s);
} else {
read(s);
}
}
}
} catch (Exception e) {}
}
public void gruessGott() {
try {
nickname = input.readLine();
parent.printAll(nickname + " has joined" );
} catch (Exception e) {}
}
public void aufWiedersehen() {
active=false;
parent.printAll(nickname + " has expectedly quit" );
}
public void read(String s) {
s = nickname + ": " + s ;
parent.log.add(s);
parent.printAll(s);
}
public void parseCmd(String s) {
if(s.equals("/exit")) { aufWiedersehen(); };
if(s.equals("/log")) { parent.printLog(this); };
if(s.equals("/clear")) { parent.clearLog(); };
}
public void print(String s) {
out.print(s + "\r\n" );
out.flush();
}
}
//authors so far:
|
|