|
@@ -23,7 +23,6 @@
|
23
|
23
|
package com.dmdirc;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.actions.ActionManager;
|
26
|
|
-import com.dmdirc.actions.ActionType;
|
27
|
26
|
import com.dmdirc.actions.CoreActionType;
|
28
|
27
|
import com.dmdirc.actions.wrappers.AliasWrapper;
|
29
|
28
|
import com.dmdirc.commandparser.CommandManager;
|
|
@@ -38,7 +37,6 @@ import com.dmdirc.parser.IRCParser;
|
38
|
37
|
import com.dmdirc.parser.MyInfo;
|
39
|
38
|
import com.dmdirc.parser.ParserError;
|
40
|
39
|
import com.dmdirc.parser.ServerInfo;
|
41
|
|
-import com.dmdirc.parser.callbacks.CallbackNotFoundException;
|
42
|
40
|
import com.dmdirc.ui.input.TabCompleter;
|
43
|
41
|
import com.dmdirc.ui.interfaces.InputWindow;
|
44
|
42
|
import com.dmdirc.ui.interfaces.ServerWindow;
|
|
@@ -79,22 +77,6 @@ public final class Server extends WritableFrameContainer implements Serializable
|
79
|
77
|
/** The name of the server notification target. */
|
80
|
78
|
private static final String NOTIFICATION_SERVER = "server".intern();
|
81
|
79
|
|
82
|
|
- /** An enumeration of possible states for servers. */
|
83
|
|
- public static enum STATE {
|
84
|
|
- /** Indicates the client is in the process of connecting. */
|
85
|
|
- CONNECTING,
|
86
|
|
- /** Indicates the client has connected to the server. */
|
87
|
|
- CONNECTED,
|
88
|
|
- /** Indicates that we've been temporarily disconnected. */
|
89
|
|
- TRANSIENTLY_DISCONNECTED,
|
90
|
|
- /** Indicates that the user has told us to disconnect. */
|
91
|
|
- DISCONNECTED,
|
92
|
|
- /** Indicates we're waiting for the auto-reconnect timer to fire. */
|
93
|
|
- RECONNECT_WAIT,
|
94
|
|
- /** Indicates that the server frame and its children are closing. */
|
95
|
|
- CLOSING,
|
96
|
|
- };
|
97
|
|
-
|
98
|
80
|
/** Open channels that currently exist on the server. */
|
99
|
81
|
private final Map<String, Channel> channels = new Hashtable<String, Channel>();
|
100
|
82
|
/** Open query windows on the server. */
|
|
@@ -107,19 +89,14 @@ public final class Server extends WritableFrameContainer implements Serializable
|
107
|
89
|
/** The ServerWindow corresponding to this server. */
|
108
|
90
|
private ServerWindow window;
|
109
|
91
|
|
110
|
|
- /** The name of the server we're connecting to. */
|
111
|
|
- private String server;
|
112
|
|
- /** The port we're connecting to. */
|
113
|
|
- private int port;
|
114
|
|
- /** The password we're using to connect. */
|
115
|
|
- private String password;
|
116
|
|
- /** Whether we're using SSL or not. */
|
117
|
|
- private boolean ssl;
|
|
92
|
+ /** The details of the server we're connecting to. */
|
|
93
|
+ private ServerInfo serverInfo;
|
|
94
|
+
|
118
|
95
|
/** The profile we're using. */
|
119
|
96
|
private transient Identity profile;
|
120
|
97
|
|
121
|
98
|
/** The current state of this server. */
|
122
|
|
- private STATE myState = STATE.DISCONNECTED;
|
|
99
|
+ private ServerState myState = ServerState.DISCONNECTED;
|
123
|
100
|
/** The timer we're using to delay reconnects. */
|
124
|
101
|
private Timer reconnectTimer;
|
125
|
102
|
|
|
@@ -169,7 +146,8 @@ public final class Server extends WritableFrameContainer implements Serializable
|
169
|
146
|
final boolean ssl, final Identity profile, final List<String> autochannels) {
|
170
|
147
|
super();
|
171
|
148
|
|
172
|
|
- this.server = server;
|
|
149
|
+ serverInfo = new ServerInfo(server, port, password);
|
|
150
|
+ serverInfo.setSSL(ssl);
|
173
|
151
|
|
174
|
152
|
ServerManager.getServerManager().registerServer(this);
|
175
|
153
|
|
|
@@ -214,22 +192,29 @@ public final class Server extends WritableFrameContainer implements Serializable
|
214
|
192
|
public void connect(final String server, final int port, final String password,
|
215
|
193
|
final boolean ssl, final Identity profile) {
|
216
|
194
|
synchronized(myState) {
|
217
|
|
- if (myState == STATE.RECONNECT_WAIT) {
|
|
195
|
+ switch (myState) {
|
|
196
|
+ case RECONNECT_WAIT:
|
218
|
197
|
reconnectTimer.cancel();
|
219
|
|
- } else if (myState == STATE.CLOSING) {
|
|
198
|
+ break;
|
|
199
|
+ case CLOSING:
|
220
|
200
|
Logger.appError(ErrorLevel.MEDIUM,
|
221
|
201
|
"Connect attempt while not expecting one",
|
222
|
202
|
new UnsupportedOperationException("Current state: " + myState));
|
223
|
203
|
return;
|
224
|
|
- } else if (myState == STATE.CONNECTED || myState == STATE.CONNECTING) {
|
|
204
|
+ case CONNECTED:
|
|
205
|
+ case CONNECTING:
|
225
|
206
|
disconnect(configManager.getOption(DOMAIN_GENERAL, "quitmessage"));
|
|
207
|
+ break;
|
|
208
|
+ default:
|
|
209
|
+ // Do nothing
|
|
210
|
+ break;
|
226
|
211
|
}
|
227
|
212
|
|
228
|
|
- ActionManager.processEvent(CoreActionType.SERVER_CONNECTING, null, this);
|
229
|
|
-
|
230
|
|
- myState = Server.STATE.CONNECTING;
|
|
213
|
+ myState = ServerState.CONNECTING;
|
231
|
214
|
}
|
232
|
215
|
|
|
216
|
+ ActionManager.processEvent(CoreActionType.SERVER_CONNECTING, null, this);
|
|
217
|
+
|
233
|
218
|
if (parser != null && parser.getSocketState() == parser.STATE_OPEN) {
|
234
|
219
|
Logger.appError(ErrorLevel.MEDIUM,
|
235
|
220
|
"Parser was still connected when making a connection attempt",
|
|
@@ -237,10 +222,9 @@ public final class Server extends WritableFrameContainer implements Serializable
|
237
|
222
|
disconnect(configManager.getOption(DOMAIN_GENERAL, "quitmessage"));
|
238
|
223
|
}
|
239
|
224
|
|
240
|
|
- this.server = server;
|
241
|
|
- this.port = port;
|
242
|
|
- this.password = password;
|
243
|
|
- this.ssl = ssl;
|
|
225
|
+ serverInfo = new ServerInfo(server, port, password);
|
|
226
|
+ serverInfo.setSSL(ssl);
|
|
227
|
+
|
244
|
228
|
this.profile = profile;
|
245
|
229
|
|
246
|
230
|
configManager = new ConfigManager("", "", server);
|
|
@@ -281,7 +265,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
281
|
265
|
* Updates this server's icon.
|
282
|
266
|
*/
|
283
|
267
|
private void updateIcon() {
|
284
|
|
- icon = IconManager.getIconManager().getIcon(ssl ? "secure-server" : "server");
|
|
268
|
+ icon = IconManager.getIconManager().getIcon(serverInfo.getSSL() ? "secure-server" : "server");
|
285
|
269
|
if (window != null) {
|
286
|
270
|
window.setFrameIcon(icon);
|
287
|
271
|
Main.getUI().getMainWindow().getFrameManager().iconUpdated(this);
|
|
@@ -330,13 +314,14 @@ public final class Server extends WritableFrameContainer implements Serializable
|
330
|
314
|
*/
|
331
|
315
|
public void reconnect(final String reason) {
|
332
|
316
|
synchronized(myState) {
|
333
|
|
- if (myState == STATE.CLOSING) {
|
|
317
|
+ if (myState == ServerState.CLOSING) {
|
334
|
318
|
return;
|
335
|
319
|
}
|
336
|
320
|
}
|
337
|
321
|
|
338
|
322
|
disconnect(reason);
|
339
|
|
- connect(server, port, password, ssl, profile);
|
|
323
|
+ connect(serverInfo.getHost(), serverInfo.getPort(),
|
|
324
|
+ serverInfo.getPassword(), serverInfo.getSSL(), profile);
|
340
|
325
|
}
|
341
|
326
|
|
342
|
327
|
/**
|
|
@@ -349,7 +334,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
349
|
334
|
/** {@inheritDoc} */
|
350
|
335
|
public void sendLine(final String line) {
|
351
|
336
|
synchronized(myState) {
|
352
|
|
- if (parser != null && myState == STATE.CONNECTED) {
|
|
337
|
+ if (parser != null && myState == ServerState.CONNECTED) {
|
353
|
338
|
parser.sendLine(window.getTranscoder().encode(line));
|
354
|
339
|
}
|
355
|
340
|
}
|
|
@@ -489,7 +474,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
489
|
474
|
* @return The name of this server
|
490
|
475
|
*/
|
491
|
476
|
public String getName() {
|
492
|
|
- return this.server;
|
|
477
|
+ return serverInfo.getHost();
|
493
|
478
|
}
|
494
|
479
|
|
495
|
480
|
/**
|
|
@@ -553,7 +538,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
553
|
538
|
*
|
554
|
539
|
* @return This server's state
|
555
|
540
|
*/
|
556
|
|
- public STATE getState() {
|
|
541
|
+ public ServerState getState() {
|
557
|
542
|
return myState;
|
558
|
543
|
}
|
559
|
544
|
|
|
@@ -571,7 +556,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
571
|
556
|
// Disconnect from the server
|
572
|
557
|
disconnect(reason);
|
573
|
558
|
|
574
|
|
- myState = STATE.CLOSING;
|
|
559
|
+ myState = ServerState.CLOSING;
|
575
|
560
|
|
576
|
561
|
// Close all channel windows
|
577
|
562
|
closeChannels();
|
|
@@ -618,7 +603,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
618
|
603
|
break;
|
619
|
604
|
}
|
620
|
605
|
|
621
|
|
- myState = STATE.DISCONNECTED;
|
|
606
|
+ myState = ServerState.DISCONNECTED;
|
622
|
607
|
}
|
623
|
608
|
|
624
|
609
|
if (parser != null && parser.getSocketState() == parser.STATE_OPEN) {
|
|
@@ -693,14 +678,19 @@ public final class Server extends WritableFrameContainer implements Serializable
|
693
|
678
|
*
|
694
|
679
|
* @param chan channel to add
|
695
|
680
|
*/
|
696
|
|
- private void addChannel(final ChannelInfo chan) {
|
697
|
|
- final Channel newChan = new Channel(this, chan);
|
698
|
|
-
|
699
|
|
- tabCompleter.addEntry(chan.getName());
|
700
|
|
- channels.put(parser.toLowerCase(chan.getName()), newChan);
|
701
|
|
- Main.getUI().getMainWindow().getFrameManager().addWindow(this, newChan);
|
702
|
|
-
|
703
|
|
- newChan.show();
|
|
681
|
+ public void addChannel(final ChannelInfo chan) {
|
|
682
|
+ if (hasChannel(chan.getName())) {
|
|
683
|
+ getChannel(chan.getName()).setChannelInfo(chan);
|
|
684
|
+ getChannel(chan.getName()).selfJoin();
|
|
685
|
+ } else {
|
|
686
|
+ final Channel newChan = new Channel(this, chan);
|
|
687
|
+
|
|
688
|
+ tabCompleter.addEntry(chan.getName());
|
|
689
|
+ channels.put(parser.toLowerCase(chan.getName()), newChan);
|
|
690
|
+ Main.getUI().getMainWindow().getFrameManager().addWindow(this, newChan);
|
|
691
|
+
|
|
692
|
+ newChan.show();
|
|
693
|
+ }
|
704
|
694
|
}
|
705
|
695
|
|
706
|
696
|
/**
|
|
@@ -847,16 +837,6 @@ public final class Server extends WritableFrameContainer implements Serializable
|
847
|
837
|
}
|
848
|
838
|
}
|
849
|
839
|
|
850
|
|
- /** {@inheritDoc} */
|
851
|
|
- public void onChannelSelfJoin(final ChannelInfo cChannel) {
|
852
|
|
- if (hasChannel(cChannel.getName())) {
|
853
|
|
- getChannel(cChannel.getName()).setChannelInfo(cChannel);
|
854
|
|
- getChannel(cChannel.getName()).selfJoin();
|
855
|
|
- } else {
|
856
|
|
- addChannel(cChannel);
|
857
|
|
- }
|
858
|
|
- }
|
859
|
|
-
|
860
|
840
|
/** {@inheritDoc} */
|
861
|
841
|
public void onPrivateCTCP(final String sType,
|
862
|
842
|
final String sMessage, final String sHost) {
|
|
@@ -887,7 +867,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
887
|
867
|
parser.sendCTCPReply(source, "CLIENTINFO", "VERSION PING CLIENTINFO");
|
888
|
868
|
}
|
889
|
869
|
}
|
890
|
|
-
|
|
870
|
+
|
891
|
871
|
/** {@inheritDoc} */
|
892
|
872
|
public void onPrivateCTCPReply(final String sType,
|
893
|
873
|
final String sMessage, final String sHost) {
|
|
@@ -945,7 +925,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
945
|
925
|
/** {@inheritDoc} */
|
946
|
926
|
public void onGotNetwork(final String networkName,
|
947
|
927
|
final String ircdVersion, final String ircdType) {
|
948
|
|
- configManager = new ConfigManager(ircdType, networkName, this.server);
|
|
928
|
+ configManager = new ConfigManager(ircdType, networkName, getName());
|
949
|
929
|
|
950
|
930
|
updateIgnoreList();
|
951
|
931
|
}
|
|
@@ -1036,8 +1016,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1036
|
1016
|
}
|
1037
|
1017
|
|
1038
|
1018
|
/** {@inheritDoc} */
|
1039
|
|
- public void onAwayState(final boolean currentState,
|
1040
|
|
- final String reason) {
|
|
1019
|
+ public void onAwayState(final boolean currentState, final String reason) {
|
1041
|
1020
|
if (currentState) {
|
1042
|
1021
|
away = true;
|
1043
|
1022
|
awayMessage = reason;
|
|
@@ -1055,15 +1034,15 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1055
|
1034
|
|
1056
|
1035
|
/** {@inheritDoc} */
|
1057
|
1036
|
public void onSocketClosed() {
|
1058
|
|
- handleNotification("socketClosed", this.server);
|
|
1037
|
+ handleNotification("socketClosed", getName());
|
1059
|
1038
|
|
1060
|
1039
|
synchronized(myState) {
|
1061
|
|
- if (myState == STATE.CLOSING || myState == STATE.DISCONNECTED) {
|
|
1040
|
+ if (myState == ServerState.CLOSING || myState == ServerState.DISCONNECTED) {
|
1062
|
1041
|
// This has been triggered via .disconect()
|
1063
|
1042
|
return;
|
1064
|
1043
|
}
|
1065
|
1044
|
|
1066
|
|
- myState = STATE.TRANSIENTLY_DISCONNECTED;
|
|
1045
|
+ myState = ServerState.TRANSIENTLY_DISCONNECTED;
|
1067
|
1046
|
}
|
1068
|
1047
|
|
1069
|
1048
|
if (configManager.getOptionBool(DOMAIN_GENERAL, "closechannelsondisconnect", false)) {
|
|
@@ -1082,14 +1061,14 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1082
|
1061
|
/** {@inheritDoc} */
|
1083
|
1062
|
public void onConnectError(final ParserError errorInfo) {
|
1084
|
1063
|
synchronized(myState) {
|
1085
|
|
- if (myState != STATE.CONNECTING) {
|
|
1064
|
+ if (myState != ServerState.CONNECTING) {
|
1086
|
1065
|
Logger.appError(ErrorLevel.MEDIUM,
|
1087
|
1066
|
"Connection error while not expecting a connection attempt",
|
1088
|
1067
|
new UnsupportedOperationException("Current state: " + myState));
|
1089
|
1068
|
return;
|
1090
|
1069
|
}
|
1091
|
1070
|
|
1092
|
|
- myState = STATE.TRANSIENTLY_DISCONNECTED;
|
|
1071
|
+ myState = ServerState.TRANSIENTLY_DISCONNECTED;
|
1093
|
1072
|
}
|
1094
|
1073
|
|
1095
|
1074
|
String description;
|
|
@@ -1113,7 +1092,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1113
|
1092
|
|
1114
|
1093
|
ActionManager.processEvent(CoreActionType.SERVER_CONNECTERROR, null, this, description);
|
1115
|
1094
|
|
1116
|
|
- handleNotification("connectError", server, description);
|
|
1095
|
+ handleNotification("connectError", getName(), description);
|
1117
|
1096
|
|
1118
|
1097
|
if (configManager.getOptionBool(DOMAIN_GENERAL, "reconnectonconnectfailure", false)) {
|
1119
|
1098
|
doDelayedReconnect();
|
|
@@ -1126,44 +1105,38 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1126
|
1105
|
private void doDelayedReconnect() {
|
1127
|
1106
|
final int delay = Math.max(1, configManager.getOptionInt(DOMAIN_GENERAL, "reconnectdelay", 5));
|
1128
|
1107
|
|
1129
|
|
- handleNotification("connectRetry", server, delay);
|
|
1108
|
+ handleNotification("connectRetry", getName(), delay);
|
1130
|
1109
|
|
1131
|
1110
|
reconnectTimer = new Timer("Server Reconnect Timer");
|
1132
|
1111
|
reconnectTimer.schedule(new TimerTask() {
|
1133
|
1112
|
public void run() {
|
1134
|
1113
|
synchronized(myState) {
|
1135
|
|
- if (myState == STATE.RECONNECT_WAIT) {
|
1136
|
|
- myState = STATE.TRANSIENTLY_DISCONNECTED;
|
|
1114
|
+ if (myState == ServerState.RECONNECT_WAIT) {
|
|
1115
|
+ myState = ServerState.TRANSIENTLY_DISCONNECTED;
|
1137
|
1116
|
reconnect();
|
1138
|
1117
|
}
|
1139
|
1118
|
}
|
1140
|
1119
|
}
|
1141
|
1120
|
}, delay * 1000);
|
1142
|
1121
|
|
1143
|
|
- myState = STATE.RECONNECT_WAIT;
|
|
1122
|
+ myState = ServerState.RECONNECT_WAIT;
|
1144
|
1123
|
}
|
1145
|
1124
|
|
1146
|
1125
|
/** {@inheritDoc} */
|
1147
|
1126
|
public void onPingFailed() {
|
1148
|
1127
|
Main.getUI().getStatusBar().setMessage("No ping reply from "
|
1149
|
|
- + this.server + " for over "
|
|
1128
|
+ + getName() + " for over "
|
1150
|
1129
|
+ Math.floor(parser.getPingTime(false) / 1000.0) + " seconds.", null, 10);
|
1151
|
1130
|
|
1152
|
1131
|
ActionManager.processEvent(CoreActionType.SERVER_NOPING, null, this,
|
1153
|
1132
|
Long.valueOf(parser.getPingTime(false)));
|
1154
|
1133
|
|
1155
|
1134
|
if (parser.getPingTime(false) >= configManager.getOptionInt(DOMAIN_SERVER, "pingtimeout", 60000)) {
|
1156
|
|
- handleNotification("stonedServer", server);
|
|
1135
|
+ handleNotification("stonedServer", getName());
|
1157
|
1136
|
reconnect();
|
1158
|
1137
|
}
|
1159
|
1138
|
}
|
1160
|
1139
|
|
1161
|
|
- /** {@inheritDoc} */
|
1162
|
|
- public void onPingSuccess() {
|
1163
|
|
- ActionManager.processEvent(CoreActionType.SERVER_GOTPING, null, this,
|
1164
|
|
- Long.valueOf(parser.getServerLag()));
|
1165
|
|
- }
|
1166
|
|
-
|
1167
|
1140
|
/** {@inheritDoc} */
|
1168
|
1141
|
public void onAwayStateOther(final ClientInfo client, final boolean state) {
|
1169
|
1142
|
for (Channel chan : channels.values()) {
|
|
@@ -1174,18 +1147,11 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1174
|
1147
|
/** {@inheritDoc} */
|
1175
|
1148
|
public void onPost005() {
|
1176
|
1149
|
synchronized(myState) {
|
1177
|
|
- if (myState != STATE.CONNECTING) {
|
1178
|
|
- Logger.appError(ErrorLevel.HIGH,
|
1179
|
|
- "Received post005 when not connecting",
|
1180
|
|
- new UnsupportedOperationException("Current state: " + myState));
|
1181
|
|
- parser.disconnect("Error");
|
1182
|
|
- return;
|
1183
|
|
- }
|
1184
|
|
-
|
1185
|
|
- ActionManager.processEvent(CoreActionType.SERVER_CONNECTED, null, this);
|
1186
|
|
- myState = STATE.CONNECTED;
|
|
1150
|
+ myState = ServerState.CONNECTED;
|
1187
|
1151
|
}
|
1188
|
1152
|
|
|
1153
|
+ ActionManager.processEvent(CoreActionType.SERVER_CONNECTED, null, this);
|
|
1154
|
+
|
1189
|
1155
|
if (configManager.hasOption(DOMAIN_GENERAL, "rejoinchannels")) {
|
1190
|
1156
|
for (Channel chan : channels.values()) {
|
1191
|
1157
|
chan.join();
|
|
@@ -1220,7 +1186,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1220
|
1186
|
} else {
|
1221
|
1187
|
Logger.appError(errorLevel, errorInfo.getData(),
|
1222
|
1188
|
new Exception("Parser exception.\n\n\tLast line:\t" //NOPMD
|
1223
|
|
- + errorInfo.getLastLine() + "\n\tServer:\t" + server + "\n"));
|
|
1189
|
+ + errorInfo.getLastLine() + "\n\tServer:\t" + getName() + "\n"));
|
1224
|
1190
|
}
|
1225
|
1191
|
}
|
1226
|
1192
|
|
|
@@ -1230,7 +1196,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1230
|
1196
|
* @return A string representation of this server (i.e., its name)
|
1231
|
1197
|
*/
|
1232
|
1198
|
public String toString() {
|
1233
|
|
- return this.server;
|
|
1199
|
+ return getName();
|
1234
|
1200
|
}
|
1235
|
1201
|
|
1236
|
1202
|
/**
|