Source code: org/rakiura/mbot/LimitThread.java
1
2 package org.rakiura.mbot;
3
4 import java.util.*;
5 import java.io.*;
6
7 /**
8 * Thread for managing +l updates on different channels.
9 *
10 * <br><br>
11 * LimitThread.java
12 * Created: Wed Jul 14 16:59:28 1999
13 *
14 *@author Mariusz Nowostawski
15 *@version 0.3 $Revision: 1.1.1.1 $
16 */
17 public class LimitThread extends Thread {
18
19 private Engine engine;
20 private int limit;
21 private Vector channels;
22 private long delay;
23 private Hashtable current_limit;
24
25 /**/
26 public LimitThread(Engine engine) {
27 super();
28 this.channels = new Vector();
29 this.engine = engine;
30 delay = 45;
31 limit = 3;
32 current_limit = new Hashtable();
33 }
34
35 /**/
36 public LimitThread(Engine engine, Vector chan) {
37 super();
38 this.channels = chan;
39 this.engine = engine;
40 delay = 45;
41 limit = 3;
42 current_limit = new Hashtable();
43 for(int i=0; i<chan.size(); i++)
44 current_limit.put(((String)chan.elementAt(i)).toLowerCase(), new Integer(0));
45 }
46
47 /**
48 * Get the value of limit.
49 *@return Value of limit.
50 */
51 public int getLimit() {return limit;}
52
53 /**
54 * Set the value of limit.
55 *@param v Value to assign to limit.
56 *@return old value of limit.
57 */
58 public int setLimit(int v) {
59 int old = this.limit;
60 this.limit = v;
61 return old;
62 }
63
64 /**
65 * Get the value of channels.
66 *@return Value of channels.
67 */
68 public Vector getChannels() {return channels;}
69
70 /**
71 */
72 public synchronized void addChannel(String chan) {
73 synchronized(channels){
74 if(channels.indexOf(chan.toLowerCase()) == -1) {
75 channels.addElement(chan.toLowerCase());
76 current_limit.put(chan.toLowerCase(), new Integer(0));
77 }
78 }
79 }
80
81 /**
82 */
83 public synchronized void removeChannel(String chan) {
84 synchronized(channels){
85 channels.removeElement(chan.toLowerCase());
86 current_limit.remove(chan.toLowerCase());
87 }
88 }
89
90 /**
91 * Get the value of delay.
92 *@return Value of delay.
93 */
94 public long getDelay() {return delay;}
95
96 /**
97 * Set the value of delay.
98 *@param v Value to assign to delay.
99 *@return old value of delay.
100 */
101 public long setDelay(long v) {
102 long old = this.delay;
103 this.delay = v;
104 return old;
105 }
106
107 /**/
108 public synchronized void run(){
109 while(true){
110 try{
111 wait(delay*1000);
112 }catch(InterruptedException e){
113 e.printStackTrace();
114 }
115 if(channels.size()>0 && engine.MODE < 2){
116 synchronized(channels){
117 Enumeration enum = channels.elements();
118 while(enum.hasMoreElements()){
119 String s = (String)enum.nextElement();
120 engine.writeLine("LIST "+s);
121 String line = engine.listLineVector.getString();
122 while(line !=null && line.indexOf("322") == -1){
123 line = engine.listLineVector.getString();
124 }
125 if(line != null && line.indexOf("322") != -1){
126 StringTokenizer st = new StringTokenizer(line, " ");
127 st.nextToken(); // server name
128 st.nextToken(); // number
129 st.nextToken(); // nick
130 String ch = st.nextToken().toLowerCase(); // channel
131 Channel chan = engine.getChannel(ch);
132 if(chan == null){
133 chan = new Channel();
134 chan.setName(ch);
135 chan.addFlag("autoop");
136 chan.addFlag("bitch");
137 engine.addChannel(chan);
138 }
139 if(current_limit.get(ch) == null) continue;
140
141 int cur_limit = ((Integer)current_limit.get(ch)).intValue();
142 int num_users = Integer.parseInt(st.nextToken());
143 engine.getChannel(ch).setNumberOfUsers(num_users);
144 num_users = num_users + limit;
145 if(num_users < cur_limit || (num_users - cur_limit) > 1){
146 if(engine.IamOP.get(ch.toLowerCase()) != null) {
147 if(engine.writeActionLine("MODE "+ch+" +l "+num_users))
148 engine.LastMode_chan = ch;
149 current_limit.put(ch, new Integer(num_users));
150 }
151 else current_limit.put(ch, new Integer(0));
152 }
153 }
154 }
155 }
156 }
157 }
158 }
159
160 } // LimitThread
161 //////////////////// end of file ////////////////////