]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/ChannelInterpretor.java
Pjirc 2.2.1 as available on the net, reformatted and made it compile.
[irc/pjirc-ng.git] / src / main / java / irc / ChannelInterpretor.java
1 /*****************************************************/\r
2 /*          This java file is a part of the          */\r
3 /*                                                   */\r
4 /*           -  Plouf's Java IRC Client  -           */\r
5 /*                                                   */\r
6 /*   Copyright (C)  2002 - 2004 Philippe Detournay   */\r
7 /*                                                   */\r
8 /*         All contacts : theplouf@yahoo.com         */\r
9 /*                                                   */\r
10 /*  PJIRC is free software; you can redistribute     */\r
11 /*  it and/or modify it under the terms of the GNU   */\r
12 /*  General Public License as published by the       */\r
13 /*  Free Software Foundation; version 2 or later of  */\r
14 /*  the License.                                     */\r
15 /*                                                   */\r
16 /*  PJIRC is distributed in the hope that it will    */\r
17 /*  be useful, but WITHOUT ANY WARRANTY; without     */\r
18 /*  even the implied warranty of MERCHANTABILITY or  */\r
19 /*  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   */\r
20 /*  General Public License for more details.         */\r
21 /*                                                   */\r
22 /*  You should have received a copy of the GNU       */\r
23 /*  General Public License along with PJIRC; if      */\r
24 /*  not, write to the Free Software Foundation,      */\r
25 /*  Inc., 59 Temple Place, Suite 330, Boston,        */\r
26 /*  MA  02111-1307  USA                              */\r
27 /*                                                   */\r
28 /*****************************************************/\r
29 \r
30 package irc;\r
31 \r
32 /**\r
33  * Channel interpretor.\r
34  */\r
35 public class ChannelInterpretor extends IRCInterpretor {\r
36         /**\r
37          * Create a new ChannelInterpretor.\r
38          * \r
39          * @param config\r
40          *          global configuration.\r
41          */\r
42         public ChannelInterpretor(IRCConfiguration config) {\r
43                 super(config);\r
44         }\r
45 \r
46         private boolean isChannel(String name, Source source) {\r
47                 if (name.length() == 0)\r
48                         return false;\r
49                 Server s = source.getServer();\r
50                 if (s instanceof IRCServer) {\r
51                         char[] prefixes = ((IRCServer) s).getChannelPrefixes();\r
52                         for (int i = 0; i < prefixes.length; i++)\r
53                                 if (name.charAt(0) == prefixes[i])\r
54                                         return true;\r
55                 }\r
56                 return false;\r
57         }\r
58 \r
59         @Override\r
60         protected void handleCommand(Source source, String cmd, String[] parts, String[] cumul) {\r
61                 try {\r
62                         if (cmd.equals("part")) {\r
63                                 if (parts.length == 1) {\r
64                                         sendString(source, "/part " + source.getName());\r
65                                 } else {\r
66                                         if (isChannel(parts[1], source))\r
67                                                 super.handleCommand(source, cmd, parts, cumul);\r
68                                         else\r
69                                                 sendString(source, "/part " + source.getName() + " " + cumul[1]);\r
70                                 }\r
71                         } else if (cmd.equals("hop")) {\r
72                                 sendString(source, "/part");\r
73                                 sendString(source, "/join " + source.getName());\r
74                         } else if (cmd.equals("onotice")) {\r
75                                 test(cmd, parts, 1);\r
76                                 if (isChannel(parts[1], source))\r
77                                         super.handleCommand(source, cmd, parts, cumul);\r
78                                 else\r
79                                         sendString(source, "/onotice " + source.getName() + " " + cumul[1]);\r
80                         } else {\r
81                                 super.handleCommand(source, cmd, parts, cumul);\r
82                         }\r
83                 } catch (NotEnoughParametersException ex) {\r
84                         source.report(getText(IRCTextProvider.INTERPRETOR_INSUFFICIENT_PARAMETERS, ex.getMessage()));\r
85                 }\r
86 \r
87         }\r
88 }\r