KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > client > server > PerformOnConnect


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 JavaDoc;
15 import java.util.Iterator JavaDoc;
16
17 /**
18  * temporary listener to halt /list replies that don't match our criteria *
19  */

20 public class PerformOnConnect extends Feature implements ChatListener
21 {
22     UserHandler user;
23     String JavaDoc network; // just in case...
24
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 JavaDoc eventDescription)
33     {
34         String JavaDoc event = (String JavaDoc) eventDescription.get("$event");
35
36         // perform on connect code, should be in its own class...
37
if (event.equals("001")) {
38             String JavaDoc[] 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; // flag this as a new connection...
49
} else if ((event.equals("376") || event.equals("422")) && newConnect) // 422 = no motd, 376 = end of /motd
50
{
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                     // this is a hack to help users migrate their jIRCii perform settings...
65

66                     actions = ClientState.getClientState().getStringList("perform." + network);
67                 } else {
68                     actions =
69                         ClientState.getClientState().getStringList("perform." + NetworkSelect.ALL_NETWORKS.toLowerCase());
70                 }
71
72                 Iterator JavaDoc ii = actions.getList().iterator();
73                 while (ii.hasNext()) {
74                     String JavaDoc temp = ii.next().toString();
75                     processInput(temp);
76                 }
77             }
78
79             //
80
// lets not interrupt the processing for "this" server...
81
//
82
if (rero.test.QuickConnect.IsQuickConnect()) {
83                 user.processInput(rero.test.QuickConnect.GetInformation().getCommand());
84             }
85
86             newConnect = false; // our new connection status just expired...
87
}
88         return EVENT_DONE;
89     }
90
91     public void processInput(String JavaDoc input)
92     {
93         // @Serge: ignore text, only process commands that start with slash
94
// Fix for: http://jirc.hick.org/cgi-bin/bitch.cgi/view.html?4487090
95
if (input.charAt(0) != '/') return;
96         String JavaDoc 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 JavaDoc event, HashMap JavaDoc eventDescription)
107     {
108         return (event.equals("376") || event.equals("001") || event.equals("422")); /* end of /MOTD reply */
109     }
110 }
111
Popular Tags