1 20 21 package freecs.commands; 22 import java.util.Vector ; 23 import java.util.Iterator ; 24 25 import freecs.interfaces.ICommand; 26 import freecs.interfaces.IUserStates; 27 import freecs.util.GroupUserList; 28 import freecs.core.Group; 29 import freecs.core.GroupManager; 30 import freecs.core.User; 31 import freecs.content.MessageState; 32 33 38 public class CmdKick extends AbstractCommand { 39 public final String cmd= "/k"; 40 private static final ICommand selve=new CmdKick(); 41 42 private CmdKick () { } 43 44 public static ICommand getInstance () { 45 return selve; 46 } 47 48 public boolean execute (MessageState msgState, String param) { 49 if (isPunished (msgState)) 50 return false; 51 Group sg = msgState.sender.getGroup (); 53 boolean mayKick = msgState.sender.hasRight(IUserStates.MAY_KICK); 54 int pos1 = param.indexOf(" "); 55 int pos2 = param.indexOf(":"); 56 boolean multiUser = (pos1!=-1 && (pos2 > pos1+1 || pos2==-1)); 57 if (multiUser && !msgState.sender.hasRight(IUserStates.ROLE_VIP)) { 58 msgState.msgTemplate="error.mass.noRight.noVipAdmin"; 59 msgState.sender.sendMessage (msgState.mp); 60 return false; 61 } 62 if (pos2>-1) { 64 String parts[] = param.split (":"); 65 param = parts[0]; 66 msgState.reason = parts[1]; 67 } 68 msgState.targetGroup = GroupManager.mgr.getGroup ("exil"); 69 Vector found = getMultibleUsers(msgState, param); 70 if (found.size() > 1 71 && !msgState.sender.hasRight(IUserStates.ROLE_VIP)) { 72 msgState.msgTemplate = "error.noRight.noVipAdmin"; 73 msgState.sender.sendMessage(msgState.mp); 74 return false; } 76 GroupUserList gul = new GroupUserList(); 77 msgState.useRenderCache=false; 78 for (Iterator i = found.iterator(); i.hasNext(); ) { 79 User cu = (User) i.next(); 80 msgState.sourceGroup = cu.getGroup(); 81 if (!cu.hasRight(IUserStates.FREELY_KICKABLE)) { 82 if (!msgState.sender.hasRight(IUserStates.ROLE_VIP) 83 && (msgState.sourceGroup==null 84 || !msgState.sourceGroup.equals(msgState.sender.getGroup()))) { 85 msgState.usercontext = cu; 86 msgState.msgTemplate = "error.noRight.noVipAdmin"; 87 msgState.sender.sendMessage(msgState.mp); 88 return false; } else if (!msgState.sender.hasRight(IUserStates.ROLE_VIP) 90 && !msgState.sourceGroup.usrIsSu(msgState.sender)) { 91 msgState.usercontext = cu; 92 msgState.msgTemplate = "error.noRight.noSuVipAdmin"; 93 msgState.sender.sendMessage(msgState.mp); 94 return false; } else if (cu.hasRight(IUserStates.ROLE_GOD)) { 96 msgState.usercontext = cu; 97 msgState.msgTemplate = "error.noRight.isAdmin"; 98 msgState.sender.sendMessage(msgState.mp); 99 i.remove(); 100 continue; 101 } else if (cu.hasRight(IUserStates.ROLE_VIP) 102 && !msgState.sender.hasRight(IUserStates.ROLE_GOD)){ 103 msgState.usercontext = cu; 104 msgState.msgTemplate = "error.noRight.isVip"; 105 msgState.sender.sendMessage(msgState.mp); 106 i.remove(); 107 continue; 108 } 109 } 110 if (msgState.targetGroup == null) { 111 msgState.targetGroup = GroupManager.mgr.openGroup ("exil", "punished users here", null, msgState.sender); 112 if (msgState.targetGroup == null) { 113 msgState.param = "exil"; 114 msgState.usercontext = cu; 115 msgState.msgTemplate = "error.k.noGroupRight"; 116 msgState.sender.sendMessage(msgState.mp); 117 return false; 118 } 119 msgState.targetGroup.removeFromSusers(cu); 120 } else if (!msgState.targetGroup.usrMayJoin(msgState.sender)) { 121 msgState.param = ""; 122 msgState.usercontext = cu; 123 msgState.msgTemplate = "error.k.noGroupRight"; 124 msgState.sender.sendMessage (msgState.mp); 125 return false; 126 } 127 msgState.usercontext = cu; 128 gul.addUser(cu); 129 msgState.targetGroup.addUser(cu, msgState.sender); 130 msgState.msgTemplate = "message.k.personal"; 131 cu.sendMessage(msgState.mp); 132 } 133 if (found.size()==0) 134 return false; 135 if (found.size()==1) { 136 msgState.msgTemplate="message.k.destination.singular"; 137 msgState.targetGroup.exclusiveSendMessage(msgState.mp, found); 138 if (!msgState.sender.getGroup().equals(msgState.sourceGroup) 139 && !msgState.sender.equals(msgState.usercontext)) { 140 msgState.msgTemplate="message.k.confirm.singular"; 141 msgState.sender.sendMessage(msgState.mp); 142 } 143 msgState.msgTemplate="message.k.singular"; 144 msgState.sourceGroup.sendMessage(msgState.mp); 145 return true; 146 } 147 msgState.usrList = found.toArray(); 148 gul.sendMessage(msgState, "message.k", false); 149 msgState.msgTemplate="message.k.destination.plural"; 150 msgState.targetGroup.exclusiveSendMessage(msgState.mp, found); 151 msgState.msgTemplate="message.k.confirm.plural"; 152 msgState.sender.sendMessage(msgState.mp); 153 return true; 154 } 155 } | Popular Tags |