From 226652fbcb8b6d219f76af93cfa90b7451eeaa5c Mon Sep 17 00:00:00 2001 From: Chalwk77 Date: Fri, 14 Jul 2023 22:01:14 +1200 Subject: [PATCH] ... --- .../Abandoned/Admin Manager/Admin Manager.lua | 58 +++++-------- .../Admin Manager/Commands/hash_admin_add.lua | 58 ++++++------- .../Commands/hash_admin_delete.lua | 15 ++-- .../Admin Manager/Commands/hash_admins.lua | 13 ++- .../Admin Manager/Commands/ip_admin_add.lua | 65 +++++++-------- .../Commands/ip_admin_delete.lua | 15 ++-- .../Admin Manager/Commands/ip_admins.lua | 13 ++- .../Admin Manager/Commands/login.lua | 80 +++++++++--------- .../Admin Manager/Commands/logout.lua | 19 +++-- .../Admin Manager/Commands/pw_admin_add.lua | 82 +++++++++---------- .../Commands/pw_admin_delete.lua | 15 ++-- .../Admin Manager/Commands/pw_admins.lua | 13 ++- .../Abandoned/Admin Manager/Events/Join.lua | 19 ----- .../Admin Manager/Events/OnCommand.lua | 35 -------- .../Abandoned/Admin Manager/Utils/Misc.lua | 44 ---------- .../Admin Manager/Utils/PermissionHandler.lua | 12 --- .../Abandoned/Admin Manager/admins.json | 13 +-- .../Abandoned/Admin Manager/commands.json | 3 +- .../Admin Manager/{Utils => util}/FileIO.lua | 5 ++ .../{Utils => util}/LoadDatabase.lua | 4 +- .../Abandoned/Admin Manager/util/Misc.lua | 71 ++++++++++++++++ .../{Utils/Json.lua => util/json.lua} | 0 22 files changed, 291 insertions(+), 361 deletions(-) delete mode 100644 Miscellaneous/Abandoned/Admin Manager/Events/Join.lua delete mode 100644 Miscellaneous/Abandoned/Admin Manager/Events/OnCommand.lua delete mode 100644 Miscellaneous/Abandoned/Admin Manager/Utils/Misc.lua delete mode 100644 Miscellaneous/Abandoned/Admin Manager/Utils/PermissionHandler.lua rename Miscellaneous/Abandoned/Admin Manager/{Utils => util}/FileIO.lua (90%) rename Miscellaneous/Abandoned/Admin Manager/{Utils => util}/LoadDatabase.lua (91%) create mode 100644 Miscellaneous/Abandoned/Admin Manager/util/Misc.lua rename Miscellaneous/Abandoned/Admin Manager/{Utils/Json.lua => util/json.lua} (100%) diff --git a/Miscellaneous/Abandoned/Admin Manager/Admin Manager.lua b/Miscellaneous/Abandoned/Admin Manager/Admin Manager.lua index 69c2bd37..4c399ef0 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Admin Manager.lua +++ b/Miscellaneous/Abandoned/Admin Manager/Admin Manager.lua @@ -12,25 +12,24 @@ https://github.com/Chalwk77/HALO-SCRIPT-PROJECTS/blob/master/LICENSE api_version = '1.12.0.0' local AdminManager = { - cmds = {}, - commands_path = './Admin Manager/Commands/', -- management commands path - json = loadfile('./Admin Manager/Utils/Json.lua')(), + commands_dir = './Admin Manager/commands/', -- management commands path + json = loadfile('./Admin Manager/util/json.lua')(), dependencies = { ['./Admin Manager/'] = { 'settings' }, - ['./Admin Manager/Events/'] = { - 'Join', - 'OnCommand' + ['./Admin Manager/events/'] = { + 'on_command', + 'on_join', + 'on_start' }, - ['./Admin Manager/Utils/'] = { + ['./Admin Manager/util/'] = { 'FileIO', 'LoadDatabase', - 'Misc', - 'PermissionHandler' + 'Misc' } } } -function AdminManager:LoadDependencies() +function AdminManager:loadDependencies() local s = self for path, t in pairs(self.dependencies) do for _, file in pairs(t) do @@ -46,47 +45,34 @@ function OnScriptLoad() local am = AdminManager -- load file dependencies: - am:LoadDependencies() + am:loadDependencies() -- load management commands: - am:LoadManagementCMDS() + am:loadManagementCMDS() -- create default commands: - --am:WriteDefaultCommands() + am:WriteDefaultCommands() -- create default admins: --am:WriteDefaultAdmins() - -- Load admins and player commands: - am.admins = am:LoadAdmins() - am.commands = am:LoadCommands() - - register_callback(cb['EVENT_JOIN'], 'OnJoin') - register_callback(cb['EVENT_COMMAND'], 'OnCommand') - register_callback(cb['EVENT_GAME_START'], 'OnStart') - OnStart() + -- Load server admins and management commands: + am.admins = am:loadAdmins() + am.commands = am:loadCommands() + am.management = am:loadManagementCMDS() + am:onStart() end function OnStart() - if (get_var(0, '$gt') ~= 'n/a') then - local am = AdminManager - am.players = {} - am.players[0] = am:NewPlayer({ - id = 0, - level = #am.commands, - name = 'Server', - hash = 'N/A', - ip = '127.0.0.1' - }) - end + AdminManager:onStart() end -function OnJoin(Ply) - return AdminManager:OnJoin(Ply) +function OnJoin(...) + AdminManager:onJoin(...) end -function OnCommand(Ply, CMD) - return AdminManager:OnCommand(Ply, CMD) +function OnCommand(...) + return AdminManager:onCommand(...) end function OnScriptUnload() diff --git a/Miscellaneous/Abandoned/Admin Manager/Commands/hash_admin_add.lua b/Miscellaneous/Abandoned/Admin Manager/Commands/hash_admin_add.lua index e62c1b37..a039bb9d 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Commands/hash_admin_add.lua +++ b/Miscellaneous/Abandoned/Admin Manager/Commands/hash_admin_add.lua @@ -1,4 +1,4 @@ -local Command = { +local command = { name = 'hash_admin_add', description = 'Add hash admin', permission_level = 1, @@ -6,47 +6,49 @@ local Command = { } local date = os.date -function Command:Run(ply, args) +function command:run(id, args) - local p = self.players[ply] + local player = self.players[id] local dir = self.directories[1] local admins = self.admins - if (p:HasPermission(self.permission_level)) then + if (not player:hasPermission(self.permission_level)) then + return false + end + + local target, level = args[2], args[3] - local player, level = args[2], args[3] - if (not player or not level) then - p:Send(self.help) - elseif (player:match('%d+')) then - player = tonumber(player) - if player_present(player) then + if (not target or not level) then + player:send(self.help) + elseif (target:match('%d+')) then + target = tonumber(target) + if player_present(target) then - player = self.players[player] + local target_player = self.players[target] + local name = target_player.name + local hash = target_player.hash - local hash = player.hash - if (not admins.hash_admins[hash]) then + if (not admins.hash_admins[hash]) then - admins.hash_admins[hash] = { - level = tonumber(level), - name = player.name, - date = 'Added on ' .. date('%m/%d/%Y at %I:%M %p (%z) by ' .. p.name .. ' (' .. p.ip .. ')') - } - execute_command('adminadd ' .. player.id .. ' 4') + target_player.level = tonumber(level) + admins.hash_admins[hash] = { + level = tonumber(level), + name = name, + date = 'Added on ' .. date('%m/%d/%Y at %I:%M %p (%z) by ' .. player.name .. ' (' .. player.ip .. ')') + } + execute_command('adminadd ' .. target .. ' 4') - self:Write(dir, admins) - p:Send('Added ' .. player.name .. ' to the hash-admin list.') - else - p:Send(player.name .. ' is already a hash-admin (level ' .. admins.hash_admins[hash].level .. ')') - end + self:Write(dir, admins) + player:send('Added ' .. name .. ' to the hash-admin list.') else - p:Send('Player ' .. player .. ' is not present.') + player:send(name .. ' is already a hash-admin (level ' .. admins.hash_admins[hash].level .. ')') end + else + player:send('Player #' .. target .. ' is not present.') end - else - p:Send('Insufficient Permission') end return false end -return Command \ No newline at end of file +return command \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Commands/hash_admin_delete.lua b/Miscellaneous/Abandoned/Admin Manager/Commands/hash_admin_delete.lua index 6cd16ac8..79c581af 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Commands/hash_admin_delete.lua +++ b/Miscellaneous/Abandoned/Admin Manager/Commands/hash_admin_delete.lua @@ -1,22 +1,19 @@ -local Command = { +local command = { name = 'hash_admin_delete', description = 'Delete hash admin', permission_level = 1, help = 'Syntax: /$cmd ' } -function Command:Run(ply, args) +function command:run(id, args) - local player = args[2] - local p = self.players[player] + local target = args[2] + local player = self.players[target] - if (p:HasPermission(self.permission_level)) then + if (player:hasPermission(self.permission_level)) then - else - p:Send('Insufficient Permission') end - return false end -return Command \ No newline at end of file +return command \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Commands/hash_admins.lua b/Miscellaneous/Abandoned/Admin Manager/Commands/hash_admins.lua index f3e3b6de..bb2a99e2 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Commands/hash_admins.lua +++ b/Miscellaneous/Abandoned/Admin Manager/Commands/hash_admins.lua @@ -1,19 +1,16 @@ -local Command = { +local command = { name = 'hash_admins', description = 'List hash admins', permission_level = 1, help = 'Syntax: /$cmd' } -function Command:Run(ply, args) - local p = self.players[ply] - if (p:HasPermission(self.permission_level)) then +function command:run(id, args) + local player = self.players[id] + if (player:hasPermission(self.permission_level)) then - else - p:Send('Insufficient Permission') end - return false end -return Command \ No newline at end of file +return command \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Commands/ip_admin_add.lua b/Miscellaneous/Abandoned/Admin Manager/Commands/ip_admin_add.lua index c77f2f2e..e5b4e062 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Commands/ip_admin_add.lua +++ b/Miscellaneous/Abandoned/Admin Manager/Commands/ip_admin_add.lua @@ -1,4 +1,4 @@ -local Command = { +local command = { name = 'ip_admin_add', description = 'Add ip admin', permission_level = 1, @@ -6,47 +6,48 @@ local Command = { } local date = os.date -function Command:Run(ply, args) +function command:run(id, args) - local p = self.players[ply] + local player = self.players[id] local dir = self.directories[1] local admins = self.admins - if (p:HasPermission(self.permission_level)) then - - local player, level = args[2], args[3] - if (not player or not level) then - p:Send(self.help) - elseif (player:match('%d+')) then - player = tonumber(player) - if player_present(player) then - - player = self.players[player] - - local ip = player.ip - if (not admins.ip_admins[ip]) then - - admins.ip_admins[ip] = { - level = tonumber(level), - name = player.name, - date = 'Added on ' .. date('%m/%d/%Y at %I:%M %p (%z) by ' .. p.name .. ' (' .. p.ip .. ')') - } - execute_command('adminadd ' .. player.id .. ' 4') + if (not player:hasPermission(self.permission_level)) then + return false + end - self:Write(dir, admins) - p:Send('Added ' .. player.name .. ' to the ip-admin list.') - else - p:Send(player.name .. ' is already an ip-admin (level ' .. admins.ip_admins[ip].level .. ')') - end + local target, level = args[2], args[3] + if (not target or not level) then + player:send(self.help) + elseif (target:match('%d+')) then + target = tonumber(target) + if player_present(target) then + + local target_player = self.players[target] + local ip = target_player.ip + local name = target_player.name + + if (not admins.ip_admins[ip]) then + + target_player.level = tonumber(level) + admins.ip_admins[ip] = { + level = tonumber(level), + name = name, + date = 'Added on ' .. date('%m/%d/%Y at %I:%M %p (%z) by ' .. player.name .. ' (' .. player.ip .. ')') + } + execute_command('adminadd ' .. target .. ' 4') + + self:Write(dir, admins) + player:send('Added ' .. name .. ' to the ip-admin list.') else - p:Send('Player ' .. player .. ' is not present.') + player:send(name .. ' is already an ip-admin (level ' .. admins.ip_admins[ip].level .. ')') end + else + player:send('Player #' .. target .. ' is not present.') end - else - p:Send('Insufficient Permission') end return false end -return Command \ No newline at end of file +return command \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Commands/ip_admin_delete.lua b/Miscellaneous/Abandoned/Admin Manager/Commands/ip_admin_delete.lua index c3a2f383..eaf17642 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Commands/ip_admin_delete.lua +++ b/Miscellaneous/Abandoned/Admin Manager/Commands/ip_admin_delete.lua @@ -1,22 +1,19 @@ -local Command = { +local command = { name = 'ip_admin_delete', description = 'Delete ip admin', permission_level = 1, help = 'Syntax: /$cmd ' } -function Command:Run(ply, args) +function command:run(id, args) - local player = args[2] - local p = self.players[player] + local target = args[2] + local player = self.players[target] - if (p:HasPermission(self.permission_level)) then + if (player:hasPermission(self.permission_level)) then - else - p:Send('Insufficient Permission') end - return false end -return Command \ No newline at end of file +return command \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Commands/ip_admins.lua b/Miscellaneous/Abandoned/Admin Manager/Commands/ip_admins.lua index bc2870cd..4c91ddab 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Commands/ip_admins.lua +++ b/Miscellaneous/Abandoned/Admin Manager/Commands/ip_admins.lua @@ -1,19 +1,16 @@ -local Command = { +local command = { name = 'ip_admins', description = 'List ip admins', permission_level = 1, help = 'Syntax: /$cmd' } -function Command:Run(ply, args) - local p = self.players[ply] - if (p:HasPermission(self.permission_level)) then +function command:run(id, args) + local player = self.players[id] + if (player:hasPermission(self.permission_level)) then - else - p:Send('Insufficient Permission') end - return false end -return Command \ No newline at end of file +return command \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Commands/login.lua b/Miscellaneous/Abandoned/Admin Manager/Commands/login.lua index 0d8e38b3..b33c183d 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Commands/login.lua +++ b/Miscellaneous/Abandoned/Admin Manager/Commands/login.lua @@ -1,58 +1,62 @@ -local Command = { +local command = { name = 'l', description = 'Login to the server', help = 'Syntax: /$cmd [type: 1 = hash, 2 = ip or "your password"]' } -function Command:Run(ply, args) +function command:run(id, args) - local p = self.players[ply] - if (p:HasPermission()) then + local player = self.players[id] + if (not player:hasPermission()) then + return false + end - local admins = self.admins - local type = args[2] + local ip = player.ip + local name = player.name + local hash = player.hash - if (not type) then - p:Send(self.help) - elseif (type == 1) then - local hash = p.hash - if (admins.hash_admins[hash]) then - p.level = admins.hash_admins[hash].level - p:Send('Successfully logged in as ' .. p.name .. ' (level ' .. p.level .. ')') - else - p:Send('You are not a hash-admin.') - end - elseif (type == 2) then - local ip = p.ip - if (admins.ip_admins[ip]) then - p.level = admins.ip_admins[ip].level - p:Send('Successfully logged in as ' .. p.name .. ' (level ' .. p.level .. ')') - else - p:Send('You are not an ip-admin.') - end + local admins = self.admins + local type = args[2] + + if (not type) then + player:send(self.help) + elseif (type == 1) then + if (admins.hash_admins[hash]) then + player.level = admins.hash_admins[hash].level + player:send('Successfully logged in as ' .. name .. ' (level ' .. player.level .. ')') else + player:send('You are not a hash-admin.') + end + elseif (type == 2) then + if (admins.ip_admins[ip]) then + player.level = admins.ip_admins[ip].level + player:send('Successfully logged in as ' .. name .. ' (level ' .. player.level .. ')') + else + player:send('You are not an ip-admin.') + end + else - -- these admins have to used sapp's /login command - local password = table.concat(args, ' ', 2) - if (password and password ~= '') then - local username = p.name - if (admins.password_admins[username]) then - if (admins.password_admins[username].password == password) then - p.level = admins.password_admins[username].level - p:Send('Successfully logged in as ' .. p.name .. ' (level ' .. p.level .. ')') - else - p:Send('Incorrect username or password.') - end + -- these admins have to used sapp's /login command + local password = table.concat(args, ' ', 2) + if (password and password ~= '') then + if (admins.password_admins[name]) then + + password = self:decryptPassword(password) + if (admins.password_admins[name].password == password) then + player.level = admins.password_admins[name].level + player:send('Successfully logged in as ' .. name .. ' (level ' .. player.level .. ')') else - p:Send('Incorrect username or password.') + player:send('Incorrect username or password.') end else - p:Send('You must specify a password.') + player:send('Incorrect username or password.') end + else + player:Send('You must specify a password.') end end return false end -return Command \ No newline at end of file +return command \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Commands/logout.lua b/Miscellaneous/Abandoned/Admin Manager/Commands/logout.lua index 51a631a2..65f95003 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Commands/logout.lua +++ b/Miscellaneous/Abandoned/Admin Manager/Commands/logout.lua @@ -1,18 +1,19 @@ -local Command = { +local command = { name = 'lo', description = 'Logout of the server', help = 'Syntax: /$cmd' } -function Command:Run(ply, args) - local p = self.players[ply] - if (p:HasPermission()) then - p.level = 1 - p:Send('Successfully logged out.') - else - p:Send('Insufficient Permission') +function command:run(id) + local player = self.players[id] + if (id == 0) then + player:send('You cannot logout from the console.') + return + elseif (player:hasPermission()) then + player.level = 1 + player:send('Successfully logged out.') end return false end -return Command \ No newline at end of file +return command \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Commands/pw_admin_add.lua b/Miscellaneous/Abandoned/Admin Manager/Commands/pw_admin_add.lua index 448fc7c8..35949844 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Commands/pw_admin_add.lua +++ b/Miscellaneous/Abandoned/Admin Manager/Commands/pw_admin_add.lua @@ -1,4 +1,4 @@ -local Command = { +local command = { name = 'pw_admin_add', description = 'Add password admin', permission_level = 1, @@ -7,53 +7,51 @@ local Command = { local date = os.date -function Command:Run(ply, args) +function command:run(id, args) - local player = args[2] - - local p = self.players[ply] + local target = tonumber(args[2]) + local player = self.players[id] local dir = self.directories[1] - if (p:HasPermission(self.permission_level)) then - - local level = args[3] - local admins = self.admins - local password = table.concat(args, ' ', 4) - - if (not player or not level) then - p:Send(self.help) - elseif (not password or password == '') then - p:Send('You must specify a password.') - elseif (player:match('%d+')) then - player = tonumber(player) - if player_present(player) then - - player = self.players[player] - local username = player.name - - if (not admins.password_admins[username]) then - admins.password_admins[username] = { - password = password, - level = tonumber(level), - name = player.name, - date = 'Added on ' .. date('%m/%d/%Y at %I:%M %p (%z) by ' .. p.name .. ' (' .. p.ip .. ')') - } - execute_command('admin_add ' .. player.id .. ' "' .. password .. '" 4') - player.level = tonumber(level) - - self:Write(dir, admins) - p:Send('Added ' .. player.name .. ' to the password-admin list.') - else - p:Send(player.name .. ' is already a password-admin (level ' .. admins.password_admins[username].level .. ')') - end - else - p:Send('Player ' .. player .. ' is not present.') - end + + if (not player:hasPermission(self.permission_level)) then + return false + end + + local level = args[3] + local admins = self.admins + local password = table.concat(args, ' ', 4) + + if (not player or not level) then + player:send(self.help) + elseif (not password or password == '') then + player:send('You must specify a password.') + elseif (not target) then + player:send('Invalid Player ID.') + elseif player_present(target) then + + local target_player = self.players[target] + local name = target_player.name + + if (not admins.password_admins[name]) then + target_player.level = tonumber(level) + admins.password_admins[name] = { + password = self:encryptPassword(password), + level = tonumber(level), + name = name, + date = 'Added on ' .. date('%m/%d/%Y at %I:%M %p (%z) by ' .. player.name .. ' (' .. player.ip .. ')') + } + execute_command('admin_add ' .. target .. ' "' .. password .. '" 4') + + self:Write(dir, admins) + player:send('Added ' .. name .. ' to the password-admin list.') + else + player:send(name .. ' is already a password-admin (level ' .. admins.password_admins[name].level .. ')') end else - p:Send('Insufficient Permission') + player:send('Player #' .. target .. ' is not present.') end return false end -return Command \ No newline at end of file +return command \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Commands/pw_admin_delete.lua b/Miscellaneous/Abandoned/Admin Manager/Commands/pw_admin_delete.lua index 94cf2899..dfba8305 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Commands/pw_admin_delete.lua +++ b/Miscellaneous/Abandoned/Admin Manager/Commands/pw_admin_delete.lua @@ -1,22 +1,19 @@ -local Command = { +local command = { name = 'pw_admin_delete', description = 'Delete password admin', permission_level = 1, help = 'Syntax: /$cmd ' } -function Command:Run(ply, args) +function command:run(id, args) - local player = args[2] - local p = self.players[player] + local target = args[2] + local player = self.players[target] - if (p:HasPermission(self.permission_level)) then + if (player:HasPermission(self.permission_level)) then - else - p:Send('Insufficient Permission') end - return false end -return Command \ No newline at end of file +return command \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Commands/pw_admins.lua b/Miscellaneous/Abandoned/Admin Manager/Commands/pw_admins.lua index c74873cc..0fbd302d 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Commands/pw_admins.lua +++ b/Miscellaneous/Abandoned/Admin Manager/Commands/pw_admins.lua @@ -1,19 +1,16 @@ -local Command = { +local command = { name = 'pw_admins', description = 'List password admins', permission_level = 1, help = 'Syntax: /$cmd' } -function Command:Run(ply, args) - local p = self.players[ply] - if (p:HasPermission(self.permission_level)) then +function command:run(id, args) + local player = self.players[id] + if (player:hasPermission(self.permission_level)) then - else - p:Send('Insufficient Permission') end - return false end -return Command \ No newline at end of file +return command \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Events/Join.lua b/Miscellaneous/Abandoned/Admin Manager/Events/Join.lua deleted file mode 100644 index f04e9f21..00000000 --- a/Miscellaneous/Abandoned/Admin Manager/Events/Join.lua +++ /dev/null @@ -1,19 +0,0 @@ -local Event = {} - -function Event:NewPlayer(o) - setmetatable(o, { __index = self }) - self.__index = self - return o -end - -function Event:OnJoin(Ply) - self.players[Ply] = self:NewPlayer({ - level = 1, -- default level - id = Ply, - name = get_var(Ply, '$name'), - hash = get_var(Ply, '$hash'), - ip = get_var(Ply, '$ip'):match('%d+.%d+.%d+.%d+') - }) -end - -return Event \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Events/OnCommand.lua b/Miscellaneous/Abandoned/Admin Manager/Events/OnCommand.lua deleted file mode 100644 index 8bb92038..00000000 --- a/Miscellaneous/Abandoned/Admin Manager/Events/OnCommand.lua +++ /dev/null @@ -1,35 +0,0 @@ --- Command listener for management commands: - -local Message = {} - -local function CMDSplit(s) - local t = { } - for arg in s:gmatch('([^%s]+)') do - t[#t + 1] = arg:lower() - end - return t -end - -function Message:OnCommand(Ply, CMD) - - local args = CMDSplit(CMD) - local cmd = args[1] - - if (self.cmds[cmd]) then - return self.cmds[cmd]:Run(Ply, args) - end - - local p = self.players[Ply] - local level = p.level - - for l = 1, #self.commands do - local command_table = self.commands[l] - if (command_table[cmd] and l > level) then - p:Send('Insufficient Permission.') - p:Send('You must be level ' .. l .. ' or higher.') - return false - end - end -end - -return Message \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Utils/Misc.lua b/Miscellaneous/Abandoned/Admin Manager/Utils/Misc.lua deleted file mode 100644 index 39f0185f..00000000 --- a/Miscellaneous/Abandoned/Admin Manager/Utils/Misc.lua +++ /dev/null @@ -1,44 +0,0 @@ -local Misc = {} - -function Misc:LoadManagementCMDS() - local cmds = self.management_commands - for file, enabled in pairs(cmds) do - if (enabled) then - local command = require(self.commands_path .. file) - local cmd = command.name - self.cmds[cmd] = command - self.cmds[cmd].help = command.help:gsub('$cmd', cmd) - setmetatable(self.cmds[cmd], { __index = self }) - end - end -end - -function Misc:Send(msg) - return (self.id == 0 and cprint(msg) or rprint(self.id, msg)) -end - -function Misc:GetHighestLevel() - - local ip = self.ip - local admins = self.admins - local hash = self.hash - - local t = { [1] = { level = 1 } } - - if (admins.hash_admins[hash]) then - t[#t + 1] = { level = admins.hash_admins[hash].level } - end - - if (admins.ip_admins[ip]) then - t[#t + 1] = { level = admins.ip_admins[ip].level } - end - - table.sort(t, function(a, b) - return a.level > b.level - end) - print('highest level for ' .. self.name .. ' is ' .. t[1].level) - - return (t[1].level) -end - -return Misc \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Utils/PermissionHandler.lua b/Miscellaneous/Abandoned/Admin Manager/Utils/PermissionHandler.lua deleted file mode 100644 index 43a8237c..00000000 --- a/Miscellaneous/Abandoned/Admin Manager/Utils/PermissionHandler.lua +++ /dev/null @@ -1,12 +0,0 @@ -local Util = {} - -function Util:HasPermission(level) - level = level or -1 - local lvl = tonumber(get_var(self.id, '$lvl')) - if (self.id == 0 or lvl >= level) then - return true - end - return false -end - -return Util \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/admins.json b/Miscellaneous/Abandoned/Admin Manager/admins.json index 8c929b1f..0637a088 100644 --- a/Miscellaneous/Abandoned/Admin Manager/admins.json +++ b/Miscellaneous/Abandoned/Admin Manager/admins.json @@ -1,12 +1 @@ -{ - "hash_admins": [], - "ip_admins": [], - "password_admins": { - "Chalwk": { - "date": "Added on 09/17/2022 at 06:50 PM (+1200) by Server (127.0.0.1)", - "level": 4, - "name": "Chalwk", - "password": "cool" - } - } -} \ No newline at end of file +[] \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/commands.json b/Miscellaneous/Abandoned/Admin Manager/commands.json index 4b7e79f2..56ffac2f 100644 --- a/Miscellaneous/Abandoned/Admin Manager/commands.json +++ b/Miscellaneous/Abandoned/Admin Manager/commands.json @@ -1,11 +1,11 @@ { "1": { - "afk": true, "about": true, "clead": true, "info": true, "lead": true, "list": true, + "login": true, "report": true, "stats": true, "stfu": true, @@ -17,6 +17,7 @@ "2": { "adminadd": true, "admindel": true, + "afk": true, "change_password": true, "kdr": true, "mapcycle": true, diff --git a/Miscellaneous/Abandoned/Admin Manager/Utils/FileIO.lua b/Miscellaneous/Abandoned/Admin Manager/util/FileIO.lua similarity index 90% rename from Miscellaneous/Abandoned/Admin Manager/Utils/FileIO.lua rename to Miscellaneous/Abandoned/Admin Manager/util/FileIO.lua index 862e077d..504f109a 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Utils/FileIO.lua +++ b/Miscellaneous/Abandoned/Admin Manager/util/FileIO.lua @@ -23,9 +23,14 @@ function IO:Write(dir, content) end function IO:WriteDefaultAdmins() + local dir = self.directories[1] local admins = self:Read(dir) admins = self.json:decode(admins) + + -- Check if the file is empty first. + -- Check if file contains the default admins. + self:Write(dir, self.default_admins) end diff --git a/Miscellaneous/Abandoned/Admin Manager/Utils/LoadDatabase.lua b/Miscellaneous/Abandoned/Admin Manager/util/LoadDatabase.lua similarity index 91% rename from Miscellaneous/Abandoned/Admin Manager/Utils/LoadDatabase.lua rename to Miscellaneous/Abandoned/Admin Manager/util/LoadDatabase.lua index 0e40a9fc..0513c2bd 100644 --- a/Miscellaneous/Abandoned/Admin Manager/Utils/LoadDatabase.lua +++ b/Miscellaneous/Abandoned/Admin Manager/util/LoadDatabase.lua @@ -1,6 +1,6 @@ local Database = { } -function Database:LoadAdmins() +function Database:loadAdmins() local dir = self.directories[1] local admins = self:Read(dir) @@ -13,7 +13,7 @@ function Database:LoadAdmins() return admins or {} end -function Database:LoadCommands() +function Database:loadCommands() local dir = self.directories[2] local commands = self:Read(dir) diff --git a/Miscellaneous/Abandoned/Admin Manager/util/Misc.lua b/Miscellaneous/Abandoned/Admin Manager/util/Misc.lua new file mode 100644 index 00000000..180b22b9 --- /dev/null +++ b/Miscellaneous/Abandoned/Admin Manager/util/Misc.lua @@ -0,0 +1,71 @@ +local misc = {} + +function misc:loadManagementCMDS() + local t = {} + local cmds = self.management_commands + for file, enabled in pairs(cmds) do + if (enabled) then + local command = require(self.commands_dir .. file) + local cmd = command.name + t[cmd] = command + t[cmd].help = command.help:gsub('$cmd', cmd) + setmetatable(t[cmd], { __index = self }) + end + end + return t +end + +function misc:hasPermission(level) + + local id = self.id + level = level or -1 + + local lvl = tonumber(get_var(id, '$lvl')) + if (id == 0 or lvl >= level) then + return true + end + + self:send('Insufficient Permission.') + return false +end + +function misc:send(msg) + return (self.id == 0 and cprint(msg) or rprint(self.id, msg)) +end + +function misc:encryptPassword(raw_password) + + local password = raw_password + local len = string.len(password) + local t = {} + for i = 1, len do + t[i] = string.byte(password, i) + end + + local encrypted = '' + for i = 1, len do + encrypted = encrypted .. string.format('%02X', t[i]) + end + + return encrypted +end + +function misc:decryptPassword(encrypted_password) + local password = encrypted_password + + local len = string.len(password) + local t = {} + + for i = 1, len, 2 do + t[#t + 1] = tonumber('0x' .. password:sub(i, i + 1)) + end + + local decrypted = '' + for i = 1, #t do + decrypted = decrypted .. string.char(t[i]) + end + + return decrypted +end + +return misc \ No newline at end of file diff --git a/Miscellaneous/Abandoned/Admin Manager/Utils/Json.lua b/Miscellaneous/Abandoned/Admin Manager/util/json.lua similarity index 100% rename from Miscellaneous/Abandoned/Admin Manager/Utils/Json.lua rename to Miscellaneous/Abandoned/Admin Manager/util/json.lua