Skip to content

Commit

Permalink
....
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalwk77 committed Jul 16, 2023
1 parent 0e88572 commit 2d41201
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 83 deletions.
55 changes: 35 additions & 20 deletions INDEV/Admin Manager/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,54 @@ highest of the two. Furthermore, a player will inherit all commands from the adm

## Management Commands:

todo: -- ADD COMMANDS ABOVE hash_ban, hash_bans, hash_unban, ip_ban, ip_bans, ip_unban, silence, silence_list, unsilence

| Command | Description | Permission Level |
|---------------------------------------------------------------------------------------------|--------------------------------------------------|------------------|
| **hash_admin_add** `<player id>` `<level>` | Add player as a hash-admin | **1** |
| **hash_admin_del** `<player id>` | Remove player as a hash-admin | **1** |
| **hash_admin_list** | List all hash-admins | **1** |
| **ip_admin_add** `<player id>` `<level>` | Add player as an ip-admin | **1** |
| **ip_admin_del** `<player id>` | Remove player as an ip-admin | **1** |
| **ip_admin_list** | List all ip-admins | **1** |
| **pw_admin_add** `<player id>` `<level> <password>` | Add player as a password-admin | **1** |
| **pw_admin_del** `<player id>` | Remove player as a password-admin | **1** |
| **pw_admin_list** | List all password-admins | **1** |
| **l** `<password>` | Login with a password (username is your IGN) | **1** |
| **lo** | Logout of the server | **1** |
| **change_level** `<player id>` `<type (hash/ip/password)>` | Change player admin level | **1** |
| **level_add** `<level>` | Add an admin level | **1** |
| **level_delete** `<level>` | Delete an admin level (requires confirmation) | **1** |
| **confirm** | Confirm level delete | **1** |
| **set_command** `<command>` `<level>` `(opt 3rd arg: "true" to enable, "false" to disable)` | Add or set a new/existing command to a new level | **1** |
| **disable_command** `<command>` | Disables a command | **1** |
| **enable_command** `<command>` | Enables a command | **1** |
| **hash_admin_add** `<player id>` `<level>` | Add player as a hash-admin | **6** |
| **hash_admin_del** `<player id>` | Remove player as a hash-admin | **6** |
| **hash_admin_list** | List all hash-admins | **6** |
| **ip_admin_add** `<player id>` `<level>` | Add player as an ip-admin | **6** |
| **ip_admin_del** `<player id>` | Remove player as an ip-admin | **6** |
| **ip_admin_list** | List all ip-admins | **6** |
| **pw_admin_add** `<player id>` `<level> <password>` | Add player as a password-admin | **6** |
| **pw_admin_del** `<player id>` | Remove player as a password-admin | **6** |
| **pw_admin_list** | List all password-admins | **6** |
| **l** `<password>` | Login with a password (username is your IGN) | **6** |
| **lo** | Logout of the server | **6** |
| **change_level** `<player id>` `<type (hash/ip/password)>` | Change player admin level | **6** |
| **level_add** `<level>` | Add an admin level | **6** |
| **level_delete** `<level>` | Delete an admin level (requires confirmation) | **6** |
| **confirm** | Confirm level delete | **6** |
| **set_command** `<command>` `<level>` `(opt 3rd arg: "true" to enable, "false" to disable)` | Add or set a new/existing command to a new level | **6** |
| **disable_command** `<command>` | Disables a command | **6** |
| **enable_command** `<command>` | Enables a command | **6** |
| **hash_ban** `<player id>` `<flag (-y -mo -w -d -h -m -s -r "example reason")>` | Ban a player by hash | **6** |
| **hash_bans** | List all hash-bans | **6** |
| **hash_unban** `<ban id>` | Unban a player's hash | **6** |
| **ip_ban** `<player id>` `<flag (-y -mo -w -d -h -m -s -r "example reason")>` | Ban a player by IP | **6** |
| **ip_bans** | List all IP-bans | **6** |
| **ip_unban** `<ban id>` | Unban a player's IP | **6** |
| **silence** `<player id>` `<flag (-y -mo -w -d -h -m -s -r "example reason")>` | Silence a player | **6** |
| **silence_list** | List all silenced players | **6** |
| **unsilence** `<player id>` | Unsilence a player | **6** |

Each management command above has a permission level.

The permission level is the minimum admin level required to use the command.
This can be edited inside the *./Admin Manager/commands/<command>* directory.

Additionally, each command has a `help` argument - this will display the command's usage and description. For example: `hash_admin_add help`
Additionally, each command has a `help` argument - this will display the command's usage and description. For
example: `hash_admin_add help`

### Getting started:
Before you can add members of your clan/community as admins, you must first add yourself as an admin.

Before you can add members of your clan/community as admins, you must first add yourself as an admin.
This can be done by joining the server and executing one of the admin-add commands from the server console.
Once you're an admin, you can add other admins in-game using the desired admin-add command.

### Password encryption:

> Passwords are encrypted using the SHA256 algorithm.
### Admin database:
Expand All @@ -54,6 +68,7 @@ Once you're an admin, you can add other admins in-game using the desired admin-a
> The file is located in the `./Admin Manager` folder.
### Logging:

> Admin commands are logged in the `logs.json` file. This file is created automatically when the plugin is loaded.
> You can optionally log management commands and/or default commands.
Expand Down
6 changes: 6 additions & 0 deletions INDEV/Admin Manager/bans.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"hash": [],
"ip": [],
"mute": [],
"name": []
}
40 changes: 9 additions & 31 deletions INDEV/Admin Manager/commands/hash_bans.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,24 @@ local command = {
description = 'Command ($cmd) | List all hash-bans.',
permission_level = 6,
help = 'Syntax: /$cmd>',
output = '[$ban_id] [$offender] [Expires: $Y/$m/$d - $H:$M:$S]'
output = '[$id] [$offender] [Expires: $years/$months/$days - $hours:$minutes:$seconds]'
}

local function formatOutput(t)

local str = t.str

for k,v in pairs(t) do
str = str:gsub('%$' .. k, v)
end

return str
end

function command:run(id, args)

local admin = self.players[id]
if admin:hasPermission(self.permission_level, args[1]) then

admin:send('[Hash-Bans]') -- Header

local found

local header = true
for _, ban in pairs(self.bans['hash']) do
found = true
local str = formatOutput({
ban_id = ban.id,
offender = ban.offender,
str = self.output,
Y = ban.time.year,
m = ban.time.month,
d = ban.time.day,
H = ban.time.hour,
M = ban.time.min,
S = ban.time.sec
})
admin:send(str)
if (header) then
header = false
admin:send('[Hash-Bans]')
end
local stdout = self:banViewFormat(ban.id, ban.offender, ban.time)
admin:send(stdout)
end

if (not found) then
if (header) then
admin:send('There are no hash-bans.')
end
self:log(admin.name .. ' viewed the hash-ban list.', self.logging.management)
Expand Down
42 changes: 10 additions & 32 deletions INDEV/Admin Manager/commands/ip_bans.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,27 @@ local command = {
description = 'Command ($cmd) | List all IP-bans.',
permission_level = 6,
help = 'Syntax: /$cmd>',
output = '[$ban_id] [$offender] [Expires: $Y/$m/$d - $H:$M:$S]'
output = '[$id] [$offender] [Expires: $years/$months/$days - $hours:$minutes:$seconds]'
}

local function formatOutput(t)

local str = t.str

for k,v in pairs(t) do
str = str:gsub('%$' .. k, v)
end

return str
end

function command:run(id, args)

local admin = self.players[id]
if admin:hasPermission(self.permission_level, args[1]) then

admin:send('[IP-Bans]') -- Header

local found

local header = true
for _, ban in pairs(self.bans['ip']) do
found = true
local str = formatOutput({
ban_id = ban.id,
offender = ban.offender,
str = self.output,
Y = ban.time.year,
m = ban.time.month,
d = ban.time.day,
H = ban.time.hour,
M = ban.time.min,
S = ban.time.sec
})
admin:send(str)
if (header) then
header = false
admin:send('[IP-Bans]')
end
local stdout = self:banViewFormat(ban.id, ban.offender, ban.time)
admin:send(stdout)
end

if (not found) then
if (header) then
admin:send('There are no IP-bans.')
end
self:log(admin.name .. ' viewed the ip-ban list.', self.logging.management)
self:log(admin.name .. ' viewed the IP-ban list.', self.logging.management)
end

return false
Expand Down
Empty file added INDEV/Admin Manager/logs.json
Empty file.
33 changes: 33 additions & 0 deletions INDEV/Admin Manager/util/ban.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,39 @@ function util:banSTDOUT(...)
return str
end

function util:banViewFormat(...)

local args = { ... }
local id = args[1]
local offender = args[2]

local expiration = args[3]
local years = expiration.year
local months = expiration.month
local days = expiration.day
local hours = expiration.hour
local minutes = expiration.min
local seconds = expiration.sec

local placeholders = {
['$id'] = id,
['$offender'] = offender,
['$years'] = years,
['$months'] = months,
['$days'] = days,
['$hours'] = hours,
['$minutes'] = minutes,
['$seconds'] = seconds
}

local str = self.output
for k, v in pairs(placeholders) do
str = str:gsub(k, v)
end

return str
end

function util:newBan(admin_name, offender_name, hash, ip, reason, time, type)
return {
added_on = self:getDate(),
Expand Down

0 comments on commit 2d41201

Please sign in to comment.