Skip to content
This repository was archived by the owner on Feb 9, 2020. It is now read-only.

Commit 91061b3

Browse files
committed
kms
1 parent 2d11db7 commit 91061b3

14 files changed

Lines changed: 103 additions & 656 deletions

File tree

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pocketnode",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "Server software written in Javascript for Minecraft: PE",
55
"main": "src/pocketnode/PocketNode.js",
66
"scripts": {
@@ -18,8 +18,9 @@
1818
"license": "ISC",
1919
"dependencies": {
2020
"adm-zip": "^0.4.7",
21-
"raknet": "git+https://github.com/PocketNode/RakNet.git",
21+
"pocketnode-binarystream": "git+https://github.com/PocketNode/PocketNode-BinaryStream.git",
2222
"pocketnode-language": "git+https://github.com/PocketNode/PocketNode-Language.git",
23+
"raknet": "git+https://github.com/PocketNode/RakNet.git",
2324
"time-stamp": "^2.0.0"
2425
},
2526
"devDependencies": {

src/pocketnode/PocketNode.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ require("./utils/methods/Globals");
55
const Logger = pocketnode("logger/Logger");
66
const Server = pocketnode("Server");
77

8+
const g = global;
9+
810
function PocketNode(paths){
9-
this.START_TIME = Date.now();
10-
this.NAME = "PocketNode";
11-
this.CODENAME = "[BEGINNINGS]";
12-
this.VERSION = "0.0.4";
13-
this.API_VERSION = "1.0.0";
11+
global.pocketnode.START_TIME = Date.now();
12+
global.pocketnode.NAME = "PocketNode";
13+
global.pocketnode.CODENAME = "[BEGINNINGS]";
14+
global.pocketnode.VERSION = "0.0.4";
15+
global.pocketnode.API_VERSION = "1.0.0";
1416

1517
let logger = new Logger("Server");
1618
let path = {
@@ -27,10 +29,11 @@ function PocketNode(paths){
2729

2830
logger.info("Loading PocketNode...");
2931

30-
global.TRAVIS_BUILD = process.argv.indexOf("--travis-build") !== -1;
32+
global.pocketnode.TRAVIS_BUILD = process.argv.indexOf("--travis-build") !== -1;
33+
global.pocketnode.RUNNING_LOCALLY = (process.argv.indexOf("--local") !== -1 || process.argv.indexOf("-l") !== -1);
3134

32-
let server = new Server(this, logger, path);
33-
if(TRAVIS_BUILD === true){
35+
let server = new Server(logger, path);
36+
if(pocketnode.TRAVIS_BUILD === true){
3437
server.shutdown();
3538
}
3639

src/pocketnode/Server.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,16 @@ const SFS = pocketnode("utils/SimpleFileSystem");
2323

2424
class Server {
2525
initVars(){
26-
this.PocketNode = {};
27-
2826
this._bannedIps = {};
2927
this._bannedNames = {};
3028
this._ops = {};
3129
this._whitelist = {};
32-
30+
3331
this._running = true;
3432
this._stopped = false;
3533

3634
this._pluginManager = {};
37-
35+
3836
this._scheduler = {}; //todo
3937

4038
this._tickCounter = 0;
@@ -51,18 +49,18 @@ class Server {
5149
this._commandMap = {};
5250

5351
this._resourcePackManager = {};
54-
52+
5553
this._onlineMode = false;
5654

5755
this._raknetAdapter = {};
58-
56+
5957
this._serverId = Math.floor((Math.random() * 99999999)+1);
6058

6159
this._paths = {};
6260
this._config = {};
6361

6462
this._maxPlayers = -1;
65-
63+
6664
this._players = new PlayerList();
6765
this._loggedInPlayers = new PlayerList();
6866
this._playerList = new PlayerList();
@@ -72,10 +70,9 @@ class Server {
7270
this._entityCount = 0;
7371
}
7472

75-
constructor(PocketNode, logger, paths){
73+
constructor(logger, paths){
7674
this.initVars();
7775

78-
this.PocketNode = PocketNode;
7976
this._logger = logger;
8077
this._paths = paths;
8178

@@ -111,7 +108,7 @@ class Server {
111108
this._maxPlayers = this._config.getNested("server.max-players", 20);
112109
this._onlineMode = this._config.getNested("server.online-mode", true);
113110

114-
if(!TRAVIS_BUILD) process.stdout.write("\x1b]0;" + this.getName() + " " + this.getPocketNodeVersion() + "\x07");
111+
if(!pocketnode.TRAVIS_BUILD) process.stdout.write("\x1b]0;" + this.getName() + " " + this.getPocketNodeVersion() + "\x07");
115112

116113
this.getLogger().debug("Server Id:", this._serverId);
117114

@@ -148,7 +145,7 @@ class Server {
148145

149146
this._tickCounter = 0;
150147

151-
this.getLogger().info("Done ("+(Date.now() - this.PocketNode.START_TIME)+"ms)!");
148+
this.getLogger().info("Done ("+(Date.now() - pocketnode.START_TIME)+"ms)!");
152149

153150
this.tickProcessor();
154151
//this.forceShutdown();
@@ -183,21 +180,21 @@ class Server {
183180
* @return {string}
184181
*/
185182
getName(){
186-
return this.PocketNode.NAME;
183+
return pocketnode.NAME;
187184
}
188185

189186
/**
190187
* @return {string}
191188
*/
192189
getCodeName(){
193-
return this.PocketNode.CODENAME;
190+
return pocketnode.CODENAME;
194191
}
195192

196193
/**
197194
* @return {string}
198195
*/
199196
getPocketNodeVersion(){
200-
return this.PocketNode.VERSION;
197+
return pocketnode.VERSION;
201198
}
202199

203200
/**
@@ -218,7 +215,7 @@ class Server {
218215
* @return {string}
219216
*/
220217
getApiVersion(){
221-
return this.PocketNode.API_VERSION;
218+
return pocketnode.API_VERSION;
222219
}
223220

224221
/**
@@ -306,7 +303,7 @@ class Server {
306303
* @return {string}
307304
*/
308305
getMotd(){
309-
return this._config.getNested("server.motd", this.PocketNode.NAME + " Server");
306+
return this._config.getNested("server.motd", pocketnode.NAME + " Server");
310307
}
311308

312309
/**

src/pocketnode/level/chunk/Chunk.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const BinaryStream = pocketnode("utils/BinaryStream");
1+
const BinaryStream = pocketnode("network/minecraft/NetworkBinaryStream");
22
const SubChunk = pocketnode("level/chunk/SubChunk");
33
const EmptySubChunk = pocketnode("level/chunk/EmptySubChunk");
44

@@ -232,8 +232,17 @@ class Chunk {
232232
}
233233

234234
getFilledSubChunks(){
235-
this.pruneEmptySubChunks();
236-
return this._subChunks.size;
235+
//this.pruneEmptySubChunks();
236+
//return this._subChunks.size;
237+
let y;
238+
for(y = this._subChunks.size - 1; y >= 0; --y){
239+
if(this._subChunks.get(y) instanceof EmptySubChunk){
240+
continue;
241+
}
242+
break;
243+
}
244+
245+
return y + 1;
237246
}
238247

239248
pruneEmptySubChunks(){

src/pocketnode/network/PlayerSessionAdapter.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ const TextPacket = pocketnode("network/minecraft/protocol/TextPacket");
1515

1616
const ResourcePack = pocketnode("resourcepacks/ResourcePack");
1717

18-
const BinaryStream = pocketnode("utils/BinaryStream");
19-
2018
const Async = pocketnode("utils/Async");
2119

2220
class PlayerSessionAdapter {
@@ -126,7 +124,6 @@ class PlayerSessionAdapter {
126124
this.player.setViewDistance(packet.radius);
127125

128126
let distance = this.player.getViewDistance();
129-
let ccount = 1;
130127
for(let chunkX = -distance; chunkX <= distance; chunkX++) {
131128
for(let chunkZ = -distance; chunkZ <= distance; chunkZ++) {
132129
let chunk = new Chunk(chunkX, chunkZ);
@@ -145,11 +142,10 @@ class PlayerSessionAdapter {
145142
}
146143
}
147144

148-
chunk.recalculateHeightMap();
145+
//chunk.recalculateHeightMap();
149146
//if(chunkX === -distance && chunkZ === -distance) console.log(`${chunk.toBinary().length}`);// > ${chunk.toBinary().toString("hex")}`);
150147

151148
this.player.sendChunk(chunk);
152-
console.log(`sent chunk #${ccount++}`);
153149
}
154150
}
155151

src/pocketnode/network/RakNetAdapter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const RakNetServer = ((process.argv.indexOf("--local") !== -1 || process.argv.indexOf("-l") !== -1) ? require("../../../../RakNet") : require("raknet"));
1+
console.log(global.pocketnode.RUNNING_LOCALLY);
2+
3+
const RakNetServer = (pocketnode.RUNNING_LOCALLY ? require("../../../../RakNet") : require("raknet"));
24

35
const Logger = pocketnode("logger/Logger");
46

@@ -8,8 +10,6 @@ const BatchPacket = pocketnode("network/minecraft/protocol/BatchPacket");
810
const Player = pocketnode("player/Player");
911
const PlayerList = pocketnode("player/PlayerList");
1012

11-
const RakNet = raknet("RakNet");
12-
1313
class RakNetAdapter {
1414
constructor(server){
1515
this.server = server;
@@ -39,7 +39,7 @@ class RakNetAdapter {
3939
if(packet instanceof BatchPacket){
4040
let session;
4141
if((session = this.raknet.getSessionManager().getSessionByIdentifier(identifier))){
42-
session.queueConnectedPacket(packet, (needACK === true ? RakNet.FLAG_NEED_ACK : 0) | (immediate === true ? RakNet.PRIORITY_IMMEDIATE : RakNet.PRIORITY_NORMAL));
42+
session.queueConnectedPacketFromServer(packet, needACK, immediate);
4343
}
4444
return null;
4545
}else{
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const UUID = pocketnode("utils/UUID");
2+
3+
class NetworkBinaryStream extends (pocketnode.RUNNING_LOCALLY ? require("../../../../../PocketNode-BinaryStream") : require("pocketnode-binarystream")) {
4+
/**
5+
* @return {string}
6+
*/
7+
readString(){
8+
return this.read(this.readUnsignedVarInt()).toString();
9+
}
10+
11+
/**
12+
* @param v {string}
13+
* @return {NetworkBinaryStream}
14+
*/
15+
writeString(v){
16+
this.writeUnsignedVarInt(v.length);
17+
if(v.length === 0) return this;
18+
this.append(Buffer.from(v));
19+
return this;
20+
}
21+
22+
/**
23+
* @return {UUID}
24+
*/
25+
readUUID(){
26+
let [p1, p0, p3, p2] = [this.readLInt(), this.readLInt(), this.readLInt(), this.readLInt()];
27+
28+
return new UUID(p0, p1, p2, p3);
29+
}
30+
31+
/**
32+
* @param uuid {UUID}
33+
* @return {NetworkBinaryStream}
34+
*/
35+
writeUUID(uuid){
36+
this.writeLInt(uuid.getPart(1))
37+
.writeLInt(uuid.getPart(0))
38+
.writeLInt(uuid.getPart(3))
39+
.writeLInt(uuid.getPart(2));
40+
41+
return this;
42+
}
43+
44+
// todo everything else
45+
}
46+
47+
module.exports = NetworkBinaryStream;

src/pocketnode/network/minecraft/protocol/BatchPacket.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const DataPacket = pocketnode("network/minecraft/protocol/DataPacket");
2-
const BinaryStream = pocketnode("utils/BinaryStream");
2+
const BinaryStream = pocketnode("network/minecraft/NetworkBinaryStream");
33
const Zlib = require("zlib");
44

55
class BatchPacket extends DataPacket {
@@ -62,7 +62,7 @@ class BatchPacket extends DataPacket {
6262
getPackets(){
6363
let pks = [];
6464
while(!this.payload.feof()){
65-
pks.push(this.payload.readString(true));
65+
pks.push(this.payload.read(this.payload.readUnsignedVarInt()));
6666
}
6767
return pks;
6868
}

src/pocketnode/network/minecraft/protocol/DataPacket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const BinaryStream = pocketnode("utils/BinaryStream");
1+
const BinaryStream = pocketnode("network/minecraft/NetworkBinaryStream");
22
const Vector3 = pocketnode("math/Vector3");
33

44
class DataPacket extends BinaryStream {

0 commit comments

Comments
 (0)