Strip client & network name from username
This commit is contained in:
parent
3dbc205beb
commit
88877f3c5a
@ -11,10 +11,10 @@ A user-friendly IRC bouncer.
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
sqlite3 soju.db <schema.sql
|
sqlite3 soju.db <schema.sql
|
||||||
go run ./cmd/sojuctl create-user soju
|
go run ./cmd/sojuctl create-user <username>
|
||||||
go run ./cmd/soju
|
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
|
## Contributing
|
||||||
|
|
||||||
|
@ -61,13 +61,14 @@ type downstreamConn struct {
|
|||||||
consumptions chan consumption
|
consumptions chan consumption
|
||||||
closed chan struct{}
|
closed chan struct{}
|
||||||
|
|
||||||
registered bool
|
registered bool
|
||||||
user *user
|
user *user
|
||||||
nick string
|
nick string
|
||||||
username string
|
username string
|
||||||
realname string
|
rawUsername string
|
||||||
password string // empty after authentication
|
realname string
|
||||||
network *network // can be nil
|
password string // empty after authentication
|
||||||
|
network *network // can be nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDownstreamConn(srv *Server, netConn net.Conn) *downstreamConn {
|
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 {
|
if err := parseMessageParams(msg, &username, nil, nil, &dc.realname); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dc.username = "~" + username
|
dc.rawUsername = username
|
||||||
case "PASS":
|
case "PASS":
|
||||||
if err := parseMessageParams(msg, &dc.password); err != nil {
|
if err := parseMessageParams(msg, &dc.password); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -332,7 +333,7 @@ func (dc *downstreamConn) handleMessageUnregistered(msg *irc.Message) error {
|
|||||||
dc.logger.Printf("unhandled message: %v", msg)
|
dc.logger.Printf("unhandled message: %v", msg)
|
||||||
return newUnknownCommandError(msg.Command)
|
return newUnknownCommandError(msg.Command)
|
||||||
}
|
}
|
||||||
if dc.username != "" && dc.nick != "" {
|
if dc.rawUsername != "" && dc.nick != "" {
|
||||||
return dc.register()
|
return dc.register()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -348,7 +349,7 @@ func sanityCheckServer(addr string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dc *downstreamConn) register() error {
|
func (dc *downstreamConn) register() error {
|
||||||
username := strings.TrimPrefix(dc.username, "~")
|
username := dc.rawUsername
|
||||||
var networkName string
|
var networkName string
|
||||||
if i := strings.LastIndexAny(username, "/@"); i >= 0 {
|
if i := strings.LastIndexAny(username, "/@"); i >= 0 {
|
||||||
networkName = username[i+1:]
|
networkName = username[i+1:]
|
||||||
@ -356,6 +357,7 @@ func (dc *downstreamConn) register() error {
|
|||||||
if i := strings.IndexAny(username, "/@"); i >= 0 {
|
if i := strings.IndexAny(username, "/@"); i >= 0 {
|
||||||
username = username[:i]
|
username = username[:i]
|
||||||
}
|
}
|
||||||
|
dc.username = "~" + username
|
||||||
|
|
||||||
password := dc.password
|
password := dc.password
|
||||||
dc.password = ""
|
dc.password = ""
|
||||||
|
Loading…
Reference in New Issue
Block a user