7 import java.security.*;
\r
8 import javax.crypto.*;
\r
9 import javax.crypto.spec.*;
\r
11 import org.bouncycastle.openssl.*;
\r
12 import org.bouncycastle.util.encoders.*;
\r
17 public class TCP implements Runnable{
\r
18 private ServerSocket $ss = null;
\r
19 protected List<TCPW> $conn = null;
\r
20 protected PrivateKey $prk = null;
\r
23 public TCP(int $port)throws Exception{
\r
24 System.out.println(Main.$cfg.getString("key")+"SERVER TCP: "+$port);
\r
25 PEMReader in = new PEMReader(new FileReader(Main.$cfg.getString("key")), new PasswordFinder() {
\r
27 public char[] getPassword(){
\r
28 try{System.out.println("Enter pass phrase:"); return (new BufferedReader(new InputStreamReader(System.in)).readLine()).toCharArray();}catch(Exception $e){$e.printStackTrace();}return null;
\r
30 $prk = ((KeyPair) in.readObject()).getPrivate();
\r
31 $conn = Collections.synchronizedList(new ArrayList());
\r
32 $ss = new ServerSocket($port);
\r
33 new Thread(this).start();
\r
39 new TCPW($ss.accept(),this);
\r
41 }catch(Exception $e){$e.printStackTrace();}
\r
44 public void sendAll(String $msg){
\r
45 for(int $i = 0; $i < $conn.size(); $i++){
\r
46 if($conn.get($i).isLoggedIn())$conn.get($i).send($msg);
\r
50 public TCPW getConnByName(String $name){
\r
51 for(int $i = 0; $i < $conn.size() ; $i++){
\r
52 TCPW $tmp = $conn.get($i);
\r
53 if($name.equalsIgnoreCase($tmp.getName()))return $tmp;
\r
58 public void delConn(TCPW $delme){
\r
59 for(int $i = 0; $i < $conn.size() ; $i++){
\r
60 if($conn.get($i) == $delme){$conn.remove($i);return;}
\r
64 public void shutdown(){
\r
67 }catch(Exception $e){$e.printStackTrace();}
\r
68 for(int $i = 0; $i < $conn.size() ; $i++){
\r
69 $conn.get($i).shutdown();
\r