File Source: ProcessNick.java
/*
P/P * Method: com.dmdirc.parser.irc.ProcessNick__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.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
/*
P/P * Method: void process(String, String[])
*
* Preconditions:
* token != null
* (soft) init'ed(this.myParser.stringConverter)
* (soft) this.myParser != null
* (soft) this.myParser.hChannelList != null
* (soft) this.myParser.hClientList != null
* (soft) init'ed(this.myParser.lastLine)
* (soft) this.myParser.myCallbackManager != null
* (soft) this.myParser.myCallbackManager.callbackHash != null
* (soft) this.myParser.stringConverter.lowercase != null
* (soft) init'ed(this.myParser.stringConverter.lowercase[...])
* ...
*
* Presumptions:
* getClientInfo(...).sNickname != null
* getIRCStringConverter(...).lowercase != null
* getIRCStringConverter(...).lowercase.length >= 1
* iChannel.hChannelUserList@61 != null
* iChannel.myParser.stringConverter.lowercase@61 != null
* ...
*
* Postconditions:
* init'ed(this.myParser.stringConverter)
* new IRCStringConverter(getIRCStringConverter#1) num objects == 0
* new IRCStringConverter(getIRCStringConverter#1) num objects <= 1
* new char[](IRCStringConverter#1) num objects == new IRCStringConverter(getIRCStringConverter#1) num objects
* new char[](IRCStringConverter#2) num objects == new IRCStringConverter(getIRCStringConverter#1) num objects
* init'ed(new IRCStringConverter(getIRCStringConverter#1).limit)
* possibly_updated(new IRCStringConverter(getIRCStringConverter#1).limit)
* new IRCStringConverter(getIRCStringConverter#1).limit == 4
* init'ed(new IRCStringConverter(getIRCStringConverter#1).lowercase)
* possibly_updated(new IRCStringConverter(getIRCStringConverter#1).lowercase)
* ...
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@61: {0}, {1}
*/
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) {
/*
P/P * Method: bool callChannelNickChanged(ChannelInfo, ChannelClientInfo, String)
*
* Preconditions:
* this.myParser != null
* this.myParser.myCallbackManager != null
* this.myParser.myCallbackManager.callbackHash != null
*
* Presumptions:
* getCallbackManager(...)@91 init'ed
*
* Postconditions:
* init'ed(return_value)
*/
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) {
/*
P/P * Method: bool callNickChanged(ClientInfo, String)
*
* Preconditions:
* this.myParser != null
* this.myParser.myCallbackManager != null
* this.myParser.myCallbackManager.callbackHash != null
*
* Presumptions:
* getCallbackManager(...)@103 init'ed
*
* Postconditions:
* init'ed(return_value)
*/
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() {
/*
P/P * Method: String[] handles()
*
* Postconditions:
* return_value == &new String[](handles#1)
* new String[](handles#1) num objects == 1
* return_value.length == 1
* return_value[0] == &"NICK"
*/
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 */
/*
P/P * Method: void com.dmdirc.parser.irc.ProcessNick(IRCParser, ProcessingManager)
*
* Postconditions:
* this.myManager == manager
* init'ed(this.myManager)
* this.myParser == parser
* init'ed(this.myParser)
*/
122 protected ProcessNick (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
123
124 }
SofCheck Inspector Build Version : 2.17854
| ProcessNick.java |
2009-Jun-25 01:54:24 |
| ProcessNick.class |
2009-Sep-02 17:04:16 |