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