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 { Position, Rotation, World } from "./classes.ts";
import { PacketDefinitions, PacketWriter } from "./Packets.ts"; import { PacketDefinitions, PacketWriter } from "./Packets.ts";
import { log } from "../deps.ts"; import { config, log } from "../deps.ts";
import { Server } from "./Server.ts"; import { Server } from "./Server.ts";
export class Player { export class Player {
@ -10,7 +10,7 @@ export class Player {
username: string; username: string;
ip: string; ip: string;
id: number; id: number;
world = "main"; world = config.main;
position: Position; position: Position;
rotation: Rotation = { yaw: 0, pitch: 0 }; rotation: Rotation = { yaw: 0, pitch: 0 };
@ -25,7 +25,7 @@ export class Player {
this.position = position; this.position = position;
this.server = server; this.server = server;
this.ip = (this.socket.remoteAddr as Deno.NetAddr).hostname; this.ip = (this.socket.remoteAddr as Deno.NetAddr).hostname;
let id = Math.floor(Math.random() * server.maxUsers); let id = Math.floor(Math.random() * server.maxUsers);
// reassigns ID until finds available one // reassigns ID until finds available one

View file

@ -28,9 +28,9 @@ export class Server {
[13, 65], [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) { async start(port: number) {
this.server = Deno.listen({ port: port }); this.server = Deno.listen({ port: port });
@ -52,7 +52,7 @@ export class Server {
(await s3.listObjects({ (await s3.listObjects({
Bucket: "cla66ic", Bucket: "cla66ic",
})).Contents.forEach((e) => { })).Contents.forEach((e) => {
if (e.Key !== "main.buf") { if (e.Key !== config.main + ".buf") {
log.info(`Autoloaded a world from s3! ${e.Key}`); log.info(`Autoloaded a world from s3! ${e.Key}`);
const world = new World({ x: 0, y: 0, z: 0 }, e.Key!.split(".buf")[0]); 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}` + `&max=${this.maxUsers}` +
"&name=Cla66ic" + "&name=Cla66ic" +
"&public=True" + "&public=True" +
"&software=Cla66ic" + "&software=Cla66ic" +
`&version=7&salt=${config.hash}` + `&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); }, 10000);
} }
@ -151,7 +151,7 @@ export class Server {
this.broadcast(`${player.username} has &cleft`); 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( this.broadcastPacket(
(e) => PacketDefinitions.despawn(player.id, e), (e) => PacketDefinitions.despawn(player.id, e),
@ -172,8 +172,7 @@ export class Server {
const verification = packet.readString(); const verification = packet.readString();
if(this.players.length >= this.maxUsers) { if (this.players.length >= this.maxUsers) {
connection.close(); connection.close();
return; return;
@ -232,7 +231,7 @@ export class Server {
this.broadcast(`${player.username} has &ajoined`); this.broadcast(`${player.username} has &ajoined`);
} else if (packetType == 0x08) { } else if (packetType == 0x08) {
const player = this.players.find((e) => e.socket == connection); const player = this.players.find((e) => e.socket == connection);
if(!player) return; if (!player) return;
packet.readByte(); packet.readByte();
player.position.x = packet.readShort(); player.position.x = packet.readShort();
@ -250,7 +249,7 @@ export class Server {
packet.readByte(); packet.readByte();
const player = this.players.find((e) => e.socket == connection); const player = this.players.find((e) => e.socket == connection);
if(!player) return; if (!player) return;
const message = packet.readString(); const message = packet.readString();
let playerColor = "[member] &b"; let playerColor = "[member] &b";
@ -275,7 +274,7 @@ export class Server {
this.broadcast(`${playerColor}${player.username}&f: ${message}`); this.broadcast(`${playerColor}${player.username}&f: ${message}`);
} else if (packetType == 0x05) { } else if (packetType == 0x05) {
const player = this.players.find((e) => e.socket == connection); const player = this.players.find((e) => e.socket == connection);
if(!player) return; if (!player) return;
const position = { const position = {
x: packet.readShort(), x: packet.readShort(),
@ -288,7 +287,7 @@ export class Server {
const id = mode ? block : 0; const id = mode ? block : 0;
const world = this.worlds.find((e) => e.name == player.world); const world = this.worlds.find((e) => e.name == player.world);
if(!world) return; if (!world) return;
let pluginAnswer: boolean[] = []; let pluginAnswer: boolean[] = [];

View file

@ -24,4 +24,5 @@ export const config = {
port: +Deno.env.get("PORT")!, port: +Deno.env.get("PORT")!,
hash: Deno.env.get("HASH"), hash: Deno.env.get("HASH"),
onlineMode: Deno.env.get("ONLINEMODE") == "true", 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", "g",
"worlds", "worlds",
"world", "world",
"main",
]; ];
constructor(server: Server) { constructor(server: Server) {
@ -25,8 +26,14 @@ export default class CommandPlugin extends Plugin {
return false; return false;
}); });
this.on("command", async (command, player, args) => { this.on("command", async (command, player, args) => {
if (command == "g") { if (command == "main") {
await server.worlds.find(e => e.name == player.world)!.save(); 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) => const requestedWorld = server.worlds.find((e) =>
e.name.toLowerCase() == args.join(" ").toLowerCase() e.name.toLowerCase() == args.join(" ").toLowerCase()

View file

@ -20,9 +20,11 @@ PORT=6969
HASH=RandomHashIlIke HASH=RandomHashIlIke
OPS=["Me"] OPS=["Me"]
ONLINEMODE=true ONLINEMODE=true
MAIN=main
S3_ACCESS_KEY_ID="MyAccessKey" S3_ACCESS_KEY_ID="MyAccessKey"
S3_SECRET_KEY="SecretKey" 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 NOTE: if you are running inside of a cloud provider, just set these as your
@ -39,9 +41,10 @@ environment variables
### issues: ### issues:
1. Properly queue up map saves instead of just blantantly saving whenever
1. Properly queue up map saves instead of just blantantly saving whenever possible possible
2. massive performance issues, running more than 100 something accounts makes the server instead insane amounts of cpu (most likely multithreading needed) 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 3. no cpe support! i want to get all of the above issues fixed before
implementing CPE support implementing CPE support
4. no IP cooldown connections (no block cooldown either), no anticheat 4. no IP cooldown connections (no block cooldown either), no anticheat