added server password, and flag in config to enable it
This commit is contained in:
parent
d0b882f362
commit
49ae78f98b
52
main.go
52
main.go
@ -27,6 +27,7 @@ import (
|
||||
type Client struct {
|
||||
nick string
|
||||
user string
|
||||
realname string
|
||||
conn net.Conn
|
||||
host string
|
||||
channels map[string]*Channel
|
||||
@ -58,22 +59,26 @@ type Channelconfig struct {
|
||||
Description string `json:"description"`
|
||||
}
|
||||
type Config struct {
|
||||
Port int `json:"port"`
|
||||
Webapiport int `json:"webapiport"`
|
||||
Motd string `json:"motd"`
|
||||
Channels []Channelconfig `json:"channels"`
|
||||
Ops []string `json:"ops"`
|
||||
Port int `json:"port"`
|
||||
Webapiport int `json:"webapiport"`
|
||||
Motd string `json:"motd"`
|
||||
Enableserverpasswd bool `json:"enableserverpassword"`
|
||||
Serverpassword string `json:"serverpassword"`
|
||||
Channels []Channelconfig `json:"channels"`
|
||||
Ops []string `json:"ops"`
|
||||
}
|
||||
|
||||
var (
|
||||
channels = make(map[string]*Channel)
|
||||
clients = make(map[string]*Client)
|
||||
globalOps = make(map[string]bool)
|
||||
chMu sync.Mutex // mutex for channels
|
||||
cliMu sync.RWMutex // mutex for clients
|
||||
motdString []string
|
||||
motdFile string
|
||||
db *sql.DB
|
||||
channels = make(map[string]*Channel)
|
||||
clients = make(map[string]*Client)
|
||||
globalOps = make(map[string]bool)
|
||||
chMu sync.Mutex // mutex for channels
|
||||
cliMu sync.RWMutex // mutex for clients
|
||||
motdString []string
|
||||
motdFile string
|
||||
Enableserverpasswd bool
|
||||
Serverpassword string
|
||||
db *sql.DB
|
||||
)
|
||||
|
||||
func loadConfig() (*Config, error) {
|
||||
@ -94,6 +99,8 @@ func loadConfig() (*Config, error) {
|
||||
globalOps[cleanedNick] = true
|
||||
}
|
||||
motdFile = conf.Motd
|
||||
Enableserverpasswd = conf.Enableserverpasswd
|
||||
Serverpassword = conf.Serverpassword
|
||||
return &conf, nil
|
||||
}
|
||||
func loadMOTD(filename string) error {
|
||||
@ -203,7 +210,23 @@ func handleConn(conn net.Conn) {
|
||||
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":
|
||||
if len(msg.Params) < 1 {
|
||||
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 {
|
||||
uname := msg.Params[0]
|
||||
client.user = uname
|
||||
client.realname = msg.Params[3]
|
||||
client.checkRegistration()
|
||||
} else {
|
||||
fmt.Fprintf(conn, ":server 461 * USER :Not enough parameters\r\n")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user