Quellcode durchsuchen

Refactored parser.

Now has separate classes for different types of incomming message


git-svn-id: http://svn.dmdirc.com/trunk@480 00569f92-eb28-0410-84fd-f71c24880f
tags/0.3
Shane Mc Cormack vor 17 Jahren
Ursprung
Commit
595d674600

+ 151
- 1435
src/uk/org/ownage/dmdirc/parser/IRCParser.java
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen


+ 179
- 0
src/uk/org/ownage/dmdirc/parser/IRCProcessor.java Datei anzeigen

@@ -0,0 +1,179 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: IRCProcessor.java 273 2007-03-03 02:09:17Z greboid $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackManager;
28
+
29
+import java.util.Hashtable;
30
+import java.util.ArrayList;
31
+
32
+/**
33
+ * IRCProcessor.
34
+ * Superclass for all IRCProcessor types.
35
+ *
36
+ * @author            Shane Mc Cormack
37
+ * @version           $Id: IRCProcessor.java 273 2007-03-03 02:09:17Z greboid $
38
+ */
39
+public abstract class IRCProcessor {
40
+	/** Reference to the IRCParser that owns this IRCProcessor. */
41
+	protected IRCParser myParser = null;
42
+	
43
+	/** Reference to the Processing in charge of this IRCProcessor. */
44
+	protected ProcessingManager myManager = null;
45
+
46
+	// Some functions from the main parser are useful, and having to use myParser.functionName
47
+	// is annoying, so we also implement them here (calling them again using myParser)
48
+
49
+	/**
50
+	 * Callback to all objects implementing the IErrorInfo Interface.
51
+	 *
52
+	 * @see IErrorInfo
53
+	 * @param errorInfo ParserError object representing the error.
54
+	 */
55
+	protected final boolean callErrorInfo(ParserError errorInfo) {
56
+		return myParser.callErrorInfo(errorInfo);
57
+	}
58
+	
59
+	/**
60
+	 * Callback to all objects implementing the DebugInfo Callback.
61
+	 *
62
+	 * @see IDebugInfo
63
+	 * @param level Debugging Level (ndInfo, ndSocket etc)
64
+	 * @param data Debugging Information
65
+	 * @param args Formatting String Options
66
+	 */
67
+	protected boolean callDebugInfo(int level, String data, Object... args) {
68
+		return myParser.callDebugInfo(level, String.format(data, args));
69
+	}
70
+	
71
+	/**
72
+	 * Callback to all objects implementing the DebugInfo Callback.
73
+	 *
74
+	 * @see IDebugInfo
75
+	 * @param level Debugging Level (ndInfo, ndSocket etc)
76
+	 * @param data Debugging Information
77
+	 */
78
+	protected boolean callDebugInfo(int level, String data) {
79
+		return myParser.callDebugInfo(level, data);
80
+	}
81
+	
82
+	/**
83
+	 * Check if a channel name is valid .
84
+	 *
85
+	 * @param sChannelName Channel name to test
86
+	 */
87
+	protected boolean isValidChannelName(String sChannelName) {
88
+		return myParser.isValidChannelName(sChannelName);
89
+	}
90
+	
91
+	/**
92
+	 * Get the ClientInfo object for a person.
93
+	 *
94
+	 * @param sWho Who can be any valid identifier for a client as long as it contains a nickname (?:)nick(?!ident)(?@host)
95
+	 * @return ClientInfo Object for the client, or null
96
+	 */
97
+	protected ClientInfo getClientInfo(String sWho) {
98
+		return myParser.getClientInfo(sWho);
99
+	}
100
+	
101
+	/**
102
+	 * Get the ChannelInfo object for a channel.
103
+	 *
104
+	 * @param sWhat This is the name of the channel.
105
+	 * @return ChannelInfo Object for the channel, or null
106
+	 */
107
+	protected ChannelInfo getChannelInfo(String sWhat) {
108
+		return myParser.getChannelInfo(sWhat);
109
+	}
110
+	
111
+	/**
112
+	 * Get a reference to the CallbackManager
113
+	 *
114
+	 * @return Reference to the CallbackManager
115
+	 */
116
+	protected CallbackManager getCallbackManager() {
117
+		return myParser.getCallbackManager();
118
+	}
119
+	
120
+	/** 
121
+	 * Send a line to the server and add proper line ending.
122
+	 *
123
+	 * @param line Line to send (\r\n termination is added automatically)
124
+	 */
125
+	protected void sendString(String line) {
126
+		myParser.sendString(line);
127
+	}
128
+	
129
+	/**
130
+	 * Create a new instance of the IRCProcessor Object
131
+	 *
132
+	 * @param parser IRCParser That owns this IRCProcessor
133
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
134
+	 */
135
+	protected IRCProcessor (IRCParser parser, ProcessingManager manager) {
136
+		this.myParser = parser;
137
+		this.myManager = manager;
138
+	}
139
+	
140
+	/**
141
+	 * Process a Line.
142
+	 *
143
+	 * @param sParam Type of line to process ("005", "PRIVMSG" etc)
144
+	 * @param token IRCTokenised line to process
145
+	 */
146
+	public abstract void process(String sParam, String[] token);
147
+	
148
+	/**
149
+	 * What does this IRCProcessor handle.
150
+	 *
151
+	 * @return String[] with the names of the tokens we handle.
152
+	 */
153
+	public abstract String[] handles();
154
+	
155
+	/** Get the name for this Processor */
156
+	public String getName() {
157
+		Package thisPackage = this.getClass().getPackage();
158
+		int packageLength = 0;
159
+		if (thisPackage != null) {
160
+			packageLength = thisPackage.getName().length()+1;
161
+		}
162
+		return this.getClass().getName().substring(packageLength);
163
+	}
164
+	
165
+	/** Get the name for this Processor in lowercase */
166
+	public final String getLowerName() {
167
+		return this.getName().toLowerCase();
168
+	}
169
+	
170
+	/** Get the name for this Processor */
171
+	public final String toString() { return this.getName(); }
172
+	
173
+	/**
174
+	 * Get SVN Version information
175
+	 *
176
+	 * @return SVN Version String
177
+	 */
178
+	public static String getSvnInfo () { return "$Id: IRCParser.java 478 2007-03-08 05:52:14Z ShaneMcC $"; }	
179
+}

+ 1
- 1
src/uk/org/ownage/dmdirc/parser/ParserError.java Datei anzeigen

@@ -39,7 +39,7 @@ public class ParserError {
39 39
 	public static final int errWarning = 4;
40 40
 	/** Error was an exception from elsewhere. */
41 41
 	public static final int errException = 8;
42
-
42
+	
43 43
 	/** Store the Error level */
44 44
 	protected int errorLevel = 0;
45 45
 	/** Store the Error Information */

+ 91
- 0
src/uk/org/ownage/dmdirc/parser/Process001.java Datei anzeigen

@@ -0,0 +1,91 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnServerReady;
28
+
29
+/**
30
+ * Process a 001 message.
31
+ */
32
+public class Process001 extends IRCProcessor {
33
+	/**
34
+	 * Process a 001 message.
35
+	 *
36
+	 * @param type Type of line to process ("001")
37
+	 * @param tokens IRCTokenised line to process
38
+	 */
39
+	public void process(String sParam, String[] token) {
40
+		myParser.Got001 = true;
41
+		// << :demon1.uk.quakenet.org 001 Java-Test :Welcome to the QuakeNet IRC Network, Java-Test
42
+		String sNick;
43
+		myParser.sServerName = token[0].substring(1,token[0].length());
44
+		sNick = token[2];
45
+		
46
+		/* Code below is here incase relying on token[2] breaks somewhere
47
+		String[] temp = token[token.length-1].split(" ");
48
+		sConfirmedNickname = temp[temp.length-1];
49
+		// Some servers give a full host in 001
50
+		temp = sNick.split("!",2);
51
+		sNick = temp[0];  /* */
52
+		
53
+		myParser.cMyself = getClientInfo(sNick);
54
+		if (myParser.cMyself == null) {
55
+			myParser.cMyself = new ClientInfo(myParser, sNick);
56
+			myParser.hClientList.put(myParser.cMyself.getNickname().toLowerCase(),myParser.cMyself);
57
+		}
58
+		
59
+		callServerReady();
60
+	}
61
+	
62
+	/**
63
+	 * Callback to all objects implementing the ServerReady Callback.
64
+	 *
65
+	 * @see IServerReady
66
+	 */	
67
+	protected boolean callServerReady() {
68
+		CallbackOnServerReady cb = (CallbackOnServerReady)getCallbackManager().getCallbackType("OnServerReady");
69
+		if (cb != null) { return cb.call(); }
70
+		return false;
71
+	}
72
+	
73
+	/**
74
+	 * What does this IRCProcessor handle.
75
+	 *
76
+	 * @return String[] with the names of the tokens we handle.
77
+	 */
78
+	public String[] handles() {
79
+		String[] iHandle = new String[1];
80
+		iHandle[0] = "001";
81
+		return iHandle;
82
+	} 
83
+	
84
+	/**
85
+	 * Create a new instance of the IRCProcessor Object
86
+	 *
87
+	 * @param parser IRCParser That owns this IRCProcessor
88
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
89
+	 */
90
+	protected Process001 (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
91
+}

+ 76
- 0
src/uk/org/ownage/dmdirc/parser/Process004005.java Datei anzeigen

@@ -0,0 +1,76 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+// import uk.org.ownage.dmdirc.parser.callbacks.;
28
+
29
+/**
30
+ * Process ISUPPORT lines.
31
+ */
32
+public class Process004005 extends IRCProcessor {
33
+	/**
34
+	 * Process ISUPPORT lines.
35
+	 *
36
+	 * @param type Type of line to process ("005", "PRIVMSG" etc)
37
+	 * @param tokens IRCTokenised line to process
38
+	 */
39
+	public void process(String sParam, String[] token) {
40
+		if (sParam.equals("004")) {
41
+			// 004
42
+			myParser.h005Info.put("USERMODES",token[5]);
43
+		} else {
44
+			// 005
45
+			String[] Bits = null;
46
+			String sKey = null, sValue = null;
47
+			for (int i = 3; i < token.length ; i++) {
48
+				Bits = token[i].split("=",2);
49
+				sKey = Bits[0].toUpperCase();
50
+				if (Bits.length == 2) { sValue = Bits[1]; } else { sValue = ""; }
51
+				callDebugInfo(myParser.ndInfo, "%s => %s",sKey,sValue);
52
+				myParser.h005Info.put(sKey,sValue);
53
+			}
54
+		}
55
+	}
56
+	
57
+	/**
58
+	 * What does this IRCProcessor handle.
59
+	 *
60
+	 * @return String[] with the names of the tokens we handle.
61
+	 */
62
+	public String[] handles() {
63
+		String[] iHandle = new String[2];
64
+		iHandle[0] = "004";
65
+		iHandle[1] = "005";
66
+		return iHandle;
67
+	} 
68
+	
69
+	/**
70
+	 * Create a new instance of the IRCProcessor Object
71
+	 *
72
+	 * @param parser IRCParser That owns this IRCProcessor
73
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
74
+	 */
75
+	protected Process004005 (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
76
+}

+ 62
- 0
src/uk/org/ownage/dmdirc/parser/Process464.java Datei anzeigen

@@ -0,0 +1,62 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+// import uk.org.ownage.dmdirc.parser.callbacks.;
28
+
29
+/**
30
+ * Process a 464 message.
31
+ */
32
+public class Process464 extends IRCProcessor {
33
+	/**
34
+	 * Process a 464 message.
35
+	 *
36
+	 * @param type Type of line to process ("464")
37
+	 * @param tokens IRCTokenised line to process
38
+	 */
39
+	public void process(String sParam, String[] token) {
40
+		ParserError ei = new ParserError(ParserError.errError, "Password Required");
41
+		callErrorInfo(ei);
42
+	}
43
+	
44
+	/**
45
+	 * What does this IRCProcessor handle.
46
+	 *
47
+	 * @return String[] with the names of the tokens we handle.
48
+	 */
49
+	public String[] handles() {
50
+		String[] iHandle = new String[1];
51
+		iHandle[0] = "464";
52
+		return iHandle;
53
+	} 
54
+	
55
+	/**
56
+	 * Create a new instance of the IRCProcessor Object
57
+	 *
58
+	 * @param parser IRCParser That owns this IRCProcessor
59
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
60
+	 */
61
+	protected Process464 (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
62
+}

+ 62
- 0
src/uk/org/ownage/dmdirc/parser/ProcessAway.java Datei anzeigen

@@ -0,0 +1,62 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+// import uk.org.ownage.dmdirc.parser.callbacks.;
28
+
29
+/**
30
+ * Process an Away/Back message.
31
+ */
32
+public class ProcessAway extends IRCProcessor {
33
+	/**
34
+	 * Process an Away/Back message.
35
+	 *
36
+	 * @param type Type of line to process ("306", "350")
37
+	 * @param tokens IRCTokenised line to process
38
+	 */
39
+	public void process(String sParam, String[] token) {
40
+		myParser.cMyself.setAwayState(sParam.equals("306"));
41
+	}
42
+	
43
+	/**
44
+	 * What does this IRCProcessor handle.
45
+	 *
46
+	 * @return String[] with the names of the tokens we handle.
47
+	 */
48
+	public String[] handles() {
49
+		String[] iHandle = new String[2];
50
+		iHandle[0] = "305";
51
+		iHandle[1] = "306";
52
+		return iHandle;
53
+	} 
54
+	
55
+	/**
56
+	 * Create a new instance of the IRCProcessor Object
57
+	 *
58
+	 * @param parser IRCParser That owns this IRCProcessor
59
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
60
+	 */
61
+	protected ProcessAway (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
62
+}

+ 124
- 0
src/uk/org/ownage/dmdirc/parser/ProcessJoin.java Datei anzeigen

@@ -0,0 +1,124 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelJoin;
28
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelSelfJoin;
29
+import java.util.Enumeration;
30
+
31
+/**
32
+ * Process a channel join.
33
+ */
34
+public class ProcessJoin extends IRCProcessor {
35
+	/**
36
+	 * Process a channel join.
37
+	 *
38
+	 * @param type Type of line to process ("005", "PRIVMSG" etc)
39
+	 * @param tokens IRCTokenised line to process
40
+	 */
41
+	public void process(String sParam, String[] token) {
42
+		// :nick!ident@host JOIN (:)#Channel
43
+		Character cTemp;
44
+		Byte nTemp;
45
+		if (token.length < 3) { return; }
46
+		ClientInfo iClient;
47
+		ChannelInfo iChannel;
48
+		ChannelClientInfo iChannelClient;
49
+		
50
+		iClient = myParser.getClientInfo(token[0]);
51
+		iChannel = myParser.getChannelInfo(token[token.length-1]);
52
+		
53
+		if (iClient == null) { 
54
+			iClient = new ClientInfo(myParser, token[0]);
55
+			myParser.hClientList.put(iClient.getNickname().toLowerCase(),iClient);
56
+		}
57
+		// Check to see if we know the host/ident for this client to facilitate dmdirc Formatter
58
+		if (iClient.getHost().equals("")) { iClient.setUserBits(token[0],false); }
59
+		if (iChannel == null) { 
60
+			if (iClient != myParser.cMyself) {
61
+				callErrorInfo(new ParserError(ParserError.errWarning, "Got join for channel ("+token[token.length-1]+") that I am not on. [User: "+token[0]+"]"));
62
+			}
63
+			iChannel = new ChannelInfo(myParser, token[token.length-1]);
64
+			myParser.hChannelList.put(iChannel.getName().toLowerCase(),iChannel);
65
+			sendString("MODE "+iChannel.getName());
66
+			
67
+			// Find out the lists currently in use
68
+			for (Enumeration e = myParser.hChanModesOther.keys(); e.hasMoreElements();) {
69
+				cTemp = (Character)e.nextElement();
70
+				nTemp = myParser.hChanModesOther.get(cTemp);
71
+				if (nTemp == myParser.cmList) { sendString("MODE "+iChannel.getName()+" "+cTemp); }
72
+			}
73
+			callChannelSelfJoin(iChannel);
74
+		} else {
75
+			// This is only done if we are on the channel. Else we wait for names.
76
+			iChannelClient = iChannel.addClient(iClient);
77
+			callChannelJoin(iChannel, iChannelClient);
78
+		}
79
+	}	
80
+	
81
+	/**
82
+	 * Callback to all objects implementing the ChannelJoin Callback.
83
+	 *
84
+	 * @see IChannelJoin
85
+	 * @param cChannel Channel Object
86
+	 * @param cChannelClient ChannelClient object for new person
87
+	 */
88
+	protected boolean callChannelJoin(ChannelInfo cChannel, ChannelClientInfo cChannelClient) {
89
+		CallbackOnChannelJoin cb = (CallbackOnChannelJoin)getCallbackManager().getCallbackType("OnChannelJoin");
90
+		if (cb != null) { return cb.call(cChannel, cChannelClient); }
91
+		return false;
92
+	}
93
+	
94
+	/**
95
+	 * Callback to all objects implementing the ChannelSelfJoin Callback.
96
+	 *
97
+	 * @see IChannelSelfJoin
98
+	 * @param cChannel Channel Object
99
+	 */
100
+	protected boolean callChannelSelfJoin(ChannelInfo cChannel) {
101
+		CallbackOnChannelSelfJoin cb = (CallbackOnChannelSelfJoin)getCallbackManager().getCallbackType("OnChannelSelfJoin");
102
+		if (cb != null) { return cb.call(cChannel); }
103
+		return false;
104
+	}
105
+	
106
+	/**
107
+	 * What does this IRCProcessor handle.
108
+	 *
109
+	 * @return String[] with the names of the tokens we handle.
110
+	 */
111
+	public String[] handles() {
112
+		String[] iHandle = new String[1];
113
+		iHandle[0] = "JOIN";
114
+		return iHandle;
115
+	} 
116
+	
117
+	/**
118
+	 * Create a new instance of the IRCProcessor Object
119
+	 *
120
+	 * @param parser IRCParser That owns this IRCProcessor
121
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
122
+	 */
123
+	protected ProcessJoin (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
124
+}

+ 116
- 0
src/uk/org/ownage/dmdirc/parser/ProcessKick.java Datei anzeigen

@@ -0,0 +1,116 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelKick;
28
+
29
+/**
30
+ * Process a channel kick.
31
+ */
32
+public class ProcessKick extends IRCProcessor {
33
+	/**
34
+	 * Process a channel kick.
35
+	 *
36
+	 * @param type Type of line to process ("005", "PRIVMSG" etc)
37
+	 * @param tokens IRCTokenised line to process
38
+	 */
39
+	public void process(String sParam, String[] token) {
40
+		ChannelClientInfo iChannelClient;
41
+		ChannelClientInfo iChannelKicker;
42
+		ChannelInfo iChannel;
43
+		ClientInfo iClient;
44
+		ClientInfo iKicker;
45
+		String sReason = "";
46
+		
47
+		iClient = getClientInfo(token[3]);
48
+		iKicker = getClientInfo(token[0]);
49
+		iChannel = getChannelInfo(token[2]);
50
+		
51
+		if (iClient == null) { return; }
52
+		
53
+		if (myParser.alwaysUpdateClient && iKicker != null) {
54
+			// To facilitate dmdirc formatter, get user information
55
+			if (iKicker.getHost().equals("")) { iKicker.setUserBits(token[0],false); }
56
+		}
57
+
58
+		if (iChannel == null) { 
59
+			if (iClient != myParser.cMyself) {
60
+				callErrorInfo(new ParserError(ParserError.errWarning, "Got kick for channel ("+token[2]+") that I am not on. [User: "+token[3]+"]"));
61
+			}
62
+			return;
63
+		} else {
64
+			if (token.length > 4) { sReason = token[token.length-1]; }
65
+			iChannelClient = iChannel.getUser(iClient);
66
+			iChannelKicker = iChannel.getUser(token[0]);
67
+			callChannelKick(iChannel,iChannelClient,iChannelKicker,sReason,token[0]);
68
+			iChannel.delClient(iClient);
69
+			if (iClient == myParser.cMyself) {
70
+				iChannel.emptyChannel();
71
+				myParser.hChannelList.remove(iChannel.getName().toLowerCase());
72
+			} else { 
73
+				// Check if client is still on any channel we are on
74
+				if (!iClient.checkVisability()) {
75
+					// if not, remove them from memory incase they quit without us seeing
76
+					myParser.hClientList.remove(iClient.getNickname().toLowerCase());
77
+				}
78
+			}
79
+		}
80
+	}
81
+	
82
+	/**
83
+	 * Callback to all objects implementing the ChannelKick Callback.
84
+	 *
85
+	 * @see IChannelKick
86
+	 * @param cChannel Channel where the kick took place
87
+	 * @param cKickedClient ChannelClient that got kicked
88
+	 * @param cKickedByClient ChannelClient that did the kicking (may be null if server)
89
+	 * @param sReason Reason for kick (may be "")
90
+	 * @param sKickedByHost Hostname of Kicker (or servername)
91
+	 */
92
+	protected boolean callChannelKick(ChannelInfo cChannel, ChannelClientInfo cKickedClient, ChannelClientInfo cKickedByClient, String sReason, String sKickedByHost) {
93
+		CallbackOnChannelKick cb = (CallbackOnChannelKick)getCallbackManager().getCallbackType("OnChannelKick");
94
+		if (cb != null) { return cb.call(cChannel, cKickedClient, cKickedByClient, sReason, sKickedByHost); }
95
+		return false;
96
+	}
97
+	
98
+	/**
99
+	 * What does this IRCProcessor handle.
100
+	 *
101
+	 * @return String[] with the names of the tokens we handle.
102
+	 */
103
+	public String[] handles() {
104
+		String[] iHandle = new String[1];
105
+		iHandle[0] = "KICK";
106
+		return iHandle;
107
+	} 
108
+	
109
+	/**
110
+	 * Create a new instance of the IRCProcessor Object
111
+	 *
112
+	 * @param parser IRCParser That owns this IRCProcessor
113
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
114
+	 */
115
+	protected ProcessKick (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
116
+}

+ 112
- 0
src/uk/org/ownage/dmdirc/parser/ProcessMOTD.java Datei anzeigen

@@ -0,0 +1,112 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnMOTDEnd;
28
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnMOTDLine;
29
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnMOTDStart;
30
+
31
+/**
32
+ * Process a MOTD Related Line
33
+ */
34
+public class ProcessMOTD extends IRCProcessor {
35
+	/**
36
+	 * Process a MOTD Related Line.
37
+	 *
38
+	 * @param type Type of line to process ("005", "PRIVMSG" etc)
39
+	 * @param tokens IRCTokenised line to process
40
+	 */
41
+	public void process(String sParam, String[] token) {
42
+		if (sParam.equals("375")) {
43
+			callMOTDStart(token[token.length-1]);
44
+		} else if (sParam.equals("372")) {
45
+			callMOTDLine(token[token.length-1]);
46
+		} else {
47
+			myParser.parseChanModes();
48
+			myParser.parseChanPrefix();
49
+			myParser.parsePrefixModes();
50
+			myParser.parseUserModes();
51
+			callMOTDEnd(sParam.equals(422));
52
+		}
53
+	}
54
+	
55
+	/**
56
+	 * Callback to all objects implementing the MOTDEnd Callback.
57
+	 *
58
+	 * @param noMOTD Was this an MOTDEnd or NoMOTD
59
+	 * @see IMOTDEnd
60
+	 */
61
+	protected boolean callMOTDEnd(boolean noMOTD) {
62
+		CallbackOnMOTDEnd cb = (CallbackOnMOTDEnd)getCallbackManager().getCallbackType("OnMOTDEnd");
63
+		if (cb != null) { return cb.call(noMOTD); }
64
+		return false;
65
+	}
66
+	
67
+	/**
68
+	 * Callback to all objects implementing the MOTDLine Callback.
69
+	 *
70
+	 * @see IMOTDLine
71
+	 * @param data Incomming Line.
72
+	 */
73
+	protected boolean callMOTDLine(String data) {
74
+		CallbackOnMOTDLine cb = (CallbackOnMOTDLine)getCallbackManager().getCallbackType("OnMOTDLine");
75
+		if (cb != null) { return cb.call(data); }
76
+		return false;
77
+	}
78
+	
79
+	/**
80
+	 * Callback to all objects implementing the MOTDStart
81
+	 *
82
+	 * @see IMOTDStart
83
+	 * @param data Incomming Line.
84
+	 */
85
+	protected boolean callMOTDStart(String data) {
86
+		CallbackOnMOTDStart cb = (CallbackOnMOTDStart)getCallbackManager().getCallbackType("OnMOTDStart");
87
+		if (cb != null) { return cb.call(data); }
88
+		return false;
89
+	}
90
+	
91
+	/**
92
+	 * What does this IRCProcessor handle.
93
+	 *
94
+	 * @return String[] with the names of the tokens we handle.
95
+	 */
96
+	public String[] handles() {
97
+		String[] iHandle = new String[4];
98
+		iHandle[0] = "372";
99
+		iHandle[1] = "375";
100
+		iHandle[2] = "376";
101
+		iHandle[3] = "422";
102
+		return iHandle;
103
+	} 
104
+	
105
+	/**
106
+	 * Create a new instance of the IRCProcessor Object
107
+	 *
108
+	 * @param parser IRCParser That owns this IRCProcessor
109
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
110
+	 */
111
+	protected ProcessMOTD (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
112
+}

+ 419
- 0
src/uk/org/ownage/dmdirc/parser/ProcessMessage.java Datei anzeigen

@@ -0,0 +1,419 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelAction;
28
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelCTCP;
29
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelCTCPReply;
30
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelMessage;
31
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelNotice;
32
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnPrivateAction;
33
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnPrivateCTCP;
34
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnPrivateCTCPReply;
35
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnPrivateMessage;
36
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnPrivateNotice;
37
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnUnknownAction;
38
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnUnknownCTCP;
39
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnUnknownCTCPReply;
40
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnUnknownMessage;
41
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnUnknownNotice;
42
+
43
+
44
+/**
45
+ * Process PRIVMSGs and NOTICEs.
46
+ * This horrible handles PRIVMSGs and NOTICES<br>
47
+ * This inclues CTCPs and CTCPReplies<br>
48
+ * It handles all 3 targets (Channel, Private, Unknown)<br>
49
+ * Actions are handled here aswell separately from CTCPs.<br>
50
+ * Each type has 5 Calls, making 15 callbacks handled here.
51
+ */
52
+public class ProcessMessage extends IRCProcessor {
53
+	/**
54
+	 * Process PRIVMSGs and NOTICEs.
55
+	 * This horrible thing handles PRIVMSGs and NOTICES<br>
56
+	 * This inclues CTCPs and CTCPReplies<br>
57
+	 * It handles all 3 targets (Channel, Private, Unknown)<br>
58
+	 * Actions are handled here aswell separately from CTCPs.<br>
59
+	 * Each type has 5 Calls, making 15 callbacks handled here.
60
+	 *
61
+	 * @param type Type of line to process ("005", "PRIVMSG" etc)
62
+	 * @param tokens IRCTokenised line to process
63
+	 */
64
+	public void process(String sParam, String[] token) {
65
+		// Ignore people!
66
+		String bits[] = token[0].split(":",2);
67
+		String sMessage = "";
68
+		if (bits.length > 1) { sMessage = bits[1]; } else { sMessage = bits[0]; }
69
+		// We use sMessage to be the users host (first token in the line)
70
+		if (myParser.getIgnoreList().matches(sMessage) > -1) { return; }
71
+		
72
+		ChannelClientInfo iChannelClient = null;
73
+		ChannelInfo iChannel = null;
74
+		ClientInfo iClient = null;
75
+		sMessage = token[token.length-1];
76
+		bits = sMessage.split(" ", 2);
77
+		Character Char1 = Character.valueOf((char)1);
78
+		String sCTCP = "";
79
+		boolean isAction = false;
80
+		boolean isCTCP = false;
81
+		
82
+		if (sParam.equalsIgnoreCase("PRIVMSG")) {
83
+			// Actions are special CTCPs
84
+			// Bits is the message been split into 2 parts, the first word and the rest
85
+			if (bits[0].equalsIgnoreCase(Char1+"ACTION") && Character.valueOf(sMessage.charAt(sMessage.length()-1)).equals(Char1)) {
86
+				isAction = true;
87
+				if (bits.length > 1) {
88
+					sMessage = bits[1];
89
+					sMessage = sMessage.substring(0, sMessage.length()-1);
90
+				} else { sMessage = ""; }
91
+			}
92
+		}
93
+		// If the message is not an action, check if it is another type of CTCP
94
+		if (!isAction) {
95
+			// CTCPs have Character(1) at the start/end of the line
96
+			if (Character.valueOf(sMessage.charAt(0)).equals(Char1) && Character.valueOf(sMessage.charAt(sMessage.length()-1)).equals(Char1)) {
97
+				isCTCP = true;
98
+				// Bits is the message been split into 2 parts, the first word and the rest
99
+				// Some CTCPs have messages and some do not
100
+				if (bits.length > 1) { sMessage = bits[1]; } else { sMessage = ""; }
101
+				// Remove the leading char1
102
+				bits = bits[0].split(Char1.toString());
103
+				sCTCP = bits[1];
104
+				// remove the trailing char1
105
+				if (sMessage == "") { sMessage = sMessage.split(Char1.toString())[0]; }
106
+				else { sCTCP = sCTCP.split(Char1.toString())[0]; }
107
+				callDebugInfo(myParser.ndInfo, "CTCP: \"%s\" \"%s\"",sCTCP,sMessage);
108
+			}
109
+		}
110
+
111
+		iClient = getClientInfo(token[0]);
112
+		if (myParser.alwaysUpdateClient && iClient != null) {
113
+			// Facilitate DMDIRC Formatter
114
+			if (iClient.getHost().equals("")) {iClient.setUserBits(token[0],false); }
115
+		}
116
+		
117
+		// Fire the appropriate callbacks.
118
+		// OnChannel* Callbacks are fired if the target was a channel
119
+		// OnPrivate* Callbacks are fired if the target was us
120
+		// OnUnknown* Callbacks are fired if the target was neither of the above
121
+		// Actions and CTCPs are send as PRIVMSGS
122
+		// CTCPReplies are sent as Notices		
123
+		if (isValidChannelName(token[2])) {
124
+			iChannel = getChannelInfo(token[2]);
125
+			if (iClient != null && iChannel != null) { iChannelClient = iChannel.getUser(iClient); }
126
+			if (sParam.equalsIgnoreCase("PRIVMSG")) {
127
+				if (!isAction) {
128
+					if (isCTCP) {
129
+						callChannelCTCP(iChannel, iChannelClient, sCTCP, sMessage, token[0]);
130
+					} else {
131
+						callChannelMessage(iChannel, iChannelClient, sMessage, token[0]);
132
+					}
133
+				} else {
134
+					callChannelAction(iChannel, iChannelClient, sMessage, token[0]);
135
+				}
136
+			} else if (sParam.equalsIgnoreCase("NOTICE")) {
137
+				if (isCTCP) {
138
+					callChannelCTCPReply(iChannel, iChannelClient, sCTCP, sMessage, token[0]);
139
+				} else {
140
+					callChannelNotice(iChannel, iChannelClient, sMessage, token[0]);
141
+				}
142
+			}
143
+		} else if (token[2].equalsIgnoreCase(myParser.cMyself.getNickname())) {
144
+			if (sParam.equalsIgnoreCase("PRIVMSG")) {
145
+				if (!isAction) {
146
+					if (isCTCP) {
147
+						callPrivateCTCP(sCTCP, sMessage, token[0]);
148
+					} else {
149
+						callPrivateMessage(sMessage, token[0]);
150
+					}
151
+				} else {
152
+					callPrivateAction(sMessage, token[0]);
153
+				}
154
+			} else if (sParam.equalsIgnoreCase("NOTICE")) {
155
+				if (isCTCP) {
156
+					callPrivateCTCPReply(sCTCP, sMessage, token[0]);
157
+				} else {
158
+					callPrivateNotice(sMessage, token[0]);
159
+				}
160
+			}
161
+		} else {
162
+			callDebugInfo(myParser.ndInfo, "Message for Other ("+token[2]+")");
163
+			if (sParam.equalsIgnoreCase("PRIVMSG")) {
164
+				if (!isAction) {
165
+					if (isCTCP) {
166
+						callUnknownCTCP(sCTCP, sMessage, token[2], token[0]);
167
+					} else {
168
+						callUnknownMessage(sMessage, token[2], token[0]);
169
+					}
170
+				} else {
171
+					callUnknownAction(sMessage, token[2], token[0]);
172
+				}
173
+			} else if (sParam.equalsIgnoreCase("NOTICE")) {
174
+				if (isCTCP) {
175
+					callUnknownCTCPReply(sCTCP, sMessage, token[2], token[0]);
176
+				} else {
177
+					callUnknownNotice(sMessage, token[2], token[0]);
178
+				}
179
+			}
180
+		}
181
+	}
182
+	
183
+	/**
184
+	 * Callback to all objects implementing the ChannelAction Callback.
185
+	 *
186
+	 * @see IChannelAction
187
+	 * @param cChannel Channel where the action was sent to
188
+	 * @param cChannelClient ChannelClient who sent the action (may be null if server)
189
+	 * @param sMessage action contents
190
+	 * @param sHost Hostname of sender (or servername)
191
+	 */
192
+	protected boolean callChannelAction(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sMessage, String sHost) {
193
+		CallbackOnChannelAction cb = (CallbackOnChannelAction)getCallbackManager().getCallbackType("OnChannelAction");
194
+		if (cb != null) { return cb.call(cChannel, cChannelClient, sMessage, sHost); }
195
+		return false;
196
+	}
197
+	
198
+	/**
199
+	 * Callback to all objects implementing the ChannelCTCP Callback.
200
+	 *
201
+	 * @see IChannelCTCP
202
+	 * @param cChannel Channel where CTCP was sent
203
+	 * @param cChannelClient ChannelClient who sent the message (may be null if server)
204
+	 * @param sType Type of CTCP (VERSION, TIME etc)
205
+	 * @param sMessage Additional contents
206
+	 * @param sHost Hostname of sender (or servername)
207
+	 */
208
+	protected boolean callChannelCTCP(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sType, String sMessage, String sHost) {
209
+		CallbackOnChannelCTCP cb = (CallbackOnChannelCTCP)getCallbackManager().getCallbackType("OnChannelCTCP");
210
+		if (cb != null) { return cb.call(cChannel, cChannelClient, sType, sMessage, sHost); }
211
+		return false;
212
+	}
213
+
214
+	/**
215
+	 * Callback to all objects implementing the ChannelCTCPReply Callback.
216
+	 *
217
+	 * @see IChannelCTCPReply
218
+	 * @param cChannel Channel where CTCPReply was sent
219
+	 * @param cChannelClient ChannelClient who sent the message (may be null if server)
220
+	 * @param sType Type of CTCPRReply (VERSION, TIME etc)
221
+	 * @param sMessage Reply Contents
222
+	 * @param sHost Hostname of sender (or servername)
223
+	 */
224
+	protected boolean callChannelCTCPReply(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sType, String sMessage, String sHost) {
225
+		CallbackOnChannelCTCPReply cb = (CallbackOnChannelCTCPReply)getCallbackManager().getCallbackType("OnChannelCTCPReply");
226
+		if (cb != null) { return cb.call(cChannel, cChannelClient, sType, sMessage, sHost); }
227
+		return false;
228
+	}
229
+	
230
+	/**
231
+	 * Callback to all objects implementing the ChannelMessage Callback.
232
+	 *
233
+	 * @see IChannelMessage
234
+	 * @param cChannel Channel where the message was sent to
235
+	 * @param cChannelClient ChannelClient who sent the message (may be null if server)
236
+	 * @param sMessage Message contents
237
+	 * @param sHost Hostname of sender (or servername)
238
+	 */
239
+	protected boolean callChannelMessage(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sMessage, String sHost) {
240
+		CallbackOnChannelMessage cb = (CallbackOnChannelMessage)getCallbackManager().getCallbackType("OnChannelMessage");
241
+		if (cb != null) { return cb.call(cChannel, cChannelClient, sMessage, sHost); }
242
+		return false;
243
+	}
244
+	
245
+	/**
246
+	 * Callback to all objects implementing the ChannelNotice Callback.
247
+	 *
248
+	 * @see IChannelNotice
249
+	 * @param cChannel Channel where the notice was sent to
250
+	 * @param cChannelClient ChannelClient who sent the notice (may be null if server)
251
+	 * @param sMessage notice contents
252
+	 * @param sHost Hostname of sender (or servername)
253
+	 */
254
+	protected boolean callChannelNotice(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sMessage, String sHost) {
255
+		CallbackOnChannelNotice cb = (CallbackOnChannelNotice)getCallbackManager().getCallbackType("OnChannelNotice");
256
+		if (cb != null) { return cb.call(cChannel, cChannelClient, sMessage, sHost); }
257
+		return false;
258
+	}
259
+	
260
+	/**
261
+	 * Callback to all objects implementing the PrivateAction Callback.
262
+	 *
263
+	 * @see IPrivateAction
264
+	 * @param sMessage action contents
265
+	 * @param sHost Hostname of sender (or servername)
266
+	 */
267
+	protected boolean callPrivateAction(String sMessage, String sHost) {
268
+		CallbackOnPrivateAction cb = (CallbackOnPrivateAction)getCallbackManager().getCallbackType("OnPrivateAction");
269
+		if (cb != null) { return cb.call(sMessage, sHost); }
270
+		return false;
271
+	}
272
+
273
+	/**
274
+	 * Callback to all objects implementing the PrivateCTCP Callback.
275
+	 *
276
+	 * @see IPrivateCTCP
277
+	 * @param sType Type of CTCP (VERSION, TIME etc)
278
+	 * @param sMessage Additional contents
279
+	 * @param sHost Hostname of sender (or servername)
280
+	 */
281
+	protected boolean callPrivateCTCP(String sType, String sMessage, String sHost) {
282
+		CallbackOnPrivateCTCP cb = (CallbackOnPrivateCTCP)getCallbackManager().getCallbackType("OnPrivateCTCP");
283
+		if (cb != null) { return cb.call(sType, sMessage, sHost); }
284
+		return false;
285
+	}
286
+
287
+	/**
288
+	 * Callback to all objects implementing the PrivateCTCPReply Callback.
289
+	 *
290
+	 * @see IPrivateCTCPReply
291
+	 * @param sType Type of CTCPRReply (VERSION, TIME etc)
292
+	 * @param sMessage Reply Contents
293
+	 * @param sHost Hostname of sender (or servername)
294
+	 */
295
+	protected boolean callPrivateCTCPReply(String sType, String sMessage, String sHost) {
296
+		CallbackOnPrivateCTCPReply cb = (CallbackOnPrivateCTCPReply)getCallbackManager().getCallbackType("OnPrivateCTCPReply");
297
+		if (cb != null) { return cb.call(sType, sMessage, sHost); }
298
+		return false;
299
+	}
300
+
301
+	/**
302
+	 * Callback to all objects implementing the PrivateMessage Callback.
303
+	 *
304
+	 * @see IPrivateMessage
305
+	 * @param sMessage Message contents
306
+	 * @param sHost Hostname of sender (or servername)
307
+	 */
308
+	protected boolean callPrivateMessage(String sMessage, String sHost) {
309
+		CallbackOnPrivateMessage cb = (CallbackOnPrivateMessage)getCallbackManager().getCallbackType("OnPrivateMessage");
310
+		if (cb != null) { return cb.call(sMessage, sHost); }
311
+		return false;
312
+	}
313
+
314
+	/**
315
+	 * Callback to all objects implementing the PrivateNotice Callback.
316
+	 *
317
+	 * @see IPrivateNotice
318
+	 * @param sMessage Notice contents
319
+	 * @param sHost Hostname of sender (or servername)
320
+	 */
321
+	protected boolean callPrivateNotice(String sMessage, String sHost) {
322
+		CallbackOnPrivateNotice cb = (CallbackOnPrivateNotice)getCallbackManager().getCallbackType("OnPrivateNotice");
323
+		if (cb != null) { return cb.call(sMessage, sHost); }
324
+		return false;
325
+	}
326
+	
327
+	/**
328
+	 * Callback to all objects implementing the UnknownAction Callback.
329
+	 *
330
+	 * @see IUnknownAction
331
+	 * @param sMessage Action contents
332
+	 * @param sTarget Actual target of action
333
+	 * @param sHost Hostname of sender (or servername)
334
+	 */
335
+	protected boolean callUnknownAction(String sMessage, String sTarget, String sHost) {
336
+		CallbackOnUnknownAction cb = (CallbackOnUnknownAction)getCallbackManager().getCallbackType("OnUnknownAction");
337
+		if (cb != null) { return cb.call(sMessage, sTarget, sHost); }
338
+		return false;
339
+	}
340
+
341
+	/**
342
+	 * Callback to all objects implementing the UnknownCTCP Callback.
343
+	 *
344
+	 * @see IUnknownCTCP
345
+	 * @param sType Type of CTCP (VERSION, TIME etc)
346
+	 * @param sMessage Additional contents
347
+	 * @param sTarget Actual Target of CTCP
348
+	 * @param sHost Hostname of sender (or servername)
349
+	 */
350
+	protected boolean callUnknownCTCP(String sType, String sMessage, String sTarget, String sHost) {
351
+		CallbackOnUnknownCTCP cb = (CallbackOnUnknownCTCP)getCallbackManager().getCallbackType("OnUnknownCTCP");
352
+		if (cb != null) { return cb.call(sType, sMessage, sTarget, sHost); }
353
+		return false;
354
+	}
355
+
356
+	/**
357
+	 * Callback to all objects implementing the UnknownCTCPReply Callback.
358
+	 *
359
+	 * @see IUnknownCTCPReply
360
+	 * @param sType Type of CTCPRReply (VERSION, TIME etc)
361
+	 * @param sMessage Reply Contents
362
+	 * @param sTarget Actual Target of CTCPReply
363
+	 * @param sHost Hostname of sender (or servername)
364
+	 */
365
+	protected boolean callUnknownCTCPReply(String sType, String sMessage, String sTarget, String sHost) {
366
+		CallbackOnUnknownCTCPReply cb = (CallbackOnUnknownCTCPReply)getCallbackManager().getCallbackType("OnUnknownCTCPReply");
367
+		if (cb != null) { return cb.call(sType, sMessage, sTarget, sHost); }
368
+		return false;
369
+	}
370
+
371
+	/**
372
+	 * Callback to all objects implementing the UnknownMessage Callback.
373
+	 *
374
+	 * @see IUnknownMessage
375
+	 * @param sMessage Message contents
376
+	 * @param sTarget Actual target of message
377
+	 * @param sHost Hostname of sender (or servername)
378
+	 */
379
+	protected boolean callUnknownMessage(String sMessage, String sTarget, String sHost) {
380
+		CallbackOnUnknownMessage cb = (CallbackOnUnknownMessage)getCallbackManager().getCallbackType("OnUnknownMessage");
381
+		if (cb != null) { return cb.call(sMessage, sTarget, sHost); }
382
+		return false;
383
+	}
384
+
385
+	/**
386
+	 * Callback to all objects implementing the UnknownNotice Callback.
387
+	 *
388
+	 * @see IUnknownNotice
389
+	 * @param sMessage Notice contents
390
+	 * @param sTarget Actual target of notice
391
+	 * @param sHost Hostname of sender (or servername)
392
+	 */
393
+	protected boolean callUnknownNotice(String sMessage, String sTarget, String sHost) {
394
+		CallbackOnUnknownNotice cb = (CallbackOnUnknownNotice)getCallbackManager().getCallbackType("OnUnknownNotice");
395
+		if (cb != null) { return cb.call(sMessage, sTarget, sHost); }
396
+		return false;
397
+	}
398
+
399
+	
400
+	/**
401
+	 * What does this IRCProcessor handle.
402
+	 *
403
+	 * @return String[] with the names of the tokens we handle.
404
+	 */
405
+	public String[] handles() {
406
+		String[] iHandle = new String[2];
407
+		iHandle[0] = "PRIVMSG";
408
+		iHandle[1] = "NOTICE";
409
+		return iHandle;
410
+	} 
411
+	
412
+	/**
413
+	 * Create a new instance of the IRCProcessor Object
414
+	 *
415
+	 * @param parser IRCParser That owns this IRCProcessor
416
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
417
+	 */
418
+	protected ProcessMessage (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
419
+}

+ 307
- 0
src/uk/org/ownage/dmdirc/parser/ProcessMode.java Datei anzeigen

@@ -0,0 +1,307 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelSingleModeChanged;
28
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelNonUserModeChanged;
29
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelModeChanged;
30
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelUserModeChanged;
31
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnUserModeChanged;
32
+
33
+/**
34
+ * Process a Mode line.
35
+ */
36
+public class ProcessMode extends IRCProcessor {
37
+	/**
38
+	 * Process a Mode Line.
39
+	 *
40
+	 * @param type Type of line to process ("005", "PRIVMSG" etc)
41
+	 * @param tokens IRCTokenised line to process
42
+	 */
43
+	public void process(String sParam, String[] token) {
44
+		String[] sModestr;
45
+		String sChannelName;
46
+		if (sParam.equals("324")) {
47
+			sChannelName = token[3];
48
+			sModestr = new String[token.length-4];
49
+			System.arraycopy(token, 4, sModestr, 0, token.length-4);
50
+		} else {
51
+			sChannelName = token[2];
52
+			sModestr = new String[token.length-3];
53
+			System.arraycopy(token, 3, sModestr, 0, token.length-3);
54
+		}
55
+
56
+		if (!isValidChannelName(sChannelName)) { processUserMode(sParam, token, sModestr); }
57
+		else { processChanMode(sParam, token, sModestr, sChannelName); }
58
+	}
59
+	
60
+	/**
61
+	 * Method to trim spaces from strings
62
+	 *
63
+	 * @param str String to trim
64
+	 * @return String without spaces on the ends
65
+	 */
66
+	private String trim(String str) { return str.trim(); }
67
+	
68
+	/**
69
+	 * Process Chan modes.
70
+	 *
71
+	 * @param sParam String representation of parameter to parse
72
+	 * @param token IRCTokenised Array of the incomming line
73
+	 */	
74
+	public void processChanMode(String sParam, String token[], String sModestr[], String sChannelName) {
75
+		String sFullModeStr;
76
+		String sNonUserModeStr = "";
77
+		String sNonUserModeStrParams = "";
78
+		String sModeParam;
79
+		String sTemp;
80
+		int nCurrent = 0, nParam = 1, nValue = 0;
81
+		boolean bPositive = true, bBooleanMode = true;
82
+		char cPositive = '+';
83
+		ChannelInfo iChannel;
84
+		ChannelClientInfo iChannelClientInfo;
85
+		ClientInfo iClient;
86
+		ChannelClientInfo setterCCI;
87
+		
88
+		CallbackOnChannelSingleModeChanged cbSingle = null;
89
+		CallbackOnChannelNonUserModeChanged cbNonUser = null;
90
+		if (!sParam.equals("324")) {
91
+			cbSingle = (CallbackOnChannelSingleModeChanged)getCallbackManager().getCallbackType("OnChannelSingleModeChanged");
92
+			cbNonUser = (CallbackOnChannelNonUserModeChanged)getCallbackManager().getCallbackType("OnChannelNonUserModeChanged");
93
+		}
94
+		
95
+		iChannel = getChannelInfo(sChannelName);
96
+		if (iChannel == null) { 
97
+			callErrorInfo(new ParserError(ParserError.errWarning, "Got modes for channel ("+sChannelName+") that I am not on."));
98
+			iChannel = new ChannelInfo(myParser, sChannelName);
99
+			myParser.hChannelList.put(iChannel.getName().toLowerCase(),iChannel);
100
+		}
101
+		// Get the current channel modes
102
+		if (!sParam.equals("324")) { nCurrent = iChannel.getMode(); }
103
+		
104
+		setterCCI = iChannel.getUser(token[0]);
105
+		if (myParser.alwaysUpdateClient && setterCCI != null) {
106
+			// Facilitate dmdirc formatter
107
+			if (setterCCI.getClient().getHost().equals("")) {setterCCI.getClient().setUserBits(token[0],false); }
108
+		}
109
+		
110
+		// Loop through the mode string, and add/remove modes/params where they are needed
111
+		for (int i = 0; i < sModestr[0].length(); ++i) {
112
+			Character cMode = sModestr[0].charAt(i);
113
+			if (cMode.equals(":".charAt(0))) { continue; }
114
+			
115
+			sNonUserModeStr = sNonUserModeStr+cMode;
116
+			if (cMode.equals("+".charAt(0))) { cPositive = '+'; bPositive = true; }
117
+			else if (cMode.equals("-".charAt(0))) { cPositive = '-'; bPositive = false; }
118
+			else {
119
+				if (myParser.hChanModesBool.containsKey(cMode)) { nValue = myParser.hChanModesBool.get(cMode); bBooleanMode = true; }
120
+				else if (myParser.hChanModesOther.containsKey(cMode)) { nValue = myParser.hChanModesOther.get(cMode); bBooleanMode = false; }
121
+				else if (myParser.hPrefixModes.containsKey(cMode)) { 
122
+					// (de) OP/Voice someone
123
+					sModeParam = sModestr[nParam++];
124
+					nValue = myParser.hPrefixModes.get(cMode);
125
+					callDebugInfo(myParser.ndInfo, "User Mode: %c / %d [%s] {Positive: %b}",cMode, nValue, sModeParam, bPositive);
126
+					iChannelClientInfo = iChannel.getUser(sModeParam);
127
+					if (iChannelClientInfo == null) {
128
+						// Client not known?
129
+						callErrorInfo(new ParserError(ParserError.errWarning, "Got mode for client not known on channel - Added"));
130
+						iClient = getClientInfo(sModeParam);
131
+						if (iClient == null) { 
132
+							callErrorInfo(new ParserError(ParserError.errWarning, "Got mode for client not known at all - Added"));
133
+							iClient = new ClientInfo(myParser, sModeParam);
134
+							myParser.hClientList.put(iClient.getNickname().toLowerCase(),iClient);
135
+						}
136
+						iChannelClientInfo = iChannel.addClient(iClient);
137
+					}
138
+					callDebugInfo(myParser.ndInfo, "\tOld Mode Value: %d",iChannelClientInfo.getChanMode());
139
+					if (bPositive) { iChannelClientInfo.setChanMode(iChannelClientInfo.getChanMode() + nValue); sTemp = "+"; }
140
+					else { iChannelClientInfo.setChanMode(iChannelClientInfo.getChanMode() - nValue); sTemp = "-"; }
141
+					sTemp = sTemp+cMode+" "+iChannelClientInfo.getNickname();
142
+					
143
+					callChannelUserModeChanged(iChannel, iChannelClientInfo, setterCCI, token[0], sTemp);
144
+					continue;
145
+				} else {
146
+					// unknown mode - add as boolean
147
+					callErrorInfo(new ParserError(ParserError.errWarning, "Got unknown mode "+cMode+" - Added as boolean mode"));
148
+					myParser.hChanModesBool.put(cMode,myParser.nNextKeyCMBool);
149
+					nValue = myParser.nNextKeyCMBool;
150
+					bBooleanMode = true;
151
+					myParser.nNextKeyCMBool = myParser.nNextKeyCMBool*2;
152
+				}
153
+				
154
+				if (bBooleanMode) {
155
+					callDebugInfo(myParser.ndInfo, "Boolean Mode: %c [%d] {Positive: %b}",cMode, nValue, bPositive);
156
+					if (bPositive) { nCurrent = nCurrent + nValue; }
157
+					else { nCurrent = nCurrent - nValue; }
158
+				} else {
159
+					if (nValue == myParser.cmList) {
160
+						// List Mode
161
+						sModeParam = sModestr[nParam++];
162
+						sNonUserModeStrParams = sNonUserModeStrParams+" "+sModeParam;
163
+						iChannel.setListModeParam(cMode, sModeParam, bPositive);
164
+						callDebugInfo(myParser.ndInfo, "List Mode: %c [%s] {Positive: %b}",cMode, sModeParam, bPositive);
165
+						if (cbSingle != null) { cbSingle.call(iChannel, setterCCI, token[0], cPositive+cMode+" "+sModeParam ); }
166
+					} else {
167
+						// Mode with a parameter
168
+						if (bPositive) { 
169
+							// +Mode - always needs a parameter to set
170
+							sModeParam = sModestr[nParam++];
171
+							sNonUserModeStrParams = sNonUserModeStrParams+" "+sModeParam;
172
+							callDebugInfo(myParser.ndInfo, "Set Mode: %c [%s] {Positive: %b}",cMode, sModeParam, bPositive);
173
+							iChannel.setModeParam(cMode,sModeParam);
174
+							if (cbSingle != null) { cbSingle.call(iChannel, setterCCI, token[0], cPositive+cMode+" "+sModeParam ); }
175
+						} else {
176
+							// -Mode - parameter isn't always needed, we need to check
177
+							if ((nValue & myParser.cmUnset) == myParser.cmUnset) {
178
+								sModeParam = sModestr[nParam++];
179
+								sNonUserModeStrParams = sNonUserModeStrParams+" "+sModeParam;
180
+							} else {
181
+								sModeParam = "";
182
+							}
183
+							callDebugInfo(myParser.ndInfo, "Unset Mode: %c [%s] {Positive: %b}",cMode, sModeParam, bPositive);
184
+							iChannel.setModeParam(cMode,"");
185
+							if (cbSingle != null) { cbSingle.call(iChannel, setterCCI, token[0], trim(cPositive+cMode+" "+sModeParam) ); }
186
+						}
187
+					}
188
+				}
189
+			}
190
+		}
191
+		
192
+		// Call Callbacks
193
+		sFullModeStr = "";
194
+		for (int i = 0; i < sModestr.length; ++i) { sFullModeStr = sFullModeStr+sModestr[i]+" "; }
195
+		
196
+		iChannel.setMode(nCurrent);
197
+		if (sParam.equals("324")) { callChannelModeChanged(iChannel, null, "", trim(sFullModeStr)); }
198
+		else { callChannelModeChanged(iChannel, setterCCI, token[0], trim(sFullModeStr)); }
199
+		if (cbNonUser != null) { cbNonUser.call(iChannel, setterCCI, token[0], trim(sNonUserModeStr+sNonUserModeStrParams)); }
200
+	}
201
+	
202
+	/**
203
+	 * Process user modes.
204
+	 *
205
+	 * @param sParam String representation of parameter to parse
206
+	 * @param token IRCTokenised Array of the incomming line
207
+	 */	
208
+	private void processUserMode(String sParam, String token[], String sModestr[]) {
209
+		int nCurrent = 0, nValue = 0;
210
+		boolean bPositive = true;
211
+		
212
+		ClientInfo iClient;
213
+		
214
+		iClient = getClientInfo(token[2]);
215
+		if (iClient == null) { return; }
216
+		
217
+		nCurrent = iClient.getUserMode();
218
+		
219
+		for (int i = 0; i < sModestr[0].length(); ++i) {
220
+			Character cMode = sModestr[0].charAt(i);
221
+			if (cMode.equals("+".charAt(0))) { bPositive = true; }
222
+			else if (cMode.equals("-".charAt(0))) { bPositive = false; }
223
+			else if (cMode.equals(":".charAt(0))) { continue; }
224
+			else {
225
+				if (myParser.hUserModes.containsKey(cMode)) { nValue = myParser.hUserModes.get(cMode); }
226
+				else {
227
+					// Unknown mode
228
+					callErrorInfo(new ParserError(ParserError.errWarning, "Got unknown user mode "+cMode+" - Added"));
229
+					myParser.hUserModes.put(cMode,myParser.nNextKeyUser);
230
+					nValue = myParser.nNextKeyUser;
231
+					myParser.nNextKeyUser = myParser.nNextKeyUser*2;
232
+				}
233
+				// Usermodes are always boolean
234
+				callDebugInfo(myParser.ndInfo, "User Mode: %c [%d] {Positive: %b}",cMode, nValue, bPositive);
235
+				if (bPositive) { nCurrent = nCurrent + nValue; }
236
+				else { nCurrent = nCurrent - nValue; }
237
+			}
238
+		}
239
+		
240
+		iClient.setUserMode(nCurrent);
241
+		callUserModeChanged(iClient, token[0]);
242
+	}	
243
+	
244
+	/**
245
+	 * Callback to all objects implementing the ChannelModeChanged Callback.
246
+	 *
247
+	 * @see IChannelModeChanged
248
+	 * @param cChannel Channel where modes were changed
249
+	 * @param cChannelClient Client chaning the modes (null if server)
250
+	 * @param sHost Host doing the mode changing (User host or server name)
251
+	 * @param sModes Exact String parsed
252
+	 */
253
+	protected boolean callChannelModeChanged(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sHost, String sModes) {
254
+		CallbackOnChannelModeChanged cb = (CallbackOnChannelModeChanged)getCallbackManager().getCallbackType("OnChannelModeChanged");
255
+		if (cb != null) { return cb.call(cChannel, cChannelClient, sHost, sModes); }
256
+		return false;
257
+	}
258
+	
259
+	/**
260
+	 * Callback to all objects implementing the ChannelUserModeChanged Callback.
261
+	 *
262
+	 * @see IChannelUserModeChanged
263
+	 * @param cChannel Channel where modes were changed
264
+	 * @param cChangedClient Client being changed
265
+	 * @param cSetByClient Client chaning the modes (null if server)
266
+	 * @param sMode String representing mode change (ie +o)
267
+	 * @param sHost Host doing the mode changing (User host or server name)
268
+	 */
269
+	protected boolean callChannelUserModeChanged(ChannelInfo cChannel, ChannelClientInfo cChangedClient, ChannelClientInfo cSetByClient, String sHost, String sMode) {
270
+		CallbackOnChannelUserModeChanged cb = (CallbackOnChannelUserModeChanged)getCallbackManager().getCallbackType("OnChannelUserModeChanged");
271
+		if (cb != null) { return cb.call(cChannel, cChangedClient, cSetByClient, sHost, sMode); }
272
+		return false;
273
+	}
274
+	
275
+	/**
276
+	 * Callback to all objects implementing the UserModeChanged Callback.
277
+	 *
278
+	 * @see IUserModeChanged
279
+	 * @param cClient Client that had the mode changed (almost always us)
280
+	 * @param sSetby Host that set the mode (us or servername)
281
+	 */
282
+	protected boolean callUserModeChanged(ClientInfo cClient, String sSetby) {
283
+		CallbackOnUserModeChanged cb = (CallbackOnUserModeChanged)getCallbackManager().getCallbackType("OnUserModeChanged");
284
+		if (cb != null) { return cb.call(cClient, sSetby); }
285
+		return false;
286
+	}	
287
+	
288
+	/**
289
+	 * What does this IRCProcessor handle.
290
+	 *
291
+	 * @return String[] with the names of the tokens we handle.
292
+	 */
293
+	public String[] handles() {
294
+		String[] iHandle = new String[2];
295
+		iHandle[0] = "MODE";
296
+		iHandle[1] = "324";
297
+		return iHandle;
298
+	} 
299
+	
300
+	/**
301
+	 * Create a new instance of the IRCProcessor Object
302
+	 *
303
+	 * @param parser IRCParser That owns this IRCProcessor
304
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
305
+	 */
306
+	protected ProcessMode (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
307
+}

+ 131
- 0
src/uk/org/ownage/dmdirc/parser/ProcessNames.java Datei anzeigen

@@ -0,0 +1,131 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelGotNames;
28
+
29
+/**
30
+ * Process a Names reply.
31
+ */
32
+public class ProcessNames extends IRCProcessor {
33
+	/**
34
+	 * Process a Names reply.
35
+	 *
36
+	 * @param type Type of line to process ("005", "PRIVMSG" etc)
37
+	 * @param tokens IRCTokenised line to process
38
+	 */
39
+	public void process(String sParam, String[] token) {
40
+		ChannelInfo iChannel;
41
+		if (sParam.equals("366")) {
42
+			// End of names
43
+			iChannel = getChannelInfo(token[3]);
44
+			if (iChannel != null) {
45
+				iChannel.bAddingNames = false;
46
+				callChannelGotNames(iChannel);
47
+			}
48
+		} else {
49
+			// Names
50
+			
51
+			ClientInfo iClient;
52
+			ChannelClientInfo iChannelClient;
53
+			
54
+			iChannel = getChannelInfo(token[4]);
55
+		
56
+			if (iChannel == null) { 
57
+				callErrorInfo(new ParserError(ParserError.errWarning, "Got names for channel ("+token[4]+") that I am not on."));
58
+				iChannel = new ChannelInfo(myParser, token[4]);
59
+				myParser.hChannelList.put(iChannel.getName().toLowerCase(),iChannel);
60
+			}
61
+			
62
+			// If we are not expecting names, clear the current known names - this is fresh stuff!
63
+			if (!iChannel.bAddingNames) { iChannel.emptyChannel(); }
64
+			iChannel.bAddingNames = true;
65
+			
66
+			String[] sNames = token[token.length-1].split(" ");
67
+			String sNameBit = "", sModes = "", sName = "";
68
+			int nPrefix = 0;
69
+			for (int j = 0; j < sNames.length; ++j) {
70
+				sNameBit = sNames[j];
71
+				for (int i = 0; i < sNameBit.length(); ++i) {
72
+					Character cMode = sNameBit.charAt(i);
73
+					if (myParser.hPrefixMap.containsKey(cMode)) {
74
+						// hPrefixMap contains @, o, +, v this caused issue 107
75
+						// hPrefixModes only contains o, v so if the mode is in hPrefixMap
76
+						// and not in hPrefixModes, its ok to use.
77
+						if (!myParser.hPrefixModes.containsKey(cMode)) {
78
+							sModes = sModes+cMode;
79
+							nPrefix = nPrefix + myParser.hPrefixModes.get(myParser.hPrefixMap.get(cMode));
80
+						}
81
+					} else {
82
+						sName = sNameBit.substring(i);
83
+						break;
84
+					}
85
+				}
86
+				callDebugInfo(myParser.ndInfo, "Name: %s Modes: \"%s\" [%d]",sName,sModes,nPrefix);
87
+				
88
+				iClient = getClientInfo(sName);
89
+				if (iClient == null) { iClient = new ClientInfo(myParser, sName); myParser.hClientList.put(iClient.getNickname().toLowerCase(),iClient); }
90
+				iChannelClient = iChannel.addClient(iClient);
91
+				iChannelClient.setChanMode(nPrefix);
92
+
93
+				sName = "";
94
+				sModes = "";
95
+				nPrefix = 0;
96
+			}
97
+		}
98
+	}
99
+	
100
+	/**
101
+	 * Callback to all objects implementing the ChannelGotNames Callback.
102
+	 *
103
+	 * @see IChannelGotNames
104
+	 * @param cChannel Channel which the names reply is for
105
+	 */
106
+	protected boolean callChannelGotNames(ChannelInfo cChannel) {
107
+		CallbackOnChannelGotNames cb = (CallbackOnChannelGotNames)getCallbackManager().getCallbackType("OnChannelGotNames");
108
+		if (cb != null) { return cb.call(cChannel); }
109
+		return false;
110
+	}
111
+	
112
+	/**
113
+	 * What does this IRCProcessor handle.
114
+	 *
115
+	 * @return String[] with the names of the tokens we handle.
116
+	 */
117
+	public String[] handles() {
118
+		String[] iHandle = new String[2];
119
+		iHandle[0] = "353";
120
+		iHandle[1] = "366";
121
+		return iHandle;
122
+	} 
123
+	
124
+	/**
125
+	 * Create a new instance of the IRCProcessor Object
126
+	 *
127
+	 * @param parser IRCParser That owns this IRCProcessor
128
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
129
+	 */
130
+	protected ProcessNames (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
131
+}

+ 113
- 0
src/uk/org/ownage/dmdirc/parser/ProcessNick.java Datei anzeigen

@@ -0,0 +1,113 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelNickChanged;
28
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnNickChanged;
29
+import java.util.Enumeration;
30
+
31
+/**
32
+ * Process a Nick change.
33
+ */
34
+public class ProcessNick extends IRCProcessor {
35
+	/**
36
+	 * Process a Nick change.
37
+	 *
38
+	 * @param type Type of line to process ("005", "PRIVMSG" etc)
39
+	 * @param tokens IRCTokenised line to process
40
+	 */
41
+	public void process(String sParam, String[] token) {
42
+		ClientInfo iClient;
43
+		ChannelClientInfo iChannelClient;
44
+		ChannelInfo iChannel;
45
+		
46
+		iClient = getClientInfo(token[0]);
47
+		if (iClient != null) {
48
+			// Remove the client from the known clients list
49
+			myParser.hClientList.remove(iClient.getNickname().toLowerCase());
50
+			// Change the nickame
51
+			iClient.setUserBits(token[2],true);
52
+			// Readd the client
53
+			myParser.hClientList.put(iClient.getNickname().toLowerCase(),iClient);
54
+			
55
+			for (Enumeration e = myParser.hChannelList.keys(); e.hasMoreElements();) {
56
+				iChannel = myParser.hChannelList.get(e.nextElement());
57
+				iChannelClient = iChannel.getUser(iClient);
58
+				if (iChannelClient != null) {
59
+					callChannelNickChanged(iChannel,iChannelClient,ClientInfo.parseHost(token[0]));
60
+				}
61
+			}
62
+			
63
+			callNickChanged(iClient, ClientInfo.parseHost(token[0]));
64
+		}
65
+		
66
+	}
67
+	
68
+	/**
69
+	 * Callback to all objects implementing the ChannelNickChanged Callback.
70
+	 *
71
+	 * @see IChannelNickChanged
72
+	 * @param cChannel One of the channels that the user is on
73
+	 * @param cChannelClient Client changing nickname
74
+	 * @param sOldNick Nickname before change
75
+	 */
76
+	protected boolean callChannelNickChanged(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sOldNick) {
77
+		CallbackOnChannelNickChanged cb = (CallbackOnChannelNickChanged)getCallbackManager().getCallbackType("OnChannelNickChanged");
78
+		if (cb != null) { return cb.call(cChannel, cChannelClient, sOldNick); }
79
+		return false;
80
+	}
81
+	
82
+	/**
83
+	 * Callback to all objects implementing the NickChanged Callback.
84
+	 *
85
+	 * @see INickChanged
86
+	 * @param cClient Client changing nickname
87
+	 * @param sOldNick Nickname before change
88
+	 */
89
+	protected boolean callNickChanged(ClientInfo cClient, String sOldNick) {
90
+		CallbackOnNickChanged cb = (CallbackOnNickChanged)getCallbackManager().getCallbackType("OnNickChanged");
91
+		if (cb != null) { return cb.call(cClient, sOldNick); }
92
+		return false;
93
+	}
94
+	
95
+	/**
96
+	 * What does this IRCProcessor handle.
97
+	 *
98
+	 * @return String[] with the names of the tokens we handle.
99
+	 */
100
+	public String[] handles() {
101
+		String[] iHandle = new String[1];
102
+		iHandle[0] = "NICK";
103
+		return iHandle;
104
+	} 
105
+	
106
+	/**
107
+	 * Create a new instance of the IRCProcessor Object
108
+	 *
109
+	 * @param parser IRCParser That owns this IRCProcessor
110
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
111
+	 */
112
+	protected ProcessNick (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
113
+}

+ 96
- 0
src/uk/org/ownage/dmdirc/parser/ProcessNickInUse.java Datei anzeigen

@@ -0,0 +1,96 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnNickInUse;
28
+
29
+/**
30
+ * Process a NickInUse message.
31
+ * Parser implements handling of this if Pre-001 and no other handler found,
32
+ * adding the NickInUse handler (addNickInUse) after 001 is prefered over before.<br><br>
33
+ * <br>
34
+ * If the first nickname is in use, and a NickInUse message is recieved before 001, we
35
+ * will attempt to use the altnickname instead.<br>
36
+ * If this also fails, we will start prepending _ (or the value of me.cPrepend) to the main nickname.
37
+ */
38
+public class ProcessNickInUse extends IRCProcessor {
39
+	/**
40
+	 * Process a NickInUse message.
41
+	 * Parser implements handling of this if Pre-001 and no other handler found,
42
+	 * adding the NickInUse handler (addNickInUse) after 001 is prefered over before.<br><br>
43
+	 * <br>
44
+	 * If the first nickname is in use, and a NickInUse message is recieved before 001, we
45
+	 * will attempt to use the altnickname instead.<br>
46
+	 * If this also fails, we will start prepending _ (or the value of me.cPrepend) to the main nickname.
47
+	 *
48
+	 * @param type Type of line to process ("005", "PRIVMSG" etc)
49
+	 * @param tokens IRCTokenised line to process
50
+	 */
51
+	public void process(String sParam, String[] token) {
52
+		if (!callNickInUse()) {
53
+			// Manually handle nick in use.
54
+			callDebugInfo(myParser.ndInfo,"No Nick in use Handler.");
55
+			if (!myParser.Got001) {
56
+				callDebugInfo(myParser.ndInfo,"Using inbuilt handler");
57
+				// If this is before 001 we will try and get a nickname, else we will leave the nick as-is
58
+				if (!myParser.TriedAlt) { myParser.setNickname(myParser.me.sAltNickname); myParser.TriedAlt = true; }
59
+				else {
60
+					if (myParser.sThinkNickname.equalsIgnoreCase(myParser.me.sAltNickname)) { myParser.sThinkNickname = myParser.me.sNickname; }
61
+					myParser.setNickname(myParser.me.cPrepend+myParser.sThinkNickname);
62
+				}
63
+			}
64
+		}
65
+	}
66
+	
67
+	/**
68
+	 * Callback to all objects implementing the NickInUse Callback.
69
+	 *
70
+	 * @see INickInUse
71
+	 */
72
+	protected boolean callNickInUse() {
73
+		CallbackOnNickInUse cb = (CallbackOnNickInUse)getCallbackManager().getCallbackType("OnNickInUse");
74
+		if (cb != null) { return cb.call(); }
75
+		return false;
76
+	}
77
+	
78
+	/**
79
+	 * What does this IRCProcessor handle.
80
+	 *
81
+	 * @return String[] with the names of the tokens we handle.
82
+	 */
83
+	public String[] handles() {
84
+		String[] iHandle = new String[1];
85
+		iHandle[0] = "433";
86
+		return iHandle;
87
+	} 
88
+	
89
+	/**
90
+	 * Create a new instance of the IRCProcessor Object
91
+	 *
92
+	 * @param parser IRCParser That owns this IRCProcessor
93
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
94
+	 */
95
+	protected ProcessNickInUse (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
96
+}

+ 73
- 0
src/uk/org/ownage/dmdirc/parser/ProcessNoticeAuth.java Datei anzeigen

@@ -0,0 +1,73 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnNoticeAuth;
28
+
29
+/**
30
+ * Process a NoticeAuth message.
31
+ */
32
+public class ProcessNoticeAuth extends IRCProcessor {
33
+	/**
34
+	 * Process a NoticeAuth message.
35
+	 *
36
+	 * @param type Type of line to process ("Notice Auth")
37
+	 * @param tokens IRCTokenised line to process
38
+	 */
39
+	public void process(String sParam, String[] token) {
40
+		callNoticeAuth(token[token.length-1]);
41
+	}
42
+	
43
+	/**
44
+	 * Callback to all objects implementing the NoticeAuth Callback.
45
+	 *
46
+	 * @see INoticeAuth
47
+	 * @param data Incomming Line.
48
+	 */
49
+	protected boolean callNoticeAuth(String data) {
50
+		CallbackOnNoticeAuth cb = (CallbackOnNoticeAuth)getCallbackManager().getCallbackType("OnNoticeAuth");
51
+		if (cb != null) { return cb.call(data); }
52
+		return false;
53
+	}
54
+	
55
+	/**
56
+	 * What does this IRCProcessor handle.
57
+	 *
58
+	 * @return String[] with the names of the tokens we handle.
59
+	 */
60
+	public String[] handles() {
61
+		String[] iHandle = new String[1];
62
+		iHandle[0] = "Notice Auth";
63
+		return iHandle;
64
+	} 
65
+	
66
+	/**
67
+	 * Create a new instance of the IRCProcessor Object
68
+	 *
69
+	 * @param parser IRCParser That owns this IRCProcessor
70
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
71
+	 */
72
+	protected ProcessNoticeAuth (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
73
+}

+ 110
- 0
src/uk/org/ownage/dmdirc/parser/ProcessPart.java Datei anzeigen

@@ -0,0 +1,110 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelPart;
28
+
29
+/**
30
+ * Process a channel part.
31
+ */
32
+public class ProcessPart extends IRCProcessor {
33
+	/**
34
+	 * Process a channel part.
35
+	 *
36
+	 * @param type Type of line to process ("005", "PRIVMSG" etc)
37
+	 * @param tokens IRCTokenised line to process
38
+	 */
39
+	public void process(String sParam, String[] token) {
40
+		// :nick!ident@host PART #Channel
41
+		// :nick!ident@host PART #Channel :reason
42
+		if (token.length < 3) { return; }
43
+		ClientInfo iClient;
44
+		ChannelInfo iChannel;
45
+		ChannelClientInfo iChannelClient;
46
+		
47
+		iClient = getClientInfo(token[0]);
48
+		iChannel = getChannelInfo(token[2]);
49
+		
50
+		if (iClient == null) { return; }
51
+		if (myParser.alwaysUpdateClient) {
52
+			// This may seem pointless - updating before they leave - but the formatter needs it!
53
+			if (iClient.getHost().equals("")) {iClient.setUserBits(token[0],false); }
54
+		}
55
+		if (iChannel == null) { 
56
+			if (iClient != myParser.cMyself) {
57
+				callErrorInfo(new ParserError(ParserError.errWarning, "Got part for channel ("+token[2]+") that I am not on. [User: "+token[0]+"]"));
58
+			}
59
+			return;
60
+		} else {
61
+			String sReason = "";
62
+			if (token.length > 3) { sReason = token[token.length-1]; }
63
+			iChannelClient = iChannel.getUser(iClient);
64
+			if (iChannelClient == null) {
65
+				callErrorInfo(new ParserError(ParserError.errWarning, "Got part for channel ("+token[2]+") for a non-existant user. [User: "+token[0]+"]"));
66
+				return;
67
+			}
68
+			callChannelPart(iChannel,iChannelClient,sReason);
69
+			callDebugInfo(myParser.ndInfo, "Removing %s from %s",iClient.getNickname(),iChannel.getName());
70
+			iChannel.delClient(iClient);
71
+			if (iClient == myParser.cMyself) {
72
+				iChannel.emptyChannel();
73
+				myParser.hChannelList.remove(iChannel.getName().toLowerCase());
74
+			} else { iClient.checkVisability(); }
75
+		}
76
+	}
77
+	
78
+	/**
79
+	 * Callback to all objects implementing the ChannelPart Callback.
80
+	 *
81
+	 * @see IChannelPart
82
+	 * @param cChannel Channel that the user parted
83
+	 * @param cChannelClient Client that parted
84
+	 * @param sReason Reason given for parting (May be "")
85
+	 */
86
+	protected boolean callChannelPart(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sReason) {
87
+		CallbackOnChannelPart cb = (CallbackOnChannelPart)getCallbackManager().getCallbackType("OnChannelPart");
88
+		if (cb != null) { return cb.call(cChannel, cChannelClient, sReason); }
89
+		return false;
90
+	}
91
+	
92
+	/**
93
+	 * What does this IRCProcessor handle.
94
+	 *
95
+	 * @return String[] with the names of the tokens we handle.
96
+	 */
97
+	public String[] handles() {
98
+		String[] iHandle = new String[1];
99
+		iHandle[0] = "PART";
100
+		return iHandle;
101
+	} 
102
+	
103
+	/**
104
+	 * Create a new instance of the IRCProcessor Object
105
+	 *
106
+	 * @param parser IRCParser That owns this IRCProcessor
107
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
108
+	 */
109
+	protected ProcessPart (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
110
+}

+ 126
- 0
src/uk/org/ownage/dmdirc/parser/ProcessQuit.java Datei anzeigen

@@ -0,0 +1,126 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelQuit;
28
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnQuit;
29
+import java.util.Enumeration;
30
+
31
+/**
32
+ * Process a Quit message.
33
+ */
34
+public class ProcessQuit extends IRCProcessor {
35
+	/**
36
+	 * Process a Quit message.
37
+	 *
38
+	 * @param type Type of line to process ("005", "PRIVMSG" etc)
39
+	 * @param tokens IRCTokenised line to process
40
+	 */
41
+	public void process(String sParam, String[] token) {
42
+		// :nick!ident@host QUIT
43
+		// :nick!ident@host QUIT :reason
44
+		if (token.length < 2) { return; }
45
+		ClientInfo iClient;
46
+		ChannelInfo iChannel;
47
+		ChannelClientInfo iChannelClient;
48
+		
49
+		iClient = getClientInfo(token[0]);
50
+		
51
+		if (iClient == null) { return; }
52
+		if (myParser.alwaysUpdateClient) {
53
+			// This may seem pointless - updating before they leave - but the formatter needs it!
54
+			if (iClient.getHost().equals("")) {iClient.setUserBits(token[0],false); }
55
+		}
56
+		String sReason = "";
57
+		if (token.length > 2) { sReason = token[token.length-1]; }
58
+		
59
+		for (Enumeration e = myParser.hChannelList.keys(); e.hasMoreElements();) {
60
+			iChannel = myParser.hChannelList.get(e.nextElement());
61
+			iChannelClient = iChannel.getUser(iClient);
62
+			if (iChannelClient != null) {
63
+				callChannelQuit(iChannel,iChannelClient,sReason);
64
+				if (iClient == myParser.cMyself) {
65
+					iChannel.emptyChannel();
66
+					myParser.hChannelList.remove(iChannel.getName().toLowerCase());
67
+				} else {
68
+					iChannel.delClient(iClient);
69
+				}
70
+			}
71
+		}
72
+
73
+		callQuit(iClient,sReason);
74
+		if (iClient == myParser.cMyself) {
75
+			myParser.hClientList.clear();
76
+		} else {
77
+			myParser.hClientList.remove(iClient.getNickname().toLowerCase());
78
+		}
79
+	}	
80
+	
81
+	/**
82
+	 * Callback to all objects implementing the ChannelQuit Callback.
83
+	 *
84
+	 * @see IChannelQuit
85
+	 * @param cChannel Channel that user was on
86
+	 * @param cChannelClient User thats quitting
87
+	 * @param sReason Quit reason
88
+	 */
89
+	protected boolean callChannelQuit(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sReason) {
90
+		CallbackOnChannelQuit cb = (CallbackOnChannelQuit)getCallbackManager().getCallbackType("OnChannelQuit");
91
+		if (cb != null) { return cb.call(cChannel, cChannelClient, sReason); }
92
+		return false;
93
+	}
94
+	
95
+	/**
96
+	 * Callback to all objects implementing the Quit Callback.
97
+	 *
98
+	 * @see IQuit
99
+	 * @param cClient Client Quitting
100
+	 * @param sReason Reason for quitting (may be "")
101
+	 */
102
+	protected boolean callQuit(ClientInfo cClient, String sReason) {
103
+		CallbackOnQuit cb = (CallbackOnQuit)getCallbackManager().getCallbackType("OnQuit");
104
+		if (cb != null) { return cb.call(cClient, sReason); }
105
+		return false;
106
+	}
107
+	
108
+	/**
109
+	 * What does this IRCProcessor handle.
110
+	 *
111
+	 * @return String[] with the names of the tokens we handle.
112
+	 */
113
+	public String[] handles() {
114
+		String[] iHandle = new String[1];
115
+		iHandle[0] = "QUIT";
116
+		return iHandle;
117
+	} 
118
+	
119
+	/**
120
+	 * Create a new instance of the IRCProcessor Object
121
+	 *
122
+	 * @param parser IRCParser That owns this IRCProcessor
123
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
124
+	 */
125
+	protected ProcessQuit (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
126
+}

+ 104
- 0
src/uk/org/ownage/dmdirc/parser/ProcessTopic.java Datei anzeigen

@@ -0,0 +1,104 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackOnChannelNotice.java 257 2007-03-02 23:08:30Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelTopic;
28
+
29
+import java.util.Calendar;
30
+
31
+/**
32
+ * Process a topic change.
33
+ */
34
+public class ProcessTopic extends IRCProcessor {
35
+	/**
36
+	 * Process a topic change.
37
+	 *
38
+	 * @param type Type of line to process ("005", "PRIVMSG" etc)
39
+	 * @param tokens IRCTokenised line to process
40
+	 */
41
+	public void process(String sParam, String[] token) {
42
+		ChannelInfo iChannel;
43
+		if (sParam.equals("332")) {
44
+			iChannel = getChannelInfo(token[3]);
45
+			if (iChannel == null) { return; };
46
+			iChannel.setTopic(token[token.length-1]);
47
+		} else if (sParam.equals("333")) {
48
+			iChannel = getChannelInfo(token[3]);
49
+			if (iChannel == null) { return; };
50
+			iChannel.setTopicTime(Long.parseLong(token[5]));
51
+			iChannel.setTopicUser(token[4]);
52
+			callChannelTopic(iChannel,true);
53
+		} else {
54
+			if (myParser.alwaysUpdateClient) {
55
+				ClientInfo iClient = getClientInfo(token[0]);
56
+				if (iClient != null) {
57
+					if (iClient.getHost().equals("")) {iClient.setUserBits(token[0],false); }
58
+				}
59
+			}
60
+			iChannel = getChannelInfo(token[2]);
61
+			if (iChannel == null) { return; };
62
+			iChannel.setTopicTime(Calendar.getInstance().getTimeInMillis() / 1000);
63
+			String sTemp[] = token[0].split(":",2);
64
+			if (sTemp.length > 1) { token[0] = sTemp[1]; }
65
+			iChannel.setTopicUser(token[0]);
66
+			iChannel.setTopic(token[token.length-1]);
67
+			callChannelTopic(iChannel,false);
68
+		}
69
+	}
70
+	
71
+	/**
72
+	 * Callback to all objects implementing the ChannelTopic Callback.
73
+	 *
74
+	 * @see IChannelTopic
75
+	 * @param cChannel Channel that topic was set on
76
+	 * @param bIsJoinTopic True when getting topic on join, false if set by user/server
77
+	 */
78
+	protected boolean callChannelTopic(ChannelInfo cChannel, boolean bIsJoinTopic) {
79
+		CallbackOnChannelTopic cb = (CallbackOnChannelTopic)getCallbackManager().getCallbackType("OnChannelTopic");
80
+		if (cb != null) { return cb.call(cChannel, bIsJoinTopic); }
81
+		return false;
82
+	}
83
+	
84
+	/**
85
+	 * What does this IRCProcessor handle.
86
+	 *
87
+	 * @return String[] with the names of the tokens we handle.
88
+	 */
89
+	public String[] handles() {
90
+		String[] iHandle = new String[3];
91
+		iHandle[0] = "TOPIC";
92
+		iHandle[1] = "332";
93
+		iHandle[2] = "333";
94
+		return iHandle;
95
+	} 
96
+	
97
+	/**
98
+	 * Create a new instance of the IRCProcessor Object
99
+	 *
100
+	 * @param parser IRCParser That owns this IRCProcessor
101
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
102
+	 */
103
+	protected ProcessTopic (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
104
+}

+ 194
- 0
src/uk/org/ownage/dmdirc/parser/ProcessingManager.java Datei anzeigen

@@ -0,0 +1,194 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: ProcessingManager.java 446 2007-03-06 16:46:38Z ShaneMcC $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+import java.util.Hashtable;
27
+import java.util.Enumeration;
28
+
29
+/**
30
+ * IRC Parser Processing Manager.
31
+ * Manages adding/removing/calling processing stuff.
32
+ *
33
+ * @author            Shane Mc Cormack
34
+ * @version           $Id: ProcessingManager.java 446 2007-03-06 16:46:38Z ShaneMcC $
35
+ */
36
+public class ProcessingManager {
37
+	/** Reference to the parser object that owns this ProcessingManager */
38
+	IRCParser myParser = null;
39
+	
40
+	/** Hashtable used to store the different types of IRCProcessor known. */
41
+	private Hashtable<String,IRCProcessor> processHash = new Hashtable<String,IRCProcessor>();
42
+
43
+	/**
44
+	 * Constructor to create a ProcessingManager
45
+	 *
46
+	 * @param parser IRCParser that owns this Processing Manager
47
+	 */
48
+	public ProcessingManager(IRCParser parser) {
49
+		myParser = parser;
50
+	}
51
+	
52
+	/**
53
+	 * Debugging Data to the console.
54
+	 */
55
+	private void DoDebug(String line, Object... args) {
56
+		myParser.callDebugInfo(myParser.ndProcessor, line, args);
57
+	}
58
+	
59
+	/**
60
+	 * Initialise the ProcessingManager with the default processors
61
+	 */
62
+	public void init() {
63
+		//------------------------------------------------
64
+		// Add processors
65
+		//------------------------------------------------
66
+		// NOTICE AUTH
67
+		addProcessor(new ProcessNoticeAuth(myParser, this));
68
+		// 001
69
+		addProcessor(new Process001(myParser, this));
70
+		// 004
71
+		// 005
72
+		addProcessor(new Process004005(myParser, this));
73
+		// 464
74
+		addProcessor(new Process464(myParser, this));
75
+		// 305
76
+		// 306
77
+		addProcessor(new ProcessAway(myParser, this));
78
+		// JOIN
79
+		addProcessor(new ProcessJoin(myParser, this));
80
+		// KICK
81
+		addProcessor(new ProcessKick(myParser, this));
82
+		// PRIVMSG
83
+		// NOTICE
84
+		addProcessor(new ProcessMessage(myParser, this));
85
+		// MODE
86
+		// 324
87
+		addProcessor(new ProcessMode(myParser, this));
88
+		// 372
89
+		// 375
90
+		// 376
91
+		// 422
92
+		addProcessor(new ProcessMOTD(myParser, this));
93
+		// 353
94
+		// 366
95
+		addProcessor(new ProcessNames(myParser, this));
96
+		// 433
97
+		addProcessor(new ProcessNickInUse(myParser, this));
98
+		// NICK
99
+		addProcessor(new ProcessNick(myParser, this));
100
+		// PART
101
+		addProcessor(new ProcessPart(myParser, this));
102
+		// QUIT
103
+		addProcessor(new ProcessQuit(myParser, this));
104
+		// TOPIC
105
+		// 332
106
+		// 333
107
+		addProcessor(new ProcessTopic(myParser, this));
108
+	}
109
+	
110
+	/**
111
+	 * Remove all processors
112
+	 */
113
+	public void empty() {
114
+		processHash.clear();
115
+	}
116
+	
117
+	/** Empty clone method to prevent cloning to get more copies of the ProcessingManager */
118
+	public Object clone() throws CloneNotSupportedException {
119
+		throw new CloneNotSupportedException();
120
+	}
121
+
122
+	/**
123
+	 * Add new Process type.
124
+	 *
125
+	 * @param processor IRCProcessor subclass for the processor.
126
+	 */
127
+	public void addProcessor(IRCProcessor processor) {	
128
+		// handles() returns a String array of all the tokens
129
+		// that this processor will parse.
130
+		DoDebug("Adding processor: "+processor.getName());
131
+		
132
+		try {
133
+			String[] handles = processor.handles();
134
+			for (int i = 0; i < handles.length; ++i) {
135
+				if (processHash.containsKey(handles[i].toLowerCase())) {
136
+					// New Processors take priority over old ones
137
+					processHash.remove(handles[i].toLowerCase());
138
+				}
139
+				DoDebug("\t Added handler for: "+handles[i]);
140
+				processHash.put(handles[i].toLowerCase(), processor);
141
+			}
142
+		} catch (Exception e) {
143
+			DoDebug("\t[ERROR] "+e.getMessage()+" - Removing processor");
144
+			delProcessor(processor);
145
+		}
146
+	}
147
+		
148
+	/**
149
+	 * Remove a Process type.
150
+	 *
151
+	 * @param processor IRCProcessor subclass for the processor.
152
+	 */
153
+	public void delProcessor(IRCProcessor processor) {	
154
+		IRCProcessor testProcessor;
155
+		String elementName;
156
+		DoDebug("Deleting processor: "+processor.getName());
157
+		for (Enumeration e = processHash.keys(); e.hasMoreElements();) {
158
+			elementName = (String)e.nextElement();
159
+			DoDebug("\t Checking handler for: "+elementName);
160
+			testProcessor = processHash.get(elementName);
161
+			if (testProcessor.getName().equalsIgnoreCase(processor.getName())) {
162
+				DoDebug("\t Removed handler for: "+elementName);
163
+				processHash.remove(elementName);
164
+			}
165
+		}
166
+	}
167
+	
168
+	/**
169
+	 * Process a Line.
170
+	 *
171
+	 * @param sParam Type of line to process ("005", "PRIVMSG" etc)
172
+	 * @param token IRCTokenised line to process
173
+	 * @throws ProcessorNotFound exception if no processors exists to handle the line
174
+	 */
175
+	public void process(String sParam, String[] token) throws ProcessorNotFound {
176
+		IRCProcessor messageProcessor = null;
177
+		try {
178
+			if (processHash.containsKey(sParam.toLowerCase())) {
179
+				messageProcessor = processHash.get(sParam.toLowerCase());
180
+				messageProcessor.process(sParam, token);
181
+			} else {
182
+				throw new ProcessorNotFound("No processors will handle "+sParam);
183
+			}
184
+		} catch (Exception e) {
185
+			String line = "";
186
+			for (int i = 0; i < token.length; ++i ) { line = line+" "+token[i]; }
187
+			line = line.trim();
188
+			ParserError ei = new ParserError(ParserError.errFatal,"Exception in Parser. [Param: "+sParam+"] [Processor: "+messageProcessor+"] [Line: "+line+"]");
189
+			ei.setException(e);
190
+			myParser.callErrorInfo(ei);
191
+		}
192
+	}
193
+		
194
+}

+ 47
- 0
src/uk/org/ownage/dmdirc/parser/ProcessorNotFound.java Datei anzeigen

@@ -0,0 +1,47 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: CallbackNotFound.java 298 2007-03-03 14:52:33Z chris87 $
23
+ */
24
+
25
+package uk.org.ownage.dmdirc.parser;
26
+
27
+/**
28
+ * IRC Parser Processor Not Found Exception.
29
+ *
30
+ * @author            Shane Mc Cormack
31
+ * @version           $Id: CallbackNotFound.java 298 2007-03-03 14:52:33Z chris87 $
32
+ */
33
+public class ProcessorNotFound extends Exception {
34
+	/**
35
+	 * A version number for this class. It should be changed whenever the class
36
+	 * structure is changed (or anything else that would prevent serialized
37
+	 * objects being unserialized with the new class).
38
+	 */
39
+	private static final long serialVersionUID = 1;
40
+	
41
+	/**
42
+	 * Create a new ProcessorNotFound Exception.
43
+	 *
44
+	 * @param message Reason for exception
45
+	 */
46
+	public ProcessorNotFound(String message) { super(message); }
47
+}

+ 0
- 1
src/uk/org/ownage/dmdirc/parser/callbacks/CallbackOnErrorInfo.java Datei anzeigen

@@ -36,7 +36,6 @@ public class CallbackOnErrorInfo extends CallbackObject {
36 36
 	 * @param errorInfo ParserError object representing the error.
37 37
 	 */
38 38
 	public boolean call(ParserError errorInfo) {
39
-		if (IRCParser.bDebug) { myParser.doDebug("[ERROR] {%d} %s\n", errorInfo.getLevel(), errorInfo.getData()); }
40 39
 		boolean bResult = false;
41 40
 		for (int i = 0; i < callbackInfo.size(); i++) {
42 41
 			try {

Laden…
Abbrechen
Speichern