天上太阳红衫衫
This commit is contained in:
parent
4af20b4df5
commit
8cd07e8521
|
@ -39,7 +39,10 @@ export class Player {
|
||||||
async writeToSocket(ar: Uint8Array) {
|
async writeToSocket(ar: Uint8Array) {
|
||||||
await this.socket.write(ar).catch(async (e) => {
|
await this.socket.write(ar).catch(async (e) => {
|
||||||
log.critical(e);
|
log.critical(e);
|
||||||
await this.server.removeUser(this.socket);
|
await this.server.removeUser(
|
||||||
|
this.socket,
|
||||||
|
"Write failed" + e.message.split("\n")[0],
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ export class Server {
|
||||||
[13, 65],
|
[13, 65],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
maxUsers = 69;
|
maxUsers = config.maxUsers;
|
||||||
|
|
||||||
worlds: World[] = [new World({ x: 64, y: 64, z: 64 }, config.main)];
|
worlds: World[] = [new World({ x: 64, y: 64, z: 64 }, config.main)];
|
||||||
|
|
||||||
|
@ -67,9 +67,9 @@ export class Server {
|
||||||
"https://www.classicube.net/heartbeat.jsp" +
|
"https://www.classicube.net/heartbeat.jsp" +
|
||||||
`?port=${config.port}` +
|
`?port=${config.port}` +
|
||||||
`&max=${this.maxUsers}` +
|
`&max=${this.maxUsers}` +
|
||||||
"&name=Cla66ic" +
|
`&name=${config.name}` +
|
||||||
"&public=True" +
|
"&public=True" +
|
||||||
"&software=Cla66ic" +
|
`&software=${config.software}` +
|
||||||
`&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}`,
|
||||||
);
|
);
|
||||||
|
@ -136,7 +136,7 @@ export class Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async removeUser(conn: Deno.Conn) {
|
async removeUser(conn: Deno.Conn, text: string) {
|
||||||
const player = this.players.find((e) => e.socket == conn);
|
const player = this.players.find((e) => e.socket == conn);
|
||||||
|
|
||||||
if (!player) return;
|
if (!player) return;
|
||||||
|
@ -149,7 +149,7 @@ export class Server {
|
||||||
// whatever
|
// whatever
|
||||||
}
|
}
|
||||||
|
|
||||||
this.broadcast(`${player.username} has &cleft`);
|
this.broadcast(`${player.username} has &cleft&f, "${text}"`);
|
||||||
|
|
||||||
await this.worlds.find((e) => e.name == player.world)!.save();
|
await this.worlds.find((e) => e.name == player.world)!.save();
|
||||||
|
|
||||||
|
@ -319,7 +319,7 @@ export class Server {
|
||||||
try {
|
try {
|
||||||
packetIDReadAttempt = await connection.read(packetID);
|
packetIDReadAttempt = await connection.read(packetID);
|
||||||
} catch {
|
} catch {
|
||||||
await this.removeUser(connection); // TODO: add a reason to this
|
await this.removeUser(connection, "Packet ID read failed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ export class Server {
|
||||||
|
|
||||||
if (!packetLength) {
|
if (!packetLength) {
|
||||||
log.critical("Unknown Packet: " + packetID[0]);
|
log.critical("Unknown Packet: " + packetID[0]);
|
||||||
await this.removeUser(connection); // TODO: add a reason to this
|
await this.removeUser(connection, "Unknown packet ID " + packetID[0]); // TODO: add a reason to this
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@ export class Server {
|
||||||
try {
|
try {
|
||||||
packetReadAttempt = await connection.read(rawPacket);
|
packetReadAttempt = await connection.read(rawPacket);
|
||||||
} catch {
|
} catch {
|
||||||
await this.removeUser(connection); // TODO: add a reason to this
|
await this.removeUser(connection, "Packet read attempt failed."); // TODO: add a reason to this
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,14 +351,20 @@ export class Server {
|
||||||
try {
|
try {
|
||||||
fullRead += (await connection.read(halfPacket))!;
|
fullRead += (await connection.read(halfPacket))!;
|
||||||
} catch {
|
} catch {
|
||||||
await this.removeUser(connection); // TODO: add a reason to this
|
await this.removeUser(
|
||||||
|
connection,
|
||||||
|
"Couldn't read all of packet " + packetID[0],
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handlePacket(rawPacket, packetID[0], connection);
|
this.handlePacket(rawPacket, packetID[0], connection);
|
||||||
} else {
|
} else {
|
||||||
await this.removeUser(connection);
|
await this.removeUser(
|
||||||
|
connection,
|
||||||
|
"Packet ID read returned null. Packet " + packetID[0],
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
3
deps.ts
3
deps.ts
|
@ -25,4 +25,7 @@ export const config = {
|
||||||
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",
|
main: Deno.env.get("MAIN") || "main",
|
||||||
|
maxUsers: +(Deno.env.get("USERS") || 24) > 255 ? 255 : +(Deno.env.get("USERS") || 24),
|
||||||
|
software: Deno.env.get("SOFTWARE") || "Custom Cla66ic",
|
||||||
|
name: Deno.env.get("NAME") || "Cla66ic Server"
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Plugin } from "../classes/classes.ts";
|
import { PacketWriter, Player, Plugin } from "../classes/classes.ts";
|
||||||
import { Server } from "../classes/Server.ts";
|
import { Server } from "../classes/Server.ts";
|
||||||
import { config } from "../deps.ts";
|
import { config } from "../deps.ts";
|
||||||
|
|
||||||
|
@ -7,14 +7,36 @@ export default class CommandPlugin extends Plugin {
|
||||||
"help",
|
"help",
|
||||||
"reloadplugins",
|
"reloadplugins",
|
||||||
"clients",
|
"clients",
|
||||||
|
"tp",
|
||||||
|
"eval"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
async tp(from: Player, to: Player) {
|
||||||
|
if(to.world != from.world) {
|
||||||
|
from.toWorld(this.server.worlds.find((e) =>
|
||||||
|
e.name == to.world
|
||||||
|
)!);
|
||||||
|
}
|
||||||
|
|
||||||
|
await from.writeToSocket(
|
||||||
|
new PacketWriter()
|
||||||
|
.writeByte(0x08)
|
||||||
|
.writeSByte(255)
|
||||||
|
.writeShort(to.position.x)
|
||||||
|
.writeShort(to.position.y)
|
||||||
|
.writeShort(to.position.z)
|
||||||
|
.writeByte(to.rotation.yaw)
|
||||||
|
.writeByte(to.rotation.pitch)
|
||||||
|
.toPacket(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
constructor(server: Server) {
|
constructor(server: Server) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
|
||||||
this.on("command", async (command, player) => {
|
this.on("command", async (command, player, args) => {
|
||||||
if (command == "help") {
|
if (command == "help") {
|
||||||
let allComamnds = "";
|
let allComamnds = "";
|
||||||
for (const [_k, v] of server.plugins) {
|
for (const [_k, v] of server.plugins) {
|
||||||
|
@ -38,7 +60,42 @@ export default class CommandPlugin extends Plugin {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
} else if(command == "eval") {
|
||||||
});
|
if(config.ops.includes(player.username)) {
|
||||||
|
|
||||||
|
server.broadcast(eval(args.join(" ")));
|
||||||
|
}
|
||||||
|
} else if (command == "tp") {
|
||||||
|
if(args.length == 1) {
|
||||||
|
const teleportTo = this.server.players.find((e) => args[0] === e.username)
|
||||||
|
|
||||||
|
if(teleportTo) {
|
||||||
|
await this.tp(player, teleportTo);
|
||||||
|
} else {
|
||||||
|
player.message("Player is missing")
|
||||||
|
}
|
||||||
|
} else if(args.length == 3) {
|
||||||
|
const x = +args[0]
|
||||||
|
const y = +args[1]
|
||||||
|
const z = +args[2]
|
||||||
|
|
||||||
|
if(isNaN(x) || isNaN(y) || isNaN(z)) {
|
||||||
|
player.message("invalid coords")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await player.writeToSocket(
|
||||||
|
new PacketWriter()
|
||||||
|
.writeByte(0x08)
|
||||||
|
.writeSByte(255)
|
||||||
|
.writeShort(x * 32)
|
||||||
|
.writeShort(y * 32)
|
||||||
|
.writeShort(z * 32)
|
||||||
|
.writeByte(player.rotation.yaw)
|
||||||
|
.writeByte(player.rotation.pitch)
|
||||||
|
.toPacket(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue