From c50328818fee0893d354932415062c02cff3da91 Mon Sep 17 00:00:00 2001 From: Ethan Stubbs <37120476+tgpethan@users.noreply.github.com> Date: Thu, 12 Aug 2021 01:44:18 +0100 Subject: [PATCH] uosodfsjfid --- index.js | 18 +++--------------- server/chunkManager.js | 22 +++++++++++++++++++++- server/server.js | 18 +++++++++++++++++- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 57a60ee..bb104e9 100644 --- a/index.js +++ b/index.js @@ -1,20 +1,8 @@ const server = new (require('net').Server)(); const config = require("./config.json"); -server.listen(config.port, function() { +const mcServer = require("./server/server.js"); -}); +server.listen(config.port, () => mcServer.init(config)); -server.on('connection', function(socket) { - socket.on('data', function(chunk) { - - }); - - socket.on('end', function() { - - }); - - socket.on('error', function(err) { - - }); -}); \ No newline at end of file +server.on('connection', mcServer.connection); \ No newline at end of file diff --git a/server/chunkManager.js b/server/chunkManager.js index 09a31ed..d3d13ba 100644 --- a/server/chunkManager.js +++ b/server/chunkManager.js @@ -1,5 +1,25 @@ module.exports = class { constructor() { - this.chunks = []; + this.chunks = {}; + + this.createChunk(0, 0); + } + + createChunk(x = 0, z = 0) { + this.chunks[x] = {}; + this.chunks[x][z] = {}; + + const chunk = this.chunks[x][z]; + for (let y = 0; y < 128; y++) { + chunk[y] = {}; + for (let x = 0; x < 16; x++) { + chunk[y][x] = {}; + for (let z = 0; z < 16; z++) { + chunk[y][x][z] = 0; + } + } + } + + console.log(chunk); } } \ No newline at end of file diff --git a/server/server.js b/server/server.js index 4a956a8..9f2758e 100644 --- a/server/server.js +++ b/server/server.js @@ -1,5 +1,21 @@ const bufferStuff = require("./bufferStuff.js") -module.exports = function() { +const Socket = require("net").Socket; +module.exports.init = function(config) { + console.log(`Up! Running at 0.0.0.0:${config.port}`); +} + +module.exports.connection = function(socket = new Socket) { + socket.on('data', function(chunk) { + console.log(chunk); + }); + + socket.on('end', function() { + console.log("Connection closed"); + }); + + socket.on('error', function(err) { + console.log("Connection error!"); + }); } \ No newline at end of file