1 20 package freecs.commands; 21 22 import freecs.content.MessageState; 23 import freecs.core.User; 24 import freecs.core.UserManager; 25 import freecs.interfaces.ICommand; 26 import freecs.interfaces.IUserStates; 27 28 35 public class CmdRightChange extends AbstractCommand { 36 public final String cmd = "/rc"; 37 private static final ICommand self = new CmdRightChange(); 38 39 private CmdRightChange() { } 40 41 public static ICommand getInstance() { 42 return self; 43 } 44 45 public boolean execute(MessageState msgState, String param) { 46 if (param.length() < 1) { 47 msgState.msgTemplate = "error.rc.noArg"; 48 msgState.sender.sendMessage(msgState.mp); 49 return false; 50 } 51 String [] parts = param.split(" "); 52 param = parts[0]; 53 User u = getUser(msgState, param); 55 if (u == null) 56 return false; 57 msgState.usercontext = u; 58 59 if (parts.length < 2) { 61 if(u.compareRoleTo(msgState.sender) == 2) { 63 msgState.msgTemplate="error.noRight.noVipAdmin"; 64 msgState.sender.sendMessage(msgState.mp); 65 return false; 66 } else if(u.compareRoleTo(msgState.sender) == 3) { 67 msgState.msgTemplate="error.noRight.noAdmin"; 68 msgState.sender.sendMessage(msgState.mp); 69 return false; 70 } else if (u.compareRoleTo(msgState.sender) >= 0) { 71 if (u.getPermissionMap() == u.getDefaultPermissionMap()) 72 return false ; 73 u.resetPermission(); 74 msgState.msgTemplate = "rc.rightsReset"; 75 msgState.sender.sendMessage(msgState.mp); 76 msgState.msgTemplate = "rc.newResetRight"; 77 u.sendMessage(msgState.mp); 78 } else { 79 msgState.param = "reset"; 80 msgState.msgTemplate = "error.rc.notRight"; 81 msgState.sender.sendMessage(msgState.mp); 82 } 83 84 return true; 85 } 86 87 for (int i = 1; i < parts.length; i++) { 90 String part = parts[i]; 91 if (part.length() < 2) 92 continue; 93 if (part.startsWith("+")) { 94 part = part.substring(1); 96 msgState.param = part; 97 int right = UserManager.resolveState(part); 98 if (right != 0) { 99 if (right== IUserStates.IS_GUEST || right== IUserStates.IS_MODERATOR) { 100 if (allowedToChangeRight(right,msgState.sender)) { 101 u.givePermission(right); 102 msgState.msgTemplate = "rc.rightAssigned"; 103 msgState.sender.sendMessage(msgState.mp); 104 msgState.msgTemplate = "rc.newAssignedRight"; 105 u.sendMessage(msgState.mp); 106 continue; 107 } else { 108 msgState.msgTemplate = "error.rc.notRight"; 109 msgState.sender.sendMessage(msgState.mp); 110 continue; 111 } 112 } 113 } 114 } else if (part.startsWith("-")) { 115 part = part.substring(1); 117 msgState.param = part; 118 int right = UserManager.resolveState(part); 119 if (right != 0) { 120 if (right== IUserStates.IS_GUEST || right== IUserStates.IS_MODERATOR) { 121 if (allowedToChangeRight(right,msgState.sender)) { 122 u.takePermission(right); 123 msgState.msgTemplate = "rc.rightRevoked"; 124 msgState.sender.sendMessage(msgState.mp); 125 msgState.msgTemplate = "rc.newRevokedRight"; 126 u.sendMessage(msgState.mp); 127 continue; 128 } else { 129 msgState.msgTemplate = "error.noRight.noMOD"; 130 msgState.sender.sendMessage(msgState.mp); 131 continue; 132 } 133 } 134 } 135 } 136 if (part.startsWith("=")) { 137 part = part.substring(1); 138 msgState.param = part; 139 int right = UserManager.resolveState(part); 140 if (right != 0) { 141 if (right== IUserStates.ROLE_USER || right== IUserStates.ROLE_VIP || right== IUserStates.ROLE_ASSHOLE ) { 142 if (allowedToChangeRight(right,msgState.sender)) { 143 u.setNewPermission(right); 144 msgState.msgTemplate = "rc.rightAssigned"; 145 msgState.sender.sendMessage(msgState.mp); 146 msgState.msgTemplate = "rc.newAssignedRight"; 147 u.sendMessage(msgState.mp); 148 continue; 149 } else { 150 msgState.msgTemplate = "error.noRight.noAdmin"; 151 msgState.sender.sendMessage(msgState.mp); 152 continue; 153 } 154 } 155 } 156 } 157 msgState.msgTemplate = "error.rc.rightNotFound"; 159 msgState.sender.sendMessage(msgState.mp); 160 } 161 162 return true; 163 } 164 165 public static boolean allowedToChangeRight(int newRight, User donatingUser) { 166 if (donatingUser.hasRole(IUserStates.ROLE_GOD)) { 167 return true; 169 } else if (donatingUser.hasRight(IUserStates.IS_MODERATOR)) { 170 if (newRight == IUserStates.IS_GUEST) 172 return true; 173 if (newRight == IUserStates.IS_MODERATOR) 174 return true; 175 } 182 return false; 183 } 184 185 } | Popular Tags |