Browse Source

Initial import

master
Chris Smith 15 years ago
commit
f4d1d05aaa
100 changed files with 12003 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 74
    0
      build.xml
  3. 3
    0
      manifest.mf
  4. 642
    0
      nbproject/build-impl.xml
  5. 8
    0
      nbproject/genfiles.properties
  6. 61
    0
      nbproject/project.properties
  7. 16
    0
      nbproject/project.xml
  8. 24
    0
      src/com/dmdirc/addons/calc/Evaluator.java
  9. 62
    0
      src/com/dmdirc/addons/calc/Lexer.java
  10. 153
    0
      src/com/dmdirc/addons/calc/Parser.java
  11. 35
    0
      src/com/dmdirc/addons/calc/Token.java
  12. 148
    0
      src/com/dmdirc/addons/calc/TokenType.java
  13. 19
    0
      src/com/dmdirc/addons/calc/TokenTypeArity.java
  14. 57
    0
      src/com/dmdirc/addons/calc/TreeToken.java
  15. 209
    0
      src/com/dmdirc/parser/irc/ChannelClientInfo.java
  16. 778
    0
      src/com/dmdirc/parser/irc/ChannelInfo.java
  17. 93
    0
      src/com/dmdirc/parser/irc/ChannelListModeItem.java
  18. 427
    0
      src/com/dmdirc/parser/irc/ClientInfo.java
  19. 128
    0
      src/com/dmdirc/parser/irc/IRCAuthenticator.java
  20. 2065
    0
      src/com/dmdirc/parser/irc/IRCParser.java
  21. 179
    0
      src/com/dmdirc/parser/irc/IRCProcessor.java
  22. 142
    0
      src/com/dmdirc/parser/irc/IRCStringConverter.java
  23. 163
    0
      src/com/dmdirc/parser/irc/Logging.java
  24. 158
    0
      src/com/dmdirc/parser/irc/MyInfo.java
  25. 177
    0
      src/com/dmdirc/parser/irc/ParserError.java
  26. 55
    0
      src/com/dmdirc/parser/irc/PingTimer.java
  27. 108
    0
      src/com/dmdirc/parser/irc/Process001.java
  28. 141
    0
      src/com/dmdirc/parser/irc/Process004005.java
  29. 70
    0
      src/com/dmdirc/parser/irc/Process464.java
  30. 76
    0
      src/com/dmdirc/parser/irc/ProcessAway.java
  31. 73
    0
      src/com/dmdirc/parser/irc/ProcessInvite.java
  32. 141
    0
      src/com/dmdirc/parser/irc/ProcessJoin.java
  33. 112
    0
      src/com/dmdirc/parser/irc/ProcessKick.java
  34. 220
    0
      src/com/dmdirc/parser/irc/ProcessListModes.java
  35. 103
    0
      src/com/dmdirc/parser/irc/ProcessMOTD.java
  36. 419
    0
      src/com/dmdirc/parser/irc/ProcessMessage.java
  37. 337
    0
      src/com/dmdirc/parser/irc/ProcessMode.java
  38. 130
    0
      src/com/dmdirc/parser/irc/ProcessNames.java
  39. 124
    0
      src/com/dmdirc/parser/irc/ProcessNick.java
  40. 97
    0
      src/com/dmdirc/parser/irc/ProcessNickInUse.java
  41. 69
    0
      src/com/dmdirc/parser/irc/ProcessNoticeAuth.java
  42. 108
    0
      src/com/dmdirc/parser/irc/ProcessPart.java
  43. 123
    0
      src/com/dmdirc/parser/irc/ProcessQuit.java
  44. 99
    0
      src/com/dmdirc/parser/irc/ProcessTopic.java
  45. 111
    0
      src/com/dmdirc/parser/irc/ProcessWallops.java
  46. 137
    0
      src/com/dmdirc/parser/irc/ProcessWho.java
  47. 220
    0
      src/com/dmdirc/parser/irc/ProcessingManager.java
  48. 45
    0
      src/com/dmdirc/parser/irc/ProcessorNotFoundException.java
  49. 166
    0
      src/com/dmdirc/parser/irc/RegexStringList.java
  50. 201
    0
      src/com/dmdirc/parser/irc/ServerInfo.java
  51. 40
    0
      src/com/dmdirc/parser/irc/SocketState.java
  52. 226
    0
      src/com/dmdirc/parser/irc/callbacks/CallbackManager.java
  53. 45
    0
      src/com/dmdirc/parser/irc/callbacks/CallbackNotFoundException.java
  54. 268
    0
      src/com/dmdirc/parser/irc/callbacks/CallbackObject.java
  55. 168
    0
      src/com/dmdirc/parser/irc/callbacks/CallbackObjectSpecific.java
  56. 40
    0
      src/com/dmdirc/parser/irc/callbacks/FakableArgument.java
  57. 41
    0
      src/com/dmdirc/parser/irc/callbacks/FakableSource.java
  58. 38
    0
      src/com/dmdirc/parser/irc/callbacks/SpecificCallback.java
  59. 40
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IAwayState.java
  60. 43
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IAwayStateOther.java
  61. 28
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/ICallbackInterface.java
  62. 57
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelAction.java
  63. 45
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelAwayStateOther.java
  64. 57
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelCTCP.java
  65. 57
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelCTCPReply.java
  66. 44
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelGotListModes.java
  67. 42
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelGotNames.java
  68. 46
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelJoin.java
  69. 56
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelKick.java
  70. 56
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelMessage.java
  71. 56
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelModeChanged.java
  72. 47
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelNickChanged.java
  73. 56
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelNonUserModeChanged.java
  74. 56
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelNotice.java
  75. 47
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelPart.java
  76. 47
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelQuit.java
  77. 42
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelSelfJoin.java
  78. 56
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelSingleModeChanged.java
  79. 45
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelTopic.java
  80. 56
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelUserModeChanged.java
  81. 40
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IConnectError.java
  82. 39
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IDataIn.java
  83. 40
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IDataOut.java
  84. 40
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IDebugInfo.java
  85. 40
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IErrorInfo.java
  86. 42
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IGotNetwork.java
  87. 40
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IInvite.java
  88. 40
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IMOTDEnd.java
  89. 39
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IMOTDLine.java
  90. 39
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IMOTDStart.java
  91. 43
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/INickChanged.java
  92. 39
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/INickInUse.java
  93. 39
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/INoticeAuth.java
  94. 40
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/INumeric.java
  95. 38
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IPasswordRequired.java
  96. 38
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IPingFailed.java
  97. 38
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IPingSent.java
  98. 38
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IPingSuccess.java
  99. 38
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IPost005.java
  100. 0
    0
      src/com/dmdirc/parser/irc/callbacks/interfaces/IPrivateAction.java

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
1
+/build/
2
+/nbproject/private

+ 74
- 0
build.xml View File

@@ -0,0 +1,74 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!-- You may freely edit this file. See commented blocks below for -->
3
+<!-- some examples of how to customize the build. -->
4
+<!-- (If you delete it and reopen the project it will be recreated.) -->
5
+<!-- By default, only the Clean and Build commands use this build script. -->
6
+<!-- Commands such as Run, Debug, and Test only use this build script if -->
7
+<!-- the Compile on Save feature is turned off for the project. -->
8
+<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
9
+<!-- in the project's Project Properties dialog box.-->
10
+<project name="charliebravo" default="default" basedir=".">
11
+    <description>Builds, tests, and runs the project charliebravo.</description>
12
+    <import file="nbproject/build-impl.xml"/>
13
+    <!--
14
+
15
+    There exist several targets which are by default empty and which can be 
16
+    used for execution of your tasks. These targets are usually executed 
17
+    before and after some main targets. They are: 
18
+
19
+      -pre-init:                 called before initialization of project properties
20
+      -post-init:                called after initialization of project properties
21
+      -pre-compile:              called before javac compilation
22
+      -post-compile:             called after javac compilation
23
+      -pre-compile-single:       called before javac compilation of single file
24
+      -post-compile-single:      called after javac compilation of single file
25
+      -pre-compile-test:         called before javac compilation of JUnit tests
26
+      -post-compile-test:        called after javac compilation of JUnit tests
27
+      -pre-compile-test-single:  called before javac compilation of single JUnit test
28
+      -post-compile-test-single: called after javac compilation of single JUunit test
29
+      -pre-jar:                  called before JAR building
30
+      -post-jar:                 called after JAR building
31
+      -post-clean:               called after cleaning build products
32
+
33
+    (Targets beginning with '-' are not intended to be called on their own.)
34
+
35
+    Example of inserting an obfuscator after compilation could look like this:
36
+
37
+        <target name="-post-compile">
38
+            <obfuscate>
39
+                <fileset dir="${build.classes.dir}"/>
40
+            </obfuscate>
41
+        </target>
42
+
43
+    For list of available properties check the imported 
44
+    nbproject/build-impl.xml file. 
45
+
46
+
47
+    Another way to customize the build is by overriding existing main targets.
48
+    The targets of interest are: 
49
+
50
+      -init-macrodef-javac:     defines macro for javac compilation
51
+      -init-macrodef-junit:     defines macro for junit execution
52
+      -init-macrodef-debug:     defines macro for class debugging
53
+      -init-macrodef-java:      defines macro for class execution
54
+      -do-jar-with-manifest:    JAR building (if you are using a manifest)
55
+      -do-jar-without-manifest: JAR building (if you are not using a manifest)
56
+      run:                      execution of project 
57
+      -javadoc-build:           Javadoc generation
58
+      test-report:              JUnit report generation
59
+
60
+    An example of overriding the target for project execution could look like this:
61
+
62
+        <target name="run" depends="charliebravo-impl.jar">
63
+            <exec dir="bin" executable="launcher.exe">
64
+                <arg file="${dist.jar}"/>
65
+            </exec>
66
+        </target>
67
+
68
+    Notice that the overridden target depends on the jar target and not only on 
69
+    the compile target as the regular run target does. Again, for a list of available 
70
+    properties which you can use, check the target you are overriding in the
71
+    nbproject/build-impl.xml file. 
72
+
73
+    -->
74
+</project>

+ 3
- 0
manifest.mf View File

@@ -0,0 +1,3 @@
1
+Manifest-Version: 1.0
2
+X-COMMENT: Main-Class will be added automatically by build
3
+

+ 642
- 0
nbproject/build-impl.xml View File

@@ -0,0 +1,642 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!--
3
+*** GENERATED FROM project.xml - DO NOT EDIT  ***
4
+***         EDIT ../build.xml INSTEAD         ***
5
+
6
+For the purpose of easier reading the script
7
+is divided into following sections:
8
+
9
+  - initialization
10
+  - compilation
11
+  - jar
12
+  - execution
13
+  - debugging
14
+  - javadoc
15
+  - junit compilation
16
+  - junit execution
17
+  - junit debugging
18
+  - applet
19
+  - cleanup
20
+
21
+        -->
22
+<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="charliebravo-impl">
23
+    <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
24
+    <!-- 
25
+                ======================
26
+                INITIALIZATION SECTION 
27
+                ======================
28
+            -->
29
+    <target name="-pre-init">
30
+        <!-- Empty placeholder for easier customization. -->
31
+        <!-- You can override this target in the ../build.xml file. -->
32
+    </target>
33
+    <target depends="-pre-init" name="-init-private">
34
+        <property file="nbproject/private/config.properties"/>
35
+        <property file="nbproject/private/configs/${config}.properties"/>
36
+        <property file="nbproject/private/private.properties"/>
37
+    </target>
38
+    <target depends="-pre-init,-init-private" name="-init-user">
39
+        <property file="${user.properties.file}"/>
40
+        <!-- The two properties below are usually overridden -->
41
+        <!-- by the active platform. Just a fallback. -->
42
+        <property name="default.javac.source" value="1.4"/>
43
+        <property name="default.javac.target" value="1.4"/>
44
+    </target>
45
+    <target depends="-pre-init,-init-private,-init-user" name="-init-project">
46
+        <property file="nbproject/configs/${config}.properties"/>
47
+        <property file="nbproject/project.properties"/>
48
+    </target>
49
+    <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
50
+        <available file="${manifest.file}" property="manifest.available"/>
51
+        <condition property="manifest.available+main.class">
52
+            <and>
53
+                <isset property="manifest.available"/>
54
+                <isset property="main.class"/>
55
+                <not>
56
+                    <equals arg1="${main.class}" arg2="" trim="true"/>
57
+                </not>
58
+            </and>
59
+        </condition>
60
+        <condition property="manifest.available+main.class+mkdist.available">
61
+            <and>
62
+                <istrue value="${manifest.available+main.class}"/>
63
+                <isset property="libs.CopyLibs.classpath"/>
64
+            </and>
65
+        </condition>
66
+        <condition property="have.tests">
67
+            <or>
68
+                <available file="${test.src.dir}"/>
69
+            </or>
70
+        </condition>
71
+        <condition property="have.sources">
72
+            <or>
73
+                <available file="${src.dir}"/>
74
+            </or>
75
+        </condition>
76
+        <condition property="netbeans.home+have.tests">
77
+            <and>
78
+                <isset property="netbeans.home"/>
79
+                <isset property="have.tests"/>
80
+            </and>
81
+        </condition>
82
+        <condition property="no.javadoc.preview">
83
+            <and>
84
+                <isset property="javadoc.preview"/>
85
+                <isfalse value="${javadoc.preview}"/>
86
+            </and>
87
+        </condition>
88
+        <property name="run.jvmargs" value=""/>
89
+        <property name="javac.compilerargs" value=""/>
90
+        <property name="work.dir" value="${basedir}"/>
91
+        <condition property="no.deps">
92
+            <and>
93
+                <istrue value="${no.dependencies}"/>
94
+            </and>
95
+        </condition>
96
+        <property name="javac.debug" value="true"/>
97
+        <property name="javadoc.preview" value="true"/>
98
+        <property name="application.args" value=""/>
99
+        <property name="source.encoding" value="${file.encoding}"/>
100
+        <condition property="javadoc.encoding.used" value="${javadoc.encoding}">
101
+            <and>
102
+                <isset property="javadoc.encoding"/>
103
+                <not>
104
+                    <equals arg1="${javadoc.encoding}" arg2=""/>
105
+                </not>
106
+            </and>
107
+        </condition>
108
+        <property name="javadoc.encoding.used" value="${source.encoding}"/>
109
+        <property name="includes" value="**"/>
110
+        <property name="excludes" value=""/>
111
+        <property name="do.depend" value="false"/>
112
+        <condition property="do.depend.true">
113
+            <istrue value="${do.depend}"/>
114
+        </condition>
115
+        <condition else="" property="javac.compilerargs.jaxws" value="-Djava.endorsed.dirs='${jaxws.endorsed.dir}'">
116
+            <and>
117
+                <isset property="jaxws.endorsed.dir"/>
118
+                <available file="nbproject/jaxws-build.xml"/>
119
+            </and>
120
+        </condition>
121
+    </target>
122
+    <target name="-post-init">
123
+        <!-- Empty placeholder for easier customization. -->
124
+        <!-- You can override this target in the ../build.xml file. -->
125
+    </target>
126
+    <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
127
+        <fail unless="src.dir">Must set src.dir</fail>
128
+        <fail unless="test.src.dir">Must set test.src.dir</fail>
129
+        <fail unless="build.dir">Must set build.dir</fail>
130
+        <fail unless="dist.dir">Must set dist.dir</fail>
131
+        <fail unless="build.classes.dir">Must set build.classes.dir</fail>
132
+        <fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
133
+        <fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
134
+        <fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
135
+        <fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
136
+        <fail unless="dist.jar">Must set dist.jar</fail>
137
+    </target>
138
+    <target name="-init-macrodef-property">
139
+        <macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
140
+            <attribute name="name"/>
141
+            <attribute name="value"/>
142
+            <sequential>
143
+                <property name="@{name}" value="${@{value}}"/>
144
+            </sequential>
145
+        </macrodef>
146
+    </target>
147
+    <target name="-init-macrodef-javac">
148
+        <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
149
+            <attribute default="${src.dir}" name="srcdir"/>
150
+            <attribute default="${build.classes.dir}" name="destdir"/>
151
+            <attribute default="${javac.classpath}" name="classpath"/>
152
+            <attribute default="${includes}" name="includes"/>
153
+            <attribute default="${excludes}" name="excludes"/>
154
+            <attribute default="${javac.debug}" name="debug"/>
155
+            <attribute default="/does/not/exist" name="sourcepath"/>
156
+            <element name="customize" optional="true"/>
157
+            <sequential>
158
+                <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}">
159
+                    <classpath>
160
+                        <path path="@{classpath}"/>
161
+                    </classpath>
162
+                    <compilerarg line="${javac.compilerargs} ${javac.compilerargs.jaxws}"/>
163
+                    <customize/>
164
+                </javac>
165
+            </sequential>
166
+        </macrodef>
167
+        <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
168
+            <attribute default="${src.dir}" name="srcdir"/>
169
+            <attribute default="${build.classes.dir}" name="destdir"/>
170
+            <attribute default="${javac.classpath}" name="classpath"/>
171
+            <sequential>
172
+                <depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}">
173
+                    <classpath>
174
+                        <path path="@{classpath}"/>
175
+                    </classpath>
176
+                </depend>
177
+            </sequential>
178
+        </macrodef>
179
+        <macrodef name="force-recompile" uri="http://www.netbeans.org/ns/j2se-project/3">
180
+            <attribute default="${build.classes.dir}" name="destdir"/>
181
+            <sequential>
182
+                <fail unless="javac.includes">Must set javac.includes</fail>
183
+                <pathconvert pathsep="," property="javac.includes.binary">
184
+                    <path>
185
+                        <filelist dir="@{destdir}" files="${javac.includes}"/>
186
+                    </path>
187
+                    <globmapper from="*.java" to="*.class"/>
188
+                </pathconvert>
189
+                <delete>
190
+                    <files includes="${javac.includes.binary}"/>
191
+                </delete>
192
+            </sequential>
193
+        </macrodef>
194
+    </target>
195
+    <target name="-init-macrodef-junit">
196
+        <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
197
+            <attribute default="${includes}" name="includes"/>
198
+            <attribute default="${excludes}" name="excludes"/>
199
+            <attribute default="**" name="testincludes"/>
200
+            <sequential>
201
+                <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true">
202
+                    <batchtest todir="${build.test.results.dir}">
203
+                        <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
204
+                            <filename name="@{testincludes}"/>
205
+                        </fileset>
206
+                    </batchtest>
207
+                    <classpath>
208
+                        <path path="${run.test.classpath}"/>
209
+                    </classpath>
210
+                    <syspropertyset>
211
+                        <propertyref prefix="test-sys-prop."/>
212
+                        <mapper from="test-sys-prop.*" to="*" type="glob"/>
213
+                    </syspropertyset>
214
+                    <formatter type="brief" usefile="false"/>
215
+                    <formatter type="xml"/>
216
+                    <jvmarg line="${run.jvmargs}"/>
217
+                </junit>
218
+            </sequential>
219
+        </macrodef>
220
+    </target>
221
+    <target depends="-init-debug-args" name="-init-macrodef-nbjpda">
222
+        <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
223
+            <attribute default="${main.class}" name="name"/>
224
+            <attribute default="${debug.classpath}" name="classpath"/>
225
+            <attribute default="" name="stopclassname"/>
226
+            <sequential>
227
+                <nbjpdastart addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}" transport="${debug-transport}">
228
+                    <classpath>
229
+                        <path path="@{classpath}"/>
230
+                    </classpath>
231
+                </nbjpdastart>
232
+            </sequential>
233
+        </macrodef>
234
+        <macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
235
+            <attribute default="${build.classes.dir}" name="dir"/>
236
+            <sequential>
237
+                <nbjpdareload>
238
+                    <fileset dir="@{dir}" includes="${fix.classes}">
239
+                        <include name="${fix.includes}*.class"/>
240
+                    </fileset>
241
+                </nbjpdareload>
242
+            </sequential>
243
+        </macrodef>
244
+    </target>
245
+    <target name="-init-debug-args">
246
+        <property name="version-output" value="java version &quot;${ant.java.version}"/>
247
+        <condition property="have-jdk-older-than-1.4">
248
+            <or>
249
+                <contains string="${version-output}" substring="java version &quot;1.0"/>
250
+                <contains string="${version-output}" substring="java version &quot;1.1"/>
251
+                <contains string="${version-output}" substring="java version &quot;1.2"/>
252
+                <contains string="${version-output}" substring="java version &quot;1.3"/>
253
+            </or>
254
+        </condition>
255
+        <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
256
+            <istrue value="${have-jdk-older-than-1.4}"/>
257
+        </condition>
258
+        <condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem">
259
+            <os family="windows"/>
260
+        </condition>
261
+        <condition else="${debug-transport-by-os}" property="debug-transport" value="${debug.transport}">
262
+            <isset property="debug.transport"/>
263
+        </condition>
264
+    </target>
265
+    <target depends="-init-debug-args" name="-init-macrodef-debug">
266
+        <macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
267
+            <attribute default="${main.class}" name="classname"/>
268
+            <attribute default="${debug.classpath}" name="classpath"/>
269
+            <element name="customize" optional="true"/>
270
+            <sequential>
271
+                <java classname="@{classname}" dir="${work.dir}" fork="true">
272
+                    <jvmarg line="${debug-args-line}"/>
273
+                    <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
274
+                    <jvmarg line="${run.jvmargs}"/>
275
+                    <classpath>
276
+                        <path path="@{classpath}"/>
277
+                    </classpath>
278
+                    <syspropertyset>
279
+                        <propertyref prefix="run-sys-prop."/>
280
+                        <mapper from="run-sys-prop.*" to="*" type="glob"/>
281
+                    </syspropertyset>
282
+                    <customize/>
283
+                </java>
284
+            </sequential>
285
+        </macrodef>
286
+    </target>
287
+    <target name="-init-macrodef-java">
288
+        <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
289
+            <attribute default="${main.class}" name="classname"/>
290
+            <element name="customize" optional="true"/>
291
+            <sequential>
292
+                <java classname="@{classname}" dir="${work.dir}" fork="true">
293
+                    <jvmarg line="${run.jvmargs}"/>
294
+                    <classpath>
295
+                        <path path="${run.classpath}"/>
296
+                    </classpath>
297
+                    <syspropertyset>
298
+                        <propertyref prefix="run-sys-prop."/>
299
+                        <mapper from="run-sys-prop.*" to="*" type="glob"/>
300
+                    </syspropertyset>
301
+                    <customize/>
302
+                </java>
303
+            </sequential>
304
+        </macrodef>
305
+    </target>
306
+    <target name="-init-presetdef-jar">
307
+        <presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
308
+            <jar compress="${jar.compress}" jarfile="${dist.jar}">
309
+                <j2seproject1:fileset dir="${build.classes.dir}"/>
310
+            </jar>
311
+        </presetdef>
312
+    </target>
313
+    <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar" name="init"/>
314
+    <!--
315
+                ===================
316
+                COMPILATION SECTION
317
+                ===================
318
+            -->
319
+    <target depends="init" name="deps-jar" unless="no.deps"/>
320
+    <target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
321
+    <target depends="init" name="-check-automatic-build">
322
+        <available file="${build.classes.dir}/.netbeans_automatic_build" property="netbeans.automatic.build"/>
323
+    </target>
324
+    <target depends="init" if="netbeans.automatic.build" name="-clean-after-automatic-build">
325
+        <antcall target="clean"/>
326
+    </target>
327
+    <target depends="init,deps-jar" name="-pre-pre-compile">
328
+        <mkdir dir="${build.classes.dir}"/>
329
+    </target>
330
+    <target name="-pre-compile">
331
+        <!-- Empty placeholder for easier customization. -->
332
+        <!-- You can override this target in the ../build.xml file. -->
333
+    </target>
334
+    <target if="do.depend.true" name="-compile-depend">
335
+        <j2seproject3:depend/>
336
+    </target>
337
+    <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-compile-depend" if="have.sources" name="-do-compile">
338
+        <j2seproject3:javac/>
339
+        <copy todir="${build.classes.dir}">
340
+            <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
341
+        </copy>
342
+    </target>
343
+    <target name="-post-compile">
344
+        <!-- Empty placeholder for easier customization. -->
345
+        <!-- You can override this target in the ../build.xml file. -->
346
+    </target>
347
+    <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/>
348
+    <target name="-pre-compile-single">
349
+        <!-- Empty placeholder for easier customization. -->
350
+        <!-- You can override this target in the ../build.xml file. -->
351
+    </target>
352
+    <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
353
+        <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
354
+        <j2seproject3:force-recompile/>
355
+        <j2seproject3:javac excludes="" includes="${javac.includes}" sourcepath="${src.dir}"/>
356
+    </target>
357
+    <target name="-post-compile-single">
358
+        <!-- Empty placeholder for easier customization. -->
359
+        <!-- You can override this target in the ../build.xml file. -->
360
+    </target>
361
+    <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
362
+    <!--
363
+                ====================
364
+                JAR BUILDING SECTION
365
+                ====================
366
+            -->
367
+    <target depends="init" name="-pre-pre-jar">
368
+        <dirname file="${dist.jar}" property="dist.jar.dir"/>
369
+        <mkdir dir="${dist.jar.dir}"/>
370
+    </target>
371
+    <target name="-pre-jar">
372
+        <!-- Empty placeholder for easier customization. -->
373
+        <!-- You can override this target in the ../build.xml file. -->
374
+    </target>
375
+    <target depends="init,compile,-pre-pre-jar,-pre-jar" name="-do-jar-without-manifest" unless="manifest.available">
376
+        <j2seproject1:jar/>
377
+    </target>
378
+    <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class">
379
+        <j2seproject1:jar manifest="${manifest.file}"/>
380
+    </target>
381
+    <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available">
382
+        <j2seproject1:jar manifest="${manifest.file}">
383
+            <j2seproject1:manifest>
384
+                <j2seproject1:attribute name="Main-Class" value="${main.class}"/>
385
+            </j2seproject1:manifest>
386
+        </j2seproject1:jar>
387
+        <echo>To run this application from the command line without Ant, try:</echo>
388
+        <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
389
+        <property location="${dist.jar}" name="dist.jar.resolved"/>
390
+        <pathconvert property="run.classpath.with.dist.jar">
391
+            <path path="${run.classpath}"/>
392
+            <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
393
+        </pathconvert>
394
+        <echo>java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
395
+    </target>
396
+    <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class+mkdist.available" name="-do-jar-with-libraries">
397
+        <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
398
+        <pathconvert property="run.classpath.without.build.classes.dir">
399
+            <path path="${run.classpath}"/>
400
+            <map from="${build.classes.dir.resolved}" to=""/>
401
+        </pathconvert>
402
+        <pathconvert pathsep=" " property="jar.classpath">
403
+            <path path="${run.classpath.without.build.classes.dir}"/>
404
+            <chainedmapper>
405
+                <flattenmapper/>
406
+                <globmapper from="*" to="lib/*"/>
407
+            </chainedmapper>
408
+        </pathconvert>
409
+        <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
410
+        <copylibs compress="${jar.compress}" jarfile="${dist.jar}" manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
411
+            <fileset dir="${build.classes.dir}"/>
412
+            <manifest>
413
+                <attribute name="Main-Class" value="${main.class}"/>
414
+                <attribute name="Class-Path" value="${jar.classpath}"/>
415
+            </manifest>
416
+        </copylibs>
417
+        <echo>To run this application from the command line without Ant, try:</echo>
418
+        <property location="${dist.jar}" name="dist.jar.resolved"/>
419
+        <echo>java -jar "${dist.jar.resolved}"</echo>
420
+    </target>
421
+    <target name="-post-jar">
422
+        <!-- Empty placeholder for easier customization. -->
423
+        <!-- You can override this target in the ../build.xml file. -->
424
+    </target>
425
+    <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
426
+    <!--
427
+                =================
428
+                EXECUTION SECTION
429
+                =================
430
+            -->
431
+    <target depends="init,compile" description="Run a main class." name="run">
432
+        <j2seproject1:java>
433
+            <customize>
434
+                <arg line="${application.args}"/>
435
+            </customize>
436
+        </j2seproject1:java>
437
+    </target>
438
+    <target name="-do-not-recompile">
439
+        <property name="javac.includes.binary" value=""/>
440
+    </target>
441
+    <target depends="init,-do-not-recompile,compile-single" name="run-single">
442
+        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
443
+        <j2seproject1:java classname="${run.class}"/>
444
+    </target>
445
+    <!--
446
+                =================
447
+                DEBUGGING SECTION
448
+                =================
449
+            -->
450
+    <target depends="init" if="netbeans.home" name="-debug-start-debugger">
451
+        <j2seproject1:nbjpdastart name="${debug.class}"/>
452
+    </target>
453
+    <target depends="init,compile" name="-debug-start-debuggee">
454
+        <j2seproject3:debug>
455
+            <customize>
456
+                <arg line="${application.args}"/>
457
+            </customize>
458
+        </j2seproject3:debug>
459
+    </target>
460
+    <target depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE." if="netbeans.home" name="debug"/>
461
+    <target depends="init" if="netbeans.home" name="-debug-start-debugger-stepinto">
462
+        <j2seproject1:nbjpdastart stopclassname="${main.class}"/>
463
+    </target>
464
+    <target depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee" if="netbeans.home" name="debug-stepinto"/>
465
+    <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-single">
466
+        <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
467
+        <j2seproject3:debug classname="${debug.class}"/>
468
+    </target>
469
+    <target depends="init,-do-not-recompile,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/>
470
+    <target depends="init" name="-pre-debug-fix">
471
+        <fail unless="fix.includes">Must set fix.includes</fail>
472
+        <property name="javac.includes" value="${fix.includes}.java"/>
473
+    </target>
474
+    <target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix">
475
+        <j2seproject1:nbjpdareload/>
476
+    </target>
477
+    <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
478
+    <!--
479
+                ===============
480
+                JAVADOC SECTION
481
+                ===============
482
+            -->
483
+    <target depends="init" name="-javadoc-build">
484
+        <mkdir dir="${dist.javadoc.dir}"/>
485
+        <javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
486
+            <classpath>
487
+                <path path="${javac.classpath}"/>
488
+            </classpath>
489
+            <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
490
+                <filename name="**/*.java"/>
491
+            </fileset>
492
+        </javadoc>
493
+    </target>
494
+    <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview">
495
+        <nbbrowse file="${dist.javadoc.dir}/index.html"/>
496
+    </target>
497
+    <target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
498
+    <!--
499
+                =========================
500
+                JUNIT COMPILATION SECTION
501
+                =========================
502
+            -->
503
+    <target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
504
+        <mkdir dir="${build.test.classes.dir}"/>
505
+    </target>
506
+    <target name="-pre-compile-test">
507
+        <!-- Empty placeholder for easier customization. -->
508
+        <!-- You can override this target in the ../build.xml file. -->
509
+    </target>
510
+    <target if="do.depend.true" name="-compile-test-depend">
511
+        <j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
512
+    </target>
513
+    <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
514
+        <j2seproject3:javac classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
515
+        <copy todir="${build.test.classes.dir}">
516
+            <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
517
+        </copy>
518
+    </target>
519
+    <target name="-post-compile-test">
520
+        <!-- Empty placeholder for easier customization. -->
521
+        <!-- You can override this target in the ../build.xml file. -->
522
+    </target>
523
+    <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/>
524
+    <target name="-pre-compile-test-single">
525
+        <!-- Empty placeholder for easier customization. -->
526
+        <!-- You can override this target in the ../build.xml file. -->
527
+    </target>
528
+    <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
529
+        <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
530
+        <j2seproject3:force-recompile destdir="${build.test.classes.dir}"/>
531
+        <j2seproject3:javac classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" sourcepath="${test.src.dir}" srcdir="${test.src.dir}"/>
532
+        <copy todir="${build.test.classes.dir}">
533
+            <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
534
+        </copy>
535
+    </target>
536
+    <target name="-post-compile-test-single">
537
+        <!-- Empty placeholder for easier customization. -->
538
+        <!-- You can override this target in the ../build.xml file. -->
539
+    </target>
540
+    <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
541
+    <!--
542
+                =======================
543
+                JUNIT EXECUTION SECTION
544
+                =======================
545
+            -->
546
+    <target depends="init" if="have.tests" name="-pre-test-run">
547
+        <mkdir dir="${build.test.results.dir}"/>
548
+    </target>
549
+    <target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run">
550
+        <j2seproject3:junit testincludes="**/*Test.java"/>
551
+    </target>
552
+    <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
553
+        <fail if="tests.failed">Some tests failed; see details above.</fail>
554
+    </target>
555
+    <target depends="init" if="have.tests" name="test-report"/>
556
+    <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/>
557
+    <target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/>
558
+    <target depends="init" if="have.tests" name="-pre-test-run-single">
559
+        <mkdir dir="${build.test.results.dir}"/>
560
+    </target>
561
+    <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single">
562
+        <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
563
+        <j2seproject3:junit excludes="" includes="${test.includes}"/>
564
+    </target>
565
+    <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
566
+        <fail if="tests.failed">Some tests failed; see details above.</fail>
567
+    </target>
568
+    <target depends="init,-do-not-recompile,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
569
+    <!--
570
+                =======================
571
+                JUNIT DEBUGGING SECTION
572
+                =======================
573
+            -->
574
+    <target depends="init,compile-test" if="have.tests" name="-debug-start-debuggee-test">
575
+        <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
576
+        <property location="${build.test.results.dir}/TEST-${test.class}.xml" name="test.report.file"/>
577
+        <delete file="${test.report.file}"/>
578
+        <mkdir dir="${build.test.results.dir}"/>
579
+        <j2seproject3:debug classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" classpath="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar:${debug.test.classpath}">
580
+            <customize>
581
+                <syspropertyset>
582
+                    <propertyref prefix="test-sys-prop."/>
583
+                    <mapper from="test-sys-prop.*" to="*" type="glob"/>
584
+                </syspropertyset>
585
+                <arg value="${test.class}"/>
586
+                <arg value="showoutput=true"/>
587
+                <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"/>
588
+                <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.report.file}"/>
589
+            </customize>
590
+        </j2seproject3:debug>
591
+    </target>
592
+    <target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test">
593
+        <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${test.class}"/>
594
+    </target>
595
+    <target depends="init,-do-not-recompile,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
596
+    <target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
597
+        <j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
598
+    </target>
599
+    <target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/>
600
+    <!--
601
+                =========================
602
+                APPLET EXECUTION SECTION
603
+                =========================
604
+            -->
605
+    <target depends="init,compile-single" name="run-applet">
606
+        <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
607
+        <j2seproject1:java classname="sun.applet.AppletViewer">
608
+            <customize>
609
+                <arg value="${applet.url}"/>
610
+            </customize>
611
+        </j2seproject1:java>
612
+    </target>
613
+    <!--
614
+                =========================
615
+                APPLET DEBUGGING  SECTION
616
+                =========================
617
+            -->
618
+    <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-applet">
619
+        <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
620
+        <j2seproject3:debug classname="sun.applet.AppletViewer">
621
+            <customize>
622
+                <arg value="${applet.url}"/>
623
+            </customize>
624
+        </j2seproject3:debug>
625
+    </target>
626
+    <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet" if="netbeans.home" name="debug-applet"/>
627
+    <!--
628
+                ===============
629
+                CLEANUP SECTION
630
+                ===============
631
+            -->
632
+    <target depends="init" name="deps-clean" unless="no.deps"/>
633
+    <target depends="init" name="-do-clean">
634
+        <delete dir="${build.dir}"/>
635
+        <delete dir="${dist.dir}"/>
636
+    </target>
637
+    <target name="-post-clean">
638
+        <!-- Empty placeholder for easier customization. -->
639
+        <!-- You can override this target in the ../build.xml file. -->
640
+    </target>
641
+    <target depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products." name="clean"/>
642
+</project>

+ 8
- 0
nbproject/genfiles.properties View File

@@ -0,0 +1,8 @@
1
+build.xml.data.CRC32=1c42d963
2
+build.xml.script.CRC32=d4296ee3
3
+build.xml.stylesheet.CRC32=958a1d3e
4
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
5
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6
+nbproject/build-impl.xml.data.CRC32=1c42d963
7
+nbproject/build-impl.xml.script.CRC32=fc1d50d2
8
+nbproject/build-impl.xml.stylesheet.CRC32=65b8de21

+ 61
- 0
nbproject/project.properties View File

@@ -0,0 +1,61 @@
1
+build.classes.dir=${build.dir}/classes
2
+build.classes.excludes=**/*.java,**/*.form
3
+# This directory is removed when the project is cleaned:
4
+build.dir=build
5
+build.generated.dir=${build.dir}/generated
6
+# Only compile against the classpath explicitly listed here:
7
+build.sysclasspath=ignore
8
+build.test.classes.dir=${build.dir}/test/classes
9
+build.test.results.dir=${build.dir}/test/results
10
+# Uncomment to specify the preferred debugger connection transport:
11
+#debug.transport=dt_socket
12
+debug.classpath=\
13
+    ${run.classpath}
14
+debug.test.classpath=\
15
+    ${run.test.classpath}
16
+# This directory is removed when the project is cleaned:
17
+dist.dir=dist
18
+dist.jar=${dist.dir}/charliebravo.jar
19
+dist.javadoc.dir=${dist.dir}/javadoc
20
+excludes=
21
+includes=**
22
+jar.compress=false
23
+javac.classpath=
24
+# Space-separated list of extra javac options
25
+javac.compilerargs=
26
+javac.deprecation=false
27
+javac.source=1.5
28
+javac.target=1.5
29
+javac.test.classpath=\
30
+    ${javac.classpath}:\
31
+    ${build.classes.dir}:\
32
+    ${libs.junit.classpath}:\
33
+    ${libs.junit_4.classpath}
34
+javadoc.additionalparam=
35
+javadoc.author=false
36
+javadoc.encoding=${source.encoding}
37
+javadoc.noindex=false
38
+javadoc.nonavbar=false
39
+javadoc.notree=false
40
+javadoc.private=false
41
+javadoc.splitindex=true
42
+javadoc.use=true
43
+javadoc.version=false
44
+javadoc.windowtitle=
45
+main.class=com.md87.charliebravo.CharlieBravo
46
+manifest.file=manifest.mf
47
+meta.inf.dir=${src.dir}/META-INF
48
+platform.active=default_platform
49
+run.classpath=\
50
+    ${javac.classpath}:\
51
+    ${build.classes.dir}
52
+# Space-separated list of JVM arguments used when running the project
53
+# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
54
+# or test-sys-prop.name=value to set system properties for unit tests):
55
+run.jvmargs=
56
+run.test.classpath=\
57
+    ${javac.test.classpath}:\
58
+    ${build.test.classes.dir}
59
+source.encoding=UTF-8
60
+src.dir=src
61
+test.src.dir=test

+ 16
- 0
nbproject/project.xml View File

@@ -0,0 +1,16 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://www.netbeans.org/ns/project/1">
3
+    <type>org.netbeans.modules.java.j2seproject</type>
4
+    <configuration>
5
+        <data xmlns="http://www.netbeans.org/ns/j2se-project/3">
6
+            <name>charliebravo</name>
7
+            <minimum-ant-version>1.6.5</minimum-ant-version>
8
+            <source-roots>
9
+                <root id="src.dir"/>
10
+            </source-roots>
11
+            <test-roots>
12
+                <root id="test.src.dir"/>
13
+            </test-roots>
14
+        </data>
15
+    </configuration>
16
+</project>

+ 24
- 0
src/com/dmdirc/addons/calc/Evaluator.java View File

@@ -0,0 +1,24 @@
1
+/*
2
+ * To change this template, choose Tools | Templates
3
+ * and open the template in the editor.
4
+ */
5
+
6
+package com.dmdirc.addons.calc;
7
+
8
+/**
9
+ *
10
+ * @author chris
11
+ */
12
+public class Evaluator {
13
+
14
+    private final TreeToken node;
15
+
16
+    public Evaluator(TreeToken node) {
17
+        this.node = node;
18
+    }
19
+
20
+    public Number evaluate() {
21
+        return node.evaluate();
22
+    }
23
+
24
+}

+ 62
- 0
src/com/dmdirc/addons/calc/Lexer.java View File

@@ -0,0 +1,62 @@
1
+/*
2
+ * To change this template, choose Tools | Templates
3
+ * and open the template in the editor.
4
+ */
5
+
6
+package com.dmdirc.addons.calc;
7
+
8
+import java.text.ParseException;
9
+import java.util.ArrayList;
10
+import java.util.Arrays;
11
+import java.util.List;
12
+import java.util.regex.Matcher;
13
+import java.util.regex.Pattern;
14
+
15
+/**
16
+ *
17
+ * @author chris
18
+ */
19
+public class Lexer {
20
+
21
+    final String input;
22
+
23
+    public Lexer(String input) {
24
+        this.input = input.replaceAll("\\s+", "");
25
+    }
26
+
27
+    public List<Token> tokenise() throws ParseException {
28
+        final List<Token> res = new ArrayList<Token>();
29
+        List<TokenType> possibles = Arrays.asList(TokenType.values());
30
+
31
+        boolean cont = true;
32
+        int i = 0;
33
+
34
+        do {
35
+            boolean found = false;
36
+
37
+            for (TokenType type : possibles) {
38
+                final int match = type.match(input, i);
39
+
40
+                if (match > -1) {
41
+                    res.add(new Token(type, input.substring(i, match)));
42
+
43
+                    possibles = type.getFollowers();
44
+                    i = match;
45
+                    found = true;
46
+                    cont = type != TokenType.END;
47
+
48
+                    break;
49
+                }
50
+            }
51
+
52
+            if (!found) {
53
+                throw new ParseException("No legal token found at offset "
54
+                        + i + ". Expecting one of: "
55
+                        + Arrays.toString(possibles.toArray()), i);
56
+            }
57
+        } while (cont);
58
+
59
+        return res;
60
+    }
61
+
62
+}

+ 153
- 0
src/com/dmdirc/addons/calc/Parser.java View File

@@ -0,0 +1,153 @@
1
+/*
2
+ * To change this template, choose Tools | Templates
3
+ * and open the template in the editor.
4
+ */
5
+
6
+package com.dmdirc.addons.calc;
7
+
8
+import java.text.ParseException;
9
+import java.util.ArrayList;
10
+import java.util.Arrays;
11
+import java.util.Collections;
12
+import java.util.Comparator;
13
+import java.util.List;
14
+
15
+/**
16
+ *
17
+ * @author chris
18
+ */
19
+public class Parser {
20
+
21
+    protected final Lexer lexer;
22
+    protected static final List<TokenType> TOKENS_BY_PRECEDENCE;
23
+
24
+    static {
25
+        TOKENS_BY_PRECEDENCE = new ArrayList<TokenType>(Arrays.asList(TokenType.values()));
26
+        Collections.sort(TOKENS_BY_PRECEDENCE, new TokenTypePrecedenceComparator());
27
+    }
28
+
29
+    public Parser(Lexer lexer) {
30
+        this.lexer = lexer;
31
+    }
32
+
33
+    public TreeToken parse() throws ParseException {
34
+        final List<TreeToken> tokens = new ArrayList<TreeToken>();
35
+
36
+        for (Token token : lexer.tokenise()) {
37
+            tokens.add(new TreeToken(token));
38
+        }
39
+
40
+        return parse(tokens);
41
+    }
42
+
43
+    protected TreeToken parse(final List<TreeToken> tokens) throws ParseException {
44
+        System.out.println("Parse: " + Arrays.toString(tokens.toArray()));
45
+
46
+        while (tokens.size() > 1) {
47
+            System.out.println(" --> " + Arrays.toString(tokens.toArray()));
48
+            for (TokenType type : TOKENS_BY_PRECEDENCE) {
49
+                final int offset = findTokenType(tokens, type);
50
+
51
+                if (offset > -1) {
52
+                    System.out.println(" --> Found token " + type);
53
+                    switch (type.getArity()) {
54
+                        case HIDDEN:
55
+                            parseHiddenOperator(tokens, offset);
56
+                            break;
57
+                        case BINARY:
58
+                            parseBinaryOperator(tokens, offset);
59
+                            break;
60
+                        case UNARY:
61
+                            parseUnaryOperator(tokens, offset);
62
+                            break;
63
+                        case NULLARY:
64
+                            parseNullaryOperator(tokens, offset);
65
+                            break;
66
+                    }
67
+
68
+                    break;
69
+                }
70
+            }
71
+        }
72
+
73
+        return tokens.get(0);
74
+    }
75
+
76
+    protected void parseNullaryOperator(final List<TreeToken> tokens, final int offset)
77
+            throws ParseException {
78
+        if (tokens.get(offset).getToken().getType() == TokenType.BRACKET_CLOSE
79
+                || tokens.get(offset).getToken().getType() == TokenType.BRACKET_OPEN) {
80
+            parseBracket(tokens, offset);
81
+        } else {
82
+            parseNumber(tokens, offset);
83
+        }
84
+    }
85
+
86
+    protected void parseBracket(final List<TreeToken> tokens, final int offset)
87
+            throws ParseException {
88
+        final List<TreeToken> stack = new ArrayList<TreeToken>();
89
+
90
+        System.out.println("ParseBracket: " + offset + " " + Arrays.toString(tokens.toArray()));
91
+
92
+        for (int i = offset - 1; i > 0; i--) {
93
+            if (tokens.get(i).getToken().getType() == TokenType.BRACKET_OPEN
94
+                    && !tokens.get(i).isProcessed()) {
95
+                System.out.println("Found opening bracket at index " + i);
96
+                tokens.add(i, parse(stack));
97
+                tokens.get(i).setProcessed();
98
+                tokens.remove(i + 1);
99
+                tokens.remove(i + 1);
100
+                return;
101
+            } else {
102
+                System.out.println("Skipping " + tokens.get(i));
103
+                stack.add(0, tokens.get(i));
104
+                tokens.remove(i);
105
+            }
106
+        }
107
+
108
+        throw new ParseException("Couldn't find matching opening bracket", offset);
109
+    }
110
+
111
+    protected void parseBinaryOperator(final List<TreeToken> tokens, final int offset) {
112
+        tokens.get(offset).addChild(tokens.get(offset - 1));
113
+        tokens.get(offset).addChild(tokens.get(offset + 1));
114
+        tokens.get(offset).setProcessed();
115
+
116
+        tokens.remove(offset + 1);
117
+        tokens.remove(offset - 1);
118
+    }
119
+
120
+    protected void parseUnaryOperator(final List<TreeToken> tokens, final int offset) {
121
+        tokens.get(offset).addChild(tokens.get(offset + 1));
122
+        tokens.get(offset).setProcessed();
123
+        tokens.remove(offset + 1);
124
+    }
125
+
126
+    protected void parseHiddenOperator(final List<TreeToken> tokens, final int offset) {
127
+        tokens.remove(offset);
128
+    }
129
+
130
+    protected void parseNumber(final List<TreeToken> tokens, final int offset) {
131
+        tokens.get(offset).setProcessed();
132
+    }
133
+
134
+    protected static int findTokenType(final List<TreeToken> tokens, final TokenType type) {
135
+        for (int i = 0; i < tokens.size(); i++) {
136
+            if (tokens.get(i).getToken().getType() == type && !tokens.get(i).isProcessed()) {
137
+                return i;
138
+            }
139
+        }
140
+
141
+        return -1;
142
+    }
143
+
144
+    protected static class TokenTypePrecedenceComparator implements Comparator<TokenType> {
145
+
146
+        @Override
147
+        public int compare(TokenType o1, TokenType o2) {
148
+            return o2.getPrecedence() - o1.getPrecedence();
149
+        }
150
+
151
+    }
152
+
153
+}

+ 35
- 0
src/com/dmdirc/addons/calc/Token.java View File

@@ -0,0 +1,35 @@
1
+/*
2
+ * To change this template, choose Tools | Templates
3
+ * and open the template in the editor.
4
+ */
5
+
6
+package com.dmdirc.addons.calc;
7
+
8
+/**
9
+ *
10
+ * @author chris
11
+ */
12
+public class Token {
13
+
14
+    private final TokenType type;
15
+    private String content;
16
+
17
+    public Token(TokenType type, String content) {
18
+        this.type = type;
19
+        this.content = content;
20
+    }
21
+
22
+    public String getContent() {
23
+        return content;
24
+    }
25
+
26
+    public TokenType getType() {
27
+        return type;
28
+    }
29
+
30
+    @Override
31
+    public String toString() {
32
+        return "[type: " + type + "; content: " + content + "]";
33
+    }
34
+
35
+}

+ 148
- 0
src/com/dmdirc/addons/calc/TokenType.java View File

@@ -0,0 +1,148 @@
1
+
2
+package com.dmdirc.addons.calc;
3
+
4
+import java.util.ArrayList;
5
+import java.util.List;
6
+import java.util.regex.Matcher;
7
+import java.util.regex.Pattern;
8
+
9
+public enum TokenType {
10
+
11
+    START(TokenTypeArity.HIDDEN, "^", 0, "NUMBER_*", "BRACKET_OPEN", "MOD_*"),
12
+    END(TokenTypeArity.HIDDEN, "$", 0),
13
+    
14
+    BRACKET_OPEN(TokenTypeArity.NULLARY, "\\(", 0, "NUMBER_*", "MOD_*", "BRACKET_OPEN"),
15
+    BRACKET_CLOSE(TokenTypeArity.NULLARY, "\\)", 50, "OP_*", "BRACKET_*", "END"),
16
+
17
+    NUMBER_FLOAT(TokenTypeArity.NULLARY, "[0-9]+\\.[0-9]+", 1, "OP_*", "BRACKET_*", "END") {
18
+        public Number evaluate(final TreeToken token) {
19
+            return Float.valueOf(token.getToken().getContent());
20
+        }
21
+    },
22
+
23
+    NUMBER_INT(TokenTypeArity.NULLARY, "[0-9]+", 1, "OP_*", "BRACKET_*", "END") {
24
+        public Number evaluate(final TreeToken token) {
25
+            return Float.valueOf(token.getToken().getContent());
26
+        }
27
+    },
28
+
29
+    MOD_POSITIVE(TokenTypeArity.UNARY, "\\+", 100, "NUMBER_*") {
30
+        public Number evaluate(final TreeToken token) {
31
+            return token.getChildren().get(0).evaluate();
32
+        }
33
+    },
34
+
35
+    MOD_NEGATIVE(TokenTypeArity.UNARY, "-", 100, "NUMBER_*") {
36
+        public Number evaluate(final TreeToken token) {
37
+            return -1 * token.getChildren().get(0).evaluate().floatValue();
38
+        }
39
+    },
40
+
41
+    OP_PLUS(TokenTypeArity.BINARY, "\\+", 7, "NUMBER_*", "BRACKET_OPEN") {
42
+        public Number evaluate(final TreeToken token) {
43
+            return token.getChildren().get(0).evaluate().floatValue()
44
+                    + token.getChildren().get(1).evaluate().floatValue();
45
+        }
46
+    },
47
+
48
+    OP_MINUS(TokenTypeArity.BINARY, "-", 6, "NUMBER_*", "BRACKET_OPEN") {
49
+        public Number evaluate(final TreeToken token) {
50
+            return token.getChildren().get(0).evaluate().floatValue()
51
+                    - token.getChildren().get(1).evaluate().floatValue();
52
+        }
53
+    },
54
+
55
+    OP_MULT(TokenTypeArity.BINARY, "(?=\\()|\\*", 9, "NUMBER_*", "BRACKET_OPEN") {
56
+        public Number evaluate(final TreeToken token) {
57
+            return token.getChildren().get(0).evaluate().floatValue()
58
+                    * token.getChildren().get(1).evaluate().floatValue();
59
+        }
60
+    },
61
+
62
+    OP_DIVIDE(TokenTypeArity.BINARY, "/", 10, "NUMBER_*", "BRACKET_OPEN") {
63
+        public Number evaluate(final TreeToken token) {
64
+            return token.getChildren().get(0).evaluate().floatValue()
65
+                    / token.getChildren().get(1).evaluate().floatValue();
66
+        }
67
+    },
68
+
69
+    OP_MOD(TokenTypeArity.BINARY, "%", 8, "NUMBER_*", "BRACKET_OPEN") {
70
+        public Number evaluate(final TreeToken token) {
71
+            return token.getChildren().get(0).evaluate().floatValue()
72
+                    % token.getChildren().get(1).evaluate().floatValue();
73
+        }
74
+    },
75
+
76
+    OP_POWER(TokenTypeArity.BINARY, "\\^", 11, "NUMBER_*", "BRACKET_OPEN") {
77
+        public Number evaluate(final TreeToken token) {
78
+            return new Float(Math.pow(token.getChildren().get(0).evaluate().doubleValue(),
79
+                    token.getChildren().get(1).evaluate().doubleValue()));
80
+        }
81
+    },
82
+    ;
83
+
84
+    private final String[] strfollows;
85
+    private final int precedence;
86
+    private List<TokenType> follows;
87
+    private final Pattern regex;
88
+    private final TokenTypeArity arity;
89
+
90
+    TokenType(final TokenTypeArity arity, final String regex,
91
+            final int precedence, final String ... follows) {
92
+        this.arity = arity;
93
+        this.strfollows = follows;
94
+        this.precedence = precedence;
95
+        this.regex = Pattern.compile(regex);
96
+    }
97
+
98
+    public synchronized  List<TokenType> getFollowers() {
99
+        if (follows == null) {
100
+            follows = new ArrayList<TokenType>();
101
+
102
+            for (int i = 0; i < strfollows.length; i++) {
103
+                follows.addAll(searchValueOf(strfollows[i]));
104
+            }
105
+        }
106
+
107
+        return follows;
108
+    }
109
+
110
+    public TokenTypeArity getArity() {
111
+        return arity;
112
+    }
113
+
114
+    public int getPrecedence() {
115
+        return precedence;
116
+    }
117
+
118
+    public int match(final String input, final int offset) {
119
+        final Matcher matcher = regex.matcher(input);
120
+        matcher.useAnchoringBounds(false);
121
+        matcher.useTransparentBounds(true);
122
+
123
+        return matcher.find(offset) && matcher.start() == offset ? matcher.end() : -1;
124
+    }
125
+
126
+    public Number evaluate(final TreeToken token) {
127
+        throw new AbstractMethodError("Can't evaluate this token type");
128
+    }
129
+
130
+    /**
131
+     *
132
+     * @param name
133
+     * @return
134
+     */
135
+    protected static List<TokenType> searchValueOf(final String name) {
136
+        final List<TokenType> res = new ArrayList<TokenType>();
137
+
138
+        for (TokenType token : values()) {
139
+            if ((name.endsWith("*")
140
+                    && token.name().startsWith(name.substring(0, name.length() - 1)))
141
+                    || name.equals(token.name())) {
142
+                res.add(token);
143
+            }
144
+        }
145
+
146
+        return res;
147
+    }
148
+}

+ 19
- 0
src/com/dmdirc/addons/calc/TokenTypeArity.java View File

@@ -0,0 +1,19 @@
1
+/*
2
+ * To change this template, choose Tools | Templates
3
+ * and open the template in the editor.
4
+ */
5
+
6
+package com.dmdirc.addons.calc;
7
+
8
+/**
9
+ *
10
+ * @author chris
11
+ */
12
+public enum TokenTypeArity {
13
+
14
+    HIDDEN,
15
+    NULLARY,
16
+    UNARY,
17
+    BINARY;
18
+
19
+}

+ 57
- 0
src/com/dmdirc/addons/calc/TreeToken.java View File

@@ -0,0 +1,57 @@
1
+/*
2
+ * To change this template, choose Tools | Templates
3
+ * and open the template in the editor.
4
+ */
5
+
6
+package com.dmdirc.addons.calc;
7
+
8
+import java.util.ArrayList;
9
+import java.util.List;
10
+
11
+/**
12
+ *
13
+ * @author chris
14
+ */
15
+public class TreeToken {
16
+
17
+    private final List<TreeToken> children = new ArrayList<TreeToken>();
18
+
19
+    private final Token token;
20
+
21
+    private boolean processed = false;
22
+
23
+    public TreeToken(Token token) {
24
+        this.token = token;
25
+    }
26
+
27
+    public List<TreeToken> getChildren() {
28
+        return children;
29
+    }
30
+
31
+    public Token getToken() {
32
+        return token;
33
+    }
34
+
35
+    public void addChild(final TreeToken token) {
36
+        children.add(token);
37
+    }
38
+
39
+    public boolean isProcessed() {
40
+        return processed;
41
+    }
42
+
43
+    public void setProcessed() {
44
+        processed = true;
45
+    }
46
+
47
+    public Number evaluate() {
48
+        return token.getType().evaluate(this);
49
+    }
50
+
51
+    @Override
52
+    public String toString() {
53
+        return "[token: " + token + "; children: " + children + "; processed: "
54
+                + processed + "]";
55
+    }
56
+
57
+}

+ 209
- 0
src/com/dmdirc/parser/irc/ChannelClientInfo.java View File

@@ -0,0 +1,209 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import java.util.HashMap;
26
+import java.util.Map;
27
+
28
+/**
29
+ * Contains information about a client on a channel.
30
+ * 
31
+ * @author Shane Mc Cormack
32
+ * @author Chris Smith
33
+ * @see IRCParser
34
+ */
35
+public class ChannelClientInfo {
36
+	/** Reference to ClientInfo object this represents. */
37
+	private final ClientInfo cClient;
38
+	/** Integer representation of the channel modes assocated with this user. */
39
+	private long nModes;
40
+	/** Reference to the parser object that owns this channelclient, Used for modes. */
41
+	private final IRCParser myParser;
42
+	/** Reference to the channel object that owns this channelclient. */
43
+	private final ChannelInfo myChannel;
44
+	/** A Map to allow applications to attach misc data to this object */
45
+	private Map myMap;
46
+	
47
+	/**
48
+	 * Create a ChannelClient instance of a CLient.
49
+	 *
50
+	 * @param tParser Refernce to parser that owns this channelclient (used for modes)
51
+	 * @param client Client that this channelclient represents
52
+	 * @param channel Channel that owns this channelclient
53
+	 */	
54
+	public ChannelClientInfo(final IRCParser tParser, final ClientInfo client, final ChannelInfo channel) {
55
+		myMap = new HashMap<Object, Object>();
56
+		myParser = tParser;
57
+		cClient = client;
58
+		myChannel = channel;
59
+		cClient.addChannelClientInfo(this);
60
+	}
61
+	
62
+	/**
63
+	 * Set the Map object attatched to this object.
64
+	 *
65
+	 * @param newMap New Map to attatch.
66
+	 * @see #getMap
67
+	 */
68
+	public void setMap(final Map newMap) {
69
+		myMap = newMap;
70
+	}
71
+	
72
+	/**
73
+	 * Get the Map object attatched to this object.
74
+	 *
75
+	 * @return Map to attatched to this.
76
+	 * @see #setMap
77
+	 */
78
+	public Map getMap() {
79
+		return myMap;
80
+	}
81
+	
82
+	/**
83
+	 * Get the client object represented by this channelclient.
84
+	 *
85
+	 * @return Client object represented by this channelclient
86
+	 */
87
+	public ClientInfo getClient() { return cClient; }
88
+	/**
89
+	 * Get the Channel object that owns this ChannelClient.
90
+	 *
91
+	 * @return Channel object that owns this ChannelClient
92
+	 */
93
+	public ChannelInfo getChannel() { return myChannel; }
94
+	/**
95
+	 * Get the nickname of the client object represented by this channelclient.
96
+	 *
97
+	 * @return Nickname of the Client object represented by this channelclient
98
+	 */	
99
+	public String getNickname() { return cClient.getNickname(); }	
100
+	
101
+	/**
102
+	 * Set the modes this client has (Prefix modes).
103
+	 *
104
+	 * @param nNewMode integer representing the modes this client has.
105
+	 */
106
+	public void setChanMode(final long nNewMode) { nModes = nNewMode; }
107
+	/**
108
+	 * Get the modes this client has (Prefix modes).
109
+	 *
110
+	 * @return integer representing the modes this client has.
111
+	 */
112
+	public long getChanMode() { return nModes; }
113
+	
114
+	/**
115
+	 * Get the modes this client has (Prefix modes) as a string.
116
+	 * Returns all known modes that the client has.
117
+	 * getChanModeStr(false).charAt(0) can be used to get the highest mode (o)
118
+	 * getChanModeStr(true).charAt(0) can be used to get the highest prefix (@)
119
+	 *
120
+	 * @param bPrefix if this is true, prefixes will be returned (@+) not modes (ov)
121
+	 * @return String representing the modes this client has.
122
+	 */
123
+	public String getChanModeStr(final boolean bPrefix) {
124
+		StringBuilder sModes = new StringBuilder();
125
+		long nTemp = 0;
126
+		final long nCurrentModes = this.getChanMode();
127
+
128
+		for (long i = myParser.nNextKeyPrefix; i > 0; i = i / 2) {
129
+			if ((nCurrentModes & i) == i) {
130
+				for (char cTemp : myParser.hPrefixModes.keySet()) {
131
+					nTemp = myParser.hPrefixModes.get(cTemp);
132
+					if (nTemp == i) {
133
+						if (bPrefix) { cTemp = myParser.hPrefixMap.get(cTemp); }
134
+						sModes = sModes.append(cTemp);
135
+						break;
136
+					}
137
+				}
138
+			}
139
+		}
140
+		
141
+		return sModes.toString();
142
+	}
143
+
144
+	/**
145
+	 * Get the value of the most important mode this client has (Prefix modes).
146
+	 * A higher value, is a more important mode, 0 = no modes.
147
+	 *
148
+	 * @return integer representing the value of the most important mode.
149
+	 */
150
+	public long getImportantModeValue() {
151
+		for (long i = myParser.nNextKeyPrefix; i > 0; i = i / 2) {
152
+			if ((nModes & i) == i) { return i; }
153
+		}
154
+		return 0;
155
+	}
156
+	
157
+	/**
158
+	 * Get the most important mode this client has (o, v etc), or an empty
159
+     * string if the client has no modes.
160
+	 *
161
+	 * @return String representing the most important mode.
162
+	 */
163
+	public String getImportantMode() {
164
+		String sModes = this.getChanModeStr(false);
165
+		if (!sModes.isEmpty()) { sModes = "" + sModes.charAt(0); }
166
+		return sModes;
167
+	}
168
+	
169
+	/**
170
+	 * Get the most important prefix this client has (@, + etc), or an empty
171
+     * string if the client has no modes.
172
+	 *
173
+	 * @return String representing the most important mode.
174
+	 */
175
+	public String getImportantModePrefix() {
176
+		String sModes = this.getChanModeStr(true);
177
+		if (!sModes.isEmpty()) { sModes = "" + sModes.charAt(0); }
178
+		return sModes;
179
+	}
180
+	
181
+
182
+	/**
183
+	 * Get the String Value of ChannelClientInfo (ie @Nickname).
184
+	 *
185
+	 * @return String Value of user (inc prefix) (ie @Nickname)
186
+	 */
187
+	@Override
188
+	public String toString() { 
189
+		return this.getImportantModePrefix() + this.getNickname();
190
+	}	
191
+	
192
+	/**
193
+	 * Attempt to kick this user from the channel.
194
+	 *
195
+	 * @param sReason Why are they being kicked? "" for no reason
196
+	 */
197
+	public void kick(final String sReason) {
198
+		myParser.sendString("KICK " + myChannel + " " + this.getNickname() + (sReason.isEmpty() ? sReason : " :" + sReason));
199
+	}
200
+	
201
+	/**
202
+	 * Get the "Complete" String Value of ChannelClientInfo (ie @+Nickname).
203
+	 *
204
+	 * @return String Value of user (inc prefix) (ie @+Nickname)
205
+	 */
206
+	public String toFullString() { return this.getChanModeStr(true) + this.getNickname(); }	
207
+
208
+}
209
+

+ 778
- 0
src/com/dmdirc/parser/irc/ChannelInfo.java View File

@@ -0,0 +1,778 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import java.util.ArrayList;
26
+import java.util.Hashtable;
27
+import java.util.HashMap;
28
+import java.util.LinkedList;
29
+import java.util.List;
30
+import java.util.Map;
31
+import java.util.Queue;
32
+
33
+/**
34
+ * Contains Channel information.
35
+ * 
36
+ * @author Shane Mc Cormack
37
+ * @author Chris Smith
38
+ * @see IRCParser
39
+ */
40
+public class ChannelInfo {
41
+	/**
42
+	 * Boolean repreenting the status of names requests.
43
+	 * When this is false, any new names reply will cause current known channelclients to be removed.
44
+	 */
45
+	private boolean bAddingNames = true;
46
+	
47
+	/** Unixtimestamp representing time when the channel was created. */
48
+	private long nCreateTime = 0;
49
+	
50
+	/** Current known topic in the channel. */
51
+	private String sTopic = "";
52
+	/** Last known user to set the topic (Full host where possible). */
53
+	private String sTopicUser = "";
54
+	/** Unixtimestamp representing time when the topic was set. */
55
+	private long nTopicTime = 0;
56
+	
57
+	/** Known boolean-modes for channel. */
58
+	private long nModes;
59
+	/** Reference to the parser object that owns this channel, Used for modes. */
60
+	private final IRCParser myParser; // Reference to parser object that owns this channel. Used for Modes
61
+	
62
+	/** Channel Name. */
63
+	private final String sName;
64
+	
65
+	/** Hashtable containing references to ChannelClients. */
66
+	private final Map<String, ChannelClientInfo> hChannelUserList = new Hashtable<String, ChannelClientInfo>();
67
+	/** Hashtable storing values for modes set in the channel that use parameters. */
68
+	private final Map<Character, String> hParamModes = new Hashtable<Character, String>();
69
+	/** Hashtable storing list modes. */
70
+	private final Map<Character, ArrayList<ChannelListModeItem>> hListModes = new Hashtable<Character, ArrayList<ChannelListModeItem>>();
71
+	/**
72
+	 * LinkedList storing status of mode adding.
73
+	 * if an item is in this list for a mode, we are expecting new items for the list
74
+	 */
75
+	private final List<Character> lAddingModes = new LinkedList<Character>();
76
+	/** Modes waiting to be sent to the server. */
77
+	private final List<String> lModeQueue = new LinkedList<String>();
78
+	/** A Map to allow applications to attach misc data to this object */
79
+	private Map myMap;
80
+	
81
+	/** Queue of requested list modes */
82
+	private final Queue<Character> listModeQueue = new LinkedList<Character>();
83
+	/** Listmode Queue Time */
84
+	private long listModeQueueTime = System.currentTimeMillis();
85
+	/** Have we asked the server for the list modes for this channel yet? */
86
+	private boolean askedForListModes = false;
87
+	/** Has OnChannelGotListModes ever been called for this channel? */
88
+	private boolean hasGotListModes = false;
89
+
90
+	/**
91
+	 * Create a new channel object.
92
+	 *
93
+	 * @param tParser Refernce to parser that owns this channelclient (used for modes)	 
94
+	 * @param name Channel name.
95
+	 */
96
+	public ChannelInfo(final IRCParser tParser, final String name) {
97
+		myMap = new HashMap<Object, Object>();
98
+		myParser = tParser;
99
+		sName = name;
100
+	}
101
+	
102
+	/**
103
+	 * Get the listModeQueue.
104
+	 *
105
+	 * @return The listModeQueue
106
+	 */
107
+	public Queue<Character> getListModeQueue() {
108
+		Queue<Character> result = listModeQueue;
109
+		final long now = System.currentTimeMillis();
110
+		// Incase of breakage, if getListModeQueue() was last called greater than
111
+		// 60 seconds ago, we reset the list.
112
+		if (now-(30*1000) > listModeQueueTime) {
113
+			result = new LinkedList<Character>();
114
+			myParser.callDebugInfo(IRCParser.DEBUG_LMQ, "Resetting LMQ");
115
+		}
116
+		listModeQueueTime = now;
117
+		return result;
118
+	}
119
+	
120
+	/**
121
+	 * Ask the server for all the list modes for this channel.
122
+	 */
123
+	public void requestListModes() {
124
+		final ChannelClientInfo me = getUser(myParser.getMyself());
125
+		if (me == null) {
126
+			// In a normal situation of non bouncer-brokenness this won't happen
127
+			return;
128
+		}
129
+		
130
+		askedForListModes = true;
131
+		
132
+		final String thisIRCD = myParser.getIRCD(true).toLowerCase();
133
+		final boolean isFreenode = (thisIRCD.equals("hyperion") || thisIRCD.equals("dancer"));
134
+		final boolean isUnreal = thisIRCD.equals("unreal");
135
+		final boolean isStarChat = thisIRCD.equals("starchat");
136
+		final boolean isHybrid = thisIRCD.equals("hybrid");
137
+		final boolean isCharybdis = thisIRCD.equals("charybdis");
138
+		
139
+		// We are considered opped if we have a mode higher than voice (or if we have any modes if voice doesn't exist)
140
+		long voiceValue = 0;
141
+		if (myParser.hPrefixModes.get('v') != null) { voiceValue = myParser.hPrefixModes.get('v');}
142
+		final boolean isOpped = me.getImportantModeValue() > voiceValue;
143
+		
144
+		int modecount = 1;
145
+		if (!isUnreal) {
146
+			try { 
147
+				modecount = Integer.parseInt(myParser.h005Info.get("MODES"));
148
+			} catch (NumberFormatException e) { /* use default modecount */}
149
+		}
150
+		
151
+		// Support for potential future decent mode listing in the protocol
152
+		//
153
+		// See my proposal: http://shane.dmdirc.com/listmodes.php
154
+		// Add listmode handler
155
+		final boolean supportLISTMODE = myParser.h005Info.containsKey("LISTMODE");
156
+		
157
+		String listmodes = "";
158
+		int i = 0;
159
+		for (Character cTemp : myParser.hChanModesOther.keySet()) {
160
+			final int nTemp = myParser.hChanModesOther.get(cTemp);
161
+			if (nTemp == IRCParser.MODE_LIST) {
162
+				if ((isFreenode || isHybrid || isCharybdis) && (cTemp == 'e' || cTemp == 'I') && !isOpped) {
163
+					// IRCD doesn't allow non-ops to ask for these modes.
164
+					continue;
165
+				} else if (isStarChat && cTemp == 'H') {
166
+					// IRCD Denies the mode exists
167
+					continue;
168
+				}
169
+				i++;
170
+				listmodes = listmodes + cTemp;
171
+				if (i >= modecount && !supportLISTMODE) {
172
+					myParser.sendString("MODE "+getName()+" "+listmodes);
173
+					i = 0;
174
+					listmodes = "";
175
+				}
176
+			}
177
+		}
178
+		if (i > 0) {
179
+			if (supportLISTMODE) {
180
+				myParser.sendString("LISTMODE "+getName()+" "+listmodes);
181
+			} else {
182
+				myParser.sendString("MODE "+getName()+" "+listmodes);
183
+			}
184
+		}
185
+	}
186
+	
187
+	/**
188
+	 * Have we ever asked the server for this channels listmodes?
189
+	 *
190
+	 * @return True if requestListModes() has ever been used, else false
191
+	 */
192
+	public boolean hasAskedForListModes() {
193
+		return askedForListModes;
194
+	}
195
+	
196
+	/**
197
+	 * Returns true if OnChannelGotListModes ever been called for this channel.
198
+	 *
199
+	 * @return True if OnChannelGotListModes ever been called for this channel.
200
+	 */
201
+	public boolean hasGotListModes() {
202
+		return hasGotListModes;
203
+	}
204
+	
205
+	/**
206
+	 * Set if OnChannelGotListModes ever been called for this channel.
207
+	 *
208
+	 * @param newValue new value for if OnChannelGotListModes ever been called for this channel.
209
+	 */
210
+	protected void setHasGotListModes(final boolean newValue) {
211
+		hasGotListModes = newValue;
212
+	}
213
+	
214
+	/**
215
+	 * Set the Map object attatched to this object.
216
+	 *
217
+	 * @param newMap New Map to attatch.
218
+	 */
219
+	public void setMap(final Map newMap) {
220
+		myMap = newMap;
221
+	}
222
+	
223
+	/**
224
+	 * Get the Map object attatched to this object.
225
+	 *
226
+	 * @return Map to attatched to this.
227
+	 */
228
+	public Map getMap() {
229
+		return myMap;
230
+	}
231
+	
232
+	/**
233
+	 * Set if we are getting a names request or not.
234
+	 *
235
+	 * @param newValue if false, any new names reply will cause current known channelclients to be removed.
236
+	 */
237
+	public void setAddingNames(final boolean newValue) { bAddingNames = newValue; }
238
+	
239
+	/**
240
+	 * Get if we are getting a names request or not.
241
+	 *
242
+	 * @return if false, any new names reply will cause current known channelclients to be removed.
243
+	 */
244
+	public boolean isAddingNames() { return bAddingNames; }
245
+	
246
+	/**
247
+	 * Get the name of this channel object.
248
+	 *
249
+	 * @return Channel name.
250
+	 */	
251
+	public String getName() { return sName; }
252
+	/**
253
+	 * Get the number of users known on this channel.
254
+	 *
255
+	 * @return Channel user count.
256
+	 */
257
+	public int getUserCount() { return hChannelUserList.size(); }
258
+	
259
+	/**
260
+	 * Get the channel users.
261
+	 *
262
+	 * @return ArrayList of ChannelClients
263
+	 */
264
+	public List<ChannelClientInfo> getChannelClients() {
265
+		return new ArrayList<ChannelClientInfo>(hChannelUserList.values());
266
+	}
267
+	
268
+	/**
269
+	 * Empty the channel (Remove all known channelclients).
270
+	 */
271
+	protected void emptyChannel() {
272
+		ClientInfo cTemp = null;
273
+		for (ChannelClientInfo client : hChannelUserList.values()) {
274
+			cTemp = client.getClient();
275
+			cTemp.delChannelClientInfo(client);
276
+			if (cTemp != myParser.getMyself() && !cTemp.checkVisibility()) {
277
+				myParser.removeClient(cTemp);
278
+			}
279
+		}
280
+		hChannelUserList.clear();
281
+	}
282
+
283
+	/**
284
+	 * Get the ChannelClientInfo object associated with a nickname.
285
+	 *
286
+	 * @param sWho Nickname to return channelclient for
287
+	 * @return ChannelClientInfo object requested, or null if not found
288
+	 */
289
+	public ChannelClientInfo getUser(final String sWho) {
290
+		return getUser(sWho, false);
291
+	}
292
+	
293
+	/**
294
+	 * Get the ChannelClientInfo object associated with a nickname.
295
+	 *
296
+	 * @param sWho Nickname to return channelclient for
297
+	 * @param createFake Create a fake client if not found
298
+	 * @return ChannelClientInfo object requested
299
+	 * @since 0.6
300
+	 */
301
+	public ChannelClientInfo getUser(final String sWho, final boolean createFake) {
302
+		final String who = myParser.getIRCStringConverter().toLowerCase(ClientInfo.parseHost(sWho));
303
+		if (hChannelUserList.containsKey(who)) {
304
+			return hChannelUserList.get(who);
305
+		}
306
+		if (createFake) {
307
+			return new ChannelClientInfo(myParser, (new ClientInfo(myParser, sWho)).setFake(true), this);
308
+		} else {
309
+			return null;
310
+		}
311
+	}
312
+	
313
+	/**
314
+	 * Get the ChannelClientInfo object associated with a ClientInfo object.
315
+	 *
316
+	 * @param cWho ClientInfo to return ChannelClient for
317
+	 * @return ChannelClientInfo object requested, or null if not found
318
+	 */	
319
+	public ChannelClientInfo getUser(final ClientInfo cWho) {
320
+		for (ChannelClientInfo client : hChannelUserList.values()) {
321
+			if (client.getClient() == cWho) {
322
+				return client;
323
+			}
324
+		}
325
+		return null;
326
+	}
327
+	
328
+	/**
329
+	 * Get the ChannelClientInfo object associated with a ClientInfo object.
330
+	 *
331
+	 * @param cClient Client object to be added to channel
332
+	 * @return ChannelClientInfo object added, or an existing object if already known on channel
333
+	 */
334
+	protected ChannelClientInfo addClient(final ClientInfo cClient) {
335
+		ChannelClientInfo cTemp = getUser(cClient);
336
+		if (cTemp == null) { 
337
+			cTemp = new ChannelClientInfo(myParser, cClient, this);
338
+			hChannelUserList.put(myParser.getIRCStringConverter().toLowerCase(cTemp.getNickname()), cTemp);
339
+		}
340
+		return cTemp;
341
+	}
342
+	
343
+	/**
344
+	 * Remove ChannelClientInfo object associated with a ClientInfo object.
345
+	 *
346
+	 * @param cClient Client object to be removed from channel
347
+	 */	
348
+	protected void delClient(final ClientInfo cClient) {
349
+		ChannelClientInfo cTemp = null;
350
+		cTemp = getUser(cClient);
351
+		if (cTemp != null) {
352
+			final ClientInfo clTemp = cTemp.getClient();
353
+			clTemp.delChannelClientInfo(cTemp);
354
+			if (clTemp != myParser.getMyself() && !clTemp.checkVisibility()) {
355
+				myParser.removeClient(clTemp);
356
+			}
357
+			hChannelUserList.remove(myParser.getIRCStringConverter().toLowerCase(cTemp.getNickname()));
358
+		}
359
+	}	
360
+	
361
+	/**
362
+	 * Rename a channelClient.
363
+	 *
364
+	 * @param oldNickname Nickname client used to be known as
365
+	 * @param cChannelClient ChannelClient object with updated client object
366
+	 */	
367
+	protected void renameClient(final String oldNickname, final ChannelClientInfo cChannelClient) {
368
+		ChannelClientInfo cTemp = null;
369
+		if (hChannelUserList.containsKey(oldNickname)) {
370
+			cTemp = hChannelUserList.get(oldNickname);
371
+			if (cTemp == cChannelClient) {
372
+				// Remove the old key
373
+				hChannelUserList.remove(oldNickname);
374
+				// Add with the new key. (getNickname will return the new name not the
375
+				// old one)
376
+				hChannelUserList.put(myParser.getIRCStringConverter().toLowerCase(cTemp.getNickname()), cTemp);
377
+			}
378
+		}
379
+	}
380
+	
381
+	/**
382
+	 * Set the create time.
383
+	 *
384
+	 * @param nNewTime New unixtimestamp time for the channel creation (Seconds since epoch, not milliseconds)
385
+	 */
386
+	protected void setCreateTime(final long nNewTime) { nCreateTime = nNewTime; }
387
+	/**
388
+	 * Get the Create time.
389
+	 *
390
+	 * @return Unixtimestamp time for the channel creation (Seconds since epoch, not milliseconds)
391
+	 */
392
+	public long getCreateTime() { return nCreateTime; }	
393
+	
394
+	/**
395
+	 * Set the topic time.
396
+	 *
397
+	 * @param nNewTime New unixtimestamp time for the topic (Seconds since epoch, not milliseconds)
398
+	 */
399
+	protected void setTopicTime(final long nNewTime) { nTopicTime = nNewTime; }
400
+	/**
401
+	 * Get the topic time.
402
+	 *
403
+	 * @return Unixtimestamp time for the topic (Seconds since epoch, not milliseconds)
404
+	 */
405
+	public long getTopicTime() { return nTopicTime; }	
406
+	
407
+	/**
408
+	 * Set the topic.
409
+	 *
410
+	 * @param sNewTopic New contents of topic
411
+	 */	
412
+	protected void setTopic(final String sNewTopic) { sTopic = sNewTopic; }
413
+	/**
414
+	 * Get the topic.
415
+	 *
416
+	 * @return contents of topic
417
+	 */	
418
+	public String getTopic() { return sTopic; }	
419
+
420
+	/**
421
+	 * Set the topic creator.
422
+	 *
423
+	 * @param sNewUser New user who set the topic (nickname if gotten on connect, full host if seen by parser)
424
+	 */	
425
+	protected void setTopicUser(final String sNewUser) { sTopicUser = sNewUser; }
426
+	/**
427
+	 * Get the topic creator.
428
+	 *
429
+	 * @return user who set the topic (nickname if gotten on connect, full host if seen by parser)
430
+	 */	
431
+	public String getTopicUser() { return sTopicUser; }
432
+	
433
+	/**
434
+	 * Set the channel modes (as an integer).
435
+	 *
436
+	 * @param nNewMode new long representing channel modes. (Boolean only)
437
+	 */	
438
+	protected void setMode(final long nNewMode) { nModes = nNewMode; }
439
+	/**
440
+	 * Get the channel modes (as an integer).
441
+	 *
442
+	 * @return long representing channel modes. (Boolean only)
443
+	 */	
444
+	public long getMode() { return nModes; }	
445
+	
446
+	/**
447
+	 * Get the channel modes (as a string representation).
448
+	 *
449
+	 * @return string representing modes. (boolean and non-list)
450
+	 */	
451
+	public String getModeStr() {
452
+		final StringBuilder sModes = new StringBuilder("+");
453
+		final StringBuilder sModeParams = new StringBuilder();
454
+		String sTemp = "";
455
+		long nTemp = 0;
456
+		final long nChanModes = this.getMode();
457
+		for (char cTemp : myParser.hChanModesBool.keySet()) {
458
+			nTemp = myParser.hChanModesBool.get(cTemp);
459
+			if ((nChanModes & nTemp) == nTemp) { sModes.append(cTemp); }
460
+		}
461
+		for (char cTemp : hParamModes.keySet()) {
462
+			sTemp = hParamModes.get(cTemp);
463
+			if (!sTemp.isEmpty()) {
464
+				sModes.append(cTemp);
465
+				sModeParams.append(" ").append(this.getModeParam(cTemp));
466
+ 			}
467
+		}
468
+		
469
+		return sModes.append(sModeParams).toString();
470
+	}	
471
+	
472
+	/**
473
+	 * Set a channel mode that requires a parameter.
474
+	 *
475
+	 * @param cMode Character representing mode
476
+	 * @param sValue String repreenting value (if "" mode is unset)
477
+	 */	
478
+	protected void setModeParam(final Character cMode, final String sValue) { 
479
+		if (sValue.isEmpty()) {
480
+			if (hParamModes.containsKey(cMode)) {
481
+				hParamModes.remove(cMode);
482
+			}
483
+		} else {
484
+			hParamModes.put(cMode, sValue);
485
+		}
486
+	}
487
+	/**
488
+	 * Get the value of a mode that requires a parameter.
489
+	 *
490
+	 * @param cMode Character representing mode
491
+	 * @return string representing the value of the mode ("" if mode not set)
492
+	 */	
493
+	public String getModeParam(final Character cMode) { 
494
+		if (hParamModes.containsKey(cMode)) { 
495
+			return hParamModes.get(cMode); 
496
+		}
497
+		return "";
498
+	}
499
+	
500
+	/**
501
+	 * Add/Remove a value to a channel list.
502
+	 *
503
+	 * @param givenMode Character representing mode
504
+	 * @param givenItem ChannelListModeItem representing the item
505
+	 * @param bAdd Add or remove the value. (true for add, false for remove)
506
+	 */
507
+	protected void setListModeParam(final Character givenMode, final ChannelListModeItem givenItem, final boolean bAdd) { 
508
+		Character cMode = givenMode;
509
+		ChannelListModeItem newItem = givenItem;
510
+		if (!myParser.hChanModesOther.containsKey(cMode) || myParser.hChanModesOther.get(cMode) != IRCParser.MODE_LIST) { return; }
511
+		
512
+		// Hyperion sucks.
513
+		if (cMode == 'b' || cMode == 'q') {
514
+			final String thisIRCD = myParser.getIRCD(true).toLowerCase();
515
+			if ((thisIRCD.equals("hyperion") || thisIRCD.equals("dancer"))) {
516
+				if (cMode == 'b' && givenItem.getItem().charAt(0) == '%') {
517
+					cMode = 'q';
518
+				} else if (cMode == 'q' && givenItem.getItem().charAt(0) != '%') {
519
+					cMode = 'b';
520
+				}
521
+				if (givenItem.getItem().charAt(0) == '%') {
522
+					newItem = new ChannelListModeItem(givenItem.getItem().substring(1), givenItem.getOwner(), givenItem.getTime());
523
+				}
524
+			}
525
+		}
526
+		
527
+		if (!hListModes.containsKey(cMode)) { 
528
+			hListModes.put(cMode, new ArrayList<ChannelListModeItem>());	
529
+		}
530
+		final ArrayList<ChannelListModeItem> lModes = hListModes.get(cMode);
531
+		for (int i = 0; i < lModes.size(); i++) {
532
+			if (myParser.getIRCStringConverter().equalsIgnoreCase(lModes.get(i).getItem(), newItem.getItem())) { 
533
+				if (bAdd) { return; }
534
+				else { 
535
+					lModes.remove(i);
536
+					break;
537
+				}
538
+			}
539
+		}
540
+		if (bAdd) { lModes.add(newItem); }
541
+	}
542
+	
543
+	/**
544
+	 * Get the list object representing a channel mode.
545
+	 *
546
+	 * @param cMode Character representing mode
547
+	 * @return ArrayList containing ChannelListModeItem in the list, or null if mode is invalid
548
+	 */
549
+	public List<ChannelListModeItem> getListModeParam(final Character cMode) {
550
+		if (!myParser.hChanModesOther.containsKey(cMode) || myParser.hChanModesOther.get(cMode) != myParser.MODE_LIST) { return null; }
551
+		
552
+		if (!hListModes.containsKey(cMode)) { 
553
+			hListModes.put(cMode, new ArrayList<ChannelListModeItem>());
554
+		}
555
+		return hListModes.get(cMode);
556
+	}
557
+	
558
+	/**
559
+	 * Get the "adding state" of a list mode.
560
+	 * 
561
+	 * @param cMode Character representing mode 
562
+	 * @return false if we are not expecting a 367 etc, else true.
563
+	 */
564
+	public boolean getAddState(final Character cMode) { 
565
+		synchronized (lAddingModes) {
566
+			return lAddingModes.contains(cMode);
567
+		}
568
+	}
569
+	
570
+	/**
571
+	 * Get the "adding state" of a list mode.
572
+	 * 
573
+	 * @param cMode Character representing mode
574
+	 * @param newState change the value returned by getAddState
575
+	 */
576
+	protected void setAddState(final Character cMode, final boolean newState) { 
577
+		synchronized (lAddingModes) {
578
+			if (newState) {
579
+				lAddingModes.add(cMode);
580
+			} else {
581
+				if (lAddingModes.contains(cMode)) { lAddingModes.remove(cMode); }
582
+			}
583
+		}
584
+	}
585
+	
586
+	/**
587
+	 * Reset the "adding state" of *all* list modes.
588
+	 */
589
+	protected void resetAddState() {
590
+		synchronized (lAddingModes) {
591
+			lAddingModes.clear();
592
+		}
593
+	}
594
+	
595
+	/**
596
+	 * Adjust the channel modes on a channel.
597
+	 * This function will queue modes up to be sent in one go, according to 005 params.
598
+	 * If less modes are altered than the queue accepts, sendModes() must be called.<br><br>
599
+	 * sendModes is automatically called if you attempt to add more modes than is allowed
600
+	 * to be queued
601
+	 *
602
+	 * @param positive Is this a positive mode change, or a negative mode change
603
+	 * @param mode Character representing the mode to change
604
+	 * @param parameter Parameter needed to make change (not used if mode doesn't need a parameter)
605
+	 */
606
+	public void alterMode(final boolean positive, final Character mode, final String parameter) { 
607
+		int modecount = 1;
608
+		int modeint = 0;
609
+		String modestr = "";
610
+		if (myParser.h005Info.containsKey("MODES")) {
611
+			try {
612
+				modecount = Integer.parseInt(myParser.h005Info.get("MODES")); 
613
+			} catch (NumberFormatException e) { 
614
+				modecount = 1; 
615
+			}
616
+		}
617
+		if (!myParser.isUserSettable(mode)) { return; }
618
+
619
+		modestr = ((positive) ? "+" : "-") + mode;
620
+		if (myParser.hChanModesBool.containsKey(mode)) {
621
+			final String teststr = ((positive) ? "-" : "+") + mode;
622
+			if (lModeQueue.contains(teststr)) {
623
+				lModeQueue.remove(teststr);
624
+				return;
625
+			} else if (lModeQueue.contains(modestr)) {
626
+				return;
627
+			}
628
+		} else {
629
+			// May need a param
630
+			if (myParser.hPrefixModes.containsKey(mode)) {
631
+				modestr = modestr + " " + parameter;
632
+			} else {
633
+				modeint = myParser.hChanModesOther.get(mode);
634
+				if ((modeint & IRCParser.MODE_LIST) == IRCParser.MODE_LIST) {
635
+					modestr = modestr + " " + parameter;
636
+				} else if (!positive && ((modeint & IRCParser.MODE_UNSET) == IRCParser.MODE_UNSET)) {
637
+					modestr = modestr + " " + parameter;
638
+				} else if (positive && ((modeint & IRCParser.MODE_SET) == IRCParser.MODE_SET)) {
639
+					// Does mode require a param to unset aswell?
640
+					// We might need to queue an unset first
641
+					if (((modeint & IRCParser.MODE_UNSET) == IRCParser.MODE_UNSET)) {
642
+						final String existingParam = getModeParam(mode);
643
+						if (!existingParam.isEmpty()) {
644
+							final String reverseModeStr = "-" + mode + " " + existingParam;
645
+							
646
+							myParser.callDebugInfo(IRCParser.DEBUG_INFO, "Queueing mode: %s", reverseModeStr);
647
+							lModeQueue.add(reverseModeStr);
648
+							if (lModeQueue.size() == modecount) { sendModes(); }
649
+						}
650
+					}
651
+					modestr = modestr + " " + parameter;
652
+				}
653
+			}
654
+		}
655
+		myParser.callDebugInfo(IRCParser.DEBUG_INFO, "Queueing mode: %s", modestr);
656
+		lModeQueue.add(modestr);
657
+		if (lModeQueue.size() == modecount) { sendModes(); }
658
+	}
659
+	
660
+	/**
661
+	 * This function will send modes that are currently queued up to send.
662
+	 * This assumes that the queue only contains the amount that are alowed to be sent
663
+	 * and thus will try to send the entire queue in one go.<br><br>
664
+	 * Modes are always sent negative then positive and not mixed.
665
+	 */
666
+	public void sendModes() { 
667
+		if (lModeQueue.isEmpty()) { return; }
668
+		final StringBuilder positivemode = new StringBuilder();
669
+		final StringBuilder positiveparam = new StringBuilder();
670
+		final StringBuilder negativemode = new StringBuilder();
671
+		final StringBuilder negativeparam = new StringBuilder();
672
+		final StringBuilder sendModeStr = new StringBuilder();
673
+		String modestr;
674
+		String[] modeparam;
675
+		boolean positive;
676
+		for (int i = 0; i < lModeQueue.size(); ++i) {
677
+			modeparam = lModeQueue.get(i).split(" ");
678
+			modestr = modeparam[0];
679
+			positive = modestr.charAt(0) == '+';
680
+			if (positive) {
681
+				positivemode.append(modestr.charAt(1));
682
+				if (modeparam.length > 1) { positiveparam.append(" ").append(modeparam[1]); }
683
+			} else {
684
+				negativemode.append(modestr.charAt(1));
685
+				if (modeparam.length > 1) { negativeparam.append(" ").append(modeparam[1]); }
686
+			}
687
+		}
688
+		if (negativemode.length() > 0) { sendModeStr.append("-").append(negativemode); }
689
+		if (positivemode.length() > 0) { sendModeStr.append("+").append(positivemode); }
690
+		if (negativeparam.length() > 0) { sendModeStr.append(negativeparam); }
691
+		if (positiveparam.length() > 0) { sendModeStr.append(positiveparam); }
692
+		myParser.callDebugInfo(IRCParser.DEBUG_INFO, "Sending mode: %s", sendModeStr.toString());
693
+		myParser.sendLine("MODE " + sName + " " + sendModeStr.toString());
694
+		clearModeQueue();
695
+	}
696
+	
697
+	/**
698
+	 * This function will clear the mode queue (WITHOUT Sending).
699
+	 */
700
+	public void clearModeQueue() { 
701
+		lModeQueue.clear();
702
+	}
703
+	
704
+	/**
705
+	 * Send a private message to the channel.
706
+	 *
707
+	 * @param sMessage Message to send
708
+	 */
709
+	public void sendMessage(final String sMessage) { 
710
+		if (sMessage.isEmpty()) { return; }
711
+		
712
+		myParser.sendString("PRIVMSG " + sName + " :" + sMessage);	
713
+	}
714
+	
715
+	/**
716
+	 * Send a notice message to a target.
717
+	 *
718
+	 * @param sMessage Message to send
719
+	 */
720
+	public void sendNotice(final String sMessage) { 
721
+		if (sMessage.isEmpty()) { return; }
722
+		
723
+		myParser.sendString("NOTICE " + sName + " :" + sMessage);	
724
+	}
725
+
726
+	/**
727
+	 * Send a private message to a target.
728
+	 *
729
+	 * @param sMessage Message to send
730
+	 */
731
+	public void sendAction(final String sMessage) { 
732
+		if (sMessage.isEmpty()) { return; }
733
+		sendCTCP("ACTION", sMessage);
734
+	}
735
+	
736
+	/**
737
+	 * Send a CTCP to a target.
738
+	 *
739
+	 * @param sType Type of CTCP
740
+	 * @param sMessage Optional Additional Parameters
741
+	 */
742
+	public void sendCTCP(final String sType, String sMessage) { 
743
+		if (sType.isEmpty()) { return; }
744
+		final char char1 = (char) 1;
745
+		if (!sMessage.isEmpty()) { sMessage = " " + sMessage; }
746
+		sendMessage(char1 + sType.toUpperCase() + sMessage + char1);
747
+	}
748
+	
749
+	/**
750
+	 * Send a CTCPReply to a target.
751
+	 *
752
+	 * @param sType Type of CTCP
753
+	 * @param sMessage Optional Additional Parameters
754
+	 */
755
+	public void sendCTCPReply(final String sType, String sMessage) { 
756
+		if (sType.isEmpty()) { return; }
757
+		final char char1 = (char) 1;
758
+		if (!sMessage.isEmpty()) { sMessage = " " + sMessage; }
759
+		sendNotice(char1 + sType.toUpperCase() + sMessage + char1);	
760
+	}
761
+	
762
+	/**
763
+	 * Get a string representation of the Channel.
764
+	 *
765
+	 * @return String representation of the Channel.
766
+	 */
767
+	@Override
768
+	public String toString() { return sName; }
769
+	
770
+	/**
771
+	 * Get the parser object that owns this channel.
772
+	 *
773
+	 * @return The parser object that owns this channel
774
+	 */
775
+	public IRCParser getParser() { return myParser; }
776
+
777
+}
778
+

+ 93
- 0
src/com/dmdirc/parser/irc/ChannelListModeItem.java View File

@@ -0,0 +1,93 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Contains Channel List Mode information.
27
+ * 
28
+ * @author Shane Mc Cormack
29
+ * @author Chris Smith
30
+ * @see IRCParser
31
+ */
32
+public final class ChannelListModeItem {
33
+
34
+	/** The Item itself. */
35
+	private final String myItem;
36
+	
37
+	/** The Time the item was created. */
38
+	private final long myTime;
39
+	
40
+	/** The Person who created the item. */
41
+	private final String myOwner;
42
+	
43
+	/**
44
+	 * Create a new Item.
45
+	 *
46
+	 * @param item The item (ie: test!joe@user.com)
47
+	 * @param owner The owner (ie: Dataforce)
48
+	 * @param time The Time (ie: 1173389295)
49
+	 */
50
+	public ChannelListModeItem(final String item, final String owner, final long time) {
51
+		myItem = item;
52
+		myTime = time;
53
+
54
+		if (!owner.isEmpty() && owner.charAt(0) == ':') {
55
+			myOwner = owner.substring(1);
56
+		} else {
57
+			myOwner = owner;
58
+		}
59
+	}
60
+	
61
+	/**
62
+	 * Get The Item itself.
63
+	 *
64
+	 * @return The Item itself.
65
+	 */
66
+	public String getItem() { return myItem; }
67
+	
68
+	/**
69
+	 * Get The Person who created the item.
70
+	 *
71
+	 * @return The Person who created the item.
72
+	 */
73
+	public String getOwner() { return myOwner; }
74
+	
75
+	/**
76
+	 * Get The Time the item was created.
77
+	 *
78
+	 * @return The Time the item was created.
79
+	 */
80
+	public long getTime() { return myTime; }
81
+	
82
+	/**
83
+	* Returns a String representation of this object.
84
+	*
85
+	* @return String representation of this object
86
+	*/
87
+	@Override
88
+	public String toString() {
89
+		return getItem();
90
+	}
91
+
92
+}
93
+

+ 427
- 0
src/com/dmdirc/parser/irc/ClientInfo.java View File

@@ -0,0 +1,427 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import java.util.ArrayList;
26
+import java.util.List;
27
+import java.util.LinkedList;
28
+import java.util.Hashtable;
29
+import java.util.HashMap;
30
+import java.util.Map;
31
+
32
+/**
33
+ * Contains information about known users.
34
+ * 
35
+ * @author Shane Mc Cormack
36
+ * @author Chris Smith
37
+ * @see IRCParser
38
+ */
39
+public final class ClientInfo {
40
+	/** Known nickname of client. */
41
+	private String sNickname = "";
42
+	/** Known ident of client. */
43
+	private String sIdent = "";	
44
+	/** Known host of client. */
45
+	private String sHost = "";
46
+	/** Known user modes of client. */
47
+	private long nModes;
48
+	/** Known Away Reason of client. */
49
+	private String myAwayReason = "";
50
+	/** Known RealName of client. */
51
+	private String sRealName = "";
52
+	/** Known away state for client. */
53
+	private boolean bIsAway;
54
+	/** Is this a fake client created just for a callback? */
55
+	private boolean bIsFake;
56
+	/** Reference to the parser object that owns this channel, Used for modes. */
57
+	private final IRCParser myParser;
58
+	/** A Map to allow applications to attach misc data to this object */
59
+	private Map myMap;
60
+	/** List of ChannelClientInfos that point to this */
61
+	private final Map<String, ChannelClientInfo> myChannelClientInfos = new Hashtable<String, ChannelClientInfo>();
62
+	/** Modes waiting to be sent to the server. */
63
+	private final List<String> lModeQueue = new LinkedList<String>();
64
+
65
+	/**
66
+	 * Create a new client object from a hostmask.
67
+	 *
68
+ 	 * @param tParser Refernce to parser that owns this channelclient (used for modes)	 
69
+	 * @param sHostmask Hostmask parsed by parseHost to get nickname
70
+	 * @see ClientInfo#parseHost
71
+	 */
72
+	public ClientInfo(final IRCParser tParser, final String sHostmask) { 
73
+		myMap = new HashMap<Object, Object>();
74
+		setUserBits(sHostmask, true);
75
+		myParser = tParser;
76
+	}
77
+
78
+	/**
79
+	 * Set the Map object attatched to this object.
80
+	 *
81
+	 * @param newMap New Map to attatch.
82
+	 */
83
+	public void setMap(final Map newMap) {
84
+		myMap = newMap;
85
+	}
86
+	
87
+	/**
88
+	 * Get the Map object attatched to this object.
89
+	 *
90
+	 * @return Map to attatched to this.
91
+	 */
92
+	public Map getMap() {
93
+		return myMap;
94
+	}
95
+
96
+	/**
97
+	 * Check if this is a fake client.
98
+	 *
99
+	 * @return True if this is a fake client, else false
100
+	 */
101
+	public boolean isFake() { return bIsFake; }
102
+	/**
103
+	 * Check if this client is actually a server.
104
+	 *
105
+	 * @return True if this client is actually a server.
106
+	 */
107
+	public boolean isServer() { return !(sNickname.indexOf(':') == -1); }
108
+	/**
109
+	 * Set if this is a fake client.
110
+	 * This returns "this" and thus can be used in the construction line.
111
+	 *
112
+	 * @param newValue new value for isFake - True if this is a fake client, else false
113
+	 * @return this Object
114
+	 */
115
+	public ClientInfo setFake(final boolean newValue) { bIsFake = newValue; return this; }
116
+
117
+	/**
118
+	 * Get a nickname of a user from a hostmask.
119
+	 * Hostmask must match (?:)nick(?!ident)(?@host)
120
+	 *
121
+	 * @param sWho Hostname to parse
122
+	 * @return nickname of user
123
+	 */
124
+	public static String parseHost(final String sWho) {
125
+		// Get the nickname from the string.
126
+		return parseHostFull(sWho)[0];
127
+	}
128
+	
129
+	/**
130
+	 * Get a nick ident and host of a user from a hostmask.
131
+	 * Hostmask must match (?:)nick(?!ident)(?@host)
132
+	 *
133
+	 * @param sWho Hostname to parse
134
+	 * @return Array containing details. (result[0] -> Nick | result[1] -> Ident | result[2] -> Host)
135
+	 */
136
+	public static String[] parseHostFull(String sWho) {
137
+		String[] sTemp = null;
138
+		final String[] result = new String[3];
139
+		if (!sWho.isEmpty() && sWho.charAt(0) == ':') { sWho = sWho.substring(1); }
140
+		sTemp = sWho.split("@", 2);
141
+		if (sTemp.length == 1) { result[2] = ""; } else { result[2] = sTemp[1]; }
142
+		sTemp = sTemp[0].split("!", 2);
143
+		if (sTemp.length == 1) { result[1] = ""; } else { result[1] = sTemp[1]; }
144
+		result[0] = sTemp[0];
145
+		
146
+		return result;
147
+	}
148
+
149
+	/**
150
+	 * Set the nick/ident/host of this client.
151
+	 *
152
+	 * @param sHostmask takes a host (?:)nick(?!ident)(?@host) and sets nick/host/ident variables
153
+	 * @param bUpdateNick if this is false, only host/ident will be updated.
154
+	 */	
155
+	public void setUserBits(final String sHostmask, final boolean bUpdateNick) {
156
+		setUserBits(sHostmask, bUpdateNick, false);
157
+	}
158
+	
159
+	/**
160
+	 * Set the nick/ident/host of this client.
161
+	 *
162
+	 * @param sHostmask takes a host (?:)nick(?!ident)(?@host) and sets nick/host/ident variables
163
+	 * @param bUpdateNick if this is false, only host/ident will be updated.
164
+	 * @param allowBlank if this is true, ident/host will be set even if
165
+	 *                   parseHostFull returns empty values for them
166
+	 */	
167
+	public void setUserBits(final String sHostmask, final boolean bUpdateNick, final boolean allowBlank) {
168
+		final String[] sTemp = parseHostFull(sHostmask);
169
+		if (!sTemp[2].isEmpty() || allowBlank) { sHost = sTemp[2]; }
170
+		if (!sTemp[1].isEmpty() || allowBlank) { sIdent = sTemp[1]; }
171
+		if (bUpdateNick) { sNickname = sTemp[0]; }
172
+	}
173
+	
174
+	/**
175
+	 * Get a string representation of the user.
176
+	 *
177
+	 * @return String representation of the user.
178
+	 */
179
+	@Override
180
+	public String toString() { return sNickname + "!" + sIdent + "@" + sHost; }
181
+	
182
+	/**
183
+	 * Get the nickname for this user.
184
+	 *
185
+	 * @return Known nickname for user.
186
+	 */
187
+	public String getNickname() { return sNickname; }
188
+	
189
+	/**
190
+	 * Get the ident for this user.
191
+	 *
192
+	 * @return Known ident for user. (May be "")
193
+	 */		
194
+	public String getIdent() { return sIdent; }
195
+	
196
+	/**
197
+	 * Get the hostname for this user.
198
+	 *
199
+	 * @return Known host for user. (May be "")
200
+	 */		
201
+	public String getHost() { return sHost; }
202
+	
203
+	/**
204
+	 * Set the away state of a user.
205
+	 * Automatically sets away reason to "" if set to false
206
+	 *
207
+	 * @param bNewState Boolean representing state. true = away, false = here
208
+	 */	
209
+	protected void setAwayState(final boolean bNewState) {
210
+		bIsAway = bNewState;
211
+		if (!bIsAway) { myAwayReason = ""; }
212
+	}
213
+	
214
+	/**
215
+	 * Get the away state of a user.
216
+	 *
217
+	 * @return Boolean representing state. true = away, false = here
218
+	 */	
219
+	public boolean getAwayState() { return bIsAway; }
220
+	
221
+	/**
222
+	 * Get the Away Reason for this user.
223
+	 *
224
+	 * @return Known away reason for user.
225
+	 */
226
+	public String getAwayReason() { return myAwayReason; }
227
+	
228
+	/**
229
+	 * Set the Away Reason for this user.
230
+	 * Automatically set to "" if awaystate is set to false
231
+	 *
232
+	 * @param newValue new away reason for user.
233
+	 */
234
+	protected void setAwayReason(final String newValue) { myAwayReason = newValue; }
235
+	
236
+	/**
237
+	 * Get the RealName for this user.
238
+	 *
239
+	 * @return Known RealName for user.
240
+	 */
241
+	public String getRealName() { return sRealName; }
242
+	
243
+	/**
244
+	 * Set the RealName for this user.
245
+	 *
246
+	 * @param newValue new RealName for user.
247
+	 */
248
+	protected void setRealName(final String newValue) { sRealName = newValue; }
249
+	
250
+	/**
251
+	 * Set the user modes (as an integer).
252
+	 *
253
+	 * @param nNewMode new long representing channel modes. (Boolean only)
254
+	 */	
255
+	protected void setUserMode(final long nNewMode) { nModes = nNewMode; }
256
+	
257
+	/**
258
+	 * Get the user modes (as an integer).
259
+	 *
260
+	 * @return long representing channel modes. (Boolean only)
261
+	 */	
262
+	public long getUserMode() { return nModes; }	
263
+	
264
+	/**
265
+	 * Get the user modes (as a string representation).
266
+	 *
267
+	 * @return string representing modes. (boolean and non-list)
268
+	 */	
269
+	public String getUserModeStr() { 
270
+		final StringBuilder sModes = new StringBuilder("+");
271
+		long nTemp = 0;
272
+		final long nChanModes = this.getUserMode();
273
+		
274
+		for (char cTemp : myParser.hUserModes.keySet()) {
275
+			nTemp = myParser.hUserModes.get(cTemp);
276
+			if ((nChanModes & nTemp) == nTemp) { sModes.append(cTemp); }
277
+		}
278
+		
279
+		return sModes.toString();
280
+	}
281
+	
282
+	/**
283
+	 * Is this client an oper?
284
+	 * This is a guess currently based on user-modes and thus only works on the
285
+	 * parsers own client.
286
+	 *
287
+	 * @return True/False if this client appears to be an oper
288
+	 */
289
+	public boolean isOper() {
290
+		final String modestr = getUserModeStr();
291
+		return (modestr.indexOf('o') > -1) || (modestr.indexOf('O') > -1);
292
+	}
293
+	
294
+	/**
295
+	 * Add a ChannelClientInfo as a known reference to this client.
296
+	 *
297
+	 * @param cci ChannelClientInfo to add as a known reference
298
+	 */	
299
+	public void addChannelClientInfo(final ChannelClientInfo cci) {
300
+		final String key = myParser.getIRCStringConverter().toLowerCase(cci.getChannel().getName());
301
+		if (!myChannelClientInfos.containsKey(key)) {
302
+			myChannelClientInfos.put(key, cci);
303
+		}
304
+	}
305
+	
306
+	/**
307
+	 * Remove a ChannelClientInfo as a known reference to this client.
308
+	 *
309
+	 * @param cci ChannelClientInfo to remove as a known reference
310
+	 */	
311
+	public void delChannelClientInfo(final ChannelClientInfo cci) {
312
+		final String key = myParser.getIRCStringConverter().toLowerCase(cci.getChannel().getName());
313
+		if (myChannelClientInfos.containsKey(key)) {
314
+			myChannelClientInfos.remove(key);
315
+		}
316
+	}
317
+	
318
+	/**
319
+	 * Check to see if a client is still known on any of the channels we are on.
320
+	 *
321
+	 * @return Boolean to see if client is still visable.
322
+	 */
323
+	public boolean checkVisibility() {
324
+		return !myChannelClientInfos.isEmpty();
325
+	}
326
+	
327
+	/**
328
+	 * Check how many channels this client is known on.
329
+	 *
330
+	 * @return int with the count of known channels
331
+	 */	
332
+	public int channelCount() {
333
+		return myChannelClientInfos.size();
334
+	}
335
+	
336
+	/**
337
+	 * Get a list of channelClients that point to this object.
338
+	 *
339
+	 * @return int with the count of known channels
340
+	 */	
341
+	public List<ChannelClientInfo> getChannelClients() {
342
+		final List<ChannelClientInfo> result = new ArrayList<ChannelClientInfo>();
343
+		for (ChannelClientInfo cci : myChannelClientInfos.values()) {
344
+			result.add(cci);
345
+		}
346
+		return result;
347
+	}
348
+	
349
+	/**
350
+	 * Adjust the channel modes on a channel.
351
+	 * This function will queue modes up to be sent in one go, according to 005 params.
352
+	 * If less modes are altered than the queue accepts, sendModes() must be called.<br><br>
353
+	 * sendModes is automatically called if you attempt to add more modes than is allowed
354
+	 * to be queued
355
+	 *
356
+	 * @param positive Is this a positive mode change, or a negative mode change
357
+	 * @param mode Character representing the mode to change
358
+	 */
359
+	public void alterMode(final boolean positive, final Character mode) {
360
+		if (isFake()) { return; }
361
+		int modecount = 1;
362
+		String modestr = "";
363
+		if (myParser.h005Info.containsKey("MODES")) {
364
+			try { 
365
+				modecount = Integer.parseInt(myParser.h005Info.get("MODES")); 
366
+			} catch (NumberFormatException e) { 
367
+				modecount = 1;
368
+			}
369
+		}
370
+		modestr = ((positive) ? "+" : "-") + mode;
371
+		if (!myParser.hUserModes.containsKey(mode)) { return; }
372
+		final String teststr = ((positive) ? "-" : "+") + mode;
373
+		if (lModeQueue.contains(teststr)) {
374
+			lModeQueue.remove(teststr);
375
+			return;
376
+		} else if (lModeQueue.contains(modestr)) {
377
+			return;
378
+		}
379
+		myParser.callDebugInfo(myParser.DEBUG_INFO, "Queueing user mode: %s", modestr);
380
+		lModeQueue.add(modestr);
381
+		if (lModeQueue.size() == modecount) { sendModes(); }
382
+	}
383
+	
384
+	/**
385
+	 * This function will send modes that are currently queued up to send.
386
+	 * This assumes that the queue only contains the amount that are alowed to be sent
387
+	 * and thus will try to send the entire queue in one go.<br><br>
388
+	 * Modes are always sent negative then positive and not mixed.
389
+	 */
390
+	public void sendModes() {
391
+		if (lModeQueue.isEmpty()) { return; }
392
+		final StringBuilder positivemode = new StringBuilder();
393
+		final StringBuilder negativemode = new StringBuilder();
394
+		final StringBuilder sendModeStr = new StringBuilder();
395
+		String modestr;
396
+		boolean positive;
397
+		for (int i = 0; i < lModeQueue.size(); ++i) {
398
+			modestr = lModeQueue.get(i);
399
+			positive = modestr.charAt(0) == '+';
400
+			if (positive) {
401
+				positivemode.append(modestr.charAt(1));
402
+			} else {
403
+				negativemode.append(modestr.charAt(1));
404
+			}
405
+		}
406
+		if (negativemode.length() > 0) { sendModeStr.append("-").append(negativemode); }
407
+		if (positivemode.length() > 0) { sendModeStr.append("+").append(positivemode); }
408
+		myParser.callDebugInfo(IRCParser.DEBUG_INFO, "Sending mode: %s", sendModeStr.toString());
409
+		myParser.sendLine("MODE " + sNickname + " " + sendModeStr.toString());
410
+		clearModeQueue();
411
+	}
412
+	
413
+	/**
414
+	 * This function will clear the mode queue (WITHOUT Sending).
415
+	 */
416
+	public void clearModeQueue() { 
417
+		lModeQueue.clear();
418
+	}
419
+	
420
+	/**
421
+	 * Get the parser object that owns this client.
422
+	 *
423
+	 * @return The parser object that owns this client
424
+	 */
425
+	public IRCParser getParser() { return myParser; }
426
+
427
+}

+ 128
- 0
src/com/dmdirc/parser/irc/IRCAuthenticator.java View File

@@ -0,0 +1,128 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import java.net.Authenticator;
26
+import java.net.PasswordAuthentication;
27
+
28
+import java.util.Map;
29
+import java.util.HashMap;
30
+
31
+/**
32
+ * Handles proxy authentication for the parser
33
+ * 
34
+ * @author Shane Mc Cormack
35
+ * @see IRCParser
36
+ */
37
+public class IRCAuthenticator extends Authenticator {
38
+	/**
39
+	 * A version number for this class. It should be changed whenever the class
40
+	 * structure is changed (or anything else that would prevent serialized
41
+	 * objects being unserialized with the new class).
42
+	 */
43
+	private static final long serialVersionUID = 1;
44
+
45
+	/** Singleton instance of IRCAuthenticator. */
46
+	private static IRCAuthenticator me = null;
47
+	
48
+	/** List of authentication replies. */
49
+	private final Map<String,PasswordAuthentication> replies = new HashMap<String,PasswordAuthentication>();
50
+	
51
+	/**
52
+	 * Create a new IRCAuthenticator.
53
+	 *
54
+	 * This creates an IRCAuthenticator and registers it as the default
55
+	 * Authenticator.
56
+	 */
57
+	private IRCAuthenticator() {
58
+/*		try {
59
+			final Field field = Authenticator.class.getDeclaredField("theAuthenticator");
60
+			field.setAccessible(true);
61
+			final Object authenticator = field.get(null);
62
+			if (authenticator instanceof Authenticator) {
63
+				oldAuthenticator = (Authenticator)authenticator;
64
+			}
65
+		} catch (NoSuchFieldException nsfe) {
66
+		} catch (IllegalAccessException iae) {
67
+		}*/
68
+		Authenticator.setDefault(this);
69
+	}
70
+	
71
+	/**
72
+	 * Get the instance of IRCAuthenticator
73
+	 */
74
+	public static synchronized IRCAuthenticator getIRCAuthenticator() {
75
+		if (me == null) {
76
+			me = new IRCAuthenticator();
77
+		}
78
+		return me;
79
+	}
80
+
81
+	/**
82
+	 * Add a server to authenticate for.
83
+	 *
84
+	 * @param server ServerInfo object with proxy details.
85
+	 */
86
+	public void addAuthentication(final ServerInfo server) {
87
+		addAuthentication(server.getProxyHost(), server.getProxyPort(), server.getProxyUser(), server.getProxyPass());
88
+	}
89
+
90
+	/**
91
+	 * Add a host to authenticate for.
92
+	 *
93
+	 * @param host Hostname
94
+	 * @param port Port
95
+	 * @param username Username to return for authentication
96
+	 * @param password Password to return for authentication
97
+	 */
98
+	public void addAuthentication(final String host, final int port, final String username, final String password) {
99
+		if (username == null || password == null || username.isEmpty() || password.isEmpty()) {
100
+			return;
101
+		}
102
+		final PasswordAuthentication pass = new PasswordAuthentication(username, password.toCharArray());
103
+		final String fullhost = host.toLowerCase()+":"+port;
104
+		
105
+		if (replies.containsKey(fullhost)) {
106
+			replies.remove(fullhost);
107
+		}
108
+		
109
+		replies.put(fullhost, pass);
110
+	}
111
+	
112
+	/** {@inheritDoc} */
113
+	protected PasswordAuthentication getPasswordAuthentication() {
114
+		/*
115
+		 * getRequestingHost: 85.234.138.2
116
+		 * getRequestingPort: 1080
117
+		 * getRequestingPrompt: SOCKS authentication
118
+		 * getRequestingProtocol: SOCKS5
119
+		 * getRequestingScheme: null
120
+		 * getRequestingSite: /85.234.138.2
121
+		 * getRequestingURL: null
122
+		 * getRequestorType: SERVER
123
+		 */
124
+
125
+		final String fullhost = getRequestingHost().toLowerCase()+":"+getRequestingPort();
126
+		return replies.get(fullhost);
127
+	}
128
+}

+ 2065
- 0
src/com/dmdirc/parser/irc/IRCParser.java
File diff suppressed because it is too large
View File


+ 179
- 0
src/com/dmdirc/parser/irc/IRCProcessor.java View File

@@ -0,0 +1,179 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.parser.irc.callbacks.CallbackManager;
26
+
27
+/**
28
+ * IRCProcessor.
29
+ * Superclass for all IRCProcessor types.
30
+ *
31
+ * @author Shane Mc Cormack
32
+ */
33
+public abstract class IRCProcessor {
34
+	/** Reference to the IRCParser that owns this IRCProcessor. */
35
+	protected IRCParser myParser;
36
+	
37
+	/** Reference to the Processing in charge of this IRCProcessor. */
38
+	protected ProcessingManager myManager;
39
+
40
+	// Some functions from the main parser are useful, and having to use myParser.functionName
41
+	// is annoying, so we also implement them here (calling them again using myParser)
42
+	/**
43
+	 * Create a new instance of the IRCProcessor Object.
44
+	 *
45
+	 * @param parser IRCParser That owns this IRCProcessor
46
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
47
+	 */
48
+	protected IRCProcessor(final IRCParser parser, final ProcessingManager manager) {
49
+		this.myParser = parser;
50
+		this.myManager = manager;
51
+	}
52
+
53
+	/**
54
+	 * Callback to all objects implementing the IErrorInfo Interface.
55
+	 *
56
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IErrorInfo
57
+	 * @param errorInfo ParserError object representing the error.
58
+	 * @return true if a method was called, false otherwise
59
+	 */
60
+	protected final boolean callErrorInfo(final ParserError errorInfo) {
61
+		return myParser.callErrorInfo(errorInfo);
62
+	}
63
+	
64
+	/**
65
+	 * Callback to all objects implementing the DebugInfo Callback.
66
+	 *
67
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IDebugInfo
68
+	 * @param level Debugging Level (DEBUG_INFO, ndSocket etc)
69
+	 * @param data Debugging Information
70
+	 * @param args Formatting String Options
71
+	 * @return true if a method was called, false otherwise
72
+	 */
73
+	protected final boolean callDebugInfo(final int level, final String data, final Object... args) {
74
+		return myParser.callDebugInfo(level, String.format(data, args));
75
+	}
76
+	
77
+	/**
78
+	 * Callback to all objects implementing the DebugInfo Callback.
79
+	 *
80
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IDebugInfo
81
+	 * @param level Debugging Level (DEBUG_INFO, ndSocket etc)
82
+	 * @param data Debugging Information
83
+	 * @return true if a method was called, false otherwise
84
+	 */
85
+	protected final boolean callDebugInfo(final int level, final String data) {
86
+		return myParser.callDebugInfo(level, data);
87
+	}
88
+	
89
+	/**
90
+	 * Check if a channel name is valid .
91
+	 *
92
+	 * @param sChannelName Channel name to test
93
+	 * @return true if name is valid on the current connection, false otherwise. (Always false before noMOTD/MOTDEnd)
94
+	 */
95
+	protected final boolean isValidChannelName(final String sChannelName) {
96
+		return myParser.isValidChannelName(sChannelName);
97
+	}
98
+	
99
+	/**
100
+	 * Get the ClientInfo object for a person.
101
+	 *
102
+	 * @param sWho Who can be any valid identifier for a client as long as it contains a nickname (?:)nick(?!ident)(?@host)
103
+	 * @return ClientInfo Object for the client, or null
104
+	 */
105
+	protected final ClientInfo getClientInfo(final String sWho) {
106
+		return myParser.getClientInfo(sWho);
107
+	}
108
+	
109
+	/**
110
+	 * Get the ChannelInfo object for a channel.
111
+	 *
112
+	 * @param sWhat This is the name of the channel.
113
+	 * @return ChannelInfo Object for the channel, or null
114
+	 */
115
+	protected final ChannelInfo getChannelInfo(final String sWhat) {
116
+		return myParser.getChannelInfo(sWhat);
117
+	}
118
+	
119
+	/**
120
+	 * Get a reference to the CallbackManager.
121
+	 *
122
+	 * @return Reference to the CallbackManager
123
+	 */
124
+	protected final CallbackManager getCallbackManager() {
125
+		return myParser.getCallbackManager();
126
+	}
127
+	
128
+	/** 
129
+	 * Send a line to the server and add proper line ending.
130
+	 *
131
+	 * @param line Line to send (\r\n termination is added automatically)
132
+	 */
133
+	protected final void sendString(final String line) {
134
+		myParser.sendString(line);
135
+	}
136
+	
137
+	/**
138
+	 * Process a Line.
139
+	 *
140
+	 * @param sParam Type of line to process ("005", "PRIVMSG" etc)
141
+	 * @param token IRCTokenised line to process
142
+	 */
143
+	public abstract void process(final String sParam, final String[] token);
144
+	
145
+	/**
146
+	 * What does this IRCProcessor handle.
147
+	 *
148
+	 * @return String[] with the names of the tokens we handle.
149
+	 */
150
+	public abstract String[] handles();
151
+	
152
+	/** 
153
+	 * Get the name for this Processor.
154
+	 * @return the name of this processor
155
+	 */
156
+	public final String getName() {
157
+		final 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
+	/** 
166
+	 * Get the name for this Processor in lowercase.
167
+	 * @return lower case name of this processor
168
+	 */
169
+	public final String getLowerName() {
170
+		return this.getName().toLowerCase();
171
+	}
172
+	
173
+	/** 
174
+	 * Get the name for this Processor.
175
+	 * @return the name of this processor
176
+	 */
177
+	public final String toString() { return this.getName(); }
178
+	
179
+}

+ 142
- 0
src/com/dmdirc/parser/irc/IRCStringConverter.java View File

@@ -0,0 +1,142 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * IRC String Converter.
27
+ *
28
+ * @author Shane Mc Cormack
29
+ */
30
+public class IRCStringConverter {
31
+	/** Characters to use when converting tolowercase. */
32
+	private final char[] lowercase;
33
+	/** Characters to use when converting touppercase. */
34
+	private final char[] uppercase;
35
+	/** limit */
36
+	private final byte limit;
37
+
38
+	/**
39
+	 * Create a new IRCStringConverter with rfc1459 encoding.
40
+	 */
41
+	public IRCStringConverter() {
42
+		this((byte)4);
43
+	}
44
+	
45
+	/**
46
+	 * Create a new IRCStringConverter.
47
+	 * @param limit Number of post-alphabetical characters to convert
48
+	 *              0 = ascii encoding
49
+	 *              3 = strict-rfc1459 encoding
50
+	 *              4 = rfc1459 encoding
51
+	 */
52
+	public IRCStringConverter(final byte limit) {
53
+		// If limit is out side the boundries, use rfc1459
54
+		if (limit > 4 || limit < 0 ) { this.limit = (byte)4; }
55
+		else { this.limit = limit; }
56
+		
57
+		lowercase = new char[127];
58
+		uppercase = new char[127];
59
+		// Normal Chars
60
+		for (char i = 0; i < lowercase.length; ++i) {
61
+			lowercase[i] = i;
62
+			uppercase[i] = i;
63
+		}
64
+
65
+		// Replace the uppercase chars with lowercase
66
+		for (char i = 65; i <= (90 + this.limit); ++i) {
67
+			lowercase[i] = (char)(i + 32);
68
+			uppercase[i + 32] = i;
69
+		}
70
+	}
71
+
72
+	/**
73
+	 * Get last used chararray limit.
74
+	 *
75
+	 * @return last used chararray limit
76
+	 */
77
+	protected int getLimit() { return limit; }
78
+	
79
+	/**
80
+	 * Get the lowercase version of a String for this Server.
81
+	 *
82
+	 * @param input String to convert lowercase
83
+	 * @return input String converterd to lowercase
84
+	 */
85
+	public String toLowerCase(final String input) {
86
+		final char[] result = input.toCharArray();
87
+		for (int i = 0; i < input.length(); ++i) {
88
+			if (result[i] >= 0 && result[i] < lowercase.length) {
89
+				result[i] = lowercase[result[i]];
90
+			} else {
91
+				result[i] = result[i];
92
+			}
93
+		}
94
+		return new String(result);
95
+	}
96
+
97
+	/**
98
+	 * Get the uppercase version of a String for this Server.
99
+	 *
100
+	 * @param input String to convert uppercase
101
+	 * @return input String converterd to uppercase
102
+	 */
103
+	public String toUpperCase(final String input) {
104
+		final char[] result = input.toCharArray();
105
+		for (int i = 0; i < input.length(); ++i) {
106
+			if (result[i] >= 0 && result[i] < uppercase.length) {
107
+				result[i] = uppercase[result[i]];
108
+			} else {
109
+				result[i] = result[i];
110
+			}
111
+		}
112
+		return new String(result);
113
+	}
114
+
115
+	/**
116
+	 * Check if 2 strings are equal to each other ignoring case.
117
+	 *
118
+	 * @param first First string to check
119
+	 * @param second Second string to check
120
+	 * @return True if both strings are equal after being lowercased
121
+	 */
122
+	public boolean equalsIgnoreCase(final String first, final String second) {
123
+		if (first == null && second == null) { return true; }
124
+		if (first == null || second == null) { return false; }
125
+		boolean result = (first.length() == second.length());
126
+		if (result) {
127
+			final char[] firstChar = first.toCharArray();
128
+			final char[] secondChar = second.toCharArray();
129
+			for (int i = 0; i < first.length(); ++i) {
130
+				if (firstChar[i] < lowercase.length && secondChar[i] < lowercase.length) {
131
+					result = (lowercase[firstChar[i]] == lowercase[secondChar[i]]);
132
+				} else {
133
+					result = firstChar[i] == secondChar[i];
134
+				}
135
+				if (!result) { break; }
136
+			}
137
+		}
138
+
139
+		return result;
140
+	}
141
+
142
+}

+ 163
- 0
src/com/dmdirc/parser/irc/Logging.java View File

@@ -0,0 +1,163 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import java.lang.reflect.Method;
26
+import java.lang.reflect.InvocationTargetException;
27
+
28
+/**
29
+ * Logging using log4j if available.
30
+ */
31
+public class Logging {
32
+	/** Available Log Levels */
33
+	public enum LogLevel {
34
+		TRACE("trace", "isTraceEnabled"),
35
+		DEBUG("debug", "isDebugEnabled"),
36
+		INFO("info", "isInfoEnabled"),
37
+		WARN("warn", "isWarnEnabled"),
38
+		ERROR("error", "isErrorEnabled"),
39
+		FATAL("fatal", "isFatalEnabled");
40
+		
41
+		/** Method name */
42
+		private final String methodName;
43
+		
44
+		/** Check Method name */
45
+		private final String checkMethodName;
46
+		
47
+		/**
48
+		 * Create a new LogLevel
49
+		 *
50
+		 * @param methodName Name of method in log4j to log to
51
+		 * @param checkMethodName Name of method in log4j to sue to check logging
52
+		 */
53
+		private LogLevel(final String methodName, final String checkMethodName) {
54
+			this.methodName = methodName;
55
+			this.checkMethodName = checkMethodName;
56
+		}
57
+		
58
+		/**
59
+		 * Get the Name of method in log4j to log to
60
+		 *
61
+		 * @return Name of method in log4j to log to
62
+		 */
63
+		public String getMethodName() { return methodName; }
64
+		
65
+		/**
66
+		 * Get the Name of the check method in log4j
67
+		 *
68
+		 * @return Name of check method in log4j
69
+		 */
70
+		public String getCheckMethodName() { return checkMethodName; }
71
+	};
72
+	
73
+	/** Singleton Instance of Logging */
74
+	private static Logging me;
75
+	
76
+	/** Is log4j available */
77
+	private final boolean isAvailable;
78
+	
79
+	/** "Log" object if available */
80
+	private Object log = null;
81
+	
82
+	/** Get an instance of Logging */
83
+	public static Logging getLogging() {
84
+		if (me == null) { me = new Logging(); }
85
+		return me;
86
+	}
87
+	
88
+	/** Create a new Logging */
89
+	@SuppressWarnings("unchecked")
90
+	private Logging() {
91
+		boolean classExists = false;
92
+		try {
93
+			Class factory = null;
94
+			// Check for classes
95
+			Class.forName("org.apache.commons.logging.Log");
96
+			factory = Class.forName("org.apache.commons.logging.LogFactory");
97
+		
98
+			classExists = (factory != null);
99
+			if (classExists) {
100
+				final Method getLog = factory.getMethod("getLog", new Class[]{Class.class});
101
+				log = getLog.invoke(null, this.getClass());
102
+			}
103
+		} catch (ClassNotFoundException cnfe) {
104
+		} catch (NoSuchMethodException nsme) {
105
+		} catch (IllegalAccessException iae) {
106
+		} catch (InvocationTargetException ite) {
107
+		}
108
+		
109
+		isAvailable = (classExists && log != null);
110
+	}
111
+	
112
+	/**
113
+	 * Check is a log level is available.
114
+	 *
115
+	 * @param level Level to check
116
+	 */
117
+	public boolean levelEnabled(final LogLevel level) {
118
+		if (isAvailable) {
119
+			try {
120
+				final Method check = log.getClass().getMethod(level.getCheckMethodName(), new Class[0]);
121
+				return (Boolean)check.invoke(log, new Object[0]);
122
+			} catch (NoSuchMethodException nsme) {
123
+			} catch (IllegalAccessException iae) {
124
+			} catch (InvocationTargetException ite) {
125
+			}
126
+		}
127
+		
128
+		return false;
129
+	}
130
+	
131
+	/**
132
+	 * Log a message if log4j is available.
133
+	 *
134
+	 * @param level Level to log at
135
+	 * @param message Message to log
136
+	 */
137
+	public void log(final LogLevel level, final String message) {
138
+		log(level, message, null);
139
+	}
140
+	
141
+	/**
142
+	 * Log a message if log4j is available.
143
+	 *
144
+	 * @param level Level to log at
145
+	 * @param message Message to log
146
+	 * @param throwable Throwable to log alongside message
147
+	 */
148
+	public void log(final LogLevel level, final String message, final Throwable throwable) {
149
+		if (!isAvailable) { return; }
150
+		try {
151
+			if (throwable == null) {
152
+				final Method method = log.getClass().getMethod(level.getMethodName(), new Class[]{String.class});
153
+				method.invoke(log, new Object[]{message});
154
+			} else {
155
+				final Method method = log.getClass().getMethod(level.getMethodName(), new Class[]{String.class, Throwable.class});
156
+				method.invoke(log, new Object[]{message, throwable});
157
+			}
158
+		} catch (NoSuchMethodException nsme) {
159
+		} catch (IllegalAccessException iae) {
160
+		} catch (InvocationTargetException ite) {
161
+		}
162
+	}
163
+}

+ 158
- 0
src/com/dmdirc/parser/irc/MyInfo.java View File

@@ -0,0 +1,158 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Contains User information.
27
+ * 
28
+ * @author Shane Mc Cormack
29
+ * @author Chris Smith
30
+ * @see IRCParser
31
+ */
32
+public final class MyInfo {
33
+	/** Character to prepend to nickname if in use (Default "_"). */
34
+	private char prependChar = '_';	
35
+	/** Nickname to attempt to use on IRC. */
36
+	private String nickname;
37
+	/**
38
+	 * Alternative nickname to attempt to use on IRC.
39
+	 * If the first nickname is in use, and a NickInUse message is recieved before 001, we
40
+	 * will attempt to use this nickname instead.<br>
41
+	 * If this also fails, we will start prepending the prependChar character (_) to the main nickname
42
+	 */
43
+	private String altNickname;
44
+	/** Realname string to use */
45
+	private String realname;
46
+	/** Username to use, this doesn't matter when an ident server is running*/
47
+	private String username;
48
+	
49
+	/**
50
+	 * Create a new MyInfo object.
51
+	 */
52
+	public MyInfo() {
53
+		String result;
54
+		try {
55
+			result = System.getProperty("user.name");
56
+		} catch (SecurityException e) {
57
+			result = null;
58
+		}
59
+		if (result == null || result.isEmpty()) {
60
+			nickname = "IRCParser";
61
+			username = "IRCParser";
62
+			realname = "DMDIrc IRCParser";
63
+			altNickname = "IRC-Parser";
64
+		} else {
65
+			nickname = result;
66
+			username = nickname;
67
+			realname = nickname+" - DMDIrc";
68
+			altNickname = nickname+"-";
69
+		}
70
+	}
71
+	
72
+	/**
73
+	 * Set the Nickname.
74
+	 *
75
+	 * @param newValue Value to set to.
76
+	 */
77
+	public void setNickname(final String newValue) {
78
+		if (newValue != null && !newValue.isEmpty()) {
79
+			nickname = newValue;
80
+		}
81
+	}
82
+	
83
+	/**
84
+	 * Get the Nickname.
85
+	 *
86
+	 * @return Current Nickname
87
+	 */
88
+	public String getNickname() { return nickname; }
89
+	
90
+	/**
91
+	 * Set the Alternative Nickname.
92
+	 *
93
+	 * @param newValue Value to set to.
94
+	 */
95
+	public void setAltNickname(final String newValue) {
96
+		if (newValue != null && !newValue.isEmpty()) {
97
+			altNickname = newValue;
98
+		}
99
+	}
100
+	
101
+	/**
102
+	 * Get the Alternative Nickname.
103
+	 *
104
+	 * @return Current Nickname
105
+	 */
106
+	public String getAltNickname() { return altNickname; }
107
+	
108
+	/**
109
+	 * Set the Realname.
110
+	 *
111
+	 * @param newValue Value to set to.
112
+	 */
113
+	public void setRealname(final String newValue) {
114
+		if (newValue != null && !newValue.isEmpty()) {
115
+			realname = newValue;
116
+		}
117
+	}
118
+	
119
+	/**
120
+	 * Get the Realname.
121
+	 *
122
+	 * @return Current Realname
123
+	 */
124
+	public String getRealname() { return realname; }
125
+	
126
+	/**
127
+	 * Set the Username.
128
+	 *
129
+	 * @param newValue Value to set to.
130
+	 */
131
+	public void setUsername(final String newValue) {
132
+		if (newValue != null && !newValue.isEmpty()) {
133
+			username = newValue;
134
+		}
135
+	}
136
+	
137
+	/**
138
+	 * Get the Username.
139
+	 *
140
+	 * @return Current Username
141
+	 */
142
+	public String getUsername() { return username; }
143
+	
144
+	/**
145
+	 * Set the Prepend Character.
146
+	 *
147
+	 * @param newValue Value to set to.
148
+	 */
149
+	public void setPrependChar(final char newValue) { prependChar = newValue; }
150
+	
151
+	/**
152
+	 * Get the Prepend Character.
153
+	 *
154
+	 * @return Current Prepend Character
155
+	 */
156
+	public char getPrependChar() { return prependChar; }	
157
+
158
+}

+ 177
- 0
src/com/dmdirc/parser/irc/ParserError.java View File

@@ -0,0 +1,177 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * IRC Parser Error.
27
+ *
28
+ * @author Shane Mc Cormack
29
+ */
30
+public final class ParserError {
31
+	/** Error is potentially Fatal, Desync 99% Guaranteed! */
32
+	public static final int ERROR_FATAL = 1;
33
+	/** Error is not fatal, but is more severe than a warning. */
34
+	public static final int ERROR_ERROR = 2;
35
+	/** Error was an unexpected occurance, but shouldn't be anything to worry about. */
36
+	public static final int ERROR_WARNING = 4;
37
+	/** Error is a user-error rather than a server error. */
38
+	public static final int ERROR_USER = 8;
39
+	/** Error was an exception from elsewhere. */
40
+	public static final int ERROR_EXCEPTION = 16;
41
+	
42
+	/** Store the Error level. */
43
+	private int errorLevel;
44
+	/** Store the Error Information. */
45
+	private String errorData;
46
+	/** Store the Exception object. */
47
+	private Exception exceptionInfo;
48
+	
49
+	/** Last line of server input before this exception was triggered. */
50
+	private String lastLine = "";
51
+	
52
+	/**
53
+	 * Create a new Error.
54
+	 *
55
+	 * @param level Set the error level.
56
+	 * @param data String containing information about the error.
57
+	 * @param line The last line of data recieved from the server before this exception.
58
+	 */
59
+	public ParserError(final int level, final String data, final String line) {
60
+		errorData = data;
61
+		errorLevel = level;
62
+		lastLine = line;
63
+	}
64
+	
65
+	/**
66
+	 * Check if this error is considered Fatal.
67
+	 *
68
+	 * @return Returns true for a fatal error, false for a non-fatal error
69
+	 */
70
+	public boolean isFatal() {
71
+		return (errorLevel & ERROR_FATAL) == ERROR_FATAL;
72
+	}
73
+	
74
+	/**
75
+	 * Check if this error is considered an error (less severe than fatal, worse than warning).
76
+	 *
77
+	 * @return Returns true for an "Error" level error, else false.
78
+	 */
79
+	public boolean isError() {
80
+		return (errorLevel & ERROR_ERROR) == ERROR_ERROR;
81
+	}
82
+	
83
+	/**
84
+	 * Check if this error is considered a warning.
85
+	 *
86
+	 * @return Returns true for a warning, else false.
87
+	 */
88
+	public boolean isWarning() {
89
+		return (errorLevel & ERROR_WARNING) == ERROR_WARNING;
90
+	}
91
+	
92
+	/**
93
+	 * Check if this error is considered a user-error rather than a server error.
94
+	 * For DMDirc this will cause the error not to be reported to the developers
95
+	 *
96
+	 * @return Returns true for a user error, else false.
97
+	 */
98
+	public boolean isUserError() {
99
+		return (errorLevel & ERROR_USER) == ERROR_USER;
100
+	}
101
+	
102
+	/**
103
+	 * Check if this error was generated from an exception.
104
+	 *
105
+	 * @return Returns true if getException will return an exception.
106
+	 */
107
+	public boolean isException() {
108
+		return (errorLevel & ERROR_EXCEPTION) == ERROR_EXCEPTION;
109
+	}
110
+	
111
+	/**
112
+	 * Check if this error has a lastLine parameter.
113
+	 *
114
+	 * @return Returns true if getLastLine returns anything non null, non empty.
115
+	 */
116
+	public boolean hasLastLine() {
117
+		return (lastLine != null && !lastLine.isEmpty());
118
+	}
119
+	
120
+	/**
121
+	 * Set the Exception object.
122
+	 *
123
+	 * @param newException The exception object to store
124
+	 */
125
+	public void setException(final Exception newException) {
126
+		exceptionInfo = newException;
127
+		if (!this.isException()) {
128
+			this.errorLevel = this.errorLevel + ERROR_EXCEPTION;
129
+		}
130
+	}
131
+	
132
+	/**
133
+	 * Get the Exception object.
134
+	 *
135
+	 * @return Returns the exception object
136
+	 */
137
+	public Exception getException() {
138
+		return exceptionInfo;
139
+	}
140
+	
141
+	/**
142
+	 * Get the full ErrorLevel.
143
+	 *
144
+	 * @return Returns the error level
145
+	 */
146
+	public int getLevel() {
147
+		return errorLevel;
148
+	}
149
+	
150
+	/**
151
+	 * Get the Error information.
152
+	 *
153
+	 * @return Returns the error data
154
+	 */
155
+	public String getData() {
156
+		return errorData;
157
+	}
158
+	
159
+	/**
160
+	 * Add to the error information.
161
+	 *
162
+	 * @param data Information to add to the end of the existing Data
163
+	 */
164
+	public void appendData(final String data) {
165
+		errorData = errorData + '[' + data + ']';
166
+	}
167
+	
168
+	/**
169
+	 * Get the last line recieved from the server before this exception.
170
+	 *
171
+	 * @return Returns the error data
172
+	 */
173
+	public String getLastLine() {
174
+		return lastLine;
175
+	}	
176
+
177
+}

+ 55
- 0
src/com/dmdirc/parser/irc/PingTimer.java View File

@@ -0,0 +1,55 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import java.util.TimerTask;
26
+import java.util.Timer;
27
+
28
+/**
29
+ * Used by the parser to ping the server at a set interval to check that the
30
+ * server is still alive.
31
+ *
32
+ * @author Shane Mc Cormack
33
+ */
34
+public class PingTimer extends TimerTask {
35
+	/** Owning Parser. */
36
+	final IRCParser myOwner;
37
+	/** The Timer that owns this task */
38
+	final Timer myTimer;
39
+	
40
+	/**
41
+	 * Create the PingTimer.
42
+	 *
43
+	 * @param control IRCParser that owns this TimerTask.
44
+	 * @param timer Timer that owns this TimerTask.
45
+	 */
46
+	public PingTimer(final IRCParser control, final Timer timer) {
47
+		myOwner = control;
48
+		myTimer = timer;
49
+	}
50
+	
51
+	/** Timer has been executed. */
52
+	public void run() {
53
+		myOwner.pingTimerTask(myTimer);
54
+	}
55
+}

+ 108
- 0
src/com/dmdirc/parser/irc/Process001.java View File

@@ -0,0 +1,108 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process a 001 message.
27
+ */
28
+public class Process001 extends IRCProcessor {
29
+	/**
30
+	 * Process a 001 message.
31
+	 *
32
+	 * @param sParam Type of line to process ("001")
33
+	 * @param token IRCTokenised line to process
34
+	 */
35
+	@Override
36
+	public void process(final String sParam, final String[] token) {
37
+		myParser.got001 = true;
38
+		// << :demon1.uk.quakenet.org 001 Java-Test :Welcome to the QuakeNet IRC Network, Java-Test
39
+		myParser.sServerName = token[0].substring(1,token[0].length());
40
+		final String sNick = token[2];
41
+		
42
+		/* Code below is here incase relying on token[2] breaks somewhere
43
+		String[] temp = token[token.length-1].split(" ");
44
+		sConfirmedNickname = temp[temp.length-1];
45
+		// Some servers give a full host in 001
46
+		temp = sNick.split("!",2);
47
+		sNick = temp[0];  /* */
48
+		
49
+		// Get old nickname incase we need it later
50
+		final String oldnick = myParser.getMyself().getNickname();
51
+		
52
+		// myself will be fake if we havn't recieved a 001 yet
53
+		if (myParser.getMyself().isFake()) {
54
+			// Update stored information
55
+			myParser.getMyself().setUserBits(sNick, true, true);
56
+			myParser.getMyself().setFake(false);
57
+			myParser.addClient(myParser.getMyself());
58
+		} else {
59
+			// Another 001? if nicknames change then we need to update the hashtable
60
+			if (!myParser.getMyself().getNickname().equalsIgnoreCase(sNick)) {
61
+				// Nick changed, remove old me
62
+				myParser.forceRemoveClient(myParser.getMyself());
63
+				/// Update stored information
64
+				myParser.getMyself().setUserBits(sNick, true, true);
65
+				// Check that we don't already know someone by this name
66
+				if (myParser.getClientInfo(myParser.getMyself().getNickname()) == null) {
67
+					// And add to list
68
+					myParser.addClient(myParser.getMyself());
69
+				} else {
70
+					// Someone else already know? this is bad!
71
+					myParser.callErrorInfo(new ParserError(ParserError.ERROR_FATAL, "001 overwrites existing client?", myParser.getLastLine()));
72
+				}
73
+			}
74
+		}
75
+		
76
+		callServerReady();
77
+		myParser.startPingTimer();
78
+	}
79
+	
80
+	/**
81
+	 * Callback to all objects implementing the ServerReady Callback.
82
+	 *
83
+	 * @see IServerReady
84
+	 * @return true if a method was called, false otherwise
85
+	 */	
86
+	protected boolean callServerReady() {
87
+		return getCallbackManager().getCallbackType("OnServerReady").call();
88
+	}
89
+	
90
+	/**
91
+	 * What does this IRCProcessor handle.
92
+	 *
93
+	 * @return String[] with the names of the tokens we handle.
94
+	 */
95
+	@Override
96
+	public String[] handles() {
97
+		return new String[]{"001"};
98
+	} 
99
+	
100
+	/**
101
+	 * Create a new instance of the IRCProcessor Object.
102
+	 *
103
+	 * @param parser IRCParser That owns this IRCProcessor
104
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
105
+	 */
106
+	protected Process001 (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
107
+
108
+}

+ 141
- 0
src/com/dmdirc/parser/irc/Process004005.java View File

@@ -0,0 +1,141 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process ISUPPORT lines.
27
+ */
28
+public class Process004005 extends IRCProcessor {
29
+	/**
30
+	 * Process ISUPPORT lines.
31
+	 *
32
+	 * @param sParam Type of line to process ("005", "004")
33
+	 * @param token IRCTokenised line to process
34
+	 */
35
+	@Override
36
+	public void process(final String sParam, final String[] token) {
37
+		if (sParam.equals("003")) {
38
+			myParser.h005Info.put("003IRCD",token[token.length-1]);
39
+		} else if (sParam.equals("004")) {
40
+			// 004
41
+			if (token.length > 4) {
42
+				myParser.h005Info.put("004IRCD",token[4]);
43
+				myParser.h005Info.put("USERMODES",token[5]);
44
+				myParser.h005Info.put("USERCHANMODES",token[6]);
45
+			} else {
46
+				final String[] bits = token[3].split(" ");
47
+				myParser.h005Info.put("004IRCD",bits[1]);
48
+				myParser.h005Info.put("USERMODES",bits[2]);
49
+				myParser.h005Info.put("USERCHANMODES",bits[3]);
50
+			}
51
+			myParser.parseUserModes();
52
+		} else if (sParam.equals("005")) {
53
+			// 005
54
+			String[] Bits = null;
55
+			String sKey = null, sValue = null;
56
+			for (int i = 3; i < token.length ; i++) {
57
+				Bits = token[i].split("=",2);
58
+				sKey = Bits[0].toUpperCase();
59
+				if (Bits.length == 2) { sValue = Bits[1]; } else { sValue = ""; }
60
+				callDebugInfo(IRCParser.DEBUG_INFO, "%s => %s",sKey,sValue);
61
+				myParser.h005Info.put(sKey,sValue);
62
+				if (sKey.equals("NETWORK")) {
63
+					myParser.sNetworkName = sValue;
64
+					callGotNetwork();
65
+				} else if (sKey.equals("CASEMAPPING")) {
66
+					byte limit = (byte)4;
67
+					if (sValue.equalsIgnoreCase("strict-rfc1459")) {
68
+						limit = (byte)3;
69
+					} else if (sValue.equalsIgnoreCase("ascii")) {
70
+						limit = (byte)0;
71
+					} else if (!sValue.equalsIgnoreCase("rfc1459")) {
72
+						myParser.callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Unknown casemapping: '"+sValue+"' - assuming rfc1459", myParser.getLastLine()));
73
+					}
74
+					final boolean limitChanged = (myParser.getIRCStringConverter().getLimit() != limit);
75
+					myParser.updateCharArrays(limit);
76
+					if (limitChanged && myParser.knownClients() == 1) {
77
+							// This means that the casemapping is not rfc1459
78
+							// We have only added ourselves so far (from 001)
79
+							// We can fix the hashtable easily.
80
+						myParser.removeClient(myParser.getMyself());
81
+						myParser.addClient(myParser.getMyself());
82
+					}
83
+				} else if (sKey.equals("CHANTYPES")) {
84
+					myParser.parseChanPrefix();
85
+				} else if (sKey.equals("PREFIX")) {
86
+					myParser.parsePrefixModes();
87
+				} else if (sKey.equals("CHANMODES")) {
88
+					myParser.parseChanModes();
89
+				} else if (sKey.equals("LISTMODE")) {
90
+					// Support for potential future decent mode listing in the protocol
91
+					// 
92
+					// See my proposal: http://shane.dmdirc.com/listmodes.php
93
+					// Add listmode handler
94
+					String[] handles = new String[2];
95
+					handles[0] = sValue; // List mode item
96
+					sValue = ""+(Integer.parseInt(sValue) + 1);
97
+					myParser.h005Info.put("LISTMODEEND", sValue);
98
+					handles[1] = sValue; // List mode end
99
+					// Add listmode handlers
100
+					try {
101
+						myParser.getProcessingManager().addProcessor(handles, myParser.getProcessingManager().getProcessor("__LISTMODE__"));
102
+					} catch (ProcessorNotFoundException e) { }
103
+				}
104
+			}
105
+		}
106
+	}
107
+	
108
+	/**
109
+	 * What does this IRCProcessor handle.
110
+	 *
111
+	 * @return String[] with the names of the tokens we handle.
112
+	 */
113
+	@Override
114
+	public String[] handles() {
115
+		return new String[]{"003", "004", "005"};
116
+	} 
117
+	
118
+	/**
119
+	 * Callback to all objects implementing the GotNetwork Callback.
120
+	 * This takes no params of its own, but works them out itself.
121
+	 *
122
+	 * @see IGotNetwork
123
+	 * @return true if a method was called, false otherwise
124
+	 */
125
+	protected boolean callGotNetwork() {
126
+		final String networkName = myParser.sNetworkName;
127
+		final String ircdVersion = myParser.getIRCD(false);
128
+		final String ircdType = myParser.getIRCD(true);
129
+		
130
+		return getCallbackManager().getCallbackType("OnGotNetwork").call(networkName, ircdVersion, ircdType);
131
+	}
132
+	
133
+	/**
134
+	 * Create a new instance of the IRCProcessor Object.
135
+	 *
136
+	 * @param parser IRCParser That owns this IRCProcessor
137
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
138
+	 */
139
+	protected Process004005 (final IRCParser parser, final ProcessingManager manager) { super(parser, manager); }
140
+
141
+}

+ 70
- 0
src/com/dmdirc/parser/irc/Process464.java View File

@@ -0,0 +1,70 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process a 464 message.
27
+ */
28
+public class Process464 extends IRCProcessor {
29
+	/**
30
+	 * Process a 464 message.
31
+	 *
32
+	 * @param sParam Type of line to process ("464")
33
+	 * @param token IRCTokenised line to process
34
+	 */
35
+	@Override
36
+	public void process(String sParam, String[] token) {
37
+		callPasswordRequired();
38
+//		ParserError ei = new ParserError(ParserError.ERROR_ERROR, "Password Required");
39
+//		callErrorInfo(ei);
40
+	}
41
+	
42
+	/**
43
+	 * What does this IRCProcessor handle.
44
+	 *
45
+	 * @return String[] with the names of the tokens we handle.
46
+	 */
47
+	@Override
48
+	public String[] handles() {
49
+		return new String[]{"464"};
50
+	} 
51
+	
52
+	/**
53
+	 * Callback to all objects implementing the PasswordRequired Callback.
54
+	 *
55
+	 * @see IPasswordRequired
56
+	 * @return true if a method was called, false otherwise
57
+	 */
58
+	protected boolean callPasswordRequired() {
59
+		return getCallbackManager().getCallbackType("OnPasswordRequired").call();
60
+	}
61
+	
62
+	/**
63
+	 * Create a new instance of the IRCProcessor Object.
64
+	 *
65
+	 * @param parser IRCParser That owns this IRCProcessor
66
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
67
+	 */
68
+	protected Process464 (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
69
+
70
+}

+ 76
- 0
src/com/dmdirc/parser/irc/ProcessAway.java View File

@@ -0,0 +1,76 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process an Away/Back message.
27
+ */
28
+public class ProcessAway extends IRCProcessor {
29
+	/**
30
+	 * Process an Away/Back message.
31
+	 *
32
+	 * @param sParam Type of line to process ("305", "306")
33
+	 * @param token IRCTokenised line to process
34
+	 */
35
+	@Override
36
+	public void process(String sParam, String[] token) {
37
+		if (sParam.equals("301")) {
38
+			ClientInfo iClient = myParser.getClientInfo(token[3]);
39
+			if (iClient != null) { iClient.setAwayReason(token[token.length-1]); }
40
+		} else {
41
+			myParser.getMyself().setAwayState(sParam.equals("306"));
42
+			callAwayState(myParser.getMyself().getAwayState(), myParser.getMyself().getAwayReason());
43
+		}
44
+	}
45
+	
46
+	/**
47
+	 * Callback to all objects implementing the onAwayState Callback.
48
+	 *
49
+	 * @see IAwayState
50
+	 * @param currentState Set to true if we are now away, else false.
51
+	 * @param reason Best guess at away reason
52
+	 * @return true if a method was called, false otherwise
53
+	 */
54
+	protected boolean callAwayState(boolean currentState, String reason) {
55
+		return myParser.getCallbackManager().getCallbackType("OnAwayState").call(currentState, reason);
56
+	}
57
+	
58
+	/**
59
+	 * What does this IRCProcessor handle.
60
+	 *
61
+	 * @return String[] with the names of the tokens we handle.
62
+	 */
63
+	@Override
64
+	public String[] handles() {
65
+		return new String[]{"301", "305", "306"};
66
+	} 
67
+	
68
+	/**
69
+	 * Create a new instance of the IRCProcessor Object.
70
+	 *
71
+	 * @param parser IRCParser That owns this IRCProcessor
72
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
73
+	 */
74
+	protected ProcessAway (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
75
+
76
+}

+ 73
- 0
src/com/dmdirc/parser/irc/ProcessInvite.java View File

@@ -0,0 +1,73 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process an Invite Request.
27
+ */
28
+public class ProcessInvite extends IRCProcessor {
29
+	/**
30
+	 * Process an Invite Request.
31
+	 *
32
+	 * @param sParam Type of line to process ("INVITE")
33
+	 * @param token IRCTokenised line to process
34
+	 */
35
+	@Override
36
+	public void process(final String sParam, final String[] token) {
37
+		// :Tobavaj!shane@Tobavaj.users.quakenet.org INVITE Dataforce #dataforceisgod 1188846462
38
+		if (token.length > 2) {
39
+			callInvite(token[0].substring(1), token[3]);
40
+		}
41
+	}
42
+	
43
+	/**
44
+	 * Callback to all objects implementing the Invite Callback.
45
+	 *
46
+	 * @see IInvite
47
+	 * @param userHost The hostname of the person who invited us
48
+	 * @param channel The name of the channel we were invited to
49
+	 * @return true if a method was called, false otherwise
50
+	 */
51
+	protected boolean callInvite(final String userHost, final String channel) {
52
+		return getCallbackManager().getCallbackType("OnInvite").call(userHost, channel);
53
+	}
54
+	
55
+	/**
56
+	 * What does this IRCProcessor handle.
57
+	 *
58
+	 * @return String[] with the names of the tokens we handle.
59
+	 */
60
+	@Override
61
+	public String[] handles() {
62
+		return new String[]{"INVITE"};
63
+	} 
64
+	
65
+	/**
66
+	 * Create a new instance of the IRCProcessor Object.
67
+	 *
68
+	 * @param parser IRCParser That owns this IRCProcessor
69
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
70
+	 */
71
+	protected ProcessInvite (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
72
+
73
+}

+ 141
- 0
src/com/dmdirc/parser/irc/ProcessJoin.java View File

@@ -0,0 +1,141 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process a channel join.
27
+ */
28
+public class ProcessJoin extends IRCProcessor {
29
+
30
+	/**
31
+	 * Process a channel join.
32
+	 *
33
+	 * @param sParam Type of line to process ("JOIN")
34
+	 * @param token IRCTokenised line to process
35
+	 */
36
+	@Override
37
+	public void process(final String sParam, final String[] token) {
38
+		if (sParam.equals("329")) {
39
+			if (token.length < 5) { return; }
40
+			ChannelInfo iChannel = myParser.getChannelInfo(token[3]);
41
+			if (iChannel != null) {
42
+				try {
43
+					iChannel.setCreateTime(Integer.parseInt(token[4]));
44
+				} catch (NumberFormatException nfe) { /* Oh well, not a normal ircd I guess */ }
45
+			}
46
+		} else {
47
+			// :nick!ident@host JOIN (:)#Channel
48
+			Byte nTemp;
49
+			if (token.length < 3) { return; }
50
+			ClientInfo iClient;
51
+			ChannelInfo iChannel;
52
+			ChannelClientInfo iChannelClient;
53
+			
54
+			iClient = myParser.getClientInfo(token[0]);
55
+			iChannel = myParser.getChannelInfo(token[token.length-1]);
56
+			
57
+			if (iClient == null) { 
58
+				iClient = new ClientInfo(myParser, token[0]);
59
+				myParser.addClient(iClient);
60
+			}
61
+			// Check to see if we know the host/ident for this client to facilitate dmdirc Formatter
62
+			if (iClient.getHost().isEmpty()) { iClient.setUserBits(token[0],false); }
63
+			if (iChannel != null) {
64
+				if (iClient == myParser.getMyself()) {
65
+					try {
66
+						if (iChannel.getUser(iClient) != null) {
67
+							// If we are joining a channel we are already on, fake a part from
68
+							// the channel internally, and rejoin.
69
+							myParser.getProcessingManager().process("PART", token);
70
+						} else {
71
+							// Otherwise we have a channel known, that we are not in?
72
+							myParser.callErrorInfo(new ParserError(ParserError.ERROR_FATAL, "Joined known channel that we wern't already on..", myParser.getLastLine()));
73
+						}
74
+					} catch (ProcessorNotFoundException e) { }
75
+				} else if (iChannel.getUser(iClient) != null) {
76
+					// Client joined channel that we already know of.
77
+					return;
78
+				} else {
79
+					// This is only done if we are already the channel, and it isn't us that
80
+					// joined.
81
+					iChannelClient = iChannel.addClient(iClient);
82
+					callChannelJoin(iChannel, iChannelClient);
83
+					return;
84
+				}
85
+			}
86
+			//if (iClient != myParser.getMyself()) {
87
+				// callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got join for channel ("+token[token.length-1]+") that I am not on. [Me: "+myParser.getMyself()+"]", myParser.getLastLine()));
88
+			//}
89
+			iChannel = new ChannelInfo(myParser, token[token.length-1]);
90
+			// Add ourself to the channel, this will be overridden by the NAMES reply
91
+			iChannel.addClient(iClient);
92
+			myParser.addChannel(iChannel);
93
+			sendString("MODE "+iChannel.getName());
94
+			
95
+			callChannelSelfJoin(iChannel);
96
+		}
97
+	}
98
+	
99
+
100
+	/**
101
+	 * Callback to all objects implementing the ChannelJoin Callback.
102
+	 *
103
+	 * @see IChannelJoin
104
+	 * @param cChannel Channel Object
105
+	 * @param cChannelClient ChannelClient object for new person
106
+	 * @return true if a method was called, false otherwise
107
+	 */
108
+	protected boolean callChannelJoin(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient) {
109
+		return getCallbackManager().getCallbackType("OnChannelJoin").call(cChannel, cChannelClient);
110
+	}
111
+	
112
+	/**
113
+	 * Callback to all objects implementing the ChannelSelfJoin Callback.
114
+	 *
115
+	 * @see IChannelSelfJoin
116
+	 * @param cChannel Channel Object
117
+	 * @return true if a method was called, false otherwise
118
+	 */
119
+	protected boolean callChannelSelfJoin(final ChannelInfo cChannel) {
120
+		return  getCallbackManager().getCallbackType("OnChannelSelfJoin").call(cChannel);
121
+	}
122
+	
123
+	/**
124
+	 * What does this IRCProcessor handle.
125
+	 *
126
+	 * @return String[] with the names of the tokens we handle.
127
+	 */
128
+	@Override
129
+	public String[] handles() {
130
+		return new String[]{"JOIN", "329"};
131
+	} 
132
+	
133
+	/**
134
+	 * Create a new instance of the IRCProcessor Object.
135
+	 *
136
+	 * @param parser IRCParser That owns this IRCProcessor
137
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
138
+	 */
139
+	protected ProcessJoin (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
140
+
141
+}

+ 112
- 0
src/com/dmdirc/parser/irc/ProcessKick.java View File

@@ -0,0 +1,112 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process a channel kick.
27
+ */
28
+public class ProcessKick extends IRCProcessor {
29
+
30
+	/**
31
+	 * Process a channel kick.
32
+	 *
33
+	 * @param sParam Type of line to process ("KICK")
34
+	 * @param token IRCTokenised line to process
35
+	 */
36
+	@Override
37
+	public void process(final String sParam, final String[] token) {
38
+		ChannelClientInfo iChannelClient;
39
+		ChannelClientInfo iChannelKicker;
40
+		ChannelInfo iChannel;
41
+		ClientInfo iClient;
42
+		ClientInfo iKicker;
43
+		String sReason = "";
44
+		
45
+		iClient = getClientInfo(token[3]);
46
+		iKicker = getClientInfo(token[0]);
47
+		iChannel = getChannelInfo(token[2]);
48
+		
49
+		if (iClient == null) { return; }
50
+		
51
+		if (IRCParser.ALWAYS_UPDATECLIENT && iKicker != null) {
52
+			// To facilitate dmdirc formatter, get user information
53
+			if (iKicker.getHost().isEmpty()) { iKicker.setUserBits(token[0],false); }
54
+		}
55
+
56
+		if (iChannel == null) { 
57
+			if (iClient != myParser.getMyself()) {
58
+				callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got kick for channel ("+token[2]+") that I am not on. [User: "+token[3]+"]", myParser.getLastLine()));
59
+			}
60
+			return;
61
+		} else {
62
+			if (token.length > 4) { sReason = token[token.length-1]; }
63
+			iChannelClient = iChannel.getUser(iClient);
64
+			if (iChannelClient == null) {
65
+				// callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got kick for channel ("+token[2]+") for a non-existant user. [User: "+token[0]+"]", myParser.getLastLine()));
66
+				return;
67
+			}
68
+			iChannelKicker = iChannel.getUser(token[0]);
69
+			if (myParser.removeAfterCallback) { callChannelKick(iChannel,iChannelClient,iChannelKicker,sReason,token[0]); }
70
+			iChannel.delClient(iClient);
71
+			if (!myParser.removeAfterCallback) { callChannelKick(iChannel,iChannelClient,iChannelKicker,sReason,token[0]); }
72
+			if (iClient == myParser.getMyself()) {
73
+				iChannel.emptyChannel();
74
+				myParser.removeChannel(iChannel);
75
+			}
76
+		}
77
+	}
78
+	
79
+	/**
80
+	 * Callback to all objects implementing the ChannelKick Callback.
81
+	 *
82
+	 * @see IChannelKick
83
+	 * @param cChannel Channel where the kick took place
84
+	 * @param cKickedClient ChannelClient that got kicked
85
+	 * @param cKickedByClient ChannelClient that did the kicking (may be null if server)
86
+	 * @param sReason Reason for kick (may be "")
87
+	 * @param sKickedByHost Hostname of Kicker (or servername)
88
+	 * @return true if a method was called, false otherwise
89
+	 */
90
+	protected boolean callChannelKick(ChannelInfo cChannel, ChannelClientInfo cKickedClient, ChannelClientInfo cKickedByClient, String sReason, String sKickedByHost) {
91
+		return getCallbackManager().getCallbackType("OnChannelKick").call(cChannel, cKickedClient, cKickedByClient, sReason, sKickedByHost);
92
+	}
93
+	
94
+	/**
95
+	 * What does this IRCProcessor handle.
96
+	 *
97
+	 * @return String[] with the names of the tokens we handle.
98
+	 */
99
+	@Override
100
+	public String[] handles() {
101
+		return new String[]{"KICK"};
102
+	} 
103
+	
104
+	/**
105
+	 * Create a new instance of the IRCProcessor Object.
106
+	 *
107
+	 * @param parser IRCParser That owns this IRCProcessor
108
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
109
+	 */
110
+	protected ProcessKick (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
111
+
112
+}

+ 220
- 0
src/com/dmdirc/parser/irc/ProcessListModes.java View File

@@ -0,0 +1,220 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import java.util.List;
26
+import java.util.LinkedList;
27
+import java.util.Queue;
28
+
29
+/**
30
+ * Process a List Modes.
31
+ */
32
+public class ProcessListModes extends IRCProcessor {
33
+	/**
34
+	 * Process a ListModes.
35
+	 *
36
+	 * @param sParam Type of line to process
37
+	 * @param token IRCTokenised line to process
38
+	 */
39
+	@SuppressWarnings("unchecked")
40
+	@Override
41
+	public void process(String sParam, String[] token) {
42
+		ChannelInfo channel = getChannelInfo(token[3]);
43
+		String thisIRCD = myParser.getIRCD(true).toLowerCase();
44
+		String item = "";
45
+		String owner = "";
46
+		byte tokenStart = 4; // Where do the relevent tokens start?
47
+		boolean isCleverMode = false;
48
+		long time = 0;
49
+		char mode = 'b';
50
+		boolean isItem = true; // true if item listing, false if "end of .." item
51
+		if (channel == null) { return; }
52
+		
53
+		if (sParam.equals("367") || sParam.equals("368")) {
54
+			// Ban List/Item.
55
+			// (Also used for +d and +q on hyperion... -_-)
56
+			mode = 'b';
57
+			isItem = sParam.equals("367");
58
+		} else if (sParam.equals("348") || sParam.equals("349")) {
59
+			// Except / Exempt List etc
60
+			mode = 'e';
61
+			isItem = sParam.equals("348");
62
+		} else if (sParam.equals("346") || sParam.equals("347")) {
63
+			// Invite List
64
+			mode = 'I';
65
+			isItem = sParam.equals("346");
66
+		} else if (sParam.equals("940") || sParam.equals("941")) {
67
+			// Censored words List
68
+			mode = 'g';
69
+			isItem = sParam.equals("941");
70
+		} else if (sParam.equals("344") || sParam.equals("345")) {
71
+			// Reop List, or bad words list, or quiet list. god damn.
72
+			if (thisIRCD.equals("euircd")) {
73
+				mode = 'w';
74
+			} else if (thisIRCD.equals("oftc-hybrid")) {
75
+				mode = 'q';
76
+			} else {
77
+				mode = 'R';
78
+			}
79
+			isItem = sParam.equals("344");
80
+		} else if (thisIRCD.equals("swiftirc") && (sParam.equals("386") || sParam.equals("387"))) {
81
+			// Channel Owner list
82
+			mode = 'q';
83
+			isItem = sParam.equals("387");
84
+		} else if (thisIRCD.equals("swiftirc") && (sParam.equals("388") || sParam.equals("389"))) {
85
+			// Protected User list
86
+			mode = 'a';
87
+			isItem = sParam.equals("389");
88
+		} else if (sParam.equals(myParser.h005Info.get("LISTMODE")) || sParam.equals(myParser.h005Info.get("LISTMODEEND"))) {
89
+			// Support for potential future decent mode listing in the protocol
90
+			//
91
+			// See my proposal: http://shane.dmdirc.com/listmodes.php
92
+			mode = token[4].charAt(0);
93
+			isItem = sParam.equals(myParser.h005Info.get("LISTMODE"));
94
+			tokenStart = 5;
95
+			isCleverMode = true;
96
+		}
97
+		
98
+		final Queue<Character> listModeQueue = channel.getListModeQueue();
99
+		if (!isCleverMode && listModeQueue != null) {
100
+			if (sParam.equals("482")) {
101
+				myParser.callDebugInfo(IRCParser.DEBUG_LMQ, "Dropped LMQ mode "+listModeQueue.poll());
102
+				return;
103
+			} else {
104
+				if (listModeQueue.peek() != null) {
105
+					Character oldMode = mode;
106
+					mode = listModeQueue.peek();
107
+					myParser.callDebugInfo(IRCParser.DEBUG_LMQ, "LMQ says this is "+mode);
108
+					
109
+					boolean error = true;
110
+					
111
+					if ((thisIRCD.equals("hyperion") || thisIRCD.equals("dancer")) && (mode == 'b' || mode == 'q')) {
112
+						LinkedList<Character> lmq = (LinkedList<Character>)listModeQueue;
113
+						if (mode == 'b') {
114
+							error = !(oldMode == 'q');
115
+							lmq.remove((Character)'q');
116
+							myParser.callDebugInfo(IRCParser.DEBUG_LMQ, "Dropping q from list");
117
+						} else if (mode == 'q') {
118
+							error = !(oldMode == 'b');
119
+							lmq.remove((Character)'b');
120
+							myParser.callDebugInfo(IRCParser.DEBUG_LMQ, "Dropping b from list");
121
+						}
122
+					}
123
+					
124
+					if (oldMode != mode && error) {
125
+						myParser.callDebugInfo(IRCParser.DEBUG_LMQ, "LMQ disagrees with guess. LMQ: "+mode+" Guess: "+oldMode);
126
+						myParser.callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "LMQ disagrees with guess. LMQ: "+mode+" Guess: "+oldMode, myParser.getLastLine()));
127
+					}
128
+					
129
+					if (!isItem) {
130
+						listModeQueue.poll();
131
+					}
132
+				}
133
+			}
134
+		}
135
+		
136
+		if (isItem) {
137
+			if ((!isCleverMode) && listModeQueue == null && (thisIRCD.equals("hyperion") || thisIRCD.equals("dancer")) && token.length > 4 && mode == 'b') {
138
+				// Assume mode is a 'd' mode
139
+				mode = 'd';
140
+				// Now work out if its not (or attempt to.)
141
+				int identstart = token[tokenStart].indexOf('!');
142
+				int hoststart = token[tokenStart].indexOf('@');
143
+				// Check that ! and @ are both in the string - as required by +b and +q
144
+				if ((identstart >= 0) && (identstart < hoststart)) {
145
+					if (thisIRCD.equals("hyperion") && token[tokenStart].charAt(0) == '%') { mode = 'q'; }
146
+					else { mode = 'b'; }
147
+				}
148
+			} // End Hyperian stupidness of using the same numeric for 3 different things..
149
+			
150
+			if (!channel.getAddState(mode)) {
151
+				callDebugInfo(IRCParser.DEBUG_INFO, "New List Mode Batch ("+mode+"): Clearing!");
152
+				final List<ChannelListModeItem> list = channel.getListModeParam(mode);
153
+				if (list == null) {
154
+					myParser.callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got list mode: '"+mode+"' - but channel object doesn't agree.", myParser.getLastLine()));
155
+				} else {
156
+					list.clear();
157
+				}
158
+				channel.setAddState(mode, true);
159
+			}
160
+			
161
+			if (token.length > (tokenStart+2)) {
162
+				try { time = Long.parseLong(token[tokenStart+2]); } catch (NumberFormatException e) { time = 0; }
163
+			}
164
+			if (token.length > (tokenStart+1)) { owner = token[tokenStart+1]; }
165
+			if (token.length > tokenStart) { item = token[tokenStart]; }
166
+			if (!item.isEmpty()) {
167
+				ChannelListModeItem clmi = new ChannelListModeItem(item, owner, time);
168
+				callDebugInfo(IRCParser.DEBUG_INFO, "List Mode: %c [%s/%s/%d]",mode, item, owner, time);
169
+				channel.setListModeParam(mode, clmi, true);
170
+			}
171
+		} else {
172
+			callDebugInfo(IRCParser.DEBUG_INFO, "List Mode Batch over");
173
+			channel.resetAddState();
174
+			if (isCleverMode || listModeQueue == null || ((LinkedList<Character>)listModeQueue).size() == 0) {
175
+				callDebugInfo(IRCParser.DEBUG_INFO, "Calling GotListModes");
176
+				channel.setHasGotListModes(true);
177
+				callChannelGotListModes(channel);
178
+			}
179
+		}
180
+	}
181
+	
182
+	/**
183
+	 * What does this IRCProcessor handle.
184
+	 *
185
+	 * @return String[] with the names of the tokens we handle.
186
+	 */
187
+	@Override
188
+	public String[] handles() {
189
+		return new String[]{"367", "368",  /* Bans */
190
+		                    "344", "345",  /* Reop list (ircnet) or bad words (euirc) */
191
+		                    "346", "347",  /* Invite List */
192
+		                    "348", "349",  /* Except/Exempt List */
193
+		                    "386", "387",  /* Channel Owner List (swiftirc ) */
194
+		                    "388", "389",  /* Protected User List (swiftirc) */
195
+		                    "940", "941",  /* Censored words list */
196
+		                    "482",         /* Permission Denied */
197
+		                    "__LISTMODE__" /* Sensible List Modes */
198
+		                   };
199
+	}
200
+	
201
+	/**
202
+	 * Callback to all objects implementing the ChannelGotListModes Callback.
203
+	 *
204
+	 * @see IChannelGotListModes
205
+	 * @param cChannel Channel which the ListModes reply is for
206
+	 * @return true if a method was called, false otherwise
207
+	 */
208
+	protected boolean callChannelGotListModes(ChannelInfo cChannel) {
209
+		return getCallbackManager().getCallbackType("OnChannelGotListModes").call(cChannel);
210
+	}
211
+	
212
+	/**
213
+	 * Create a new instance of the IRCProcessor Object.
214
+	 *
215
+	 * @param parser IRCParser That owns this IRCProcessor
216
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
217
+	 */
218
+	protected ProcessListModes (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
219
+
220
+}

+ 103
- 0
src/com/dmdirc/parser/irc/ProcessMOTD.java View File

@@ -0,0 +1,103 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process a MOTD Related Line.
27
+ */
28
+public class ProcessMOTD extends IRCProcessor {
29
+
30
+	/**
31
+	 * Process a MOTD Related Line.
32
+	 *
33
+	 * @param sParam Type of line to process ("375", "372", "376", "422")
34
+	 * @param token IRCTokenised line to process
35
+	 */
36
+	@Override
37
+	public void process(String sParam, String[] token) {
38
+		if (sParam.equals("375")) {
39
+			callMOTDStart(token[token.length-1]);
40
+		} else if (sParam.equals("372")) {
41
+			callMOTDLine(token[token.length-1]);
42
+		} else {
43
+			if (!myParser.h005Info.containsKey("CHANTYPES")) { myParser.parseChanPrefix(); }
44
+			if (!myParser.h005Info.containsKey("PREFIX")) { myParser.parsePrefixModes(); }
45
+			if (!myParser.h005Info.containsKey("USERMODES")) { myParser.parseUserModes(); }
46
+			if (!myParser.h005Info.containsKey("CHANMODES")) { myParser.parseChanModes(); }
47
+			callMOTDEnd(sParam.equals("422"), token[token.length-1]);
48
+		}
49
+	}
50
+	
51
+	/**
52
+	 * Callback to all objects implementing the MOTDEnd Callback.
53
+	 *
54
+	 * @param noMOTD Was this an MOTDEnd or NoMOTD
55
+	 * @param data The contents of the line (incase of language changes or so)
56
+	 * @see IMOTDEnd
57
+	 * @return true if a method was called, false otherwise
58
+	 */
59
+	protected boolean callMOTDEnd(final boolean noMOTD, final String data) {
60
+		return getCallbackManager().getCallbackType("OnMOTDEnd").call(noMOTD, data);
61
+	}
62
+	
63
+	/**
64
+	 * Callback to all objects implementing the MOTDLine Callback.
65
+	 *
66
+	 * @see IMOTDLine
67
+	 * @param data Incomming Line.
68
+	 * @return true if a method was called, false otherwise
69
+	 */
70
+	protected boolean callMOTDLine(final String data) {
71
+		return getCallbackManager().getCallbackType("OnMOTDLine").call(data);
72
+	}
73
+	
74
+	/**
75
+	 * Callback to all objects implementing the MOTDStart Callback.
76
+	 *
77
+	 * @see IMOTDStart
78
+	 * @param data Incomming Line.
79
+	 * @return true if a method was called, false otherwise
80
+	 */
81
+	protected boolean callMOTDStart(String data) {
82
+		return getCallbackManager().getCallbackType("OnMOTDStart").call(data);
83
+	}
84
+	
85
+	/**
86
+	 * What does this IRCProcessor handle.
87
+	 *
88
+	 * @return String[] with the names of the tokens we handle.
89
+	 */
90
+	@Override
91
+	public String[] handles() {
92
+		return new String[]{"372", "375", "376", "422"};
93
+	} 
94
+	
95
+	/**
96
+	 * Create a new instance of the IRCProcessor Object.
97
+	 *
98
+	 * @param parser IRCParser That owns this IRCProcessor
99
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
100
+	 */
101
+	protected ProcessMOTD (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
102
+
103
+}

+ 419
- 0
src/com/dmdirc/parser/irc/ProcessMessage.java View File

@@ -0,0 +1,419 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import java.util.regex.PatternSyntaxException;
26
+
27
+/**
28
+ * Process PRIVMSGs and NOTICEs.
29
+ * This horrible handles PRIVMSGs and NOTICES<br>
30
+ * This inclues CTCPs and CTCPReplies<br>
31
+ * It handles all 3 targets (Channel, Private, Unknown)<br>
32
+ * Actions are handled here aswell separately from CTCPs.<br>
33
+ * Each type has 5 Calls, making 15 callbacks handled here.
34
+ */
35
+public class ProcessMessage extends IRCProcessor {
36
+	/**
37
+	 * Process PRIVMSGs and NOTICEs.
38
+	 * This horrible thing handles PRIVMSGs and NOTICES<br>
39
+	 * This inclues CTCPs and CTCPReplies<br>
40
+	 * It handles all 3 targets (Channel, Private, Unknown)<br>
41
+	 * Actions are handled here aswell separately from CTCPs.<br>
42
+	 * Each type has 5 Calls, making 15 callbacks handled here.
43
+	 *
44
+	 * @param sParam Type of line to process ("NOTICE", "PRIVMSG")
45
+	 * @param token IRCTokenised line to process
46
+	 */
47
+	@Override
48
+	public void process(final String sParam, String[] token) {
49
+		// Ignore people!
50
+		String sMessage = "";
51
+		if (token[0].charAt(0) == ':') { sMessage = token[0].substring(1); } else { sMessage = token[0]; }
52
+		// We use sMessage to be the users host (first token in the line)
53
+		try {
54
+			if (myParser.getIgnoreList().matches(sMessage) > -1) { return; }
55
+		} catch (PatternSyntaxException pse) {
56
+			final ParserError pe = new ParserError(ParserError.ERROR_WARNING, "Error with ignore list regex: "+pse, myParser.getLastLine());
57
+			pe.setException(pse);
58
+			callErrorInfo(pe);
59
+		}
60
+		
61
+		// Lines such as:
62
+		// "nick!user@host PRIVMSG"
63
+		// are invalid, stop processing.
64
+		if (token.length < 3) { return; }
65
+		
66
+		// Is this actually a notice auth?
67
+		if (token[0].indexOf('!') == -1 && token[1].equalsIgnoreCase("NOTICE") && token[2].equalsIgnoreCase("AUTH")) {
68
+			try {
69
+				myParser.getProcessingManager().process("Notice Auth", token);
70
+			} catch (ProcessorNotFoundException e) { }
71
+			return;
72
+		}
73
+		
74
+		ChannelClientInfo iChannelClient = null;
75
+		ChannelInfo iChannel = null;
76
+		ClientInfo iClient = null;
77
+		// "nick!user@host PRIVMSG #Channel" should be processed as "nick!user@host PRIVMSG #Channel :"
78
+		if (token.length < 4) {
79
+			sMessage = "";
80
+		} else {
81
+			sMessage = token[token.length-1];
82
+		}
83
+		String bits[] = sMessage.split(" ", 2);
84
+		final Character Char1 = Character.valueOf((char)1);
85
+		String sCTCP = "";
86
+		boolean isAction = false;
87
+		boolean isCTCP = false;
88
+		
89
+		if (sMessage.length() > 1) {
90
+			if (sParam.equalsIgnoreCase("PRIVMSG")) {
91
+				// Actions are special CTCPs
92
+				// Bits is the message been split into 2 parts, the first word and the rest
93
+				if (bits[0].equalsIgnoreCase(Char1+"ACTION") && Character.valueOf(sMessage.charAt(sMessage.length()-1)).equals(Char1)) {
94
+					isAction = true;
95
+					if (bits.length > 1) {
96
+						sMessage = bits[1];
97
+						sMessage = sMessage.substring(0, sMessage.length()-1);
98
+					} else { sMessage = ""; }
99
+				}
100
+			}
101
+			// If the message is not an action, check if it is another type of CTCP
102
+			if (!isAction) {
103
+				// CTCPs have Character(1) at the start/end of the line
104
+				if (Character.valueOf(sMessage.charAt(0)).equals(Char1) && Character.valueOf(sMessage.charAt(sMessage.length()-1)).equals(Char1)) {
105
+					isCTCP = true;
106
+					// Bits is the message been split into 2 parts, the first word and the rest
107
+					// Some CTCPs have messages and some do not
108
+					if (bits.length > 1) { sMessage = bits[1]; } else { sMessage = ""; }
109
+					// Remove the leading char1
110
+					bits = bits[0].split(Char1.toString(),2);
111
+					sCTCP = bits[1];
112
+					// remove the trailing char1
113
+					if (!sMessage.isEmpty()) { sMessage = sMessage.split(Char1.toString(),2)[0]; }
114
+					else { sCTCP = sCTCP.split(Char1.toString(),2)[0]; }
115
+					callDebugInfo(IRCParser.DEBUG_INFO, "CTCP: \"%s\" \"%s\"",sCTCP,sMessage);
116
+				}
117
+			}
118
+		}
119
+
120
+		// Remove the leading : from the host.
121
+		if (token[0].charAt(0) == ':' && token[0].length() > 1) { token[0] = token[0].substring(1); }
122
+
123
+		iClient = getClientInfo(token[0]);
124
+		if (IRCParser.ALWAYS_UPDATECLIENT && iClient != null) {
125
+			// Facilitate DMDIRC Formatter
126
+			if (iClient.getHost().isEmpty()) {iClient.setUserBits(token[0],false); }
127
+		}
128
+		
129
+		// Fire the appropriate callbacks.
130
+		// OnChannel* Callbacks are fired if the target was a channel
131
+		// OnPrivate* Callbacks are fired if the target was us
132
+		// OnUnknown* Callbacks are fired if the target was neither of the above
133
+		// Actions and CTCPs are send as PRIVMSGS
134
+		// CTCPReplies are sent as Notices
135
+		if (isValidChannelName(token[2])) {
136
+			iChannel = getChannelInfo(token[2]);
137
+			if (iChannel == null) {
138
+				// callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got message for channel ("+token[2]+") that I am not on.", myParser.getLastLine()));
139
+				return;
140
+			}
141
+			if (iClient != null) { iChannelClient = iChannel.getUser(iClient); }
142
+			if (sParam.equalsIgnoreCase("PRIVMSG")) {
143
+				if (!isAction) {
144
+					if (isCTCP) {
145
+						callChannelCTCP(iChannel, iChannelClient, sCTCP, sMessage, token[0]);
146
+					} else {
147
+						callChannelMessage(iChannel, iChannelClient, sMessage, token[0]);
148
+					}
149
+				} else {
150
+					callChannelAction(iChannel, iChannelClient, sMessage, token[0]);
151
+				}
152
+			} else if (sParam.equalsIgnoreCase("NOTICE")) {
153
+				if (isCTCP) {
154
+					callChannelCTCPReply(iChannel, iChannelClient, sCTCP, sMessage, token[0]);
155
+				} else {
156
+					callChannelNotice(iChannel, iChannelClient, sMessage, token[0]);
157
+				}
158
+			}
159
+		} else if (myParser.getIRCStringConverter().equalsIgnoreCase(token[2], myParser.getMyNickname())) {
160
+			if (sParam.equalsIgnoreCase("PRIVMSG")) {
161
+				if (!isAction) {
162
+					if (isCTCP) {
163
+						callPrivateCTCP(sCTCP, sMessage, token[0]);
164
+					} else {
165
+						callPrivateMessage(sMessage, token[0]);
166
+					}
167
+				} else {
168
+					callPrivateAction(sMessage, token[0]);
169
+				}
170
+			} else if (sParam.equalsIgnoreCase("NOTICE")) {
171
+				if (isCTCP) {
172
+					callPrivateCTCPReply(sCTCP, sMessage, token[0]);
173
+				} else {
174
+					callPrivateNotice(sMessage, token[0]);
175
+				}
176
+			}
177
+		} else {
178
+			callDebugInfo(IRCParser.DEBUG_INFO, "Message for Other ("+token[2]+")");
179
+			if (sParam.equalsIgnoreCase("PRIVMSG")) {
180
+				if (!isAction) {
181
+					if (isCTCP) {
182
+						callUnknownCTCP(sCTCP, sMessage, token[2], token[0]);
183
+					} else {
184
+						callUnknownMessage(sMessage, token[2], token[0]);
185
+					}
186
+				} else {
187
+					callUnknownAction(sMessage, token[2], token[0]);
188
+				}
189
+			} else if (sParam.equalsIgnoreCase("NOTICE")) {
190
+				if (isCTCP) {
191
+					callUnknownCTCPReply(sCTCP, sMessage, token[2], token[0]);
192
+				} else {
193
+					callUnknownNotice(sMessage, token[2], token[0]);
194
+				}
195
+			}
196
+		}
197
+	}
198
+	
199
+	/**
200
+	 * Callback to all objects implementing the ChannelAction Callback.
201
+	 *
202
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelAction
203
+	 * @param cChannel Channel where the action was sent to
204
+	 * @param cChannelClient ChannelClient who sent the action (may be null if server)
205
+	 * @param sMessage action contents
206
+	 * @param sHost Hostname of sender (or servername)
207
+	 * @return true if a method was called, false otherwise
208
+	 */
209
+	protected boolean callChannelAction(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
210
+		return getCallbackManager().getCallbackType("OnChannelAction").call(cChannel, cChannelClient, sMessage, sHost);
211
+	}
212
+	
213
+	/**
214
+	 * Callback to all objects implementing the ChannelCTCP Callback.
215
+	 *
216
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelCTCP
217
+	 * @param cChannel Channel where CTCP was sent
218
+	 * @param cChannelClient ChannelClient who sent the message (may be null if server)
219
+	 * @param sType Type of CTCP (VERSION, TIME etc)
220
+	 * @param sMessage Additional contents
221
+	 * @param sHost Hostname of sender (or servername)
222
+	 * @return true if a method was called, false otherwise
223
+	 */
224
+	protected boolean callChannelCTCP(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sType, final String sMessage, final String sHost) {
225
+		return getCallbackManager().getCallbackType("OnChannelCTCP").call(cChannel, cChannelClient, sType, sMessage, sHost);
226
+	}
227
+
228
+	/**
229
+	 * Callback to all objects implementing the ChannelCTCPReply Callback.
230
+	 *
231
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelCTCPReply
232
+	 * @param cChannel Channel where CTCPReply was sent
233
+	 * @param cChannelClient ChannelClient who sent the message (may be null if server)
234
+	 * @param sType Type of CTCPRReply (VERSION, TIME etc)
235
+	 * @param sMessage Reply Contents
236
+	 * @param sHost Hostname of sender (or servername)
237
+	 * @return true if a method was called, false otherwise
238
+	 */
239
+	protected boolean callChannelCTCPReply(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sType, final String sMessage, final String sHost) {
240
+		return getCallbackManager().getCallbackType("OnChannelCTCPReply").call(cChannel, cChannelClient, sType, sMessage, sHost);
241
+	}
242
+	
243
+	/**
244
+	 * Callback to all objects implementing the ChannelMessage Callback.
245
+	 *
246
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelMessage
247
+	 * @param cChannel Channel where the message was sent to
248
+	 * @param cChannelClient ChannelClient who sent the message (may be null if server)
249
+	 * @param sMessage Message contents
250
+	 * @param sHost Hostname of sender (or servername)
251
+	 * @return true if a method was called, false otherwise
252
+	 */
253
+	protected boolean callChannelMessage(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
254
+		return getCallbackManager().getCallbackType("OnChannelMessage").call(cChannel, cChannelClient, sMessage, sHost);
255
+	}
256
+	
257
+	/**
258
+	 * Callback to all objects implementing the ChannelNotice Callback.
259
+	 *
260
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IChannelNotice
261
+	 * @param cChannel Channel where the notice was sent to
262
+	 * @param cChannelClient ChannelClient who sent the notice (may be null if server)
263
+	 * @param sMessage notice contents
264
+	 * @param sHost Hostname of sender (or servername)
265
+	 * @return true if a method was called, false otherwise
266
+	 */
267
+	protected boolean callChannelNotice(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sMessage, final String sHost) {
268
+		return getCallbackManager().getCallbackType("OnChannelNotice").call(cChannel, cChannelClient, sMessage, sHost);
269
+	}
270
+	
271
+	/**
272
+	 * Callback to all objects implementing the PrivateAction Callback.
273
+	 *
274
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IPrivateAction
275
+	 * @param sMessage action contents
276
+	 * @param sHost Hostname of sender (or servername)
277
+	 * @return true if a method was called, false otherwise
278
+	 */
279
+	protected boolean callPrivateAction(final String sMessage, final String sHost) {
280
+		return getCallbackManager().getCallbackType("OnPrivateAction").call(sMessage, sHost);
281
+	}
282
+
283
+	/**
284
+	 * Callback to all objects implementing the PrivateCTCP Callback.
285
+	 *
286
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IPrivateCTCP
287
+	 * @param sType Type of CTCP (VERSION, TIME etc)
288
+	 * @param sMessage Additional contents
289
+	 * @param sHost Hostname of sender (or servername)
290
+	 * @return true if a method was called, false otherwise
291
+	 */
292
+	protected boolean callPrivateCTCP(final String sType, final String sMessage, final String sHost) {
293
+		return getCallbackManager().getCallbackType("OnPrivateCTCP").call(sType, sMessage, sHost);
294
+	}
295
+
296
+	/**
297
+	 * Callback to all objects implementing the PrivateCTCPReply Callback.
298
+	 *
299
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IPrivateCTCPReply
300
+	 * @param sType Type of CTCPRReply (VERSION, TIME etc)
301
+	 * @param sMessage Reply Contents
302
+	 * @param sHost Hostname of sender (or servername)
303
+	 * @return true if a method was called, false otherwise
304
+	 */
305
+	protected boolean callPrivateCTCPReply(final String sType, final String sMessage, final String sHost) {
306
+		return getCallbackManager().getCallbackType("OnPrivateCTCPReply").call(sType, sMessage, sHost);
307
+	}
308
+
309
+	/**
310
+	 * Callback to all objects implementing the PrivateMessage Callback.
311
+	 *
312
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IPrivateMessage
313
+	 * @param sMessage Message contents
314
+	 * @param sHost Hostname of sender (or servername)
315
+	 * @return true if a method was called, false otherwise
316
+	 */
317
+	protected boolean callPrivateMessage(final String sMessage, final String sHost) {
318
+		return getCallbackManager().getCallbackType("OnPrivateMessage").call(sMessage, sHost);
319
+	}
320
+
321
+	/**
322
+	 * Callback to all objects implementing the PrivateNotice Callback.
323
+	 *
324
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IPrivateNotice
325
+	 * @param sMessage Notice contents
326
+	 * @param sHost Hostname of sender (or servername)
327
+	 * @return true if a method was called, false otherwise
328
+	 */
329
+	protected boolean callPrivateNotice(final String sMessage, final String sHost) {
330
+		return getCallbackManager().getCallbackType("OnPrivateNotice").call(sMessage, sHost);
331
+	}
332
+	
333
+	/**
334
+	 * Callback to all objects implementing the UnknownAction Callback.
335
+	 *
336
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IUnknownAction
337
+	 * @param sMessage Action contents
338
+	 * @param sTarget Actual target of action
339
+	 * @param sHost Hostname of sender (or servername)
340
+	 * @return true if a method was called, false otherwise
341
+	 */
342
+	protected boolean callUnknownAction(final String sMessage, final String sTarget, final String sHost) {
343
+		return getCallbackManager().getCallbackType("OnUnknownAction").call(sMessage, sTarget, sHost);
344
+	}
345
+
346
+	/**
347
+	 * Callback to all objects implementing the UnknownCTCP Callback.
348
+	 *
349
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IUnknownCTCP
350
+	 * @param sType Type of CTCP (VERSION, TIME etc)
351
+	 * @param sMessage Additional contents
352
+	 * @param sTarget Actual Target of CTCP
353
+	 * @param sHost Hostname of sender (or servername)
354
+	 * @return true if a method was called, false otherwise
355
+	 */
356
+	protected boolean callUnknownCTCP(final String sType, final String sMessage, final String sTarget, final String sHost) {
357
+		return getCallbackManager().getCallbackType("OnUnknownCTCP").call(sType, sMessage, sTarget, sHost);
358
+	}
359
+
360
+	/**
361
+	 * Callback to all objects implementing the UnknownCTCPReply Callback.
362
+	 *
363
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IUnknownCTCPReply
364
+	 * @param sType Type of CTCPRReply (VERSION, TIME etc)
365
+	 * @param sMessage Reply Contents
366
+	 * @param sTarget Actual Target of CTCPReply
367
+	 * @param sHost Hostname of sender (or servername)
368
+	 * @return true if a method was called, false otherwise
369
+	 */
370
+	protected boolean callUnknownCTCPReply(final String sType, final String sMessage, final String sTarget, final String sHost) {
371
+		return getCallbackManager().getCallbackType("OnUnknownCTCPReply").call(sType, sMessage, sTarget, sHost);
372
+	}
373
+
374
+	/**
375
+	 * Callback to all objects implementing the UnknownMessage Callback.
376
+	 *
377
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IUnknownMessage
378
+	 * @param sMessage Message contents
379
+	 * @param sTarget Actual target of message
380
+	 * @param sHost Hostname of sender (or servername)
381
+	 * @return true if a method was called, false otherwise
382
+	 */
383
+	protected boolean callUnknownMessage(final String sMessage, final String sTarget, final String sHost) {
384
+		return getCallbackManager().getCallbackType("OnUnknownMessage").call(sMessage, sTarget, sHost);
385
+	}
386
+
387
+	/**
388
+	 * Callback to all objects implementing the UnknownNotice Callback.
389
+	 *
390
+	 * @see com.dmdirc.parser.irc.callbacks.interfaces.IUnknownNotice
391
+	 * @param sMessage Notice contents
392
+	 * @param sTarget Actual target of notice
393
+	 * @param sHost Hostname of sender (or servername)
394
+	 * @return true if a method was called, false otherwise
395
+	 */
396
+	protected boolean callUnknownNotice(final String sMessage, final String sTarget, final String sHost) {
397
+		return getCallbackManager().getCallbackType("OnUnknownNotice").call(sMessage, sTarget, sHost);
398
+	}
399
+
400
+	
401
+	/**
402
+	 * What does this IRCProcessor handle.
403
+	 *
404
+	 * @return String[] with the names of the tokens we handle.
405
+	 */
406
+	@Override
407
+	public String[] handles() {
408
+		return new String[]{"PRIVMSG", "NOTICE"};
409
+	}
410
+	
411
+	/**
412
+	 * Create a new instance of the IRCProcessor Object.
413
+	 *
414
+	 * @param parser IRCParser That owns this IRCProcessor
415
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
416
+	 */
417
+	protected ProcessMessage (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
418
+
419
+}

+ 337
- 0
src/com/dmdirc/parser/irc/ProcessMode.java View File

@@ -0,0 +1,337 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.parser.irc.callbacks.CallbackObject;
26
+import java.util.Calendar;
27
+
28
+/**
29
+ * Process a Mode line.
30
+ */
31
+public class ProcessMode extends IRCProcessor {
32
+	/**
33
+	 * Process a Mode Line.
34
+	 *
35
+	 * @param sParam Type of line to process ("MODE", "324")
36
+	 * @param token IRCTokenised line to process
37
+	 */
38
+	@Override
39
+	public void process(String sParam, String[] token) {
40
+		String[] sModestr;
41
+		String sChannelName;
42
+		if (sParam.equals("324")) {
43
+			sChannelName = token[3];
44
+			sModestr = new String[token.length-4];
45
+			System.arraycopy(token, 4, sModestr, 0, token.length-4);
46
+		} else if (sParam.equals("221")) {
47
+			processUserMode(sParam, token, new String[]{token[token.length-1]}, true);
48
+			return;
49
+		} else {
50
+			sChannelName = token[2];
51
+			sModestr = new String[token.length-3];
52
+			System.arraycopy(token, 3, sModestr, 0, token.length-3);
53
+		}
54
+
55
+		if (!isValidChannelName(sChannelName)) { processUserMode(sParam, token, sModestr, false); }
56
+		else { processChanMode(sParam, token, sModestr, sChannelName); }
57
+	}
58
+	
59
+	/**
60
+	 * Method to trim spaces from strings
61
+	 *
62
+	 * @param str String to trim
63
+	 * @return String without spaces on the ends
64
+	 */
65
+	private String trim(String str) { return str.trim(); }
66
+	
67
+	/**
68
+	 * Process Chan modes.
69
+	 *
70
+	 * @param sParam String representation of parameter to parse
71
+	 * @param token IRCTokenised Array of the incomming line
72
+	 * @param sModestr The modes and params
73
+	 * @param sChannelName Channel these modes are for
74
+	 */	
75
+	public void processChanMode(String sParam, String token[], String sModestr[], String sChannelName) {
76
+		StringBuilder sFullModeStr = new StringBuilder();
77
+		String sNonUserModeStr = "";
78
+		String sNonUserModeStrParams = "";
79
+		String sModeParam;
80
+		String sTemp;
81
+		int nParam = 1;
82
+		long nTemp = 0, nValue = 0, nCurrent = 0;
83
+		boolean bPositive = true, bBooleanMode = true;
84
+		char cPositive = '+';
85
+		ChannelInfo iChannel;
86
+		ChannelClientInfo iChannelClientInfo;
87
+		ClientInfo iClient;
88
+		ChannelClientInfo setterCCI;
89
+		
90
+		CallbackObject cbSingle = null;
91
+		CallbackObject cbNonUser = null;
92
+
93
+		if (!sParam.equals("324")) {
94
+			cbSingle = getCallbackManager().getCallbackType("OnChannelSingleModeChanged");
95
+			cbNonUser = getCallbackManager().getCallbackType("OnChannelNonUserModeChanged");
96
+		}
97
+		
98
+		iChannel = getChannelInfo(sChannelName);
99
+		if (iChannel == null) { 
100
+			// callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got modes for channel ("+sChannelName+") that I am not on.", myParser.getLastLine()));
101
+			// iChannel = new ChannelInfo(myParser, sChannelName);
102
+			// myParser.addChannel(iChannel);
103
+			return;
104
+		}
105
+		// Get the current channel modes
106
+		if (!sParam.equals("324")) { nCurrent = iChannel.getMode(); }
107
+		
108
+		setterCCI = iChannel.getUser(token[0]);
109
+		if (IRCParser.ALWAYS_UPDATECLIENT && setterCCI != null) {
110
+			// Facilitate dmdirc formatter
111
+			if (setterCCI.getClient().getHost().isEmpty()) {setterCCI.getClient().setUserBits(token[0],false); }
112
+		}
113
+		
114
+		// Loop through the mode string, and add/remove modes/params where they are needed
115
+		for (int i = 0; i < sModestr[0].length(); ++i) {
116
+			Character cMode = sModestr[0].charAt(i);
117
+			if (cMode.equals(":".charAt(0))) { continue; }
118
+			
119
+			sNonUserModeStr = sNonUserModeStr+cMode;
120
+			if (cMode.equals("+".charAt(0))) { cPositive = '+'; bPositive = true; }
121
+			else if (cMode.equals("-".charAt(0))) { cPositive = '-'; bPositive = false; }
122
+			else {
123
+				if (myParser.hChanModesBool.containsKey(cMode)) { nValue = myParser.hChanModesBool.get(cMode); bBooleanMode = true; }
124
+				else if (myParser.hChanModesOther.containsKey(cMode)) { nValue = myParser.hChanModesOther.get(cMode); bBooleanMode = false; }
125
+				else if (myParser.hPrefixModes.containsKey(cMode)) { 
126
+					// (de) OP/Voice someone
127
+					if (sModestr.length <= nParam) {
128
+						myParser.callErrorInfo(new ParserError(ParserError.ERROR_FATAL + ParserError.ERROR_USER, "Broken Modes. Parameter required but not given.", myParser.getLastLine()));
129
+					}
130
+					sModeParam = sModestr[nParam++];
131
+					nValue = myParser.hPrefixModes.get(cMode);
132
+					callDebugInfo(IRCParser.DEBUG_INFO, "User Mode: %c / %d [%s] {Positive: %b}",cMode, nValue, sModeParam, bPositive);
133
+					iChannelClientInfo = iChannel.getUser(sModeParam);
134
+					if (iChannelClientInfo == null) {
135
+						// Client not known?
136
+//						callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got mode for client not known on channel - Added", myParser.getLastLine()));
137
+						iClient = getClientInfo(sModeParam);
138
+						if (iClient == null) { 
139
+//							callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got mode for client not known at all - Added", myParser.getLastLine()));
140
+							iClient = new ClientInfo(myParser, sModeParam);
141
+							myParser.addClient(iClient);
142
+						}
143
+						iChannelClientInfo = iChannel.addClient(iClient);
144
+					}
145
+					callDebugInfo(IRCParser.DEBUG_INFO, "\tOld Mode Value: %d",iChannelClientInfo.getChanMode());
146
+					if (bPositive) { iChannelClientInfo.setChanMode(iChannelClientInfo.getChanMode() | nValue); sTemp = "+"; }
147
+					else { iChannelClientInfo.setChanMode(iChannelClientInfo.getChanMode() ^ (iChannelClientInfo.getChanMode() & nValue)); sTemp = "-"; }
148
+					sTemp = sTemp+cMode;
149
+					callChannelUserModeChanged(iChannel, iChannelClientInfo, setterCCI, token[0], sTemp);
150
+					continue;
151
+				} else {
152
+					// unknown mode - add as boolean
153
+//					callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got unknown mode "+cMode+" - Added as boolean mode", myParser.getLastLine()));
154
+					myParser.hChanModesBool.put(cMode,myParser.nNextKeyCMBool);
155
+					nValue = myParser.nNextKeyCMBool;
156
+					bBooleanMode = true;
157
+					myParser.nNextKeyCMBool = myParser.nNextKeyCMBool*2;
158
+				}
159
+				
160
+				if (bBooleanMode) {
161
+					callDebugInfo(IRCParser.DEBUG_INFO, "Boolean Mode: %c [%d] {Positive: %b}",cMode, nValue, bPositive);
162
+					
163
+					if (bPositive) { nCurrent = nCurrent | nValue; }
164
+					else { nCurrent = nCurrent ^ (nCurrent & nValue); }
165
+				} else {
166
+					
167
+					if ((bPositive || nValue == IRCParser.MODE_LIST || ((nValue & IRCParser.MODE_UNSET) == IRCParser.MODE_UNSET)) && (sModestr.length <= nParam)) {
168
+						myParser.callErrorInfo(new ParserError(ParserError.ERROR_FATAL + ParserError.ERROR_USER, "Broken Modes. Parameter required but not given.", myParser.getLastLine()));
169
+					}
170
+					
171
+					if (nValue == IRCParser.MODE_LIST) {
172
+						// List Mode
173
+						sModeParam = sModestr[nParam++];
174
+						sNonUserModeStrParams = sNonUserModeStrParams+" "+sModeParam;
175
+						nTemp = (Calendar.getInstance().getTimeInMillis() / 1000);
176
+						iChannel.setListModeParam(cMode, new ChannelListModeItem(sModeParam, token[0], nTemp ), bPositive);
177
+						callDebugInfo(IRCParser.DEBUG_INFO, "List Mode: %c [%s] {Positive: %b}",cMode, sModeParam, bPositive);
178
+						if (cbSingle != null) { cbSingle.call(iChannel, setterCCI, token[0], cPositive+cMode+" "+sModeParam ); }
179
+					} else {
180
+						// Mode with a parameter
181
+						if (bPositive) { 
182
+							// +Mode - always needs a parameter to set
183
+							sModeParam = sModestr[nParam++];
184
+							sNonUserModeStrParams = sNonUserModeStrParams+" "+sModeParam;
185
+							callDebugInfo(IRCParser.DEBUG_INFO, "Set Mode: %c [%s] {Positive: %b}",cMode, sModeParam, bPositive);
186
+							iChannel.setModeParam(cMode,sModeParam);
187
+							if (cbSingle != null) { cbSingle.call(iChannel, setterCCI, token[0], cPositive+cMode+" "+sModeParam ); }
188
+						} else {
189
+							// -Mode - parameter isn't always needed, we need to check
190
+							if ((nValue & IRCParser.MODE_UNSET) == IRCParser.MODE_UNSET) {
191
+								sModeParam = sModestr[nParam++];
192
+								sNonUserModeStrParams = sNonUserModeStrParams+" "+sModeParam;
193
+							} else {
194
+								sModeParam = "";
195
+							}
196
+							callDebugInfo(IRCParser.DEBUG_INFO, "Unset Mode: %c [%s] {Positive: %b}",cMode, sModeParam, bPositive);
197
+							iChannel.setModeParam(cMode,"");
198
+							if (cbSingle != null) { cbSingle.call(iChannel, setterCCI, token[0], trim(cPositive+cMode+" "+sModeParam) ); }
199
+						}
200
+					}
201
+				}
202
+			}
203
+		}
204
+		
205
+		// Call Callbacks
206
+		for (int i = 0; i < sModestr.length; ++i) { sFullModeStr.append(sModestr[i]).append(" "); }
207
+		
208
+		iChannel.setMode(nCurrent);
209
+		if (sParam.equals("324")) { callChannelModeChanged(iChannel, null, "", sFullModeStr.toString().trim()); }
210
+		else { callChannelModeChanged(iChannel, setterCCI, token[0], sFullModeStr.toString().trim()); }
211
+		if (cbNonUser != null) { cbNonUser.call(iChannel, setterCCI, token[0], trim(sNonUserModeStr+sNonUserModeStrParams)); }
212
+	}
213
+	
214
+	/**
215
+	 * Process user modes.
216
+	 *
217
+	 * @param sParam String representation of parameter to parse
218
+	 * @param token IRCTokenised Array of the incomming line
219
+	 * @param clearOldModes Clear old modes before applying these modes (used by 221)
220
+	 */	
221
+	private void processUserMode(String sParam, String token[], String sModestr[], boolean clearOldModes) {
222
+		long nCurrent = 0, nValue = 0;
223
+		boolean bPositive = true;
224
+		
225
+		ClientInfo iClient;
226
+		
227
+		iClient = getClientInfo(token[2]);
228
+		if (iClient == null) { return; }
229
+		
230
+		if (clearOldModes) {
231
+			nCurrent = 0;
232
+		} else {
233
+			nCurrent = iClient.getUserMode();
234
+		}
235
+		
236
+		for (int i = 0; i < sModestr[0].length(); ++i) {
237
+			Character cMode = sModestr[0].charAt(i);
238
+			if (cMode.equals("+".charAt(0))) { bPositive = true; }
239
+			else if (cMode.equals("-".charAt(0))) { bPositive = false; }
240
+			else if (cMode.equals(":".charAt(0))) { continue; }
241
+			else {
242
+				if (myParser.hUserModes.containsKey(cMode)) { nValue = myParser.hUserModes.get(cMode); }
243
+				else {
244
+					// Unknown mode
245
+					callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got unknown user mode "+cMode+" - Added", myParser.getLastLine()));
246
+					myParser.hUserModes.put(cMode,myParser.nNextKeyUser);
247
+					nValue = myParser.nNextKeyUser;
248
+					myParser.nNextKeyUser = myParser.nNextKeyUser*2;
249
+				}
250
+				// Usermodes are always boolean
251
+				callDebugInfo(IRCParser.DEBUG_INFO, "User Mode: %c [%d] {Positive: %b}",cMode, nValue, bPositive);
252
+				if (bPositive) { nCurrent = nCurrent | nValue; }
253
+				else { nCurrent = nCurrent ^ (nCurrent & nValue); }
254
+			}
255
+		}
256
+		
257
+		iClient.setUserMode(nCurrent);
258
+		if (sParam.equals("221")) {
259
+			callUserModeDiscovered(iClient, sModestr[0]);
260
+		} else {
261
+			callUserModeChanged(iClient, token[0], sModestr[0]);
262
+		}
263
+	}
264
+	
265
+	/**
266
+	 * Callback to all objects implementing the ChannelModeChanged Callback.
267
+	 *
268
+	 * @see IChannelModeChanged
269
+	 * @param cChannel Channel where modes were changed
270
+	 * @param cChannelClient Client chaning the modes (null if server)
271
+	 * @param sHost Host doing the mode changing (User host or server name)
272
+	 * @param sModes Exact String parsed
273
+	 * @return true if a method was called, false otherwise
274
+	 */
275
+	protected boolean callChannelModeChanged(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sHost, String sModes) {
276
+		return getCallbackManager().getCallbackType("OnChannelModeChanged").call(cChannel, cChannelClient, sHost, sModes);
277
+	}
278
+	
279
+	/**
280
+	 * Callback to all objects implementing the ChannelUserModeChanged Callback.
281
+	 *
282
+	 * @see IChannelUserModeChanged
283
+	 * @param cChannel Channel where modes were changed
284
+	 * @param cChangedClient Client being changed
285
+	 * @param cSetByClient Client chaning the modes (null if server)
286
+	 * @param sMode String representing mode change (ie +o)
287
+	 * @param sHost Host doing the mode changing (User host or server name)
288
+	 * @return true if a method was called, false otherwise
289
+	 */
290
+	protected boolean callChannelUserModeChanged(ChannelInfo cChannel, ChannelClientInfo cChangedClient, ChannelClientInfo cSetByClient, String sHost, String sMode) {
291
+		return getCallbackManager().getCallbackType("OnChannelUserModeChanged").call(cChannel, cChangedClient, cSetByClient, sHost, sMode);
292
+	}
293
+	
294
+	/**
295
+	 * Callback to all objects implementing the UserModeChanged Callback.
296
+	 *
297
+	 * @see IUserModeChanged
298
+	 * @param cClient Client that had the mode changed (almost always us)
299
+	 * @param sSetby Host that set the mode (us or servername)
300
+	 * @param sModes The modes set.
301
+	 * @return true if a method was called, false otherwise
302
+	 */
303
+	protected boolean callUserModeChanged(ClientInfo cClient, String sSetby, String sModes) {
304
+		return getCallbackManager().getCallbackType("OnUserModeChanged").call(cClient, sSetby, sModes);
305
+	}
306
+	
307
+	/**
308
+	 * Callback to all objects implementing the UserModeDiscovered Callback.
309
+	 *
310
+	 * @see IUserModeDiscovered
311
+	 * @param cClient Client that had the mode changed (almost always us)
312
+	 * @param sModes The modes set.
313
+	 * @return true if a method was called, false otherwise
314
+	 */
315
+	protected boolean callUserModeDiscovered(ClientInfo cClient, String sModes) {
316
+		return getCallbackManager().getCallbackType("OnUserModeDiscovered").call(cClient, sModes);
317
+	}	
318
+	
319
+	/**
320
+	 * What does this IRCProcessor handle.
321
+	 *
322
+	 * @return String[] with the names of the tokens we handle.
323
+	 */
324
+	@Override
325
+	public String[] handles() {
326
+		return new String[]{"MODE", "324", "221"};
327
+	} 
328
+	
329
+	/**
330
+	 * Create a new instance of the IRCProcessor Object.
331
+	 *
332
+	 * @param parser IRCParser That owns this IRCProcessor
333
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
334
+	 */
335
+	protected ProcessMode (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
336
+
337
+}

+ 130
- 0
src/com/dmdirc/parser/irc/ProcessNames.java View File

@@ -0,0 +1,130 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process a Names reply.
27
+ */
28
+public class ProcessNames extends IRCProcessor {
29
+	/**
30
+	 * Process a Names reply.
31
+	 *
32
+	 * @param sParam Type of line to process ("366", "353")
33
+	 * @param token IRCTokenised line to process
34
+	 */
35
+	@Override
36
+	public void process(String sParam, String[] token) {
37
+		ChannelInfo iChannel;
38
+		if (sParam.equals("366")) {
39
+			// End of names
40
+			iChannel = getChannelInfo(token[3]);
41
+			if (iChannel == null) { return; }
42
+			
43
+			iChannel.setAddingNames(false);
44
+			callChannelGotNames(iChannel);
45
+			
46
+			if (!iChannel.hasAskedForListModes()) {
47
+				if (myParser.getAutoListMode()) {
48
+					iChannel.requestListModes();
49
+				}
50
+			}
51
+		} else {
52
+			// Names
53
+			
54
+			ClientInfo iClient;
55
+			ChannelClientInfo iChannelClient;
56
+			
57
+			iChannel = getChannelInfo(token[4]);
58
+		
59
+			if (iChannel == null) { return; }
60
+			
61
+			// If we are not expecting names, clear the current known names - this is fresh stuff!
62
+			if (!iChannel.isAddingNames()) { iChannel.emptyChannel(); }
63
+			iChannel.setAddingNames(true);
64
+			
65
+			String[] sNames = token[token.length-1].split(" ");
66
+			String sNameBit = "", sName = "";
67
+			StringBuilder sModes = new StringBuilder();
68
+			long nPrefix = 0;
69
+			for (int j = 0; j < sNames.length; ++j) {
70
+				sNameBit = sNames[j];
71
+				// If name is empty (ie there was an extra space) ignore it.
72
+				if (sNameBit.isEmpty()) { continue; }
73
+				// This next bit of code allows for any ircd which decides to use @+Foo in names
74
+				for (int i = 0; i < sNameBit.length(); ++i) {
75
+					Character cMode = sNameBit.charAt(i);
76
+					// hPrefixMap contains @, o, +, v this caused issue 107
77
+					// hPrefixModes only contains o, v so if the mode is in hPrefixMap
78
+					// and not in hPrefixModes, its ok to use.
79
+					if (myParser.hPrefixMap.containsKey(cMode) && !myParser.hPrefixModes.containsKey(cMode)) {
80
+						sModes.append(cMode);
81
+						nPrefix = nPrefix + myParser.hPrefixModes.get(myParser.hPrefixMap.get(cMode));
82
+					} else {
83
+						sName = sNameBit.substring(i);
84
+						break;
85
+					}
86
+				}
87
+				callDebugInfo(IRCParser.DEBUG_INFO, "Name: %s Modes: \"%s\" [%d]",sName,sModes.toString(),nPrefix);
88
+				
89
+				iClient = getClientInfo(sName);
90
+				if (iClient == null) { iClient = new ClientInfo(myParser, sName); myParser.addClient(iClient); }
91
+				iChannelClient = iChannel.addClient(iClient);
92
+				iChannelClient.setChanMode(nPrefix);
93
+
94
+				sName = "";
95
+				sModes = new StringBuilder();
96
+				nPrefix = 0;
97
+			}
98
+		}
99
+	}
100
+	
101
+	/**
102
+	 * Callback to all objects implementing the ChannelGotNames Callback.
103
+	 *
104
+	 * @see IChannelGotNames
105
+	 * @param cChannel Channel which the names reply is for
106
+	 * @return true if a method was called, false otherwise
107
+	 */
108
+	protected boolean callChannelGotNames(ChannelInfo cChannel) {
109
+		return getCallbackManager().getCallbackType("OnChannelGotNames").call(cChannel);
110
+	}
111
+	
112
+	/**
113
+	 * What does this IRCProcessor handle.
114
+	 *
115
+	 * @return String[] with the names of the tokens we handle.
116
+	 */
117
+	@Override
118
+	public String[] handles() {
119
+		return new String[]{"353", "366"};
120
+	} 
121
+	
122
+	/**
123
+	 * Create a new instance of the IRCProcessor Object.
124
+	 *
125
+	 * @param parser IRCParser That owns this IRCProcessor
126
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
127
+	 */
128
+	protected ProcessNames (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
129
+
130
+}

+ 124
- 0
src/com/dmdirc/parser/irc/ProcessNick.java View File

@@ -0,0 +1,124 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process a Nick change.
27
+ */
28
+public class ProcessNick extends IRCProcessor {
29
+	/**
30
+	 * Process a Nick change.
31
+	 *
32
+	 * @param sParam Type of line to process ("NICK")
33
+	 * @param token IRCTokenised line to process
34
+	 */
35
+	@Override
36
+	public void process(String sParam, String[] token) {
37
+		ClientInfo iClient;
38
+		ChannelClientInfo iChannelClient;
39
+		String oldNickname;
40
+		
41
+		iClient = getClientInfo(token[0]);
42
+		if (iClient != null) {
43
+			oldNickname = myParser.getIRCStringConverter().toLowerCase(iClient.getNickname());
44
+			// Remove the client from the known clients list
45
+			final boolean isSameNick = myParser.getIRCStringConverter().equalsIgnoreCase(oldNickname, token[token.length-1]);
46
+			
47
+			if (!isSameNick) {
48
+				myParser.forceRemoveClient(getClientInfo(oldNickname));
49
+			}
50
+			// Change the nickame
51
+			iClient.setUserBits(token[token.length-1],true);
52
+			// Readd the client
53
+			if (!isSameNick && myParser.getClientInfo(iClient.getNickname()) != null) {
54
+//				myParser.onPostErrorInfo(new ParserError(ParserError.ERROR_FATAL, "Nick change would overwrite existing client", myParser.getLastLine()), false);
55
+				myParser.callErrorInfo(new ParserError(ParserError.ERROR_FATAL + ParserError.ERROR_USER, "Nick change would overwrite existing client", myParser.getLastLine()));
56
+			} else {
57
+				if (!isSameNick) {
58
+					myParser.addClient(iClient);
59
+				}
60
+				
61
+				for (ChannelInfo iChannel : myParser.getChannels()) {
62
+					// Find the user (using the old nickname)
63
+					iChannelClient = iChannel.getUser(oldNickname);
64
+					if (iChannelClient != null) {
65
+						// Rename them. This uses the old nickname (the key in the hashtable)
66
+						// and the channelClient object has access to the new nickname (by way
67
+						// of the ClientInfo object we updated above)
68
+						if (!isSameNick) {
69
+							iChannel.renameClient(oldNickname, iChannelClient);
70
+						}
71
+						callChannelNickChanged(iChannel,iChannelClient,ClientInfo.parseHost(token[0]));
72
+					}
73
+				}
74
+				
75
+				callNickChanged(iClient, ClientInfo.parseHost(token[0]));
76
+			}
77
+		}
78
+		
79
+	}
80
+	
81
+	/**
82
+	 * Callback to all objects implementing the ChannelNickChanged Callback.
83
+	 *
84
+	 * @see IChannelNickChanged
85
+	 * @param cChannel One of the channels that the user is on
86
+	 * @param cChannelClient Client changing nickname
87
+	 * @param sOldNick Nickname before change
88
+	 * @return true if a method was called, false otherwise
89
+	 */
90
+	protected boolean callChannelNickChanged(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sOldNick) {
91
+		return getCallbackManager().getCallbackType("OnChannelNickChanged").call(cChannel, cChannelClient, sOldNick);
92
+	}
93
+	
94
+	/**
95
+	 * Callback to all objects implementing the NickChanged Callback.
96
+	 *
97
+	 * @see INickChanged
98
+	 * @param cClient Client changing nickname
99
+	 * @param sOldNick Nickname before change
100
+	 * @return true if a method was called, false otherwise
101
+	 */
102
+	protected boolean callNickChanged(ClientInfo cClient, String sOldNick) {
103
+		return getCallbackManager().getCallbackType("OnNickChanged").call(cClient, sOldNick);
104
+	}
105
+	
106
+	/**
107
+	 * What does this IRCProcessor handle.
108
+	 *
109
+	 * @return String[] with the names of the tokens we handle.
110
+	 */
111
+	@Override
112
+	public String[] handles() {
113
+		return new String[]{"NICK"};
114
+	} 
115
+	
116
+	/**
117
+	 * Create a new instance of the IRCProcessor Object.
118
+	 *
119
+	 * @param parser IRCParser That owns this IRCProcessor
120
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
121
+	 */
122
+	protected ProcessNick (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
123
+
124
+}

+ 97
- 0
src/com/dmdirc/parser/irc/ProcessNickInUse.java View File

@@ -0,0 +1,97 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process a NickInUse message.
27
+ * Parser implements handling of this if Pre-001 and no other handler found,
28
+ * adding the NickInUse handler (addNickInUse) after 001 is prefered over before.<br><br>
29
+ * <br>
30
+ * If the first nickname is in use, and a NickInUse message is recieved before 001, we
31
+ * will attempt to use the altnickname instead.<br>
32
+ * If this also fails, we will start prepending _ (or the value of me.cPrepend) to the main nickname.
33
+ */
34
+public class ProcessNickInUse extends IRCProcessor {
35
+	/**
36
+	 * Process a NickInUse message.
37
+	 * Parser implements handling of this if Pre-001 and no other handler found,
38
+	 * adding the NickInUse handler (addNickInUse) after 001 is prefered over before.<br><br>
39
+	 * <br>
40
+	 * If the first nickname is in use, and a NickInUse message is recieved before 001, we
41
+	 * will attempt to use the altnickname instead.<br>
42
+	 * If this also fails, we will start prepending _ (or the value of me.cPrepend) to the main nickname.
43
+	 *
44
+	 * @param sParam Type of line to process ("433")
45
+	 * @param token IRCTokenised line to process
46
+	 */
47
+	@Override
48
+	public void process(final String sParam, final String[] token) {
49
+		if (!callNickInUse(token[3])) {
50
+			// Manually handle nick in use.
51
+			callDebugInfo(IRCParser.DEBUG_INFO,"No Nick in use Handler.");
52
+			if (!myParser.got001) {
53
+				callDebugInfo(IRCParser.DEBUG_INFO,"Using inbuilt handler");
54
+				// If this is before 001 we will try and get a nickname, else we will leave the nick as-is
55
+				if (myParser.triedAlt) {
56
+					if (myParser.getIRCStringConverter().equalsIgnoreCase(myParser.sThinkNickname, myParser.me.getAltNickname())) {
57
+						myParser.sThinkNickname = myParser.me.getNickname();
58
+					}
59
+					myParser.setNickname(myParser.me.getPrependChar()+myParser.sThinkNickname);
60
+				} else {
61
+					myParser.setNickname(myParser.me.getAltNickname());
62
+					myParser.triedAlt = true; 
63
+				}
64
+			}
65
+		}
66
+	}
67
+	
68
+	/**
69
+	 * Callback to all objects implementing the NickInUse Callback.
70
+	 *
71
+	 * @param nickname Nickname that was wanted.
72
+	 * @see INickInUse
73
+	 * @return true if a method was called, false otherwise
74
+	 */
75
+	protected boolean callNickInUse(final String nickname) {
76
+		return getCallbackManager().getCallbackType("OnNickInUse").call(nickname);
77
+	}
78
+	
79
+	/**
80
+	 * What does this IRCProcessor handle.
81
+	 *
82
+	 * @return String[] with the names of the tokens we handle.
83
+	 */
84
+	@Override
85
+	public String[] handles() {
86
+		return new String[]{"433"};
87
+	}
88
+	
89
+	/**
90
+	 * Create a new instance of the ProcessNickInUse Object.
91
+	 *
92
+	 * @param parser IRCParser That owns this object
93
+	 * @param manager ProcessingManager that is in charge of this object
94
+	 */
95
+	protected ProcessNickInUse (final IRCParser parser, final ProcessingManager manager) { super(parser, manager); }
96
+
97
+}

+ 69
- 0
src/com/dmdirc/parser/irc/ProcessNoticeAuth.java View File

@@ -0,0 +1,69 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process a NoticeAuth message.
27
+ */
28
+public class ProcessNoticeAuth extends IRCProcessor {
29
+	/**
30
+	 * Process a NoticeAuth message.
31
+	 *
32
+	 * @param sParam Type of line to process ("Notice Auth")
33
+	 * @param token IRCTokenised line to process
34
+	 */
35
+	@Override
36
+	public void process(final String sParam, final String[] token) {
37
+		callNoticeAuth(token[token.length-1]);
38
+	}
39
+	
40
+	/**
41
+	 * Callback to all objects implementing the NoticeAuth Callback.
42
+	 *
43
+	 * @see INoticeAuth
44
+	 * @param data Incomming Line.
45
+	 * @return true if a method was called, false otherwise
46
+	 */
47
+	protected boolean callNoticeAuth(final String data) {
48
+		return getCallbackManager().getCallbackType("OnNoticeAuth").call(data);
49
+	}
50
+	
51
+	/**
52
+	 * What does this IRCProcessor handle.
53
+	 *
54
+	 * @return String[] with the names of the tokens we handle.
55
+	 */
56
+	@Override
57
+	public String[] handles() {
58
+		return new String[]{"Notice Auth"};
59
+	} 
60
+	
61
+	/**
62
+	 * Create a new instance of the ProcessNoticeAuth Object.
63
+	 *
64
+	 * @param parser IRCParser That owns this object
65
+	 * @param manager ProcessingManager that is in charge of this object
66
+	 */
67
+	protected ProcessNoticeAuth (final IRCParser parser, final ProcessingManager manager) { super(parser, manager); }
68
+
69
+}

+ 108
- 0
src/com/dmdirc/parser/irc/ProcessPart.java View File

@@ -0,0 +1,108 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process a channel part.
27
+ */
28
+public class ProcessPart extends IRCProcessor {
29
+
30
+	/**
31
+	 * Process a channel part.
32
+	 *
33
+	 * @param sParam Type of line to process ("PART")
34
+	 * @param token IRCTokenised line to process
35
+	 */
36
+	@Override
37
+	public void process(final String sParam, final String[] token) {
38
+		// :nick!ident@host PART #Channel
39
+		// :nick!ident@host PART #Channel :reason
40
+		if (token.length < 3) { return; }
41
+		ClientInfo iClient;
42
+		ChannelInfo iChannel;
43
+		ChannelClientInfo iChannelClient;
44
+		
45
+		iClient = getClientInfo(token[0]);
46
+		iChannel = getChannelInfo(token[2]);
47
+		
48
+		if (iClient == null) { return; }
49
+		if (IRCParser.ALWAYS_UPDATECLIENT && iClient.getHost().isEmpty()) {
50
+			// This may seem pointless - updating before they leave - but the formatter needs it!
51
+			iClient.setUserBits(token[0],false);
52
+		}
53
+		if (iChannel == null) { 
54
+			if (iClient != myParser.getMyself()) {
55
+				callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got part for channel ("+token[2]+") that I am not on. [User: "+token[0]+"]", myParser.getLastLine()));
56
+			}
57
+			return;
58
+		} else {
59
+			String sReason = "";
60
+			if (token.length > 3) { sReason = token[token.length-1]; }
61
+			iChannelClient = iChannel.getUser(iClient);
62
+			if (iChannelClient == null) {
63
+				// callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got part for channel ("+token[2]+") for a non-existant user. [User: "+token[0]+"]", myParser.getLastLine()));
64
+				return;
65
+			}
66
+			if (myParser.removeAfterCallback) { callChannelPart(iChannel,iChannelClient,sReason); }
67
+			callDebugInfo(IRCParser.DEBUG_INFO, "Removing %s from %s",iClient.getNickname(),iChannel.getName());
68
+			iChannel.delClient(iClient);
69
+			if (!myParser.removeAfterCallback) { callChannelPart(iChannel,iChannelClient,sReason); }
70
+			if (iClient == myParser.getMyself()) {
71
+				iChannel.emptyChannel();
72
+				myParser.removeChannel(iChannel);
73
+			}
74
+		}
75
+	}
76
+	
77
+	/**
78
+	 * Callback to all objects implementing the ChannelPart Callback.
79
+	 *
80
+	 * @see IChannelPart
81
+	 * @param cChannel Channel that the user parted
82
+	 * @param cChannelClient Client that parted
83
+	 * @param sReason Reason given for parting (May be "")
84
+	 * @return true if a method was called, false otherwise
85
+	 */
86
+	protected boolean callChannelPart(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sReason) {
87
+		return getCallbackManager().getCallbackType("OnChannelPart").call(cChannel, cChannelClient, sReason);
88
+	}
89
+	
90
+	/**
91
+	 * What does this IRCProcessor handle.
92
+	 *
93
+	 * @return String[] with the names of the tokens we handle.
94
+	 */
95
+	@Override
96
+	public String[] handles() {
97
+		return new String[]{"PART"};
98
+	} 
99
+	
100
+	/**
101
+	 * Create a new instance of the IRCProcessor Object.
102
+	 *
103
+	 * @param parser IRCParser That owns this IRCProcessor
104
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
105
+	 */
106
+	protected ProcessPart (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
107
+
108
+}

+ 123
- 0
src/com/dmdirc/parser/irc/ProcessQuit.java View File

@@ -0,0 +1,123 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import java.util.ArrayList;
26
+
27
+/**
28
+ * Process a Quit message.
29
+ */
30
+public class ProcessQuit extends IRCProcessor {
31
+
32
+	/**
33
+	 * Process a Quit message.
34
+	 *
35
+	 * @param sParam Type of line to process ("QUIT")
36
+	 * @param token IRCTokenised line to process
37
+	 */
38
+	@Override
39
+	public void process(final String sParam, final String[] token) {
40
+		// :nick!ident@host QUIT
41
+		// :nick!ident@host QUIT :reason
42
+		if (token.length < 2) { return; }
43
+		ClientInfo iClient;
44
+		ChannelClientInfo iChannelClient;
45
+		
46
+		iClient = getClientInfo(token[0]);
47
+		
48
+		if (iClient == null) { return; }
49
+		if (IRCParser.ALWAYS_UPDATECLIENT && iClient.getHost().isEmpty()) {
50
+			// This may seem pointless - updating before they leave - but the formatter needs it!
51
+			iClient.setUserBits(token[0],false);
52
+		}
53
+		String sReason = "";
54
+		if (token.length > 2) { sReason = token[token.length-1]; }
55
+		
56
+		ArrayList<ChannelInfo> channelList = new ArrayList<ChannelInfo>(myParser.getChannels());
57
+		for (ChannelInfo iChannel : channelList) {
58
+			iChannelClient = iChannel.getUser(iClient);
59
+			if (iChannelClient != null) {
60
+				if (myParser.removeAfterCallback) { callChannelQuit(iChannel,iChannelClient,sReason); }
61
+				if (iClient == myParser.getMyself()) {
62
+					iChannel.emptyChannel();
63
+					myParser.removeChannel(iChannel);
64
+				} else {
65
+					iChannel.delClient(iClient);
66
+				}
67
+				if (!myParser.removeAfterCallback) { callChannelQuit(iChannel,iChannelClient,sReason); }
68
+			}
69
+		}
70
+
71
+		if (myParser.removeAfterCallback) { callQuit(iClient,sReason); }
72
+		if (iClient == myParser.getMyself()) {
73
+			myParser.clearClients();
74
+		} else {
75
+			myParser.removeClient(iClient);
76
+		}
77
+		if (!myParser.removeAfterCallback) { callQuit(iClient,sReason); }
78
+	}	
79
+	
80
+	/**
81
+	 * Callback to all objects implementing the ChannelQuit Callback.
82
+	 *
83
+	 * @see IChannelQuit
84
+	 * @param cChannel Channel that user was on
85
+	 * @param cChannelClient User thats quitting
86
+	 * @param sReason Quit reason
87
+	 * @return true if a method was called, false otherwise
88
+	 */
89
+	protected boolean callChannelQuit(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sReason) {
90
+		return getCallbackManager().getCallbackType("OnChannelQuit").call(cChannel, cChannelClient, sReason);
91
+	}
92
+	
93
+	/**
94
+	 * Callback to all objects implementing the Quit Callback.
95
+	 *
96
+	 * @see IQuit
97
+	 * @param cClient Client Quitting
98
+	 * @param sReason Reason for quitting (may be "")
99
+	 * @return true if a method was called, false otherwise
100
+	 */
101
+	protected boolean callQuit(final ClientInfo cClient, final String sReason) {
102
+		return getCallbackManager().getCallbackType("OnQuit").call(cClient, sReason);
103
+	}
104
+	
105
+	/**
106
+	 * What does this IRCProcessor handle.
107
+	 *
108
+	 * @return String[] with the names of the tokens we handle.
109
+	 */
110
+	@Override
111
+	public String[] handles() {
112
+		return new String[]{"QUIT"};
113
+	} 
114
+	
115
+	/**
116
+	 * Create a new instance of the IRCProcessor Object.
117
+	 *
118
+	 * @param parser IRCParser That owns this IRCProcessor
119
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
120
+	 */
121
+	protected ProcessQuit (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
122
+
123
+}

+ 99
- 0
src/com/dmdirc/parser/irc/ProcessTopic.java View File

@@ -0,0 +1,99 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process a topic change.
27
+ */
28
+public class ProcessTopic extends IRCProcessor {
29
+	/**
30
+	 * Process a topic change.
31
+	 *
32
+	 * @param sParam Type of line to process ("TOPIC", "332", "333")
33
+	 * @param token IRCTokenised line to process
34
+	 */
35
+	@Override
36
+	public void process(final String sParam, final String[] token) {
37
+		ChannelInfo iChannel;
38
+		if (sParam.equals("332")) {
39
+			iChannel = getChannelInfo(token[3]);
40
+			if (iChannel == null) { return; }
41
+			iChannel.setTopic(token[token.length-1]);
42
+		} else if (sParam.equals("333")) {
43
+			if (token.length > 3) {
44
+				iChannel = getChannelInfo(token[3]);
45
+				if (iChannel == null) { return; }
46
+				if (token.length > 4) {
47
+					iChannel.setTopicUser(token[4]);
48
+					if (token.length > 5) {
49
+						iChannel.setTopicTime(Long.parseLong(token[5]));
50
+					}
51
+				}
52
+				callChannelTopic(iChannel,true);
53
+			}
54
+		} else {
55
+			if (IRCParser.ALWAYS_UPDATECLIENT) {
56
+				final ClientInfo iClient = getClientInfo(token[0]);
57
+				if (iClient != null && iClient.getHost().isEmpty()) {iClient.setUserBits(token[0],false); }
58
+			}
59
+			iChannel = getChannelInfo(token[2]);
60
+			if (iChannel == null) { return; }
61
+			iChannel.setTopicTime(System.currentTimeMillis() / 1000);
62
+			if (token[0].charAt(0) == ':') { token[0] = token[0].substring(1); }
63
+			iChannel.setTopicUser(token[0]);
64
+			iChannel.setTopic(token[token.length-1]);
65
+			callChannelTopic(iChannel,false);
66
+		}
67
+	}
68
+	
69
+	/**
70
+	 * Callback to all objects implementing the ChannelTopic Callback.
71
+	 *
72
+	 * @see IChannelTopic
73
+	 * @param cChannel Channel that topic was set on
74
+	 * @param bIsJoinTopic True when getting topic on join, false if set by user/server
75
+	 * @return true if a method was called, false otherwise
76
+	 */
77
+	protected boolean callChannelTopic(final ChannelInfo cChannel, final boolean bIsJoinTopic) {
78
+		return getCallbackManager().getCallbackType("OnChannelTopic").call(cChannel, bIsJoinTopic);
79
+	}
80
+	
81
+	/**
82
+	 * What does this IRCProcessor handle.
83
+	 *
84
+	 * @return String[] with the names of the tokens we handle.
85
+	 */
86
+	@Override
87
+	public String[] handles() {
88
+		return new String[]{"TOPIC", "332", "333"};
89
+	} 
90
+	
91
+	/**
92
+	 * Create a new instance of the IRCProcessor Object.
93
+	 *
94
+	 * @param parser IRCParser That owns this IRCProcessor
95
+	 * @param manager ProcessingManager that is in charge of this IRCProcessor
96
+	 */
97
+	protected ProcessTopic (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
98
+
99
+}

+ 111
- 0
src/com/dmdirc/parser/irc/ProcessWallops.java View File

@@ -0,0 +1,111 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process a WALLOPS Message.
27
+ */
28
+public class ProcessWallops extends IRCProcessor {
29
+	/**
30
+	 * Process a Wallops Message.
31
+	 *
32
+	 * @param sParam Type of line to process ("WALLOPS")
33
+	 * @param token IRCTokenised line to process
34
+	 */
35
+	@Override
36
+	public void process(final String sParam, final String[] token) {
37
+		if (token.length < 3) { return; }
38
+		
39
+		String user = token[0];
40
+		String message = token[token.length-1];
41
+		if (user.charAt(0) == ':' && user.length() > 1) { user = user.substring(1); }
42
+		String[] bits = message.split(" ", 2);
43
+
44
+		if (bits.length > 1) {
45
+			if (message.charAt(0) == '*') {
46
+				callWallop(bits[1], user);
47
+				return;
48
+			} else if (message.charAt(0) == '$') {
49
+				callWalluser(bits[1], user);
50
+				return;
51
+			}
52
+		}
53
+		callWallDesync(message, user);
54
+	}
55
+	
56
+	/**
57
+	 * Callback to all objects implementing the Wallop Callback.
58
+	 *
59
+	 * @see IWallop
60
+	 * @param host Host of the user who sent the wallop
61
+	 * @param message The message
62
+	 * @return true if a method was called, false otherwise
63
+	 */
64
+	protected boolean callWallop(final String message, final String host) {
65
+		return getCallbackManager().getCallbackType("OnWallop").call(message, host);
66
+	}
67
+	
68
+	/**
69
+	 * Callback to all objects implementing the Walluser Callback.
70
+	 *
71
+	 * @see IWalluser
72
+	 * @param host Host of the user who sent the walluser
73
+	 * @param message The message
74
+	 * @return true if a method was called, false otherwise
75
+	 */
76
+	protected boolean callWalluser(final String message, final String host) {
77
+		return getCallbackManager().getCallbackType("OnWalluser").call(message, host);
78
+	}
79
+	
80
+	/**
81
+	 * Callback to all objects implementing the WallDesync Callback.
82
+	 *
83
+	 * @see IWallDesync
84
+	 * @param host Host of the user who sent the WallDesync
85
+	 * @param message The message
86
+	 * @return true if a method was called, false otherwise
87
+	 */
88
+	protected boolean callWallDesync(final String message, final String host) {
89
+		return getCallbackManager().getCallbackType("OnWallDesync").call(message, host);
90
+	}
91
+	
92
+	
93
+	/**
94
+	 * What does this IRCProcessor handle.
95
+	 *
96
+	 * @return String[] with the names of the tokens we handle.
97
+	 */
98
+	@Override
99
+	public String[] handles() {
100
+		return new String[]{"WALLOPS"};
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 ProcessWallops (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
110
+
111
+}

+ 137
- 0
src/com/dmdirc/parser/irc/ProcessWho.java View File

@@ -0,0 +1,137 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Process a /who reply.
27
+ */
28
+public class ProcessWho extends IRCProcessor {
29
+	/**
30
+	 * Process a /who reply.
31
+	 *
32
+	 * @param sParam Type of line to process ("352")
33
+	 * @param token IRCTokenised line to process
34
+	 */
35
+	@Override
36
+	public void process(final String sParam, final String[] token) {
37
+		// :blueyonder2.uk.quakenet.org 352 Dataforce #mdbot shane Tobavaj.users.quakenet.org *.quakenet.org Tobavaj G+x :3 Tobavaj - http://shane.dmdirc.com/scriptbot.php
38
+		//              0               1      2        3     4              5                      6           7     8        9
39
+		// :blueyonder2.uk.quakenet.org 352 Dataforce #mdbot ~Dataforce ResNetUser-BrynDinas-147.143.246.102.bangor.ac.uk *.quakenet.org Dataforce H@ :0 Dataforce
40
+		//              0               1      2        3      4                               5                            6              7      8        9
41
+		// :blueyonder2.uk.quakenet.org 352 Dataforce #mdbot shane soren.dataforce.org.uk *.quakenet.org DF|Soren H :3 Unknown
42
+		//              0               1      2        3     4              5                      6       7     8      9
43
+		// :server 352 mynickname channel username address server nick flags :hops info
44
+		//     0    1      2         3     4          5      6      7    8        9
45
+		
46
+//		ChannelInfo channel = myParser.getChannelInfo(token[3]);
47
+//		ChannelClientInfo channelClient = channel.getUser(token[7]);
48
+//		ClientInfo client = channelClient.getClient();
49
+		final ClientInfo client = myParser.getClientInfo(token[7]);
50
+		if (client != null) {
51
+			// Update ident/host
52
+			client.setUserBits(token[7]+"!"+token[4]+"@"+token[5], false);
53
+			// Update real name
54
+			if (client.getRealName().isEmpty()) {
55
+				final String name = token[9].split(" ", 2)[1];
56
+				client.setRealName(name);
57
+			}
58
+			// Update away state
59
+			final String mode = token[8];
60
+			final boolean isAway = mode.indexOf('G') != -1;
61
+			if (client.getAwayState() != isAway) {
62
+//				System.out.println("Away state for '"+client+"' changed to: "+isAway);
63
+				client.setAwayState(isAway);
64
+				if (!isAway) { client.setAwayReason(""); }
65
+				if (client == myParser.getMyself()) {
66
+					callAwayState(client.getAwayState(), client.getAwayReason());
67
+				} else {
68
+					callAwayStateOther(client, isAway);
69
+					
70
+					ChannelClientInfo iChannelClient;
71
+					for (ChannelInfo iChannel : myParser.getChannels()) {
72
+						iChannelClient = iChannel.getUser(client);
73
+						if (iChannelClient != null) {
74
+							callChannelAwayStateOther(iChannel,iChannelClient,isAway);
75
+						}
76
+					}
77
+				}
78
+			}
79
+		}
80
+	}
81
+	
82
+	/**
83
+	 * Callback to all objects implementing the onAwayState Callback.
84
+	 *
85
+	 * @see IAwayState
86
+	 * @param currentState Set to true if we are now away, else false.
87
+	 * @param reason Best guess at away reason
88
+	 * @return true if a method was called, false otherwise
89
+	 */
90
+	protected boolean callAwayState(boolean currentState, String reason) {
91
+		return getCallbackManager().getCallbackType("OnAwayState").call(currentState, reason);
92
+	}
93
+	
94
+	/**
95
+	 * Callback to all objects implementing the onAwayStateOther Callback.
96
+	 *
97
+	 * @see IAwayStateOther
98
+	 * @param client Client this is for
99
+	 * @param state Away State (true if away, false if here)
100
+	 * @return true if a method was called, false otherwise
101
+	 */
102
+	protected boolean callAwayStateOther(final ClientInfo client, final boolean state) {
103
+		return getCallbackManager().getCallbackType("OnAwayStateOther").call(client, state);
104
+	}
105
+	
106
+	/**
107
+	 * Callback to all objects implementing the onChannelAwayStateOther Callback.
108
+	 *
109
+	 * @see IAwayStateOther
110
+	 * @param channel Channel this is for
111
+	 * @param channelClient ChannelClient this is for
112
+	 * @param state Away State (true if away, false if here)
113
+	 * @return true if a method was called, false otherwise
114
+	 */
115
+	protected boolean callChannelAwayStateOther(final ChannelInfo channel, final ChannelClientInfo channelClient, final boolean state) {
116
+		return getCallbackManager().getCallbackType("OnChannelAwayStateOther").call(channel, channelClient, state);
117
+	}
118
+	
119
+	/**
120
+	 * What does this IRCProcessor handle.
121
+	 *
122
+	 * @return String[] with the names of the tokens we handle.
123
+	 */
124
+	@Override
125
+	public String[] handles() {
126
+		return new String[]{"352"};
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 ProcessWho (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
136
+
137
+}

+ 220
- 0
src/com/dmdirc/parser/irc/ProcessingManager.java View File

@@ -0,0 +1,220 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import java.util.Hashtable;
26
+
27
+/**
28
+ * IRC Parser Processing Manager.
29
+ * Manages adding/removing/calling processing stuff.
30
+ *
31
+ * @author Shane Mc Cormack
32
+ */
33
+public class ProcessingManager {
34
+	/** Reference to the parser object that owns this ProcessingManager */
35
+	IRCParser myParser;
36
+
37
+	/** Hashtable used to store the different types of IRCProcessor known. */
38
+	private final Hashtable<String,IRCProcessor> processHash = new Hashtable<String,IRCProcessor>();
39
+
40
+	/**
41
+	 * Debugging Data to the console.
42
+	 */
43
+	private void doDebug(final String line, final Object... args) {
44
+		myParser.callDebugInfo(IRCParser.DEBUG_PROCESSOR, line, args);
45
+	}
46
+
47
+	/**
48
+	 * Constructor to create a ProcessingManager.
49
+	 *
50
+	 * @param parser IRCParser that owns this Processing Manager
51
+	 */
52
+	public ProcessingManager(IRCParser parser) {
53
+		myParser = parser;
54
+		//------------------------------------------------
55
+		// Add processors
56
+		//------------------------------------------------
57
+		// NOTICE AUTH
58
+		addProcessor(new ProcessNoticeAuth(myParser, this));
59
+		// 001
60
+		addProcessor(new Process001(myParser, this));
61
+		// 004
62
+		// 005
63
+		addProcessor(new Process004005(myParser, this));
64
+		// 464
65
+		addProcessor(new Process464(myParser, this));
66
+		// 301
67
+		// 305
68
+		// 306
69
+		addProcessor(new ProcessAway(myParser, this));
70
+		// 352
71
+		addProcessor(new ProcessWho(myParser, this));
72
+		// INVITE
73
+		addProcessor(new ProcessInvite(myParser, this));
74
+		// JOIN
75
+		addProcessor(new ProcessJoin(myParser, this));
76
+		// KICK
77
+		addProcessor(new ProcessKick(myParser, this));
78
+		// PRIVMSG
79
+		// NOTICE
80
+		addProcessor(new ProcessMessage(myParser, this));
81
+		// MODE
82
+		// 324
83
+		addProcessor(new ProcessMode(myParser, this));
84
+		// 372
85
+		// 375
86
+		// 376
87
+		// 422
88
+		addProcessor(new ProcessMOTD(myParser, this));
89
+		// 353
90
+		// 366
91
+		addProcessor(new ProcessNames(myParser, this));
92
+		// 433
93
+		addProcessor(new ProcessNickInUse(myParser, this));
94
+		// NICK
95
+		addProcessor(new ProcessNick(myParser, this));
96
+		// PART
97
+		addProcessor(new ProcessPart(myParser, this));
98
+		// QUIT
99
+		addProcessor(new ProcessQuit(myParser, this));
100
+		// TOPIC
101
+		// 332
102
+		// 333
103
+		addProcessor(new ProcessTopic(myParser, this));
104
+		// 344
105
+		// 345
106
+		// 346
107
+		// 347
108
+		// 348
109
+		// 349
110
+		// 367
111
+		// 368
112
+		addProcessor(new ProcessListModes(myParser, this));
113
+		// WALLOPS
114
+		addProcessor(new ProcessWallops(myParser, this));
115
+	}
116
+
117
+	/**
118
+	 * Add new Process type.
119
+	 *
120
+	 * @param processor IRCProcessor subclass for the processor.
121
+	 */
122
+	public void addProcessor(final IRCProcessor processor) {
123
+		// handles() returns a String array of all the tokens
124
+		// that this processor will parse.
125
+		addProcessor(processor.handles(), processor);
126
+	}
127
+
128
+	/**
129
+	 * Add a processor to tokens not-specified in the handles() reply.
130
+	 *
131
+	 * @param processor IRCProcessor subclass for the processor.
132
+	 * @param handles String Array of tokens to add this processor as a hadler for
133
+	 */
134
+	public void addProcessor(final String[] handles, final IRCProcessor processor) {
135
+		doDebug("Adding processor: "+processor.getName());
136
+
137
+		for (int i = 0; i < handles.length; ++i) {
138
+			if (processHash.containsKey(handles[i].toLowerCase())) {
139
+				// New Processors take priority over old ones
140
+				processHash.remove(handles[i].toLowerCase());
141
+			}
142
+			doDebug("\t Added handler for: "+handles[i]);
143
+			processHash.put(handles[i].toLowerCase(), processor);
144
+		}
145
+	}
146
+
147
+	/**
148
+	 * Remove a Process type.
149
+	 *
150
+	 * @param processor IRCProcessor subclass for the processor.
151
+	 */
152
+	public void delProcessor(final IRCProcessor processor) {
153
+		IRCProcessor testProcessor;
154
+		doDebug("Deleting processor: "+processor.getName());
155
+		for (String elementName : processHash.keySet()) {
156
+			doDebug("\t Checking handler for: "+elementName);
157
+			testProcessor = processHash.get(elementName);
158
+			if (testProcessor.getName().equalsIgnoreCase(processor.getName())) {
159
+				doDebug("\t Removed handler for: "+elementName);
160
+				processHash.remove(elementName);
161
+			}
162
+		}
163
+	}
164
+
165
+	/**
166
+	 * Get the processor used for a specified token.
167
+	 *
168
+	 * @param sParam Type of line to process ("005", "PRIVMSG" etc)
169
+	 * @return IRCProcessor for the given param.
170
+	 * @throws ProcessorNotFoundException if no processer exists for the param
171
+	 */
172
+	public IRCProcessor getProcessor(final String sParam) throws ProcessorNotFoundException {
173
+		if (processHash.containsKey(sParam.toLowerCase())) {
174
+			return processHash.get(sParam.toLowerCase());
175
+		} else {
176
+			throw new ProcessorNotFoundException("No processors will handle "+sParam);
177
+		}
178
+	}
179
+
180
+	/**
181
+	 * Process a Line.
182
+	 *
183
+	 * @param sParam Type of line to process ("005", "PRIVMSG" etc)
184
+	 * @param token IRCTokenised line to process
185
+	 * @throws ProcessorNotFoundException exception if no processors exists to handle the line
186
+	 */
187
+	public void process(final String sParam, final String[] token) throws ProcessorNotFoundException {
188
+		IRCProcessor messageProcessor = null;
189
+		try {
190
+			messageProcessor = getProcessor(sParam);
191
+			messageProcessor.process(sParam, token);
192
+		} catch (ProcessorNotFoundException p) {
193
+			throw p;
194
+		} catch (Exception e) {
195
+			final ParserError ei = new ParserError(ParserError.ERROR_ERROR,"Exception in Processor. ["+messageProcessor+"]: "+e.getMessage(), myParser.getLastLine());
196
+			ei.setException(e);
197
+			myParser.callErrorInfo(ei);
198
+		} finally {
199
+			// Try to call callNumeric. We don't want this to work if sParam is a non
200
+			// integer param, hense the empty catch
201
+			try {
202
+				callNumeric(Integer.parseInt(sParam), token);
203
+			} catch (NumberFormatException e) { }
204
+		}
205
+	}
206
+
207
+	/**
208
+	 * Callback to all objects implementing the onNumeric Callback.
209
+	 *
210
+	 * @see INumeric
211
+	 * @param numeric What numeric is this for
212
+	 * @param token IRC Tokenised line
213
+	 * @return true if a method was called, false otherwise
214
+	 */
215
+	protected boolean callNumeric(final int numeric, final String[] token) {
216
+		return myParser.getCallbackManager().getCallbackType("OnNumeric").call(numeric, token);
217
+	}
218
+
219
+}
220
+

+ 45
- 0
src/com/dmdirc/parser/irc/ProcessorNotFoundException.java View File

@@ -0,0 +1,45 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * IRC Parser Processor Not Found Exception.
27
+ *
28
+ * @author Shane Mc Cormack
29
+ */
30
+public class ProcessorNotFoundException extends Exception {
31
+	/**
32
+	 * A version number for this class. It should be changed whenever the class
33
+	 * structure is changed (or anything else that would prevent serialized
34
+	 * objects being unserialized with the new class).
35
+	 */
36
+	private static final long serialVersionUID = 1;
37
+	
38
+	/**
39
+	 * Create a new ProcessorNotFound Exception.
40
+	 *
41
+	 * @param message Reason for exception
42
+	 */
43
+	public ProcessorNotFoundException(final String message) { super(message); }
44
+
45
+}

+ 166
- 0
src/com/dmdirc/parser/irc/RegexStringList.java View File

@@ -0,0 +1,166 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import java.util.ArrayList;
26
+import java.util.List;
27
+import java.util.regex.PatternSyntaxException;
28
+
29
+/**
30
+ * IRC Parser Ignore list.
31
+ *
32
+ * @author Shane Mc Cormack
33
+ */
34
+public class RegexStringList {
35
+
36
+	/** Arraylist storing ignore patterns. */
37
+	protected final List<String> ignoreInfo = new ArrayList<String>();
38
+
39
+	/**
40
+	 * Creates a new instance of RegexStringList.
41
+	 */
42
+	public RegexStringList() {
43
+		// Do nothing
44
+	}
45
+
46
+	/**
47
+	 * Creates a new instance of RegexStringList, with the specified items.
48
+	 *
49
+	 * @param items Items to add to this RegexStringList
50
+	 */
51
+	public RegexStringList(final List<String> items) {
52
+		addAll(items);
53
+	}
54
+
55
+	/**
56
+	 * Add a new ignore pattern to the ignore list.
57
+	 *
58
+	 * @param pattern Regex syntax for the ignore (Pattern is matched case-insensitively as ^pattern$)
59
+	 */
60
+	public void add(final String pattern) {
61
+		for (String target : ignoreInfo) {
62
+			if (pattern.equalsIgnoreCase(target)) {
63
+				return;
64
+			}
65
+		}
66
+
67
+		ignoreInfo.add(pattern);
68
+	}
69
+
70
+	/**
71
+	 * Adds a set of patterns to the list.
72
+	 *
73
+	 * @param patterns A list of patterns to be added
74
+	 */
75
+	public void addAll(final List<String> patterns) {
76
+		for (String pattern : patterns) {
77
+			add(pattern);
78
+		}
79
+	}
80
+
81
+	/**
82
+	 * Delete an ignore from the list.
83
+	 *
84
+	 * @param position Position in the list to remove
85
+	 */
86
+	public void remove(final int position) {
87
+		if (position < this.count()) {
88
+			ignoreInfo.remove(position);
89
+		}
90
+	}
91
+
92
+	/**
93
+	 * Clear the ignore list.
94
+	 */
95
+	public void clear() {
96
+		ignoreInfo.clear();
97
+	}
98
+
99
+	/**
100
+	 * Check if a string matches any of the ignores in the list.
101
+	 *
102
+	 * @param check String to check (Patterns are matched case-insensitively as ^pattern$)
103
+	 * @return integer showing the position of the first match in the ignore list (-1 if none)
104
+	 * @throws PatternSyntaxException if one of the items in the list is an invalid regex
105
+	 */
106
+	public int matches(final String check) throws PatternSyntaxException {
107
+		for (int i = 0; i < this.count(); ++i) {
108
+			if (check.matches("(?i)"+this.get(i))) {
109
+				return i;
110
+			}
111
+		}
112
+		return -1;
113
+	}
114
+
115
+	/**
116
+	 * Check if a string matches a specific ignore in the list.
117
+	 *
118
+	 * @param position Position to check
119
+	 * @param check String to check (Patterns are matched case-insensitively as ^pattern$)
120
+	 * @return boolean true/false
121
+	 * @throws PatternSyntaxException if the item is an invalid regex
122
+	 */
123
+	public boolean matches(final int position, final String check) throws PatternSyntaxException {
124
+		if (position < this.count()) {
125
+			return check.matches("(?i)"+this.get(position));
126
+		} else {
127
+			return false;
128
+		}
129
+	}
130
+
131
+	/**
132
+	 * Get the ignore pattern in a given position in the list.
133
+	 *
134
+	 * @param position Position to check
135
+	 * @return String showing the pattern. ("" if position isn't valid)
136
+	 */
137
+	public String get(final int position) {
138
+		if (position < this.count()) {
139
+			return ignoreInfo.get(position);
140
+		} else {
141
+			return "";
142
+		}
143
+	}
144
+
145
+	/**
146
+	 * Change the ignore pattern in a given position in the list.
147
+	 *
148
+	 * @param position Position to change
149
+	 * @param pattern New pattern
150
+	 */
151
+	public void set(final int position, final String pattern) {
152
+		if (position < this.count()) {
153
+			ignoreInfo.set(position, pattern);
154
+		}
155
+	}
156
+
157
+	/**
158
+	 * Get the amount of ignores in the list.
159
+	 *
160
+	 * @return int showing the number of ignores
161
+	 */
162
+	public int count() {
163
+		return ignoreInfo.size();
164
+	}
165
+
166
+}

+ 201
- 0
src/com/dmdirc/parser/irc/ServerInfo.java View File

@@ -0,0 +1,201 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * Contains Server information.
27
+ * 
28
+ * @author Shane Mc Cormack
29
+ * @author Chris Smith
30
+ * @see IRCParser
31
+ */
32
+public class ServerInfo {
33
+	/**
34
+	 * A version number for this class. It should be changed whenever the class
35
+	 * structure is changed (or anything else that would prevent serialized
36
+	 * objects being unserialized with the new class).
37
+	 */
38
+	private static final long serialVersionUID = 1;
39
+
40
+	/** Server to connect to (Default: "irc.quakenet.org"). */
41
+	private String host = "irc.quakenet.org";
42
+	/** Port server listens on for client connections (Default: 6667). */
43
+	private int port = 6667;
44
+	/** Optional password needed to connect to server (Default: ""). */
45
+	private String password = "";
46
+	/** Is this an ssl-enabled server (Default: false). */
47
+	private boolean isSSL = false;	
48
+	/** Are we using a socks proxy (Default: false). */
49
+	private boolean useSocksProxy = false;
50
+	/** Proxy server to connect to (Default: "127.0.0.1"). */
51
+	private String proxyHost = "127.0.0.1";
52
+	/** Port server listens on for client connections (Default: 8080). */
53
+	private int proxyPort = 1080;
54
+	/** Proxy username if required. */
55
+	private String proxyUser = "";
56
+	/** Proxy password if required. */
57
+	private String proxyPass = "";
58
+	
59
+	/** Constructor using Default values. */
60
+	public ServerInfo () { }
61
+	
62
+	/**
63
+	 * Constructor using specifed host, port and password, SSL/Proxy must be specifed separately.
64
+	 *
65
+	 * @param serverHost Host to use
66
+	 * @param serverPort Port to use
67
+	 * @param serverPass Password to use
68
+	 */
69
+	public ServerInfo (final String serverHost, final int serverPort, final String serverPass) {
70
+		host = serverHost;
71
+		port = serverPort;
72
+		password = serverPass;
73
+	}
74
+	
75
+	/**
76
+	 * Set the hostname.
77
+	 *
78
+	 * @param newValue Value to set to.
79
+	 */
80
+	public void setHost(final String newValue) { host = newValue; }
81
+	
82
+	/**
83
+	 * Get the hostname.
84
+	 *
85
+	 * @return Current hostname
86
+	 */
87
+	public String getHost() { return host; }
88
+	
89
+	/**
90
+	 * Set the port.
91
+	 *
92
+	 * @param newValue Value to set to.
93
+	 */
94
+	public void setPort(final int newValue) { port = newValue; }
95
+	
96
+	/**
97
+	 * Get the port.
98
+	 *
99
+	 * @return Current port
100
+	 */
101
+	public int getPort() { return port; }
102
+	
103
+	/**
104
+	 * Set the password.
105
+	 *
106
+	 * @param newValue Value to set to.
107
+	 */
108
+	public void setPassword(final String newValue) { password = newValue; }
109
+	
110
+	/**
111
+	 * Get the password.
112
+	 *
113
+	 * @return Current Password
114
+	 */
115
+	public String getPassword() { return password; }
116
+	
117
+	/**
118
+	 * Set if the server uses ssl.
119
+	 *
120
+	 * @param newValue true if server uses ssl, else false
121
+	 */
122
+	public void setSSL(final boolean newValue) { isSSL = newValue; }
123
+	
124
+	/**
125
+	 * Get if the server uses ssl.
126
+	 *
127
+	 * @return true if server uses ssl, else false
128
+	 */
129
+	public boolean getSSL() { return isSSL; }
130
+	
131
+	/**
132
+	 * Set if we are connecting via a socks proxy.
133
+	 *
134
+	 * @param newValue true if we are using socks, else false
135
+	 */
136
+	public void setUseSocks(final boolean newValue) { useSocksProxy = newValue; }
137
+	
138
+	/**
139
+	 * Get if we are connecting via a socks proxy.
140
+	 *
141
+	 * @return true if we are using socks, else false
142
+	 */
143
+	public boolean getUseSocks() { return useSocksProxy; }
144
+	
145
+	/**
146
+	 * Set the Proxy hostname.
147
+	 *
148
+	 * @param newValue Value to set to.
149
+	 */
150
+	public void setProxyHost(final String newValue) { proxyHost = newValue; }
151
+	
152
+	/**
153
+	 * Get the Proxy hostname.
154
+	 *
155
+	 * @return Current Proxy hostname
156
+	 */
157
+	public String getProxyHost() { return proxyHost; }
158
+	
159
+	/**
160
+	 * Set the Proxy port.
161
+	 *
162
+	 * @param newValue Value to set to.
163
+	 */
164
+	public void setProxyPort(final int newValue) { proxyPort = newValue; }
165
+	
166
+	/**
167
+	 * Get the Proxy port.
168
+	 *
169
+	 * @return Current Proxy port
170
+	 */
171
+	public int getProxyPort() { return proxyPort; }
172
+
173
+	/**
174
+	 * Set the Proxy username.
175
+	 *
176
+	 * @param newValue Value to set to.
177
+	 */
178
+	public void setProxyUser(final String newValue) { proxyUser = newValue; }
179
+	
180
+	/**
181
+	 * Get the Proxy username.
182
+	 *
183
+	 * @return Current Proxy username
184
+	 */
185
+	public String getProxyUser() { return proxyUser; }
186
+	
187
+	/**
188
+	 * Set the Proxy password.
189
+	 *
190
+	 * @param newValue Value to set to.
191
+	 */
192
+	public void setProxyPass(final String newValue) { proxyPass = newValue; }
193
+	
194
+	/**
195
+	 * Get the Proxy password.
196
+	 *
197
+	 * @return Current Proxy password
198
+	 */
199
+	public String getProxyPass() { return proxyPass; }
200
+}
201
+

+ 40
- 0
src/com/dmdirc/parser/irc/SocketState.java View File

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+/**
26
+ * An enumeration of possible states of an IRC Parser's socket.
27
+ *
28
+ * @since 0.6.3
29
+ * @author chris
30
+ */
31
+public enum SocketState {
32
+
33
+    /** Socket is not created yet. */
34
+    NULL,
35
+    /** Socket is closed. */
36
+    CLOSED,
37
+    /** Socket is Open. */
38
+    OPEN;
39
+
40
+}

+ 226
- 0
src/com/dmdirc/parser/irc/callbacks/CallbackManager.java View File

@@ -0,0 +1,226 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+import com.dmdirc.parser.irc.callbacks.interfaces.*;
27
+
28
+import java.util.Hashtable;
29
+import java.util.Map;
30
+
31
+/**
32
+ * IRC Parser Callback Manager.
33
+ * Manages adding/removing/calling callbacks.
34
+ *
35
+ * @author            Shane Mc Cormack
36
+ */
37
+public final class CallbackManager {
38
+
39
+    private static final Class[] CLASSES = {
40
+        IAwayState.class, IAwayStateOther.class, IChannelAwayStateOther.class,
41
+        IChannelAction.class, IChannelCTCP.class, IChannelCTCPReply.class,
42
+        IChannelGotListModes.class, IChannelGotNames.class, IChannelJoin.class,
43
+        IChannelKick.class, IChannelMessage.class, IChannelModeChanged.class,
44
+        IChannelNickChanged.class, IChannelNonUserModeChanged.class,
45
+        IChannelNotice.class, IChannelPart.class, IChannelQuit.class,
46
+        IChannelSelfJoin.class, IChannelSingleModeChanged.class,
47
+        IChannelTopic.class, IChannelUserModeChanged.class, IConnectError.class,
48
+        IDataIn.class, IDataOut.class, IDebugInfo.class, IErrorInfo.class,
49
+        IGotNetwork.class, IInvite.class, IMOTDEnd.class, IMOTDLine.class,
50
+        IMOTDStart.class, INickChanged.class, INickInUse.class,
51
+        INoticeAuth.class, INumeric.class, IPasswordRequired.class,
52
+        IPingFailed.class, IPingSuccess.class, IPingSent.class, IPrivateAction.class,
53
+        IPrivateCTCP.class, IPrivateCTCPReply.class, IPrivateMessage.class,
54
+        IPrivateNotice.class, IPost005.class, IQuit.class, IServerError.class,
55
+        IServerReady.class, ISocketClosed.class, IUnknownAction.class,
56
+        IUnknownCTCP.class, IUnknownCTCPReply.class, IUnknownMessage.class,
57
+        IUnknownNotice.class, IUserModeChanged.class, IUserModeDiscovered.class,
58
+        IWallDesync.class, IWallop.class, IWalluser.class,
59
+    };
60
+
61
+	/** Reference to the parser object that owns this CallbackManager. */
62
+	IRCParser myParser;
63
+	
64
+	/** Hashtable used to store the different types of callback known. */
65
+	private final Map<String, CallbackObject> callbackHash = new Hashtable<String, CallbackObject>();
66
+	
67
+	/**
68
+	 * Constructor to create a CallbackManager.
69
+	 *
70
+	 * @param parser IRCParser that owns this callback manager.
71
+	 */
72
+	public CallbackManager(final IRCParser parser) {
73
+		myParser = parser;
74
+		
75
+        for (Class<?> type : CLASSES) {
76
+            if (type.isAnnotationPresent(SpecificCallback.class)) {
77
+                addCallbackType(new CallbackObjectSpecific(myParser, this,
78
+                        type.asSubclass(ICallbackInterface.class)));
79
+            } else {
80
+                addCallbackType(new CallbackObject(myParser, this,
81
+                        type.asSubclass(ICallbackInterface.class)));
82
+            }
83
+        }
84
+	}
85
+
86
+	/**
87
+	 * Add new callback type.
88
+	 *
89
+	 * @param callback CallbackObject subclass for the callback.
90
+	 * @return if adding succeeded or not.
91
+	 */
92
+	public boolean addCallbackType(final CallbackObject callback) {
93
+		if (!callbackHash.containsKey(callback.getLowerName())) {
94
+			callbackHash.put(callback.getLowerName(), callback);
95
+			return true;
96
+		}
97
+		return false;
98
+	}
99
+	
100
+	/**
101
+	 * Remove a callback type.
102
+	 *
103
+	 * @param callback CallbackObject subclass to remove.
104
+	 * @return if removal succeeded or not.
105
+	 */
106
+	public boolean delCallbackType(final CallbackObject callback) {
107
+		if (callbackHash.containsKey(callback.getLowerName())) {
108
+			callbackHash.remove(callback.getLowerName());
109
+			return true;
110
+		}
111
+		return false;
112
+	}
113
+	
114
+	/**
115
+	 * Get reference to callback object.
116
+	 *
117
+	 * @param callbackName Name of callback object.
118
+	 * @return CallbackObject returns the callback object for this type
119
+	 */
120
+	public CallbackObject getCallbackType(final String callbackName) {
121
+		if (!callbackHash.containsKey(callbackName.toLowerCase())) {
122
+			throw new CallbackNotFoundException("Callback not found: " + callbackName);
123
+		}
124
+		
125
+		return callbackHash.get(callbackName.toLowerCase());
126
+	}
127
+	
128
+	/**
129
+	 * Remove all callbacks associated with a specific object.
130
+	 *
131
+	 * @param o instance of ICallbackInterface to remove.
132
+	 */
133
+	public void delAllCallback(final ICallbackInterface o) {
134
+		for (CallbackObject cb : callbackHash.values()) {
135
+			if (cb != null) { cb.del(o); }
136
+		}
137
+	}
138
+	
139
+	/**
140
+	 * Add all callbacks.
141
+	 *
142
+	 * @param o instance of ICallbackInterface to add.
143
+	 */
144
+	public void addAllCallback(final ICallbackInterface o) {
145
+		for (CallbackObject cb : callbackHash.values()) {
146
+			if (cb != null) { cb.add(o); }
147
+		}
148
+	}
149
+	
150
+	/**
151
+	 * Add a callback.
152
+ 	 * This method will throw a CallbackNotFoundException if the callback does not exist.
153
+	 *
154
+	 * @param callbackName Name of callback object.
155
+	 * @param o instance of ICallbackInterface to add.
156
+	 * @throws CallbackNotFoundException If callback is not found.
157
+	 * @throws NullPointerException If 'o' is null
158
+	 */
159
+	public void addCallback(final String callbackName, final ICallbackInterface o) throws CallbackNotFoundException {
160
+		if (o == null) {
161
+			throw new NullPointerException("CallbackInterface is null");
162
+		}
163
+		
164
+		final CallbackObject cb = getCallbackType(callbackName);
165
+		
166
+		if (cb != null) { cb.add(o); }
167
+	}
168
+	
169
+	/**
170
+	 * Add a callback with a specific target.
171
+ 	 * This method will throw a CallbackNotFoundException if the callback does not exist.
172
+	 *
173
+	 * @param callbackName Name of callback object.
174
+	 * @param o instance of ICallbackInterface to add.
175
+	 * @param target Parameter to specify that a callback should only fire for specific things
176
+	 * @throws CallbackNotFoundException If callback is not found.
177
+	 * @throws NullPointerException If 'o' is null
178
+	 */
179
+	public void addCallback(final String callbackName, final ICallbackInterface o, final String target) throws CallbackNotFoundException {
180
+		if (o == null) { throw new NullPointerException("CallbackInterface is null"); }
181
+		((CallbackObjectSpecific) getCallbackType(callbackName)).add(o,target);
182
+	}
183
+	
184
+	/**
185
+	 * Add a callback without an exception.
186
+	 * This should be used if a callback is not essential for execution (ie the DebugOut callback)
187
+	 *
188
+	 * @param callbackName Name of callback object.
189
+	 * @param o instance of ICallbackInterface to add.
190
+	 * @return true/false if the callback was added or not.
191
+	 */
192
+	public boolean addNonCriticalCallback(final String callbackName, final ICallbackInterface o)  {
193
+		try {
194
+			addCallback(callbackName, o);
195
+			return true;
196
+		} catch (CallbackNotFoundException e) { return false; }
197
+	}
198
+	
199
+	/**
200
+	 * Add a callback with a specific target.
201
+	 * This should be used if a callback is not essential for execution
202
+	 *
203
+	 * @param callbackName Name of callback object.
204
+	 * @param o instance of ICallbackInterface to add.
205
+	 * @param target Parameter to specify that a callback should only fire for specific things
206
+	 * @return true/false if the callback was added or not.
207
+	 */
208
+	public boolean addNonCriticalCallback(final String callbackName, final ICallbackInterface o, final String target) {
209
+		try {
210
+			addCallback(callbackName, o, target);
211
+			return true;
212
+		} catch (CallbackNotFoundException e) { return false;	}
213
+	}
214
+	
215
+	
216
+	/**
217
+	 * Remove a callback.
218
+	 *
219
+	 * @param callbackName Name of callback object.
220
+	 * @param o instance of ICallbackInterface to remove.
221
+	 */
222
+	public void delCallback(final String callbackName, final ICallbackInterface o) {
223
+		getCallbackType(callbackName).del(o);
224
+	}
225
+
226
+}

+ 45
- 0
src/com/dmdirc/parser/irc/callbacks/CallbackNotFoundException.java View File

@@ -0,0 +1,45 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks;
24
+
25
+/**
26
+ * IRC Parser Callback Exception.
27
+ *
28
+ * @author            Shane Mc Cormack
29
+ */
30
+public class CallbackNotFoundException extends RuntimeException {
31
+	/**
32
+	 * A version number for this class. It should be changed whenever the class
33
+	 * structure is changed (or anything else that would prevent serialized
34
+	 * objects being unserialized with the new class).
35
+	 */
36
+	private static final long serialVersionUID = 1;
37
+	
38
+	/**
39
+	 * Create a new CallbackNotFound Exception.
40
+	 *
41
+	 * @param message Reason for exception
42
+	 */
43
+	public CallbackNotFoundException(final String message) { super(message); }
44
+
45
+}

+ 268
- 0
src/com/dmdirc/parser/irc/callbacks/CallbackObject.java View File

@@ -0,0 +1,268 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+import com.dmdirc.parser.irc.ParserError;
27
+import com.dmdirc.parser.irc.callbacks.interfaces.ICallbackInterface;
28
+
29
+import java.lang.annotation.Annotation;
30
+import java.lang.reflect.Constructor;
31
+import java.lang.reflect.InvocationTargetException;
32
+import java.lang.reflect.Method;
33
+import java.util.ArrayList;
34
+import java.util.HashMap;
35
+import java.util.List;
36
+import java.util.Map;
37
+
38
+/**
39
+ * CallbackObject.
40
+ * Superclass for all callback types.
41
+ *
42
+ * @author            Shane Mc Cormack
43
+ */
44
+public class CallbackObject {
45
+
46
+    /** The type of callback that this object is operating with. */
47
+    protected final Class<? extends ICallbackInterface> type;
48
+
49
+	/** Arraylist for storing callback information related to the callback. */
50
+	protected final List<ICallbackInterface> callbackInfo = new ArrayList<ICallbackInterface>();
51
+	
52
+	/** Reference to the IRCParser that owns this callback. */
53
+	protected IRCParser myParser;
54
+	/** Reference to the CallbackManager in charge of this callback. */
55
+	protected CallbackManager myManager;
56
+	
57
+	/**
58
+	 * Create a new instance of the Callback Object.
59
+	 *
60
+	 * @param parser IRCParser That owns this callback
61
+	 * @param manager CallbackManager that is in charge of this callback
62
+     * @param type The type of callback to use
63
+     * @since 0.6.3
64
+	 */
65
+	protected CallbackObject(final IRCParser parser, final CallbackManager manager,
66
+            final Class<? extends ICallbackInterface> type) {
67
+		this.myParser = parser;
68
+		this.myManager = manager;
69
+        this.type = type;
70
+	}
71
+	
72
+	/**
73
+	 * Add a callback pointer to the appropriate ArrayList.
74
+	 *
75
+	 * @param eMethod OBject to callback to.
76
+	 */
77
+	protected final void addCallback(final ICallbackInterface eMethod) {
78
+		for (int i = 0; i < callbackInfo.size(); i++) {
79
+			if (eMethod.equals(callbackInfo.get(i))) { return; }
80
+		}
81
+		callbackInfo.add(eMethod);
82
+	}
83
+	
84
+	/**
85
+	 * Delete a callback pointer from the appropriate ArrayList.
86
+	 *
87
+	 * @param eMethod Object that was being called back to.
88
+	 */
89
+	protected final void delCallback(final ICallbackInterface eMethod) {
90
+		for (int i = 0; i < callbackInfo.size(); i++) {
91
+			if (eMethod.equals(callbackInfo.get(i))) { callbackInfo.remove(i); break; }
92
+		}
93
+	}
94
+	
95
+	/**
96
+	 * Call the OnErrorInfo callback.
97
+	 *
98
+	 * @param errorInfo ParserError object to pass as error.
99
+	 * @return true if error call succeeded, false otherwise
100
+	 */
101
+	protected final boolean callErrorInfo(final ParserError errorInfo) {
102
+		return myManager.getCallbackType("OnErrorInfo").call(errorInfo);
103
+	}
104
+	
105
+	/**
106
+	 * Add a new callback.
107
+	 *
108
+	 * @param eMethod Object to callback to.
109
+	 */
110
+	public void add(final ICallbackInterface eMethod) { addCallback(eMethod); }
111
+	
112
+	/**
113
+	 * Remove a callback.
114
+	 *
115
+	 * @param eMethod Object to remove callback to.
116
+	 */
117
+	public void del(final ICallbackInterface eMethod) { delCallback(eMethod); }
118
+	
119
+	/**
120
+	 * Get the name for this callback.
121
+	 *
122
+	 * @return Name of callback
123
+	 */
124
+	public String getName() {
125
+		return "On" + type.getSimpleName().substring(1); // Trim the 'I'
126
+	}
127
+	
128
+	/**
129
+	 * Get the name for this callback in lowercase.
130
+	 *
131
+	 * @return Name of callback, in lowercase
132
+	 */
133
+	public final String getLowerName() { return this.getName().toLowerCase(); }
134
+
135
+    /**
136
+     * Actually calls this callback. The specified arguments must match those
137
+     * specified in the callback's interface, or an error will be raised.
138
+     *
139
+     * @param args The arguments to pass to the callback implementation
140
+     * @return True if a method was called, false otherwise
141
+     */
142
+    public boolean call(final Object ... args) {
143
+		boolean bResult = false;
144
+
145
+        final Object[] newArgs = new Object[args.length + 1];
146
+        System.arraycopy(args, 0, newArgs, 1, args.length);
147
+        newArgs[0] = myParser;
148
+
149
+        if (myParser.getCreateFake()) {
150
+            createFakeArgs(newArgs);
151
+        }
152
+
153
+		for (ICallbackInterface iface : new ArrayList<ICallbackInterface>(callbackInfo)) {
154
+			try {
155
+                type.getMethods()[0].invoke(iface, newArgs);
156
+			} catch (Exception e) {
157
+				final ParserError ei = new ParserError(ParserError.ERROR_ERROR,
158
+                        "Exception in callback ("+e.getMessage()+")", myParser.getLastLine());
159
+				ei.setException(e);
160
+				callErrorInfo(ei);
161
+			}
162
+			bResult = true;
163
+		}
164
+		return bResult;
165
+    }
166
+
167
+    /**
168
+     * Replaces all null entries in the specified array with fake values,
169
+     * if the corresponding parameter of this callback's type is marked with
170
+     * the {@link FakableArgument} annotation. The fake classes are constructed
171
+     * by using parameters designated {@link FakableSource}.
172
+     *
173
+     * @param args The arguments to be faked
174
+     */
175
+    protected void createFakeArgs(final Object[] args) {
176
+        int i = 0;
177
+
178
+        for (Annotation[] anns : type.getMethods()[0].getParameterAnnotations()) {
179
+            for (Annotation ann : anns) {
180
+                if (ann.annotationType().equals(FakableArgument.class)
181
+                        && args[i] == null) {
182
+                    args[i] = getFakeArg(args, type.getMethods()[0].getParameterTypes()[i]);
183
+                }
184
+            }
185
+
186
+            i++;
187
+        }
188
+    }
189
+
190
+    /**
191
+     * Tries to create fake argument of the specified target class, by using
192
+     * {@link FakableSource} denoted parameters from the specified arg array.
193
+     *
194
+     * If an argument is missing, the method attempts to create a fake instance
195
+     * by recursing into this method again. Note that this could cause an
196
+     * infinite recursion in cases of cyclic dependencies. If recursion fails,
197
+     * the constructor is skipped.
198
+     *
199
+     * If the created object has a <code>setFake(boolean)</code> method, it
200
+     * is automatically invoked with an argument of <code>true</code>.
201
+     *
202
+     * @param args The arguments array to use for sources
203
+     * @param target The class that should be constructed
204
+     * @return An instance of the target class, or null on failure
205
+     */
206
+    protected Object getFakeArg(final Object[] args, final Class<?> target) {
207
+        final Map<Class, Object> sources = new HashMap<Class, Object>();
208
+        int i = 0;
209
+
210
+        for (Annotation[] anns : type.getMethods()[0].getParameterAnnotations()) {
211
+            for (Annotation ann : anns) {
212
+                if (ann.annotationType().equals(FakableSource.class)) {
213
+                    sources.put(type.getMethods()[0].getParameterTypes()[i], args[i]);
214
+                }
215
+            }
216
+
217
+            i++;
218
+        }
219
+
220
+        for (Constructor<?> ctor : target.getConstructors()) {
221
+            Object[] params = new Object[ctor.getParameterTypes().length];
222
+
223
+            i = 0;
224
+            Object param;
225
+            boolean failed = false;
226
+
227
+            for (Class<?> needed : ctor.getParameterTypes()) {
228
+                if (sources.containsKey(needed)) {
229
+                    params[i] = sources.get(needed);
230
+                } else if ((param = getFakeArg(args, needed)) != null) {
231
+                    params[i] = param;
232
+                } else {
233
+                    failed = true;
234
+                }
235
+
236
+                i++;
237
+            }
238
+
239
+            if (!failed) {
240
+                try {
241
+                    final Object instance = ctor.newInstance(params);
242
+
243
+                    for (Method method : target.getMethods()) {
244
+                        if (method.getName().equals("setFake")
245
+                                && method.getParameterTypes().length == 1
246
+                                && method.getParameterTypes()[0].equals(Boolean.TYPE)) {
247
+
248
+                            method.invoke(instance, true);
249
+                        }
250
+                    }
251
+
252
+                    return instance;
253
+                } catch (InstantiationException ex) {
254
+                    // Do nothing
255
+                } catch (IllegalAccessException ex) {
256
+                    // Do nothing
257
+                } catch (IllegalArgumentException ex) {
258
+                    // Do nothing
259
+                } catch (InvocationTargetException ex) {
260
+                    // Do nothing
261
+                }
262
+            }
263
+        }
264
+
265
+        return null;
266
+    }
267
+
268
+}

+ 168
- 0
src/com/dmdirc/parser/irc/callbacks/CallbackObjectSpecific.java View File

@@ -0,0 +1,168 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks;
24
+
25
+import java.util.Hashtable;
26
+
27
+import com.dmdirc.parser.irc.ChannelInfo;
28
+import com.dmdirc.parser.irc.ClientInfo;
29
+import com.dmdirc.parser.irc.IRCParser;
30
+import com.dmdirc.parser.irc.ParserError;
31
+import com.dmdirc.parser.irc.callbacks.interfaces.ICallbackInterface;
32
+import java.util.ArrayList;
33
+
34
+/**
35
+ * CallbackObjectSpecific.
36
+ * Superclass for all callback types that have a "specific" target.
37
+ *
38
+ * @author            Shane Mc Cormack
39
+ */
40
+public class CallbackObjectSpecific extends CallbackObject {
41
+	
42
+	/** Hashtable for storing specific information for callback. */	
43
+	protected volatile Hashtable<ICallbackInterface, String> specificData = new Hashtable<ICallbackInterface, String>();
44
+	
45
+	/**
46
+	 * Create a new instance of the Callback Object.
47
+	 *
48
+	 * @param parser IRCParser That owns this callback
49
+	 * @param manager CallbackManager that is in charge of this callback
50
+     * @param type The type of callback to use
51
+     * @since 0.6.3
52
+	 */
53
+	public CallbackObjectSpecific(final IRCParser parser,
54
+            final CallbackManager manager, final Class<? extends ICallbackInterface> type) {
55
+        super(parser, manager, type);
56
+    }
57
+	
58
+	/**
59
+	 * Used to check if a channel matches the specificData.
60
+	 * 
61
+	 * @param eMethod Object that is being called back to
62
+	 * @param cChannel ChannelInfo object for the channel to test
63
+	 * @return true if channel given matches the specifics for the method given
64
+	 */
65
+	protected boolean isValidChan(final ICallbackInterface eMethod, final ChannelInfo cChannel) {
66
+		if (specificData.containsKey(eMethod)) { 
67
+			if (!myParser.getIRCStringConverter().equalsIgnoreCase(cChannel.getName(), specificData.get(eMethod))) { return false; }
68
+		}
69
+		return true;
70
+	}
71
+	
72
+	/**
73
+	 * Used to check if a hostname matches the specificData.
74
+	 * 
75
+	 * @param eMethod Object that is being called back to
76
+	 * @param sHost Hostname of user that sent the query
77
+	 * @return true if host given matches the specifics for the method given
78
+	 */
79
+	protected boolean isValidUser(final ICallbackInterface eMethod, final String sHost) {
80
+		final String nickname = ClientInfo.parseHost(sHost);
81
+		if (specificData.containsKey(eMethod)) {
82
+			if (!myParser.getIRCStringConverter().equalsIgnoreCase(nickname, specificData.get(eMethod))) { return false; }
83
+		}
84
+		return true;
85
+	}
86
+	
87
+	// We override the default add method to make sure that any add with no
88
+	// specifics will have the specific data removed.
89
+	/**
90
+	 * Add a new callback.
91
+	 *
92
+	 * @param eMethod Object to callback to.
93
+	 */
94
+    @Override
95
+	public void add(final ICallbackInterface eMethod) {
96
+		addCallback(eMethod);
97
+		if (specificData.containsKey(eMethod)) { specificData.remove(eMethod); }
98
+	}
99
+	
100
+	/**
101
+	 * Add a new callback with a specific target.
102
+	 *
103
+	 * @param eMethod Object to callback to.
104
+	 * @param specificTarget Target that must match for callback to be called.
105
+	 */
106
+	public void add(final ICallbackInterface eMethod, final String specificTarget) {
107
+		add(eMethod);
108
+		if (!specificTarget.isEmpty()) {
109
+			specificData.put(eMethod, specificTarget);
110
+		}
111
+	}
112
+	
113
+	/**
114
+	 * Remove a callback.
115
+	 *
116
+	 * @param eMethod Object to remove callback to.
117
+	 */
118
+    @Override
119
+	public void del(final ICallbackInterface eMethod) {
120
+		delCallback(eMethod);
121
+		if (specificData.containsKey(eMethod)) { specificData.remove(eMethod); }
122
+	}
123
+
124
+    /**
125
+     * Actually calls this callback. The specified arguments must match those
126
+     * specified in the callback's interface, or an error will be raised.
127
+     *
128
+     * @param args The arguments to pass to the callback implementation
129
+     * @return True if a method was called, false otherwise
130
+     */
131
+    @Override
132
+    public boolean call(final Object ... args) {
133
+		boolean bResult = false;
134
+
135
+        final Object[] newArgs = new Object[args.length + 1];
136
+        System.arraycopy(args, 0, newArgs, 1, args.length);
137
+        newArgs[0] = myParser;
138
+
139
+        if (myParser.getCreateFake()) {
140
+            createFakeArgs(newArgs);
141
+        }
142
+
143
+		for (ICallbackInterface iface :new ArrayList<ICallbackInterface>(callbackInfo)) {
144
+            if (type.isAnnotationPresent(SpecificCallback.class) &&
145
+                    ((args[0] instanceof ClientInfo
146
+                        && !isValidUser(iface, ((ClientInfo) args[0]).getHost()))
147
+                        || (args[0] instanceof ChannelInfo
148
+                        && !isValidChan(iface, (ChannelInfo) args[0]))
149
+                        || (!(args[0] instanceof ClientInfo || args[0] instanceof ChannelInfo) &&
150
+                        args[args.length - 1] instanceof String
151
+                        && !isValidUser(iface, (String) args[args.length - 1])))) {
152
+                continue;
153
+            }
154
+
155
+			try {
156
+                type.getMethods()[0].invoke(iface, newArgs);
157
+			} catch (Exception e) {
158
+				final ParserError ei = new ParserError(ParserError.ERROR_ERROR,
159
+                        "Exception in callback ("+e.getMessage()+")", myParser.getLastLine());
160
+				ei.setException(e);
161
+				callErrorInfo(ei);
162
+			}
163
+			bResult = true;
164
+		}
165
+		return bResult;
166
+    }
167
+
168
+}

+ 40
- 0
src/com/dmdirc/parser/irc/callbacks/FakableArgument.java View File

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks;
24
+
25
+import java.lang.annotation.ElementType;
26
+import java.lang.annotation.Retention;
27
+import java.lang.annotation.RetentionPolicy;
28
+import java.lang.annotation.Target;
29
+
30
+/**
31
+ * Indicates a specific argument may be faked.
32
+ *
33
+ * @since 0.6.3
34
+ * @author chris
35
+ */
36
+@Retention(RetentionPolicy.RUNTIME)
37
+@Target(ElementType.PARAMETER)
38
+public @interface FakableArgument {
39
+
40
+}

+ 41
- 0
src/com/dmdirc/parser/irc/callbacks/FakableSource.java View File

@@ -0,0 +1,41 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks;
24
+
25
+import java.lang.annotation.ElementType;
26
+import java.lang.annotation.Retention;
27
+import java.lang.annotation.RetentionPolicy;
28
+import java.lang.annotation.Target;
29
+
30
+/**
31
+ * Indicates that the specified argument is a source of data for fakable
32
+ * arguments.
33
+ *
34
+ * @since 0.6.3
35
+ * @author chris
36
+ */
37
+@Retention(RetentionPolicy.RUNTIME)
38
+@Target(ElementType.PARAMETER)
39
+public @interface FakableSource {
40
+
41
+}

+ 38
- 0
src/com/dmdirc/parser/irc/callbacks/SpecificCallback.java View File

@@ -0,0 +1,38 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks;
24
+
25
+import java.lang.annotation.Retention;
26
+import java.lang.annotation.RetentionPolicy;
27
+
28
+/**
29
+ * Used to indicate that a callback interface can be called for specified
30
+ * objects (hosts/channels/etc).
31
+ *
32
+ * @since 0.6.3
33
+ * @author chris
34
+ */
35
+@Retention(RetentionPolicy.RUNTIME)
36
+public @interface SpecificCallback {
37
+
38
+}

+ 40
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IAwayState.java View File

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Called when we go away, or come back.
29
+ */
30
+public interface IAwayState extends ICallbackInterface { 
31
+	/**
32
+	 * Called when we go away, or come back.
33
+	 *
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @param currentState Set to true if we are now away, else false.
36
+	 * @param reason Best guess at away reason
37
+	 * @see com.dmdirc.parser.irc.ProcessAway#callAwayState
38
+	 */
39
+	void onAwayState(IRCParser tParser, boolean currentState, String reason);
40
+}

+ 43
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IAwayStateOther.java View File

@@ -0,0 +1,43 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+import com.dmdirc.parser.irc.ClientInfo;
27
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
28
+
29
+/**
30
+ * Called when we go away, or come back.
31
+ */
32
+@SpecificCallback
33
+public interface IAwayStateOther extends ICallbackInterface { 
34
+	/**
35
+	 * Called when we go away, or come back.
36
+	 *
37
+	 * @param tParser Reference to the parser object that made the callback.
38
+	 * @param client Client this is for
39
+	 * @param state Away State (true if away, false if here)
40
+	 * @see com.dmdirc.parser.irc.ProcessAway#callAwayStateOther
41
+	 */
42
+	void onAwayStateOther(IRCParser tParser, ClientInfo client, boolean state);
43
+}

+ 28
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/ICallbackInterface.java View File

@@ -0,0 +1,28 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+/**
26
+ * "SuperInterface" for all callbacks.
27
+ */
28
+public interface ICallbackInterface { }

+ 57
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelAction.java View File

@@ -0,0 +1,57 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.FakableArgument;
29
+import com.dmdirc.parser.irc.callbacks.FakableSource;
30
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
31
+
32
+/**
33
+ * Called when a person does an action in a channel.
34
+ * sHost is the hostname of the person sending the action. (Can be a server or a person)<br>
35
+ * cChannelClient is null if user is a server, or not on the channel.
36
+ */
37
+@SpecificCallback
38
+public interface IChannelAction extends ICallbackInterface {
39
+	/**
40
+	 * Called when a person does an action in a channel.
41
+	 * sHost is the hostname of the person sending the action. (Can be a server or a person)<br>
42
+	 * cChannelClient is null if user is a server, or not on the channel.
43
+	 * 
44
+	 * @param tParser Reference to the parser object that made the callback.
45
+	 * @param cChannel Channel where the action was sent to
46
+	 * @param cChannelClient ChannelClient who sent the action (may be null if server)
47
+	 * @param sMessage action contents
48
+	 * @param sHost Hostname of sender (or servername)
49
+	 * @see com.dmdirc.parser.irc.ProcessMessage#callChannelAction
50
+	 */
51
+	void onChannelAction(
52
+            @FakableSource IRCParser tParser,
53
+            @FakableSource ChannelInfo cChannel,
54
+            @FakableArgument ChannelClientInfo cChannelClient,
55
+            String sMessage,
56
+            @FakableSource String sHost);
57
+}

+ 45
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelAwayStateOther.java View File

@@ -0,0 +1,45 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+import com.dmdirc.parser.irc.ChannelClientInfo;
27
+import com.dmdirc.parser.irc.ChannelInfo;
28
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
29
+
30
+/**
31
+ * Called when we go away, or come back.
32
+ */
33
+@SpecificCallback
34
+public interface IChannelAwayStateOther extends ICallbackInterface { 
35
+	/**
36
+	 * Called when we go away, or come back.
37
+	 *
38
+	 * @param tParser Reference to the parser object that made the callback.
39
+	 * @param channel Channel this is for
40
+	 * @param channelClient Client this is for
41
+	 * @param state Away State (true if away, false if here)
42
+	 * @see com.dmdirc.parser.irc.ProcessAway#callChannelAwayStateOther
43
+	 */
44
+	void onChannelAwayStateOther(IRCParser tParser, ChannelInfo channel, ChannelClientInfo channelClient, boolean state);
45
+}

+ 57
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelCTCP.java View File

@@ -0,0 +1,57 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.FakableArgument;
29
+import com.dmdirc.parser.irc.callbacks.FakableSource;
30
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
31
+
32
+/**
33
+ * Called when a person sends a CTCP to a channel.
34
+ * sHost is the hostname of the person sending the CTCP. (Can be a server or a person)<br>
35
+ * cChannelClient is null if user is a server.
36
+ */
37
+@SpecificCallback
38
+public interface IChannelCTCP extends ICallbackInterface {
39
+	/**
40
+	 * Called when a person sends a CTCP to a channel.
41
+	 * sHost is the hostname of the person sending the CTCP. (Can be a server or a person)<br>
42
+	 * cChannelClient is null if user is a server.
43
+	 * 
44
+	 * @param tParser Reference to the parser object that made the callback.
45
+	 * @param cChannel Channel where CTCP was sent
46
+	 * @param cChannelClient ChannelClient who sent the message (may be null if server)
47
+	 * @param sType Type of CTCP (VERSION, TIME etc)
48
+	 * @param sMessage Additional contents
49
+	 * @param sHost Hostname of sender (or servername)
50
+	 * @see com.dmdirc.parser.irc.ProcessMessage#callChannelCTCP
51
+	 */
52
+	void onChannelCTCP(@FakableSource IRCParser tParser,
53
+            @FakableSource ChannelInfo cChannel,
54
+            @FakableArgument ChannelClientInfo cChannelClient,
55
+            String sType, String sMessage,
56
+            @FakableSource String sHost);
57
+}

+ 57
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelCTCPReply.java View File

@@ -0,0 +1,57 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.FakableArgument;
29
+import com.dmdirc.parser.irc.callbacks.FakableSource;
30
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
31
+
32
+/**
33
+ * Called when a person sends a CTCPRReply to a channel.
34
+ * sHost is the hostname of the person sending the CTCPReply. (Can be a server or a person)<br>
35
+ * cChannelClient is null if user is a server.
36
+ */
37
+@SpecificCallback
38
+public interface IChannelCTCPReply extends ICallbackInterface {
39
+	/**
40
+	 * Called when a person sends a CTCPRReply to a channel.
41
+	 * sHost is the hostname of the person sending the CTCPReply. (Can be a server or a person)<br>
42
+	 * cChannelClient is null if user is a server.
43
+	 * 
44
+	 * @param tParser Reference to the parser object that made the callback.
45
+	 * @param cChannel Channel where CTCPReply was sent
46
+	 * @param cChannelClient ChannelClient who sent the message (may be null if server)
47
+	 * @param sType Type of CTCPRReply (VERSION, TIME etc)
48
+	 * @param sMessage Reply Contents
49
+	 * @param sHost Hostname of sender (or servername)
50
+	 * @see com.dmdirc.parser.irc.ProcessMessage#callChannelCTCPReply
51
+	 */
52
+	void onChannelCTCPReply(@FakableSource IRCParser tParser,
53
+            @FakableSource ChannelInfo cChannel,
54
+            @FakableArgument ChannelClientInfo cChannelClient,
55
+            String sType, String sMessage,
56
+            @FakableSource String sHost);
57
+}

+ 44
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelGotListModes.java View File

@@ -0,0 +1,44 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelInfo;
26
+import com.dmdirc.parser.irc.IRCParser;
27
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
28
+
29
+/**
30
+ * Called when all requested ListModes have been sent.
31
+ * This is decided by ProcessListModes, and is called when an "end of list"
32
+ * reply is sent, and the listModeQueue is empty (or non-existant).
33
+ */
34
+@SpecificCallback
35
+public interface IChannelGotListModes extends ICallbackInterface {
36
+	/**
37
+	 * Called when a ListModes reply is parsed.
38
+	 *
39
+	 * @param tParser Reference to the parser object that made the callback.
40
+	 * @param cChannel Channel which the ListModes reply is for
41
+	 * @see com.dmdirc.parser.irc.ProcessListModes#callChannelGotListModes
42
+	 */
43
+	void onChannelGotListModes(IRCParser tParser, ChannelInfo cChannel);
44
+}

+ 42
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelGotNames.java View File

@@ -0,0 +1,42 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelInfo;
26
+import com.dmdirc.parser.irc.IRCParser;
27
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
28
+
29
+/**
30
+ * Called when a names reply is parsed.
31
+ */
32
+@SpecificCallback
33
+public interface IChannelGotNames extends ICallbackInterface {
34
+	/**
35
+	 * Called when a names reply is parsed.
36
+	 *
37
+	 * @param tParser Reference to the parser object that made the callback.
38
+	 * @param cChannel Channel which the names reply is for
39
+	 * @see com.dmdirc.parser.irc.ProcessNames#callChannelGotNames
40
+	 */
41
+	void onChannelGotNames(IRCParser tParser, ChannelInfo cChannel);
42
+}

+ 46
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelJoin.java View File

@@ -0,0 +1,46 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
29
+
30
+/** 
31
+ * Called When we, or another client joins a channel.
32
+ * This is called AFTER client has been added to channel as a ChannelClientInfo
33
+ */
34
+@SpecificCallback
35
+public interface IChannelJoin extends ICallbackInterface {
36
+	/**
37
+	 * Called When another client joins a channel.
38
+	 * This is called AFTER client has been added to channel as a ChannelClientInfo
39
+	 * 
40
+	 * @param tParser Reference to the parser object that made the callback.
41
+	 * @param cChannel Channel Object
42
+	 * @param cChannelClient ChannelClient object for new person
43
+	 * @see com.dmdirc.parser.irc.ProcessJoin#callChannelJoin
44
+	 */
45
+	void onChannelJoin(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cChannelClient);
46
+}

+ 56
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelKick.java View File

@@ -0,0 +1,56 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.FakableArgument;
29
+import com.dmdirc.parser.irc.callbacks.FakableSource;
30
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
31
+
32
+/**
33
+ * Called when a person is kicked.
34
+ * cKickedByClient can be null if kicked by a server. sKickedByHost is the hostname of the person/server doing the kicking.
35
+ */
36
+@SpecificCallback
37
+public interface IChannelKick extends ICallbackInterface {
38
+	/**
39
+	 * Called when a person is kicked.
40
+	 * cKickedByClient can be null if kicked by a server. sKickedByHost is the hostname of the person/server doing the kicking.
41
+	 *
42
+	 * @param tParser Reference to the parser object that made the callback.
43
+	 * @param cChannel Channel where the kick took place
44
+	 * @param cKickedClient ChannelClient that got kicked
45
+	 * @param cKickedByClient ChannelClient that did the kicking (may be null if server)
46
+	 * @param sReason Reason for kick (may be "")
47
+	 * @param sKickedByHost Hostname of Kicker (or servername)
48
+	 * @see com.dmdirc.parser.irc.ProcessKick#callChannelKick
49
+	 */
50
+	void onChannelKick(@FakableSource IRCParser tParser,
51
+            @FakableSource ChannelInfo cChannel,
52
+            ChannelClientInfo cKickedClient,
53
+            @FakableArgument ChannelClientInfo cKickedByClient,
54
+            String sReason,
55
+            @FakableSource String sKickedByHost);
56
+}

+ 56
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelMessage.java View File

@@ -0,0 +1,56 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.FakableArgument;
29
+import com.dmdirc.parser.irc.callbacks.FakableSource;
30
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
31
+
32
+/**
33
+ * Called when a person sends a message to a channel.
34
+ * sHost is the hostname of the person sending the message. (Can be a server or a person)<br>
35
+ * cChannelClient is null if user is a server, or not on the channel.
36
+ */
37
+@SpecificCallback
38
+public interface IChannelMessage extends ICallbackInterface {
39
+	/**
40
+	 * Called when a person sends a message to a channel.
41
+	 * sHost is the hostname of the person sending the message. (Can be a server or a person)<br>
42
+	 * cChannelClient is null if user is a server, or not on the channel.
43
+	 *
44
+	 * @param tParser Reference to the parser object that made the callback.
45
+	 * @param cChannel Channel where the message was sent to
46
+	 * @param cChannelClient ChannelClient who sent the message (may be null if server)
47
+	 * @param sMessage Message contents
48
+	 * @param sHost Hostname of sender (or servername)
49
+	 * @see com.dmdirc.parser.irc.ProcessMessage#callChannelMessage
50
+	 */
51
+	void onChannelMessage(@FakableSource IRCParser tParser,
52
+            @FakableSource ChannelInfo cChannel,
53
+            @FakableArgument ChannelClientInfo cChannelClient,
54
+            String sMessage,
55
+            @FakableSource String sHost);
56
+}

+ 56
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelModeChanged.java View File

@@ -0,0 +1,56 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.FakableArgument;
29
+import com.dmdirc.parser.irc.callbacks.FakableSource;
30
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
31
+
32
+/** 
33
+ * Called when the channel modes are changed or discovered.
34
+ * cChannelClient is null if the modes were found from raw 324 (/MODE #Chan reply) or if a server set the mode.<br>
35
+ * If a Server set the mode, sHost is the servers name, else it is the full host of the user who set it
36
+ */
37
+@SpecificCallback
38
+public interface IChannelModeChanged extends ICallbackInterface {
39
+	/**
40
+	 * Called when the channel modes are changed or discovered.
41
+	 * cChannelClient is null if the modes were found from raw 324 (/MODE #Chan reply) or if a server set the mode.<br>
42
+	 * If a Server set the mode, sHost is the servers name, else it is the full host of the user who set it
43
+	 * 
44
+	 * @param tParser Reference to the parser object that made the callback.
45
+	 * @param cChannel Channel where modes were changed
46
+	 * @param cChannelClient Client chaning the modes (null if server)
47
+	 * @param sHost Host doing the mode changing (User host or server name)
48
+	 * @param sModes String showing the exact mode change parsed.
49
+	 * @see com.dmdirc.parser.irc.ProcessMode#callChannelModeChanged
50
+	 */
51
+	void onChannelModeChanged(@FakableSource IRCParser tParser,
52
+            @FakableSource ChannelInfo cChannel,
53
+            @FakableArgument ChannelClientInfo cChannelClient,
54
+            @FakableSource String sHost,
55
+            String sModes);
56
+}

+ 47
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelNickChanged.java View File

@@ -0,0 +1,47 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
29
+
30
+/** 
31
+ * Called when we or another user change nickname (Called once per channel the user is on).
32
+ * This is called after the nickname change has been done internally
33
+ */
34
+@SpecificCallback
35
+public interface IChannelNickChanged extends ICallbackInterface {
36
+	/**
37
+	 * Called when we or another user change nickname (Called once per channel the user is on).
38
+	 * This is called after the nickname change has been done internally
39
+	 * 
40
+	 * @param tParser Reference to the parser object that made the callback.
41
+	 * @param cChannel One of the channels that the user is on
42
+	 * @param cChannelClient Client changing nickname
43
+	 * @param sOldNick Nickname before change
44
+	 * @see com.dmdirc.parser.irc.ProcessNick#callChannelNickChanged
45
+	 */
46
+	 void onChannelNickChanged(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sOldNick);
47
+}

+ 56
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelNonUserModeChanged.java View File

@@ -0,0 +1,56 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.FakableArgument;
29
+import com.dmdirc.parser.irc.callbacks.FakableSource;
30
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
31
+
32
+/** 
33
+ * Called when the channel modes are changed or discovered.
34
+ * cChannelClient is null if the modes were found from raw 324 (/MODE #Chan reply) or if a server set the mode.<br>
35
+ * If a Server set the mode, sHost is the servers name, else it is the full host of the user who set it
36
+ */
37
+@SpecificCallback
38
+public interface IChannelNonUserModeChanged extends ICallbackInterface {
39
+	/**
40
+	 * Called when the channel modes are changed or discovered.
41
+	 * cChannelClient is null if the modes were found from raw 324 (/MODE #Chan reply) or if a server set the mode.<br>
42
+	 * If a Server set the mode, sHost is the servers name, else it is the full host of the user who set it
43
+	 * 
44
+	 * @param tParser Reference to the parser object that made the callback.
45
+	 * @param cChannel Channel where modes were changed
46
+	 * @param cChannelClient Client chaning the modes (null if server)
47
+	 * @param sHost Host doing the mode changing (User host or server name)
48
+	 * @param sModes String showing the exact mode change parsed. (Not including user modes)
49
+	 */
50
+	void onChannelNonUserModeChanged(@FakableSource IRCParser tParser,
51
+            @FakableSource ChannelInfo cChannel,
52
+            @FakableArgument ChannelClientInfo cChannelClient,
53
+            @FakableSource String sHost,
54
+            String sModes);
55
+}
56
+

+ 56
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelNotice.java View File

@@ -0,0 +1,56 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.FakableArgument;
29
+import com.dmdirc.parser.irc.callbacks.FakableSource;
30
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
31
+
32
+/**
33
+ * Called when a person sends a notice to a channel.
34
+ * sHost is the hostname of the person sending the notice. (Can be a server or a person)<br>
35
+ * cChannelClient is null if user is a server, or not on the channel.
36
+ */
37
+@SpecificCallback
38
+public interface IChannelNotice extends ICallbackInterface {
39
+	/**
40
+	 * Called when a person sends a notice to a channel.
41
+	 * sHost is the hostname of the person sending the notice. (Can be a server or a person)<br>
42
+	 * cChannelClient is null if user is a server, or not on the channel.
43
+	 * 
44
+	 * @param tParser Reference to the parser object that made the callback.
45
+	 * @param cChannel Channel where the notice was sent to
46
+	 * @param cChannelClient ChannelClient who sent the notice (may be null if server)
47
+	 * @param sMessage notice contents
48
+	 * @param sHost Hostname of sender (or servername)
49
+	 * @see com.dmdirc.parser.irc.ProcessMessage#callChannelNotice
50
+	 */
51
+	void onChannelNotice(@FakableSource IRCParser tParser,
52
+            @FakableSource ChannelInfo cChannel,
53
+            @FakableArgument ChannelClientInfo cChannelClient,
54
+            String sMessage,
55
+            @FakableSource String sHost);
56
+}

+ 47
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelPart.java View File

@@ -0,0 +1,47 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
29
+
30
+/** 
31
+ * Called When we, or another client parts a channel.
32
+ * This is called BEFORE client has been removed from the channel.
33
+ */
34
+@SpecificCallback
35
+public interface IChannelPart extends ICallbackInterface {
36
+	/**
37
+	 * Called When we, or another client parts a channel.
38
+	 * This is called BEFORE client has been removed from the channel.
39
+	 * 
40
+	 * @param tParser Reference to the parser object that made the callback.
41
+	 * @param cChannel Channel that the user parted
42
+	 * @param cChannelClient Client that parted
43
+	 * @param sReason Reason given for parting (May be "")
44
+	 * @see com.dmdirc.parser.irc.ProcessPart#callChannelPart
45
+	 */
46
+	void onChannelPart(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sReason);
47
+}

+ 47
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelQuit.java View File

@@ -0,0 +1,47 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
29
+
30
+/** 
31
+ * Called When we, or another client quits IRC (Called once per channel the user was on).
32
+ * This is called BEFORE client has been removed from the channel.
33
+ */
34
+@SpecificCallback
35
+public interface IChannelQuit extends ICallbackInterface {
36
+	/**
37
+	 * Called When we, or another client quits IRC (Called once per channel the user was on).
38
+	 * This is called BEFORE client has been removed from the channel.
39
+	 * 
40
+	 * @param tParser Reference to the parser object that made the callback.
41
+	 * @param cChannel Channel that user was on
42
+	 * @param cChannelClient User thats quitting
43
+	 * @param sReason Quit reason
44
+	 * @see com.dmdirc.parser.irc.ProcessQuit#callChannelQuit
45
+	 */
46
+	void onChannelQuit(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sReason);
47
+}

+ 42
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelSelfJoin.java View File

@@ -0,0 +1,42 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelInfo;
26
+import com.dmdirc.parser.irc.IRCParser;
27
+
28
+/** 
29
+ * Called When we join a channel.
30
+ * We are NOT added as a channelclient until after the names reply
31
+ */
32
+public interface IChannelSelfJoin extends ICallbackInterface {
33
+	/**
34
+	 * Called When we join a channel.
35
+	 * We are NOT added as a channelclient until after the names reply
36
+	 * 
37
+	 * @param tParser Reference to the parser object that made the callback.
38
+	 * @param cChannel Channel Object
39
+	 * @see com.dmdirc.parser.irc.ProcessJoin#callChannelSelfJoin
40
+	 */
41
+	void onChannelSelfJoin(IRCParser tParser, ChannelInfo cChannel);
42
+}

+ 56
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelSingleModeChanged.java View File

@@ -0,0 +1,56 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.FakableArgument;
29
+import com.dmdirc.parser.irc.callbacks.FakableSource;
30
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
31
+
32
+/** 
33
+ * Called when the channel modes are changed or discovered.
34
+ * cChannelClient is null if the modes were found from raw 324 (/MODE #Chan reply) or if a server set the mode.<br>
35
+ * If a Server set the mode, sHost is the servers name, else it is the full host of the user who set it
36
+ */
37
+@SpecificCallback
38
+public interface IChannelSingleModeChanged extends ICallbackInterface {
39
+	/**
40
+	 * Called when the channel modes are changed or discovered.
41
+	 * cChannelClient is null if the modes were found from raw 324 (/MODE #Chan reply) or if a server set the mode.<br>
42
+	 * If a Server set the mode, sHost is the servers name, else it is the full host of the user who set it
43
+	 * 
44
+	 * @param tParser Reference to the parser object that made the callback.
45
+	 * @param cChannel Channel where modes were changed
46
+	 * @param cChannelClient Client chaning the modes (null if server)
47
+	 * @param sHost Host doing the mode changing (User host or server name)
48
+	 * @param sModes String parsed (ie "+m" or "+k moo"
49
+	 */
50
+	void onChannelSingleModeChanged(@FakableSource IRCParser tParser,
51
+            @FakableSource ChannelInfo cChannel,
52
+            @FakableArgument ChannelClientInfo cChannelClient,
53
+            @FakableSource String sHost,
54
+            String sModes);
55
+}
56
+

+ 45
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelTopic.java View File

@@ -0,0 +1,45 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelInfo;
26
+import com.dmdirc.parser.irc.IRCParser;
27
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
28
+
29
+/** 
30
+ * Called when the topic is changed or discovered for the first time.
31
+ * bIsNewTopic is true if someone sets the topic, false if the topic is discovered on join
32
+ */
33
+@SpecificCallback
34
+public interface IChannelTopic extends ICallbackInterface {
35
+	/**
36
+	 * Called when the topic is changed or discovered for the first time.
37
+	 * bIsNewTopic is true if someone sets the topic, false if the topic is discovered on join
38
+	 * 
39
+	 * @param tParser Reference to the parser object that made the callback.
40
+	 * @param cChannel Channel that topic was set on
41
+	 * @param bIsJoinTopic True when getting topic on join, false if set by user/server
42
+	 * @see com.dmdirc.parser.irc.ProcessTopic#callChannelTopic
43
+	 */
44
+	void onChannelTopic(IRCParser tParser, ChannelInfo cChannel, boolean bIsJoinTopic);
45
+}

+ 56
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IChannelUserModeChanged.java View File

@@ -0,0 +1,56 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ChannelClientInfo;
26
+import com.dmdirc.parser.irc.ChannelInfo;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.callbacks.FakableArgument;
29
+import com.dmdirc.parser.irc.callbacks.FakableSource;
30
+import com.dmdirc.parser.irc.callbacks.SpecificCallback;
31
+
32
+/** 
33
+ * Called when a users channel mode is changed.
34
+ */
35
+@SpecificCallback
36
+public interface IChannelUserModeChanged extends ICallbackInterface {
37
+	/**
38
+	 * Called when a users channel mode is changed.
39
+	 * cChannelClient is null if the modes were found from raw 324 (/MODE #Chan reply) or if a server set the mode.<br>
40
+	 * If a Server set the mode, sHost is the servers name, else it is the full host of the user who set it
41
+	 * 
42
+	 * @param tParser Reference to the parser object that made the callback.
43
+	 * @param cChannel Channel where modes were changed
44
+	 * @param cChangedClient Client being changed
45
+	 * @param cSetByClient Client chaning the modes (null if server)
46
+	 * @param sHost Host doing the mode changing (User host or server name)
47
+	 * @param sMode String representing mode change (ie +o)
48
+	 * @see com.dmdirc.parser.irc.ProcessMode#callChannelUserModeChanged
49
+	 */
50
+	void onChannelUserModeChanged(@FakableSource IRCParser tParser,
51
+            @FakableSource ChannelInfo cChannel,
52
+            ChannelClientInfo cChangedClient,
53
+            @FakableArgument ChannelClientInfo cSetByClient,
54
+            @FakableSource String sHost,
55
+            String sMode);
56
+}

+ 40
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IConnectError.java View File

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+import com.dmdirc.parser.irc.ParserError;
27
+
28
+/**
29
+ * Called to give Error Information related to a connection attempt.
30
+ */
31
+public interface IConnectError extends ICallbackInterface {
32
+	/**
33
+	 * Called to give Error Information related to a connection attempt.
34
+	 * 
35
+	 * @param tParser Reference to the parser object that made the callback.
36
+	 * @param errorInfo ParserError object representing the error.
37
+	 * @see com.dmdirc.parser.irc.IRCParser#callConnectError
38
+	 */
39
+	void onConnectError(IRCParser tParser, ParserError errorInfo);
40
+}

+ 39
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IDataIn.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Interface Used on every incomming line BEFORE parsing.
29
+ */
30
+public interface IDataIn extends ICallbackInterface {
31
+	/**
32
+	 * Called on every incomming line BEFORE parsing.
33
+	 * 
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @param sData Incomming Line.
36
+	 * @see com.dmdirc.parser.irc.IRCParser#callDataIn
37
+	 */
38
+	void onDataIn(IRCParser tParser, String sData);
39
+}

+ 40
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IDataOut.java View File

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Called on every incomming line BEFORE being sent.
29
+ */
30
+public interface IDataOut extends ICallbackInterface {
31
+	/**
32
+	 * Called on every incomming line BEFORE being sent.
33
+	 * 
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @param sData Outgoing Data
36
+	 * @param bFromParser True if parser sent the data, false if sent using .sendLine
37
+	 * @see com.dmdirc.parser.irc.IRCParser#callDataOut
38
+	 */
39
+	void onDataOut(IRCParser tParser, String sData, boolean bFromParser);
40
+}

+ 40
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IDebugInfo.java View File

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Interface Used to give Debug Information.
29
+ */
30
+public interface IDebugInfo extends ICallbackInterface { 
31
+	/**
32
+	 * This callback is used to provide occasional debug information from the parser.
33
+	 *
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @param nLevel Debugging Level (ndInfo, ndSocket etc)
36
+	 * @param sData Debugging Information
37
+	 * @see com.dmdirc.parser.irc.IRCParser#callDebugInfo
38
+	 */
39
+	void onDebugInfo(IRCParser tParser, int nLevel, String sData);
40
+}

+ 40
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IErrorInfo.java View File

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+import com.dmdirc.parser.irc.ParserError;
27
+
28
+/**
29
+ * Called to give Error Information.
30
+ */
31
+public interface IErrorInfo extends ICallbackInterface {
32
+	/**
33
+	 * Called to give Error Information.
34
+	 * 
35
+	 * @param tParser Reference to the parser object that made the callback.
36
+	 * @param errorInfo ParserError object representing the error.
37
+	 * @see com.dmdirc.parser.irc.IRCParser#callErrorInfo
38
+	 */
39
+	void onErrorInfo(IRCParser tParser, ParserError errorInfo);
40
+}

+ 42
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IGotNetwork.java View File

@@ -0,0 +1,42 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Interface Used when the Network=blah 005 token is recieved.
29
+ */
30
+public interface IGotNetwork extends ICallbackInterface {
31
+	/**
32
+	 * Called when the Network=blah 005 token is recieved.
33
+	 * if NETWORK= is not sent in 005, this will not be called.
34
+	 * 
35
+	 * @param tParser Reference to the parser object that made the callback.
36
+	 * @param networkName The name of the network.
37
+	 * @param ircdVersion The version of the ircd.
38
+	 * @param ircdType The Guessed type of the ircd based on the name.
39
+	 * @see com.dmdirc.parser.irc.Process004005#callGotNetwork
40
+	 */
41
+	void onGotNetwork(IRCParser tParser, String networkName, String ircdVersion, String ircdType);
42
+}

+ 40
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IInvite.java View File

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Called when we are invited to a channel.
29
+ */
30
+public interface IInvite extends ICallbackInterface {
31
+	/**
32
+	 * Called when we are invited to a channel.
33
+	 * 
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @param userHost Hostname of user who invited us
36
+	 * @param channel Channel we were invited to
37
+	 * @see com.dmdirc.parser.irc.ProcessInvite#callInvite
38
+	 */
39
+	void onInvite(IRCParser tParser, String userHost, String channel);
40
+}

+ 40
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IMOTDEnd.java View File

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Called when "End of MOTD" or "No MOTD" is received.
29
+ */
30
+public interface IMOTDEnd extends ICallbackInterface { 
31
+	/**
32
+	 * Called when "End of MOTD" or "No MOTD".
33
+	 *
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @param noMOTD Set to true if this was a "No MOTD Found" message rather than an "End of MOTD"
36
+	 * @param sData The contents of the line (incase of language changes or so)
37
+	 * @see com.dmdirc.parser.irc.ProcessMOTD#callMOTDEnd
38
+	 */
39
+	void onMOTDEnd(IRCParser tParser, boolean noMOTD, String sData);
40
+}

+ 39
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IMOTDLine.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Interface Used to give MOTD Information.
29
+ */
30
+public interface IMOTDLine extends ICallbackInterface {
31
+	/**
32
+	 * Called on every incomming line from the MOTD.
33
+	 * 
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @param sData Incomming Line.
36
+	 * @see com.dmdirc.parser.irc.ProcessMOTD#callMOTDLine
37
+	 */
38
+	void onMOTDLine(IRCParser tParser, String sData);
39
+}

+ 39
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IMOTDStart.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Interface Used when the MOTD Starts.
29
+ */
30
+public interface IMOTDStart extends ICallbackInterface {
31
+	/**
32
+	 * Called on MOTD Start.
33
+	 * 
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @param sData Incomming Line.
36
+	 * @see com.dmdirc.parser.irc.ProcessMOTD#callMOTDStart
37
+	 */
38
+	void onMOTDStart(IRCParser tParser, String sData);
39
+}

+ 43
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/INickChanged.java View File

@@ -0,0 +1,43 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.ClientInfo;
26
+import com.dmdirc.parser.irc.IRCParser;
27
+
28
+/**
29
+ * Called when we or another user change nickname.
30
+ * This is called after the nickname change has been done internally
31
+ */
32
+public interface INickChanged extends ICallbackInterface {
33
+	/**
34
+	 * Called when we or another user change nickname.
35
+	 * This is called after the nickname change has been done internally
36
+	 * 
37
+	 * @param tParser Reference to the parser object that made the callback.
38
+	 * @param cClient Client changing nickname
39
+	 * @param sOldNick Nickname before change
40
+	 * @see com.dmdirc.parser.irc.ProcessNick#callNickChanged
41
+	 */
42
+	void onNickChanged(IRCParser tParser, ClientInfo cClient, String sOldNick);
43
+}

+ 39
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/INickInUse.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Called when requested nickname is in use.
29
+ */
30
+public interface INickInUse extends ICallbackInterface {
31
+	/**
32
+	 * Called when requested nickname is in use.
33
+	 *
34
+	 * @param nickname Nickname that was wanted.
35
+	 * @param tParser Reference to the parser object that made the callback.
36
+	 * @see com.dmdirc.parser.irc.ProcessNickInUse#callNickInUse
37
+	 */
38
+	void onNickInUse(IRCParser tParser, String nickname);
39
+}

+ 39
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/INoticeAuth.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Interface Used on every incomming line before 001.
29
+ */
30
+public interface INoticeAuth extends ICallbackInterface {
31
+	/**
32
+	 * Called on every incomming line before 001.
33
+	 * 
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @param sData Incomming Line.
36
+	 * @see com.dmdirc.parser.irc.ProcessNoticeAuth#callNoticeAuth
37
+	 */
38
+	void onNoticeAuth(IRCParser tParser, String sData);
39
+}

+ 40
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/INumeric.java View File

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Interface Used to give numeric Information.
29
+ */
30
+public interface INumeric extends ICallbackInterface {
31
+	/**
32
+	 * Called on every incomming line with a numerical type.
33
+	 * 
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @param numeric What numeric is this for
36
+	 * @param token IRC Tokenised line
37
+	 * @see com.dmdirc.parser.irc.ProcessingManager#callNumeric
38
+	 */
39
+	void onNumeric(IRCParser tParser, int numeric, String[] token);
40
+}

+ 38
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IPasswordRequired.java View File

@@ -0,0 +1,38 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Interface Used when a raw 464 is recieved.
29
+ */
30
+public interface IPasswordRequired extends ICallbackInterface {
31
+	/**
32
+	 * Called when a raw 464 is recieved.
33
+	 *
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @see com.dmdirc.parser.irc.Process004005#callPasswordRequired
36
+	 */
37
+	void onPasswordRequired(IRCParser tParser);
38
+}

+ 38
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IPingFailed.java View File

@@ -0,0 +1,38 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Called when a Ping Failed.
29
+ */
30
+public interface IPingFailed extends ICallbackInterface {
31
+	/**
32
+	 * Called when a ping failed.
33
+	 * 
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @see IRCParser#callPingFailed
36
+	 */
37
+	void onPingFailed(IRCParser tParser);
38
+}

+ 38
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IPingSent.java View File

@@ -0,0 +1,38 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Called when a Ping was Sent.
29
+ */
30
+public interface IPingSent extends ICallbackInterface {
31
+	/**
32
+	 * Called when a ping was Sent.
33
+	 * 
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @see IRCParser#callPingSent
36
+	 */
37
+	void onPingSent(IRCParser tParser);
38
+}

+ 38
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IPingSuccess.java View File

@@ -0,0 +1,38 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Called when a Ping was a Success.
29
+ */
30
+public interface IPingSuccess extends ICallbackInterface {
31
+	/**
32
+	 * Called when a ping was a Success.
33
+	 * 
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @see IRCParser#callPingSuccess
36
+	 */
37
+	void onPingSuccess(IRCParser tParser);
38
+}

+ 38
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IPost005.java View File

@@ -0,0 +1,38 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc.callbacks.interfaces;
24
+
25
+import com.dmdirc.parser.irc.IRCParser;
26
+
27
+/**
28
+ * Called after 001.
29
+ */
30
+public interface IPost005 extends ICallbackInterface {
31
+	/**
32
+	 * Called after 005.
33
+	 * 
34
+	 * @param tParser Reference to the parser object that made the callback.
35
+	 * @see com.dmdirc.parser.irc.Process001#callPost005
36
+	 */
37
+	void onPost005(IRCParser tParser);
38
+}

+ 0
- 0
src/com/dmdirc/parser/irc/callbacks/interfaces/IPrivateAction.java View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save