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.core.GroupManager; 27 import freecs.content.MessageState; 28 29 34 public class CmdSepa extends AbstractCommand { 35 public final String cmd= "/sepa"; 36 private static final ICommand selve=new CmdSepa(); 37 38 private CmdSepa () { } 39 40 public static ICommand getInstance () { 41 return selve; 42 } 43 44 public boolean execute (MessageState msgState, String param) { 45 if (isPunished (msgState)) 46 return false; 47 if (param.length () < 1) { 48 msgState.msgTemplate = "error.sepa.noArg"; 49 msgState.sender.sendMessage (msgState.mp); 50 return false; 51 } 52 int pos = param.indexOf (":"); 53 String joinGroup; 54 String topic = null; 55 if (pos > -1) { 56 joinGroup = param.substring (0,pos).trim(); 57 topic = param.substring (pos+1).trim(); 58 } else { 59 joinGroup = param; 60 } 61 if (joinGroup.length() <1 ) { 62 msgState.msgTemplate="error.sepa.noArg"; 63 msgState.sender.sendMessage (msgState.mp); 64 return false; 65 } 66 if (Server.srv.MAX_GROUPNAME_LENGTH > 0 67 && joinGroup.length() > Server.srv.MAX_GROUPNAME_LENGTH) 68 joinGroup = joinGroup.substring (0,Server.srv.MAX_GROUPNAME_LENGTH); 69 if (joinGroup.equalsIgnoreCase ("exil") || 70 !msgState.sender.hasRight (IUserStates.MAY_OPEN_GROUP)) { 71 msgState.param = joinGroup; 72 msgState.msgTemplate = "error.sepa.noRight"; 73 msgState.sender.sendMessage (msgState.mp); 74 return false; 75 } 76 msgState.sourceGroup = msgState.sender.getGroup (); 77 msgState.targetGroup = GroupManager.mgr.getGroup(joinGroup); 78 if (msgState.sender.getGroup().equals(msgState.targetGroup)) { 79 msgState.msgTemplate = "error.sepa.alreadyHere"; 80 msgState.sender.sendMessage(msgState.mp); 81 return false; 82 } 83 if (msgState.targetGroup != null) { 84 msgState.msgTemplate = "error.sepa.alreadyExists"; 85 msgState.sender.sendMessage(msgState.mp); 86 return false; 87 } 88 msgState.targetGroup = GroupManager.mgr.openGroup (joinGroup, topic, msgState.sender); 89 if (msgState.targetGroup == null) { 90 msgState.param = joinGroup; 91 msgState.msgTemplate = "error.sepa.noRight"; 92 msgState.sender.sendMessage (msgState.mp); 93 return false; 94 } 95 if (!msgState.targetGroup.usrMayLock(msgState.sender)) { 96 msgState.msgTemplate = "message.user.leaving.group"; 97 msgState.sourceGroup.sendMessage(msgState.mp); 98 msgState.msgTemplate = "message.j"; 99 msgState.sender.sendMessage(msgState.mp); 100 msgState.msgTemplate = "error.sepa.l.noRight"; 101 msgState.sender.sendMessage (msgState.mp); 102 return false; 103 } 104 msgState.targetGroup.unsetState(IGroupState.OPEN); 105 msgState.msgTemplate="message.sepa"; 106 msgState.sourceGroup.sendMessage(msgState.mp); 107 msgState.msgTemplate="message.sepa.confirm"; 108 msgState.sender.sendMessage(msgState.mp); 109 return true; 110 } 111 } 112 | Popular Tags |