Fix: panic when spawning 10,000 bots :^)

This commit is contained in:
kayos@tcp.direct 2021-11-09 08:14:35 -08:00
parent b9856ab64e
commit ff65f6fa03

@ -519,6 +519,9 @@ func (c *Client) ConnSince() (since *time.Duration, err error) {
// IsConnected returns true if the client is connected to the server. // IsConnected returns true if the client is connected to the server.
func (c *Client) IsConnected() bool { func (c *Client) IsConnected() bool {
if c == nil {
return false
}
if c.conn == nil { if c.conn == nil {
return false return false
} }
@ -529,6 +532,9 @@ func (c *Client) IsConnected() bool {
// GetNick returns the current nickname of the active connection. Panics if // GetNick returns the current nickname of the active connection. Panics if
// tracking is disabled. // tracking is disabled.
func (c *Client) GetNick() string { func (c *Client) GetNick() string {
if c == nil {
return ""
}
c.panicIfNotTracking() c.panicIfNotTracking()
n := c.state.nick.Load().(string) n := c.state.nick.Load().(string)
@ -788,6 +794,9 @@ func (c *Client) HasCapability(name string) (has bool) {
// disabled. Adds useful info like what function specifically, and where it // disabled. Adds useful info like what function specifically, and where it
// was called from. // was called from.
func (c *Client) panicIfNotTracking() { func (c *Client) panicIfNotTracking() {
if c == nil {
return
}
if !c.Config.disableTracking { if !c.Config.disableTracking {
return return
} }