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 CmdJoinClosed extends AbstractCommand { 35 public final String cmd= "/jclosed"; 36 private static final ICommand selve=new CmdJoinClosed(); 37 38 private CmdJoinClosed () { } 39 40 public static ICommand getInstance () { 41 return selve; 42 } 43 44 public boolean execute (MessageState msgState, String param) { 45 if (!msgState.sender.hasRight(IUserStates.MAY_JOIN_LOCKED_GROUP)) { 46 msgState.msgTemplate="error.noRight.noAdmin"; 47 msgState.sender.sendMessage (msgState.mp); 48 return false; 49 } 50 if (param.length () < 1) { 51 msgState.msgTemplate="error.j.noArg"; 52 msgState.sender.sendMessage (msgState.mp); 53 return false; 54 } 55 msgState.sourceGroup=msgState.sender.getGroup(); 56 String groupname; 57 String topic = null; 58 int pos = param.indexOf (":"); 59 if (pos > -1) { topic = param.substring (pos+1).trim (); 61 groupname = param.substring (0, pos).trim (); 62 } else { 63 groupname = param; 64 } 65 if (groupname.length() <1 ) { 66 msgState.msgTemplate="error.j.noArg"; 67 msgState.sender.sendMessage (msgState.mp); 68 return false; 69 } 70 if (Server.srv.MAX_GROUPNAME_LENGTH > 0 71 && groupname.length() > Server.srv.MAX_GROUPNAME_LENGTH) 72 groupname = groupname.substring (0,Server.srv.MAX_GROUPNAME_LENGTH); 73 if (msgState.sourceGroup.getRawName ().equalsIgnoreCase (groupname)) { 74 msgState.targetGroup=msgState.sourceGroup; 75 msgState.msgTemplate="error.j.alreadyHere"; 76 msgState.sender.sendMessage (msgState.mp); 77 return false; 78 } 79 msgState.sourceGroup = msgState.sender.getGroup (); 80 boolean senderWasSu = msgState.sourceGroup.usrIsSu(msgState.sender); 81 msgState.targetGroup = GroupManager.mgr.getGroup (groupname); 82 if (msgState.targetGroup==null) { 83 msgState.param = groupname; 84 msgState.msgTemplate="error.jclosed.groupNotExisting"; 85 msgState.sender.sendMessage(msgState.mp); 86 return false; 87 } 88 if (!msgState.targetGroup.hasState(IGroupState.ENTRANCE) 89 && isPunished (msgState)) 90 return false; 91 if (msgState.sender.isPunished()) { 92 if (msgState.targetGroup != null && msgState.targetGroup.usrMayJoinPunished(msgState.sender)){ 93 msgState.targetGroup.incrementJoinPunishedCounter(); 94 } else { 95 msgState.msgTemplate = "error.user.punished"; 96 msgState.sender.sendMessage(msgState.mp); 97 return false; 98 } 99 } 100 if (!msgState.sender.isPunished()) 101 msgState.sourceGroup.resetJoinPunishedCounter(); 102 if (msgState.targetGroup.usrIsBaned (msgState.sender.getName())) { 103 msgState.msgTemplate = "error.j.banned"; 104 msgState.sender.sendMessage (msgState.mp); 105 return false; 106 } 107 if (!msgState.targetGroup.usrMayJoin(msgState.sender)) { 108 msgState.msgTemplate = "error.j.noRight"; 109 msgState.sender.sendMessage (msgState.mp); 110 return false; 111 } 112 Server.log(this, msgState.sender.getName() 113 + " joines closed group" 114 + msgState.targetGroup.getRawName(), Server.MSG_STATE, Server.LVL_MINOR); 115 msgState.msgTemplate = "message.user.join.closedGroup"; 116 msgState.targetGroup.sendMessage (msgState.mp); 117 msgState.targetGroup.addUser (msgState.sender); 118 if (msgState.sourceGroup.size() > 0) { 119 msgState.msgTemplate = "message.user.leaving.group"; 120 msgState.sourceGroup.sendMessage (msgState.mp); 121 } 122 msgState.msgTemplate = "message.jclosed"; 123 msgState.sender.sendMessage (msgState.mp); 124 return true; 125 } 126 } | Popular Tags |