mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-29 07:29:31 +01:00
maintain lenBytes as a running count
This commit is contained in:
parent
2779fe7c10
commit
8efbc4bc32
@ -146,6 +146,7 @@ type MultilineBatch struct {
|
||||
target string
|
||||
responseLabel string // this is the value of the labeled-response tag sent with BATCH
|
||||
message utils.SplitMessage
|
||||
lenBytes int
|
||||
tags map[string]string
|
||||
}
|
||||
|
||||
@ -168,7 +169,7 @@ func (s *Session) EndMultilineBatch(label string) (batch MultilineBatch, err err
|
||||
s.fakelag.Unsuspend()
|
||||
|
||||
// heuristics to estimate how much data they used while fakelag was suspended
|
||||
fakelagBill := (batch.message.LenBytes() / 512) + 1
|
||||
fakelagBill := (batch.lenBytes / 512) + 1
|
||||
fakelagBillLines := (batch.message.LenLines() * 60) / 512
|
||||
if fakelagBill < fakelagBillLines {
|
||||
fakelagBill = fakelagBillLines
|
||||
|
@ -1816,9 +1816,13 @@ func absorbBatchedMessage(server *Server, client *Client, msg ircmsg.IrcMessage,
|
||||
errorCode, errorMessage = "MULTILINE_INVALID", client.t("Cannot send a blank line with the multiline concat tag")
|
||||
return
|
||||
}
|
||||
if !isConcat && len(rb.session.batch.message.Split) != 0 {
|
||||
rb.session.batch.lenBytes++ // bill for the newline
|
||||
}
|
||||
rb.session.batch.message.Append(msg.Params[1], isConcat)
|
||||
rb.session.batch.lenBytes += len(msg.Params[1])
|
||||
config := server.Config()
|
||||
if config.Limits.Multiline.MaxBytes < rb.session.batch.message.LenBytes() {
|
||||
if config.Limits.Multiline.MaxBytes < rb.session.batch.lenBytes {
|
||||
errorCode, errorMessage = "MULTILINE_MAX_BYTES", strconv.Itoa(config.Limits.Multiline.MaxBytes)
|
||||
} else if config.Limits.Multiline.MaxLines != 0 && config.Limits.Multiline.MaxLines < rb.session.batch.message.LenLines() {
|
||||
errorCode, errorMessage = "MULTILINE_MAX_LINES", strconv.Itoa(config.Limits.Multiline.MaxLines)
|
||||
|
@ -67,20 +67,6 @@ func (sm *SplitMessage) LenLines() int {
|
||||
return len(sm.Split)
|
||||
}
|
||||
|
||||
func (sm *SplitMessage) LenBytes() (result int) {
|
||||
if sm.Split == nil {
|
||||
return len(sm.Message)
|
||||
}
|
||||
for i := 0; i < len(sm.Split); i++ {
|
||||
result += len(sm.Split[i].Message)
|
||||
// bill for the joining newline if necessary
|
||||
if i != 0 && !sm.Split[i].Concat {
|
||||
result += 1
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (sm *SplitMessage) ValidMultiline() bool {
|
||||
// must contain at least one nonblank line
|
||||
for i := 0; i < len(sm.Split); i++ {
|
||||
|
Loading…
Reference in New Issue
Block a user