mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 06:45:42 +00:00
Bug 261696 - Use state variable for connection information, making /cancel work better.
ChatZilla only. r=samuel@sieb.net
This commit is contained in:
parent
6fbab3cc29
commit
045d7584fa
@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
const JSIRC_ERR_NO_SOCKET = "JSIRCE:NS";
|
const JSIRC_ERR_NO_SOCKET = "JSIRCE:NS";
|
||||||
const JSIRC_ERR_EXHAUSTED = "JSIRCE:E";
|
const JSIRC_ERR_EXHAUSTED = "JSIRCE:E";
|
||||||
|
const JSIRC_ERR_CANCELLED = "JSIRCE:C";
|
||||||
|
|
||||||
function userIsMe (user)
|
function userIsMe (user)
|
||||||
{
|
{
|
||||||
@ -74,6 +75,17 @@ function decodeParam(number, charsetOrObject)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var i = 1;
|
||||||
|
|
||||||
|
const NET_OFFLINE = i++; // Initial, disconected.
|
||||||
|
const NET_WAITING = i++; // Waiting before trying.
|
||||||
|
const NET_CONNECTING = i++; // Trying a connect...
|
||||||
|
const NET_CANCELLING = i++; // Cancelling connect.
|
||||||
|
const NET_ONLINE = i++; // Connected ok.
|
||||||
|
const NET_DISCONNECTING = i++; // Disconnecting.
|
||||||
|
|
||||||
|
delete i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* irc network
|
* irc network
|
||||||
*/
|
*/
|
||||||
@ -87,7 +99,7 @@ function CIRCNetwork (name, serverList, eventPump)
|
|||||||
this.serverList = new Array();
|
this.serverList = new Array();
|
||||||
this.ignoreList = new Object();
|
this.ignoreList = new Object();
|
||||||
this.ignoreMaskCache = new Object();
|
this.ignoreMaskCache = new Object();
|
||||||
this.connecting = false;
|
this.state = NET_OFFLINE;
|
||||||
|
|
||||||
for (var i = 0; i < serverList.length; ++i)
|
for (var i = 0; i < serverList.length; ++i)
|
||||||
{
|
{
|
||||||
@ -174,6 +186,7 @@ function net_connect(requireSecurity)
|
|||||||
if ("primServ" in this && this.primServ.isConnected)
|
if ("primServ" in this && this.primServ.isConnected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
this.state = NET_CONNECTING;
|
||||||
this.connectAttempt = 0;
|
this.connectAttempt = 0;
|
||||||
this.nextHost = 0;
|
this.nextHost = 0;
|
||||||
var ev = new CEvent("network", "do-connect", this, "onDoConnect");
|
var ev = new CEvent("network", "do-connect", this, "onDoConnect");
|
||||||
@ -189,6 +202,28 @@ function net_quit (reason)
|
|||||||
this.primServ.logout(reason);
|
this.primServ.logout(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CIRCNetwork.prototype.cancel =
|
||||||
|
function net_cancel()
|
||||||
|
{
|
||||||
|
if (this.state == NET_ONLINE)
|
||||||
|
{
|
||||||
|
// Pull the plug on the current connection, or...
|
||||||
|
this.quit();
|
||||||
|
}
|
||||||
|
else if ((this.state == NET_CONNECTING) || (this.state == NET_WAITING))
|
||||||
|
{
|
||||||
|
this.state = NET_CANCELLING;
|
||||||
|
|
||||||
|
// ...try a reconnect (which will fail us).
|
||||||
|
var ev = new CEvent("network", "do-connect", this, "onDoConnect");
|
||||||
|
this.eventPump.addEvent(ev);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dd("Network cancel in odd state: " + this.state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handles a request to connect to a primary server.
|
* Handles a request to connect to a primary server.
|
||||||
*/
|
*/
|
||||||
@ -197,32 +232,49 @@ function net_doconnect(e)
|
|||||||
{
|
{
|
||||||
var c;
|
var c;
|
||||||
|
|
||||||
if ("primServ" in this && this.primServ.isConnected)
|
// Clear the timer, if there is one.
|
||||||
return true;
|
if ("reconnectTimer" in this)
|
||||||
|
{
|
||||||
|
clearTimeout(this.reconnectTimer);
|
||||||
|
delete this.reconnectTimer;
|
||||||
|
}
|
||||||
|
|
||||||
var ev;
|
var ev;
|
||||||
|
|
||||||
if ((this.connectAttempt++ >= this.MAX_CONNECT_ATTEMPTS) ||
|
if (this.state == NET_CANCELLING)
|
||||||
("cancelConnect" in this))
|
|
||||||
{
|
{
|
||||||
if ("reconnectTimer" in this)
|
if ("primServ" in this && this.primServ.connection)
|
||||||
{
|
this.primServ.connection.disconnect();
|
||||||
clearTimeout(this.reconnectTimer);
|
else
|
||||||
delete this.reconnectTimer;
|
this.state = NET_OFFLINE;
|
||||||
}
|
|
||||||
delete this.cancelConnect;
|
ev = new CEvent ("network", "error", this, "onError");
|
||||||
|
ev.server = this;
|
||||||
|
ev.debug = "Connect sequence was cancelled.";
|
||||||
|
ev.errorCode = JSIRC_ERR_CANCELLED;
|
||||||
|
this.eventPump.addEvent(ev);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("primServ" in this && this.primServ.isConnected)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (this.connectAttempt++ >= this.MAX_CONNECT_ATTEMPTS)
|
||||||
|
{
|
||||||
|
this.state = NET_OFFLINE;
|
||||||
|
|
||||||
ev = new CEvent ("network", "error", this, "onError");
|
ev = new CEvent ("network", "error", this, "onError");
|
||||||
ev.server = this;
|
ev.server = this;
|
||||||
ev.debug = "Connection attempts exhausted, giving up.";
|
ev.debug = "Connection attempts exhausted, giving up.";
|
||||||
ev.errorCode = JSIRC_ERR_EXHAUSTED;
|
ev.errorCode = JSIRC_ERR_EXHAUSTED;
|
||||||
this.eventPump.addEvent (ev);
|
this.eventPump.addEvent(ev);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.connecting = true; /* connection is considered "made" when serve
|
this.state = NET_CONNECTING; /* connection is considered "made" when server
|
||||||
* sends a 001 message (see server.on001) */
|
* sends a 001 message (see server.on001) */
|
||||||
|
|
||||||
var host = this.nextHost++;
|
var host = this.nextHost++;
|
||||||
if (host >= this.serverList.length)
|
if (host >= this.serverList.length)
|
||||||
@ -784,9 +836,13 @@ function serv_whois (target)
|
|||||||
CIRCServer.prototype.onDisconnect =
|
CIRCServer.prototype.onDisconnect =
|
||||||
function serv_disconnect(e)
|
function serv_disconnect(e)
|
||||||
{
|
{
|
||||||
if ((this.parent.connecting) ||
|
function stateChangeFn(network, state) {
|
||||||
|
network.state = state;
|
||||||
|
};
|
||||||
|
|
||||||
|
if ((this.parent.state == NET_CONNECTING) ||
|
||||||
/* fell off while connecting, try again */
|
/* fell off while connecting, try again */
|
||||||
(this.parent.primServ == this) &&
|
(this.parent.primServ == this) && (this.parent.state == NET_ONLINE) &&
|
||||||
(!("quitting" in this) && this.parent.stayingPower))
|
(!("quitting" in this) && this.parent.stayingPower))
|
||||||
{ /* fell off primary server, reconnect to any host in the serverList */
|
{ /* fell off primary server, reconnect to any host in the serverList */
|
||||||
var reconnectFn = function(server) {
|
var reconnectFn = function(server) {
|
||||||
@ -795,8 +851,13 @@ function serv_disconnect(e)
|
|||||||
"onDoConnect");
|
"onDoConnect");
|
||||||
server.parent.eventPump.addEvent(ev);
|
server.parent.eventPump.addEvent(ev);
|
||||||
};
|
};
|
||||||
|
setTimeout(stateChangeFn, 0, this.parent, NET_WAITING);
|
||||||
this.parent.reconnectTimer = setTimeout(reconnectFn, 15000, this);
|
this.parent.reconnectTimer = setTimeout(reconnectFn, 15000, this);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setTimeout(stateChangeFn, 0, this.parent, NET_OFFLINE);
|
||||||
|
}
|
||||||
|
|
||||||
e.server = this;
|
e.server = this;
|
||||||
e.set = "network";
|
e.set = "network";
|
||||||
@ -1165,7 +1226,7 @@ CIRCServer.prototype.on001 =
|
|||||||
function serv_001 (e)
|
function serv_001 (e)
|
||||||
{
|
{
|
||||||
this.parent.connectAttempt = 0;
|
this.parent.connectAttempt = 0;
|
||||||
this.parent.connecting = false;
|
this.parent.state = NET_ONLINE;
|
||||||
|
|
||||||
/* servers won't send a nick change notification if user was forced
|
/* servers won't send a nick change notification if user was forced
|
||||||
* to change nick while logging in (eg. nick already in use.) We need
|
* to change nick while logging in (eg. nick already in use.) We need
|
||||||
|
@ -588,25 +588,14 @@ function cmdCancel(e)
|
|||||||
{
|
{
|
||||||
var network = e.network;
|
var network = e.network;
|
||||||
|
|
||||||
if (!network.connecting)
|
if ((network.state != NET_CONNECTING) && (network.state != NET_WAITING))
|
||||||
{
|
{
|
||||||
display(MSG_NOTHING_TO_CANCEL, MT_ERROR);
|
display(MSG_NOTHING_TO_CANCEL, MT_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
network.cancelConnect = true;
|
|
||||||
display(getMsg(MSG_CANCELLING, network.unicodeName));
|
display(getMsg(MSG_CANCELLING, network.unicodeName));
|
||||||
if (network.isConnected())
|
network.cancel();
|
||||||
{
|
|
||||||
// Pull the plug on the current connection, or...
|
|
||||||
network.dispatch("disconnect");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// ...try a reconnect (which will fail us).
|
|
||||||
var ev = new CEvent("network", "do-connect", network, "onDoConnect");
|
|
||||||
network.eventPump.addEvent(ev);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cmdChanUserMode(e)
|
function cmdChanUserMode(e)
|
||||||
|
@ -1323,7 +1323,7 @@ function my_invite (e)
|
|||||||
CIRCNetwork.prototype.on433 = /* nickname in use */
|
CIRCNetwork.prototype.on433 = /* nickname in use */
|
||||||
function my_433 (e)
|
function my_433 (e)
|
||||||
{
|
{
|
||||||
if (e.params[2] == this.INITIAL_NICK && this.connecting)
|
if ((e.params[2] == this.INITIAL_NICK) && (this.state == NET_CONNECTING))
|
||||||
{
|
{
|
||||||
var newnick = this.INITIAL_NICK + "_";
|
var newnick = this.INITIAL_NICK + "_";
|
||||||
this.INITIAL_NICK = newnick;
|
this.INITIAL_NICK = newnick;
|
||||||
@ -1352,6 +1352,7 @@ CIRCNetwork.prototype.onError =
|
|||||||
function my_neterror (e)
|
function my_neterror (e)
|
||||||
{
|
{
|
||||||
var msg;
|
var msg;
|
||||||
|
var type = "ERROR";
|
||||||
|
|
||||||
if (typeof e.errorCode != "undefined")
|
if (typeof e.errorCode != "undefined")
|
||||||
{
|
{
|
||||||
@ -1364,16 +1365,20 @@ function my_neterror (e)
|
|||||||
case JSIRC_ERR_EXHAUSTED:
|
case JSIRC_ERR_EXHAUSTED:
|
||||||
msg = MSG_ERR_EXHAUSTED;
|
msg = MSG_ERR_EXHAUSTED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case JSIRC_ERR_CANCELLED:
|
||||||
|
msg = MSG_ERR_CANCELLED;
|
||||||
|
type = "INFO";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
msg = e.params[e.params.length - 1];
|
msg = e.params[e.params.length - 1];
|
||||||
|
|
||||||
this.connecting = false;
|
|
||||||
dispatch("sync-header");
|
dispatch("sync-header");
|
||||||
updateTitle();
|
updateTitle();
|
||||||
|
|
||||||
this.display (msg, "ERROR");
|
this.display(msg, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1381,7 +1386,6 @@ CIRCNetwork.prototype.onDisconnect =
|
|||||||
function my_netdisconnect (e)
|
function my_netdisconnect (e)
|
||||||
{
|
{
|
||||||
var msg;
|
var msg;
|
||||||
var reconnect = false;
|
|
||||||
|
|
||||||
if (typeof e.disconnectStatus != "undefined")
|
if (typeof e.disconnectStatus != "undefined")
|
||||||
{
|
{
|
||||||
@ -1417,7 +1421,6 @@ function my_netdisconnect (e)
|
|||||||
msg = getMsg(MSG_CLOSE_STATUS,
|
msg = getMsg(MSG_CLOSE_STATUS,
|
||||||
[this.getURL(), e.server.getURL(),
|
[this.getURL(), e.server.getURL(),
|
||||||
e.disconnectStatus]);
|
e.disconnectStatus]);
|
||||||
reconnect = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1430,7 +1433,7 @@ function my_netdisconnect (e)
|
|||||||
/* If we were only /trying/ to connect, and failed, just put an error on
|
/* If we were only /trying/ to connect, and failed, just put an error on
|
||||||
* the network tab. If we were actually connected ok, put it on all tabs.
|
* the network tab. If we were actually connected ok, put it on all tabs.
|
||||||
*/
|
*/
|
||||||
if (this.connecting)
|
if (this.state != NET_ONLINE)
|
||||||
{
|
{
|
||||||
this.busy = false;
|
this.busy = false;
|
||||||
updateProgress();
|
updateProgress();
|
||||||
|
@ -347,7 +347,7 @@ function updateClient()
|
|||||||
|
|
||||||
function updateNetwork()
|
function updateNetwork()
|
||||||
{
|
{
|
||||||
if (view.connecting)
|
if (view.state == client.mainWindow.NET_CONNECTING)
|
||||||
{
|
{
|
||||||
setText("status", MSG_CONNECTING);
|
setText("status", MSG_CONNECTING);
|
||||||
setAttribute("status","condition", "yellow");
|
setAttribute("status","condition", "yellow");
|
||||||
|
@ -2821,7 +2821,7 @@ function cli_connect(networkOrName, requireSecurity)
|
|||||||
return network;
|
return network;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (network.connecting)
|
if (network.state != NET_OFFLINE)
|
||||||
return network;
|
return network;
|
||||||
|
|
||||||
if (network.prefs["nickname"] == DEFAULT_NICK)
|
if (network.prefs["nickname"] == DEFAULT_NICK)
|
||||||
@ -2830,7 +2830,6 @@ function cli_connect(networkOrName, requireSecurity)
|
|||||||
if (!("connecting" in network))
|
if (!("connecting" in network))
|
||||||
network.display(getMsg(MSG_NETWORK_CONNECTING, name));
|
network.display(getMsg(MSG_NETWORK_CONNECTING, name));
|
||||||
|
|
||||||
network.connecting = true;
|
|
||||||
network.connect(requireSecurity);
|
network.connect(requireSecurity);
|
||||||
|
|
||||||
network.updateHeader();
|
network.updateHeader();
|
||||||
|
@ -561,6 +561,7 @@ msg.err.no.default = No default action for objects of type ``%S''.
|
|||||||
msg.err.no.match = No match for ``%S''.
|
msg.err.no.match = No match for ``%S''.
|
||||||
msg.err.no.socket = Error creating socket.
|
msg.err.no.socket = Error creating socket.
|
||||||
msg.err.exhausted = Connection attempts exhausted, giving up.
|
msg.err.exhausted = Connection attempts exhausted, giving up.
|
||||||
|
msg.err.cancelled = Connection process cancelled.
|
||||||
msg.err.badalias = Malformed alias: %S"
|
msg.err.badalias = Malformed alias: %S"
|
||||||
msg.err.no.ctcp.cmd = %S is not a valid CTCP function for this client
|
msg.err.no.ctcp.cmd = %S is not a valid CTCP function for this client
|
||||||
msg.err.no.ctcp.help = %S does not have any help information
|
msg.err.no.ctcp.help = %S does not have any help information
|
||||||
|
Loading…
Reference in New Issue
Block a user