mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
fix #725
This commit is contained in:
parent
0d5a4fd584
commit
438fffab99
@ -116,6 +116,11 @@ func init() {
|
||||
minParams: 1,
|
||||
oper: true,
|
||||
},
|
||||
"DEOPER": {
|
||||
handler: deoperHandler,
|
||||
minParams: 0,
|
||||
oper: true,
|
||||
},
|
||||
"DLINE": {
|
||||
handler: dlineHandler,
|
||||
minParams: 1,
|
||||
|
@ -2141,35 +2141,49 @@ 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)
|
||||
}
|
||||
|
||||
// set new modes: modes.Operator, plus anything specified in the config
|
||||
modeChanges := make([]modes.ModeChange, len(oper.Modes)+1)
|
||||
modeChanges[0] = modes.ModeChange{
|
||||
Mode: modes.Operator,
|
||||
Op: modes.Add,
|
||||
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{
|
||||
Mode: modes.Operator,
|
||||
Op: modes.Add,
|
||||
}
|
||||
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]]"), 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))
|
||||
}
|
||||
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))
|
||||
|
||||
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())
|
||||
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], ",")
|
||||
|
@ -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,
|
||||
|
13
irc/modes.go
13
irc/modes.go
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user