forked from EnigmaticaModpacks/Enigmatica2Expert
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
252 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import fse from 'fs-extra' | ||
import { parse as parseNbt } from 'prismarine-nbt' | ||
|
||
import { globs } from '../build/build_utils' | ||
|
||
const { readFileSync } = fse | ||
|
||
// Get player data | ||
const playerDataList = globs('E:/mc/BBOP-Extended/playerdata/*.dat') | ||
const players = await Promise.all(playerDataList.map((filename) => { | ||
const p = parseNbt(readFileSync(filename)) | ||
p.then(() => process.stdout.write('.')) | ||
return p | ||
})) | ||
const fromSpawn = players.map((decoded, i) => { | ||
const [x, _y, z] = (decoded.parsed.value.Pos.value as any).value | ||
const dist = Math.sqrt(x ** 2 + z ** 2) | 0 | ||
if (dist > 100000) console.log('\n>100k :>> ', playerDataList[i]) | ||
return dist | ||
}) | ||
fromSpawn.sort((a, b) => a - b) | ||
console.log('\nfrom spawn :>> ', fromSpawn.reverse()) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* Find too far regions on server using SFTP and remove them | ||
* | ||
* Also show players positions | ||
*/ | ||
|
||
import chalk from 'chalk' | ||
import Client from 'ssh2-sftp-client' | ||
|
||
import { getBoxForLabel, pressEnterOrEsc } from '../../build/build_utils' | ||
import { | ||
loadJson, | ||
} from '../../lib/utils.js' | ||
import { filterForPrunning, pruneWorld, removeFilesOnServer } from './world' | ||
|
||
let updateBox = getBoxForLabel('sftp') | ||
|
||
const sftp = new Client() | ||
|
||
const sftpConfig = loadJson('secrets/sftp_servers/1. Guncolony/sftp.json') as { [key: string]: string } | ||
|
||
/************************************************ | ||
* Getting info | ||
************************************************/ | ||
updateBox('Connecting') | ||
await sftp.connect(sftpConfig) | ||
|
||
await pruneWorld(sftp, { | ||
title : 'Overworld', | ||
region : 'region', | ||
maxDistanceFromSpawn: 30000, | ||
obsoleteMonths : 6, | ||
}) | ||
|
||
await pruneWorld(sftp, { | ||
title : 'The Nether', | ||
region : 'DIM-1/region', | ||
maxDistanceFromSpawn: 5000, | ||
obsoleteMonths : 6, | ||
}) | ||
|
||
await pruneWorld(sftp, { | ||
title : 'The End', | ||
region : 'DIM1/region', | ||
maxDistanceFromSpawn: 5000, | ||
obsoleteMonths : 6, | ||
}) | ||
|
||
await pruneWorld(sftp, { | ||
title : 'Twilight Forest', | ||
region : 'DIM7/region', | ||
maxDistanceFromSpawn: 10000, | ||
obsoleteMonths : 6, | ||
}) | ||
|
||
await pruneWorld(sftp, { | ||
title : 'Deep Dark', | ||
region : 'DIM-11325/region', | ||
maxDistanceFromSpawn: 1000, | ||
obsoleteMonths : 3, | ||
}) | ||
|
||
await pruneWorld(sftp, { | ||
title : 'Ratlantis', | ||
region : 'DIM-8/region', | ||
maxDistanceFromSpawn: 3000, | ||
obsoleteMonths : 3, | ||
}) | ||
|
||
/************************************************ | ||
* Remove useless dimensions | ||
************************************************/ | ||
updateBox = getBoxForLabel('Prune dimensions') | ||
updateBox('Getting list') | ||
const advRocketryDims = filterForPrunning(await sftp.list('/BBOP-Extended/advRocketry'), f => f.name.startsWith('DIM') && f.name !== 'DIM-2') | ||
|
||
updateBox( | ||
'AR dimension to remove: ', | ||
advRocketryDims.list.map(f => chalk.green(f.substring(3))).join(chalk.gray(', ')) | ||
) | ||
|
||
if (await pressEnterOrEsc(`Press ENTER to remove ALL AdvRock dimensions except Space Stations. Press ESC to skip.`)) { | ||
updateBox = getBoxForLabel(`Task: ${chalk.yellow`Remove Adv. Rocketry worlds`}`) | ||
await removeFilesOnServer( | ||
sftp, | ||
advRocketryDims.list.map(f => `/BBOP-Extended/advRocketry/${f}`), | ||
fileCounter => updateBox('Removing files', fileCounter, '/', advRocketryDims.list.length), | ||
updateBox | ||
) | ||
} | ||
|
||
/************************************************ | ||
* Done | ||
************************************************/ | ||
updateBox = getBoxForLabel('sftp') | ||
updateBox('Done!') | ||
await sftp.end() | ||
process.exit(0) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import type Client from 'ssh2-sftp-client' | ||
|
||
import chalk from 'chalk' | ||
|
||
import { getBoxForLabel, pressEnterOrEsc } from '../../build/build_utils' | ||
|
||
export async function pruneWorld( | ||
sftp: Client, | ||
config: { | ||
maxDistanceFromSpawn: number | ||
obsoleteMonths : number | ||
region : string | ||
title : string | ||
} | ||
) { | ||
let updateBox = getBoxForLabel(`Prunning ${config.title}`) | ||
updateBox('Getting list') | ||
const regions = await sftp.list(`/BBOP-Extended/${config.region}`) | ||
updateBox('Connected!') | ||
|
||
function fileSizeText(size:number) { | ||
return `${(size / 1048576) | 0}mb` | ||
} | ||
|
||
async function pruneTask(taskName:string, predicate: (f:Client.FileInfo)=>boolean) { | ||
const pruneData = filterForPrunning(regions, predicate) | ||
|
||
updateBox = getBoxForLabel(taskName) | ||
updateBox( | ||
chalk.gray`Filtering / Total:`, | ||
chalk.green(pruneData.list.length), | ||
chalk.gray`/`, | ||
`${chalk.green(regions.length)}\n`, | ||
chalk.gray`Total size: `, | ||
`${chalk.green(fileSizeText(pruneData.size))}` | ||
) | ||
|
||
if (await pressEnterOrEsc(`Press ENTER to remove filtered regions. Press ESC to skip.`)) { | ||
updateBox = getBoxForLabel(`Task: ${chalk.yellow`Remove Overworld regions`}`) | ||
await removeFilesOnServer( | ||
sftp, | ||
pruneData.list.map(f => `/BBOP-Extended/${config.region}/${f}`), | ||
fileCounter => updateBox('Removing files', fileCounter, '/', pruneData.list.length), | ||
updateBox | ||
) | ||
return pruneData.list | ||
} | ||
} | ||
|
||
/************************************************ | ||
* Remove distant regions | ||
************************************************/ | ||
const removed = await pruneTask(`Prune by distance >${config.maxDistanceFromSpawn}`, (f) => { | ||
const [x, z] = f.name.split('.').slice(1, 3).map(Number) | ||
return Math.sqrt(x * x + z * z) > config.maxDistanceFromSpawn / 512 | ||
}) | ||
|
||
/************************************************ | ||
* Remove unupdated regions | ||
************************************************/ | ||
const currentDate = new Date().valueOf() | ||
await pruneTask(`Prune if older ${config.obsoleteMonths} month`, (f) => { | ||
if (removed?.includes(f.name)) return false | ||
const monthsPast = new Date(currentDate - f.modifyTime).getMonth() | ||
return monthsPast >= config.obsoleteMonths | ||
}) | ||
} | ||
|
||
export function filterForPrunning(list: Client.FileInfo[], predicate: (f:Client.FileInfo)=>boolean) { | ||
let pruneTotalSize = 0 | ||
const filtered = list | ||
.filter((f) => { | ||
const toRemoval = predicate(f) | ||
if (toRemoval) pruneTotalSize += f.size | ||
return toRemoval | ||
}) | ||
.map(f => f.name).sort() | ||
return { | ||
list: filtered, | ||
size: pruneTotalSize, | ||
} | ||
} | ||
|
||
export async function removeFilesOnServer( | ||
sftp:Client, | ||
list: string[], | ||
onRemove: (fileCounter: number)=>void, | ||
log:(...args: any[]) => void | ||
) { | ||
log('Removing files: ', '0', '/', list.length) | ||
|
||
let fileCounter = 0 | ||
await Promise.all(list.map((f) => { | ||
const p = sftp.delete(f) | ||
p.then(() => onRemove(++fileCounter)) | ||
return p | ||
})) | ||
|
||
log('Removed files: ', fileCounter) | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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