Add support for upstream PASS command
This commit is contained in:
parent
e39948cdbd
commit
fee8fc79c6
27
db.go
27
db.go
@ -18,6 +18,7 @@ type Network struct {
|
||||
Nick string
|
||||
Username string
|
||||
Realname string
|
||||
Pass string
|
||||
}
|
||||
|
||||
type Channel struct {
|
||||
@ -89,7 +90,7 @@ func (db *DB) ListNetworks(username string) ([]Network, error) {
|
||||
db.lock.RLock()
|
||||
defer db.lock.RUnlock()
|
||||
|
||||
rows, err := db.db.Query("SELECT id, addr, nick, username, realname FROM Network WHERE user = ?", username)
|
||||
rows, err := db.db.Query("SELECT id, addr, nick, username, realname, pass FROM Network WHERE user = ?", username)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -98,8 +99,8 @@ func (db *DB) ListNetworks(username string) ([]Network, error) {
|
||||
var networks []Network
|
||||
for rows.Next() {
|
||||
var net Network
|
||||
var username, realname *string
|
||||
if err := rows.Scan(&net.ID, &net.Addr, &net.Nick, &username, &realname); err != nil {
|
||||
var username, realname, pass *string
|
||||
if err := rows.Scan(&net.ID, &net.Addr, &net.Nick, &username, &realname, &pass); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if username != nil {
|
||||
@ -108,6 +109,9 @@ func (db *DB) ListNetworks(username string) ([]Network, error) {
|
||||
if realname != nil {
|
||||
net.Realname = *realname
|
||||
}
|
||||
if pass != nil {
|
||||
net.Pass = *pass
|
||||
}
|
||||
networks = append(networks, net)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
@ -121,20 +125,29 @@ func (db *DB) StoreNetwork(username string, network *Network) error {
|
||||
db.lock.Lock()
|
||||
defer db.lock.Unlock()
|
||||
|
||||
var netUsername, netRealname *string
|
||||
var netUsername, realname, pass *string
|
||||
if network.Username != "" {
|
||||
netUsername = &network.Username
|
||||
}
|
||||
if network.Realname != "" {
|
||||
netRealname = &network.Realname
|
||||
realname = &network.Realname
|
||||
}
|
||||
if network.Pass != "" {
|
||||
pass = &network.Pass
|
||||
}
|
||||
|
||||
var err error
|
||||
if network.ID != 0 {
|
||||
_, err = db.db.Exec("UPDATE Network SET addr = ?, nick = ?, username = ?, realname = ? WHERE id = ?", network.Addr, network.Nick, netUsername, netRealname, network.ID)
|
||||
_, err = db.db.Exec(`UPDATE Network
|
||||
SET addr = ?, nick = ?, username = ?, realname = ?, pass = ?
|
||||
WHERE id = ?`,
|
||||
network.Addr, network.Nick, netUsername, realname, pass, network.ID)
|
||||
} else {
|
||||
var res sql.Result
|
||||
res, err = db.db.Exec("INSERT INTO Network(user, addr, nick, username, realname) VALUES (?, ?, ?, ?, ?)", username, network.Addr, network.Nick, netUsername, netRealname)
|
||||
res, err = db.db.Exec(`INSERT INTO Network(user, addr, nick, username,
|
||||
realname, pass)
|
||||
VALUES (?, ?, ?, ?, ?, ?)`,
|
||||
username, network.Addr, network.Nick, netUsername, realname, pass)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -427,6 +427,7 @@ func (dc *downstreamConn) register() error {
|
||||
Command: irc.RPL_MYINFO,
|
||||
Params: []string{dc.nick, dc.srv.Hostname, "jounce", "aiwroO", "OovaimnqpsrtklbeI"},
|
||||
})
|
||||
// TODO: RPL_ISUPPORT
|
||||
dc.SendMessage(&irc.Message{
|
||||
Prefix: dc.srv.prefix(),
|
||||
Command: irc.ERR_NOMOTD,
|
||||
|
@ -10,6 +10,7 @@ CREATE TABLE Network (
|
||||
nick VARCHAR(255) NOT NULL,
|
||||
username VARCHAR(255),
|
||||
realname VARCHAR(255),
|
||||
pass VARCHAR(255),
|
||||
FOREIGN KEY(user) REFERENCES User(username),
|
||||
UNIQUE(user, addr, nick)
|
||||
);
|
||||
|
@ -460,6 +460,13 @@ func (uc *upstreamConn) register() {
|
||||
Params: []string{"LS", "302"},
|
||||
})
|
||||
|
||||
if uc.network.Pass != "" {
|
||||
uc.SendMessage(&irc.Message{
|
||||
Command: "PASS",
|
||||
Params: []string{uc.network.Pass},
|
||||
})
|
||||
}
|
||||
|
||||
uc.SendMessage(&irc.Message{
|
||||
Command: "NICK",
|
||||
Params: []string{uc.nick},
|
||||
|
Loading…
Reference in New Issue
Block a user