forked from mumud1/MiningBots-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.js
57 lines (47 loc) · 1.12 KB
/
client_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const http = require('http');
// const WebSocket = require('ws');
// const hostname = 'pre.bootcamp.tk.sg';
// const port = 9002;
const sendRequest = (path, method, params) => {
return new Promise((resolve, reject) => {
const options = {
hostname: hostname,
port: port,
path: `${path}?${new URLSearchParams(params).toString()}`,
method: method,
headers: {
'Content-Type': 'application/json'
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
resolve(JSON.parse(data));
});
});
req.on('error', (e) => {
reject(e);
});
req.end();
});
};
const main = async () => {
const playerKey = 716811849;
var playerId;
var gameId;
var factoryPosition;
var factoryId;
const miningBots = [];
try{
// Fetch game information
let response = await sendRequest('/games', 'GET', {});
const games = response;
console.log('Games:', games);
} catch (error) {
console.error('Error in main:', error);
}
};
main();