From 714a4189eb02051ddd330513048b07b3be070e27 Mon Sep 17 00:00:00 2001 From: WlodekM Date: Sat, 30 Nov 2024 14:24:39 +0200 Subject: do stuff 3 --- commands/ban.js | 17 ----------------- commands/ban.ts | 18 ++++++++++++++++++ commands/kick.js | 11 ----------- commands/kick.ts | 13 +++++++++++++ commands/motd.js | 7 ------- commands/motd.ts | 9 +++++++++ 6 files changed, 40 insertions(+), 35 deletions(-) delete mode 100644 commands/ban.js create mode 100644 commands/ban.ts delete mode 100644 commands/kick.js create mode 100644 commands/kick.ts delete mode 100644 commands/motd.js create mode 100644 commands/motd.ts (limited to 'commands') diff --git a/commands/ban.js b/commands/ban.js deleted file mode 100644 index 584b4d0..0000000 --- a/commands/ban.js +++ /dev/null @@ -1,17 +0,0 @@ -import fs from "node:fs"; - -export default { - name: "ban", - aliases: [], - command: function ({ user, server, args }) { - if(!user.admin) return user.socket.send("You are not admin"); - if(!server.accounts.checkAccount(args[0])) return user.socket.send("Account not found"); - let theUser = Object.values(server.users).find(a => a.username == args[0]); - theUser.socket.send('you were kicked because you were banned, L'); - let ipBanList = JSON.parse(String(fs.readFileSync("db/bannedIps.json"))); - ipBanList[theUser.ip] = args[1] ?? 'reason'; - ipBanList['account:'+args[0]] = args[1] ?? 'reason'; - theUser.socket.close(1003, "Kicked"); - fs.writeFileSync('db/bannedIps.json', JSON.stringify(ipBanList)); - }, -}; diff --git a/commands/ban.ts b/commands/ban.ts new file mode 100644 index 0000000..77d23b5 --- /dev/null +++ b/commands/ban.ts @@ -0,0 +1,18 @@ +import fs from "node:fs"; +import { CommandFnArgs } from "../commands.ts" + +export default { + name: "ban", + aliases: [], + command: function ({ user, server, args }: CommandFnArgs) { + if(!user.admin) return user.socket.send("You are not admin"); + if(!server.accounts.checkAccount(args[0])) return user.socket.send("Account not found"); + const theUser = Object.values(server.users).find(a => a.username == args[0]); + theUser.socket.send('you were kicked because you were banned, L'); + const ipBanList = JSON.parse(String(fs.readFileSync("db/bannedIps.json"))); + ipBanList[theUser.ip] = args[1] ?? 'reason'; + ipBanList['account:'+args[0]] = args[1] ?? 'reason'; + theUser.socket.close(1003, "Kicked"); + fs.writeFileSync('db/bannedIps.json', JSON.stringify(ipBanList)); + }, +}; diff --git a/commands/kick.js b/commands/kick.js deleted file mode 100644 index accadb0..0000000 --- a/commands/kick.js +++ /dev/null @@ -1,11 +0,0 @@ -export default { - name: "kick", - aliases: [], - command: function ({ user, server, args }) { - if(!user.admin) return user.socket.send("You are not admin"); - if(!server.accounts.checkAccount(args[0])) return user.socket.send("Account not found"); - let theUser = Object.values(server.users).find(a => a.username == args[0]); - theUser.socket.send('you were kicked') - theUser.socket.close(1003, "Kicked"); - }, -}; diff --git a/commands/kick.ts b/commands/kick.ts new file mode 100644 index 0000000..60568ed --- /dev/null +++ b/commands/kick.ts @@ -0,0 +1,13 @@ +import { CommandFnArgs } from "../commands.ts" + +export default { + name: "kick", + aliases: [], + command: function ({ user, server, args }: CommandFnArgs) { + if(!user.admin) return user.socket.send("You are not admin"); + if(!server.accounts.checkAccount(args[0])) return user.socket.send("Account not found"); + const theUser = Object.values(server.users).find(a => a.username == args[0]); + theUser.socket.send('you were kicked') + theUser.socket.close(1003, "Kicked"); + }, +}; diff --git a/commands/motd.js b/commands/motd.js deleted file mode 100644 index a4e7fde..0000000 --- a/commands/motd.js +++ /dev/null @@ -1,7 +0,0 @@ -export default { - name: "motd", - aliases: [], - command: function ({ user, server }) { - user.socket.send("MOTD: " + server.format(server.config.motd)); - }, -}; diff --git a/commands/motd.ts b/commands/motd.ts new file mode 100644 index 0000000..43293c9 --- /dev/null +++ b/commands/motd.ts @@ -0,0 +1,9 @@ +import { CommandFnArgs } from "../commands.ts" + +export default { + name: "motd", + aliases: [], + command: function ({ user, server }: CommandFnArgs) { + user.socket.send("MOTD: " + server.format(server.config.server.motd)); + }, +}; -- cgit 1.4.1-2-gfad0