|
@@ -57,6 +57,8 @@ public class Server implements IRCParser.IChannelSelfJoin, IRCParser.IErrorInfo
|
57
|
57
|
*/
|
58
|
58
|
private IRCParser parser;
|
59
|
59
|
|
|
60
|
+ private Raw raw;
|
|
61
|
+
|
60
|
62
|
/**
|
61
|
63
|
* Creates a new instance of Server
|
62
|
64
|
* @param server The hostname/ip of the server to connect to
|
|
@@ -73,15 +75,15 @@ public class Server implements IRCParser.IChannelSelfJoin, IRCParser.IErrorInfo
|
73
|
75
|
MainFrame.getMainFrame().addChild(frame);
|
74
|
76
|
|
75
|
77
|
frame.addLine("Connecting to "+server+":"+port);
|
76
|
|
-
|
|
78
|
+
|
77
|
79
|
parser = new IRCParser(new ServerInfo(server, port, password));
|
78
|
80
|
|
79
|
81
|
parser.addChannelSelfJoin(this);
|
80
|
82
|
parser.addErrorInfo(this);
|
81
|
|
-
|
82
|
|
- Raw raw = new Raw(this);
|
83
|
|
-
|
84
|
|
- try {
|
|
83
|
+
|
|
84
|
+ raw = new Raw(this);
|
|
85
|
+
|
|
86
|
+ try {
|
85
|
87
|
Thread thread = new Thread(parser);
|
86
|
88
|
thread.start();
|
87
|
89
|
} catch (Exception ex) {
|
|
@@ -89,14 +91,6 @@ public class Server implements IRCParser.IChannelSelfJoin, IRCParser.IErrorInfo
|
89
|
91
|
}
|
90
|
92
|
}
|
91
|
93
|
|
92
|
|
- /**
|
93
|
|
- * Called on destruction, the server unregisters itself with the ServerManager
|
94
|
|
- * @throws java.lang.Throwable ...
|
95
|
|
- */
|
96
|
|
- protected void finalize() throws Throwable {
|
97
|
|
- ServerManager.getServerManager().unregisterServer(this);
|
98
|
|
- }
|
99
|
|
-
|
100
|
94
|
/**
|
101
|
95
|
* Retrieves the parser used for this connection
|
102
|
96
|
* @return IRCParser this connection's parser
|
|
@@ -108,15 +102,46 @@ public class Server implements IRCParser.IChannelSelfJoin, IRCParser.IErrorInfo
|
108
|
102
|
public void addLine(String line) {
|
109
|
103
|
frame.addLine(line);
|
110
|
104
|
}
|
111
|
|
-
|
|
105
|
+
|
|
106
|
+ public void close(String reason) {
|
|
107
|
+ // Unregister parser callbacks
|
|
108
|
+ parser.delChannelSelfJoin(this);
|
|
109
|
+ parser.delErrorInfo(this);
|
|
110
|
+ // Disconnect from the server
|
|
111
|
+ disconnect(reason);
|
|
112
|
+ // Unregister ourselves with the server manager
|
|
113
|
+ ServerManager.getServerManager().unregisterServer(this);
|
|
114
|
+ // Close all channel windows
|
|
115
|
+ closeChannels();
|
|
116
|
+ // Close the raw window
|
|
117
|
+ raw.close();
|
|
118
|
+ // Close our own window
|
|
119
|
+ frame.setVisible(false);
|
|
120
|
+ MainFrame.getMainFrame().delChild(frame);
|
|
121
|
+ frame = null;
|
|
122
|
+ // Ditch the parser
|
|
123
|
+ parser = null;
|
|
124
|
+ }
|
|
125
|
+
|
|
126
|
+ public void disconnect(String reason) {
|
|
127
|
+ parser.quit(reason);
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ private void closeChannels() {
|
|
131
|
+ for (Channel channel : channels.values()) {
|
|
132
|
+ channel.close();
|
|
133
|
+ channels.remove(channel);
|
|
134
|
+ }
|
|
135
|
+ }
|
|
136
|
+
|
112
|
137
|
private void addChannel(ChannelInfo chan) {
|
113
|
138
|
channels.put(chan.getName(), new Channel(this, chan));
|
114
|
139
|
}
|
115
|
|
-
|
|
140
|
+
|
116
|
141
|
public void onChannelSelfJoin(IRCParser tParser, ChannelInfo cChannel) {
|
117
|
142
|
addChannel(cChannel);
|
118
|
143
|
}
|
119
|
|
-
|
|
144
|
+
|
120
|
145
|
public void onErrorInfo(IRCParser tParser, ParserError errorInfo) {
|
121
|
146
|
ErrorLevel errorLevel;
|
122
|
147
|
if (errorInfo.isFatal()) {
|