|
@@ -29,6 +29,7 @@ import com.dmdirc.commandparser.CommandManager;
|
29
|
29
|
import com.dmdirc.config.ConfigManager;
|
30
|
30
|
import com.dmdirc.config.Identity;
|
31
|
31
|
import com.dmdirc.config.IdentityManager;
|
|
32
|
+import com.dmdirc.interfaces.InviteListener;
|
32
|
33
|
import com.dmdirc.logger.ErrorLevel;
|
33
|
34
|
import com.dmdirc.logger.Logger;
|
34
|
35
|
import com.dmdirc.parser.ChannelInfo;
|
|
@@ -51,6 +52,8 @@ import java.util.Map;
|
51
|
52
|
import java.util.Timer;
|
52
|
53
|
import java.util.TimerTask;
|
53
|
54
|
|
|
55
|
+import javax.swing.event.EventListenerList;
|
|
56
|
+
|
54
|
57
|
/**
|
55
|
58
|
* The Server class represents the client's view of a server. It maintains
|
56
|
59
|
* a list of all channels, queries, etc, and handles parser callbacks pertaining
|
|
@@ -110,14 +113,18 @@ public final class Server extends WritableFrameContainer implements Serializable
|
110
|
113
|
/** The config manager for this server. */
|
111
|
114
|
private ConfigManager configManager;
|
112
|
115
|
|
113
|
|
- /** Whether we're marked as away or not. */
|
114
|
|
- private boolean away;
|
115
|
116
|
/** Our reason for being away, if any. */
|
116
|
|
- private String awayMessage;
|
|
117
|
+ private String awayMessage = "";
|
117
|
118
|
|
118
|
119
|
/** Our event handler. */
|
119
|
120
|
private final ServerEventHandler eventHandler = new ServerEventHandler(this);
|
120
|
121
|
|
|
122
|
+ /** A list of outstanding invites. */
|
|
123
|
+ private final List<Invite> invites = new ArrayList<Invite>();
|
|
124
|
+
|
|
125
|
+ /** A list of listeners for this server's events. */
|
|
126
|
+ private final EventListenerList listeners = new EventListenerList();
|
|
127
|
+
|
121
|
128
|
/**
|
122
|
129
|
* Creates a new instance of Server.
|
123
|
130
|
*
|
|
@@ -245,8 +252,8 @@ public final class Server extends WritableFrameContainer implements Serializable
|
245
|
252
|
|
246
|
253
|
doCallbacks();
|
247
|
254
|
|
248
|
|
- away = false;
|
249
|
255
|
awayMessage = "";
|
|
256
|
+ invites.clear();
|
250
|
257
|
window.setAwayIndicator(false);
|
251
|
258
|
|
252
|
259
|
try {
|
|
@@ -497,7 +504,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
497
|
504
|
* @return True if the client is marked as away, false otherwise
|
498
|
505
|
*/
|
499
|
506
|
public boolean isAway() {
|
500
|
|
- return away;
|
|
507
|
+ return !awayMessage.isEmpty();
|
501
|
508
|
}
|
502
|
509
|
|
503
|
510
|
/**
|
|
@@ -682,7 +689,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
682
|
689
|
final Channel newChan = new Channel(this, chan);
|
683
|
690
|
|
684
|
691
|
tabCompleter.addEntry(chan.getName());
|
685
|
|
- channels.put(parser.toLowerCase(chan.getName()), newChan);
|
|
692
|
+ channels.put(parser.toLowerCase(chan.getName()), newChan);
|
686
|
693
|
newChan.show();
|
687
|
694
|
}
|
688
|
695
|
}
|
|
@@ -832,7 +839,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
832
|
839
|
|
833
|
840
|
/**
|
834
|
841
|
* Called when a private CTCP is received.
|
835
|
|
- *
|
|
842
|
+ *
|
836
|
843
|
* @param type The type of the CTCP
|
837
|
844
|
* @param message The body (if any) of the CTCP
|
838
|
845
|
* @param host The host of the user that sent the CTCP
|
|
@@ -868,7 +875,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
868
|
875
|
|
869
|
876
|
/**
|
870
|
877
|
* Called when a private CTCP reply is received.
|
871
|
|
- *
|
|
878
|
+ *
|
872
|
879
|
* @param type The type of CTCPR
|
873
|
880
|
* @param message The body of the CTCPR
|
874
|
881
|
* @param host The host of the user who is sending the CTCPR
|
|
@@ -884,7 +891,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
884
|
891
|
|
885
|
892
|
/**
|
886
|
893
|
* Called when a private notice is received.
|
887
|
|
- *
|
|
894
|
+ *
|
888
|
895
|
* @param message The message content of the notice
|
889
|
896
|
* @param host The host of the user who sent the notice
|
890
|
897
|
*/
|
|
@@ -900,7 +907,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
900
|
907
|
/**
|
901
|
908
|
* Called when the server says that the nickname we're trying to use is
|
902
|
909
|
* already in use.
|
903
|
|
- *
|
|
910
|
+ *
|
904
|
911
|
* @param nickname The nickname that we were trying to use
|
905
|
912
|
*/
|
906
|
913
|
public void onNickInUse(final String nickname) {
|
|
@@ -937,7 +944,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
937
|
944
|
/**
|
938
|
945
|
* Called when the parser has determined the network name and IRCd type
|
939
|
946
|
* of our server.
|
940
|
|
- *
|
|
947
|
+ *
|
941
|
948
|
* @param networkName The name of the network we're connected to
|
942
|
949
|
* @param ircdType The type of IRCd that we're connected to
|
943
|
950
|
*/
|
|
@@ -947,9 +954,9 @@ public final class Server extends WritableFrameContainer implements Serializable
|
947
|
954
|
updateIgnoreList();
|
948
|
955
|
}
|
949
|
956
|
|
950
|
|
- /**
|
|
957
|
+ /**
|
951
|
958
|
* Called when we start receiving the server's MOTD.
|
952
|
|
- *
|
|
959
|
+ *
|
953
|
960
|
* @param data The data sent by the server
|
954
|
961
|
*/
|
955
|
962
|
public void onMOTDStart(final String data) {
|
|
@@ -960,9 +967,9 @@ public final class Server extends WritableFrameContainer implements Serializable
|
960
|
967
|
addLine(buffer, data);
|
961
|
968
|
}
|
962
|
969
|
|
963
|
|
- /**
|
|
970
|
+ /**
|
964
|
971
|
* Called when we receive a single line of the server's MOTD.
|
965
|
|
- *
|
|
972
|
+ *
|
966
|
973
|
* @param data The data sent by the server
|
967
|
974
|
*/
|
968
|
975
|
public void onMOTDLine(final String data) {
|
|
@@ -973,7 +980,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
973
|
980
|
addLine(buffer, data);
|
974
|
981
|
}
|
975
|
982
|
|
976
|
|
- /**
|
|
983
|
+ /**
|
977
|
984
|
* Called when the server has finished sending the MOTD.
|
978
|
985
|
*/
|
979
|
986
|
public void onMOTDEnd() {
|
|
@@ -986,7 +993,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
986
|
993
|
|
987
|
994
|
/**
|
988
|
995
|
* Called when the server sends a numeric event.
|
989
|
|
- *
|
|
996
|
+ *
|
990
|
997
|
* @param numeric The numeric code for the event
|
991
|
998
|
* @param tokens The (tokenised) arguments of the event
|
992
|
999
|
*/
|
|
@@ -1013,8 +1020,8 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1013
|
1020
|
|
1014
|
1021
|
/**
|
1015
|
1022
|
* Called when we receive an auth notice.
|
1016
|
|
- *
|
1017
|
|
- * @param data The content of the notice
|
|
1023
|
+ *
|
|
1024
|
+ * @param data The content of the notice
|
1018
|
1025
|
*/
|
1019
|
1026
|
public void onNoticeAuth(final String data) {
|
1020
|
1027
|
handleNotification("authNotice", data);
|
|
@@ -1025,8 +1032,8 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1025
|
1032
|
|
1026
|
1033
|
/**
|
1027
|
1034
|
* Called when we receive an unknown notice.
|
1028
|
|
- *
|
1029
|
|
- * @param message The content of the notice
|
|
1035
|
+ *
|
|
1036
|
+ * @param message The content of the notice
|
1030
|
1037
|
* @param target The destination of this notice (such as $*)
|
1031
|
1038
|
* @param host The host of the user that sent the notice
|
1032
|
1039
|
*/
|
|
@@ -1040,7 +1047,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1040
|
1047
|
|
1041
|
1048
|
/**
|
1042
|
1049
|
* Called when we receive a user mode change.
|
1043
|
|
- *
|
|
1050
|
+ *
|
1044
|
1051
|
* @param client The updated client object for the victim (us)
|
1045
|
1052
|
* @param setBy The host of the user that performed the change
|
1046
|
1053
|
* @param modes The modes that were changed
|
|
@@ -1063,27 +1070,25 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1063
|
1070
|
|
1064
|
1071
|
/**
|
1065
|
1072
|
* Called when our away state changes.
|
1066
|
|
- *
|
|
1073
|
+ *
|
1067
|
1074
|
* @param currentState The new aray state
|
1068
|
1075
|
* @param reason Our away reason, if applicable
|
1069
|
1076
|
*/
|
1070
|
1077
|
public void onAwayState(final boolean currentState, final String reason) {
|
1071
|
1078
|
if (currentState) {
|
1072
|
|
- away = true;
|
1073
|
1079
|
awayMessage = reason;
|
1074
|
1080
|
|
1075
|
1081
|
ActionManager.processEvent(CoreActionType.SERVER_AWAY, null, this, awayMessage);
|
1076
|
1082
|
} else {
|
1077
|
|
- away = false;
|
1078
|
1083
|
awayMessage = "";
|
1079
|
1084
|
|
1080
|
1085
|
ActionManager.processEvent(CoreActionType.SERVER_BACK, null, this);
|
1081
|
1086
|
}
|
1082
|
1087
|
|
1083
|
|
- window.setAwayIndicator(away);
|
|
1088
|
+ window.setAwayIndicator(isAway());
|
1084
|
1089
|
}
|
1085
|
1090
|
|
1086
|
|
- /**
|
|
1091
|
+ /**
|
1087
|
1092
|
* Called when the socket has been closed.
|
1088
|
1093
|
*/
|
1089
|
1094
|
public void onSocketClosed() {
|
|
@@ -1111,9 +1116,9 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1111
|
1116
|
}
|
1112
|
1117
|
}
|
1113
|
1118
|
|
1114
|
|
- /**
|
|
1119
|
+ /**
|
1115
|
1120
|
* Called when an error was encountered while connecting.
|
1116
|
|
- *
|
|
1121
|
+ *
|
1117
|
1122
|
* @param errorInfo The parser's error information
|
1118
|
1123
|
*/
|
1119
|
1124
|
public void onConnectError(final ParserError errorInfo) {
|
|
@@ -1191,7 +1196,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1191
|
1196
|
reconnect();
|
1192
|
1197
|
}
|
1193
|
1198
|
}
|
1194
|
|
-
|
|
1199
|
+
|
1195
|
1200
|
/**
|
1196
|
1201
|
* Called after the parser receives the 005 headers from the server.
|
1197
|
1202
|
*/
|
|
@@ -1226,7 +1231,57 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1226
|
1231
|
}
|
1227
|
1232
|
}
|
1228
|
1233
|
}
|
1229
|
|
-
|
|
1234
|
+
|
|
1235
|
+ /**
|
|
1236
|
+ * Adds an invite listener to this server.
|
|
1237
|
+ *
|
|
1238
|
+ * @param listener The listener to be added
|
|
1239
|
+ */
|
|
1240
|
+ public void addInviteListener(final InviteListener listener) {
|
|
1241
|
+ listeners.add(InviteListener.class, listener);
|
|
1242
|
+ }
|
|
1243
|
+
|
|
1244
|
+ /**
|
|
1245
|
+ * Removes an invite listener from this server.
|
|
1246
|
+ *
|
|
1247
|
+ * @param listener The listener to be removed
|
|
1248
|
+ */
|
|
1249
|
+ public void removeInviteListener(final InviteListener listener) {
|
|
1250
|
+ listeners.remove(InviteListener.class, listener);
|
|
1251
|
+ }
|
|
1252
|
+
|
|
1253
|
+ /**
|
|
1254
|
+ * Adds an invite to this server, and fires the appropriate listeners.
|
|
1255
|
+ *
|
|
1256
|
+ * @param invite The invite to be added
|
|
1257
|
+ */
|
|
1258
|
+ public void addInvite(final Invite invite) {
|
|
1259
|
+ invites.add(invite);
|
|
1260
|
+
|
|
1261
|
+ final Object[] listenerList = listeners.getListenerList();
|
|
1262
|
+ for (int i = 0; i < listenerList.length; i += 2) {
|
|
1263
|
+ if (listenerList[i] == InviteListener.class) {
|
|
1264
|
+ ((InviteListener) listenerList[i + 1]).inviteReceived(this, invite);
|
|
1265
|
+ }
|
|
1266
|
+ }
|
|
1267
|
+ }
|
|
1268
|
+
|
|
1269
|
+ /**
|
|
1270
|
+ * Removes an invite from this server, and fires the appropriate listeners.
|
|
1271
|
+ *
|
|
1272
|
+ * @param invite The invite to be removed
|
|
1273
|
+ */
|
|
1274
|
+ public void removeInvite(final Invite invite) {
|
|
1275
|
+ invites.remove(invite);
|
|
1276
|
+
|
|
1277
|
+ final Object[] listenerList = listeners.getListenerList();
|
|
1278
|
+ for (int i = 0; i < listenerList.length; i += 2) {
|
|
1279
|
+ if (listenerList[i] == InviteListener.class) {
|
|
1280
|
+ ((InviteListener) listenerList[i + 1]).inviteReceived(this, invite);
|
|
1281
|
+ }
|
|
1282
|
+ }
|
|
1283
|
+ }
|
|
1284
|
+
|
1230
|
1285
|
/**
|
1231
|
1286
|
* Returns this server's name.
|
1232
|
1287
|
*
|