1 20 21 package freecs.commands; 22 import freecs.Server; 23 import freecs.interfaces.ICommand; 24 import freecs.interfaces.IGroupState; 25 import freecs.core.GroupManager; 26 import freecs.content.MessageState; 27 28 33 public class CmdJoin extends AbstractCommand { 34 public final String cmd= "/j"; 35 private static final ICommand selve=new CmdJoin(); 36 37 private CmdJoin () { } 38 39 public static ICommand getInstance () { 40 return selve; 41 } 42 43 public boolean execute (MessageState msgState, String param) { 44 if (param.length () < 1) { 45 msgState.msgTemplate="error.j.noArg"; 46 msgState.sender.sendMessage (msgState.mp); 47 return false; 48 } 49 msgState.sourceGroup=msgState.sender.getGroup(); 50 String groupname; 51 String topic = null; 52 int pos = param.indexOf (":"); 53 if (pos > -1) { topic = param.substring (pos+1).trim (); 55 groupname = param.substring (0, pos).trim (); 56 } else { 57 groupname = param; 58 } 59 if (groupname.length() <1 ) { 60 msgState.msgTemplate="error.j.noArg"; 61 msgState.sender.sendMessage (msgState.mp); 62 return false; 63 } 64 if (Server.srv.MAX_GROUPNAME_LENGTH > 0 65 && groupname.length() > Server.srv.MAX_GROUPNAME_LENGTH) 66 groupname = groupname.substring (0,Server.srv.MAX_GROUPNAME_LENGTH); 67 if (msgState.sourceGroup.getRawName ().equalsIgnoreCase (groupname)) { 68 msgState.targetGroup=msgState.sourceGroup; 69 msgState.msgTemplate="error.j.alreadyHere"; 70 msgState.sender.sendMessage (msgState.mp); 71 return false; 72 } 73 msgState.sourceGroup = msgState.sender.getGroup (); 74 boolean senderWasSu = msgState.sourceGroup.usrIsSu(msgState.sender); 75 msgState.targetGroup = GroupManager.mgr.getGroup (groupname); 76 if (!GroupManager.mgr.isStartingGroup(groupname) 77 && isPunished (msgState)) 78 return false; 79 80 if (msgState.sender.isPunished() ) { 81 if (msgState.targetGroup != null && msgState.targetGroup.usrMayJoinPunished(msgState.sender)){ 82 msgState.targetGroup.incrementJoinPunishedCounter(); 83 } else { 84 msgState.msgTemplate = "error.user.punished"; 85 msgState.sender.sendMessage(msgState.mp); 86 return false; 87 } 88 } 89 if (!msgState.sender.isPunished()) 90 msgState.sourceGroup.resetJoinPunishedCounter(); 91 if (msgState.targetGroup != null 92 && msgState.targetGroup.usrIsBaned (msgState.sender.getName())) { 93 msgState.msgTemplate = "error.j.banned"; 94 msgState.sender.sendMessage (msgState.mp); 95 return false; 96 } 97 boolean created = false; 98 if (msgState.targetGroup == null) { 99 msgState.targetGroup = GroupManager.mgr.openGroup (groupname, topic, msgState.sender); 100 if (msgState.targetGroup == null) { 101 msgState.param = groupname; 102 msgState.msgTemplate = "error.j.noRightToOpen"; 103 msgState.sender.sendMessage (msgState.mp); 104 return false; 105 } 106 created=true; 107 } else if (!msgState.targetGroup.hasState(IGroupState.OPEN)) { 108 msgState.msgTemplate = "error.j.closed"; 109 msgState.sender.sendMessage (msgState.mp); 110 return false; 111 } else if (!msgState.targetGroup.usrMayJoin(msgState.sender)) { 112 msgState.msgTemplate = "error.j.noRight"; 113 msgState.sender.sendMessage (msgState.mp); 114 return false; 115 } 116 if (!created) { 117 msgState.msgTemplate = "message.user.join.group"; 118 msgState.targetGroup.sendMessage (msgState.mp); 119 msgState.targetGroup.addUser (msgState.sender); 120 msgState.msgTemplate = "message.j"; 121 msgState.sender.sendMessage (msgState.mp); 122 } else { 123 msgState.msgTemplate = "message.j.created"; 124 msgState.sender.sendMessage(msgState.mp); 125 } 126 if (msgState.sourceGroup.size() > 0) { 127 msgState.msgTemplate = "message.user.leaving.group"; 128 msgState.sourceGroup.sendMessage (msgState.mp); 129 } 130 return true; 131 } 132 } 133 | Popular Tags |