1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 package com.levelonelabs.aimbot.modules;
34
35 import java.util.ArrayList;
36 import java.util.StringTokenizer;
37
38 import com.levelonelabs.aim.AIMBuddy;
39 import com.levelonelabs.aimbot.AIMBot;
40 import com.levelonelabs.aimbot.BotModule;
41
42
43 /***
44 * Used to hanle administration of users.
45 *
46 * @author Will Gorman, Scott Oster
47 * @created January 31, 2002
48 */
49 public class UserAdminModule extends BotModule {
50 private static ArrayList services;
51
52 /***
53 * Initialize the service commands.
54 */
55 static {
56 services = new ArrayList();
57 services.add("adduser");
58 services.add("rmuser");
59 services.add("denyuser");
60 services.add("permituser");
61 services.add("permitmode");
62 }
63
64
65 /***
66 * Constructor for the UserAdminModule object
67 *
68 * @param bot
69 */
70 public UserAdminModule(AIMBot bot) {
71 super(bot);
72 }
73
74
75 /***
76 * Gets the services attribute of the UserAdminModule object
77 *
78 * @return The services value
79 */
80 public ArrayList getServices() {
81 return services;
82 }
83
84
85 /***
86 * Gets the name attribute of the UserAdminModule object
87 *
88 * @return The name value
89 */
90 public String getName() {
91 return "User Administration Module";
92 }
93
94
95 /***
96 * Describes the usage of the module
97 *
98 * @return the usage of the module
99 */
100 public String help() {
101 StringBuffer sb = new StringBuffer();
102 sb
103 .append("<B>adduser <i>BUDDY</i> <ADMIN></B> (adds a user to the list, along with allowing for admin perms)\n");
104 sb.append("<B>rmuser <i>BUDDY</i></B> (removes a user from the list)\n");
105 sb.append("<B>denyuser <i>BUDDY</i></B> (deny a user *ADMIN ONLY*)\n");
106 sb.append("<B>permituser <i>BUDDY</i></B> (permit a user *ADMIN ONLY*)\n");
107 sb.append("<B>permitmode <i>[MODE]</i></B> (set or display the permitmode*ADMIN ONLY*)\n");
108 return sb.toString();
109 }
110
111
112 /***
113 * Perform user maintenance
114 *
115 * @param buddy
116 * @param query
117 */
118 public void performService(AIMBuddy buddy, String query) {
119 if (query.toLowerCase().startsWith("adduser")) {
120
121 StringTokenizer st = new StringTokenizer(query, " ");
122 if (st.countTokens() < 2) {
123 super.sendMessage(buddy, "ERROR:\n" + help());
124 return;
125 }
126
127
128 String imcommand = st.nextToken();
129 String imcommandTo = st.nextToken();
130 AIMBuddy to = super.getBuddy(imcommandTo);
131 if (to != null) {
132 super.sendMessage(buddy, "User " + imcommandTo + " already exists in the system.");
133 return;
134 }
135
136
137 to = new AIMBuddy(imcommandTo);
138 to.addRole(AIMBot.ROLE_USER);
139 if (buddy.hasRole(AIMBot.ROLE_ADMINISTRATOR) && st.hasMoreTokens()
140 && st.nextToken().equalsIgnoreCase("ADMIN")) {
141 to.addRole(AIMBot.ROLE_ADMINISTRATOR);
142 }
143 super.addBuddy(to);
144 super.sendMessage(buddy, "User " + imcommandTo + " added.");
145 } else if (query.toLowerCase().startsWith("rmuser")) {
146
147 StringTokenizer st = new StringTokenizer(query, " ");
148 if (st.countTokens() < 2) {
149 super.sendMessage(buddy, "ERROR:\n" + help());
150 return;
151 }
152
153
154 String imcommand = st.nextToken();
155 String imcommandTo = st.nextToken();
156 AIMBuddy to = super.getBuddy(imcommandTo);
157 if (to == null) {
158 super.sendMessage(buddy, "User " + imcommandTo + " does not exist in the system.");
159 } else if (buddy.hasRole(AIMBot.ROLE_ADMINISTRATOR)) {
160 super.removeBuddy(to);
161 super.sendMessage(buddy, "User " + imcommandTo + " removed.");
162 } else {
163 super.sendMessage(buddy, "Only admins can remove users.");
164 }
165 } else if (query.toLowerCase().startsWith("denyuser")) {
166
167 StringTokenizer st = new StringTokenizer(query, " ");
168 if (st.countTokens() < 2) {
169 super.sendMessage(buddy, "ERROR:\n" + help());
170 return;
171 }
172
173
174 String imcommand = st.nextToken();
175 String imcommandTo = st.nextToken();
176 AIMBuddy to = super.getBuddy(imcommandTo);
177 if (to == null) {
178 super.sendMessage(buddy, "User " + imcommandTo + " does not exist in the system.");
179 } else if (buddy.hasRole(AIMBot.ROLE_ADMINISTRATOR)) {
180 super.denyBuddy(to);
181 super.sendMessage(buddy, "User " + imcommandTo + " denied.");
182 } else {
183 super.sendMessage(buddy, "Only admins can deny users.");
184 }
185 } else if (query.toLowerCase().startsWith("permituser")) {
186
187 StringTokenizer st = new StringTokenizer(query, " ");
188 if (st.countTokens() < 2) {
189 super.sendMessage(buddy, "ERROR:\n" + help());
190 return;
191 }
192
193
194 String imcommand = st.nextToken();
195 String imcommandTo = st.nextToken();
196 AIMBuddy to = super.getBuddy(imcommandTo);
197 if (to == null) {
198 super.sendMessage(buddy, "User " + imcommandTo + " does not exist in the system.");
199 } else if (buddy.hasRole(AIMBot.ROLE_ADMINISTRATOR)) {
200 super.permitBuddy(to);
201 super.sendMessage(buddy, "User " + imcommandTo + " permitted.");
202 } else {
203 super.sendMessage(buddy, "Only admins can permit users.");
204 }
205 } else if (query.toLowerCase().startsWith("permitmode")) {
206
207 StringTokenizer st = new StringTokenizer(query, " ");
208 if (st.countTokens() < 1) {
209 super.sendMessage(buddy, "ERROR:\n" + help());
210 return;
211 }
212
213 if (!buddy.hasRole(AIMBot.ROLE_ADMINISTRATOR)) {
214 super.sendMessage(buddy, "Only admins can permit users.");
215 return;
216 }
217
218 String imcommand = st.nextToken();
219 if (st.hasMoreTokens()) {
220 String newMode = st.nextToken();
221 try {
222 int mode = Integer.parseInt(newMode);
223 if (mode < 1 || mode > 5) {
224 throw new NumberFormatException("Not within range.");
225 }
226 super.setPermitMode(mode);
227 super.sendMessage(buddy, "Set permit mode to: " + mode
228 + "\nPERMIT_ALL = 1, DENY_ALL = 2, PERMIT_SOME = 3, DENY_SOME = 4, PERMIT_BUDDIES = 5");
229
230 } catch (NumberFormatException nfe) {
231 super.sendMessage(buddy, "Invalid permit mode.");
232 }
233 } else {
234 super.sendMessage(buddy, "Current permit mode is: " + super.getPermitMode()
235 + "\nPERMIT_ALL = 1, DENY_ALL = 2, PERMIT_SOME = 3, DENY_SOME = 4, PERMIT_BUDDIES = 5");
236 }
237 }
238 }
239 }