var io = require('socket.io-client');
function Client() {
// chunks
this.headers = { //headers for WebSocket connection.
'Origin': 'http://pixelzone.io'
};
}
Client.prototype = {
connect: function() {
var opt = {
headers: this.headers
};
if (this.agent) opt.agent = this.agent;
if (this.local_address) opt.localAddress = this.local_address;
this.socket = new io("ws://pixelzone.io:80", opt);
this.socket.on("connect", this.onConnect.bind(this))
this.socket.on("disconnect", this.onDisconnect.bind(this))
this.socket.on('captchaTest', function() {
this.disconnect();
});
},
disconnect: function() {
if (!this.socket) {
return false;
}
this.socket.close();
return true;
},
onConnect: function() {
console.log("Connected! (" + this.index + ")");
this.lastCheck = Date.now()
botss[this.index] = this
},
onDisconnect: function() {
console.log("Disconnected (" + this.index + ")");
delete botss[this.index]
},
updatePixel: function(x, y, color) {
if (Date.now() - this.lastCheck > 4000) {
console.log("Painted: " + x + " " + y + " From: " + this.index)
this.lastCheck = Date.now()
this.socket.emit('placePixel', {
x: x + 4096,
y: y + 4096,
val: color
});
}
}
}
module.exports = Client;