From a55e3f317c8ccc7c1b18d4d1896e02f11c8c638d Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Thu, 14 Apr 2022 10:13:23 -0400 Subject: [PATCH] add motd & icon support --- eagler.js | 45 ++++++++++++++++++++++++++++++++++++--------- icon.png | Bin 0 -> 450 bytes package.json | 1 + 3 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 icon.png diff --git a/eagler.js b/eagler.js index 4f295d1..cfa2a1d 100644 --- a/eagler.js +++ b/eagler.js @@ -1,21 +1,35 @@ const Net = require('net'); -const listenPort = 25565; -const mcHost = "localhost"; -const mcPort = 25569; -const httpPort = 8080; -const timeout = 10000; -const changeProtocol = true; -const removeSkin = true; - const { WebSocketServer, WebSocket } = require('ws'); - const fs = require("fs"); const path = require("path"); const mime = require("mime-types"); const bufferReplace = require('buffer-replace'); +const crypto = require('crypto'); +const Jimp = require('jimp'); +const listenPort = 25565; +const mcHost = "localhost"; +const mcPort = 25569; +const serverName = "ayunMultiPort Server"; +const serverMotd = "line1\nline2"; +const serverMaxPlayers = 20; +const serverOnlinePlayers = 4; +const serverPlayers = ["Welcome to my", "ayunMultiPort-powered", "Eaglercraft server!"]; +const serverIcon = fs.readFileSync("icon.png"); // set to null for no icon. MUST be 64x64. +const httpPort = 8080; +const timeout = 10000; +const changeProtocol = true; +const removeSkin = true; const prefix = "www"; +let iconBuff = null; + +if(serverIcon!=null){ + Jimp.read(serverIcon, function (err, image) { + if(!err)iconBuff=Buffer.from(image.bitmap.data); + }); +} + let files = []; let cache = {}; @@ -45,8 +59,15 @@ const httpsrv = require("http").createServer((req,res)=>{ res.end("404 Not Found"); } }); + const wss = new WebSocketServer({ server: httpsrv }); +const motdBase = {data:{motd:serverMotd.split("\n"),cache:true,max:serverMaxPlayers,players:serverPlayers,icon:serverIcon!=null,online:serverOnlinePlayers},vers:"0.2.0",name:serverName,time:0,type:"motd",brand:"Eagtek",uuid:crypto.randomUUID(),cracked:true}; +function getMotd(){ + motdBase.time = Date.now(); + return JSON.stringify(motdBase); +} + wss.on('connection', function(ws) { ws.on('error', function(er) {}); @@ -58,6 +79,12 @@ wss.on('connection', function(ws) { ws.on('message', function(data) { if(msgNum==0){ msgNum++; + if(data.toString()=="Accept: MOTD"){ + ws.send(getMotd()); + if(serverIcon!=null)ws.send(iconBuff); + closeIt(); + return; + } if(changeProtocol)data=bufferReplace(data,Buffer.from("0245","hex"),Buffer.from("023d","hex")); }else if(msgNum==1){ msgNum++; diff --git a/icon.png b/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..4fe5567d55e3cac259a79e007a85b86be8a9d5e7 GIT binary patch literal 450 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sDEfH31!Z9ZwBhHy_8$B>G+x3e0#4jJ&cnE(Gj|LTd*Lo<@M zdY0_1R%lm<{p{oYJm$T>SW=!xlnR4qH;Y2%Lik6at%vVT^zm| zb!62muVG%dOEHU6!Fk1trW4=H4_PaCH}y)!?wPoWWs&NZLyNo3FMVrR++ z!o_d%Cbcj2J#^E%GV|tT?OLmvFS%i2Z#C;}-f@2w@qgU=PrhM^E7OE69t@MjIFTLd c899yp@8LyJ+NYmdKI;Vst0QjA>nE(I) literal 0 HcmV?d00001 diff --git a/package.json b/package.json index 98ec87a..2136084 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "dependencies": { "buffer-replace": "^1.0.0", + "jimp": "^0.16.1", "mime-types": "^2.1.35", "ws": "^8.5.0" }