import java.net.* ; import java.io.* ; import java.util.* ; class ConnectionWaiter extends ServerSocket { ConnectionWaiter(int socket)throws Exception{ super(socket) ; } Socket connected()throws Exception{ return super.accept() ; } void closeConnection()throws Exception {super.close ();} } class Connection extends Thread { Socket s; Vector v; BufferedReader in; PrintWriter out; String nimi ; User loser; Connection(Socket s ,Vector v ){ this.s=s ;this.v=v ; initIOStreams(); start(); } void initIOStreams(){ try{ in=new BufferedReader (new InputStreamReader (s.getInputStream ())); out=new PrintWriter (s.getOutputStream (),true) ; }catch(Exception e){} } public void run(){ this.begin(); this.justTalk(); try{ s.close (); }catch(Exception e){ } } void begin(){ try{ out.println (""); Date d=new Date (); out.println (""); out.println (d.toString ().substring (0,20)); out.println ("Sisesta kasutajanimi :"); while(true){ nimi=in.readLine ().toLowerCase (); if ((nimi.equals ("")))out.println ("Vigane kasutajanimi :") ; else if (this.isUserName (nimi)) out.println ("See nimi on juba kasutusel"); else break ; } loser=new User (nimi,s); v.addElement (loser); out.println ("Tere "+nimi+" !"); out.println (""); }catch(Exception e){out.println ("ei saa lugeda !") ;} } void justTalk(){ String fromK; //loeb kuni kasutaja ei ole tillinud . read: while(true){ try{ fromK=in.readLine (); if(fromK.toLowerCase ().equals (".quit")) { break read ;} if(fromK.toLowerCase ().equals (".list")){this.getList() ; continue ; } if(fromK.toLowerCase ().equals (".privateto")) { myPrivateLine() ; continue ;} // kill Enum ; /* for(Enumeration e=v.elements ();e.hasMoreElements (); ) { if ((User)(e.nextElement ())==loser) { continue ; } else{ Socket now=((User)(e.nextElement ())).getSocket () ; PrintWriter print_out=new PrintWriter (now.getOutputStream (),true); print_out.println (nimi+" :>"+fromK); }//if lopp <<>> }// for lõpp <<>> */ int j; for(j=0;j"+fromK); }//if lopp <<>> }// for lõpp <<>> // otsepöörduse lopp }catch(Exception e){} }////while lopp <<>> v.removeElement (loser); } void myPrivateLine() throws Exception { out.println ("Kellega koneleks ?"); String partner; partner =in.readLine ().toLowerCase (); if(!this.isUserName(partner)){out.println ("Pole sellist kasutajat !");} else { try{ User myLine=this.getUser (partner); PrintWriter print_out=new PrintWriter (myLine.getSocket().getOutputStream (),true ) ; while(true){ String transs=in.readLine (); if(transs.toLowerCase ().equals (".killpr")){ break ;} print_out.println ("PRIVATE "+nimi+" :>"+transs);} }catch(Exception e){} } } User getUser(String name){ int i ; User user=null; User out; for (i=0;i