Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/rakiura/mbot/ChanExceptionThread.java


1   
2   package org.rakiura.mbot;
3   
4   /**/
5   import java.util.*;
6   
7   /**
8    * Thread responsible for managing Channel Exception list.
9    * <br><br>
10   * ChanExceptionThread.java<br><br>
11   * Created: Tue Jul 20 15:31:29 1999
12   *
13   *@author Mariusz Nowostawski
14   *@version 0.3 $Revision: 1.1.1.1 $
15   */
16  public class ChanExceptionThread extends Thread {
17  
18    private Engine engine;
19    private int delay;// in minutes
20    private boolean normal;
21  
22    Vector current;
23    HashSet shouldbe;
24  
25    /**/
26    public ChanExceptionThread(Engine e, int delay) {
27      super();
28      this.engine = e;
29      this.delay = delay;
30      normal = true;
31      current = new Vector(20);
32      shouldbe = new HashSet();
33    }
34      
35    /**
36     * Get the value of delay.
37     *@return Value of delay.
38     */
39    public int getDelay() {return delay;}
40      
41    /**
42     * Set the value of delay.
43     *@param v  Value to assign to delay.
44     *@return old value of delay.
45     */
46    public int setDelay(int  v) {
47      int old = this.delay;
48      this.delay = v;
49      return old;
50    }
51  
52    /**/
53    public void run(){
54      while(true){
55        processList();
56      }
57    }
58  
59    /**
60     * call for initialization with true.
61     */
62    public void query(String chan, boolean normalCall){
63      this.normal = normalCall;
64      engine.writeLine("MODE "+chan+" +e");
65    }
66    /**/
67    public void query(String chan){
68      this.normal = false;
69      engine.writeLine("MODE "+chan+" +e");
70    }
71  
72    /**/
73    protected void processList(){
74      String line = engine.chanExceptionLineVector.getString();
75      StringTokenizer st = new StringTokenizer(line);
76      String server = st.nextToken(); // server
77      String code = st.nextToken(); // code
78      String nick = st.nextToken(); // my nick
79      String chan = st.nextToken(); // channel
80      String mask = st.nextToken().toLowerCase(); // mask or end note
81  
82      //nick check
83      if(!engine.getNick().equals(nick)) engine.nextNick();
84  
85      if(code.equals("348")) {
86        current.addElement(mask);
87      } else {
88        // users for +e
89        Enumeration enum = engine.getUsersForFlags(chan, "e");
90        shouldbe.clear();
91  
92        // collect all masks which should have +e
93        while(enum.hasMoreElements()){
94          User u = (User)enum.nextElement();
95          Enumeration hosts = u.getHosts();
96          while(hosts.hasMoreElements())
97            shouldbe.add(((String)hosts.nextElement()).toLowerCase());
98        }
99        String flags = "", patterns = "";
100       int j = 0;//how many to send to server
101       Enumeration ms = shouldbe.elements();
102       Vector temp; boolean wasthere;
103       while(ms.hasMoreElements()){
104         String m = (String)ms.nextElement();
105         wasthere = false;
106         temp = new Vector(20);
107         for(int i=0; i<current.size(); i++){
108           if(m.equals(current.elementAt(i))){
109             current.removeElementAt(i);
110             wasthere = true;
111             break;
112           }
113         }
114         if(!wasthere) {
115           j++;
116           if(j == 1) { flags = "+e"; patterns = m; }
117           else{ 
118             flags = flags + "e"; patterns = patterns + " " + m; 
119             if(j == 3) {
120               if(engine.IamOP.get(chan.toLowerCase()) != null) {
121                 engine.writeLine("MODE "+chan+" "+flags+" "+patterns);
122                 engine.LastMode_chan = chan;
123               }
124               j=0;
125             }
126           }
127         }
128       }
129       // -e
130       boolean firsttime = true;
131       for(int i=0; i<current.size(); i++){
132         String m = (String)current.elementAt(i);
133         j++;
134         if(j == 1) { flags = "-e"; patterns = m; }
135         else { 
136           if(firsttime) flags = flags + "-e";
137           else
138             flags = flags + "e"; 
139           patterns = patterns + " " + m; 
140           if(j == 3) {
141             if(engine.IamOP.get(chan.toLowerCase()) != null){
142               engine.writeLine("MODE "+chan+" "+flags+" "+patterns);
143               engine.LastMode_chan = chan;
144             }
145             j=0;
146           }
147         }
148       }
149       if(j>0 && engine.IamOP.get(chan.toLowerCase()) != null) {
150         engine.writeLine("MODE "+chan+" "+flags+" "+patterns);
151         engine.LastMode_chan = chan;
152       }
153 
154       // leave next processing thread
155       if(normal){
156         new ActionThread(engine, delay, "MODE "+chan+" +e").start();
157       }
158       else{
159         normal = true;
160       }
161 
162       current.removeAllElements();
163     }
164   }
165 
166 } // ChanExceptionThread
167 //////////////////// end of file ////////////////////