You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CapabilitiesState.kt 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package com.dmdirc.ktirc.model
  2. /**
  3. * Describes the state of capability negotiation with the server.
  4. */
  5. class CapabilitiesState {
  6. /** The current negotiation state. */
  7. var negotiationState: CapabilitiesNegotiationState = CapabilitiesNegotiationState.AWAITING_LIST
  8. internal set
  9. // TODO: These should only be mutable internally
  10. /** The capabilities that were advertised by the server. */
  11. val advertisedCapabilities = HashMap<String, String>()
  12. /** The capabilities that we have agreed to enable. */
  13. val enabledCapabilities = HashMap<Capability, String>()
  14. internal fun reset() {
  15. negotiationState = CapabilitiesNegotiationState.AWAITING_LIST
  16. advertisedCapabilities.clear()
  17. enabledCapabilities.clear()
  18. }
  19. }
  20. /**
  21. * The state of negotiations with the server.
  22. */
  23. enum class CapabilitiesNegotiationState {
  24. /**
  25. * We have requested a list of capabilities and are awaiting a reply.
  26. */
  27. AWAITING_LIST,
  28. /**
  29. * We have sent a list of capabilities to enable, and are awaiting an acknowledgement.
  30. */
  31. AWAITING_ACK,
  32. /**
  33. * We are attempting to authenticate with SASL.
  34. */
  35. AUTHENTICATING,
  36. /**
  37. * Negotiation has completed.
  38. */
  39. FINISHED
  40. }
  41. /**
  42. * IRCv3 capabilities supported by the client.
  43. */
  44. @Suppress("unused")
  45. sealed class Capability(vararg val names: String) {
  46. // Capabilities that introduce extra commands:
  47. /** Allows authentication using SASL via the AUTHENTICATE command. */
  48. object SaslAuthentication : Capability("sasl")
  49. // Capabilities that enable more information in message tags:
  50. /** Generic support for message tags, including client-only tags. */
  51. object DraftMessageTags33 : Capability("message-tags", "draft/message-tags-0.2") // TODO: Add processor for TAGMSG
  52. /** Messages are tagged with the server time they originated at. */
  53. object ServerTimeMessageTag : Capability("server-time")
  54. /** Messages are tagged with the sender's account name. */
  55. object UserAccountMessageTag : Capability("account-tag")
  56. // Capabilities that extend existing commands to supply extra information:
  57. /** Hosts are included for users in NAMES messages. */
  58. object HostsInNamesReply : Capability("userhost-in-names")
  59. /** Multiple mode prefixes are returned per-user in NAMES messages. */
  60. object MultipleUserModePrefixes : Capability("multi-prefix")
  61. /** The user's account and real name are provided when they join a channel. */
  62. object AccountAndRealNameInJoinMessages : Capability("extended-join")
  63. // Capabilities that affect how messages are sent/received:
  64. /** Messages can be sent in batches, and potentially handled differently by the client. */
  65. object Batch : Capability("batch")
  66. /** Messages sent by the client are echo'd back on successful delivery. */
  67. object EchoMessages : Capability("echo-message")
  68. /** Allows us to label all outgoing messages and have the server identify the responses to them. */
  69. object LabeledResponse : Capability("draft/labeled-response")
  70. // Capabilities that notify us of changes to other clients:
  71. /** Receive a notification when a user's account changes. */
  72. object AccountChangeMessages : Capability("account-notify")
  73. /** Receive a notification when a user's away state changes. */
  74. object AwayStateMessages : Capability("away-notify") // TODO: Add processor
  75. /** Receive a notification when a user's host changes, instead of a quit/join. */
  76. object HostChangeMessages : Capability("chghost")
  77. }
  78. internal val capabilities: Map<String, Capability> by lazy {
  79. Capability::class.nestedClasses
  80. .map { it.objectInstance as Capability }
  81. .flatMap { it.names.map { name -> name to it } }
  82. .toMap()
  83. }