KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > ircfw > data > ChannelUserWatch


1 package rero.ircfw.data;
2
3 /* keeps track of parts, joins, quits, kicks, and nick changes for everyone but me...
4
5    the IDL API makes dealing with this aspect of things pretty easy.
6    I may consider refactoring the data list API's for this stuff into this object,
7    we'll see... */

8
9 import rero.ircfw.*;
10 import rero.ircfw.interfaces.*;
11
12 import java.util.*;
13
14 public class ChannelUserWatch extends DataEventAction implements FrameworkConstants
15 {
16     public boolean isEvent(HashMap data)
17     {
18         String JavaDoc event = (String JavaDoc)data.get($EVENT$);
19          
20         return (event.equals("QUIT") || event.equals("JOIN") || event.equals("PART") ||
21                 event.equals("NICK") || event.equals("KICK") || event.equals("PRIVMSG")) ;
22     }
23
24     public void process(HashMap data)
25     {
26         String JavaDoc event = (String JavaDoc)data.get($EVENT$);
27         String JavaDoc nick = (String JavaDoc)data.get($NICK$);
28         String JavaDoc channel = (String JavaDoc)data.get($TARGET$);
29
30         if (event.equals("JOIN"))
31         {
32             dataList.JoinNick(nick, channel);
33         }
34         else if (event.equals("PART"))
35         {
36             dataList.PartNick(nick, dataList.getChannel(channel));
37         }
38         else if (event.equals("QUIT"))
39         {
40             StringBuffer JavaDoc blah = new StringBuffer JavaDoc();
41
42             Iterator iter = dataList.getUser(nick).getChannels().iterator();
43             while (iter.hasNext())
44             {
45                blah.append(((Channel)iter.next()).getName());
46
47                if (iter.hasNext())
48                   blah.append(",");
49             }
50
51             data.put("$channels", blah.toString());
52
53             dataList.QuitNick(nick);
54         }
55         else if (event.equals("NICK") && data.containsKey($PARMS$))
56         {
57             dataList.ChangeNick(nick, (String JavaDoc)data.get($PARMS$));
58         }
59         else if (event.equals("KICK"))
60         {
61             String JavaDoc d = (String JavaDoc)data.get($PARMS$);
62             d = d.substring(0, d.indexOf(' '));
63             dataList.PartNick(d, dataList.getChannel(channel));
64         }
65         else if (event.equals("PRIVMSG"))
66         {
67             // @Serge: code moved to ProcessEvents.java, where we can touch user not only on
68
// PRIVMSG, but also on ACTION and other events.
69
// Fix for: http://jirc.hick.org/cgi-bin/bitch.cgi/view.html?1912086
70
}
71     }
72 }
73
74 /*
75 Enter String> :theUncle!~a@pcp.royalok.mi.comcast.net NICK :^butane
76   *** looking at: :^butane
77 Parsing message took: 8
78   user = ~a
79   data = <null> ^butane
80   host = pcp.royalok.mi.comcast.net
81   address = ~a@pcp.royalok.mi.comcast.net
82   event = NICK
83   source = theUncle
84   nick = theUncle
85   raw = :theUncle!~a@pcp.royalok.mi.comcast.net NICK :^butane
86   parms = ^butane
87
88 Enter String> :cheezi!chris@likes.dick.com KICK #pollution ^butane :I am the uncle
89   *** looking at: ^butane :I am the uncle
90   *** looking at: :I am the uncle
91 Parsing message took: 2
92   user = chris
93   data = #pollution ^butane I am the uncle
94   target = #pollution
95   host = likes.dick.com
96   address = chris@likes.dick.com
97   event = KICK
98   source = cheezi
99   nick = cheezi
100   raw = :cheezi!chris@likes.dick.com KICK #pollution ^butane :I am the uncle
101   parms = ^butane I am the uncle
102
103 */

104
Popular Tags