File Source: IdentdPlugin.java
/*
P/P * Method: com.dmdirc.addons.identd.IdentdPlugin__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.addons.identd;
24
25 import com.dmdirc.Server;
26 import com.dmdirc.actions.ActionManager;
27 import com.dmdirc.actions.CoreActionType;
28 import com.dmdirc.actions.interfaces.ActionType;
29 import com.dmdirc.config.IdentityManager;
30 import com.dmdirc.config.prefs.PreferencesCategory;
31 import com.dmdirc.config.prefs.PreferencesManager;
32 import com.dmdirc.config.prefs.PreferencesSetting;
33 import com.dmdirc.config.prefs.PreferencesType;
34 import com.dmdirc.config.prefs.validator.PortValidator;
35 import com.dmdirc.interfaces.ActionListener;
36 import com.dmdirc.plugins.Plugin;
37
38 import java.util.ArrayList;
39 import java.util.List;
40
41 /**
42 * The Identd plugin answers ident requests from IRC servers.
43 *
44 * @author Shane
45 */
46 public class IdentdPlugin extends Plugin implements ActionListener {
47
48 /** Array list to store all the servers in that need ident replies. */
49 private final List<Server> servers = new ArrayList<Server>();
50
51 /** The IdentdServer that we use. */
52 private IdentdServer myServer;
53
54 /**
55 * Creates a new instance of IdentdPlugin.
56 */
/*
P/P * Method: void com.dmdirc.addons.identd.IdentdPlugin()
*
* Postconditions:
* this.servers == &new ArrayList(IdentdPlugin#1)
* new ArrayList(IdentdPlugin#1) num objects == 1
*/
57 public IdentdPlugin() { }
58
59 /**
60 * Called when the plugin is loaded.
61 */
62 @Override
63 public void onLoad() {
64 // Add action hooks
/*
P/P * Method: void onLoad()
*
* Presumptions:
* com.dmdirc.config.IdentityManager:getGlobalConfig(...)@68 != null
*
* Postconditions:
* this.myServer == &new IdentdServer(onLoad#2)
* init'ed(this.myServer.myThread)
* init'ed(this.myServer.serverSocket)
* new ArrayList(IdentdServer#1) num objects == 1
* new IdentdServer(onLoad#2) num objects == 1
* this.myServer.clientList == &new ArrayList(IdentdServer#1)
* this.myServer.myPlugin == this
* this.myServer.myPlugin != null
* new ServerSocket(startServer#1) num objects <= 1
* new Thread(startServer#2) num objects <= 1
*
* Test Vectors:
* com.dmdirc.config.ConfigManager:getOptionBool(...)@68: {0}, {1}
*/
65 ActionManager.addListener(this, CoreActionType.SERVER_CONNECTED, CoreActionType.SERVER_CONNECTING, CoreActionType.SERVER_CONNECTERROR);
66
67 myServer = new IdentdServer(this);
68 if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.alwaysOn")) {
69 myServer.startServer();
70 }
71 }
72
73 /**
74 * Called when this plugin is unloaded.
75 */
76 @Override
77 public void onUnload() {
/*
P/P * Method: void onUnload()
*
* Preconditions:
* init'ed(this.myServer.myThread)
* this.myServer != null
* this.servers != null
* (soft) this.myServer.clientList != null
* (soft) this.myServer.serverSocket != null
*
* Postconditions:
* this.myServer.myThread == null
*/
78 myServer.stopServer();
79 servers.clear();
80 ActionManager.removeListener(this);
81 }
82
83 /**
84 * Process an event of the specified type.
85 *
86 * @param type The type of the event to process
87 * @param format Format of messages that are about to be sent. (May be null)
88 * @param arguments The arguments for the event
89 */
90 @Override
91 public void processEvent(final ActionType type, final StringBuffer format, final Object... arguments) {
/*
P/P * Method: void processEvent(ActionType, StringBuffer, Object[])
*
* Preconditions:
* (soft) arguments != null
* (soft) arguments.length >= 1
* (soft) init'ed(arguments[0])
* (soft) init'ed(this.myServer.myThread)
* (soft) this.myServer.serverSocket != null
* (soft) this.myServer != null
* (soft) this.myServer.clientList != null
* (soft) this.myServer.myPlugin != null
* (soft) this.servers != null
*
* Presumptions:
* com.dmdirc.config.IdentityManager:getGlobalConfig(...)@103 != null
*
* Postconditions:
* this.myServer.myThread == One-of{old this.myServer.myThread, &new Thread(startServer#2), null}
* init'ed(this.myServer.myThread)
* this.myServer.serverSocket == One-of{old this.myServer.serverSocket, &new ServerSocket(startServer#1)}
* this.myServer.serverSocket != null
* new ServerSocket(startServer#1) num objects <= 1
* new Thread(startServer#2) num objects <= 1
*
* Test Vectors:
* java.util.List:isEmpty(...)@94: {0}, {1}
*/
92 if (type == CoreActionType.SERVER_CONNECTING) {
93 synchronized (servers) {
94 if (servers.isEmpty()) {
95 myServer.startServer();
96 }
97 servers.add((Server) arguments[0]);
98 }
99 } else if (type == CoreActionType.SERVER_CONNECTED || type == CoreActionType.SERVER_CONNECTERROR) {
100 synchronized (servers) {
101 servers.remove(arguments[0]);
102
103 if (servers.isEmpty() && !IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.alwaysOn")) {
104 myServer.stopServer();
105 }
106 }
107 }
108 }
109
110 /** {@inheritDoc} */
111 @Override
112 public void showConfig(final PreferencesManager manager) {
/*
P/P * Method: void showConfig(PreferencesManager)
*
* Preconditions:
* manager != null
*
* Presumptions:
* com.dmdirc.config.prefs.PreferencesManager:getCategory(...)@167 != null
* init'ed(com.dmdirc.config.prefs.PreferencesType.BOOLEAN)
* init'ed(com.dmdirc.config.prefs.PreferencesType.INTEGER)
* init'ed(com.dmdirc.config.prefs.PreferencesType.TEXT)
*/
113 final PreferencesCategory general = new PreferencesCategory("Identd",
114 "General Identd Plugin config ('Lower' options take priority " +
115 "over those above them)");
116 final PreferencesCategory advanced = new PreferencesCategory("Advanced",
117 "Advanced Identd Plugin config - Only edit these if you need " +
118 "to/know what you are doing. Editing these could prevent " +
119 "access to some servers. ('Lower' options take priority over " +
120 "those above them)");
121
122 general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
123 getDomain(), "general.useUsername", "Use connection " +
124 "username rather than system username", "If this is enabled," +
125 " the username for the connection will be used rather than " +
126 "'" + System.getProperty("user.name") + "'"));
127 general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
128 getDomain(), "general.useNickname", "Use connection " +
129 "nickname rather than system username", "If this is enabled, " +
130 "the nickname for the connection will be used rather than " +
131 "'" + System.getProperty("user.name") + "'"));
132 general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
133 getDomain(), "general.useCustomName", "Use custom name" +
134 " all the time", "If this is enabled, the name specified below" +
135 " will be used all the time"));
136 general.addSetting(new PreferencesSetting(PreferencesType.TEXT,
137 getDomain(), "general.customName", "Custom Name to use",
138 "The custom name to use when 'Use Custom Name' is enabled"));
139
140 advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
141 getDomain(), "advanced.alwaysOn", "Always have ident " +
142 "port open", "By default the identd only runs when there are " +
143 "active connection attempts. This overrides that."));
144 advanced.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
145 new PortValidator(), getDomain(), "advanced.port",
146 "What port should the identd listen on", "Default port is 113," +
147 " this is probably useless if changed unless you port forward" +
148 " ident to a different port"));
149 advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
150 getDomain(), "advanced.useCustomSystem", "Use custom OS",
151 "By default the plugin uses 'UNIX' or 'WIN32' as the system " +
152 "type, this can be overriden by enabling this."));
153 advanced.addSetting(new PreferencesSetting(PreferencesType.TEXT,
154 getDomain(), "advanced.customSystem", "Custom OS to use",
155 "The custom system to use when 'Use Custom System' is enabled"));
156 advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
157 getDomain(), "advanced.isHiddenUser", "Respond to ident" +
158 " requests with HIDDEN-USER error", "By default the plugin will" +
159 " give a USERID response, this can force an 'ERROR :" +
160 " HIDDEN-USER' response instead."));
161 advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
162 getDomain(), "advanced.isNoUser", "Respond to ident" +
163 " requests with NO-USER error", "By default the plugin will" +
164 " give a USERID response, this can force an 'ERROR : NO-USER'" +
165 " response instead. (Overrides HIDDEN-USER)"));
166
167 manager.getCategory("Plugins").addSubCategory(general);
168 general.addSubCategory(advanced);
169 }
170
171 }
SofCheck Inspector Build Version : 2.17854
| IdentdPlugin.java |
2009-Jun-25 01:54:24 |
| IdentdPlugin.class |
2009-Sep-02 17:04:15 |