]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/DefaultInterpretor.java
Pjirc 2.2.1 as available on the net, reformatted and made it compile.
[irc/pjirc-ng.git] / src / main / java / irc / DefaultInterpretor.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  * A default interpretor.\r
34  */\r
35 public class DefaultInterpretor extends BasicInterpretor {\r
36         private StartupConfiguration _start;\r
37         private ServerManager _mgr;\r
38         private PluginManager _plugin;\r
39 \r
40         /**\r
41          * Create a new DefaultInterpretor.\r
42          * \r
43          * @param config\r
44          *          global irc configuration.\r
45          * @param start\r
46          *          statup configuration.\r
47          * @param mgr\r
48          *          the server manager to be called upon server creation.\r
49          * @param plugin\r
50          *          the plugin manager.\r
51          */\r
52         public DefaultInterpretor(IRCConfiguration config, StartupConfiguration start, ServerManager mgr, PluginManager plugin) {\r
53                 super(config);\r
54                 _start = start;\r
55                 _mgr = mgr;\r
56                 _plugin = plugin;\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("newserver")) {\r
63                                 if (_ircConfiguration.getB("multiserver")) {\r
64                                         test(cmd, parts, 2);\r
65                                         int port = 6667;\r
66                                         String pass = "";\r
67                                         String alias = parts[1];\r
68                                         if (parts.length > 3)\r
69                                                 port = new Integer(parts[3]).intValue();\r
70                                         if (parts.length > 4)\r
71                                                 pass = parts[4];\r
72                                         String host = parts[2];\r
73 \r
74                                         IRCServer server = new IRCServer(_ircConfiguration, _mgr, _start.getNick(), _start.getAltNick(),\r
75                                                         _start.getName(), alias);\r
76                                         server.setServers(new String[] { host }, new int[] { port }, new String[] { pass });\r
77                                         _mgr.newServer(server, true);\r
78                                 } else {\r
79                                         source.report(getText(IRCTextProvider.INTERPRETOR_MULTISERVER_DISABLED));\r
80                                 }\r
81                         } else if (cmd.equals("load")) {\r
82                                 test(cmd, parts, 1);\r
83                                 _plugin.loadPlugin(parts[1]);\r
84                         } else if (cmd.equals("unload")) {\r
85                                 test(cmd, parts, 1);\r
86                                 _plugin.unloadPlugin(parts[1]);\r
87                         } else {\r
88                                 super.handleCommand(source, cmd, parts, cumul);\r
89                         }\r
90                 } catch (NotEnoughParametersException ex) {\r
91                         source.report(getText(IRCTextProvider.INTERPRETOR_INSUFFICIENT_PARAMETERS, ex.getMessage()));\r
92                 }\r
93         }\r
94 }\r