1 20 21 package freecs.commands; 22 import java.nio.ByteBuffer ; 23 24 import freecs.interfaces.ICommand; 25 import freecs.core.Group; 26 import freecs.core.GroupManager; 27 import freecs.core.MessageRenderer; 28 import freecs.core.UserManager; 29 import freecs.content.MessageState; 30 import freecs.content.PersonalizedMessage; 31 32 37 public class CmdListUsers extends AbstractCommand { 38 public final String cmd= "/wc"; 39 private static final ICommand selve=new CmdListUsers(); 40 41 private CmdListUsers () { } 42 43 public static ICommand getInstance () { 44 return selve; 45 } 46 47 public boolean execute (MessageState msgState, String param) { 48 if (param == null || param.length () < 1) { 49 msgState.useRenderCache = false; 50 if ("false".equals(msgState.sender.getTemplateSet().getMessageTemplate("status.wc.renderUserlist"))) 51 return true; 52 StringBuffer sb = new StringBuffer (); 53 Group[] grps = GroupManager.mgr.currentGroupList(); 54 for (int i = 0; i < grps.length; i++) { 55 Group g = grps[i]; 56 if (!g.isValid()) { 57 GroupManager.mgr.removeGroup(g); 58 continue; 59 } 60 msgState.sourceGroup=g; 61 msgState.targetGroup=g; 62 sb.append (getUserList (msgState, true)); 63 } 64 ByteBuffer bb = MessageRenderer.encode(sb.toString()); 65 if (bb==null) 66 return false; 67 msgState.msgTemplate = "message.wc.headline"; 68 msgState.sender.sendMessage (msgState.mp); 69 msgState.sender.sendMessage(new PersonalizedMessage(bb)); 70 msgState.msgTemplate = "message.wc.underline"; 71 msgState.param = String.valueOf (UserManager.mgr.getActiveUserCount()); 72 msgState.reason = String.valueOf (GroupManager.mgr.openGroupsCount()); 73 msgState.sender.sendMessage (msgState.mp); 74 } else { 75 Group g = GroupManager.mgr.getGroup (param); 76 if (g == null) { 77 msgState.msgTemplate = "error.group.notExisting"; 78 msgState.param = param; 79 msgState.sender.sendMessage (msgState.mp); 80 } else { 81 msgState.sourceGroup = g; 82 sendUserList (msgState, false); 83 } 84 } 85 return true; 86 } 87 } 88 | Popular Tags |