I am writing a battle.net client in XUL+Javascript+XPCOM, but I am having a problem. look at my code:
function login(username,password)
{
var listener = {
finished : function(data){
//document.getElementById('chat-area').value = data;
alert(data);
}
}
readAllFromSocket("useast.battle.net",6112,"\x03"+username+"\r\n\x03"+password+"\r\n",listener,username,password);
//document.getElementById('say-button').disabled = false
//document.getElementById('say-area').disabled = false
//
Question #1
}
function talk(whattosay) {
outstream.write(whattosay,whattosay.length);
}
function readAllFromSocket(host,port,outputData,listener)
{
try {
var transportService =
Components.classes["@mozilla.org/network/socket-transport-service;1"]
.getService(Components.interfaces.nsISocketTransportService);
var transport = transportService.createTransport(null,0,host,port,null);
var outstream = transport.openOutputStream(0,0,0);
outstream.write(outputData,outputData.length);
var stream = transport.openInputStream(0,0,0);
var instream = Components.classes["@mozilla.org/scriptableinputstream;1"]
.createInstance(Components.interfaces.nsIScriptableInputStream);
instream.init(stream);
var dataListener = {
data : "",
onStartRequest: function(request, context){},
onStopRequest: function(request, context, status){},
onDataAvailable: function(request, context, inputStream, offset, count){
this.data += instream.read(count);
listener.finished(this.data);
},
};
var pump = Components.
classes["@mozilla.org/network/input-stream-pump;1"].
createInstance(Components.interfaces.nsIInputStreamPump);
pump.init(stream, -1, -1, 0, 0, false);
pump.asyncRead(dataListener,null);
} catch (ex){
return ex;
}
}
Question #1: How do I disable and enable the button and textbox with javascript.
Question #2: Login doesnt work right now for some reason, it works in an html thing i made.