From c31b81133fc75758a0780e1e767a2cb7656c9188 Mon Sep 17 00:00:00 2001 From: yourfriend Date: Thu, 14 Jul 2022 16:26:27 +0300 Subject: [PATCH] formatting + make so you can change the main world --- classes/Player.ts | 6 +++--- classes/Server.ts | 25 ++++++++++++------------- deps.ts | 1 + plugins/world.ts | 11 +++++++++-- readme.md | 9 ++++++--- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/classes/Player.ts b/classes/Player.ts index c8200e8..4393018 100644 --- a/classes/Player.ts +++ b/classes/Player.ts @@ -1,6 +1,6 @@ import { Position, Rotation, World } from "./classes.ts"; import { PacketDefinitions, PacketWriter } from "./Packets.ts"; -import { log } from "../deps.ts"; +import { config, log } from "../deps.ts"; import { Server } from "./Server.ts"; export class Player { @@ -10,7 +10,7 @@ export class Player { username: string; ip: string; id: number; - world = "main"; + world = config.main; position: Position; rotation: Rotation = { yaw: 0, pitch: 0 }; @@ -25,7 +25,7 @@ export class Player { this.position = position; this.server = server; this.ip = (this.socket.remoteAddr as Deno.NetAddr).hostname; - + let id = Math.floor(Math.random() * server.maxUsers); // reassigns ID until finds available one diff --git a/classes/Server.ts b/classes/Server.ts index 998a6aa..e58b645 100644 --- a/classes/Server.ts +++ b/classes/Server.ts @@ -28,9 +28,9 @@ export class Server { [13, 65], ]); - maxUsers = 69 - - worlds: World[] = [new World({ x: 64, y: 64, z: 64 }, "main")]; + maxUsers = 69; + + worlds: World[] = [new World({ x: 64, y: 64, z: 64 }, config.main)]; async start(port: number) { this.server = Deno.listen({ port: port }); @@ -52,7 +52,7 @@ export class Server { (await s3.listObjects({ Bucket: "cla66ic", })).Contents.forEach((e) => { - if (e.Key !== "main.buf") { + if (e.Key !== config.main + ".buf") { log.info(`Autoloaded a world from s3! ${e.Key}`); const world = new World({ x: 0, y: 0, z: 0 }, e.Key!.split(".buf")[0]); @@ -69,9 +69,9 @@ export class Server { `&max=${this.maxUsers}` + "&name=Cla66ic" + "&public=True" + - "&software=Cla66ic" + + "&software=Cla66ic" + `&version=7&salt=${config.hash}` + - `&users=${[...new Set(this.players.map(obj => obj.ip))].length}` + `&users=${[...new Set(this.players.map((obj) => obj.ip))].length}`, ); }, 10000); } @@ -151,7 +151,7 @@ export class Server { this.broadcast(`${player.username} has &cleft`); - await this.worlds.find(e => e.name == player.world)!.save(); + await this.worlds.find((e) => e.name == player.world)!.save(); this.broadcastPacket( (e) => PacketDefinitions.despawn(player.id, e), @@ -172,8 +172,7 @@ export class Server { const verification = packet.readString(); - if(this.players.length >= this.maxUsers) { - + if (this.players.length >= this.maxUsers) { connection.close(); return; @@ -232,7 +231,7 @@ export class Server { this.broadcast(`${player.username} has &ajoined`); } else if (packetType == 0x08) { const player = this.players.find((e) => e.socket == connection); - if(!player) return; + if (!player) return; packet.readByte(); player.position.x = packet.readShort(); @@ -250,7 +249,7 @@ export class Server { packet.readByte(); const player = this.players.find((e) => e.socket == connection); - if(!player) return; + if (!player) return; const message = packet.readString(); let playerColor = "[member] &b"; @@ -275,7 +274,7 @@ export class Server { this.broadcast(`${playerColor}${player.username}&f: ${message}`); } else if (packetType == 0x05) { const player = this.players.find((e) => e.socket == connection); - if(!player) return; + if (!player) return; const position = { x: packet.readShort(), @@ -288,7 +287,7 @@ export class Server { const id = mode ? block : 0; const world = this.worlds.find((e) => e.name == player.world); - if(!world) return; + if (!world) return; let pluginAnswer: boolean[] = []; diff --git a/deps.ts b/deps.ts index 605757f..f151797 100644 --- a/deps.ts +++ b/deps.ts @@ -24,4 +24,5 @@ export const config = { port: +Deno.env.get("PORT")!, hash: Deno.env.get("HASH"), onlineMode: Deno.env.get("ONLINEMODE") == "true", + main: Deno.env.get("MAIN") || "main", }; diff --git a/plugins/world.ts b/plugins/world.ts index e0878a6..03f403c 100644 --- a/plugins/world.ts +++ b/plugins/world.ts @@ -7,6 +7,7 @@ export default class CommandPlugin extends Plugin { "g", "worlds", "world", + "main", ]; constructor(server: Server) { @@ -25,8 +26,14 @@ export default class CommandPlugin extends Plugin { return false; }); this.on("command", async (command, player, args) => { - if (command == "g") { - await server.worlds.find(e => e.name == player.world)!.save(); + if (command == "main") { + await server.worlds.find((e) => e.name == player.world)!.save(); + + player.toWorld( + server.worlds.find((e) => e.name.toLowerCase() == config.main)!, + ); + } else if (command == "g") { + await server.worlds.find((e) => e.name == player.world)!.save(); const requestedWorld = server.worlds.find((e) => e.name.toLowerCase() == args.join(" ").toLowerCase() diff --git a/readme.md b/readme.md index 474ba87..39595f0 100644 --- a/readme.md +++ b/readme.md @@ -20,9 +20,11 @@ PORT=6969 HASH=RandomHashIlIke OPS=["Me"] ONLINEMODE=true +MAIN=main S3_ACCESS_KEY_ID="MyAccessKey" S3_SECRET_KEY="SecretKey" +S3_ENDPOINT_URL="https://s3.us-west-004.backblazeb2.com" ``` NOTE: if you are running inside of a cloud provider, just set these as your @@ -39,9 +41,10 @@ environment variables ### issues: - -1. Properly queue up map saves instead of just blantantly saving whenever possible -2. massive performance issues, running more than 100 something accounts makes the server instead insane amounts of cpu (most likely multithreading needed) +1. Properly queue up map saves instead of just blantantly saving whenever + possible +2. massive performance issues, running more than 100 something accounts makes + the server instead insane amounts of cpu (most likely multithreading needed) 3. no cpe support! i want to get all of the above issues fixed before implementing CPE support 4. no IP cooldown connections (no block cooldown either), no anticheat