2017-10-02 10:42:50 +02:00
|
|
|
// Copyright (c) 2017 Shivaram Lingamneni <slingamn@cs.stanford.edu>
|
|
|
|
// released under the MIT license
|
|
|
|
|
|
|
|
package irc
|
|
|
|
|
2018-02-03 11:21:32 +01:00
|
|
|
import (
|
|
|
|
"github.com/oragono/oragono/irc/isupport"
|
|
|
|
"github.com/oragono/oragono/irc/modes"
|
|
|
|
)
|
2017-10-05 15:39:57 +02:00
|
|
|
|
2018-07-16 09:46:40 +02:00
|
|
|
func (server *Server) Config() *Config {
|
|
|
|
server.configurableStateMutex.RLock()
|
|
|
|
defer server.configurableStateMutex.RUnlock()
|
|
|
|
return server.config
|
2018-03-18 02:32:12 +01:00
|
|
|
}
|
|
|
|
|
2017-11-03 07:36:55 +01:00
|
|
|
func (server *Server) ISupport() *isupport.List {
|
2017-10-02 10:42:50 +02:00
|
|
|
server.configurableStateMutex.RLock()
|
|
|
|
defer server.configurableStateMutex.RUnlock()
|
|
|
|
return server.isupport
|
|
|
|
}
|
|
|
|
|
2017-11-03 07:36:55 +01:00
|
|
|
func (server *Server) Limits() Limits {
|
2018-07-16 09:46:40 +02:00
|
|
|
return server.Config().Limits
|
2017-10-02 10:42:50 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 07:36:55 +01:00
|
|
|
func (server *Server) Password() []byte {
|
2018-07-16 09:46:40 +02:00
|
|
|
return server.Config().Server.passwordBytes
|
2017-10-02 10:42:50 +02:00
|
|
|
}
|
2017-10-04 06:57:03 +02:00
|
|
|
|
2017-10-26 10:19:01 +02:00
|
|
|
func (server *Server) RecoverFromErrors() bool {
|
2018-07-16 10:08:24 +02:00
|
|
|
return *server.Config().Debug.RecoverFromErrors
|
2017-10-26 10:19:01 +02:00
|
|
|
}
|
2017-10-04 06:57:03 +02:00
|
|
|
|
2017-10-16 00:01:59 +02:00
|
|
|
func (server *Server) ProxyAllowedFrom() []string {
|
2018-07-16 09:46:40 +02:00
|
|
|
return server.Config().Server.ProxyAllowedFrom
|
2017-10-16 00:01:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (server *Server) WebIRCConfig() []webircConfig {
|
2018-07-16 09:46:40 +02:00
|
|
|
return server.Config().Server.WebIRC
|
2017-10-16 00:01:59 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 11:21:32 +01:00
|
|
|
func (server *Server) DefaultChannelModes() modes.Modes {
|
2018-07-16 09:46:40 +02:00
|
|
|
return server.Config().Channels.defaultModes
|
2017-10-30 10:21:47 +01:00
|
|
|
}
|
|
|
|
|
2017-11-09 04:19:50 +01:00
|
|
|
func (server *Server) ChannelRegistrationEnabled() bool {
|
2018-07-16 09:46:40 +02:00
|
|
|
return server.Config().Channels.Registration.Enabled
|
2017-11-09 04:19:50 +01:00
|
|
|
}
|
|
|
|
|
2018-02-11 11:30:40 +01:00
|
|
|
func (server *Server) AccountConfig() *AccountConfig {
|
2018-07-16 09:46:40 +02:00
|
|
|
return &server.Config().Accounts
|
2018-03-22 16:04:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (server *Server) FakelagConfig() *FakelagConfig {
|
2018-07-16 09:46:40 +02:00
|
|
|
return &server.Config().Fakelag
|
2018-02-11 11:30:40 +01:00
|
|
|
}
|
|
|
|
|
2018-04-19 08:48:19 +02:00
|
|
|
func (server *Server) GetOperator(name string) (oper *Oper) {
|
|
|
|
name, err := CasefoldName(name)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
server.configurableStateMutex.RLock()
|
|
|
|
defer server.configurableStateMutex.RUnlock()
|
2018-07-16 09:46:40 +02:00
|
|
|
return server.config.operators[name]
|
2018-04-19 08:48:19 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 07:36:55 +01:00
|
|
|
func (client *Client) Nick() string {
|
2017-10-04 06:57:03 +02:00
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.nick
|
|
|
|
}
|
|
|
|
|
2017-11-03 07:36:55 +01:00
|
|
|
func (client *Client) NickMaskString() string {
|
2017-10-04 06:57:03 +02:00
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.nickMaskString
|
|
|
|
}
|
|
|
|
|
2017-11-03 07:36:55 +01:00
|
|
|
func (client *Client) NickCasefolded() string {
|
2017-10-04 06:57:03 +02:00
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.nickCasefolded
|
|
|
|
}
|
2017-10-15 18:24:28 +02:00
|
|
|
|
2018-12-23 19:25:02 +01:00
|
|
|
func (client *Client) NickMaskCasefolded() string {
|
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.nickMaskCasefolded
|
|
|
|
}
|
|
|
|
|
2017-10-23 01:50:16 +02:00
|
|
|
func (client *Client) Username() string {
|
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.username
|
|
|
|
}
|
|
|
|
|
|
|
|
func (client *Client) Hostname() string {
|
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.hostname
|
|
|
|
}
|
|
|
|
|
|
|
|
func (client *Client) Realname() string {
|
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.realname
|
|
|
|
}
|
|
|
|
|
2019-01-31 00:59:49 +01:00
|
|
|
// uniqueIdentifiers returns the strings for which the server enforces per-client
|
|
|
|
// uniqueness/ownership; no two clients can have colliding casefolded nicks or
|
|
|
|
// skeletons.
|
|
|
|
func (client *Client) uniqueIdentifiers() (nickCasefolded string, skeleton string) {
|
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.nickCasefolded, client.skeleton
|
|
|
|
}
|
|
|
|
|
2018-11-26 11:23:27 +01:00
|
|
|
func (client *Client) ResumeToken() string {
|
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.resumeToken
|
|
|
|
}
|
|
|
|
|
2018-04-19 08:48:19 +02:00
|
|
|
func (client *Client) Oper() *Oper {
|
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.oper
|
|
|
|
}
|
|
|
|
|
2017-10-15 18:24:28 +02:00
|
|
|
func (client *Client) Registered() bool {
|
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.registered
|
|
|
|
}
|
|
|
|
|
|
|
|
func (client *Client) Destroyed() bool {
|
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.isDestroyed
|
|
|
|
}
|
2017-10-23 01:50:16 +02:00
|
|
|
|
2018-02-11 11:30:40 +01:00
|
|
|
func (client *Client) Account() string {
|
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.account
|
|
|
|
}
|
|
|
|
|
2017-11-09 04:19:50 +01:00
|
|
|
func (client *Client) AccountName() string {
|
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
2018-02-11 11:30:40 +01:00
|
|
|
return client.accountName
|
|
|
|
}
|
|
|
|
|
2018-02-20 10:50:46 +01:00
|
|
|
func (client *Client) SetAccountName(account string) (changed bool) {
|
2018-02-11 11:30:40 +01:00
|
|
|
var casefoldedAccount string
|
2018-02-20 10:50:46 +01:00
|
|
|
var err error
|
2018-02-11 11:30:40 +01:00
|
|
|
if account != "" {
|
2018-02-20 10:50:46 +01:00
|
|
|
if casefoldedAccount, err = CasefoldName(account); err != nil {
|
|
|
|
return
|
|
|
|
}
|
2018-02-11 11:30:40 +01:00
|
|
|
}
|
2018-02-20 10:50:46 +01:00
|
|
|
|
2018-02-11 11:30:40 +01:00
|
|
|
client.stateMutex.Lock()
|
|
|
|
defer client.stateMutex.Unlock()
|
2018-02-20 10:50:46 +01:00
|
|
|
changed = client.account != casefoldedAccount
|
2018-02-11 11:30:40 +01:00
|
|
|
client.account = casefoldedAccount
|
|
|
|
client.accountName = account
|
2018-02-20 10:50:46 +01:00
|
|
|
return
|
2017-11-09 04:19:50 +01:00
|
|
|
}
|
|
|
|
|
2018-02-27 03:44:03 +01:00
|
|
|
func (client *Client) Authorized() bool {
|
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
return client.authorized
|
|
|
|
}
|
|
|
|
|
|
|
|
func (client *Client) SetAuthorized(authorized bool) {
|
|
|
|
client.stateMutex.Lock()
|
|
|
|
defer client.stateMutex.Unlock()
|
|
|
|
client.authorized = authorized
|
|
|
|
}
|
|
|
|
|
2018-02-03 11:21:32 +01:00
|
|
|
func (client *Client) HasMode(mode modes.Mode) bool {
|
2018-04-23 00:47:10 +02:00
|
|
|
// client.flags has its own synch
|
|
|
|
return client.flags.HasMode(mode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (client *Client) SetMode(mode modes.Mode, on bool) bool {
|
|
|
|
return client.flags.SetMode(mode, on)
|
2017-10-23 01:50:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (client *Client) Channels() (result []*Channel) {
|
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
length := len(client.channels)
|
|
|
|
result = make([]*Channel, length)
|
|
|
|
i := 0
|
|
|
|
for channel := range client.channels {
|
|
|
|
result[i] = channel
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-05-04 06:24:54 +02:00
|
|
|
func (client *Client) WhoWas() (result WhoWas) {
|
2019-01-01 19:00:16 +01:00
|
|
|
return client.Details().WhoWas
|
|
|
|
}
|
|
|
|
|
|
|
|
func (client *Client) Details() (result ClientDetails) {
|
2018-05-04 06:24:54 +02:00
|
|
|
client.stateMutex.RLock()
|
|
|
|
defer client.stateMutex.RUnlock()
|
|
|
|
|
2019-01-01 19:00:16 +01:00
|
|
|
result.nick = client.nick
|
|
|
|
result.nickCasefolded = client.nickCasefolded
|
2018-05-04 06:24:54 +02:00
|
|
|
result.username = client.username
|
2019-01-01 19:00:16 +01:00
|
|
|
result.hostname = client.username
|
2018-05-04 06:24:54 +02:00
|
|
|
result.realname = client.realname
|
2019-01-01 19:00:16 +01:00
|
|
|
result.nickMask = client.nickMaskString
|
|
|
|
result.nickMaskCasefolded = client.nickMaskCasefolded
|
|
|
|
result.account = client.account
|
|
|
|
result.accountName = client.accountName
|
2018-05-04 06:24:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-10-23 01:50:16 +02:00
|
|
|
func (channel *Channel) Name() string {
|
|
|
|
channel.stateMutex.RLock()
|
|
|
|
defer channel.stateMutex.RUnlock()
|
|
|
|
return channel.name
|
|
|
|
}
|
|
|
|
|
2017-10-30 10:21:47 +01:00
|
|
|
func (channel *Channel) setName(name string) {
|
|
|
|
channel.stateMutex.Lock()
|
|
|
|
defer channel.stateMutex.Unlock()
|
|
|
|
channel.name = name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (channel *Channel) NameCasefolded() string {
|
|
|
|
channel.stateMutex.RLock()
|
|
|
|
defer channel.stateMutex.RUnlock()
|
|
|
|
return channel.nameCasefolded
|
|
|
|
}
|
|
|
|
|
|
|
|
func (channel *Channel) setNameCasefolded(nameCasefolded string) {
|
|
|
|
channel.stateMutex.Lock()
|
|
|
|
defer channel.stateMutex.Unlock()
|
|
|
|
channel.nameCasefolded = nameCasefolded
|
|
|
|
}
|
|
|
|
|
2017-10-23 01:50:16 +02:00
|
|
|
func (channel *Channel) Members() (result []*Client) {
|
|
|
|
channel.stateMutex.RLock()
|
|
|
|
defer channel.stateMutex.RUnlock()
|
|
|
|
return channel.membersCache
|
|
|
|
}
|
|
|
|
|
2018-12-28 19:45:55 +01:00
|
|
|
func (channel *Channel) setUserLimit(limit int) {
|
2017-10-23 01:50:16 +02:00
|
|
|
channel.stateMutex.Lock()
|
|
|
|
channel.userLimit = limit
|
|
|
|
channel.stateMutex.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (channel *Channel) Key() string {
|
|
|
|
channel.stateMutex.RLock()
|
|
|
|
defer channel.stateMutex.RUnlock()
|
|
|
|
return channel.key
|
|
|
|
}
|
|
|
|
|
|
|
|
func (channel *Channel) setKey(key string) {
|
|
|
|
channel.stateMutex.Lock()
|
2018-04-04 03:49:40 +02:00
|
|
|
defer channel.stateMutex.Unlock()
|
2017-10-23 01:50:16 +02:00
|
|
|
channel.key = key
|
|
|
|
}
|
|
|
|
|
2017-11-09 04:19:50 +01:00
|
|
|
func (channel *Channel) Founder() string {
|
|
|
|
channel.stateMutex.RLock()
|
|
|
|
defer channel.stateMutex.RUnlock()
|
|
|
|
return channel.registeredFounder
|
|
|
|
}
|