mirror of
https://github.com/ayunami2000/ayunMultiPort.git
synced 2024-12-22 05:54:10 -08:00
add motd & icon support
This commit is contained in:
parent
bd6976be8b
commit
a55e3f317c
45
eagler.js
45
eagler.js
|
@ -1,21 +1,35 @@
|
||||||
const Net = require('net');
|
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 { WebSocketServer, WebSocket } = require('ws');
|
||||||
|
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const mime = require("mime-types");
|
const mime = require("mime-types");
|
||||||
const bufferReplace = require('buffer-replace');
|
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";
|
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 files = [];
|
||||||
let cache = {};
|
let cache = {};
|
||||||
|
|
||||||
|
@ -45,8 +59,15 @@ const httpsrv = require("http").createServer((req,res)=>{
|
||||||
res.end("404 Not Found");
|
res.end("404 Not Found");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const wss = new WebSocketServer({ server: httpsrv });
|
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) {
|
wss.on('connection', function(ws) {
|
||||||
ws.on('error', function(er) {});
|
ws.on('error', function(er) {});
|
||||||
|
|
||||||
|
@ -58,6 +79,12 @@ wss.on('connection', function(ws) {
|
||||||
ws.on('message', function(data) {
|
ws.on('message', function(data) {
|
||||||
if(msgNum==0){
|
if(msgNum==0){
|
||||||
msgNum++;
|
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"));
|
if(changeProtocol)data=bufferReplace(data,Buffer.from("0245","hex"),Buffer.from("023d","hex"));
|
||||||
}else if(msgNum==1){
|
}else if(msgNum==1){
|
||||||
msgNum++;
|
msgNum++;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"buffer-replace": "^1.0.0",
|
"buffer-replace": "^1.0.0",
|
||||||
|
"jimp": "^0.16.1",
|
||||||
"mime-types": "^2.1.35",
|
"mime-types": "^2.1.35",
|
||||||
"ws": "^8.5.0"
|
"ws": "^8.5.0"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user