formatting + make so you can change the main world

This commit is contained in:
yourfriend 2022-07-14 16:26:27 +03:00
parent 4d69c4c696
commit c31b81133f
No known key found for this signature in database
GPG key ID: C28FFD8607DAC4DE
5 changed files with 31 additions and 21 deletions

View file

@ -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 };

View file

@ -28,9 +28,9 @@ export class Server {
[13, 65],
]);
maxUsers = 69
maxUsers = 69;
worlds: World[] = [new World({ x: 64, y: 64, z: 64 }, "main")];
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]);
@ -71,7 +71,7 @@ export class Server {
"&public=True" +
"&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),
@ -173,7 +173,6 @@ export class Server {
const verification = packet.readString();
if (this.players.length >= this.maxUsers) {
connection.close();
return;

View file

@ -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",
};

View file

@ -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()

View file

@ -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