KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freecs > commands > CmdShowIp


1 /**
2  * Copyright (C) 2003 Manfred Andres
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  * Created on 28.09.2003
19  */

20
21 package freecs.commands;
22 import java.util.Iterator JavaDoc;
23 import java.util.Vector JavaDoc;
24
25 import freecs.Server;
26 import freecs.interfaces.*;
27 import freecs.content.MessageState;
28 import freecs.core.User;
29
30 /**
31  * @author Manfred Andres
32  *
33  * freecs.commandset
34  */

35 public class CmdShowIp extends AbstractCommand {
36     public final String JavaDoc cmd= "/ip";
37     private static final ICommand selve=new CmdShowIp();
38
39     private CmdShowIp () { }
40     
41     public static ICommand getInstance () {
42         return selve;
43     }
44     
45     public boolean execute (MessageState msgState, String JavaDoc param) {
46         if (isPunished(msgState))
47             return false;
48         if (!msgState.sender.hasRight(IUserStates.ROLE_VIP)) {
49             msgState.msgTemplate = "error.noRight.noVipAdmin";
50             msgState.sender.sendMessage(msgState.mp);
51             return false;
52         }
53         if (param.length() < 1) {
54             msgState.msgTemplate = "error.ip.noArg";
55             msgState.sender.sendMessage(msgState.mp);
56             return false;
57         }
58         Vector JavaDoc found = getMultibleUsers(msgState, param);
59         msgState.useRenderCache=false;
60         msgState.msgTemplate="message.ip";
61         for (Iterator JavaDoc i = found.iterator(); i.hasNext(); ) {
62             User cu = (User) i.next();
63             msgState.usercontext = cu;
64             msgState.sender.sendMessage(msgState.mp);
65             if (Server.checkLogLvl(Server.MSG_STATE, Server.LVL_MINOR)) {
66                 StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
67                 sb.append("User ");
68                 sb.append(msgState.sender.getName());
69                 sb.append(" has queried the IP-Address of User ");
70                 sb.append(cu.getName());
71                 Server.log (this, sb.toString(), Server.MSG_STATE, Server.LVL_MINOR);
72             }
73         }
74         return true;
75     }
76     
77     public String JavaDoc toString() {
78         return "[CmdShowIp]";
79     }
80 }
81
Popular Tags