Skip to content

Commit

Permalink
0.1.0 stable
Browse files Browse the repository at this point in the history
  • Loading branch information
dottych committed Aug 28, 2024
1 parent 23fac23 commit cb7490c
Show file tree
Hide file tree
Showing 56 changed files with 3,826 additions and 0 deletions.
446 changes: 446 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "classich",
"author": "dottych",
"dependencies": {
"perlin-noise": "^0.0.1",
"request": "^2.88.2"
}
}
73 changes: 73 additions & 0 deletions server/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"server": {
"port": 25565,

"name": "My ClassiCH Server",

"maxPlayers": 64,

"public": false,
"authentication": false,

"joinKick": false,

"motdTitle": "%servername%",
"motdDescription": "%greeting%, %playername%! -noclip",
"motdDescriptionOP": "%greeting%, %playername%!",

"checkForUpdate": true
},

"world": {
"name": "world",

"size": {
"x": 256,
"y": 128,
"z": 256
},

"spawn": {
"x": -1,
"y": -1,
"z": -1
},

"saveInterval": 45,

"generationType": "land",

"spamCount": 80,
"spamInterval": 5,

"features": {
"blastRadius": 2,
"explosions": false,
"slabs": true,
"saplings": true,
"sponges": true
}
},

"messages": {
"spamCount": 5,
"spamInterval": 5
},

"commands": {
"selfActions": false,
"8ballDelay": 10,
"flipDelay": 10
},

"heartbeat": {
"enabled": true,
"url": "https://www.classicube.net/server/heartbeat",
"interval": 45
},

"logging": {
"console": true,
"file": true
}
}
14 changes: 14 additions & 0 deletions server/greetings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
"Hello",
"Hi",
"Hey",
"Hello there",
"Hi there",
"Hey there",
"Howdy",
"What's up",
"Welcome",
"Greetings",
"Sup",
"Yo"
]
7 changes: 7 additions & 0 deletions server/run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ECHO OFF

:run
cls
node ../src/Server.js
pause
goto run
15 changes: 15 additions & 0 deletions src/Command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const ServerMessagePacket = require('./Packets/Server/Message');

class Command {
constructor(client, args) {
this.client = client;
this.args = args;
}

// default response
execute() {
new ServerMessagePacket([this.client], 0xFF, "Command does not exist!");
}
}

module.exports = Command;
36 changes: 36 additions & 0 deletions src/Commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const fs = require('fs');

const utils = require('./Utils');
const lists = require('./Lists');

let commands = {};

for (let command of fs.readdirSync('../src/Commands/')) {
// check if it's a module
if (!command.endsWith('.js')) continue;

// remove ".js" from the end
command = command.slice(0, -3);

// register command and add its information to list
try {
commands[command.toLowerCase()] = require(`./Commands/${command}`);

const tempCommand = new (commands[command.toLowerCase()])(null, []);

lists.commands[command.toLowerCase()] = {

description: tempCommand.description,
op: tempCommand.op,
hidden: tempCommand.hidden

};
} catch(error) {
console.log(error);
delete commands[command.toLowerCase()];
delete lists.commands[command.toLowerCase()]
utils.log(`"${command}" is NOT a valid command! Ignoring file`);
}
}

module.exports = commands;
76 changes: 76 additions & 0 deletions src/Commands/8ball.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const Command = require('../Command');

const ServerMessagePacket = require('../Packets/Server/Message');

const utils = require('../Utils');
const lists = require('../Lists');
const config = require('../Config')

class Command8ball extends Command {
constructor(client, args) {
super(client, args);

this.name = "8ball";
this.description = "Ask 8-Ball something.";

this.op = false;
this.hidden = false;
}

wait(ms) {
return new Promise(r => setTimeout(r, ms));
}

execute() {
const me = lists.players[this.client.id];

if (this.args.length <= 0) {
new ServerMessagePacket([this.client], 0xFF, `You must ask a question.`);
return;
}

if (performance.now() < me.commandVars.asked + config.self.commands["8ballDelay"] * 1000) {
new ServerMessagePacket([this.client], 0xFF, `Ask later.`);
return;
}

me.commandVars.asked = Math.round(performance.now());

async function ask(self) {
let questionMessages = utils.splitString(`${me.name} asked 8-Ball: ${self.args.join(' ')}`, "&7");

for (let questionMessage of questionMessages)
new ServerMessagePacket(

utils.getAllPlayerClients(),
0xFF,
questionMessage

);

await self.wait(1000 + Math.round(Math.random() * 1000));

let answerMessages = utils.splitString(

`8-Ball: ${me.name}, ${lists.answers[Math.floor(Math.random() * lists.answers.length)].toLowerCase().replaceAll(' i ', ' I ')}.`,
"&7"

);

for (let answerMessage of answerMessages)
new ServerMessagePacket(

utils.getAllPlayerClients(),
0xFF,
answerMessage

);

utils.log(answerMessages.join(''));
}

ask(this);
}
}

module.exports = Command8ball;
23 changes: 23 additions & 0 deletions src/Commands/About.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const Command = require('../Command');

const ServerMessagePacket = require('../Packets/Server/Message');

const config = require('../Config');

class CommandAbout extends Command {
constructor(client, args) {
super(client, args);

this.name = "about";
this.description = "Says stuff about the server.";

this.op = false;
this.hidden = false;
}

execute() {
new ServerMessagePacket([this.client], 0xFF, config.self.server.name);
}
}

module.exports = CommandAbout;
28 changes: 28 additions & 0 deletions src/Commands/Backup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const Command = require('../Command');

const ServerMessagePacket = require('../Packets/Server/Message');

const world = require('../World');

class CommandAbout extends Command {
constructor(client, args) {
super(client, args);

this.name = "backup";
this.description = "Saves a backup of the current world.";

this.op = true;
this.hidden = false;
}

execute() {
new ServerMessagePacket([this.client], 0xFF, "Saving backup...");

if (world.backup())
new ServerMessagePacket([this.client], 0xFF, "Backup saved.");
else
new ServerMessagePacket([this.client], 0xFF, "Something went wrong.");
}
}

module.exports = CommandAbout;
50 changes: 50 additions & 0 deletions src/Commands/Ban.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const Command = require('../Command');

const ServerMessagePacket = require('../Packets/Server/Message');
const ServerDisconnectPacket = require('../Packets/Server/Disconnect');

const lists = require('../Lists');
const utils = require('../Utils');
const config = require('../Config');

class CommandBan extends Command {
constructor(client, args) {
super(client, args);

this.name = "ban";
this.description = "Bans a specified player.";

this.op = true;
this.hidden = false;
}

execute() {
if (this.args.length <= 0) {
new ServerMessagePacket([this.client], 0xFF, "You must provide a name!");
return;
}

if (!config.self.commands.selfActions && this.args[0] === lists.players[this.client.id].name) {
new ServerMessagePacket([this.client], 0xFF, "You can't ban yourself!");
return;
}

let name = this.args.shift()
let player = utils.findPlayerByName(name);
let reason = this.args.join(' ');

if (lists.addBan(name, reason)) {
if (player != undefined)
if (reason.trim() !== "")
new ServerDisconnectPacket([player.client], `Banned: ${reason}`);
else
new ServerDisconnectPacket([player.client], "You were banned!");

new ServerMessagePacket([this.client], 0xFF, `${name} is now banned.`);
} else
new ServerMessagePacket([this.client], 0xFF, `${name} is already banned!`);

}
}

module.exports = CommandBan;
47 changes: 47 additions & 0 deletions src/Commands/DeOP.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const Command = require('../Command');

const ServerMessagePacket = require('../Packets/Server/Message');
const ServerTypePacket = require('../Packets/Server/Type');

const lists = require('../Lists');
const utils = require('../Utils');
const config = require('../Config');

class CommandDeOP extends Command {
constructor(client, args) {
super(client, args);

this.name = "deop";
this.description = "DeOPs a specified player.";

this.op = true;
this.hidden = false;
}

execute() {
if (this.args.length <= 0) {
new ServerMessagePacket([this.client], 0xFF, "You must provide a name!");
return;
}

if (!config.self.commands.selfActions && this.args[0] === lists.players[this.client.id].name) {
new ServerMessagePacket([this.client], 0xFF, "You can't deop yourself!");
return;
}

if (lists.removeOp(this.args[0])) {
let player = utils.findPlayerByName(this.args[0]);

if (player != undefined) {
player.op = false;
new ServerTypePacket([player.client], 0x00);
}

new ServerMessagePacket([this.client], 0xFF, `${this.args[0]} is no longer OP.`);
} else
new ServerMessagePacket([this.client], 0xFF, `${this.args[0]} isn't OP!`);

}
}

module.exports = CommandDeOP;
Loading

0 comments on commit cb7490c

Please sign in to comment.