From 66e0db11bd981c94e8850642580a9681b2334ae4 Mon Sep 17 00:00:00 2001 From: jsrobson10 Date: Tue, 9 Apr 2019 21:03:05 +1000 Subject: [PATCH] Got stable, functional, reliable connection between the server. Fixed issues with JavaScript strings. --- index.js | 40 +++++++++++++++++++++++++++++----------- rsa.js | 6 ++++-- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index c7b0e3e..80a217b 100644 --- a/index.js +++ b/index.js @@ -191,11 +191,13 @@ function make_encryption_key(string) var key = new Object(); // Set the varibles - key.str = string; + key.str = toBuffer(string); key.at = new Object(); key.at.rx = 0; key.at.tx = 0; + console.log("make_encryption_key:", key.str); + // Return the key return key; } @@ -303,8 +305,8 @@ function connect(hostname, port=22068) if(g.sock_new != 0) { - // Split the data by newlines - data = JSON.parse(data.toString()); + // Parse the string + data = JSON.parse(toBytes(data)); // Is this the key if(data.mode == "encryption_key") @@ -314,6 +316,9 @@ function connect(hostname, port=22068) mode: "decrypt", data: data.key })); + + // Set sock new + g.sock_new = 0; } } @@ -322,14 +327,12 @@ function connect(hostname, port=22068) // Decrypt the data data = string_decrypt(g.encryption, data); - // Split the data by newlines - data = bsplit(data, Buffer.from("\n")); + // Convert it from JSON + data = JSON.parse(data); - // Iterate over them - for(var i=0;i