-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecurity.java
More file actions
48 lines (43 loc) · 1.44 KB
/
Security.java
File metadata and controls
48 lines (43 loc) · 1.44 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public abstract class Security {
public static final int VISITOR = 0, MEMBER = 1, ADMIN = 2, OPERATOR = 3;
public static final String[] FORBIDDEN_NAMES = {"system", "server", "operator", "admin", "penis", "console"};
public static final int NAME_MAX_LENGTH = 12;
public static boolean hasPermission(User user, int minSecurityLevel) {
return user.getSecurityLevel() >= minSecurityLevel;
}
public static boolean isInvalidInt(String str) {
try {
Integer.parseInt(str);
return false;
} catch (NumberFormatException e) {
return true;
}
}
public static boolean nameDenied(String name) {
boolean out = false;
for (String forbiddenName : FORBIDDEN_NAMES) {
if (name.toLowerCase().contains(forbiddenName)) {
out = true;
break;
}
}
return out;
}
public static int switchLevel(User user, String levelString) {
if (isInvalidInt(levelString)) {
user.getServer().removeUserById(user.getUserId(), "Invalid level!");
return VISITOR;
}
int level = Integer.parseInt(levelString);
switch (level) {
case 7980:
return OPERATOR;
case 6568:
return ADMIN;
case 8673:
return VISITOR;
default:
return MEMBER;
}
}
}