1 20 21 package freecs.commands; 22 import java.util.Iterator ; 23 import java.util.Vector ; 24 25 import freecs.interfaces.ICommand; 26 import freecs.interfaces.IUserStates; 27 import freecs.util.GroupUserList; 28 import freecs.core.User; 29 import freecs.content.MessageState; 30 import freecs.Server; 31 32 37 public class CmdKickHard extends AbstractCommand { 38 public final String cmd= "/kh"; 39 private static final ICommand selve=new CmdKickHard(); 40 41 private CmdKickHard () { } 42 43 public static ICommand getInstance () { 44 return selve; 45 } 46 47 public boolean execute (MessageState msgState, String param) { 48 if (isPunished (msgState)) 49 return false; 50 if (!msgState.sender.hasRight(IUserStates.MAY_KICK_HARD)) { 51 msgState.msgTemplate = "error.noRight.noVipAdmin"; 52 msgState.sender.sendMessage(msgState.mp); 53 return false; 54 } 55 int pos1 = param.indexOf (" "); 56 int pos2 = param.indexOf (":"); 57 if ((pos1!=-1 && (pos2 > pos1+1 || pos2==-1)) 58 && !msgState.sender.hasRight(IUserStates.ROLE_VIP)) { 59 msgState.msgTemplate="error.mass.noRight.noVipAdmin"; 60 msgState.sender.sendMessage (msgState.mp); 61 return false; 62 } 63 if (pos2 > 0) { 64 msgState.reason = param.substring(pos2+1); 65 msgState.message = param.substring(pos2+1); 66 param = param.substring(0,pos2).trim(); 67 } 68 long time = Server.srv.DEFAULT_BAN_DURATION; 69 pos1 = param.trim().lastIndexOf(" "); 70 if (pos1 != -1) { 71 String timeStrg = param.substring(pos1).trim(); 72 long customTime=-1; 73 try { 74 customTime = Long.parseLong(timeStrg,10); 75 time = customTime; 76 param = param.substring(0,pos1).trim(); 77 } catch (NumberFormatException nfe) { 78 79 } 80 } 81 if (time > Server.srv.MAX_BAN_DURATION) 82 time = Server.srv.MAX_BAN_DURATION; 83 time = time * 60 * 1000; 84 85 Vector found = getMultibleUsers(msgState, param); 86 GroupUserList gul = new GroupUserList(); 87 msgState.useRenderCache=false; 88 for (Iterator i = found.iterator(); i.hasNext(); ) { 89 User cu = (User) i.next(); 90 if (cu.hasRole(IUserStates.ROLE_GOD)) { 91 msgState.usercontext= cu; 92 msgState.msgTemplate = "error.noRight.isAdmin"; 93 msgState.sender.sendMessage(msgState.mp); 94 msgState.msgTemplate = "message.kh.godinfo"; 95 cu.sendMessage(msgState.mp); 96 i.remove(); 97 continue; 98 } else if (cu.hasRight(IUserStates.PROTECTED_FROM_KICK) 99 && !msgState.sender.hasRole(IUserStates.ROLE_GOD)) { 100 msgState.usercontext= cu; 101 msgState.msgTemplate = "error.noRight.isVip"; 102 msgState.sender.sendMessage(msgState.mp); 103 i.remove(); 104 continue; 105 } else if (!msgState.sender.hasRight(IUserStates.ROLE_GOD) 106 && !isVip (msgState.sender, cu.getGroup(), msgState)) { 107 msgState.targetGroup = cu.getGroup(); 108 if (msgState.usrList.length > 1) 109 msgState.msgTemplate = "error.membership.notMember.many"; 110 else 111 msgState.msgTemplate = "error.membership.notMember"; 112 msgState.usercontext=cu; 113 msgState.sender.sendMessage(msgState.mp); 114 i.remove(); 115 continue; 116 } 117 msgState.sourceGroup=cu.getGroup(); 118 gul.addUser(cu); 119 } 120 if (found.size()==0) 121 return false; 122 if (found.size()==1) { 123 msgState.msgTemplate="message.kh.singular"; 124 msgState.usercontext=(User) found.get(0); 125 if (msgState.sourceGroup != null) 126 msgState.sourceGroup.sendMessage(msgState.mp); 127 Server.srv.banUser (found, msgState.reason, time, msgState.sender.getName()); 128 if (!msgState.sender.getGroup().equals (msgState.sourceGroup)) { 129 msgState.msgTemplate = "message.kh.confirm.singular"; 130 msgState.sender.sendMessage(msgState.mp); 131 } 132 return true; 133 } 134 msgState.usrList = found.toArray(); 135 gul.sendMessage(msgState, "message.kh", false); 136 Server.srv.banUser (found, msgState.reason, time, msgState.sender.getName()); 137 msgState.msgTemplate = "message.kh.confirm.plural"; 138 msgState.sender.sendMessage(msgState.mp); 139 return true; 140 } 141 } 142 | Popular Tags |