File Source: ChannelEventHandler.java
/*
P/P * Method: com.dmdirc.ChannelEventHandler__static_init
*/
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;
24
25 import com.dmdirc.actions.ActionManager;
26 import com.dmdirc.actions.CoreActionType;
27 import com.dmdirc.parser.irc.ChannelClientInfo;
28 import com.dmdirc.parser.irc.ChannelInfo;
29 import com.dmdirc.parser.irc.ClientInfo;
30 import com.dmdirc.parser.irc.IRCParser;
31 import com.dmdirc.parser.irc.callbacks.CallbackManager;
32 import com.dmdirc.parser.irc.callbacks.CallbackNotFoundException;
33 import com.dmdirc.parser.irc.callbacks.interfaces.*;
34
35 /**
36 * Handles events for channel objects.
37 *
38 * @author chris
39 */
40 public final class ChannelEventHandler extends EventHandler implements
41 IChannelMessage, IChannelGotNames, IChannelTopic, IChannelJoin,
42 IChannelPart, IChannelKick, IChannelQuit, IChannelAction,
43 IChannelNickChanged, IChannelModeChanged, IChannelUserModeChanged,
44 IChannelCTCP, IAwayStateOther, IChannelNotice {
45
46 /** The channel that owns this event handler. */
47 private final Channel owner;
48
49 /**
50 * Creates a new instance of ChannelEventHandler.
51 *
52 * @param owner The channel that owns this event handler.
53 */
54 public ChannelEventHandler(final Channel owner) {
/*
P/P * Method: void com.dmdirc.ChannelEventHandler(Channel)
*
* Postconditions:
* this.owner == owner
* init'ed(this.owner)
*/
55 super();
56
57 this.owner = owner;
58 }
59
60 /** {@inheritDoc} */
61 @Override
62 protected void addCallback(final CallbackManager cbm, final String name)
63 throws CallbackNotFoundException {
/*
P/P * Method: void addCallback(CallbackManager, String)
*
* Preconditions:
* cbm != null
* (soft) this.owner != null
* (soft) this.owner.channelInfo != null
*
* Test Vectors:
* java.lang.String:equals(...)@64: {0}, {1}
*/
64 if ("onAwayStateOther".equals(name)) {
65 cbm.addCallback(name, this);
66 } else {
67 cbm.addCallback(name, this, owner.getChannelInfo().getName());
68 }
69 }
70
71 /** {@inheritDoc} */
72 @Override
73 protected Server getServer() {
/*
P/P * Method: Server getServer()
*
* Preconditions:
* this.owner != null
* init'ed(this.owner.server)
*
* Postconditions:
* return_value == this.owner.server
* init'ed(return_value)
*/
74 return owner.getServer();
75 }
76
77 /**
78 * Determines if the specified client represents us.
79 *
80 * @param client The client to be tested
81 * @return True if the client is ourself, false otherwise.
82 */
83 protected boolean isMyself(final ChannelClientInfo client) {
/*
P/P * Method: bool isMyself(ChannelClientInfo)
*
* Preconditions:
* client != null
* this.owner != null
* this.owner.server != null
* this.owner.server.parser != null
*
* Presumptions:
* com.dmdirc.parser.irc.ChannelClientInfo:getClient(...)@84 != null
*
* Postconditions:
* init'ed(return_value)
*/
84 return client.getClient().equals(owner.getServer().getParser().getMyself());
85 }
86
87 /** {@inheritDoc} */
88 @Override
89 public void onChannelMessage(final IRCParser tParser,
90 final ChannelInfo cChannel, final ChannelClientInfo cChannelClient,
91 final String sMessage, final String sHost) {
/*
P/P * Method: void onChannelMessage(IRCParser, ChannelInfo, ChannelClientInfo, String, String)
*
* Preconditions:
* cChannelClient != null
* this.owner != null
* this.owner.server != null
* this.owner.server.parser != null
*/
92 checkParser(tParser);
93
94 owner.doNotification(
95 isMyself(cChannelClient) ? "channelSelfExternalMessage" : "channelMessage",
96 CoreActionType.CHANNEL_MESSAGE, cChannelClient, sMessage);
97 }
98
99 /** {@inheritDoc} */
100 @Override
101 public void onChannelGotNames(final IRCParser tParser, final ChannelInfo cChannel) {
/*
P/P * Method: void onChannelGotNames(IRCParser, ChannelInfo)
*
* Preconditions:
* cChannel != null
* init'ed(com/dmdirc/actions/ActionManager.killSwitch)
* this.owner != null
* this.owner.tabCompleter != null
* this.owner.window != null
* (soft) com.dmdirc.actions.CoreActionType__static_init.new CoreActionType(CoreActionType__static_init#42).type != null
* (soft) init'ed(com/dmdirc/ServerManager.me)
* (soft) this.owner.server != null
*
* Presumptions:
* com.dmdirc.parser.irc.ChannelInfo:getChannelClients(...)@104 != null
*
* Postconditions:
* com/dmdirc/ServerManager.me == old com/dmdirc/ServerManager.me
* new ArrayList(ServerManager#1) num objects == undefined
* new ArrayList(ServerManager#1) num objects == 0, if init'ed
* new ServerManager(getServerManager#1) num objects == new ArrayList(ServerManager#1) num objects
* new ServerManager(getServerManager#1).servers == undefined
* new ServerManager(getServerManager#1).servers == null
*/
102 checkParser(tParser);
103
104 owner.setClients(cChannel.getChannelClients());
105 ActionManager.processEvent(CoreActionType.CHANNEL_GOTNAMES, null, owner);
106 }
107
108 /** {@inheritDoc} */
109 @Override
110 public void onChannelTopic(final IRCParser tParser,
111 final ChannelInfo cChannel, final boolean bIsJoinTopic) {
/*
P/P * Method: void onChannelTopic(IRCParser, ChannelInfo, bool)
*
* Preconditions:
* cChannel != null
* this.owner != null
* this.owner.channelInfo != null
* this.owner.topics != null
* this.owner.window != null
* (soft) this.owner.server != null
*
* Test Vectors:
* bIsJoinTopic: {0}, {1}
*/
112 checkParser(tParser);
113
114 final Topic newTopic = new Topic(cChannel.getTopic(),
115 cChannel.getTopicUser(), cChannel.getTopicTime());
116
117 if (bIsJoinTopic) {
118 owner.doNotification("channelTopicDiscovered", CoreActionType.CHANNEL_GOTTOPIC,
119 newTopic);
120 } else {
121 owner.doNotification("channelTopicChanged", CoreActionType.CHANNEL_TOPICCHANGE,
122 cChannel.getUser(cChannel.getTopicUser(), true), cChannel.getTopic());
123 }
124
125 owner.addTopic(newTopic);
126 }
127
128 /** {@inheritDoc} */
129 @Override
130 public void onChannelJoin(final IRCParser tParser, final ChannelInfo cChannel,
131 final ChannelClientInfo cChannelClient) {
/*
P/P * Method: void onChannelJoin(IRCParser, ChannelInfo, ChannelClientInfo)
*
* Preconditions:
* cChannelClient != null
* this.owner != null
* this.owner.tabCompleter != null
* this.owner.window != null
* (soft) this.owner.server != null
*/
132 checkParser(tParser);
133
134 owner.doNotification("channelJoin", CoreActionType.CHANNEL_JOIN, cChannelClient);
135 owner.addClient(cChannelClient);
136 }
137
138 /** {@inheritDoc} */
139 @Override
140 public void onChannelPart(final IRCParser tParser, final ChannelInfo cChannel,
141 final ChannelClientInfo cChannelClient, final String sReason) {
/*
P/P * Method: void onChannelPart(IRCParser, ChannelInfo, ChannelClientInfo, String)
*
* Preconditions:
* cChannelClient != null
* sReason != null
* this.owner != null
* this.owner.server != null
* this.owner.server.parser != null
* this.owner.tabCompleter != null
* this.owner.window != null
* (soft) this.owner.config != null
* (soft) this.owner.listeners != null
*
* Postconditions:
* this.owner.icon == One-of{old this.owner.icon, &"channel-inactive"}
* possibly_updated(this.owner.onChannel)
*/
142 checkParser(tParser);
143
144 owner.doNotification("channel"
145 + (isMyself(cChannelClient) ? "Self" : "") + "Part"
146 + (sReason.isEmpty() ? "" : "Reason"), CoreActionType.CHANNEL_PART,
147 cChannelClient, sReason);
148 owner.removeClient(cChannelClient);
149 }
150
151 /** {@inheritDoc} */
152 @Override
153 public void onChannelKick(final IRCParser tParser, final ChannelInfo cChannel,
154 final ChannelClientInfo cKickedClient, final ChannelClientInfo cKickedByClient,
155 final String sReason, final String sKickedByHost) {
/*
P/P * Method: void onChannelKick(IRCParser, ChannelInfo, ChannelClientInfo, ChannelClientInfo, String, String)
*
* Preconditions:
* cKickedClient != null
* sReason != null
* this.owner != null
* this.owner.server != null
* this.owner.server.parser != null
* this.owner.tabCompleter != null
* this.owner.window != null
* (soft) this.owner.config != null
* (soft) this.owner.listeners != null
*
* Postconditions:
* this.owner.icon == One-of{old this.owner.icon, &"channel-inactive"}
* possibly_updated(this.owner.onChannel)
*/
156 checkParser(tParser);
157
158 owner.doNotification("channelKick" + (sReason.isEmpty() ? "" : "Reason"),
159 CoreActionType.CHANNEL_KICK, cKickedByClient, cKickedClient, sReason);
160 owner.removeClient(cKickedClient);
161 }
162
163 /** {@inheritDoc} */
164 @Override
165 public void onChannelQuit(final IRCParser tParser, final ChannelInfo cChannel,
166 final ChannelClientInfo cChannelClient, final String sReason) {
/*
P/P * Method: void onChannelQuit(IRCParser, ChannelInfo, ChannelClientInfo, String)
*
* Preconditions:
* cChannelClient != null
* sReason != null
* this.owner != null
* this.owner.server != null
* this.owner.server.parser != null
* this.owner.tabCompleter != null
* this.owner.window != null
* (soft) this.owner.config != null
* (soft) this.owner.listeners != null
*
* Postconditions:
* this.owner.icon == One-of{old this.owner.icon, &"channel-inactive"}
* possibly_updated(this.owner.onChannel)
*/
167 checkParser(tParser);
168
169 owner.doNotification("channelQuit" + (sReason.isEmpty() ? "" : "Reason"),
170 CoreActionType.CHANNEL_QUIT, cChannelClient, sReason);
171 owner.removeClient(cChannelClient);
172 }
173
174 /** {@inheritDoc} */
175 @Override
176 public void onChannelAction(final IRCParser tParser, final ChannelInfo cChannel,
177 final ChannelClientInfo cChannelClient, final String sMessage,
178 final String sHost) {
/*
P/P * Method: void onChannelAction(IRCParser, ChannelInfo, ChannelClientInfo, String, String)
*
* Preconditions:
* cChannelClient != null
* this.owner != null
* this.owner.server != null
* this.owner.server.parser != null
*/
179 checkParser(tParser);
180
181 owner.doNotification(
182 isMyself(cChannelClient) ? "channelSelfExternalAction" : "channelAction",
183 CoreActionType.CHANNEL_ACTION, cChannelClient, sMessage);
184 }
185
186 /** {@inheritDoc} */
187 @Override
188 public void onChannelNickChanged(final IRCParser tParser, final ChannelInfo cChannel,
189 final ChannelClientInfo cChannelClient, final String sOldNick) {
/*
P/P * Method: void onChannelNickChanged(IRCParser, ChannelInfo, ChannelClientInfo, String)
*
* Preconditions:
* cChannelClient != null
* this.owner != null
* this.owner.server != null
* this.owner.server.parser != null
* this.owner.tabCompleter != null
* this.owner.window != null
*/
190 checkParser(tParser);
191
192 owner.doNotification(
193 isMyself(cChannelClient) ? "channelSelfNickChange" : "channelNickChange",
194 CoreActionType.CHANNEL_NICKCHANGE, cChannelClient, sOldNick);
195 owner.renameClient(sOldNick, cChannelClient.getNickname());
196 }
197
198 /** {@inheritDoc} */
199 @Override
200 public void onChannelModeChanged(final IRCParser tParser, final ChannelInfo cChannel,
201 final ChannelClientInfo cChannelClient, final String sHost,
202 final String sModes) {
/*
P/P * Method: void onChannelModeChanged(IRCParser, ChannelInfo, ChannelClientInfo, String, String)
*
* Preconditions:
* sHost != null
* this.owner != null
* this.owner.window != null
* (soft) cChannelClient != null
* (soft) sModes != null
* (soft) this.owner.server != null
* (soft) this.owner.server.parser != null
*
* Test Vectors:
* java.lang.String:isEmpty(...)@205: {0}, {1}
*/
203 checkParser(tParser);
204
205 if (sHost.isEmpty()) {
206 owner.doNotification(sModes.length() <= 1 ? "channelNoModes"
207 : "channelModeDiscovered", CoreActionType.CHANNEL_MODESDISCOVERED,
208 sModes.length() <= 1 ? "" : sModes);
209 } else {
210 owner.doNotification(isMyself(cChannelClient) ? "channelSelfModeChanged"
211 : "channelModeChanged", CoreActionType.CHANNEL_MODECHANGE,
212 cChannelClient, sModes);
213 }
214
215 owner.refreshClients();
216 }
217
218 /** {@inheritDoc} */
219 @Override
220 public void onChannelUserModeChanged(final IRCParser tParser,
221 final ChannelInfo cChannel, final ChannelClientInfo cChangedClient,
222 final ChannelClientInfo cSetByClient, final String sHost, final String sMode) {
/*
P/P * Method: void onChannelUserModeChanged(IRCParser, ChannelInfo, ChannelClientInfo, ChannelClientInfo, String, String)
*
* Preconditions:
* this.owner != null
* (soft) this.owner.server != null
*
* Presumptions:
* com.dmdirc.Channel:getConfigManager(...)@225 != null
* com.dmdirc.Channel:getConfigManager(...)@228 != null
*
* Test Vectors:
* com.dmdirc.config.ConfigManager:getOptionBool(...)@225: {0}, {1}
* com.dmdirc.config.ConfigManager:hasOptionString(...)@228: {1}, {0}
*/
223 checkParser(tParser);
224
225 if (owner.getConfigManager().getOptionBool("channel", "splitusermodes")) {
226 String format = "channelSplitUserMode_" + sMode;
227
228 if (!owner.getConfigManager().hasOptionString("formatter", format)) {
229 format = "channelSplitUserMode_default";
230 }
231
232 owner.doNotification(format, CoreActionType.CHANNEL_USERMODECHANGE,
233 cSetByClient, cChangedClient, sMode);
234 }
235 }
236
237 /** {@inheritDoc} */
238 @Override
239 public void onChannelCTCP(final IRCParser tParser, final ChannelInfo cChannel,
240 final ChannelClientInfo cChannelClient, final String sType,
241 final String sMessage, final String sHost) {
/*
P/P * Method: void onChannelCTCP(IRCParser, ChannelInfo, ChannelClientInfo, String, String, String)
*
* Preconditions:
* cChannelClient != null
* sType != null
* this.owner != null
* this.owner.server != null
* (soft) this.owner.server.config != null
* (soft) this.owner.server.parser != null
*/
242 checkParser(tParser);
243
244 owner.doNotification("channelCTCP", CoreActionType.CHANNEL_CTCP,
245 cChannelClient, sType, sMessage);
246 owner.getServer().sendCTCPReply(cChannelClient.getNickname(), sType, sMessage);
247 }
248
249 /** {@inheritDoc} */
250 @Override
251 public void onAwayStateOther(final IRCParser tParser,
252 final ClientInfo client, final boolean state) {
/*
P/P * Method: void onAwayStateOther(IRCParser, ClientInfo, bool)
*
* Preconditions:
* this.owner != null
* this.owner.channelInfo != null
* (soft) this.owner.server != null
*
* Test Vectors:
* com.dmdirc.parser.irc.ChannelInfo:getUser(...)@255: Addr_Set{null}, Inverse{null}
*/
253 checkParser(tParser);
254
255 final ChannelClientInfo channelClient = owner.getChannelInfo().getUser(client);
256
257 if (channelClient != null) {
258 owner.doNotification(state ? "channelUserAway" : "channelUserBack",
259 state ? CoreActionType.CHANNEL_USERAWAY : CoreActionType.CHANNEL_USERBACK,
260 channelClient);
261 }
262 }
263
264 /** {@inheritDoc} */
265 @Override
266 public void onChannelNotice(final IRCParser tParser,
267 final ChannelInfo cChannel, final ChannelClientInfo cChannelClient,
268 final String sMessage, final String sHost) {
/*
P/P * Method: void onChannelNotice(IRCParser, ChannelInfo, ChannelClientInfo, String, String)
*
* Preconditions:
* this.owner != null
* (soft) this.owner.server != null
*/
269 checkParser(tParser);
270
271 owner.doNotification("channelNotice", CoreActionType.CHANNEL_NOTICE,
272 cChannelClient, sMessage);
273 }
274
275 }
SofCheck Inspector Build Version : 2.17854
| ChannelEventHandler.java |
2009-Jun-25 01:54:24 |
| ChannelEventHandler.class |
2009-Sep-02 17:04:17 |