main.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. script "log.rb"
  2. log "Main mruby script loaded OK."
  3. p Signal.constants
  4. script "client.rb"
  5. # Return an array of symbols of constants of klass that match value
  6. def const_syms(klass, value)
  7. res = []
  8. klass.constants.each do |c|
  9. cv = klass.const_get(c)
  10. res << c if cv == value
  11. end
  12. return res
  13. end
  14. def signal_syms(value)
  15. return const_syms(Signal, value)
  16. end
  17. def woe_on_connect(client_id)
  18. p "Client #{client_id} connected"
  19. Client.add(client_id)
  20. end
  21. def woe_on_disconnect(client_id)
  22. p "Client #{client_id} disconnected"
  23. Client.remove(client_id)
  24. end
  25. def woe_on_input(client_id, buf)
  26. p "Client #{client_id} input #{buf}"
  27. client = Client.get(client_id)
  28. unless client
  29. log "Unknown client #{client_id} in woe_on_input."
  30. Woe::Server.disconnect(client_id)
  31. else
  32. p "Client #{client} #{client.id} ok."
  33. client.on_input(buf)
  34. end
  35. end
  36. def woe_on_negotiate(client_id, how, option)
  37. p "Client #{client_id} negotiating."
  38. end
  39. def woe_on_subnegotiate(client_id, option, buffer)
  40. p "Client #{client_id} subnegotiating."
  41. end
  42. def woe_on_iac(client_id, option, command)
  43. p "Client #{client_id} iac #{command}."
  44. end
  45. def woe_on_ttype(client_id, cmd, name)
  46. p "Client #{client_id} ttype #{cmd} #{name}."
  47. end
  48. def woe_on_error(client_id, code, message)
  49. end
  50. def woe_on_warning(client_id, code, message)
  51. end
  52. def woe_begin_compress(client_id, state)
  53. end
  54. def woe_begin_zmp(client_id, size)
  55. end
  56. def woe_zmp_arg(client_id, index, value)
  57. end
  58. def woe_finish_zmp(client_id, size)
  59. end
  60. def woe_begin_environ(client_id, size)
  61. end
  62. def woe_environ_arg(client_id, index, type, key, value)
  63. end
  64. def woe_finish_environ(client_id, size)
  65. end
  66. def woe_begin_mssp(client_id, size)
  67. end
  68. def woe_mssp_arg(client_id, index, type, key, value)
  69. end
  70. def woe_finish_mssp(client_id, size)
  71. end
  72. def woe_on_signal(signal)
  73. log "Received signal #{signal} #{signal_syms(signal)} in script"
  74. case signal
  75. when 10 # SIGUSR1
  76. log "Reloading main script."
  77. script "main.rb"
  78. when 28
  79. # ignore this signal
  80. else
  81. Woe::Server.quit
  82. end
  83. end