Strip client & network name from username

This commit is contained in:
Simon Ser 2020-03-16 09:32:18 +01:00
parent 3dbc205beb
commit 88877f3c5a
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 14 additions and 12 deletions

View File

@ -11,10 +11,10 @@ A user-friendly IRC bouncer.
## Usage
sqlite3 soju.db <schema.sql
go run ./cmd/sojuctl create-user soju
go run ./cmd/sojuctl create-user <username>
go run ./cmd/soju
Then connect with username `soju@chat.freenode.net` and join `#soju`.
Then connect with username `<username>@chat.freenode.net` and join `#soju`.
## Contributing

View File

@ -61,13 +61,14 @@ type downstreamConn struct {
consumptions chan consumption
closed chan struct{}
registered bool
user *user
nick string
username string
realname string
password string // empty after authentication
network *network // can be nil
registered bool
user *user
nick string
username string
rawUsername string
realname string
password string // empty after authentication
network *network // can be nil
}
func newDownstreamConn(srv *Server, netConn net.Conn) *downstreamConn {
@ -323,7 +324,7 @@ func (dc *downstreamConn) handleMessageUnregistered(msg *irc.Message) error {
if err := parseMessageParams(msg, &username, nil, nil, &dc.realname); err != nil {
return err
}
dc.username = "~" + username
dc.rawUsername = username
case "PASS":
if err := parseMessageParams(msg, &dc.password); err != nil {
return err
@ -332,7 +333,7 @@ func (dc *downstreamConn) handleMessageUnregistered(msg *irc.Message) error {
dc.logger.Printf("unhandled message: %v", msg)
return newUnknownCommandError(msg.Command)
}
if dc.username != "" && dc.nick != "" {
if dc.rawUsername != "" && dc.nick != "" {
return dc.register()
}
return nil
@ -348,7 +349,7 @@ func sanityCheckServer(addr string) error {
}
func (dc *downstreamConn) register() error {
username := strings.TrimPrefix(dc.username, "~")
username := dc.rawUsername
var networkName string
if i := strings.LastIndexAny(username, "/@"); i >= 0 {
networkName = username[i+1:]
@ -356,6 +357,7 @@ func (dc *downstreamConn) register() error {
if i := strings.IndexAny(username, "/@"); i >= 0 {
username = username[:i]
}
dc.username = "~" + username
password := dc.password
dc.password = ""