1 /*****************************************************/
2 /* This java file is a part of the */
4 /* - Plouf's Java IRC Client - */
6 /* Copyright (C) 2002 - 2005 Philippe Detournay */
8 /* All contacts : theplouf@yahoo.com */
10 /* PJIRC is free software; you can redistribute */
11 /* it and/or modify it under the terms of the GNU */
12 /* General Public License as published by the */
13 /* Free Software Foundation; version 2 or later of */
16 /* PJIRC is distributed in the hope that it will */
17 /* be useful, but WITHOUT ANY WARRANTY; without */
18 /* even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
20 /* General Public License for more details. */
22 /* You should have received a copy of the GNU */
23 /* General Public License along with PJIRC; if */
24 /* not, write to the Free Software Foundation, */
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
26 /* MA 02111-1307 USA */
28 /*****************************************************/
35 public class Status extends IRCSource implements ReplyServerListener {
36 private ListenerGroup _listeners;
39 * Create a new Status.
42 * global irc configuration.
46 public Status(IRCConfiguration config, IRCServer s) {
48 s.addReplyServerListener(this);
49 _listeners = new ListenerGroup();
50 setInterpretor(new StatusInterpretor(config));
54 public void release() {
55 ((IRCServer) _server).removeReplyServerListener(this);
60 public String getType() {
65 public String getName() {
66 return getServerName();
70 * Get the server name.
72 * @return the server name.
74 public String getServerName() {
75 return getIRCServer().getServerName();
79 public boolean talkable() {
85 if (!_ircConfiguration.getB("multiserver"))
88 // sendString("/quit");
89 getIRCServer().leaveStatus(getName());
93 * Get this status nick.
95 * @return status nick.
97 public String getNick() {
98 return _server.getNick();
102 * Get this status mode.
104 * @return status mode.
106 public String getMode() {
107 return getIRCServer().getMode();
116 public void addStatusListener(StatusListener lis) {
117 _listeners.addListener(lis);
124 * listener to remove.
126 public void removeStatusListener(StatusListener lis) {
127 _listeners.removeListener(lis);
131 * Notify this status that the nick has changed.
136 public void nickChanged(String nick) {
137 _listeners.sendEvent("nickChanged", nick, this);
141 * Notify this status that the mode has changed.
146 public void modeChanged(String mode) {
147 _listeners.sendEvent("modeChanged", mode, this);
151 * We've been invited on a channel.
154 * channel we're invited to.
156 * nickname who invited us.
158 public void invited(String channel, String who) {
159 _listeners.sendEvent("invited", channel, who, this);
163 public Boolean replyReceived(String prefix, String id, String params[], IRCServer server) {
164 if (id.equals("322"))
165 return Boolean.FALSE; // chanlist
166 if (_ircConfiguration.getB("useinfo")) {
167 int i = new Integer(id).intValue();
168 if ((i >= 300) && (i != 372))
169 return Boolean.FALSE;
171 if (id.equals("401")) // no such nick/channel
173 Source src = getIRCServer().getDefaultSource();
175 for (int i = 1; i < params.length; i++)
176 toSend += " " + params[i];
177 toSend = toSend.substring(1);
180 } else if (id.equals("317")) // idle time
182 if (params.length > 3) {
183 String time = params[2];
184 long tme = Long.parseLong(time);
185 long seconds = (tme) % 60;
186 long mins = (tme / (60)) % 60;
187 long hours = (tme / (60 * 60)) % 24;
188 long days = (tme / (60 * 60 * 24)) % 7;
189 long weeks = (tme / (60 * 60 * 24 * 7));
193 if (tme > (60 * 60 * 24 * 7))
194 res += weeks + " weeks ";
195 if (tme > (60 * 60 * 24))
196 res += days + " days ";
198 res += hours + " hours ";
200 res += mins + " minutes ";
201 res += seconds + " seconds";
204 String signon = new java.util.Date(1000 * Long.parseLong(params[3])).toString();
206 report(_ircConfiguration.getText(IRCTextProvider.REPLY_IDLE, params[1], res));
207 report(_ircConfiguration.getText(IRCTextProvider.REPLY_SIGNON, params[1], signon));
211 // Source src=getIRCServer().getDefaultSource();
213 for (int i = 1; i < params.length; i++)
214 toSend += " " + params[i];
215 toSend = toSend.substring(1);
216 /* if(src!=null) src. */report(toSend);
218 return Boolean.FALSE;