2014-05-11 16:18:55 +00:00
|
|
|
/*
|
|
|
|
goircd -- minimalistic simple Internet Relay Chat (IRC) server
|
2021-12-29 15:19:22 +00:00
|
|
|
<<<<<<< HEAD
|
2021-01-05 17:48:29 +00:00
|
|
|
Copyright (C) 2014-2021 Sergey Matveev <stargrave@stargrave.org>
|
2021-12-29 15:19:22 +00:00
|
|
|
=======
|
2015-12-31 17:23:21 +00:00
|
|
|
Copyright (C) 2014-2016 Sergey Matveev <stargrave@stargrave.org>
|
2021-12-29 15:19:22 +00:00
|
|
|
>>>>>>> github/master
|
2014-05-11 16:18:55 +00:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2019-09-27 08:32:53 +00:00
|
|
|
the Free Software Foundation, version 3 of the License.
|
2014-05-11 16:18:55 +00:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2015-05-09 15:27:06 +00:00
|
|
|
|
2014-05-11 16:18:55 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2020-11-06 17:10:06 +00:00
|
|
|
"crypto/sha256"
|
|
|
|
"crypto/subtle"
|
|
|
|
"encoding/hex"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2014-05-11 16:18:55 +00:00
|
|
|
"log"
|
|
|
|
"net"
|
2020-11-06 17:10:06 +00:00
|
|
|
"regexp"
|
|
|
|
"sort"
|
2014-05-11 16:18:55 +00:00
|
|
|
"strings"
|
2015-10-11 08:12:55 +00:00
|
|
|
"sync"
|
2014-05-11 16:18:55 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-10-11 08:12:55 +00:00
|
|
|
BufSize = 1500
|
2020-11-06 17:10:06 +00:00
|
|
|
MaxOutBuf = 128
|
2015-10-06 08:27:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-11-06 17:10:06 +00:00
|
|
|
CRLF []byte = []byte{'\x0d', '\x0a'}
|
|
|
|
RENickname = regexp.MustCompile("^[a-zA-Z0-9-]{1,24}$")
|
|
|
|
|
|
|
|
clients map[*Client]struct{} = make(map[*Client]struct{})
|
|
|
|
clientsLock sync.RWMutex
|
|
|
|
clientsWG sync.WaitGroup
|
2014-05-11 16:18:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Client struct {
|
2015-10-11 08:12:55 +00:00
|
|
|
conn net.Conn
|
|
|
|
registered bool
|
2020-11-06 17:10:06 +00:00
|
|
|
nickname string
|
|
|
|
username string
|
|
|
|
realname string
|
|
|
|
password string
|
|
|
|
away string
|
2015-10-11 08:12:55 +00:00
|
|
|
recvTimestamp time.Time
|
|
|
|
sendTimestamp time.Time
|
2015-11-04 14:37:58 +00:00
|
|
|
outBuf chan *string
|
2015-10-11 08:12:55 +00:00
|
|
|
alive bool
|
2018-03-04 17:20:25 +00:00
|
|
|
quitMsg *string
|
2015-10-11 08:12:55 +00:00
|
|
|
sync.Mutex
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
2016-03-26 14:10:04 +00:00
|
|
|
func (c *Client) Host() string {
|
2020-11-06 17:10:06 +00:00
|
|
|
if *cloak != "" {
|
|
|
|
return *cloak
|
|
|
|
}
|
2015-10-18 20:07:57 +00:00
|
|
|
addr := c.conn.RemoteAddr().String()
|
|
|
|
if host, _, err := net.SplitHostPort(addr); err == nil {
|
|
|
|
addr = host
|
|
|
|
}
|
|
|
|
if domains, err := net.LookupAddr(addr); err == nil {
|
|
|
|
addr = strings.TrimSuffix(domains[0], ".")
|
|
|
|
}
|
|
|
|
return addr
|
|
|
|
}
|
|
|
|
|
2016-03-26 14:10:04 +00:00
|
|
|
func (c *Client) String() string {
|
2020-11-06 17:10:06 +00:00
|
|
|
return strings.Join([]string{c.nickname, "!", c.username, "@", c.Host()}, "")
|
2014-08-09 11:37:10 +00:00
|
|
|
}
|
|
|
|
|
2018-03-04 17:20:25 +00:00
|
|
|
func (c *Client) Match(other string) bool {
|
|
|
|
return strings.ToLower(*c.nickname) == strings.ToLower(other)
|
|
|
|
}
|
|
|
|
|
2020-11-06 17:10:06 +00:00
|
|
|
func NewClient(conn net.Conn, events chan ClientEvent) *Client {
|
2015-10-11 08:12:55 +00:00
|
|
|
nickname := "*"
|
|
|
|
username := ""
|
2018-03-04 17:20:25 +00:00
|
|
|
realname := ""
|
2015-10-11 08:12:55 +00:00
|
|
|
c := Client{
|
|
|
|
conn: conn,
|
|
|
|
nickname: &nickname,
|
|
|
|
username: &username,
|
2018-03-04 17:20:25 +00:00
|
|
|
realname: &realname,
|
2015-10-11 08:12:55 +00:00
|
|
|
recvTimestamp: time.Now(),
|
|
|
|
sendTimestamp: time.Now(),
|
|
|
|
alive: true,
|
2015-11-04 14:37:58 +00:00
|
|
|
outBuf: make(chan *string, MaxOutBuf),
|
2015-10-11 08:12:55 +00:00
|
|
|
}
|
2020-11-06 17:10:06 +00:00
|
|
|
clientsWG.Add(2)
|
2015-10-11 08:12:55 +00:00
|
|
|
go c.MsgSender()
|
2020-11-06 17:10:06 +00:00
|
|
|
go c.Processor(events)
|
2015-10-11 08:12:55 +00:00
|
|
|
return &c
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 08:12:55 +00:00
|
|
|
func (c *Client) SetDead() {
|
2015-11-04 14:37:58 +00:00
|
|
|
c.outBuf <- nil
|
2015-10-11 08:12:55 +00:00
|
|
|
c.alive = false
|
|
|
|
}
|
|
|
|
|
2018-03-04 17:20:25 +00:00
|
|
|
func (c *Client) Close(text string) {
|
2015-10-11 08:12:55 +00:00
|
|
|
c.Lock()
|
|
|
|
if c.alive {
|
2018-03-04 17:20:25 +00:00
|
|
|
c.quitMsg = &text
|
2015-10-11 08:12:55 +00:00
|
|
|
c.SetDead()
|
|
|
|
}
|
|
|
|
c.Unlock()
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 17:10:06 +00:00
|
|
|
func (c *Client) Processor(events chan ClientEvent) {
|
|
|
|
events <- ClientEvent{c, EventNew, ""}
|
|
|
|
if *verbose {
|
|
|
|
log.Println(c, "connected")
|
|
|
|
}
|
2015-10-06 08:27:11 +00:00
|
|
|
buf := make([]byte, BufSize*2)
|
2020-11-06 17:10:06 +00:00
|
|
|
var n, prev, i int
|
|
|
|
var msg string
|
2015-10-06 08:27:11 +00:00
|
|
|
var err error
|
2014-05-11 16:18:55 +00:00
|
|
|
for {
|
2015-10-06 08:27:11 +00:00
|
|
|
if prev == BufSize {
|
2015-10-11 08:12:55 +00:00
|
|
|
log.Println(c, "input buffer size exceeded, kicking him")
|
2015-10-06 08:27:11 +00:00
|
|
|
break
|
|
|
|
}
|
2015-10-11 08:12:55 +00:00
|
|
|
n, err = c.conn.Read(buf[prev:])
|
2014-05-11 16:18:55 +00:00
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
2015-10-06 08:27:11 +00:00
|
|
|
prev += n
|
|
|
|
CheckMore:
|
|
|
|
i = bytes.Index(buf[:prev], CRLF)
|
|
|
|
if i == -1 {
|
2014-05-11 16:18:55 +00:00
|
|
|
continue
|
|
|
|
}
|
2020-11-06 17:10:06 +00:00
|
|
|
if *debug {
|
|
|
|
log.Println(c, "<-", msg)
|
|
|
|
}
|
|
|
|
msg = string(buf[:i])
|
|
|
|
if *debug {
|
|
|
|
log.Println(c, "->", msg)
|
|
|
|
}
|
|
|
|
events <- ClientEvent{c, EventMsg, msg}
|
2015-10-06 08:27:11 +00:00
|
|
|
copy(buf, buf[i+2:prev])
|
|
|
|
prev -= (i + 2)
|
|
|
|
goto CheckMore
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
2015-10-11 08:12:55 +00:00
|
|
|
c.Close()
|
2020-11-06 17:10:06 +00:00
|
|
|
if *verbose {
|
|
|
|
log.Println(c, "disconnected")
|
|
|
|
}
|
|
|
|
events <- ClientEvent{c, EventDel, ""}
|
|
|
|
clientsWG.Done()
|
2018-03-04 17:20:25 +00:00
|
|
|
sink <- ClientEvent{c, EventDel, *c.quitMsg}
|
2015-10-11 08:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) MsgSender() {
|
2020-11-06 17:10:06 +00:00
|
|
|
var err error
|
2015-10-11 08:12:55 +00:00
|
|
|
for msg := range c.outBuf {
|
2020-11-06 17:10:06 +00:00
|
|
|
if *debug {
|
|
|
|
log.Println(c, "<-", msg)
|
|
|
|
}
|
2015-11-04 14:37:58 +00:00
|
|
|
if msg == nil {
|
|
|
|
c.conn.Close()
|
|
|
|
break
|
|
|
|
}
|
2020-11-06 17:10:06 +00:00
|
|
|
if _, err = c.conn.Write(append([]byte(msg), CRLF...)); err != nil {
|
|
|
|
if *verbose {
|
|
|
|
log.Println(c, "error writing", err)
|
|
|
|
}
|
2015-11-04 14:37:58 +00:00
|
|
|
break
|
|
|
|
}
|
2015-10-11 08:12:55 +00:00
|
|
|
}
|
2020-11-06 17:10:06 +00:00
|
|
|
c.conn.Close()
|
|
|
|
clientsWG.Done()
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 08:12:55 +00:00
|
|
|
func (c *Client) Msg(text string) {
|
|
|
|
c.Lock()
|
|
|
|
defer c.Unlock()
|
|
|
|
if !c.alive {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(c.outBuf) == MaxOutBuf {
|
|
|
|
log.Println(c, "output buffer size exceeded, kicking him")
|
2015-11-04 14:37:58 +00:00
|
|
|
if c.alive {
|
2020-11-06 17:10:06 +00:00
|
|
|
close(c.outBuf)
|
|
|
|
c.alive = false
|
2015-11-04 14:37:58 +00:00
|
|
|
c.SetDead()
|
2015-11-04 14:37:58 +00:00
|
|
|
}
|
2015-10-11 08:12:55 +00:00
|
|
|
return
|
|
|
|
}
|
2015-11-04 14:37:58 +00:00
|
|
|
c.outBuf <- &text
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 08:12:55 +00:00
|
|
|
func (c *Client) Reply(text string) {
|
|
|
|
c.Msg(":" + *hostname + " " + text)
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 08:12:55 +00:00
|
|
|
func (c *Client) ReplyParts(code string, text ...string) {
|
2014-05-11 16:18:55 +00:00
|
|
|
parts := []string{code}
|
|
|
|
for _, t := range text {
|
|
|
|
parts = append(parts, t)
|
|
|
|
}
|
|
|
|
parts[len(parts)-1] = ":" + parts[len(parts)-1]
|
2015-10-11 08:12:55 +00:00
|
|
|
c.Reply(strings.Join(parts, " "))
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 08:12:55 +00:00
|
|
|
func (c *Client) ReplyNicknamed(code string, text ...string) {
|
2020-11-06 17:10:06 +00:00
|
|
|
c.ReplyParts(code, append([]string{c.nickname}, text...)...)
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 08:12:55 +00:00
|
|
|
func (c *Client) ReplyNotEnoughParameters(command string) {
|
|
|
|
c.ReplyNicknamed("461", command, "Not enough parameters")
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 08:12:55 +00:00
|
|
|
func (c *Client) ReplyNoChannel(channel string) {
|
|
|
|
c.ReplyNicknamed("403", channel, "No such channel")
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
2014-05-13 19:56:29 +00:00
|
|
|
|
2015-10-11 08:12:55 +00:00
|
|
|
func (c *Client) ReplyNoNickChan(channel string) {
|
|
|
|
c.ReplyNicknamed("401", channel, "No such nick/channel")
|
2014-05-13 19:56:29 +00:00
|
|
|
}
|
2020-11-06 17:10:06 +00:00
|
|
|
|
|
|
|
func (c *Client) SendLusers() {
|
|
|
|
lusers := 0
|
|
|
|
clientsLock.RLock()
|
|
|
|
for client := range clients {
|
|
|
|
if client.registered {
|
|
|
|
lusers++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clientsLock.RUnlock()
|
|
|
|
c.ReplyNicknamed(
|
|
|
|
"251",
|
|
|
|
fmt.Sprintf("There are %d users and 0 invisible on 1 servers",
|
|
|
|
lusers,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) SendMotd() {
|
|
|
|
if motd == nil {
|
|
|
|
c.ReplyNicknamed("422", "MOTD File is missing")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
motdText, err := ioutil.ReadFile(*motd)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("can not read motd file %s: %v", *motd, err)
|
|
|
|
c.ReplyNicknamed("422", "Error reading MOTD File")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.ReplyNicknamed("375", "- "+*hostname+" Message of the day -")
|
|
|
|
for _, s := range strings.Split(strings.TrimSuffix(string(motdText), "\n"), "\n") {
|
|
|
|
c.ReplyNicknamed("372", "- "+s)
|
|
|
|
}
|
|
|
|
c.ReplyNicknamed("376", "End of /MOTD command")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) Join(cmd string) {
|
|
|
|
args := strings.Split(cmd, " ")
|
|
|
|
rs := strings.Split(args[0], ",")
|
|
|
|
keys := []string{}
|
|
|
|
if len(args) > 1 {
|
|
|
|
keys = strings.Split(args[1], ",")
|
|
|
|
}
|
|
|
|
RoomCycle:
|
|
|
|
for n, roomName := range rs {
|
|
|
|
if !RERoom.MatchString(roomName) {
|
|
|
|
c.ReplyNoChannel(roomName)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
var key string
|
|
|
|
if (n < len(keys)) && (keys[n] != "") {
|
|
|
|
key = keys[n]
|
|
|
|
}
|
|
|
|
roomsLock.RLock()
|
|
|
|
for roomNameExisting, room := range rooms {
|
|
|
|
if roomName != roomNameExisting {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if (room.key != "") && (room.key != key) {
|
|
|
|
c.ReplyNicknamed("475", roomName, "Cannot join channel (+k)")
|
|
|
|
roomsLock.RUnlock()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
room.events <- ClientEvent{c, EventNew, ""}
|
|
|
|
roomsLock.RUnlock()
|
|
|
|
continue RoomCycle
|
|
|
|
}
|
|
|
|
roomsLock.RUnlock()
|
|
|
|
roomNew := RoomRegister(roomName)
|
|
|
|
if *verbose {
|
|
|
|
log.Println("room", roomName, "created")
|
|
|
|
}
|
|
|
|
if key != "" {
|
|
|
|
roomNew.key = key
|
|
|
|
roomNew.StateSave()
|
|
|
|
}
|
|
|
|
roomNew.events <- ClientEvent{c, EventNew, ""}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (client *Client) SendWhois(nicknames []string) {
|
|
|
|
var c *Client
|
|
|
|
for _, nickname := range nicknames {
|
|
|
|
nickname = strings.ToLower(nickname)
|
|
|
|
clientsLock.RLock()
|
|
|
|
for c = range clients {
|
|
|
|
if strings.ToLower(c.nickname) == nickname {
|
|
|
|
clientsLock.RUnlock()
|
|
|
|
goto Found
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clientsLock.RUnlock()
|
|
|
|
client.ReplyNoNickChan(nickname)
|
|
|
|
continue
|
|
|
|
Found:
|
|
|
|
var host string
|
|
|
|
if *cloak != "" {
|
|
|
|
host = *cloak
|
|
|
|
} else {
|
|
|
|
host, _, err := net.SplitHostPort(c.conn.RemoteAddr().String())
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("can't parse RemoteAddr %q: %v", host, err)
|
|
|
|
host = "Unknown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
client.ReplyNicknamed("311", c.nickname, c.username, host, "*", c.realname)
|
|
|
|
client.ReplyNicknamed("312", c.nickname, *hostname, *hostname)
|
|
|
|
if c.away != "" {
|
|
|
|
client.ReplyNicknamed("301", c.nickname, c.away)
|
|
|
|
}
|
|
|
|
subscriptions := make([]string, 0)
|
|
|
|
roomsLock.RLock()
|
|
|
|
for _, room := range rooms {
|
|
|
|
for subscriber := range room.members {
|
|
|
|
if subscriber.nickname == nickname {
|
|
|
|
subscriptions = append(subscriptions, room.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
roomsLock.RUnlock()
|
|
|
|
sort.Strings(subscriptions)
|
|
|
|
client.ReplyNicknamed("319", c.nickname, strings.Join(subscriptions, " "))
|
|
|
|
client.ReplyNicknamed("318", c.nickname, "End of /WHOIS list")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) SendList(cols []string) {
|
|
|
|
var rs []string
|
|
|
|
if (len(cols) > 1) && (cols[1] != "") {
|
|
|
|
rs = strings.Split(strings.Split(cols[1], " ")[0], ",")
|
|
|
|
} else {
|
|
|
|
rs = make([]string, 0)
|
|
|
|
roomsLock.RLock()
|
|
|
|
for r := range rooms {
|
|
|
|
rs = append(rs, r)
|
|
|
|
}
|
|
|
|
roomsLock.RUnlock()
|
|
|
|
}
|
|
|
|
sort.Strings(rs)
|
|
|
|
roomsLock.RLock()
|
|
|
|
for _, r := range rs {
|
|
|
|
if room, found := rooms[r]; found {
|
|
|
|
c.ReplyNicknamed(
|
|
|
|
"322",
|
|
|
|
r,
|
|
|
|
fmt.Sprintf("%d", len(room.members)),
|
|
|
|
room.topic,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
roomsLock.RUnlock()
|
|
|
|
c.ReplyNicknamed("323", "End of /LIST")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) Register(cmd string, cols []string) {
|
|
|
|
switch cmd {
|
|
|
|
case "PASS":
|
|
|
|
if len(cols) == 1 || len(cols[1]) < 1 {
|
|
|
|
c.ReplyNotEnoughParameters("PASS")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
password := strings.TrimPrefix(cols[1], ":")
|
|
|
|
c.password = password
|
|
|
|
case "NICK":
|
|
|
|
if len(cols) == 1 || len(cols[1]) < 1 {
|
|
|
|
c.ReplyParts("431", "No nickname given")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
nickname := cols[1]
|
|
|
|
// Compatibility with some clients prepending colons to nickname
|
|
|
|
nickname = strings.TrimPrefix(nickname, ":")
|
|
|
|
nickname = strings.ToLower(nickname)
|
|
|
|
if !RENickname.MatchString(nickname) {
|
|
|
|
c.ReplyParts("432", "*", cols[1], "Erroneous nickname")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
clientsLock.RLock()
|
|
|
|
for existingClient := range clients {
|
|
|
|
if existingClient.nickname == nickname {
|
|
|
|
clientsLock.RUnlock()
|
|
|
|
c.ReplyParts("433", "*", nickname, "Nickname is already in use")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clientsLock.RUnlock()
|
|
|
|
c.nickname = nickname
|
|
|
|
case "USER":
|
|
|
|
if len(cols) == 1 {
|
|
|
|
c.ReplyNotEnoughParameters("USER")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
args := strings.SplitN(cols[1], " ", 4)
|
|
|
|
if len(args) < 4 {
|
|
|
|
c.ReplyNotEnoughParameters("USER")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.username = args[0]
|
|
|
|
realname := strings.TrimLeft(args[3], ":")
|
|
|
|
c.realname = realname
|
|
|
|
}
|
|
|
|
if c.nickname != "*" && c.username != "" {
|
|
|
|
if *passwords != "" {
|
|
|
|
authenticated := false
|
|
|
|
if c.password == "" {
|
|
|
|
c.ReplyParts("462", "You may not register")
|
|
|
|
c.Close()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
contents, err := ioutil.ReadFile(*passwords)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("can not read passwords file %s: %s", *passwords, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for n, entry := range strings.Split(string(contents), "\n") {
|
|
|
|
if entry == "" || strings.HasPrefix(entry, "#") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
cols := strings.Split(entry, ":")
|
|
|
|
if len(cols) != 2 {
|
|
|
|
log.Fatalf("bad passwords format: %s:%d", *passwords, n)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if cols[0] != c.nickname {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
h := sha256.Sum256([]byte(c.password))
|
|
|
|
authenticated = subtle.ConstantTimeCompare(
|
|
|
|
[]byte(hex.EncodeToString(h[:])),
|
|
|
|
[]byte(cols[1]),
|
|
|
|
) == 1
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if !authenticated {
|
|
|
|
c.ReplyParts("462", "You may not register")
|
|
|
|
c.Close()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.registered = true
|
|
|
|
c.ReplyNicknamed("001", "Hi, welcome to IRC")
|
|
|
|
c.ReplyNicknamed("002", "Your host is "+*hostname+", running goircd "+Version)
|
|
|
|
c.ReplyNicknamed("003", "This server was created sometime")
|
|
|
|
c.ReplyNicknamed("004", *hostname+" goircd o o")
|
|
|
|
c.SendLusers()
|
|
|
|
c.SendMotd()
|
|
|
|
if *verbose {
|
|
|
|
log.Println(c, "logged in")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|