3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 13:29:27 +01:00
This commit is contained in:
Shivaram Lingamneni 2020-02-21 06:10:35 -05:00
parent 0d5a4fd584
commit 438fffab99
4 changed files with 54 additions and 16 deletions

View File

@ -116,6 +116,11 @@ func init() {
minParams: 1,
oper: true,
},
"DEOPER": {
handler: deoperHandler,
minParams: 0,
oper: true,
},
"DLINE": {
handler: dlineHandler,
minParams: 1,

View File

@ -2141,16 +2141,19 @@ func operHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
return false
}
// applies operator status to a client, who MUST NOT already be an operator
// adds or removes operator status
// XXX: to add oper, this calls into ApplyUserModeChanges, but to remove oper,
// ApplyUserModeChanges calls into this, because the commands are asymmetric
// (/OPER to add, /MODE self -o to remove)
func applyOper(client *Client, oper *Oper, rb *ResponseBuffer) {
details := client.Details()
oldNickmask := details.nickMask
client.SetOper(oper)
newNickmask := client.NickMaskString()
if newNickmask != oldNickmask {
client.sendChghost(oldNickmask, oper.Vhost)
newDetails := client.Details()
if details.nickMask != newDetails.nickMask {
client.sendChghost(details.nickMask, newDetails.hostname)
}
if oper != nil {
// set new modes: modes.Operator, plus anything specified in the config
modeChanges := make([]modes.ModeChange, len(oper.Modes)+1)
modeChanges[0] = modes.ModeChange{
@ -2160,16 +2163,27 @@ func applyOper(client *Client, oper *Oper, rb *ResponseBuffer) {
copy(modeChanges[1:], oper.Modes)
applied := ApplyUserModeChanges(client, modeChanges, true)
client.server.snomasks.Send(sno.LocalOpers, fmt.Sprintf(ircfmt.Unescape("Client opered up $c[grey][$r%s$c[grey], $r%s$c[grey]]"), client.nickMaskString, oper.Name))
client.server.snomasks.Send(sno.LocalOpers, fmt.Sprintf(ircfmt.Unescape("Client opered up $c[grey][$r%s$c[grey], $r%s$c[grey]]"), newDetails.nickMask, oper.Name))
rb.Broadcast(nil, client.server.name, RPL_YOUREOPER, details.nick, client.t("You are now an IRC operator"))
rb.Broadcast(nil, client.server.name, "MODE", details.nick, applied.String())
} else {
client.server.snomasks.Send(sno.LocalOpers, fmt.Sprintf(ircfmt.Unescape("Client deopered $c[grey][$r%s$c[grey]]"), newDetails.nickMask))
}
for _, session := range client.Sessions() {
// client may now be unthrottled by the fakelag system
session.resetFakelag()
}
}
// DEOPER
func deoperHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
// pretend they sent /MODE $nick -o
fakeModeMsg := ircmsg.MakeMessage(nil, "", "MODE", client.Nick(), "-o")
return umodeHandler(server, client, fakeModeMsg, rb)
}
// PART <channel>{,<channel>} [<reason>]
func partHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
channels := strings.Split(msg.Params[0], ",")

View File

@ -160,6 +160,12 @@ Prints debug information about the IRCd. <option> can be one of:
* STARTCPUPROFILE: Starts the CPU profiler.
* STOPCPUPROFILE: Stops the CPU profiler.
* PROFILEHEAP: Writes out the CPU profiler info.`,
},
"deoper": {
oper: true,
text: `DEOPER
DEOPER removes the IRCop privileges granted to you by a successful /OPER.`,
},
"dline": {
oper: true,

View File

@ -45,13 +45,26 @@ func ApplyUserModeChanges(client *Client, changes modes.ModeChanges, force bool)
}
case modes.Remove:
var removedSnomasks string
if client.SetMode(change.Mode, false) {
if change.Mode == modes.Invisible {
client.server.stats.ChangeInvisible(-1)
} else if change.Mode == modes.Operator || change.Mode == modes.LocalOperator {
removedSnomasks = client.server.snomasks.String(client)
client.server.stats.ChangeOperators(-1)
applyOper(client, nil, nil)
if removedSnomasks != "" {
client.server.snomasks.RemoveClient(client)
}
}
applied = append(applied, change)
if removedSnomasks != "" {
applied = append(applied, modes.ModeChange{
Mode: modes.ServerNotice,
Op: modes.Remove,
Arg: removedSnomasks,
})
}
}
}