Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

client.go 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. // Copyright (c) 2012-2014 Jeremy Latt
  2. // Copyright (c) 2014-2015 Edmund Huber
  3. // Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
  4. // released under the MIT license
  5. package irc
  6. import (
  7. "errors"
  8. "fmt"
  9. "log"
  10. "net"
  11. "runtime/debug"
  12. "strconv"
  13. "strings"
  14. "sync"
  15. "time"
  16. "github.com/goshuirc/irc-go/ircfmt"
  17. "github.com/goshuirc/irc-go/ircmsg"
  18. ident "github.com/oragono/go-ident"
  19. "github.com/oragono/oragono/irc/caps"
  20. "github.com/oragono/oragono/irc/sno"
  21. )
  22. const (
  23. // IdleTimeout is how long without traffic before a client's considered idle.
  24. IdleTimeout = time.Minute + time.Second*30
  25. // QuitTimeout is how long without traffic (after they're considered idle) that clients are killed.
  26. QuitTimeout = time.Minute
  27. // IdentTimeoutSeconds is how many seconds before our ident (username) check times out.
  28. IdentTimeoutSeconds = 5
  29. )
  30. var (
  31. // TimeoutStatedSeconds is how many seconds before clients are timed out (IdleTimeout plus QuitTimeout).
  32. TimeoutStatedSeconds = strconv.Itoa(int((IdleTimeout + QuitTimeout).Seconds()))
  33. // ErrNickAlreadySet is a weird error that's sent when the server's consistency has been compromised.
  34. ErrNickAlreadySet = errors.New("Nickname is already set")
  35. )
  36. // Client is an IRC client.
  37. type Client struct {
  38. account *ClientAccount
  39. atime time.Time
  40. authorized bool
  41. awayMessage string
  42. capabilities *caps.Set
  43. capState CapState
  44. capVersion caps.Version
  45. certfp string
  46. channels ChannelSet
  47. class *OperClass
  48. ctime time.Time
  49. destroyMutex sync.Mutex
  50. exitedSnomaskSent bool
  51. flags map[Mode]bool
  52. hasQuit bool
  53. hops int
  54. hostname string
  55. idleTimer *time.Timer
  56. isDestroyed bool
  57. isQuitting bool
  58. monitoring map[string]bool
  59. monitoringMutex sync.RWMutex
  60. nick string
  61. nickCasefolded string
  62. nickMaskCasefolded string
  63. nickMaskString string // cache for nickmask string since it's used with lots of replies
  64. operName string
  65. proxiedIP string // actual remote IP if using the PROXY protocol
  66. quitMessage string
  67. quitMessageSent bool
  68. quitMutex sync.Mutex
  69. quitTimer *time.Timer
  70. rawHostname string
  71. realname string
  72. registered bool
  73. saslInProgress bool
  74. saslMechanism string
  75. saslValue string
  76. server *Server
  77. socket *Socket
  78. timerMutex sync.Mutex
  79. username string
  80. vhost string
  81. whoisLine string
  82. }
  83. // NewClient returns a client with all the appropriate info setup.
  84. func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
  85. now := time.Now()
  86. socket := NewSocket(conn, server.MaxSendQBytes)
  87. go socket.RunSocketWriter()
  88. client := &Client{
  89. atime: now,
  90. authorized: server.password == nil,
  91. capabilities: caps.NewSet(),
  92. capState: CapNone,
  93. capVersion: caps.Cap301,
  94. channels: make(ChannelSet),
  95. ctime: now,
  96. flags: make(map[Mode]bool),
  97. monitoring: make(map[string]bool),
  98. server: server,
  99. socket: &socket,
  100. account: &NoAccount,
  101. nick: "*", // * is used until actual nick is given
  102. nickCasefolded: "*",
  103. nickMaskString: "*", // * is used until actual nick is given
  104. }
  105. if isTLS {
  106. client.flags[TLS] = true
  107. // error is not useful to us here anyways so we can ignore it
  108. client.certfp, _ = client.socket.CertFP()
  109. }
  110. if server.checkIdent {
  111. _, serverPortString, err := net.SplitHostPort(conn.LocalAddr().String())
  112. serverPort, _ := strconv.Atoi(serverPortString)
  113. if err != nil {
  114. log.Fatal(err)
  115. }
  116. clientHost, clientPortString, err := net.SplitHostPort(conn.RemoteAddr().String())
  117. clientPort, _ := strconv.Atoi(clientPortString)
  118. if err != nil {
  119. log.Fatal(err)
  120. }
  121. client.Notice("*** Looking up your username")
  122. resp, err := ident.Query(clientHost, serverPort, clientPort, IdentTimeoutSeconds)
  123. if err == nil {
  124. username := resp.Identifier
  125. _, err := CasefoldName(username) // ensure it's a valid username
  126. if err == nil {
  127. client.Notice("*** Found your username")
  128. client.username = username
  129. // we don't need to updateNickMask here since nickMask is not used for anything yet
  130. } else {
  131. client.Notice("*** Got a malformed username, ignoring")
  132. }
  133. } else {
  134. client.Notice("*** Could not find your username")
  135. }
  136. }
  137. client.Touch()
  138. go client.run()
  139. return client
  140. }
  141. // IP returns the IP address of this client.
  142. func (client *Client) IP() net.IP {
  143. if client.proxiedIP != "" {
  144. return net.ParseIP(client.proxiedIP)
  145. }
  146. return net.ParseIP(IPString(client.socket.conn.RemoteAddr()))
  147. }
  148. // IPString returns the IP address of this client as a string.
  149. func (client *Client) IPString() string {
  150. if client.proxiedIP != "" {
  151. return client.proxiedIP
  152. }
  153. ip := client.IP().String()
  154. if 0 < len(ip) && ip[0] == ':' {
  155. ip = "0" + ip
  156. }
  157. return ip
  158. }
  159. //
  160. // command goroutine
  161. //
  162. func (client *Client) maxlens() (int, int) {
  163. maxlenTags := 512
  164. maxlenRest := 512
  165. if client.capabilities.Has(caps.MessageTags) {
  166. maxlenTags = 4096
  167. }
  168. if client.capabilities.Has(caps.MaxLine) {
  169. if client.server.limits.LineLen.Tags > maxlenTags {
  170. maxlenTags = client.server.limits.LineLen.Tags
  171. }
  172. maxlenRest = client.server.limits.LineLen.Rest
  173. }
  174. return maxlenTags, maxlenRest
  175. }
  176. func (client *Client) run() {
  177. var err error
  178. var isExiting bool
  179. var line string
  180. var msg ircmsg.IrcMessage
  181. // Set the hostname for this client
  182. // (may be overridden by a later PROXY command from stunnel)
  183. client.rawHostname = AddrLookupHostname(client.socket.conn.RemoteAddr())
  184. for {
  185. line, err = client.socket.Read()
  186. if err != nil {
  187. client.Quit("connection closed")
  188. break
  189. }
  190. maxlenTags, maxlenRest := client.maxlens()
  191. client.server.logger.Debug("userinput ", client.nick, "<- ", line)
  192. msg, err = ircmsg.ParseLineMaxLen(line, maxlenTags, maxlenRest)
  193. if err == ircmsg.ErrorLineIsEmpty {
  194. continue
  195. } else if err != nil {
  196. client.Quit("received malformed line")
  197. break
  198. }
  199. cmd, exists := Commands[msg.Command]
  200. if !exists {
  201. if len(msg.Command) > 0 {
  202. client.Send(nil, client.server.name, ERR_UNKNOWNCOMMAND, client.nick, msg.Command, "Unknown command")
  203. } else {
  204. client.Send(nil, client.server.name, ERR_UNKNOWNCOMMAND, client.nick, "lastcmd", "No command given")
  205. }
  206. continue
  207. }
  208. isExiting = cmd.Run(client.server, client, msg)
  209. if isExiting || client.isQuitting {
  210. break
  211. }
  212. }
  213. // ensure client connection gets closed
  214. client.destroy()
  215. }
  216. //
  217. // idle, quit, timers and timeouts
  218. //
  219. // Active updates when the client was last 'active' (i.e. the user should be sitting in front of their client).
  220. func (client *Client) Active() {
  221. client.atime = time.Now()
  222. }
  223. // Touch marks the client as alive (as it it has a connection to us and we
  224. // can receive messages from it), and resets when we'll send the client a
  225. // keepalive PING.
  226. func (client *Client) Touch() {
  227. client.timerMutex.Lock()
  228. defer client.timerMutex.Unlock()
  229. if client.quitTimer != nil {
  230. client.quitTimer.Stop()
  231. }
  232. if client.idleTimer == nil {
  233. client.idleTimer = time.AfterFunc(IdleTimeout, client.connectionIdle)
  234. } else {
  235. client.idleTimer.Reset(IdleTimeout)
  236. }
  237. }
  238. // connectionIdle is run when the client has not sent us any data for a while,
  239. // sends the client a PING and starts the quit timeout.
  240. func (client *Client) connectionIdle() {
  241. client.timerMutex.Lock()
  242. defer client.timerMutex.Unlock()
  243. client.Send(nil, "", "PING", client.nick)
  244. if client.quitTimer == nil {
  245. client.quitTimer = time.AfterFunc(QuitTimeout, client.connectionTimeout)
  246. } else {
  247. client.quitTimer.Reset(QuitTimeout)
  248. }
  249. }
  250. // connectionTimeout runs after connectionIdle has been run, if we do not receive a
  251. // ping or any other activity back from the client. When this happens we assume the
  252. // connection has died and remove the client from the network.
  253. func (client *Client) connectionTimeout() {
  254. client.Quit(fmt.Sprintf("Ping timeout: %s seconds", TimeoutStatedSeconds))
  255. client.isQuitting = true
  256. }
  257. //
  258. // server goroutine
  259. //
  260. // Register sets the client details as appropriate when entering the network.
  261. func (client *Client) Register() {
  262. if client.registered {
  263. return
  264. }
  265. client.registered = true
  266. client.Touch()
  267. client.updateNickMask()
  268. client.alertMonitors()
  269. }
  270. // IdleTime returns how long this client's been idle.
  271. func (client *Client) IdleTime() time.Duration {
  272. return time.Since(client.atime)
  273. }
  274. // SignonTime returns this client's signon time as a unix timestamp.
  275. func (client *Client) SignonTime() int64 {
  276. return client.ctime.Unix()
  277. }
  278. // IdleSeconds returns the number of seconds this client's been idle.
  279. func (client *Client) IdleSeconds() uint64 {
  280. return uint64(client.IdleTime().Seconds())
  281. }
  282. // HasNick returns true if the client's nickname is set (used in registration).
  283. func (client *Client) HasNick() bool {
  284. return client.nick != "" && client.nick != "*"
  285. }
  286. // HasUsername returns true if the client's username is set (used in registration).
  287. func (client *Client) HasUsername() bool {
  288. return client.username != "" && client.username != "*"
  289. }
  290. // HasRoleCapabs returns true if client has the given (role) capabilities.
  291. func (client *Client) HasRoleCapabs(capabs ...string) bool {
  292. if client.class == nil {
  293. return false
  294. }
  295. for _, capab := range capabs {
  296. if !client.class.Capabilities[capab] {
  297. return false
  298. }
  299. }
  300. return true
  301. }
  302. // ModeString returns the mode string for this client.
  303. func (client *Client) ModeString() (str string) {
  304. str = "+"
  305. for flag := range client.flags {
  306. str += flag.String()
  307. }
  308. return
  309. }
  310. // Friends refers to clients that share a channel with this client.
  311. func (client *Client) Friends(capabs ...caps.Capability) ClientSet {
  312. friends := make(ClientSet)
  313. // make sure that I have the right caps
  314. hasCaps := true
  315. for _, capab := range capabs {
  316. if !client.capabilities.Has(capab) {
  317. hasCaps = false
  318. break
  319. }
  320. }
  321. if hasCaps {
  322. friends.Add(client)
  323. }
  324. for channel := range client.channels {
  325. channel.membersMutex.RLock()
  326. for member := range channel.members {
  327. // make sure they have all the required caps
  328. hasCaps = true
  329. for _, capab := range capabs {
  330. if !member.capabilities.Has(capab) {
  331. hasCaps = false
  332. break
  333. }
  334. }
  335. if hasCaps {
  336. friends.Add(member)
  337. }
  338. }
  339. channel.membersMutex.RUnlock()
  340. }
  341. return friends
  342. }
  343. // updateNick updates the casefolded nickname.
  344. func (client *Client) updateNick() {
  345. casefoldedName, err := CasefoldName(client.nick)
  346. if err != nil {
  347. log.Println(fmt.Sprintf("ERROR: Nick [%s] couldn't be casefolded... this should never happen. Printing stacktrace.", client.nick))
  348. debug.PrintStack()
  349. }
  350. client.nickCasefolded = casefoldedName
  351. }
  352. // updateNickMask updates the casefolded nickname and nickmask.
  353. func (client *Client) updateNickMask() {
  354. client.updateNick()
  355. if len(client.vhost) > 0 {
  356. client.hostname = client.vhost
  357. } else {
  358. client.hostname = client.rawHostname
  359. }
  360. client.nickMaskString = fmt.Sprintf("%s!%s@%s", client.nick, client.username, client.hostname)
  361. nickMaskCasefolded, err := Casefold(client.nickMaskString)
  362. if err != nil {
  363. log.Println(fmt.Sprintf("ERROR: Nickmask [%s] couldn't be casefolded... this should never happen. Printing stacktrace.", client.nickMaskString))
  364. debug.PrintStack()
  365. }
  366. client.nickMaskCasefolded = nickMaskCasefolded
  367. }
  368. // AllNickmasks returns all the possible nickmasks for the client.
  369. func (client *Client) AllNickmasks() []string {
  370. var masks []string
  371. var mask string
  372. var err error
  373. if len(client.vhost) > 0 {
  374. mask, err = Casefold(fmt.Sprintf("%s!%s@%s", client.nick, client.username, client.vhost))
  375. if err == nil {
  376. masks = append(masks, mask)
  377. }
  378. }
  379. mask, err = Casefold(fmt.Sprintf("%s!%s@%s", client.nick, client.username, client.rawHostname))
  380. if err == nil {
  381. masks = append(masks, mask)
  382. }
  383. mask2, err := Casefold(fmt.Sprintf("%s!%s@%s", client.nick, client.username, IPString(client.socket.conn.RemoteAddr())))
  384. if err == nil && mask2 != mask {
  385. masks = append(masks, mask2)
  386. }
  387. return masks
  388. }
  389. // SetNickname sets the very first nickname for the client.
  390. func (client *Client) SetNickname(nickname string) error {
  391. if client.HasNick() {
  392. client.server.logger.Error("nick", fmt.Sprintf("%s nickname already set, something is wrong with server consistency", client.nickMaskString))
  393. return ErrNickAlreadySet
  394. }
  395. err := client.server.clients.Add(client, nickname)
  396. if err == nil {
  397. client.nick = nickname
  398. client.updateNick()
  399. }
  400. return err
  401. }
  402. // ChangeNickname changes the existing nickname of the client.
  403. func (client *Client) ChangeNickname(nickname string) error {
  404. origNickMask := client.nickMaskString
  405. err := client.server.clients.Replace(client.nick, nickname, client)
  406. if err == nil {
  407. client.server.logger.Debug("nick", fmt.Sprintf("%s changed nickname to %s", client.nick, nickname))
  408. client.server.snomasks.Send(sno.LocalNicks, fmt.Sprintf(ircfmt.Unescape("$%s$r changed nickname to %s"), client.nick, nickname))
  409. client.server.whoWas.Append(client)
  410. client.nick = nickname
  411. client.updateNickMask()
  412. for friend := range client.Friends() {
  413. friend.Send(nil, origNickMask, "NICK", nickname)
  414. }
  415. }
  416. return err
  417. }
  418. // LoggedIntoAccount returns true if this client is logged into an account.
  419. func (client *Client) LoggedIntoAccount() bool {
  420. return client.account != nil && client.account != &NoAccount
  421. }
  422. // Quit sends the given quit message to the client (but does not destroy them).
  423. func (client *Client) Quit(message string) {
  424. client.quitMutex.Lock()
  425. defer client.quitMutex.Unlock()
  426. if !client.quitMessageSent {
  427. quitMsg := ircmsg.MakeMessage(nil, client.nickMaskString, "QUIT", message)
  428. quitLine, _ := quitMsg.Line()
  429. errorMsg := ircmsg.MakeMessage(nil, "", "ERROR", message)
  430. errorLine, _ := errorMsg.Line()
  431. client.socket.SetFinalData(quitLine + errorLine)
  432. client.quitMessageSent = true
  433. client.quitMessage = message
  434. }
  435. }
  436. // destroy gets rid of a client, removes them from server lists etc.
  437. func (client *Client) destroy() {
  438. client.destroyMutex.Lock()
  439. defer client.destroyMutex.Unlock()
  440. if client.isDestroyed {
  441. return
  442. }
  443. client.server.logger.Debug("quit", fmt.Sprintf("%s is no longer on the server", client.nick))
  444. // send quit/error message to client if they haven't been sent already
  445. client.Quit("Connection closed")
  446. client.isDestroyed = true
  447. client.server.whoWas.Append(client)
  448. friends := client.Friends()
  449. friends.Remove(client)
  450. // remove from connection limits
  451. ipaddr := client.IP()
  452. // this check shouldn't be required but eh
  453. if ipaddr != nil {
  454. client.server.connectionLimitsMutex.Lock()
  455. client.server.connectionLimits.RemoveClient(ipaddr)
  456. client.server.connectionLimitsMutex.Unlock()
  457. }
  458. // remove from opers list
  459. _, exists := client.server.currentOpers[client]
  460. if exists {
  461. delete(client.server.currentOpers, client)
  462. }
  463. // alert monitors
  464. client.server.monitoringMutex.RLock()
  465. for _, mClient := range client.server.monitoring[client.nickCasefolded] {
  466. mClient.Send(nil, client.server.name, RPL_MONOFFLINE, mClient.nick, client.nick)
  467. }
  468. client.server.monitoringMutex.RUnlock()
  469. // remove my monitors
  470. client.clearMonitorList()
  471. // clean up channels
  472. client.server.channelJoinPartMutex.Lock()
  473. for channel := range client.channels {
  474. channel.Quit(client, &friends)
  475. }
  476. client.server.channelJoinPartMutex.Unlock()
  477. // clean up server
  478. client.server.clients.Remove(client)
  479. // clean up self
  480. if client.idleTimer != nil {
  481. client.idleTimer.Stop()
  482. }
  483. if client.quitTimer != nil {
  484. client.quitTimer.Stop()
  485. }
  486. client.socket.Close()
  487. // send quit messages to friends
  488. for friend := range friends {
  489. if client.quitMessage == "" {
  490. client.quitMessage = "Exited"
  491. }
  492. friend.Send(nil, client.nickMaskString, "QUIT", client.quitMessage)
  493. }
  494. if !client.exitedSnomaskSent {
  495. client.server.snomasks.Send(sno.LocalQuits, fmt.Sprintf(ircfmt.Unescape("%s$r exited the network"), client.nick))
  496. }
  497. }
  498. // SendSplitMsgFromClient sends an IRC PRIVMSG/NOTICE coming from a specific client.
  499. // Adds account-tag to the line as well.
  500. func (client *Client) SendSplitMsgFromClient(msgid string, from *Client, tags *map[string]ircmsg.TagValue, command, target string, message SplitMessage) {
  501. if client.capabilities.Has(caps.MaxLine) {
  502. client.SendFromClient(msgid, from, tags, command, target, message.ForMaxLine)
  503. } else {
  504. for _, str := range message.For512 {
  505. client.SendFromClient(msgid, from, tags, command, target, str)
  506. }
  507. }
  508. }
  509. // SendFromClient sends an IRC line coming from a specific client.
  510. // Adds account-tag to the line as well.
  511. func (client *Client) SendFromClient(msgid string, from *Client, tags *map[string]ircmsg.TagValue, command string, params ...string) error {
  512. // attach account-tag
  513. if client.capabilities.Has(caps.AccountTag) && from.account != &NoAccount {
  514. if tags == nil {
  515. tags = ircmsg.MakeTags("account", from.account.Name)
  516. } else {
  517. (*tags)["account"] = ircmsg.MakeTagValue(from.account.Name)
  518. }
  519. }
  520. // attach message-id
  521. if len(msgid) > 0 && client.capabilities.Has(caps.MessageTags) {
  522. if tags == nil {
  523. tags = ircmsg.MakeTags("draft/msgid", msgid)
  524. } else {
  525. (*tags)["draft/msgid"] = ircmsg.MakeTagValue(msgid)
  526. }
  527. }
  528. return client.Send(tags, from.nickMaskString, command, params...)
  529. }
  530. var (
  531. // these are all the output commands that MUST have their last param be a trailing.
  532. // this is needed because silly clients like to treat trailing as separate from the
  533. // other params in messages.
  534. commandsThatMustUseTrailing = map[string]bool{
  535. "PRIVMSG": true,
  536. "NOTICE": true,
  537. RPL_WHOISCHANNELS: true,
  538. RPL_USERHOST: true,
  539. }
  540. )
  541. // Send sends an IRC line to the client.
  542. func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error {
  543. // attach server-time
  544. if client.capabilities.Has(caps.ServerTime) {
  545. t := time.Now().UTC().Format("2006-01-02T15:04:05.999Z")
  546. if tags == nil {
  547. tags = ircmsg.MakeTags("time", t)
  548. } else {
  549. (*tags)["time"] = ircmsg.MakeTagValue(t)
  550. }
  551. }
  552. // force trailing, if message requires it
  553. var usedTrailingHack bool
  554. if commandsThatMustUseTrailing[strings.ToUpper(command)] && len(params) > 0 {
  555. lastParam := params[len(params)-1]
  556. // to force trailing, we ensure the final param contains a space
  557. if !strings.Contains(lastParam, " ") {
  558. params[len(params)-1] = lastParam + " "
  559. usedTrailingHack = true
  560. }
  561. }
  562. // send out the message
  563. message := ircmsg.MakeMessage(tags, prefix, command, params...)
  564. maxlenTags, maxlenRest := client.maxlens()
  565. line, err := message.LineMaxLen(maxlenTags, maxlenRest)
  566. if err != nil {
  567. // try not to fail quietly - especially useful when running tests, as a note to dig deeper
  568. // log.Println("Error assembling message:")
  569. // spew.Dump(message)
  570. // debug.PrintStack()
  571. message = ircmsg.MakeMessage(nil, client.server.name, ERR_UNKNOWNERROR, "*", "Error assembling message for sending")
  572. line, _ := message.Line()
  573. client.socket.Write(line)
  574. return err
  575. }
  576. // is we used the trailing hack, we need to strip the final space we appended earlier
  577. if usedTrailingHack {
  578. line = line[:len(line)-3] + "\r\n"
  579. }
  580. client.server.logger.Debug("useroutput", client.nick, " ->", strings.TrimRight(line, "\r\n"))
  581. client.socket.Write(line)
  582. return nil
  583. }
  584. // Notice sends the client a notice from the server.
  585. func (client *Client) Notice(text string) {
  586. limit := 400
  587. if client.capabilities.Has(caps.MaxLine) {
  588. limit = client.server.limits.LineLen.Rest - 110
  589. }
  590. lines := wordWrap(text, limit)
  591. for _, line := range lines {
  592. client.Send(nil, client.server.name, "NOTICE", client.nick, line)
  593. }
  594. }