diff options
-rw-r--r-- | demo/brute.sh | 282 | ||||
-rw-r--r-- | index.js | 181 | ||||
-rw-r--r-- | logo.png | bin | 0 -> 1443 bytes | |||
-rw-r--r-- | logo.svg | 66 | ||||
-rw-r--r-- | package.json | 5 |
5 files changed, 390 insertions, 144 deletions
diff --git a/demo/brute.sh b/demo/brute.sh new file mode 100644 index 0000000..209ef37 --- /dev/null +++ b/demo/brute.sh @@ -0,0 +1,282 @@ +#!/bin/bash + +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js& +node host.js&
\ No newline at end of file @@ -12,13 +12,9 @@ class MessageBuffer { } isFinished() { - if ( - this.buffer.length === 0 || - this.buffer.indexOf(this.delimiter) === -1 - ) { - return true - } - return false + return this.buffer.length === 0 || + this.buffer.indexOf(this.delimiter) === -1; + } push(data) { @@ -58,23 +54,37 @@ class KartikError extends Error { const server = new Net.Server(); server.on('connection', (socket) => { - socket.connectionId = (Math.random().toString(36).split(".")[1] + Math.random().toString(36).split(".")[1]).substr(0, 8); + socket.connectionId = "ird-" + (Math.random().toString().split(".")[1] + Math.random().toString().split(".")[1]).substr(0, 4); while (Object.keys(clients).includes(socket.connectionId)) { - socket.connectionId = (Math.random().toString(36).split(".")[1] + Math.random().toString(36).split(".")[1]).substr(0, 8); + socket.connectionId = "ird-" + (Math.random().toString().split(".")[1] + Math.random().toString().split(".")[1]).substr(0, 4); } socket.linkedTo = null; clients[socket.connectionId] = socket; - console.log("New connection " + socket.connectionId) + console.log("New connection " + socket.connectionId + " (" + socket.remoteAddress + ")") - if (clients.length > 280) { - throw new KartikError("Server is full", "lt.ro.minteck.cutefox.kartik.KartikServer.IdentifierAllocationException"); + if (Object.keys(clients).length > 280) { + socket.write(JSON.stringify( + { + _type: "init", + name: "Kartik Server", + version: _version + "-iridium", + id: socket.connectionId, + modded: null + } + ) + "\n") + socket.write(JSON.stringify({ + _type: "error", + message: "Game server is full, please try again later", + type: "E_IRIDIUM_FULL" + }) + "\n") + return; } socket.write(JSON.stringify( { _type: "init", name: "Kartik Server", - version: _version, + version: _version + "-iridium", id: socket.connectionId, modded: null } @@ -83,12 +93,12 @@ server.on('connection', (socket) => { setTimeout(() => { try { if (socket.linkedTo === null) { - throw new KartikError("Not linked within 3 minutes", "lt.ro.minteck.cutefox.kartik.KartikServer.ClientConnectTimeoutException"); + throw new KartikError("Linking timed out", "E_IRIDIUM_LINKTO"); } } catch (e) { console.error(e); if (e.name !== "KartikError") { - e.ktype = "nodejs.lang." + e.name.replaceAll("Error", "Exception"); + e.ktype = "E_SYSTEM_" + e.name.toUpperCase().replaceAll("ERROR", ""); } socket.write(JSON.stringify({ _type: "error", @@ -99,119 +109,6 @@ server.on('connection', (socket) => { } }, 180000) - /*let received = ""; - socket.on("data", (data) => { - data = data.toString(); - - received = received + data.substr(1); - console.log("{{" + data + "}}"); - if (data.startsWith(":")) { - return; - } - try { - raw = chunk.toString().replaceAll("}{", "}|{"); - - datas = raw.split("|").filter(i => i.trim() !== ""); - datas.forEach((data) => { - try { - info = JSON.parse(data); - } catch(e) { - console.dir(data); - throw e; - } - - if (data.length > 1200) { - console.dir(data); - throw new KartikError("Received data is too long", "lt.ro.minteck.cutefox.kartik.KartikServer.DataLengthException"); - } - - if (typeof info['_type'] != "string") { - throw new KartikError("Invalid JSON data", "lt.ro.minteck.cutefox.kartik.KartikServer.JsonDataException"); - } - if (!socket.initialized) { - switch (info['_type']) { - case "init": - if (info['name'] !== "Kartik Core") { - throw new KartikError("Invalid client", "lt.ro.minteck.cutefox.kartik.KartikServer.AuthenticationException"); - } - if (!info.modded) { - console.log("Connection initialized. Client running " + info.name + " version " + info.version + ", official client"); - } else { - console.log("Connection initialized. Client running " + info.name + " version " + info.version + ", MODDED client"); - if (!AllowMods) { - console.log("Modded clients are not accepted"); - socket.end(); - } - } - socket.initialized = true; - break; - default: - throw new KartikError("Trying to receive data but client not initialized", "lt.ro.minteck.cutefox.kartik.KartikServer.AuthenticationException"); - } - } else { - switch (info['_type']) { - case "init": - throw new KartikError("Trying to initialize client but client is already initialized", "lt.ro.minteck.cutefox.kartik.KartikServer.AuthenticationException"); - case "link": - if (typeof info['client'] !== "string" || isNaN(parseInt(info['client'], 16))) { - throw new KartikError("Invalid client link ID", "lt.ro.minteck.cutefox.kartik.KartikServer.GuestIdentifierException"); - } - if (typeof clients[info['client']] === "undefined") { - throw new KartikError("Guest client not found", "lt.ro.minteck.cutefox.kartik.KartikServer.GuestConnectException"); - } - if (clients[info['client']].linkedTo === null) { - socket.linkedTo = clients[info['client']]; - clients[info['client']].linkedTo = socket; - socket.linkedTo.role = "host"; - socket.linkedTo.write(JSON.stringify( - { - _type: "linked", - role: "host", - ids: { - host: socket.linkedTo.connectionId, - guest: socket.connectionId - } - } - )) - socket.role = "guest"; - socket.write(JSON.stringify( - { - _type: "linked", - role: "guest", - ids: { - host: socket.linkedTo.connectionId, - guest: socket.connectionId - } - } - )) - console.log("Link created: (H) " + socket.connectionId + " <-> " + socket.linkedTo.connectionId + " (G)") - } else { - throw new KartikError("Client already linked to another client", "lt.ro.minteck.cutefox.kartik.KartikServer.GuestAllocationException") - } - break; - default: - if (socket.linkedTo === null) { - throw new KartikError("Client not linked to another client", "lt.ro.minteck.cutefox.kartik.KartikServer.DataRoutingException"); - } else { - socket.linkedTo.write(JSON.stringify(info)); - } - } - } - }) - } catch (e) { - console.error(e); - if (e.name !== "KartikError") { - e.ktype = "nodejs.lang." + e.name.replaceAll("Error", "Exception"); - } - socket.write(JSON.stringify({ - _type: "error", - message: e.message, - type: e.ktype - })) - socket.end(); - } - })*/ - let received = new MessageBuffer("\n") socket.on("data", data => { received.push(data) @@ -225,23 +122,21 @@ server.on('connection', (socket) => { try { info = JSON.parse(data); } catch(e) { - console.dir(data); throw e; } if (data.length > 1200) { - console.dir(data); - throw new KartikError("Received data is too long", "lt.ro.minteck.cutefox.kartik.KartikServer.DataLengthException"); + throw new KartikError("Payload too large", "E_IRIDIUM_PLSIZE"); } if (typeof info['_type'] != "string") { - throw new KartikError("Invalid JSON data", "lt.ro.minteck.cutefox.kartik.KartikServer.JsonDataException"); + throw new KartikError("Payload syntax error", "E_IRIDIUM_PLSYNTAX"); } if (!socket.initialized) { switch (info['_type']) { case "init": if (info['name'] !== "Kartik Core") { - throw new KartikError("Invalid client", "lt.ro.minteck.cutefox.kartik.KartikServer.AuthenticationException"); + throw new KartikError("Client brand not supported", "E_IRIDIUM_BRAND"); } if (!info.modded) { console.log("Connection initialized. Client running " + info.name + " version " + info.version + ", official client"); @@ -255,12 +150,12 @@ server.on('connection', (socket) => { socket.initialized = true; break; default: - throw new KartikError("Trying to receive data but client not initialized", "lt.ro.minteck.cutefox.kartik.KartikServer.AuthenticationException"); + throw new KartikError("Payload received too early", "E_IRIDIUM_PLEARLY"); } } else { switch (info['_type']) { case "init": - throw new KartikError("Trying to initialize client but client is already initialized", "lt.ro.minteck.cutefox.kartik.KartikServer.AuthenticationException"); + throw new KartikError("Initialization already completed", "E_IRIDIUM_REINIT"); case "ping": socket.write(JSON.stringify( { @@ -270,10 +165,10 @@ server.on('connection', (socket) => { break; case "link": if (typeof info['client'] !== "string" || isNaN(parseInt(info['client'], 36))) { - throw new KartikError("Invalid client link ID", "lt.ro.minteck.cutefox.kartik.KartikServer.GuestIdentifierException"); + throw new KartikError("Invalid initial payload data", "E_IRIDIUM_PLINIT"); } if (typeof clients[info['client']] === "undefined") { - throw new KartikError("Guest client not found", "lt.ro.minteck.cutefox.kartik.KartikServer.GuestConnectException"); + throw new KartikError("No such client", "E_IRIDIUM_NOTFOUND"); } if (clients[info['client']].linkedTo === null) { socket.linkedTo = clients[info['client']]; @@ -302,12 +197,12 @@ server.on('connection', (socket) => { ) + "\n") console.log("Link created: (H) " + socket.connectionId + " <-> " + socket.linkedTo.connectionId + " (G)") } else { - throw new KartikError("Client already linked to another client", "lt.ro.minteck.cutefox.kartik.KartikServer.GuestAllocationException") + throw new KartikError("Client is already linked", "E_IRIDIUM_ALLOC") } break; default: if (socket.linkedTo === null) { - throw new KartikError("Client not linked to another client", "lt.ro.minteck.cutefox.kartik.KartikServer.DataRoutingException"); + throw new KartikError("Client is not linked", "E_IRIDIUM_ROUTING"); } else { socket.linkedTo.write(JSON.stringify(info).replaceAll("<", "-").replaceAll(">", "-") + "\n"); } @@ -315,9 +210,11 @@ server.on('connection', (socket) => { } }) } catch (e) { - console.error(e); if (e.name !== "KartikError") { - e.ktype = "nodejs.lang." + e.name.replaceAll("Error", "Exception"); + console.error(e); + e.ktype = "E_SYSTEM_" + e.name.toUpperCase().replaceAll("ERROR", ""); + } else { + console.error(e.ktype + ": " + e.message) } socket.write(JSON.stringify({ _type: "error", @@ -363,5 +260,5 @@ server.on('connection', (socket) => { }) server.listen(ServerPort, () => { - console.log("Kartik Server " + _version + " listening for connections on 0.0.0.0:" + ServerPort) + console.log("Iridium " + _version + " listening for connections on 0.0.0.0:" + ServerPort) }) diff --git a/logo.png b/logo.png Binary files differnew file mode 100644 index 0000000..7de4b3a --- /dev/null +++ b/logo.png diff --git a/logo.svg b/logo.svg new file mode 100644 index 0000000..ea828ef --- /dev/null +++ b/logo.svg @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + width="48" + height="48" + viewBox="0 0 12.7 12.7" + version="1.1" + id="svg5" + inkscape:version="1.1 (c4e8f9ed74, 2021-05-24)" + sodipodi:docname="logo.svg" + inkscape:export-filename="/home/minteck/Projects/Iridium/logo.png" + inkscape:export-xdpi="96" + inkscape:export-ydpi="96" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg"> + <sodipodi:namedview + id="namedview7" + pagecolor="#ffffff" + bordercolor="#999999" + borderopacity="1" + inkscape:pageshadow="0" + inkscape:pageopacity="0" + inkscape:pagecheckerboard="0" + inkscape:document-units="mm" + showgrid="false" + units="px" + width="48px" + inkscape:zoom="9.0945048" + inkscape:cx="20.341954" + inkscape:cy="23.860562" + inkscape:window-width="1600" + inkscape:window-height="799" + inkscape:window-x="0" + inkscape:window-y="32" + inkscape:window-maximized="1" + inkscape:current-layer="layer1" /> + <defs + id="defs2" /> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <rect + style="fill:#2a0c04;fill-opacity:1;stroke-width:2.72165;paint-order:markers stroke fill" + id="rect846" + width="11.556395" + height="11.479961" + x="0.57426602" + y="0.60523003" + ry="1.2681922" /> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:8.46667px;line-height:1.25;font-family:sans-serif;fill:#de9533;fill-opacity:1;stroke:none;stroke-width:0.264583" + x="6.3535714" + y="9.0665751" + id="text6952"><tspan + sodipodi:role="line" + id="tspan6950" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.46667px;font-family:'Adobe Clean';-inkscape-font-specification:'Adobe Clean';text-align:center;text-anchor:middle;fill:#de9533;fill-opacity:1;stroke-width:0.264583" + x="6.3535714" + y="9.0665751">Rd</tspan></text> + </g> +</svg> diff --git a/package.json b/package.json index ad99ac2..3750dc8 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { "name": "iridium", - "version": "1.0.0", + "version": "2.1.0", "description": "A next-generation Kartik server, based on the original server", "main": "index.js", "scripts": { "test": "node index.js", - "run": "node index.js" + "run": "node index.js", + "build": "nexe index.js -o build/iridium" }, "keywords": [], "author": "", |