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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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<Capability, 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(val name: 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. /** Draft version of message tags, enables client-only tags. */
  51. object DraftMessageTags33 : Capability("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 sent by the client are echo'd back on successful delivery. */
  65. object EchoMessages : Capability("echo-message")
  66. // Capabilities that notify us of changes to other clients:
  67. /** Receive a notification when a user's account changes. */
  68. object AccountChangeMessages : Capability("account-notify")
  69. /** Receive a notification when a user's away state changes. */
  70. object AwayStateMessages : Capability("away-notify") // TODO: Add processor
  71. /** Receive a notification when a user's host changes, instead of a quit/join. */
  72. object HostChangeMessages : Capability("chghost") // TODO: Add processor
  73. }
  74. internal val capabilities: Map<String, Capability> by lazy {
  75. Capability::class.nestedClasses.map { it.objectInstance as Capability }.associateBy { it.name }
  76. }