| 1 package rero.client.server; 2 3 import rero.client.DataStructures; 4 import rero.client.Feature; 5 import rero.client.script.ScriptManager; 6 import rero.client.user.UserHandler; 7 import rero.config.ClientState; 8 import rero.config.StringList; 9 import rero.dck.items.NetworkSelect; 10 import rero.dialogs.server.Server; 11 import rero.dialogs.server.ServerData; 12 import rero.ircfw.interfaces.ChatListener; 13 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 17 20 public class PerformOnConnect extends Feature implements ChatListener 21 { 22 UserHandler user; 23 String network; boolean newConnect = false; 25 26 public void init() 27 { 28 user = (UserHandler) getCapabilities().getDataStructure(DataStructures.UserHandler); 29 getCapabilities().addChatListener(this); 30 } 31 32 public int fireChatEvent(HashMap eventDescription) 33 { 34 String event = (String ) eventDescription.get("$event"); 35 36 if (event.equals("001")) { 38 String [] temp = eventDescription.get("$parms").toString().split(" "); 39 40 if (temp.length >= 4) { 41 getCapabilities().getSocketConnection().getSocketInformation().network = temp[3]; 42 network = temp[3]; 43 } else { 44 getCapabilities().getSocketConnection().getSocketInformation().network = ""; 45 network = ""; 46 } 47 48 newConnect = true; } else if ((event.equals("376") || event.equals("422")) && newConnect) { 51 if (ClientState.getClientState().isOption("perform.enabled", false)) { 52 Server myserver = 53 ServerData.getServerData().getServerByName(getCapabilities().getSocketConnection().getSocketInformation().hostname); 54 StringList actions; 55 56 if (myserver != null && !myserver.isRandom()) { 57 getCapabilities().getSocketConnection().getSocketInformation().network = myserver.getNetwork(); 58 network = myserver.getNetwork(); 59 } 60 61 if (ClientState.getClientState().getString("perform." + network.toLowerCase(), null) != null) { 62 actions = ClientState.getClientState().getStringList("perform." + network.toLowerCase()); 63 } else if (ClientState.getClientState().getString("perform." + network, null) != null) { 64 66 actions = ClientState.getClientState().getStringList("perform." + network); 67 } else { 68 actions = 69 ClientState.getClientState().getStringList("perform." + NetworkSelect.ALL_NETWORKS.toLowerCase()); 70 } 71 72 Iterator ii = actions.getList().iterator(); 73 while (ii.hasNext()) { 74 String temp = ii.next().toString(); 75 processInput(temp); 76 } 77 } 78 79 if (rero.test.QuickConnect.IsQuickConnect()) { 83 user.processInput(rero.test.QuickConnect.GetInformation().getCommand()); 84 } 85 86 newConnect = false; } 88 return EVENT_DONE; 89 } 90 91 public void processInput(String input) 92 { 93 if (input.charAt(0) != '/') return; 96 String command; 97 if (input.indexOf('$') > -1) { 98 command = 99 ((ScriptManager) getCapabilities().getDataStructure(DataStructures.ScriptManager)).evalString("\"" + input + "\""); 100 } else { 101 command = input; 102 } 103 user.processInput(command); 104 } 105 106 public boolean isChatEvent(String event, HashMap eventDescription) 107 { 108 return (event.equals("376") || event.equals("001") || event.equals("422")); 109 } 110 } 111 | Popular Tags |