formatting + make so you can change the main world
This commit is contained in:
parent
4d69c4c696
commit
c31b81133f
|
@ -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 };
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
@ -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[] = [];
|
||||
|
||||
|
|
1
deps.ts
1
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",
|
||||
};
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue