Created
July 16, 2012 23:11
-
-
Save Vbitz/3125699 to your computer and use it in GitHub Desktop.
not working mc server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var net = require("net"); | |
| var type = Function.prototype.call.bind( Object.prototype.toString ); | |
| function kickPlayer (c, player, reason) { | |
| if (player !== null) { | |
| } | |
| console.log("Kicking " + player + " with reason " + reason); | |
| c.end(writeBufferData(0xFF, [reason])); | |
| } | |
| function swapBytes(buffer) { | |
| var l = buffer.length; | |
| if (l & 0x01) { | |
| throw new Error('Buffer length must be even'); | |
| } | |
| for (var i = 0; i < l; i += 2) { | |
| var a = buffer[i]; | |
| buffer[i] = buffer[i+1]; | |
| buffer[i+1] = a; | |
| } | |
| //console.log(buffer.toString()); | |
| return buffer; | |
| } | |
| function writeString(str, buf, offset) { | |
| if (str.length & 0x01) { | |
| str = str + " "; | |
| } | |
| var buf2 = new Buffer(str); | |
| buf2 = swapBytes(buf2); | |
| buf.writeInt16BE(str.length, offset); | |
| buf2.copy(buf, offset + 2); | |
| return buf; | |
| } | |
| function writeBufferData(ty, data) { | |
| var size = 1; | |
| for (var i = 0; i < data.length; i++) { | |
| var it = data[i]; | |
| if (type(it) == "[object String]") { | |
| size += 2; | |
| size += it.length; | |
| } | |
| } | |
| var buf = new Buffer(size); | |
| buf.writeUInt8(ty, 0); | |
| var offset = 1; | |
| for (var x = 0; x < data.length; x++) { | |
| var it2 = data[x]; | |
| if (type(it2) == "[object String]") { | |
| buf = writeString(it2, buf, offset); | |
| offset += 2; | |
| offset += it2.length; | |
| } | |
| } | |
| console.log(buf); | |
| return buf; | |
| } | |
| handles = { | |
| 0x00: function(c, data) { | |
| console.log("Packet Type: Keep Alive"); | |
| }, | |
| 0x01: function(c, data) { | |
| console.log("Packet Type: Login Request"); | |
| }, | |
| 0x02: function(c, data) { | |
| console.log("Packet Type: Handshake"); | |
| c.write(writeBufferData(0x02, [ | |
| "-" | |
| ])); | |
| }, | |
| 0x03: function(c, data) { | |
| console.log("Packet Type: Chat Message"); | |
| }, | |
| 0x04: function(c, data) { | |
| console.log("Packet Type: Time Update"); | |
| }, | |
| 0x05: function(c, data) { | |
| console.log("Packet Type: Entity Equipment"); | |
| }, | |
| 0x06: function(c, data) { | |
| console.log("Packet Type: Spawn Position"); | |
| }, | |
| 0x07: function(c, data) { | |
| console.log("Packet Type: Use Entity"); | |
| }, | |
| 0x08: function(c, data) { | |
| console.log("Packet Type: Update Health"); | |
| }, | |
| 0x09: function(c, data) { | |
| console.log("Packet Type: Respawn"); | |
| }, | |
| 0x0A: function(c, data) { | |
| console.log("Packet Type: Player"); | |
| }, | |
| 0x0B: function(c, data) { | |
| console.log("Packet Type: Player Position"); | |
| }, | |
| 0x0C: function(c, data) { | |
| console.log("Packet Type: Player Look"); | |
| }, | |
| 0x0D: function(c, data) { | |
| console.log("Packet Type: Player Position & Look"); | |
| }, | |
| 0x0E: function(c, data) { | |
| console.log("Packet Type: Player Digging"); | |
| }, | |
| 0x0F: function(c, data) { | |
| console.log("Packet Type: Player Block Placement"); | |
| }, | |
| 0x10: function(c, data) { | |
| console.log("Packet Type: Held Item Change"); | |
| }, | |
| 0x11: function(c, data) { | |
| console.log("Packet Type: Use Bed"); | |
| }, | |
| 0x12: function(c, data) { | |
| console.log("Packet Type: Animation"); | |
| }, | |
| 0x13: function(c, data) { | |
| console.log("Packet Type: Entity Action"); | |
| }, | |
| 0x14: function(c, data) { | |
| console.log("Packet Type: Spawn Named Entity"); | |
| }, | |
| 0x15: function(c, data) { | |
| console.log("Packet Type: Spawn Dropped Item"); | |
| }, | |
| 0x16: function(c, data) { | |
| console.log("Packet Type: Collect Item"); | |
| }, | |
| 0x17: function(c, data) { | |
| console.log("Packet Type: Spawn Object/Vehicle"); | |
| }, | |
| 0x18: function(c, data) { | |
| console.log("Packet Type: Spawn Mob"); | |
| }, | |
| 0x19: function(c, data) { | |
| console.log("Packet Type: Spawn Painting"); | |
| }, | |
| 0x1A: function(c, data) { | |
| console.log("Packet Type: Spawn Experience Orb"); | |
| }, | |
| 0x1C: function(c, data) { | |
| console.log("Packet Type: Entity Velocity"); | |
| }, | |
| 0x1D: function(c, data) { | |
| console.log("Packet Type: Destroy Entity"); | |
| }, | |
| 0x1E: function(c, data) { | |
| console.log("Packet Type: Entity"); | |
| }, | |
| 0x1F: function(c, data) { | |
| console.log("Packet Type: Entity Relative Move"); | |
| }, | |
| 0x20: function(c, data) { | |
| console.log("Packet Type: Entity Look"); | |
| }, | |
| 0x21: function(c, data) { | |
| console.log("Packet Type: Entity Look and Relative Move"); | |
| }, | |
| 0x22: function(c, data) { | |
| console.log("Packet Type: Entity Teleport"); | |
| }, | |
| 0x23: function(c, data) { | |
| console.log("Packet Type: Entity Head Look"); | |
| }, | |
| 0x26: function(c, data) { | |
| console.log("Packet Type: Entity Status"); | |
| }, | |
| 0x27: function(c, data) { | |
| console.log("Packet Type: Attach Entity"); | |
| }, | |
| 0x28: function(c, data) { | |
| console.log("Packet Type: Entity Metadata"); | |
| }, | |
| 0x29: function(c, data) { | |
| console.log("Packet Type: Entity Effect"); | |
| }, | |
| 0x2A: function(c, data) { | |
| console.log("Packet Type: Remove Entity Effect"); | |
| }, | |
| 0x2B: function(c, data) { | |
| console.log("Packet Type: Set Experience"); | |
| }, | |
| 0x32: function(c, data) { | |
| console.log("Packet Type: Chunk Allocation"); | |
| }, | |
| 0x33: function(c, data) { | |
| console.log("Packet Type: Chunk Data"); | |
| }, | |
| 0x34: function(c, data) { | |
| console.log("Packet Type: Multi Block Change"); | |
| }, | |
| 0x35: function(c, data) { | |
| console.log("Packet Type: Block Change"); | |
| }, | |
| 0x36: function(c, data) { | |
| console.log("Packet Type: Block Action"); | |
| }, | |
| 0x3C: function(c, data) { | |
| console.log("Packet Type: Explosion"); | |
| }, | |
| 0x3D: function(c, data) { | |
| console.log("Packet Type: Sound/Particle Effect"); | |
| }, | |
| 0x46: function(c, data) { | |
| console.log("Packet Type: Change Game State"); | |
| }, | |
| 0x47: function(c, data) { | |
| console.log("Packet Type: Thunderbolt"); | |
| }, | |
| 0x64: function(c, data) { | |
| console.log("Packet Type: Open Window"); | |
| }, | |
| 0x65: function(c, data) { | |
| console.log("Packet Type: Close Window"); | |
| }, | |
| 0x66: function(c, data) { | |
| console.log("Packet Type: Click Window"); | |
| }, | |
| 0x67: function(c, data) { | |
| console.log("Packet Type: Set Slot"); | |
| }, | |
| 0x68: function(c, data) { | |
| console.log("Packet Type: Set Window Items"); | |
| }, | |
| 0x69: function(c, data) { | |
| console.log("Packet Type: Update Window Property"); | |
| }, | |
| 0x6A: function(c, data) { | |
| console.log("Packet Type: Confirm Transaction"); | |
| }, | |
| 0x6B: function(c, data) { | |
| console.log("Packet Type: Creative Inventory Action"); | |
| }, | |
| 0x6C: function(c, data) { | |
| console.log("Packet Type: Enchant Item"); | |
| }, | |
| 0x82: function(c, data) { | |
| console.log("Packet Type: Update Sign"); | |
| }, | |
| 0x83: function(c, data) { | |
| console.log("Packet Type: Item Data"); | |
| }, | |
| 0x84: function(c, data) { | |
| console.log("Packet Type: Update Tile Entity"); | |
| }, | |
| 0xC8: function(c, data) { | |
| console.log("Packet Type: Increment Statistic"); | |
| }, | |
| 0xC9: function(c, data) { | |
| console.log("Packet Type: Player List Item"); | |
| }, | |
| 0xCA: function(c, data) { | |
| console.log("Packet Type: Player Abilities"); | |
| }, | |
| 0xFA: function(c, data) { | |
| console.log("Packet Type: Plugin Message"); | |
| }, | |
| 0xFE: function(c, data) { | |
| console.log("Packet Type: Server List Ping"); | |
| kickPlayer(c, null, "Testing Server§0§8"); | |
| }, | |
| 0xFF: function(c, data) { | |
| console.log("Packet Type: Disconnect/Kick"); | |
| } | |
| }; | |
| var server = net.createServer(function (c) { | |
| c.on("data", function (data) { | |
| packetType = data.readUInt8(0); | |
| if (handles[packetType] !== undefined) { | |
| handles[packetType](c, data); | |
| } else { | |
| console.warn("Packet not handled: " + packetType); | |
| } | |
| console.log(c.bytesRead + " : " + c.bytesWritten); | |
| }); | |
| }); | |
| server.listen(22342, function () { | |
| console.log("Minecraft Server listening on port 22342"); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment