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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. }
  15. /**
  16. * The state of negotiations with the server.
  17. */
  18. enum class CapabilitiesNegotiationState {
  19. /**
  20. * We have requested a list of capabilities and are awaiting a reply.
  21. */
  22. AWAITING_LIST,
  23. /**
  24. * We have sent a list of capabilities to enable, and are awaiting an acknowledgement.
  25. */
  26. AWAITING_ACK,
  27. /**
  28. * We are attempting to authenticate with SASL.
  29. */
  30. AUTHENTICATING,
  31. /**
  32. * Negotiation has completed.
  33. */
  34. FINISHED
  35. }
  36. /**
  37. * IRCv3 capabilities supported by the client.
  38. */
  39. @Suppress("unused")
  40. sealed class Capability(val name: String) {
  41. // Capabilities that introduce extra commands:
  42. /** Allows authentication using SASL via the AUTHENTICATE command. */
  43. object SaslAuthentication : Capability("sasl")
  44. // Capabilities that enable more information in message tags:
  45. /** Draft version of message tags, enables client-only tags. */
  46. object DraftMessageTags33 : Capability("draft/message-tags-0.2") // TODO: Add processor for TAGMSG
  47. /** Messages are tagged with the server time they originated at. */
  48. object ServerTimeMessageTag : Capability("server-time")
  49. /** Messages are tagged with the sender's account name. */
  50. object UserAccountMessageTag : Capability("account-tag")
  51. // Capabilities that extend existing commands to supply extra information:
  52. /** Hosts are included for users in NAMES messages. */
  53. object HostsInNamesReply : Capability("userhost-in-names")
  54. /** Multiple mode prefixes are returned per-user in NAMES messages. */
  55. object MultipleUserModePrefixes : Capability("multi-prefix")
  56. /** The user's account and real name are provided when they join a channel. */
  57. object AccountAndRealNameInJoinMessages : Capability("extended-join")
  58. // Capabilities that affect how messages are sent/received:
  59. /** Messages sent by the client are echo'd back on successful delivery. */
  60. object EchoMessages : Capability("echo-message")
  61. // Capabilities that notify us of changes to other clients:
  62. /** Receive a notification when a user's account changes. */
  63. object AccountChangeMessages : Capability("account-notify")
  64. /** Receive a notification when a user's away state changes. */
  65. object AwayStateMessages : Capability("away-notify") // TODO: Add processor
  66. /** Receive a notification when a user's host changes, instead of a quit/join. */
  67. object HostChangeMessages : Capability("chghost") // TODO: Add processor
  68. }
  69. internal val capabilities: Map<String, Capability> by lazy {
  70. Capability::class.nestedClasses.map { it.objectInstance as Capability }.associateBy { it.name }
  71. }