1 20 21 package freecs.commands; 22 23 import java.util.Iterator ; 24 import java.util.Vector ; 25 26 import freecs.content.MessageState; 27 import freecs.core.Group; 28 import freecs.core.ScheduledAction; 29 import freecs.core.User; 30 import freecs.core.UserManager; 31 import freecs.interfaces.ICommand; 32 import freecs.interfaces.IUserStates; 33 import freecs.util.GroupUserList; 34 35 40 public class CmdPunish extends AbstractCommand { 41 public final String cmd= "/gag"; 42 private static final ICommand selve=new CmdPunish(); 43 44 private CmdPunish () { } 45 46 public static ICommand getInstance () { 47 return selve; 48 } 49 50 public boolean execute (MessageState msgState, String param) { 51 if (isPunished (msgState)) 52 return false; 53 boolean mayPunish = msgState.sender.hasRight (IUserStates.MAY_PUNISH); 54 Group sg = msgState.sender.getGroup (); 55 boolean isSu = sg.usrIsSu (msgState.sender); 56 if (!mayPunish && !isSu) { 57 msgState.msgTemplate = "error.noRight.noSuVipAdmin"; 58 msgState.sender.sendMessage (msgState.mp); 59 return false; 60 } 61 if (param.length () < 1) { 62 msgState.msgTemplate = "error.gag.noArg"; 63 msgState.sender.sendMessage (msgState.mp); 64 return false; 65 } 66 int pos = param.indexOf(":"); 67 if (pos != -1) { 68 msgState.reason = param.substring (pos+1); 69 param = param.substring (0, pos); 70 } else 71 msgState.reason = ""; 72 73 if (param.indexOf(" ") > -1 74 && !mayPunish) { 75 msgState.msgTemplate = "error.mass.noRight.noVipAdmin"; 76 msgState.sender.sendMessage (msgState.mp); 77 return false; 78 } 79 80 pos = param.lastIndexOf(" "); 83 long secs = -1; 84 if (pos > -1) try { 85 secs = Long.parseLong (param.substring (pos+1), 10); 86 param = param.substring (0, pos); 87 } catch (NumberFormatException nfe) { 88 } 90 GroupUserList gul = new GroupUserList(); 91 Vector found = getMultibleUsers(msgState, param); 92 msgState.useRenderCache = false; 93 for (Iterator i = found.iterator(); i.hasNext (); ) { 94 User cu = (User) i.next(); 95 if (cu.equals(msgState.sender)) { 96 i.remove(); 97 continue; 98 } 99 if (!mayPunish 100 && !msgState.sender.getGroup().equals(cu.getGroup())) { 101 msgState.msgTemplate = "error.noRight.noVipAdmin"; 102 User u = msgState.usercontext; 103 msgState.usercontext = cu; 104 msgState.sender.sendMessage (msgState.mp); 105 msgState.usercontext = u; 106 i.remove(); 107 continue; 108 } 109 114 115 boolean p = true; 116 if ((p && msgState.sender.isPunished()) 117 || cu == null || cu.isPunished () == p) 118 return false; 119 if (!cu.hasRight(IUserStates.FREELY_PUNISHABLE)) { 120 if (cu.hasRight(IUserStates.ROLE_GOD)) { 121 msgState.msgTemplate = "error.noRight.isAdmin"; 122 msgState.usercontext = cu; 123 msgState.sender.sendMessage (msgState.mp); 124 i.remove(); 125 continue; 126 } 127 if (cu.hasRight(IUserStates.ROLE_VIP) 128 && !msgState.sender.hasRight(IUserStates.ROLE_VIP)) { 129 msgState.msgTemplate = "error.noRight.isVip"; 130 msgState.usercontext = cu; 131 msgState.sender.sendMessage (msgState.mp); 132 i.remove(); 133 continue; 134 } 135 if (cu.hasRight (IUserStates.PROTECTED_FROM_PUNISH) 136 && !msgState.sender.hasRight(IUserStates.ROLE_GOD)) { 137 msgState.msgTemplate = "error.gag.protected"; 138 msgState.usercontext = cu; 139 msgState.sender.sendMessage (msgState.mp); 140 i.remove(); 141 continue; 142 } 143 } 144 cu.setPunish (p); 145 if (found.size() > 1) { 146 msgState.msgTemplate= "message.gag.personal"; 147 cu.sendMessage (msgState.mp); 148 } 149 gul.addUser(cu); 150 msgState.usercontext = cu; 151 if (secs > 0) { 152 long millsecs = secs * 1000 + System.currentTimeMillis(); 153 UserManager.mgr.scheduleAction(ScheduledAction.UNPUNISH, millsecs, cu, msgState.sender); 154 } 155 } 156 if (found.size()==0) 157 return false; 158 if (found.size()==1) { 159 msgState.msgTemplate="message.gag.singular"; 160 if (msgState.usercontext.getGroup() != null) 161 msgState.usercontext.getGroup().sendMessage(msgState.mp); 162 if (!msgState.sender.getGroup().equals(msgState.usercontext.getGroup())) { 163 msgState.msgTemplate="message.gag.confirm.singular"; 164 msgState.sender.sendMessage(msgState.mp); 165 } 166 return true; 167 } 168 msgState.msgTemplate="message.gag.confirm.plural"; 169 msgState.usrList = found.toArray(); 170 msgState.sender.sendMessage (msgState.mp); 171 gul.sendMessage(msgState, "message.gag", false); 172 return true; 173 } 174 } 175 | Popular Tags |