File Source: ProcessWho.java
/*
P/P * Method: com.dmdirc.parser.irc.ProcessWho__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 /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();
/*
P/P * Method: void process(String, String[])
*
* Preconditions:
* init'ed(this.myParser.stringConverter)
* this.myParser != null
* this.myParser.hClientList != null
* token != null
* token[7] != null
* (soft) init'ed(this.myParser.cMyself)
* (soft) this.myParser.hChannelList != null
* (soft) this.myParser.myCallbackManager != null
* (soft) this.myParser.myCallbackManager.callbackHash != null
* (soft) this.myParser.stringConverter.lowercase != null
* ...
*
* Presumptions:
* client.sRealName != null
* iChannel.hChannelUserList@71 != null
* java.util.Iterator:next(...)@71 != null
* java.util.Map:values(...)@2067 != null
*
* Postconditions:
* this.myParser.stringConverter == One-of{old this.myParser.stringConverter, &new IRCStringConverter(getIRCStringConverter#1)}
* this.myParser.stringConverter != null
* 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
* new IRCStringConverter(getIRCStringConverter#1).limit == 4
* new IRCStringConverter(getIRCStringConverter#1).lowercase == &new char[](IRCStringConverter#1)
* new IRCStringConverter(getIRCStringConverter#1).uppercase == &new char[](IRCStringConverter#2)
* new char[](IRCStringConverter#1).length == 127
* new char[](IRCStringConverter#2).length == 127
* ...
*
* Test Vectors:
* client.bIsAway: {0}, {1}
* java.lang.String:indexOf(...)@60: {-231..-2, 0..232-1}, {-1}
* java.lang.String:isEmpty(...)@54: {0}, {1}
* java.util.Iterator:hasNext(...)@71: {0}, {1}
*/
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) {
/*
P/P * Method: bool callAwayState(bool, 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("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) {
/*
P/P * Method: bool callAwayStateOther(ClientInfo, bool)
*
* 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("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) {
/*
P/P * Method: bool callChannelAwayStateOther(ChannelInfo, ChannelClientInfo, bool)
*
* Preconditions:
* this.myParser != null
* this.myParser.myCallbackManager != null
* this.myParser.myCallbackManager.callbackHash != null
*
* Presumptions:
* getCallbackManager(...)@116 init'ed
*
* Postconditions:
* init'ed(return_value)
*/
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() {
/*
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] == &"352"
*/
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 */
/*
P/P * Method: void com.dmdirc.parser.irc.ProcessWho(IRCParser, ProcessingManager)
*
* Postconditions:
* this.myManager == manager
* init'ed(this.myManager)
* this.myParser == parser
* init'ed(this.myParser)
*/
135 protected ProcessWho (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
136
137 }
SofCheck Inspector Build Version : 2.17854
| ProcessWho.java |
2009-Jun-25 01:54:24 |
| ProcessWho.class |
2009-Sep-02 17:04:16 |