client: Add AWAYLEN

This commit is contained in:
Daniel Oaks 2016-09-12 12:40:09 +10:00
parent bc42960552
commit 0087de6092
4 changed files with 21 additions and 11 deletions

View File

@ -270,8 +270,8 @@ func (channel *Channel) SetTopic(client *Client, topic string) {
return
}
if len(topic) > client.server.limits.Topic {
topic = topic[:client.server.limits.Topic]
if len(topic) > client.server.limits.TopicLen {
topic = topic[:client.server.limits.TopicLen]
}
channel.topic = topic
@ -482,8 +482,8 @@ func (channel *Channel) Kick(client *Client, target *Client, comment string) {
return
}
if len(comment) > client.server.limits.Kick {
comment = comment[:client.server.limits.Kick]
if len(comment) > client.server.limits.KickLen {
comment = comment[:client.server.limits.KickLen]
}
for member := range channel.members {

View File

@ -97,6 +97,7 @@ type Config struct {
Limits struct {
NickLen int `yaml:"nicklen"`
ChannelLen int `yaml:"channellen"`
AwayLen int `yaml:"awaylen"`
KickLen int `yaml:"kicklen"`
TopicLen int `yaml:"topiclen"`
WhowasEntries uint `yaml:"whowas-entries"`
@ -157,7 +158,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 || config.Limits.TopicLen < 1 {
if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 || config.Limits.AwayLen < 1 || config.Limits.TopicLen < 1 || config.Limits.TopicLen < 1 {
return nil, errors.New("Limits aren't setup properly, check them and make them sane")
}
return config, nil

View File

@ -28,8 +28,9 @@ import (
// Limits holds the maximum limits for various things such as topic lengths
type Limits struct {
Kick int
Topic int
AwayLen int
KickLen int
TopicLen int
}
type Server struct {
@ -81,8 +82,9 @@ func NewServer(config *Config) *Server {
db: OpenDB(config.Datastore.SQLitePath),
idle: make(chan *Client),
limits: Limits{
Kick: config.Limits.KickLen,
Topic: config.Limits.TopicLen,
AwayLen: config.Limits.AwayLen,
KickLen: config.Limits.KickLen,
TopicLen: config.Limits.TopicLen,
},
name: NewName(config.Server.Name),
nameString: NewName(config.Server.Name).String(),
@ -169,13 +171,14 @@ func NewServer(config *Config) *Server {
// add RPL_ISUPPORT tokens
server.isupport = NewISupportList()
server.isupport.Add("AWAYLEN", strconv.Itoa(server.limits.AwayLen))
server.isupport.Add("CASEMAPPING", "ascii")
// server.isupport.Add("CHANMODES", "") //TODO(dan): Channel mode list here
server.isupport.Add("CHANNELLEN", strconv.Itoa(config.Limits.ChannelLen))
server.isupport.Add("CHANTYPES", "#")
server.isupport.Add("EXCEPTS", "")
server.isupport.Add("INVEX", "")
server.isupport.Add("KICKLEN", strconv.Itoa(server.limits.Kick))
server.isupport.Add("KICKLEN", strconv.Itoa(server.limits.KickLen))
// 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)
@ -183,7 +186,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", strconv.Itoa(server.limits.Topic))
server.isupport.Add("TOPICLEN", strconv.Itoa(server.limits.TopicLen))
// account registration
if server.accountRegistration.Enabled {
@ -816,6 +819,9 @@ func awayHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
if len(msg.Params) > 0 {
isAway = true
text = msg.Params[0]
if len(text) > server.limits.AwayLen {
text = text[:server.limits.AwayLen]
}
}
if isAway {

View File

@ -87,6 +87,9 @@ limits:
# channellen is the max channel length allowed
channellen: 64
# awaylen is the maximum length of an away message
awaylen: 200
# kicklen is the maximum length of a kick message
kicklen: 390