mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 10:42:52 +01:00
channel: Add KICKLEN and TOPICLEN
This commit is contained in:
parent
3321243486
commit
79d831bbb7
@ -270,6 +270,10 @@ func (channel *Channel) SetTopic(client *Client, topic string) {
|
||||
return
|
||||
}
|
||||
|
||||
if len(topic) > client.server.limits.Topic {
|
||||
topic = topic[:client.server.limits.Topic]
|
||||
}
|
||||
|
||||
channel.topic = topic
|
||||
channel.topicSetBy = client.nickString
|
||||
channel.topicSetTime = time.Now()
|
||||
@ -478,6 +482,10 @@ func (channel *Channel) Kick(client *Client, target *Client, comment string) {
|
||||
return
|
||||
}
|
||||
|
||||
if len(comment) > client.server.limits.Kick {
|
||||
comment = comment[:client.server.limits.Kick]
|
||||
}
|
||||
|
||||
for member := range channel.members {
|
||||
member.Send(nil, client.nickMaskString, "KICK", channel.nameString, target.nickString, comment)
|
||||
}
|
||||
|
@ -99,6 +99,8 @@ type Config struct {
|
||||
Limits struct {
|
||||
NickLen int `yaml:"nicklen"`
|
||||
ChannelLen int `yaml:"channellen"`
|
||||
KickLen int `yaml:"kicklen"`
|
||||
TopicLen int `yaml:"topiclen"`
|
||||
WhowasEntries uint `yaml:"whowas-entries"`
|
||||
}
|
||||
}
|
||||
@ -169,7 +171,7 @@ func LoadConfig(filename string) (config *Config, err error) {
|
||||
if len(config.Server.Listen) == 0 {
|
||||
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 config, nil
|
||||
|
@ -26,6 +26,12 @@ import (
|
||||
"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 {
|
||||
accounts map[string]*ClientAccount
|
||||
channels ChannelNameMap
|
||||
@ -35,6 +41,7 @@ type Server struct {
|
||||
db *sql.DB
|
||||
store buntdb.DB
|
||||
idle chan *Client
|
||||
limits Limits
|
||||
motdLines []string
|
||||
name Name
|
||||
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 {
|
||||
server := &Server{
|
||||
accounts: make(map[string]*ClientAccount),
|
||||
channels: make(ChannelNameMap),
|
||||
clients: NewClientLookupSet(),
|
||||
commands: make(chan Command),
|
||||
ctime: time.Now(),
|
||||
db: OpenDB(config.Datastore.SQLitePath),
|
||||
idle: make(chan *Client),
|
||||
accounts: make(map[string]*ClientAccount),
|
||||
channels: make(ChannelNameMap),
|
||||
clients: NewClientLookupSet(),
|
||||
commands: make(chan Command),
|
||||
ctime: time.Now(),
|
||||
db: OpenDB(config.Datastore.SQLitePath),
|
||||
idle: make(chan *Client),
|
||||
limits: Limits{
|
||||
Kick: config.Limits.KickLen,
|
||||
Topic: config.Limits.TopicLen,
|
||||
},
|
||||
name: NewName(config.Server.Name),
|
||||
nameString: NewName(config.Server.Name).String(),
|
||||
newConns: make(chan clientConn),
|
||||
@ -166,7 +177,7 @@ func NewServer(config *Config) *Server {
|
||||
server.isupport.Add("CHANTYPES", "#")
|
||||
server.isupport.Add("EXCEPTS", "")
|
||||
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("MODES", "") //TODO(dan): Support max modes?
|
||||
server.isupport.Add("NETWORK", config.Network.Name)
|
||||
@ -174,7 +185,7 @@ func NewServer(config *Config) *Server {
|
||||
server.isupport.Add("PREFIX", "(qaohv)~&@%+")
|
||||
// server.isupport.Add("STATUSMSG", "@+") //TODO(dan): Support STATUSMSG
|
||||
// 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
|
||||
if server.accountRegistration.Enabled {
|
||||
|
@ -87,5 +87,11 @@ limits:
|
||||
# channellen is the max channel length allowed
|
||||
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: 100
|
||||
|
Loading…
Reference in New Issue
Block a user