3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-13 07:29:30 +01:00

Add SAMODE command, restricted by oper capab

This commit is contained in:
Daniel Oaks 2017-01-23 09:36:13 +10:00
parent c8b5fb65e0
commit 9e65d9b87e
4 changed files with 31 additions and 15 deletions

View File

@ -187,6 +187,11 @@ var Commands = map[string]Command{
minParams: 2, minParams: 2,
oper: true, oper: true,
}, },
"SAMODE": {
handler: modeHandler,
minParams: 1,
capabs: []string{"samode"},
},
"SCENE": { "SCENE": {
handler: sceneHandler, handler: sceneHandler,
minParams: 2, minParams: 2,

View File

@ -295,6 +295,14 @@ Sends the text to the given targets as a PRIVMSG.`,
text: `SANICK <currentnick> <newnick> text: `SANICK <currentnick> <newnick>
Gives the given user a new nickname.`, Gives the given user a new nickname.`,
},
"samode": {
oper: true,
text: `SAMODE <target> [<modestring> [<mode arguments>...]]
Forcibly sets and removes modes from the given target -- only available to
opers. For more specific information on mode characters, see the help for
"cmode" and "umode".`,
}, },
"scene": { "scene": {
text: `SCENE <target> <text to be sent> text: `SCENE <target> <text to be sent>

View File

@ -263,9 +263,7 @@ func umodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
return false return false
} }
//TODO(dan): restricting to Operator here should be done with SAMODE only if client != target && msg.Command != "SAMODE" {
// point SAMODE at this handler too, if they are operator and SAMODE was called then fine
if client != target && !client.flags[Operator] {
if len(msg.Params) > 1 { if len(msg.Params) > 1 {
client.Send(nil, server.name, ERR_USERSDONTMATCH, client.nick, "Can't change modes for other users") client.Send(nil, server.name, ERR_USERSDONTMATCH, client.nick, "Can't change modes for other users")
} else { } else {
@ -420,7 +418,7 @@ func cmodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
for _, change := range changes { for _, change := range changes {
// chan priv modes are checked specially so ignore them // chan priv modes are checked specially so ignore them
// means regular users can't view ban/except lists... but I'm not worried about that // means regular users can't view ban/except lists... but I'm not worried about that
if ChannelModePrefixes[change.mode] == "" && !clientIsOp { if msg.Command != "SAMODE" && ChannelModePrefixes[change.mode] == "" && !clientIsOp {
if !alreadySentPrivError { if !alreadySentPrivError {
alreadySentPrivError = true alreadySentPrivError = true
client.Send(nil, client.server.name, ERR_CHANOPRIVSNEEDED, channel.name, "You're not a channel operator") client.Send(nil, client.server.name, ERR_CHANOPRIVSNEEDED, channel.name, "You're not a channel operator")
@ -512,6 +510,9 @@ func cmodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
// make sure client has privs to edit the given prefix // make sure client has privs to edit the given prefix
var hasPrivs bool var hasPrivs bool
if msg.Command == "SAMODE" {
hasPrivs = true
} else {
for _, mode := range ChannelPrivModes { for _, mode := range ChannelPrivModes {
if channel.members[client][mode] { if channel.members[client][mode] {
hasPrivs = true hasPrivs = true
@ -527,6 +528,7 @@ func cmodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
break break
} }
} }
}
casefoldedName, err := CasefoldName(change.arg) casefoldedName, err := CasefoldName(change.arg)
if err != nil { if err != nil {

View File

@ -154,6 +154,7 @@ oper-classes:
capabilities: capabilities:
- "oper:rehash" - "oper:rehash"
- "oper:die" - "oper:die"
- "samode"
# ircd operators # ircd operators
opers: opers: