fix: address review findings — dynamic version, deduplicate KILL, update README
All checks were successful
check / check (push) Successful in 1m3s
All checks were successful
check / check (push) Successful in 1m3s
This commit is contained in:
@@ -331,18 +331,12 @@ func (hdlr *Handlers) handleKill(
|
||||
}
|
||||
|
||||
lines := bodyLines()
|
||||
if len(lines) == 0 {
|
||||
hdlr.respondIRCError(
|
||||
writer, request, clientID, sessionID,
|
||||
irc.ErrNeedMoreParams, nick,
|
||||
[]string{irc.CmdKill},
|
||||
"Not enough parameters",
|
||||
)
|
||||
|
||||
return
|
||||
var targetNick string
|
||||
if len(lines) > 0 {
|
||||
targetNick = strings.TrimSpace(lines[0])
|
||||
}
|
||||
|
||||
targetNick := strings.TrimSpace(lines[0])
|
||||
if targetNick == "" {
|
||||
hdlr.respondIRCError(
|
||||
writer, request, clientID, sessionID,
|
||||
@@ -383,8 +377,11 @@ func (hdlr *Handlers) handleKill(
|
||||
return
|
||||
}
|
||||
|
||||
hdlr.executeKillUser(
|
||||
request, targetSID, targetNick, nick, reason,
|
||||
quitReason := "Killed (" + nick + " (" + reason + "))"
|
||||
|
||||
hdlr.svc.BroadcastQuit(
|
||||
request.Context(), targetSID,
|
||||
targetNick, quitReason,
|
||||
)
|
||||
|
||||
hdlr.respondJSON(writer, request,
|
||||
@@ -392,71 +389,6 @@ func (hdlr *Handlers) handleKill(
|
||||
http.StatusOK)
|
||||
}
|
||||
|
||||
// executeKillUser forcibly disconnects a user: broadcasts
|
||||
// QUIT to their channels, parts all channels, and deletes
|
||||
// the session.
|
||||
func (hdlr *Handlers) executeKillUser(
|
||||
request *http.Request,
|
||||
targetSID int64,
|
||||
targetNick, killerNick, reason string,
|
||||
) {
|
||||
ctx := request.Context()
|
||||
|
||||
quitMsg := "Killed (" + killerNick + " (" + reason + "))"
|
||||
|
||||
quitBody, err := json.Marshal([]string{quitMsg})
|
||||
if err != nil {
|
||||
hdlr.log.Error(
|
||||
"marshal kill quit body", "error", err,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
channels, _ := hdlr.params.Database.
|
||||
GetSessionChannels(ctx, targetSID)
|
||||
|
||||
notified := map[int64]bool{}
|
||||
|
||||
var dbID int64
|
||||
|
||||
if len(channels) > 0 {
|
||||
dbID, _, _ = hdlr.params.Database.InsertMessage(
|
||||
ctx, irc.CmdQuit, targetNick, "",
|
||||
nil, json.RawMessage(quitBody), nil,
|
||||
)
|
||||
}
|
||||
|
||||
for _, chanInfo := range channels {
|
||||
memberIDs, _ := hdlr.params.Database.
|
||||
GetChannelMemberIDs(ctx, chanInfo.ID)
|
||||
|
||||
for _, mid := range memberIDs {
|
||||
if mid != targetSID && !notified[mid] {
|
||||
notified[mid] = true
|
||||
|
||||
_ = hdlr.params.Database.EnqueueToSession(
|
||||
ctx, mid, dbID,
|
||||
)
|
||||
|
||||
hdlr.broker.Notify(mid)
|
||||
}
|
||||
}
|
||||
|
||||
_ = hdlr.params.Database.PartChannel(
|
||||
ctx, chanInfo.ID, targetSID,
|
||||
)
|
||||
|
||||
_ = hdlr.params.Database.DeleteChannelIfEmpty(
|
||||
ctx, chanInfo.ID,
|
||||
)
|
||||
}
|
||||
|
||||
_ = hdlr.params.Database.DeleteSession(
|
||||
ctx, targetSID,
|
||||
)
|
||||
}
|
||||
|
||||
// handleWallops handles the WALLOPS command.
|
||||
// Broadcasts a message to all users with +w usermode
|
||||
// (oper only).
|
||||
|
||||
Reference in New Issue
Block a user