macros.rkt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #lang typed/racket
  2. (provide (all-defined-out))
  3. (require (for-syntax syntax/parse racket/list)
  4. syntax/parse/define)
  5. (define-syntax (defconst-iota stx)
  6. (syntax-parse stx
  7. [(_ i:id ...)
  8. (let* ([ids (syntax->list #'(i ...))]
  9. [cmds (for/list ([i ids] [p (range 0 (length ids))])
  10. `(define ,i ,p))])
  11. (datum->syntax stx `(begin ,@cmds))
  12. ;;#'(~@ . cmds)
  13. )]))
  14. ;; Data types for communicating with the client
  15. (defconst-iota
  16. CdMessage ;; a normal message from the client meant to be broadcast
  17. CdUsers ;; get a list of users
  18. CdPing ;; ping the server to keep the connection alive
  19. CdAuth ;; get the auth levels of the user
  20. CdColor ;; get the users color
  21. CdEmote ;; get a list of emotes
  22. CdJoin ;; a message saying the client wants to join
  23. CdNotify ;; a notify message for the client to show
  24. )
  25. (defconst-iota
  26. DTInvalid
  27. DTChat ;; chat message
  28. DTCommand ;; non-chat function
  29. DTEvent ;; join/leave/kick/ban events
  30. DTClient ;; a message coming from the client
  31. DTHidden ;; a message that is purely instruction and data, not shown to user
  32. )
  33. (defconst-iota
  34. MsgChat ;; standard chat
  35. MsgAction ;; /me command
  36. MsgServer ;; server message
  37. MsgError ;; something went wrong
  38. MsgNotice ;; Like MsgServer, but for mods and admins only.
  39. MsgCommandResponse ;; The response from command
  40. MsgCommandError ;; The error response from command
  41. )
  42. (defconst-iota
  43. EvJoin
  44. EvLeave
  45. EvKick
  46. EvBan
  47. EvServerMessage
  48. EvNameChange
  49. EvNameChangeForced
  50. )