aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.js9
1 files changed, 8 insertions, 1 deletions
diff --git a/index.js b/index.js
index d4db372..4453820 100644
--- a/index.js
+++ b/index.js
@@ -58,7 +58,7 @@ class KartikError extends Error {
const server = new Net.Server();
server.on('connection', (socket) => {
- socket.connectionId = (Math.random().toString(16).split(".")[1] + Math.random().toString(16).split(".")[1]).substr(0, 8);
+ socket.connectionId = (Math.random().toString(36).split(".")[1] + Math.random().toString(36).split(".")[1]).substr(0, 8);
socket.linkedTo = null;
clients[socket.connectionId] = socket;
console.log("New connection " + socket.connectionId)
@@ -254,6 +254,13 @@ server.on('connection', (socket) => {
switch (info['_type']) {
case "init":
throw new KartikError("Trying to initialize client but client is already initialized", "net.minteckprojects.kartik.KartikServer.AuthenticationException");
+ case "ping":
+ socket.write(JSON.stringify(
+ {
+ _type: "pong",
+ }
+ ) + "\n")
+ break;
case "link":
if (typeof info['client'] !== "string" || isNaN(parseInt(info['client'], 16))) {
throw new KartikError("Invalid client link ID", "net.minteckprojects.kartik.KartikServer.GuestIdentifierException");