diff --git a/server/Entities/EntityLiving.js b/server/Entities/EntityLiving.js new file mode 100644 index 0000000..37eae1b --- /dev/null +++ b/server/Entities/EntityLiving.js @@ -0,0 +1,15 @@ +const Entity = require("./Entity.js"); + +class EntityPlayer extends Entity { + constructor(x = 0, y = 0, z = 0) { + super(x, y, z); + + + } + + onTick() { + super.onTick(); + } +} + +module.exports = EntityPlayer; \ No newline at end of file diff --git a/server/Entities/EntityPlayer.js b/server/Entities/EntityPlayer.js new file mode 100644 index 0000000..7bd5b27 --- /dev/null +++ b/server/Entities/EntityPlayer.js @@ -0,0 +1,13 @@ +const EntityLiving = require("./EntityLiving.js"); + +class EntityPlayer extends EntityLiving { + constructor(itemID = 0x00, x = 0, y = 0, z = 0) { + super(x, y, z); + + this.motionX = (Math.random() * 0.2 - 0.1); + this.motionY = 0.2; + this.motionZ = (Math.random() * 0.2 - 0.1); + } +} + +module.exports = EntityPlayer; \ No newline at end of file diff --git a/server/bufferStuff.js b/server/bufferStuff.js index 811d3b7..9f6142f 100644 --- a/server/bufferStuff.js +++ b/server/bufferStuff.js @@ -1,3 +1,10 @@ +/* + ===========- bufferStuff.js -=========== + Created by Holly (tgpethan) (c) 2021 + Licensed under MIT + ======================================== +*/ + module.exports.Writer = class { constructor() { this.buffer = Buffer.alloc(0); @@ -60,7 +67,8 @@ module.exports.Writer = class { writeLong(data = 0) { const buff = Buffer.alloc(8); - buff.writeBigInt64BE(BigInt(data), 0); + if (data instanceof BigInt) buff.writeBigInt64BE(data, 0); + else buff.writeBigInt64BE(BigInt(data), 0); this.writeBuffer(buff); } diff --git a/server/server.js b/server/server.js index 8244f59..2ffa622 100644 --- a/server/server.js +++ b/server/server.js @@ -11,6 +11,7 @@ let idPool = 1; global.fromIDPool = function() { const oldVal = idPool; idPool++; + console.log(idPool); return oldVal; } @@ -52,6 +53,7 @@ module.exports.init = function(config) { if (tickCounter % tickRate == 0) { for (let key of netUserKeys) { netUsers[key].socket.write(new PacketMappingTable[NamedPackets.KeepAlive]().writePacket()); + } } // Update Chunks @@ -82,20 +84,22 @@ module.exports.init = function(config) { // Update users for (let key of netUserKeys) { - const user = netUsers[netUserKeys]; + const user = netUsers[key]; - let itemsToRemove = []; - for (let i = 0; i < Math.min(user.chunksToSend.getLength(), 128); i++) { - const chunkKey = user.chunksToSend.itemKeys[i]; - itemsToRemove.push(chunkKey); - user.socket.write(user.chunksToSend.items[chunkKey]); + if (user.loginFinished) { + let itemsToRemove = []; + for (let i = 0; i < Math.min(user.chunksToSend.getLength(), 128); i++) { + const chunkKey = user.chunksToSend.itemKeys[i]; + itemsToRemove.push(chunkKey); + user.socket.write(user.chunksToSend.items[chunkKey]); + } + + for (let item of itemsToRemove) { + user.chunksToSend.remove(item, false); + } + + user.chunksToSend.regenerateIterableArray(); } - - for (let item of itemsToRemove) { - user.chunksToSend.remove(item, false); - } - - user.chunksToSend.regenerateIterableArray(); } tickCounter++; @@ -108,7 +112,9 @@ module.exports.connection = async function(socket = new Socket) { socket.on('data', function(chunk) { const reader = new bufferStuff.Reader(chunk); - switch(reader.readByte()) { + const packetID = reader.readByte(); + + switch(packetID) { case NamedPackets.KeepAlive: socket.write(new PacketMappingTable[NamedPackets.KeepAlive]().writePacket()); break; @@ -151,6 +157,14 @@ module.exports.connection = async function(socket = new Socket) { socket.write(new PacketMappingTable[NamedPackets.Handshake](thisUser.username).writePacket()); break; + + case NamedPackets.Player: + + break; + + default: + console.log("0x" + packetID.toString(16)); + break; } });