diff options
-rw-r--r-- | index.js | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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"); |