3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

channel: Add KICKLEN and TOPICLEN

This commit is contained in:
Daniel Oaks 2016-09-12 12:22:50 +10:00
parent 3321243486
commit 79d831bbb7
4 changed files with 37 additions and 10 deletions

View File

@ -270,6 +270,10 @@ func (channel *Channel) SetTopic(client *Client, topic string) {
return return
} }
if len(topic) > client.server.limits.Topic {
topic = topic[:client.server.limits.Topic]
}
channel.topic = topic channel.topic = topic
channel.topicSetBy = client.nickString channel.topicSetBy = client.nickString
channel.topicSetTime = time.Now() channel.topicSetTime = time.Now()
@ -478,6 +482,10 @@ func (channel *Channel) Kick(client *Client, target *Client, comment string) {
return return
} }
if len(comment) > client.server.limits.Kick {
comment = comment[:client.server.limits.Kick]
}
for member := range channel.members { for member := range channel.members {
member.Send(nil, client.nickMaskString, "KICK", channel.nameString, target.nickString, comment) member.Send(nil, client.nickMaskString, "KICK", channel.nameString, target.nickString, comment)
} }

View File

@ -99,6 +99,8 @@ type Config struct {
Limits struct { Limits struct {
NickLen int `yaml:"nicklen"` NickLen int `yaml:"nicklen"`
ChannelLen int `yaml:"channellen"` ChannelLen int `yaml:"channellen"`
KickLen int `yaml:"kicklen"`
TopicLen int `yaml:"topiclen"`
WhowasEntries uint `yaml:"whowas-entries"` WhowasEntries uint `yaml:"whowas-entries"`
} }
} }
@ -169,7 +171,7 @@ func LoadConfig(filename string) (config *Config, err error) {
if len(config.Server.Listen) == 0 { if len(config.Server.Listen) == 0 {
return nil, errors.New("Server listening addresses missing") return nil, errors.New("Server listening addresses missing")
} }
if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 { if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 || config.Limits.TopicLen < 1 {
return nil, errors.New("Limits aren't setup properly, check them and make them sane") return nil, errors.New("Limits aren't setup properly, check them and make them sane")
} }
return config, nil return config, nil

View File

@ -26,6 +26,12 @@ import (
"github.com/tidwall/buntdb" "github.com/tidwall/buntdb"
) )
// Limits holds the maximum limits for various things such as topic lengths
type Limits struct {
Kick int
Topic int
}
type Server struct { type Server struct {
accounts map[string]*ClientAccount accounts map[string]*ClientAccount
channels ChannelNameMap channels ChannelNameMap
@ -35,6 +41,7 @@ type Server struct {
db *sql.DB db *sql.DB
store buntdb.DB store buntdb.DB
idle chan *Client idle chan *Client
limits Limits
motdLines []string motdLines []string
name Name name Name
nameString string // cache for server name string since it's used with almost every reply nameString string // cache for server name string since it's used with almost every reply
@ -67,13 +74,17 @@ type clientConn struct {
func NewServer(config *Config) *Server { func NewServer(config *Config) *Server {
server := &Server{ server := &Server{
accounts: make(map[string]*ClientAccount), accounts: make(map[string]*ClientAccount),
channels: make(ChannelNameMap), channels: make(ChannelNameMap),
clients: NewClientLookupSet(), clients: NewClientLookupSet(),
commands: make(chan Command), commands: make(chan Command),
ctime: time.Now(), ctime: time.Now(),
db: OpenDB(config.Datastore.SQLitePath), db: OpenDB(config.Datastore.SQLitePath),
idle: make(chan *Client), idle: make(chan *Client),
limits: Limits{
Kick: config.Limits.KickLen,
Topic: config.Limits.TopicLen,
},
name: NewName(config.Server.Name), name: NewName(config.Server.Name),
nameString: NewName(config.Server.Name).String(), nameString: NewName(config.Server.Name).String(),
newConns: make(chan clientConn), newConns: make(chan clientConn),
@ -166,7 +177,7 @@ func NewServer(config *Config) *Server {
server.isupport.Add("CHANTYPES", "#") server.isupport.Add("CHANTYPES", "#")
server.isupport.Add("EXCEPTS", "") server.isupport.Add("EXCEPTS", "")
server.isupport.Add("INVEX", "") server.isupport.Add("INVEX", "")
// server.isupport.Add("KICKLEN", "") //TODO(dan): Support kick length? server.isupport.Add("KICKLEN", strconv.Itoa(server.limits.Kick))
// server.isupport.Add("MAXLIST", "") //TODO(dan): Support max list length? // server.isupport.Add("MAXLIST", "") //TODO(dan): Support max list length?
// server.isupport.Add("MODES", "") //TODO(dan): Support max modes? // server.isupport.Add("MODES", "") //TODO(dan): Support max modes?
server.isupport.Add("NETWORK", config.Network.Name) server.isupport.Add("NETWORK", config.Network.Name)
@ -174,7 +185,7 @@ func NewServer(config *Config) *Server {
server.isupport.Add("PREFIX", "(qaohv)~&@%+") server.isupport.Add("PREFIX", "(qaohv)~&@%+")
// server.isupport.Add("STATUSMSG", "@+") //TODO(dan): Support STATUSMSG // server.isupport.Add("STATUSMSG", "@+") //TODO(dan): Support STATUSMSG
// server.isupport.Add("TARGMAX", "") //TODO(dan): Support this // server.isupport.Add("TARGMAX", "") //TODO(dan): Support this
// server.isupport.Add("TOPICLEN", "") //TODO(dan): Support topic length server.isupport.Add("TOPICLEN", strconv.Itoa(server.limits.Topic))
// account registration // account registration
if server.accountRegistration.Enabled { if server.accountRegistration.Enabled {

View File

@ -87,5 +87,11 @@ limits:
# channellen is the max channel length allowed # channellen is the max channel length allowed
channellen: 64 channellen: 64
# kicklen is the maximum length of a kick message
kicklen: 390
# topiclen is the maximum length of a channel topic
topiclen: 390
# whowas entries to store # whowas entries to store
whowas-entries: 100 whowas-entries: 100