1 package rero.dcc; 2 3 import rero.ircfw.*; 4 import rero.ircfw.interfaces.*; 5 6 import java.io.*; 7 import java.net.*; 8 import java.util.*; 9 10 public abstract class ProtocolDCC 11 { 12 public static final int DCC_SEND = 001; 13 public static final int DCC_RECEIVE = 002; 14 public static final int DCC_CHAT = 003; 15 16 public static final int STATE_WAIT = 401; 17 public static final int STATE_OPEN = 402; public static final int STATE_CLOSED = 403; 19 20 public static final int DCC_TIMEOUT = 60 * 1000 * 2; 22 protected String nickname; 23 protected Socket socket; 24 25 protected long idleTime; 26 protected long startTime; 27 28 protected HashMap eventData = new HashMap(); 29 protected ProtocolDispatcher dispatcher; 30 31 protected int state = STATE_WAIT; 33 34 public abstract int getTypeOfDCC(); 35 36 public void close() 37 { 38 try 39 { 40 socket.close(); 41 state = STATE_CLOSED; 42 } 43 catch (Exception ex) 44 { 45 ex.printStackTrace(); 46 } 47 } 48 49 public int getState() 50 { 51 if (state == STATE_OPEN && !isConnected()) 52 { 53 state = STATE_CLOSED; 54 } 55 return state; 56 } 57 58 public String getRemoteAddress() 59 { 60 return socket.getInetAddress().getHostAddress(); 61 } 62 63 public int getLocalPort() 64 { 65 return socket.getLocalPort(); 66 } 67 68 public int getPort() 69 { 70 return socket.getPort(); 71 } 72 73 74 public void announceFramework(ChatFramework f) 75 { 76 dispatcher = f.getProtocolDispatcher(); 77 } 78 79 public abstract void run(); 80 81 82 public boolean isConnected() 83 { 84 return socket != null && socket.isConnected(); 85 } 86 87 88 public String getNickname() 89 { 90 return nickname; 91 } 92 93 94 public long getIdleTime() 95 { 96 return (System.currentTimeMillis() - idleTime); 97 } 98 99 100 public long getStartTime() 101 { 102 return startTime; 103 } 104 105 106 public long getTotalTime() 107 { 108 return System.currentTimeMillis() - startTime; 109 } 110 111 public void setDCCSocket(Socket _socket) 112 { 113 socket = _socket; 114 115 startTime = System.currentTimeMillis(); 116 idleTime = System.currentTimeMillis(); 117 118 state = STATE_OPEN; 119 } 120 121 public abstract void fireError(String text); 122 123 } 124 | Popular Tags |