added server password, and flag in config to enable it
This commit is contained in:
parent
d0b882f362
commit
49ae78f98b
26
main.go
26
main.go
@ -27,6 +27,7 @@ import (
|
|||||||
type Client struct {
|
type Client struct {
|
||||||
nick string
|
nick string
|
||||||
user string
|
user string
|
||||||
|
realname string
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
host string
|
host string
|
||||||
channels map[string]*Channel
|
channels map[string]*Channel
|
||||||
@ -61,6 +62,8 @@ type Config struct {
|
|||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
Webapiport int `json:"webapiport"`
|
Webapiport int `json:"webapiport"`
|
||||||
Motd string `json:"motd"`
|
Motd string `json:"motd"`
|
||||||
|
Enableserverpasswd bool `json:"enableserverpassword"`
|
||||||
|
Serverpassword string `json:"serverpassword"`
|
||||||
Channels []Channelconfig `json:"channels"`
|
Channels []Channelconfig `json:"channels"`
|
||||||
Ops []string `json:"ops"`
|
Ops []string `json:"ops"`
|
||||||
}
|
}
|
||||||
@ -73,6 +76,8 @@ var (
|
|||||||
cliMu sync.RWMutex // mutex for clients
|
cliMu sync.RWMutex // mutex for clients
|
||||||
motdString []string
|
motdString []string
|
||||||
motdFile string
|
motdFile string
|
||||||
|
Enableserverpasswd bool
|
||||||
|
Serverpassword string
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -94,6 +99,8 @@ func loadConfig() (*Config, error) {
|
|||||||
globalOps[cleanedNick] = true
|
globalOps[cleanedNick] = true
|
||||||
}
|
}
|
||||||
motdFile = conf.Motd
|
motdFile = conf.Motd
|
||||||
|
Enableserverpasswd = conf.Enableserverpasswd
|
||||||
|
Serverpassword = conf.Serverpassword
|
||||||
return &conf, nil
|
return &conf, nil
|
||||||
}
|
}
|
||||||
func loadMOTD(filename string) error {
|
func loadMOTD(filename string) error {
|
||||||
@ -203,7 +210,23 @@ func handleConn(conn net.Conn) {
|
|||||||
client.checkRegistration()
|
client.checkRegistration()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case "PASS":
|
||||||
|
if !Enableserverpasswd {
|
||||||
|
client.fwrite(":server 421 * PASS :Server password not enabled\r\n")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(msg.Params) < 1 {
|
||||||
|
client.fwrite(":server 461 * PASS :Not enough parameters\r\n")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if msg.Params[0] == Serverpassword {
|
||||||
|
client.saslComplete = true
|
||||||
|
client.saslRequired = false
|
||||||
|
client.fwrite(":server NOTICE * :Server password accepted\r\n")
|
||||||
|
} else {
|
||||||
|
client.fwrite(":server 464 * :Password incorrect\r\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
case "CAP":
|
case "CAP":
|
||||||
if len(msg.Params) < 1 {
|
if len(msg.Params) < 1 {
|
||||||
client.fwrite(":server 461 %s CAP :Not enough parameters\r\n", client.nick)
|
client.fwrite(":server 461 %s CAP :Not enough parameters\r\n", client.nick)
|
||||||
@ -271,6 +294,7 @@ func handleConn(conn net.Conn) {
|
|||||||
if len(msg.Params) >= 4 {
|
if len(msg.Params) >= 4 {
|
||||||
uname := msg.Params[0]
|
uname := msg.Params[0]
|
||||||
client.user = uname
|
client.user = uname
|
||||||
|
client.realname = msg.Params[3]
|
||||||
client.checkRegistration()
|
client.checkRegistration()
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(conn, ":server 461 * USER :Not enough parameters\r\n")
|
fmt.Fprintf(conn, ":server 461 * USER :Not enough parameters\r\n")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user