-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathspiral.js
More file actions
90 lines (72 loc) · 2.63 KB
/
spiral.js
File metadata and controls
90 lines (72 loc) · 2.63 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const db = require("./lib/db");
const m = require("./lib/functions");
const cron = require('node-cron');
require('dotenv').config({path: './.env'});
const promiseExecutionUser = async () => {
u()
};
const promiseExecutionVillages = async () => {
v()
};
// players every 5 minutes
cron.schedule('*/5 * * * *', async () => {
promiseExecutionUser()
});
// villages every 30 minutes
cron.schedule('*/30 * * * *', () => {
promiseExecutionVillages();
});
async function v() {
// step 1, get all villages
let villages = await m.getVillages();
if(villages) {
villages.forEach(async element => {
// step 1.5, check if the village
let data = await m.getVillage(element.uuid);
if(data) {
let check = await m.villageExists(db, element.uuid);
if(!check) {
await m.insertVillage(db, element.uuid,data);
console.log(`[j-stats2] inserted village ${element.name}.`);
}
else {
// update data
await m.updateVillage(db, element.uuid,data);
console.log(`[j-stats2] updated village ${element.name}.`);
}
}
});
}
}
async function u() {
let server = await m.getServer();
// step 1.5, remove old entries and save the server player count
await m.purgeOldPings(db);
console.log(`[j-stats2] removed any old pings.`);
await m.insertPlayerCount(db, server.player_count);
console.log(`[j-stats2] pinged server with ${server.player_count} online.`);
// step 2, do shit with the players
server.players.forEach(async element => {
// get UUID
let muuid = await m.getMojangUser(element.name);
// ONLY PUT IN VALID ACCOUNTS
if(muuid) {
let data = await m.getUser(muuid.uuid)
// if its successful
if(data) {
let check = await m.playerExists(db,muuid.uuid);
if(!check) {
m.insertPlayer(db, muuid.uuid, data);
console.log(`[j-stats2] ${element.name} is now in the database`);
}
else {
m.updatePlayer(db, muuid.uuid, data);
console.log(`[j-stats2] ${element.name} global data updated`);
}
await m.purgeOldCoords(db);
await m.insertCoords(db, muuid.uuid, element.x, element.y, element.z, element.world)
console.log(`[j-stats2] ${element.name} coords logged`);
}
}
});
}