Skip to content

Commit aa06895

Browse files
committed
Merge branch 'cli'
2 parents f6bedfc + 0d66df6 commit aa06895

26 files changed

+458
-339
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"package-all": "electron-packager . --overwrite --all --icon=public/assets/placeholder_icon.icns --prune=true --out=release-builds"
1515
},
1616
"dependencies": {
17-
"ajv": "^5.2.2",
17+
"ajv": "^6.10.2",
1818
"bcryptjs": "^2.4.3",
1919
"body-parser": "^1.15.2",
2020
"cookie-parser": "~1.4.3",

public/js/client/GUI.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ export class GUI {
335335

336336
let startPointWorld = startPoint.world();
337337
let endPointWorld = endPoint.world();
338-
let commandParameters = [startPointWorld.x, startPointWorld.y, startPointWorld.z, endPointWorld.x, endPointWorld.y, endPointWorld.z, selectionIndex, scanLevel];
338+
let commandParameters = [startPointWorld.x, startPointWorld.y, startPointWorld.z, endPointWorld.x, endPointWorld.y, endPointWorld.z, scanLevel, selectionIndex];
339339
this.sendCommand(commandName, commandParameters);
340340

341341
this.selectStart.clear();

public/js/server/SocketToAccountMap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class SocketToAccountMap {
5353
* @returns {boolean}
5454
*/
5555
removeClient(accountName, clientSocket) {
56+
clientSocket.removeAllListeners();
5657
var result = false;
5758
var account = this.accounts[accountName];
5859
if (account && account.clients) {

public/js/server/TestClient.js

Lines changed: 84 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const net = require('net');
22
const InventoryData = require('../shared/InventoryData');
33
const MapData = require('../shared/MapData');
4-
const validators = require('../shared/fromRobotSchemas.js');
4+
const keyToValidatorMap = require('../shared/fromRobotSchemas.js').keyToValidatorMap;
55

66
/**
77
* Used to make sure the server is working properly. Attempts to replicate
@@ -32,7 +32,12 @@ class TestClient {
3232
this.equipped;
3333
this.map = new MapData();
3434
this.map.setFromMapData(this.testData.map);
35-
this.position = this.testData.position;
35+
this.position = {
36+
x: this.testData.config.posX,
37+
y: this.testData.config.posY,
38+
z: this.testData.config.posZ,
39+
};
40+
this.config = this.testData.config;
3641
this.map.set(this.position.x, this.position.y, this.position.z, {"hardness": 2});
3742
this.components = this.testData.components;
3843

@@ -57,12 +62,12 @@ class TestClient {
5762

5863
this.commandMap = {
5964

60-
scanArea: (scanLevel)=>{
65+
scanArea: (scanLevel, times)=>{
6166
for (let i = -2; i <= 5; i++) {
6267
let scan = this.geolyzerScan(-3, -3, i, 8, 8, 1);
6368
this.send('map data', scan);
6469
}
65-
this.sendWithCost('command result', [true, 'area scanned']);
70+
this.sendWithCost('command result', ['map data', true]);
6671
},
6772

6873
viewInventory: ()=>{
@@ -71,11 +76,11 @@ class TestClient {
7176
this.send('inventory data', inventoryMeta);
7277

7378
for (let slotNum in this.inventory.slots) {
74-
let slotData = this.inventory.serializeSlot(slotNum);
79+
let slotData = this.inventory.serializeSlot(parseInt(slotNum));
7580
this.send('slot data', slotData);
7681
}
7782

78-
this.sendWithCost('command result', [true, 'all slot data sent']);
83+
this.sendWithCost('command result', ['inventory data', true]);
7984

8085
},
8186

@@ -89,31 +94,56 @@ class TestClient {
8994
let slotData = this.inventory.serializeSlot(this.inventory.selected);
9095
this.send('slot data', slotData);
9196

92-
this.sendWithCost('command result', [true, {label: 'test object', size: 4}]);
97+
this.sendWithCost('command result', ['equip', {label: 'test object', size: 4}]);
9398

9499
},
95100

96-
dig: (x1, y1, z1, x2, y2, z2, selectionIndex, scanLevel)=>{
101+
dig: (x1, y1, z1, x2, y2, z2, relative, scanLevel, selectionIndex,)=>{
102+
if (relative) {
103+
x1 += this.position.x;
104+
y1 += this.position.y;
105+
z1 += this.position.z;
106+
x2 += this.position.x;
107+
y2 += this.position.y;
108+
z2 += this.position.z;
109+
}
97110
let points = this.getBoxPoints(x1, y1, z1, x2, y2, z2);
98111
for (let point of points) {
99112
this.dig(point.x, point.y, point.z);
100113
this.send('dig success', point);
101114
}
102-
this.send('delete selection', selectionIndex);
103-
this.sendWithCost('command result', [true, 'digging done']);
115+
if (selectionIndex !== undefined) {
116+
this.send('delete selection', selectionIndex);
117+
}
118+
this.sendWithCost('command result', ['dig', true]);
104119
},
105120

106-
place: (x1, y1, z1, x2, y2, z2, selectionIndex, scanLevel)=>{
121+
place: (x1, y1, z1, x2, y2, z2, relative, scanLevel, selectionIndex,)=>{
122+
if (relative) {
123+
x1 += this.position.x;
124+
y1 += this.position.y;
125+
z1 += this.position.z;
126+
x2 += this.position.x;
127+
y2 += this.position.y;
128+
z2 += this.position.z;
129+
}
107130
let points = this.getBoxPoints(x1, y1, z1, x2, y2, z2);
108131
for (let point of points) {
109132
let blockData = this.place(point.x, point.y, point.z);
110133
this.send('block data', blockData);
111134
}
112-
this.send('delete selection', selectionIndex);
113-
this.sendWithCost('command result', [true, 'placing done']);
135+
if (selectionIndex !== undefined) {
136+
this.send('delete selection', selectionIndex);
137+
}
138+
this.sendWithCost('command result', ['place', true]);
114139
},
115140

116-
move: (x, y, z, scanLevel)=>{
141+
move: (x, y, z, relative, scanLevel)=>{
142+
if (relative) {
143+
x += this.position.x;
144+
y += this.position.y;
145+
z += this.position.z;
146+
}
117147
let result = this.move(x, y, z);
118148
if (result) {
119149
this.commandMap.scanArea();
@@ -126,26 +156,36 @@ class TestClient {
126156
}
127157
},
128158

129-
interact: (x, y, z, scanLevel)=>{
159+
interact: (x, y, z, relative, scanLevel)=>{
160+
if (relative) {
161+
x += this.position.x;
162+
y += this.position.y;
163+
z += this.position.z;
164+
}
130165
let blockData = this.inspect(x, y, z);
131166
if (blockData.name == 'minecraft:chest') {
132167
this.send('inventory data', this.testData.externalInventory.meta);
133168
for (let slotNum in this.inventories[3].slots) {
134-
let slot = this.inventories[3].serializeSlot(slotNum);
169+
let slot = this.inventories[3].serializeSlot(parseInt(slotNum));
135170
this.send('slot data', slot);
136171
}
137172
}
138-
this.sendWithCost('command result', [true, 'interact complete']);
173+
this.sendWithCost('command result', ['interact', true]);
139174
},
140175

141-
inspect: (x, y, z, scanLevel)=>{
176+
inspect: (x, y, z, relative, scanLevel)=>{
177+
if (relative) {
178+
x += this.position.x;
179+
y += this.position.y;
180+
z += this.position.z;
181+
}
142182
let blockData = this.inspect(x, y, z);
143183
this.sendWithCost('block data', blockData);
144184
},
145185

146186
select: (slotNum)=>{
147187
this.select(slotNum);
148-
this.sendWithCost('command result', [true, 'select complete']);
188+
this.sendWithCost('command result', ['select', true]);
149189
},
150190

151191
transfer: (fromSlotIndex, fromSide, toSlotIndex, toSide, amount)=>{
@@ -169,20 +209,20 @@ class TestClient {
169209
let toSlotData = toInv.serializeSlot(toSlotIndex);
170210
this.send('slot data', toSlotData);
171211

172-
this.sendWithCost('command result', [true, "transfer successful"]);
212+
this.sendWithCost('command result', ['transfer', true]);
173213
}
174214
else {
175-
this.sendWithCost('command result', [false, "transfer failed"]);
215+
this.sendWithCost('command result', ['transfer', false]);
176216
}
177217

178218
},
179219

180220
craft: (itemName)=>{
181-
this.sendWithCost('command result', [false, 'crafting not implemented']);
221+
this.sendWithCost('command result', ['craft', 'crafting not implemented']);
182222
},
183223

184224
raw: (commandString)=>{
185-
let resultData = [true, 'received command: ' + commandString];
225+
let resultData = ['raw', 'received command: ' + commandString];
186226
this.sendWithCost('command result', resultData);
187227
},
188228

@@ -196,6 +236,21 @@ class TestClient {
196236
this.sendWithCost('available components', components);
197237
},
198238

239+
config: (optionName, optionValue)=>{
240+
if (optionName && (optionValue !== undefined)) {
241+
this.config[optionName] = optionValue;
242+
this.sendWithCost('command result', ['config', true]);
243+
}
244+
else if (optionName) {
245+
let result = {};
246+
result[optionName] = this.config[optionName];
247+
this.sendWithCost('config', result);
248+
}
249+
else {
250+
this.sendWithCost('config', this.config);
251+
}
252+
},
253+
199254
};
200255

201256
this.socket.on('data', (rawMessages)=>{
@@ -458,21 +513,7 @@ class TestClient {
458513
* @param {any} value
459514
*/
460515
validate(key, value) {
461-
let keyToValidatorMap = {
462-
'inventory data': validators.inventoryMeta,
463-
'slot data': validators.inventorySlot,
464-
'command result': validators.commandResult,
465-
'robot position': validators.position,
466-
'available components': validators.components,
467-
'map data': validators.geolyzerScan,
468-
'id': validators.id,
469-
'message': validators.message,
470-
'power level': validators.powerLevel,
471-
'dig success': validators.digSuccess,
472-
'delete selection': validators.deleteSelection,
473-
'block data': validators.blockData,
474-
};
475-
keyToValidatorMap[key](value);
516+
return keyToValidatorMap[key](value);
476517
}
477518

478519
/**
@@ -482,7 +523,9 @@ class TestClient {
482523
*/
483524
send(key, value) {
484525

485-
this.validate(key, value);
526+
if (!this.validate(key, value)) {
527+
throw Error(`command ${key} failed to validate with value ${JSON.stringify(value)}`);
528+
};
486529

487530
const data = {
488531
[key]: value,
@@ -520,14 +563,14 @@ class TestClient {
520563
* so it can be checked in the unit tests.
521564
*/
522565
getID() {
523-
return {robot: this.testData.robotName, account: this.testData.accountName};
566+
return {robot: this.testData.config.robotName, account: this.testData.config.accountName};
524567
}
525568

526569
/**
527570
* Used to identify the test client to the server and open the socket connection.
528571
*/
529572
connect() {
530-
this.socket.connect(this.testData.port, this.testData.host);
573+
this.socket.connect(this.testData.config.tcpPort, this.testData.config.serverIP);
531574
}
532575

533576
/**

0 commit comments

Comments
 (0)