Skip to content

Commit

Permalink
half-update
Browse files Browse the repository at this point in the history
  • Loading branch information
LapisHusky committed Sep 17, 2023
1 parent 9682c0b commit 04b613d
Show file tree
Hide file tree
Showing 10 changed files with 605 additions and 221 deletions.
8 changes: 5 additions & 3 deletions ClientHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { TickCounter } from "./internalModules/TickCounter.js"
import { WorldTracker } from "./internalModules/WorldTracker.js"
import { ServerAgeTracker } from "./internalModules/ServerAgeTracker.js"
import { CustomModules } from "./internalModules/CustomModules.js"
//import { ChunkPreloader } from "./internalModules/ChunkPreloader.js"
import { ChunkPreloader } from "./internalModules/ChunkPreloader.js"
import { TabListHandler } from "./internalModules/TabListHandler.js"

export class ClientHandler extends EventEmitter {
constructor(userClient, proxy, id) {
Expand Down Expand Up @@ -57,8 +58,9 @@ export class ClientHandler extends EventEmitter {
this.betterGameInfo = new BetterGameInfo(this)
this.consoleLogger = new ConsoleLogger(this)
this.serverAgeTracker = new ServerAgeTracker(this)
//this.chunkPreloader = new ChunkPreloader(this)
this.chunkPreloader = new ChunkPreloader(this)
this.customModules = new CustomModules(this)
this.tabListHandler = new TabListHandler(this)

this.bindEventListeners()
}
Expand Down Expand Up @@ -211,7 +213,7 @@ function randomSalt() {
// Generate two random 32-bit integers
let upperInt = Math.floor(Math.random() * 0x80000000);
let lowerInt = Math.floor(Math.random() * 0x100000000);

// Combine them into a 64-bit BigInt
let combinedInt = BigInt(upperInt) << 32n | BigInt(lowerInt);

Expand Down
4 changes: 2 additions & 2 deletions commands/commandExit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { saveData } from "../data/dataHandler.js"
//import { saveChunks } from "../data/chunkCacheHandler.js"
import { saveChunks } from "../data/chunkCacheHandler.js"

export const name = "exit"
export const aliases = ["quit", "end", "q"]
Expand All @@ -9,6 +9,6 @@ export const requireTrust = true
export async function run(usageInstance) {
usageInstance.reply("§7Exiting...")
await saveData()
//await saveChunks()
await saveChunks()
process.exit()
}
2 changes: 1 addition & 1 deletion config/configHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export let configFileWorking = false
try {
let tempConfig = fs.readFileSync("./config.yml", "utf8")
tempConfig = YAML.parse(tempConfig)
if (tempConfig["config-version"] !== 3) throw {code: "OUTDATED_CONFIG"}
if (tempConfig["config-version"] !== 4) throw {code: "OUTDATED_CONFIG"}
replaceConfig(tempConfig)
configFileWorking = true
} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions data/chunkCacheHandler.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import fs from "fs"
import fsPromises from "fs/promises"

const currentDropperVersion = "1.0"

export let chunks = {}
export let chunksFileWorking = false
try {
let tempChunks = fs.readFileSync("./chunks.json", "utf8")
tempChunks = JSON.parse(tempChunks)
if (tempChunks.dropperVersion !== currentDropperVersion) throw new Error({code: "OUTDATED_CHUNKS"})
replaceChunks(tempChunks)
chunksFileWorking = true
} catch (error) {
console.log("No valid chunks.json found. Creating a new file. (Error code: " + error.code + ")")
//create fresh data
let tempChunks = {
dropperVersion: currentDropperVersion,
versions: {}
}
replaceChunks(tempChunks)
Expand Down
15 changes: 12 additions & 3 deletions defaultConfig.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export default `# Config version, used to quickly validate the config and make sure it will have all of the necessary information in it. Do not change this unless you know what you're doing.
config-version: 3
config-version: 4
# Port to host the server on. Usually you can leave this on 25565, which is Minecraft's default port.
server-port: 25565
# The server's host. Recommended to leave this on 127.0.0.1.
server-host: 127.0.0.1
# Perfect map configurations for automatic requeueing if the maps are incorrect. If /rpm is used with no argument, "default" is chosen.
# As with the rest of the config, make sure this stays in the same general format if you modify it otherwise it may break.
# There MUST be a default config.
Expand All @@ -16,10 +19,16 @@ perfect-maps:
balloons:
- Well, Balloons, Sewer, Floating Islands, Iris
- Well, Balloons, Floating Islands, Sewer, Iris
# Displayed in the discordlink command. Change if you wish.
discord-link: https://discord.gg/Sqbj9Nb835
# CHUNK CACHING IS DISABLED TEMPORARILY DUE TO THE RELEASE BREAKING IT
# THIS IS CURRENTLY NON-FUNCTIONAL
# Dropper Utilities can fetch stats for other players in your game using Aiden (skrrrtt on Discord)'s API.
# Each player's win count will be displayed in tab in Dropper games, letting you get a quick idea of how good each player is.
# Additionally, this contributes to Aiden's database, allowing more accurate leaderboards to be displayed on his website (https://hydropper.info/leaderboard).
# Set this to true if you'd like to opt-in.
fetch-player-stats: false
# Dropper Utilities can give your client a small portion of the world around you when you teleport to a new map, prior to receiving it from Hypixel over the network.
# This can reduce load times when switching between maps by ~175ms on my setup, it may vary for you.
# Chunks near teleportation spots are saved in the file chunks.json which is placed in the same folder as this program.
Expand Down
89 changes: 89 additions & 0 deletions dropperApi/identifierHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import fetch from "node-fetch"

let cache = new Map()
let cacheTimes = new Map()
let queue = []

export function getStats(uuid) {
if (cache.has(uuid)) {
if (performance.now() - cacheTimes.get(uuid) > 300000) {
//if it's too old, re-fetch user data
cache.delete(uuid)
cacheTimes.delete(uuid)
} else {
return cache.get(uuid)
}
}

let promise = new Promise(resolve => {
queue.push({
uuid,
resolve
})
if (queue.length === 1) {
setTimeout(doFetch, 1000)
}
})
cache.set(uuid, promise)
return promise
}

async function doFetch() {
let currentQueue = queue
queue = []
let uuidsToFetch = currentQueue.map(item => item.uuid)
let resultMap = await fetchPlayers(uuidsToFetch)
let now = performance.now()
for (let uuid of uuidsToFetch) {
cacheTimes.set(uuid, now)
}
if (resultMap === null) { //error of some sort
for (let item of currentQueue) {
cache.set(item.uuid, null)
item.resolve(null)
}
return
}
for (let item of currentQueue) {
let uuid = item.uuid
let value = resultMap.get(uuid)
cache.set(uuid, value)
item.resolve(value)
}
}

async function fetchPlayers(uuids) {
try {
let response = await fetch("https://api.hydropper.info/user/multiple", {
body: JSON.stringify({
_id: uuids
}),
method: "POST",
headers: {
"User-Agent": "DropperUtilities",
"Content-Type": "application/json"
}
})
let json = await response.json()
if (json.error) {
throw new Error(JSON.stringify(json))
}
let users = new Map()
json.users.forEach(user => {
if (user.wins === null) {
console.log("NULL USER", user.uuid)
users.set(user.uuid, null)
return
}
users.set(user.uuid, {
wins: user.wins,
fails: user.fails
})
})
return users
} catch (error) {
console.log("Unexpected Dropper API error - please report to lapisfloof on Discord:")
console.log(error)
return null
}
}
27 changes: 22 additions & 5 deletions internalModules/ChunkPreloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export class ChunkPreloader {
this.userClient = clientHandler.userClient
this.proxyClient = clientHandler.proxyClient

this.stateHandler = this.clientHandler.stateHandler

this.active = false

this.loadedChunks = new Set()
Expand Down Expand Up @@ -36,8 +38,15 @@ export class ChunkPreloader {
}
this.loadedChunks.add(key)
if (!this.active) return
if (Math.abs(data.x - this.lastTpChunkX) > 1 || Math.abs(data.z - this.lastTpChunkZ) > 1) return //only save chunks near teleportation spots
this.chunkData[key] = serializeChunkData(data)
if (Math.abs(data.x - this.lastTpChunkX) > 2 || Math.abs(data.z - this.lastTpChunkZ) > 2) return //only save chunks near teleportation spots
if (this.stateHandler.mapset) {
let mapsetChunkData = this.chunkData[this.stateHandler.mapset]
if (!mapsetChunkData) {
mapsetChunkData = {}
this.chunkData[this.stateHandler.mapset] = mapsetChunkData
}
mapsetChunkData[key] = serializeChunkData(data)
}
}
if (meta.name === "unload_chunk") {
let key = data.x + "," + data.z
Expand All @@ -49,10 +58,18 @@ export class ChunkPreloader {
this.lastTpChunkX = chunkX
this.lastTpChunkZ = chunkZ
if (!this.active || !config["chunk-caching"]) return
for (let relativeX = -1; relativeX <= 1; relativeX++) {
for (let relativeZ = -1; relativeZ < 1; relativeZ++) {
for (let relativeX = -2; relativeX <= 2; relativeX++) {
for (let relativeZ = -2; relativeZ < 2; relativeZ++) {
let key = (chunkX + relativeX) + "," + (chunkZ + relativeZ)
let data = this.chunkData[key]
let data
if (this.stateHandler.mapset) {
let mapsetChunkData = this.chunkData[this.stateHandler.mapset]
if (!mapsetChunkData) {
mapsetChunkData = {}
this.chunkData[this.stateHandler.mapset] = mapsetChunkData
}
data = mapsetChunkData[key]
}
if (!data) continue
if (this.loadedChunks.has(key)) continue
this.loadedChunks.add(key)
Expand Down
Loading

0 comments on commit 04b613d

Please sign in to comment.