1
0
Fork 0
mirror of https://github.com/fluffle/goirc synced 2025-05-23 07:53:22 +00:00

NewNick handler that doesn't vary nick length. Fixes . Sort of.

This commit is contained in:
Alex Bramley 2019-10-17 20:27:52 +01:00
parent 0dc1109b0d
commit b2c51c13c6
3 changed files with 53 additions and 8 deletions

View file

@ -125,7 +125,7 @@ func NewConfig(nick string, args ...string) *Config {
cfg := &Config{
Me: &state.Nick{Nick: nick},
PingFreq: 3 * time.Minute,
NewNick: func(s string) string { return s + "_" },
NewNick: DefaultNewNick,
Recover: (*Conn).LogPanic, // in dispatch.go
SplitLen: defaultSplit,
Timeout: 60 * time.Second,
@ -143,6 +143,28 @@ func NewConfig(nick string, args ...string) *Config {
return cfg
}
// Because networks limit nick lengths, the easy approach of appending
// an '_' to a nick that is already in use can cause problems. When the
// length limit is reached, the clients idea of what its nick is
// ends up being different from the server. Hilarity ensues.
// Thanks to github.com/purpleidea for the bug report!
// Thanks to 'man ascii' for
func DefaultNewNick(old string) string {
if len(old) == 0 {
return "_"
}
c := old[len(old)-1]
switch {
case c >= '0' && c <= '9':
c = '0' + (((c - '0') + 1) % 10)
case c >= 'A' && c <= '}':
c = 'A' + (((c - 'A') + 1) % 61)
default:
c = '_'
}
return old[:len(old)-1] + string(c)
}
// SimpleClient creates a new Conn, passing its arguments to NewConfig.
// If you don't need to change any client options and just want to get
// started quickly, this is a convenient shortcut.