Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class {
this.didSendVersion = false;
this.logOutgoing = false;
this.logIncoming = false;
this.logDebugging = false;
this.incomingBuffers = [];
this.events = new EventEmitter();
this.events.on(0x00, packetHandlers.encryption)
Expand All @@ -43,7 +44,9 @@ export default class {
}

this.server = getServerFromAddress(address, port);
console.log(`Connecting to ${this.server.name}...`);
if (this.logDebugging) {
console.log(`Connecting to ${this.server.name}...`);
}

const socket = new net.Socket();
socket.on('data', this.receive.bind(this));
Expand All @@ -59,7 +62,7 @@ export default class {
});
}

disconnect(socket=this.socket) {
disconnect(socket = this.socket) {
socket.destroy();
}

Expand All @@ -81,8 +84,9 @@ export default class {
}

logIn() {
console.log(`Logging in as ${this.username}...`);

if (this.logDebugging) {
console.log(`Logging in as ${this.username}...`);
}
const key1 = random(0xFF);
const key2 = random(0xFF);
let clientId = random(0xFFFFFFFF);
Expand Down Expand Up @@ -153,7 +157,7 @@ export default class {
let buffer = Buffer.concat(this.incomingBuffers.splice(0));

while (buffer.length > 3 && buffer[0] === 0xAA) {
const length = buffer[1] << 8 | buffer[2] + 3;
const length = (buffer[1] << 8 | buffer[2]) + 3;

if (length > buffer.length) {
this.incomingBuffers.push(buffer);
Expand Down
22 changes: 16 additions & 6 deletions src/packet-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export default {

if (code === 1) {
client.appVersion -= 1;
console.log(`Invalid DA version, possibly too high. Trying again with ${client.appVersion}.`);
if (this.logDebugging) {
console.log(`Invalid DA version, possibly too high. Trying again with ${client.appVersion}.`);
}
client.reconnect();
return;
}
Expand All @@ -19,7 +21,9 @@ export default {
packet.readByte();
packet.readString8(); // patch url
client.appVersion = version;
console.log(`Your DA version is too low. Setting DA version to ${version}.`);
if (this.logDebugging) {
console.log(`Your DA version is too low. Setting DA version to ${version}.`);
}
client.reconnect();
return;
}
Expand All @@ -46,12 +50,16 @@ export default {
case 3: // Invalid name or password
case 14: // Name does not exist
case 15: // Incorrect password
console.log(`${message}.`);
if (this.logDebugging) {
console.log(`${message}.`);
}
client.disconnect();
break;
default:
console.log(message, `(code ${code})`);
console.log('Log in failed. Retrying...');
if (this.logDebugging) {
console.log(message, `(code ${code})`);
console.log('Log in failed. Retrying...');
}
setTimeout(() => client.reconnect(), 1000)
}
},
Expand Down Expand Up @@ -80,7 +88,9 @@ export default {
},

userId(packet, client) {
console.log(`Logged into ${client.server.name} as ${client.username}.`);
if (this.logDebugging) {
console.log(`Logged into ${client.server.name} as ${client.username}.`);
}
client.send(new Packet(0x2D));
},

Expand Down