1 package rero.client; 2 3 import rero.net.*; 4 import rero.ircfw.*; 5 import rero.ircfw.interfaces.*; 6 import rero.script.*; 7 import rero.util.*; 8 import rero.dcc.*; 9 10 import java.util.*; 11 import java.io.*; 12 13 import sleep.runtime.*; 14 15 import rero.client.user.*; import rero.client.server.*; 17 import rero.client.notify.*; 18 import rero.client.dcc.*; 19 import rero.client.listeners.*; import rero.client.output.*; 21 import rero.client.data.*; 22 import rero.client.script.*; 23 24 import rero.client.functions.*; 26 import rero.gui.*; 27 28 29 public class Capabilities 30 { 31 protected SocketConnection socket; 32 protected ChatFramework ircfw; 33 protected ScriptCore script; 34 protected OutputCapabilities output; 35 protected ChatCapabilities actions; 36 37 protected rero.gui.UICapabilities gui; 38 39 protected static TimerUtil timer; 41 protected WeakHashMap data; 42 protected LinkedList featureList; 43 44 public Capabilities(ChatFramework _ircfw, SocketConnection _socket, ScriptCore _script, UICapabilities _gui, WeakHashMap _data) 45 { 46 ircfw = _ircfw; 50 socket = _socket; 51 script = _script; 52 gui = _gui; 53 54 data = _data; 55 56 if (timer == null) 57 { 58 timer = new TimerUtil(); 59 timer.start(); 60 } 61 62 featureList = new LinkedList(); 66 67 output = new OutputCapabilities(); 68 setupFeature(output, featureList); 69 70 actions = new ChatCapabilities(); 71 setupFeature(actions, featureList); 72 73 UserHandler userInput = new UserHandler(); setupFeature(userInput, featureList); 75 76 ServerHandler serverOutput = new ServerHandler(); setupFeature(serverOutput, featureList); 78 79 FeatureDCC dcc = new FeatureDCC(); setupFeature(dcc, featureList); 81 82 ProcessEvents processEvents = new ProcessEvents(); setupFeature(processEvents, featureList); 84 85 NotifyData notify = new NotifyData(); setupFeature(notify, featureList); 87 88 InternalEvents internalEvents = new InternalEvents(); setupFeature(internalEvents, featureList); 90 91 LocalInfo localInfo = new LocalInfo(); setupFeature(localInfo, featureList); 93 94 ScriptManager scriptManager = new ScriptManager(); setupFeature(scriptManager, featureList); 96 97 PerformOnConnect performConnect = new PerformOnConnect(); setupFeature(performConnect, featureList); 99 100 DataStructureBridge dataStructs = new DataStructureBridge(); setupFeature(dataStructs, featureList); 105 106 ChannelOperators chanops = new ChannelOperators(); setupFeature(chanops, featureList); 108 script.addBridge(chanops); 109 110 UserOperators userops = new UserOperators(); setupFeature(userops, featureList); 112 script.addBridge(userops); 113 114 BuiltInOperators builtinops = new BuiltInOperators(); setupFeature(builtinops, featureList); 116 script.addBridge(builtinops); 117 118 NotifyOperators notifyops = new NotifyOperators(); setupFeature(notifyops, featureList); 120 script.addBridge(notifyops); 121 122 TimerOperators timerops = new TimerOperators(); setupFeature(timerops, featureList); 124 125 ConfigOperators configops = new ConfigOperators(); setupFeature(configops, featureList); 127 128 DCCOperators dccops = new DCCOperators(); setupFeature(dccops, featureList); 130 131 UtilOperators utilops = new UtilOperators(); setupFeature(utilops, featureList); 133 134 TokenOperators tokenops = new TokenOperators(); setupFeature(tokenops, featureList); 136 137 ServerOperators serverops = new ServerOperators(); setupFeature(serverops, featureList); 139 140 SoundOperators soundops = new SoundOperators(); setupFeature(soundops, featureList); 142 143 finalizeFeatures(featureList); 144 145 } 149 150 public TimerUtil getTimer() 151 { 152 return timer; 153 } 154 155 public void cleanup() 156 { 157 ListIterator i = featureList.listIterator(); 158 while (i.hasNext()) 159 { 160 Feature temp = (Feature)i.next(); 161 temp.cleanup(); 162 } 163 164 data.clear(); 165 featureList.clear(); 166 } 167 168 public boolean isConnected() 169 { 170 return socket.getSocketInformation().isConnected; } 172 173 public ChatCapabilities getChatCapabilities() 174 { 175 return actions; 176 } 177 178 public OutputCapabilities getOutputCapabilities() 179 { 180 return output; 181 } 182 183 public rero.gui.UICapabilities getUserInterface() 184 { 185 return gui; 186 } 187 188 public ScriptCore getScriptCore() 189 { 190 return script; 191 } 192 193 public SocketConnection getSocketConnection() 194 { 195 return socket; 196 } 197 198 public void sendln(String text) 199 { 200 socket.println(text); 201 } 202 203 public Object getDataStructure(String key) 204 { 205 return data.get(key); 206 } 207 208 public void injectEvent(String text) 209 { 210 ircfw.injectEvent(text); 211 } 212 213 public void dispatchEvent(HashMap data) 214 { 215 ircfw.getProtocolDispatcher().dispatchEvent(data); 216 } 217 218 public void addChatListener(ChatListener l) 219 { 220 ircfw.addChatListener(l); 221 } 222 223 public void addTemporaryListener(ChatListener l) 224 { 225 ircfw.addTemporaryListener(l); 226 } 227 228 public ChatFramework getChatFramework() 229 { 230 return ircfw; 231 } 232 233 public void registerCommand(String command, ClientCommand code) 234 { 235 UserHandler commands = (UserHandler)getDataStructure("commands"); 236 commands.registerCommand(command, code); 237 } 238 239 public void setupFeature(Feature aFeature, LinkedList features) 240 { 241 aFeature.storeDataStructures(data); 242 aFeature.installCapabilities(this); 243 244 features.add(aFeature); 245 } 246 247 public void finalizeFeatures(LinkedList features) 248 { 249 ListIterator i = features.listIterator(); 250 while (i.hasNext()) 251 { 252 Feature temp = (Feature)i.next(); 253 temp.init(); 254 } 255 } 256 257 public GlobalCapabilities getGlobalCapabilities() 258 { 259 return SessionManager.getGlobalCapabilities(); 260 } 261 } 262 | Popular Tags |