Skip to content

Commit

Permalink
ACL starting point
Browse files Browse the repository at this point in the history
  • Loading branch information
S-S-X committed May 12, 2023
1 parent 0f106b1 commit edec5a6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
12 changes: 1 addition & 11 deletions chatcommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,7 @@ local join_channel = {
return false, "ERROR: You already joined "..channel_name..", no need to rejoin"
end

if beerchat.channels[channel_name].password and beerchat.channels[channel_name].password ~= "" then
if #str == 1 then
return false, "ERROR: This channel requires that you supply a password. "
.. "Supply it in the following format: /jc my channel,password01"
end
if str[2] ~= beerchat.channels[channel_name].password then
return false, "ERROR: Invalid password."
end
end

return beerchat.join_channel(name, channel_name)
return beerchat.join_channel(name, channel_name, { password = str[2] })
end
}

Expand Down
40 changes: 40 additions & 0 deletions plugin/acl.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--luacheck: no_unused_args

--[[ TODO:
* Move rest of password stuff from chatcommands.
* Possibly also move channel invitation commands here.
* Add simple channel ACLs. Invite command to add users, kick command to remove users.
* Build simple RBAC on top of that to allow multiple managers / role based permissions for users.
--]]

beerchat.register_callback('after_joinplayer', function(player)
-- CHECK ACTIVE CHANNEL ACL HERE AND TAKE ACTION IF NEEDED
end)

beerchat.register_callback('before_invite', function(name, recipient, channel)
-- INJECT EVERYTHING THAT IS REQUIRED TO HAVE FULL ACCESS TO CHANNEL SO THAT
-- PLAYERS WITH THE FORCE CAN MOVE ANYONE TO ANY CHANNEL, ALSO TO LOCKED CHANNELS.
end)

beerchat.register_callback('before_join', function(name, channel_name, options)
local channel = beerchat.channels[channel_name]
if channel.password and channel.password ~= "" then
if not options or not options.password or options.password == "" then
return false, "ERROR: This channel requires that you supply a password. "
.. "Supply it in the following format: /jc my channel,password01"
end
if options.password ~= channel.password then
return false, "ERROR: Invalid password."
end
end
end)

beerchat.register_callback('before_switch_chan', function(name, oldchannel, newchannel)
-- COULD BE USED TO REVALIDATE ACCESS IF NEEDED, PROBABLY NOT NEEDED
-- IF KICKING PLAYERS FROM CHANNELS IS ALSO ADDED.
end)

beerchat.register_callback('on_forced_join', function(name, target, channel, from_channel)
-- INJECT EVERYTHING THAT IS REQUIRED TO HAVE FULL ACCESS TO CHANNEL SO THAT
-- PLAYERS WITH THE FORCE CAN MOVE ANYONE TO ANY CHANNEL, ALSO TO LOCKED CHANNELS.
end)
2 changes: 2 additions & 0 deletions plugin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ load_plugin("me", true)
-- Allows switching channels with "#channelname" and sending to channel with "#channelname message here"
load_plugin("hash", true)

load_plugin("acl", true)

-- Allows "@player message here" to send private messages to players
load_plugin("pm", true)

Expand Down

0 comments on commit edec5a6

Please sign in to comment.