mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
changes from discussion
This commit is contained in:
parent
acc9d8c13d
commit
c0b554e98c
@ -580,14 +580,14 @@ func (session *Session) playResume() {
|
|||||||
|
|
||||||
timestamp := session.resumeDetails.Timestamp
|
timestamp := session.resumeDetails.Timestamp
|
||||||
gap := lastDiscarded.Sub(timestamp)
|
gap := lastDiscarded.Sub(timestamp)
|
||||||
session.resumeDetails.HistoryIncomplete = gap > 0
|
session.resumeDetails.HistoryIncomplete = gap > 0 || timestamp.IsZero()
|
||||||
gapSeconds := int(gap.Seconds()) + 1 // round up to avoid confusion
|
gapSeconds := int(gap.Seconds()) + 1 // round up to avoid confusion
|
||||||
|
|
||||||
details := client.Details()
|
details := client.Details()
|
||||||
oldNickmask := details.nickMask
|
oldNickmask := details.nickMask
|
||||||
client.SetRawHostname(session.rawHostname)
|
client.SetRawHostname(session.rawHostname)
|
||||||
hostname := client.Hostname() // may be a vhost
|
hostname := client.Hostname() // may be a vhost
|
||||||
timestampString := session.resumeDetails.Timestamp.Format(IRCv3TimestampFormat)
|
timestampString := timestamp.Format(IRCv3TimestampFormat)
|
||||||
|
|
||||||
// send quit/resume messages to friends
|
// send quit/resume messages to friends
|
||||||
for friend := range friends {
|
for friend := range friends {
|
||||||
@ -596,23 +596,29 @@ func (session *Session) playResume() {
|
|||||||
}
|
}
|
||||||
for _, fSession := range friend.Sessions() {
|
for _, fSession := range friend.Sessions() {
|
||||||
if fSession.capabilities.Has(caps.Resume) {
|
if fSession.capabilities.Has(caps.Resume) {
|
||||||
if session.resumeDetails.HistoryIncomplete {
|
if !session.resumeDetails.HistoryIncomplete {
|
||||||
|
fSession.Send(nil, oldNickmask, "RESUMED", hostname, "ok")
|
||||||
|
} else if session.resumeDetails.HistoryIncomplete && !timestamp.IsZero() {
|
||||||
fSession.Send(nil, oldNickmask, "RESUMED", hostname, timestampString)
|
fSession.Send(nil, oldNickmask, "RESUMED", hostname, timestampString)
|
||||||
} else {
|
} else {
|
||||||
fSession.Send(nil, oldNickmask, "RESUMED", hostname)
|
fSession.Send(nil, oldNickmask, "RESUMED", hostname)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if session.resumeDetails.HistoryIncomplete {
|
if !session.resumeDetails.HistoryIncomplete {
|
||||||
fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected (up to %d seconds of history lost)"), gapSeconds))
|
|
||||||
} else {
|
|
||||||
fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected")))
|
fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected")))
|
||||||
|
} else if session.resumeDetails.HistoryIncomplete && !timestamp.IsZero() {
|
||||||
|
fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected (up to %d seconds of message history lost)"), gapSeconds))
|
||||||
|
} else {
|
||||||
|
fSession.Send(nil, oldNickmask, "QUIT", fmt.Sprintf(friend.t("Client reconnected (message history may have been lost)")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.resumeDetails.HistoryIncomplete {
|
if session.resumeDetails.HistoryIncomplete && !timestamp.IsZero() {
|
||||||
session.Send(nil, client.server.name, "WARN", "RESUME", "HISTORY_LOST", fmt.Sprintf(client.t("Resume may have lost up to %d seconds of history"), gapSeconds))
|
session.Send(nil, client.server.name, "WARN", "RESUME", "HISTORY_LOST", fmt.Sprintf(client.t("Resume may have lost up to %d seconds of history"), gapSeconds))
|
||||||
|
} else {
|
||||||
|
session.Send(nil, client.server.name, "WARN", "RESUME", "HISTORY_LOST", client.t("Resume may have lost some message history"))
|
||||||
}
|
}
|
||||||
|
|
||||||
session.Send(nil, client.server.name, "RESUME", "SUCCESS", details.nick)
|
session.Send(nil, client.server.name, "RESUME", "SUCCESS", details.nick)
|
||||||
|
@ -232,7 +232,7 @@ func init() {
|
|||||||
"RESUME": {
|
"RESUME": {
|
||||||
handler: resumeHandler,
|
handler: resumeHandler,
|
||||||
usablePreReg: true,
|
usablePreReg: true,
|
||||||
minParams: 2,
|
minParams: 1,
|
||||||
},
|
},
|
||||||
"SAJOIN": {
|
"SAJOIN": {
|
||||||
handler: sajoinHandler,
|
handler: sajoinHandler,
|
||||||
|
@ -2359,24 +2359,27 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// RESUME <token> <timestamp>
|
// RESUME <token> [timestamp]
|
||||||
func resumeHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
|
func resumeHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
|
||||||
|
details := ResumeDetails{
|
||||||
|
PresentedToken: msg.Params[0],
|
||||||
|
}
|
||||||
|
|
||||||
if client.registered {
|
if client.registered {
|
||||||
rb.Add(nil, server.name, "FAIL", "RESUME", "REGISTRATION_IS_COMPLETED", client.t("Cannot resume connection, connection registration has already been completed"))
|
rb.Add(nil, server.name, "FAIL", "RESUME", "REGISTRATION_IS_COMPLETED", client.t("Cannot resume connection, connection registration has already been completed"))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
ts, err := time.Parse(IRCv3TimestampFormat, msg.Params[1])
|
if 1 < len(msg.Params) {
|
||||||
if err != nil {
|
ts, err := time.Parse(IRCv3TimestampFormat, msg.Params[1])
|
||||||
rb.Add(nil, server.name, "FAIL", "RESUME", "INVALID_TIMESTAMP", client.t("Cannot resume connection, timestamp is not valid"))
|
if err == nil {
|
||||||
return false
|
details.Timestamp = ts
|
||||||
}
|
} else {
|
||||||
|
rb.Add(nil, server.name, "WARN", "RESUME", "HISTORY_LOST", client.t("Timestamp is not in 2006-01-02T15:04:05.999Z format, ignoring it"))
|
||||||
rb.session.resumeDetails = &ResumeDetails{
|
}
|
||||||
PresentedToken: msg.Params[0],
|
|
||||||
Timestamp: ts,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rb.session.resumeDetails = &details
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user