Source code: org/relayirc/chatengine/ChatEngine.java
1 /*
2 * FILE: ChatEngine.java
3 *
4 * The contents of this file are subject to the Mozilla Public License
5 * Version 1.0 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11 * License for the specific language governing rights and limitations
12 * under the License.
13 *
14 * The Original Code is Relay IRC chat client.
15 *
16 * The Initial Developer of the Original Code is David M. Johnson.
17 * Portions created by David M. Johnson are Copyright (C) 1998.
18 * All Rights Reserved.
19 *
20 * Contributor(s): No contributors to this file.
21 */
22 package org.relayirc.chatengine;
23 import org.relayirc.util.*;
24 import java.net.*;
25 import java.io.*;
26 import java.util.*;
27
28 ///////////////////////////////////////////////////////////////////////////
29 /**
30 * <p>Manages a connection to an IRC server and handles incoming
31 * messages by creating channel objects, routing messages to channel
32 * objects and routing events to chat engine listeners.</p>
33 *
34 * <p>After you have constructed a chat engine, add a ChatEngineListener
35 * to be notified of server connection and disconnection, channel
36 * joins and parts and status messages from the engine. Connect to
37 * the chat server using the connect() method and use the sendJoin()
38 * and sendPart() commands to join and leave chat channels. When a
39 * channel is joined, your listener will be informed and you may add
40 * a ChannelListener to the channel object so that you can repond
41 * to messages, bans, kicks, etc. from that channel.</p>
42 *
43 * @see org.relayirc.chatengine.ChatEngineListener
44 * @see org.relayirc.chatengine.Server
45 * @see org.relayirc.chatengine.Channel
46 * @see org.relayirc.chatengine.IdentServer
47 * @see org.relayirc.chatengine.ChannelSearch
48 * @see org.relayirc.chatengine.IChatApp
49 * @see org.relayirc.chatengine.IRCConnection
50 * @see org.relayirc.chatengine.IRCConnectionListener
51 *
52 * @author David M. Johnson.
53 */
54 public class ChatEngine implements IChatEngine {
55
56 private Server _server; // Chat server
57 private int _channelCount = 0; // Num. channels on server
58 private String _nick; // User login information
59 private String _altNick; // " "
60 private String _userName; // " "
61 private String _fullName; // " "
62 private IRCConnection _connection; // Chat connection
63 private ChannelSearch _search = null; // Current search, if one exists
64 private IdentServer _identd; // One-shot identd server
65
66 // Channel-specific IRCConnectionListener objects, keyed by name
67 private Hashtable _channels = new Hashtable();
68
69 private Vector _listeners = new Vector();
70
71 private String _appName = "Relay IRC chat-engine";
72 private String _appVersion = "Unknown version";
73
74 // Don't expose an IRCConnectionListener interface, but do use one internally.
75 private _ChatEngineMux _mux = new _ChatEngineMux();
76
77 //================================================================
78 // Constructors
79 //================================================================
80
81 /**
82 * Construct a chat engine by specifying server name, server port and
83 * user logon parameters.
84 * @param serverName IRC chat server hostname (e.g. irc.mindspring.com).
85 * @param serverPort IRC chat server port (e.g. 6667).
86 * @param altNick Alternate nickname
87 * @param userName User's UNIX login name
88 * @param fullName User's real name
89 */
90 public ChatEngine(String serverName, int serverPort,
91 String nick, String altNick, String userName, String fullName) {
92
93 _server = new Server(serverName,serverPort);
94
95 _nick = nick;
96 _altNick = altNick;
97 _userName = userName;
98 _fullName = fullName;
99
100 _connection = new IRCConnection(
101 _server.getName(),_server.getPort(),
102 _nick,_altNick,_userName,_fullName);
103
104 _connection.setIRCConnectionListener(_mux);
105 }
106 //================================================================
107 // Thread safe notification architecture
108 //================================================================
109
110 interface _EngineEventNotifier {
111 public void notify(ChatEngineListener listener);
112 }
113 //------------------------------------------------------------------
114 private synchronized void notifyListeners(_EngineEventNotifier notifier) {
115 for (int i=0; i<_listeners.size(); i++) {
116 ChatEngineListener listener = (ChatEngineListener)_listeners.elementAt(i);
117 notifier.notify(listener);
118 }
119 }
120 //------------------------------------------------------------------
121 /** Add a chat engine listener. */
122 public synchronized void addChatEngineListener(ChatEngineListener listener) {
123 _listeners.addElement(listener);
124 }
125 //------------------------------------------------------------------
126 /** Remove a chat engine listener. */
127 public synchronized void removeChatEngineListener(ChatEngineListener listener) {
128 _listeners.removeElement(listener);
129 }
130
131 //================================================================
132 // Accessors
133 //================================================================
134
135 /** Get app name to be reported to version queries. */
136 public String getAppName() {return _appName;}
137
138 /** Set app name to be reported to version queries. */
139 public void setAppName(String name) {_appName = name;}
140
141 /** Get app version to be reported to version queries. */
142 public String getAppVersion() {return _appVersion;}
143
144 /** Set app verion to be reported to version queries. */
145 public void setAppVersion(String version) {_appVersion = version;}
146
147 //------------------------------------------------------------------
148 /** Check connection status and returns true if connected. */
149 public boolean isConnected() {
150 return _connection.isConnected();
151 }
152 //------------------------------------------------------------------
153 /**
154 * Check connection status and returns true if engine
155 * is in the process of connecting
156 */
157 public boolean isConnecting() {
158 return _connection.isConnecting();
159 }
160 //------------------------------------------------------------------
161 /** Get version of IRC server. */
162 //public String getServerVersion() {
163 //return _serverVersion;
164 //}
165 //------------------------------------------------------------------
166 /** Get nick name currently in use */
167 public String getNick() {
168 return _connection.getNick();
169 }
170
171 //================================================================
172 // Methods
173 //================================================================
174
175 /** Connect to IRC server that was specified in the constructor. */
176 public void connect() {
177 if (!isConnected() && !isConnecting()) {
178 _identd = new IdentServer(this,_userName);
179 _connection.open();
180 }
181 else {
182 fireStatusEvent("Cannot connect: already connected.");
183 }
184 }
185 //------------------------------------------------------------------
186 /**
187 * Disconnect from server by sending a QUIT to the server, closing
188 * the socket to the server and then waiting for the message loop
189 * thread to die.
190 */
191 public void disconnect() {
192 if (isConnected()) {
193 fireStatusEvent("Disconnecting...");
194 _connection.close();
195 }
196 else {
197 fireStatusEvent("Cannot disconnect: not connected.");
198 }
199 }
200 //------------------------------------------------------------------
201 /** Send status message to all ChatEngineListeners. */
202 public void fireStatusEvent(String msg) {
203 final ChatEngineEvent event = new ChatEngineEvent(this,msg);
204 notifyListeners(new _EngineEventNotifier() {
205 public void notify(ChatEngineListener listener) {listener.onStatus(event);}
206 });
207 }
208 //------------------------------------------------------------------
209 /**
210 * Processes text entered by the user within a channel. If the
211 * text starts with /me, then the rest of the text is sent to the
212 * server as an ACTION command. If the text starts with / then the
213 * / is stripped off and the text is sent to the server as a command.
214 * Otherwise, the text is sent as a message.
215 */
216 public void processUserInput(String txt, String chan) {
217
218 if (txt.length()>2 && txt.toLowerCase().substring(0,3).equals("/me")) {
219
220 // Action
221 sendMessage("\001ACTION "+txt.substring(3)+"\001",chan);
222 _mux.onAction(_connection.getNick(),chan,txt.substring(3));
223 }
224 else if (txt.substring(0,1).equals("/")) {
225
226 // Some other command
227 sendCommand(txt.substring(1));
228 }
229 else {
230
231 // Normal message
232 sendMessage(txt,chan);
233 _mux.onPrivateMessage(_connection.getNick(),chan,txt);
234 }
235 }
236 //------------------------------------------------------------------
237 /** Send command string directly to server */
238 public synchronized void sendCommand( String str ) {
239 if (isConnected()) {
240 try {
241 RCTest.println("ChatEngine: sending command "+str);
242 _connection.writeln(str+"\r\n");
243 //RCTest.println("ChatEngine: sent command ");
244
245 try {
246 // If this is a join command, force creation of it's view
247 StringTokenizer toker = new StringTokenizer(str);
248 String cmd = toker.nextToken().toLowerCase();
249 if (cmd.equals("join")) {
250 createChannel(toker.nextToken());
251 }
252 }
253 catch (Exception e) {
254 e.printStackTrace();
255 }
256 }
257 catch (Exception e) {
258 fireStatusEvent("Error sending command");
259 }
260 }
261 }
262 //------------------------------------------------------------------
263 /**
264 * Join specified channel by sending JOIN command to IRC server,
265 * adding channel object to engine's channel collection and notifying
266 * listeners of channel join.
267 */
268 public void sendJoin(Channel chan) {
269
270 // Make sure channel is in hash
271 if (!_channels.contains(chan)) {
272 _channels.put(chan.getName(),chan);
273 }
274
275 // Ask server to join
276 sendCommand("JOIN "+chan.getName());
277
278 // Notify listeners that channel has been joined
279 final ChatEngineEvent event = new ChatEngineEvent(this,chan);
280 notifyListeners(new _EngineEventNotifier() {
281 public void notify(ChatEngineListener listener) {
282 listener.onChannelJoin(event);}
283 }
284 );
285 }
286 //------------------------------------------------------------------
287 /**
288 * Join specified channel by sending a JOIN command to the IRC server
289 * creating a new channel object and notifying listeners of channel join.
290 */
291 public void sendJoin(String name) {
292
293 // See if channel object already exists
294 name = name.trim().toLowerCase();
295 Channel chan = (Channel)_channels.get(name);
296
297 if (chan == null) {
298
299 // Channel object does not exist, so create it
300 RCTest.println("ChatEngine.sendJoin(): Creating channel ("+name+")\n");
301 chan = new Channel(name,this);
302 chan.setConnected(true);
303 _channels.put(name,chan);
304
305 // Ask server to join
306 sendCommand("JOIN "+name);
307
308 // Notify listeners that channel has been joined
309 final ChatEngineEvent event = new ChatEngineEvent(this,chan);
310 notifyListeners(new _EngineEventNotifier() {
311 public void notify(ChatEngineListener listener) {listener.onChannelJoin(event);}
312 });
313
314 }
315 else {
316 // Use pre-existing channel object
317 sendJoin(chan);
318 chan.setConnected(true);
319 }
320 }
321 //------------------------------------------------------------------
322 /**
323 * Send a PRIVMSG message to server.
324 * @deprecated Use Channel.privMsg() instead.
325 */
326 public void sendMessage(String str, String chan) {
327 sendCommand("PRIVMSG "+chan+" "+":"+str);
328 }
329 //------------------------------------------------------------------
330 /** Send channel part, notify listeners and remove channel. */
331 public void sendPart(Channel chan) {
332 sendPart(chan.getName());
333 }
334 //------------------------------------------------------------------
335 /** Send channel part, notify listeners and remove channel. */
336 public void sendPart(String chanName) {
337 sendCommand("PART "+chanName);
338 Channel chan = getChannel(chanName,false);
339 chan.getChannelMux().onPart(_userName,_nick,chanName);
340
341 final ChatEngineEvent event = new ChatEngineEvent(this,chan);
342 notifyListeners(new _EngineEventNotifier() {
343 public void notify(ChatEngineListener listener) {
344 listener.onChannelPart(event);}
345 }
346 );
347 _channels.remove(chan);
348 }
349 //------------------------------------------------------------------
350 /** Send version information to server */
351 public void sendVersion(String user) {
352 sendCommand("PRIVMSG "+user+" "+":\001VERSION\001");
353 }
354 //------------------------------------------------------------------
355 /**
356 * Send quit message to server.
357 */
358 public void sendQuit( String str ) {
359 sendCommand("QUIT :"+str);
360 }
361 //------------------------------------------------------------------
362 /** Start a channel search using the specified channel search object. */
363 public void startChannelSearch(ChannelSearch search) {
364 _search = search;
365
366 String cmd = "LIST ";
367
368 /*
369 if (search.getMinUsers()>Integer.MIN_VALUE && search.getMaxUsers()<Integer.MAX_VALUE) {
370 cmd = cmd + "<" + search.getMaxUsers() + ",";
371 cmd = cmd + ">" + search.getMinUsers();
372 }
373 else if (search.getMinUsers()>Integer.MIN_VALUE) {
374 cmd = cmd + ">" + search.getMinUsers();
375 }
376 else if (search.getMaxUsers()<Integer.MAX_VALUE) {
377 cmd = cmd + "<" + search.getMaxUsers();
378 }
379 */
380
381 sendCommand(cmd);
382 }
383 //------------------------------------------------------------------
384 private void createChannel(String name) {
385 RCTest.println("ChatEngine: createChannel for "+name);
386 getChannel(name,true);
387 }
388 //------------------------------------------------------------------
389 /** Determine if channel view is active. */
390 private boolean isChannelActive( String channel ) {
391 Channel chan = (Channel)_channels.get(channel);
392 if (chan!=null)
393 return true;
394 else
395 return false;
396 }
397 //------------------------------------------------------------------
398 /** Returns view for specified channel, or null if there is none. */
399 private Channel getChannel(String name) {
400 return getChannel(name,false);
401 }
402 //------------------------------------------------------------------
403 /**
404 * Returns channel object specified by name, creates one if necessary.
405 * @param name Name of channel.
406 * @param manditory If channel does not exist, then create it.
407 */
408 private synchronized Channel getChannel(String name, boolean manditory) {
409
410 name = name.trim().toLowerCase();
411 Channel chan = (Channel)_channels.get(name);
412
413 if ( chan==null && manditory ) {
414
415 // Channel object does not exist and we need it, so create it
416 RCTest.println("ChatEngine.getChannel(): Creating channel ("+name+")\n");
417 chan = new Channel(name,this);
418 chan.setConnected(true);
419 _channels.put(name,chan);
420
421 // Notify listeners that channel has been joined
422 final ChatEngineEvent event = new ChatEngineEvent(this,chan);
423 notifyListeners(new _EngineEventNotifier() {
424 public void notify(ChatEngineListener listener)
425 {listener.onChannelJoin(event);}
426 });
427
428 }
429 else if (chan==null) {
430
431 // Channel object does not exist, and we don't need it
432 RCTest.println("Couldn't find channel "+name+", hash size="
433 +Integer.toString(_channels.size())+"\n");
434 }
435 return chan;
436 }
437
438 ////////////////////////////////////////////////////////////////////////////////////
439
440 private class _ChatEngineMux implements IRCConnectionListener {
441
442 //------------------------------------------------------------------
443 public void onAction( String user, String chan, String txt ) {
444 getChannel(chan,true).getChannelMux().onAction(user,chan,txt);
445 }
446 //------------------------------------------------------------------
447 public void onBan( String banned, String chan, String banner ) {
448 getChannel(chan,true).getChannelMux().onBan(banned,chan,banner);
449 }
450 //------------------------------------------------------------------
451 public void onClientInfo(String orgnick) {
452 String response = "NOTICE "+orgnick+
453 " :\001CLIENTINFO :Supported queries are VERSION and SOURCE\001";
454 _connection.writeln(response);
455 }
456 //------------------------------------------------------------------
457 public void onClientSource(String orgnick) {
458 String response = "NOTICE "+orgnick+
459 " :\001SOURCE :http://relayirc.netpedia.net\001";
460 _connection.writeln(response);
461 }
462 //------------------------------------------------------------------
463 public void onClientVersion(String orgnick) {
464 // Tell them everything
465 String osdesc =
466 System.getProperty("os.name").replace(':','-')+"/"+
467 System.getProperty("os.version").replace(':','-')+"/"+
468 System.getProperty("os.arch").replace(':','-');
469 String vmdesc = "Java "+
470 System.getProperty("java.version").replace(':','-')+" ("+osdesc+")";
471
472 String response = "NOTICE "+orgnick+" :\001VERSION "+
473 _appName+":"+_appVersion+":"+vmdesc+"\001";
474
475 fireStatusEvent("\nSending VERSION information to "+orgnick+"\n");
476 _connection.writeln(response);
477 }
478 //----------------------------------------------------------------------
479 public void onConnect() {
480 final ChatEngineEvent event = new ChatEngineEvent(ChatEngine.this);
481 notifyListeners(new _EngineEventNotifier() {
482 public void notify(ChatEngineListener listener)
483 {listener.onConnection(event);}
484 });
485 }
486 //----------------------------------------------------------------------
487 public void onDisconnect() {
488 final ChatEngineEvent event = new ChatEngineEvent(ChatEngine.this);
489 notifyListeners(new _EngineEventNotifier() {
490 public void notify(ChatEngineListener listener)
491 {listener.onDisconnection(event);}
492 });
493 }
494 //------------------------------------------------------------------
495 public void onJoin( String user, String nick, String chan, boolean create ) {
496 getChannel(chan,true).getChannelMux().onJoin(user,nick,chan,create);
497 }
498 //------------------------------------------------------------------
499 public void onJoins( String users, String chan) {
500 getChannel(chan,true).getChannelMux().onJoins(users,chan);
501 }
502 //------------------------------------------------------------------
503 public void onKick( String kicked, String chan, String kicker, String txt ) {
504 getChannel(chan,true).getChannelMux().onKick(kicked,chan,kicker,txt);
505 }
506 //------------------------------------------------------------------
507 public void onMessage(String message) {
508 fireStatusEvent(message+"\n");
509 }
510 //------------------------------------------------------------------
511 public void onPrivateMessage(String orgnick, String chan, String txt) {
512 getChannel(chan,true).getChannelMux().onPrivateMessage(orgnick,chan,txt);
513 }
514 //------------------------------------------------------------------
515 public void onNick( String user, String oldnick, String newnick ) {
516 fireStatusEvent(oldnick+" now known as "+newnick);
517 for (Enumeration e = _channels.elements() ; e.hasMoreElements() ;) {
518 Channel chan = (Channel)e.nextElement();
519 chan.getChannelMux().onNick(user,oldnick,newnick);
520 }
521 }
522 //------------------------------------------------------------------
523 public void onNotice(String text) {
524 fireStatusEvent("NOTICE: "+text);
525 }
526 //------------------------------------------------------------------
527 public void onPart( String user, String nick, String chan ) {
528 getChannel(chan,true).getChannelMux().onPart(user,nick,chan);
529 }
530 //------------------------------------------------------------------
531 public void onOp( String oper, String chan, String oped ) {
532 getChannel(chan,true).getChannelMux().onOp(oper,chan,oped);
533 }
534 //------------------------------------------------------------------
535 public void onParsingError(String message) {
536 fireStatusEvent("Error parsing message: "+message);
537 }
538 //------------------------------------------------------------------
539 public void onPing(String params) {
540 _connection.writeln("PONG "+params+"\r\n");
541 }
542 //------------------------------------------------------------------
543 public void onStatus(String msg) {
544 fireStatusEvent(msg);
545 }
546 //------------------------------------------------------------------
547 public void onVersionNotice(String orgnick, String origin, String version) {
548 fireStatusEvent("\nVERSION Information for "+orgnick+"("+origin+")\n");
549 }
550 //------------------------------------------------------------------
551 public void onQuit( String user, String nick, String txt ) {
552 for (Enumeration e = _channels.elements() ; e.hasMoreElements() ;) {
553 Channel chan = (Channel)e.nextElement();
554 chan.getChannelMux().onQuit(user,nick,txt);
555 }
556 }
557 //------------------------------------------------------------------
558 /** Respond to server version reply. */
559 public void onReplyVersion(String version) {
560 fireStatusEvent("Server Version: "+version);
561 /*try {
562 System.out.println("0: "+((_tok)tokens.elementAt(0)).token);
563 System.out.println("1: "+((_tok)tokens.elementAt(1)).token);
564 System.out.println("2: "+((_tok)tokens.elementAt(2)).token);
565 System.out.println("3: "+((_tok)tokens.elementAt(3)).token);
566 System.out.println("4: "+((_tok)tokens.elementAt(4)).token);
567 } catch (Exception e) {}*/
568 }
569 //------------------------------------------------------------------
570 /** Respond to */
571 public void onReplyListUserChannels(int channelCount) {
572 _channelCount = channelCount;
573 }
574 //------------------------------------------------------------------
575 /** Respond to channel-list-start reply. */
576 public void onReplyListStart() {
577 if (_search!=null) _search.searchStarted(_channelCount);
578 }
579 //------------------------------------------------------------------
580 /** Respond to channel list item reply. */
581 public void onReplyList(String channel, int userCount, String topic) {
582 Channel channelObject = new Channel(channel,topic,userCount,ChatEngine.this);
583 _search.processChannel(channelObject);
584 }
585 //------------------------------------------------------------------
586 /** Respond to end-of-channel-list reply. */
587 public void onReplyListEnd() {
588 if (_search!=null) {
589 _search.searchEnded();
590 _search.setComplete(true);
591 _search = null;
592 }
593 }
594 //------------------------------------------------------------------
595 /**
596 * Respond to RPL_LUSERCLIENT messages which usually look like this:
597 * "There are <integer> users and <integer> invisible on <integer> servers"
598 */
599 public void onReplyListUserClient(String msg) {
600 fireStatusEvent(msg);
601 }
602 //------------------------------------------------------------------
603 /** Respond to who-is-user reply. */
604 public void onReplyWhoIsUser(String userName, String miscText) {
605 fireStatusEvent(userName+" is logged into "+miscText);
606 }
607 //------------------------------------------------------------------
608 /** Respond to who-is-server reply. */
609 public void onReplyWhoIsServer(String info) {
610 fireStatusEvent(info);
611 }
612 //------------------------------------------------------------------
613 /** Respond to who-is-operator reply. */
614 public void onReplyWhoIsOperator(String info) {
615 fireStatusEvent(info);
616 }
617 //------------------------------------------------------------------
618 /** Respond to who-is-idle reply. */
619 public void onReplyWhoIsIdle(String info) {
620 fireStatusEvent(info);
621 }
622 //------------------------------------------------------------------
623 /** Respond to end of WHOIS reply. */
624 public void onReplyEndOfWhoIs() {
625 fireStatusEvent(""); // force a line feed
626 }
627 //------------------------------------------------------------------
628 /**
629 * Respond to who-is-on-channels reply. The server sends this reply
630 * after you do a WHOIS command on a user. The reply lists the channels
631 * that the user is current inhabiting.
632 * @param nick Nick name of the user.
633 * @param channels List of channels, separated by spaces.
634 */
635 public void onReplyWhoIsChannels(String nick, String channels) {
636 fireStatusEvent(nick+" is on "+channels);
637 }
638 //------------------------------------------------------------------
639 /** Respond to Message-Of-The-Day start reply. */
640 public void onReplyMOTDStart() {
641 }
642 //------------------------------------------------------------------
643 /** Respond to Message-Of-The-Day reply. */
644 public void onReplyMOTD(String msg) {
645 fireStatusEvent(msg);
646 }
647 //------------------------------------------------------------------
648 /** Respond to Message-Of-The-Day end reply. */
649 public void onReplyMOTDEnd() {
650 }
651 //------------------------------------------------------------------
652 /**
653 * Respond to name reply. This reply is sent to inform you of the
654 * users that inhabit the channel that you just joined.
655 * @param channel Name of channel.
656 * @param users List of users, separated by spaces.
657 */
658 public void onReplyNameReply(String channel, String users) {
659 onJoins(users,channel);
660 }
661 //------------------------------------------------------------------
662 /** Respond to topic change. */
663 public void onTopic(String channel, String topic) {
664 getChannel(channel,true).getChannelMux().onTopic(channel,topic);
665 }
666 //------------------------------------------------------------------
667 /** Respond to topic reply. */
668 public void onReplyTopic(String channel, String topic) {
669 getChannel(channel,true).getChannelMux().onReplyTopic(channel,topic);
670 }
671 //------------------------------------------------------------------
672 /** Respond to no Message-Of-The-Day reply. */
673 public void onErrorNoMOTD() {
674 fireStatusEvent("\nERROR: No message of the day.\n");
675 }
676 //------------------------------------------------------------------
677 /** Respond to need more params error. */
678 public void onErrorNeedMoreParams() {
679 fireStatusEvent("\nERROR: Meed more parameters.\n");
680 }
681 //------------------------------------------------------------------
682 /** Respond to no nick name given error. */
683 public void onErrorNoNicknameGiven() {
684 onErrorNeedMoreParams();
685 }
686 //------------------------------------------------------------------
687 /** Respond to nick name in use error. */
688 public void onErrorNickNameInUse(String badNick) {
689 onErrorNickCollision(badNick);
690 }
691 //------------------------------------------------------------------
692 /** Respond to nick name collision error. */
693 public void onErrorNickCollision(String badNick) {
694
695 if (badNick.equals(_nick)) {
696 fireStatusEvent("\nWARNING: Nick name already in use, using alternate...\n");
697 _connection.sendNick(_altNick);
698 }
699 else if (badNick.equals(_altNick)) {
700 fireStatusEvent("\nERROR: Alternate nick name already in use, disconnecting...\n");
701 _connection.close();
702 }
703 else {
704 fireStatusEvent("\nERROR: Nick name already in use, reverting to "+_nick);
705 _connection.sendNick(_nick);
706 }
707 }
708 //------------------------------------------------------------------
709 /** Respond to erroneus nick name error. */
710 public void onErrorErroneusNickname(String badNick) {
711
712 if (badNick.equals(_nick)) {
713 fireStatusEvent("\nERROR: Error in nick name, using alternate...\n");
714 _connection.sendNick(_nick);
715 }
716 else if (badNick.equals(_nick)) {
717 fireStatusEvent("\nERROR: Error in alternate nick name, disconnecting...\n");
718 _connection.close();
719 }
720 else {
721 fireStatusEvent("\nERROR: Error in nick name, reverting to "+_nick);
722 _connection.sendNick(_nick);
723 }
724 }
725 //------------------------------------------------------------------
726 /** Respond to */
727 public void onErrorAlreadyRegistered() {
728 fireStatusEvent("\nERROR: you are already connected to this server!\n");
729 disconnect();
730 }
731 //------------------------------------------------------------------
732 /** Respond to message not recognized by message switch. */
733 public void onErrorUnknown(String message) {
734 RCTest.println("UNKNOWN: "+message+"\n");
735 }
736 //------------------------------------------------------------------
737 /** Respond to message not supported by message switch. */
738 public void onErrorUnsupported(String message) {
739 RCTest.println("UNSUPPORTED: "+message+"\n");
740 }
741 }
742 }
743