1 20 21 package freecs.commands; 22 import java.util.Vector ; 23 24 import freecs.interfaces.ICommand; 25 import freecs.interfaces.IGroupState; 26 import freecs.content.MessageState; 27 import freecs.core.GroupManager; 28 import freecs.core.User; 29 import freecs.core.UserManager; 30 import freecs.interfaces.IUserStates; 31 32 37 public class CmdUnBan extends AbstractCommand { 38 public final String cmd= "/uban"; 39 private static final ICommand selve=new CmdUnBan(); 40 41 private CmdUnBan () { } 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 String parts[] = param.split (":"); 51 param = parts[0]; 52 msgState.targetGroup = null; 53 if (parts.length > 1) { 54 msgState.targetGroup = GroupManager.mgr.getGroup (parts[1]); 55 if (!msgState.sender.hasRight(IUserStates.ROLE_VIP) 56 && !msgState.sender.getGroup().equals(msgState.targetGroup)) { 57 msgState.msgTemplate="error.noRight.noVipAdmin"; 58 msgState.sender.sendMessage(msgState.mp); 59 return false; 60 } 61 if (msgState.targetGroup==null) { 62 msgState.param = parts[1]; 63 msgState.msgTemplate="error.group.notExisting"; 64 msgState.sender.sendMessage(msgState.mp); 65 return false; 66 } 67 } else 68 msgState.targetGroup = msgState.sender.getGroup (); 69 70 if (!msgState.sender.hasRight(IUserStates.ROLE_VIP)) { 71 if (msgState.targetGroup.hasState(IGroupState.ENTRANCE)) { 72 msgState.msgTemplate = "error.noRight.noVipAdmin"; 73 msgState.sender.sendMessage (msgState.mp); 74 return false; 75 } else if (!msgState.targetGroup.usrIsSu(msgState.sender)) { 76 msgState.msgTemplate="error.noRight.noSuVipAdmin"; 77 msgState.sender.sendMessage(msgState.mp); 78 return false; 79 } 80 } else if (!isVip(msgState.sender, msgState.targetGroup, msgState)) { 81 if (msgState.usrList.length > 1) 82 msgState.msgTemplate = "error.membership.notMember.many"; 83 else 84 msgState.msgTemplate = "error.membership.notMember"; 85 msgState.usercontext=null; 86 msgState.sender.sendMessage(msgState.mp); 87 return false; 88 } 89 90 if (param != null && param.indexOf(" ") > 1 91 && !msgState.sender.hasRight (IUserStates.ROLE_VIP)) { 92 msgState.msgTemplate = "error.mass.noRight.noVipAdmin"; 93 msgState.sender.sendMessage (msgState.mp); 94 return false; 95 } else if (param == null || param.length () < 1) { 96 msgState.msgTemplate = "error.uban.noArg"; 97 msgState.sender.sendMessage (msgState.mp); 98 return false; 99 } 100 msgState.useRenderCache=false; 101 String users[] = param.split (" "); 102 Vector found = new Vector (); 103 Vector notfound = new Vector (); 104 for (int i = 0; i < users.length; i++) { 105 Object o = UserManager.mgr.getUserByName(users[i]); 106 if (o == null) 107 o = users[i]; 108 if (!msgState.targetGroup.usrIsBaned(users[i])) { 109 notfound.add(o); 110 } else { 111 found.add(o); 112 if (o instanceof User) { 113 msgState.usercontext = (User) o; 114 msgState.targetGroup.setBanForUser (msgState.usercontext.getName(), false); 115 msgState.msgTemplate = "message.uban.personal"; 116 msgState.usercontext.sendMessage (msgState.mp); 117 } else { 118 msgState.targetGroup.setBanForUser((String ) o, false); 119 } 120 } 121 } 122 if (notfound.size() == 1) { 123 msgState.msgTemplate = "error.uban.notOnList.singular"; 124 Object o = notfound.get(0); 125 if (o instanceof User) { 126 msgState.usercontext = (User) o; 127 msgState.param = null; 128 } else { 129 msgState.usercontext = null; 130 msgState.param = (String ) o; 131 } 132 msgState.sender.sendMessage(msgState.mp); 133 } else if (notfound.size() > 1) { 134 msgState.msgTemplate = "error.uban.notOnList.plural"; 135 msgState.usrList = notfound.toArray(); 136 msgState.sender.sendMessage (msgState.mp); 137 } 138 if (found.size() == 1) { 139 Object o = found.get(0); 140 if (o instanceof User) { 141 msgState.usercontext = (User) o; 142 msgState.param = ""; 143 } else { 144 msgState.usercontext = null; 145 msgState.param = (String ) o; 146 } 147 if (!msgState.sender.getGroup().equals(msgState.targetGroup)) { 148 msgState.msgTemplate = "message.uban.confirm.singular"; 149 msgState.sender.sendMessage(msgState.mp); 150 } 151 msgState.msgTemplate = "message.uban.singular"; 152 msgState.targetGroup.sendModeratedMessage(msgState.mp); 153 return true; 154 } else if (found.size() > 1) { 155 msgState.usrList = found.toArray(); 156 if (!msgState.sender.getGroup().equals(msgState.targetGroup)) { 157 msgState.msgTemplate = "message.uban.confirm.plural"; 158 msgState.sender.sendMessage (msgState.mp); 159 } 160 msgState.msgTemplate = "message.uban.plural"; 161 msgState.usrList = found.toArray(); 162 msgState.targetGroup.sendModeratedMessage(msgState.mp); 163 return true; 164 } 165 return false; 166 } 167 } 168 | Popular Tags |