1 20 21 package freecs.commands; 22 import freecs.Server; 23 import freecs.interfaces.ICommand; 24 import freecs.interfaces.IGroupState; 25 import freecs.interfaces.IUserStates; 26 import freecs.util.GroupUserList; 27 import freecs.core.Group; 28 import freecs.core.User; 29 import freecs.content.MessageState; 30 31 import java.util.Iterator ; 32 import java.util.Vector ; 33 34 39 public class CmdRSu extends AbstractCommand { 40 public final String cmd= "/rsu"; 41 private static final ICommand selve=new CmdRSu(); 42 43 private CmdRSu () { } 44 45 public static ICommand getInstance () { 46 return selve; 47 } 48 49 public boolean execute (MessageState msgState, String param) { 50 if (isPunished (msgState)) return false; 51 if (param.length () < 1) { 52 msgState.msgTemplate = "error.rsu.noArg"; 53 msgState.sender.sendMessage (msgState.mp); 54 return false; 55 } 56 msgState.targetGroup = msgState.sender.getGroup (); 57 Group sg = msgState.sender.getGroup(); 58 if (sg == null) 59 return false; 60 boolean mayChangeRights = msgState.sender.hasRight (IUserStates.MAY_CHANGE_RIGHT); 61 if (!msgState.sender.hasRight(IUserStates.ROLE_VIP) 62 && sg.hasState(IGroupState.ENTRANCE)) { 63 msgState.msgTemplate = "error.noRight.noVipAdmin"; 64 msgState.sender.sendMessage (msgState.mp); 65 return false; 66 } 67 if (!mayChangeRights 68 && !sg.usrIsSu (msgState.sender)) { 69 msgState.msgTemplate = "error.noRight.noSuVipAdmin"; 70 msgState.sender.sendMessage (msgState.mp); 71 return false; 72 } 73 if (param.indexOf(" ") > -1 74 && !msgState.sender.hasRight(IUserStates.ROLE_VIP)) { 75 msgState.msgTemplate="error.mass.noRight.noVipAdmin"; 76 msgState.sender.sendMessage(msgState.mp); 77 return false; 78 } 79 msgState.useRenderCache = false; 80 GroupUserList gul = new GroupUserList(); 81 Vector found = getMultibleUsers(msgState, param); 82 for (Iterator i = found.iterator(); i.hasNext(); ) { 83 User cu = (User) i.next(); 84 if (!cu.getGroup().usrIsSu(cu)) { 85 i.remove(); 86 continue; 87 } 88 msgState.usrList = null; 89 if (setSuRight (msgState, cu, false)) { 90 msgState.usercontext = cu; 91 gul.addUser(cu); 92 if (found.size() > 1) { 93 msgState.msgTemplate="message.rsu.personal"; 94 cu.sendMessage(msgState.mp); 95 } 96 StringBuffer sb = new StringBuffer (); 97 sb.append (msgState.sender.getName()); 98 sb.append (" took su-rights from user "); 99 sb.append (cu.getName()); 100 sb.append (" in group "); 101 sb.append (cu.getGroup().getRawName()); 102 Server.log (this, sb.toString(), Server.MSG_STATE, Server.LVL_MINOR); 103 } else if (!msgState.sender.hasRight(IUserStates.ROLE_VIP)) { 104 if (sg.hasState (IGroupState.ENTRANCE)) { 105 msgState.msgTemplate = "error.noRight.noVipAdmin"; 106 msgState.sender.sendMessage (msgState.mp); 107 } else { 108 msgState.msgTemplate = "error.noRight.noSuVipAdmin"; 109 msgState.sender.sendMessage (msgState.mp); 110 } 111 i.remove(); 112 } else if (msgState.usrList != null) { msgState.targetGroup = cu.getGroup(); 114 if (msgState.usrList.length > 1) 115 msgState.msgTemplate = "error.membership.notMember.many"; 116 else 117 msgState.msgTemplate = "error.membership.notMember"; 118 msgState.usercontext=cu; 119 msgState.sender.sendMessage(msgState.mp); 120 i.remove(); 121 continue; 122 } 123 } 124 if (found.size() == 0) 125 return false; 126 if (found.size() == 1) { 127 msgState.msgTemplate = "message.rsu.singular"; 128 msgState.usercontext = (User) found.get(0); 129 msgState.usercontext.getGroup().sendMessage(msgState.mp); 130 if (!msgState.sender.getGroup().equals(msgState.usercontext.getGroup())) { 131 msgState.msgTemplate = "message.rsu.confirm.singular"; 132 msgState.sender.sendMessage(msgState.mp); 133 } 134 return true; 135 } 136 msgState.msgTemplate = "message.rsu.confirm.plural"; 137 msgState.usrList = found.toArray(); 138 msgState.sender.sendMessage(msgState.mp); 139 gul.sendMessage(msgState, "message.rsu", false); 140 return true; 141 } 142 143 public String toString() { 144 return "[CmdRSu]"; 145 } 146 } 147 | Popular Tags |