KickJava   Java API By Example, From Geeks To Geeks.

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


1 package rero.ircfw.data;
2
3 /* Keeps Channel Information Up to Date
4     (Including: Channel topic, user names (c/o /names reply))
5  
6  */

7
8 import rero.ircfw.*;
9 import rero.ircfw.interfaces.FrameworkConstants;
10
11 import java.util.*;
12
13 public class ChannelInformationTracker extends DataEventAction implements FrameworkConstants
14 {
15     public boolean isEvent(HashMap data)
16     {
17         String JavaDoc event = (String JavaDoc)data.get($EVENT$);
18          
19         return (event.equals("353") || /* numeric giving us a /names reply */
20                 event.equals("TOPIC") || /* TOPIC has been changed... */
21                 event.equals("332")); /* numeric giving us the channel topic */
22     }
23
24     public void process(HashMap data)
25     {
26         String JavaDoc event = (String JavaDoc)data.get($EVENT$);
27         String JavaDoc parms = (String JavaDoc)data.get($PARMS$);
28         String JavaDoc channel;
29
30         if (event.equals("332"))
31         {
32             channel = parms;
33             channel = channel.substring(0, channel.indexOf(' '));
34
35             if (dataList.getChannel(channel) != null)
36                dataList.getChannel(channel).setTopic(parms.substring(channel.length() + 1, parms.length()));
37         }
38         else if (event.equals("TOPIC"))
39         {
40             channel = (String JavaDoc)data.get($TARGET$);
41             dataList.getChannel(channel).setTopic(parms);
42         }
43         else if (event.equals("353"))
44         {
45             String JavaDoc[] users = parms.split("\\s", 0);
46
47             Channel ch = dataList.getChannel(users[1]);
48
49             if (!dataList.isOn(dataList.getMyUser(), ch))
50             {
51                 return;
52             }
53
54             for (int x = 2; x < users.length; x++)
55             {
56                 dataList.AddUser(users[x], ch);
57             }
58         }
59     }
60 }
61
Popular Tags