main.rb 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. script "log.rb"
  2. log "Main mruby script loaded OK."
  3. p Signal.constants
  4. script "client.rb"
  5. script "timer.rb"
  6. # Return an array of symbols of constants of klass that match value
  7. def const_syms(klass, value)
  8. res = []
  9. klass.constants.each do |c|
  10. cv = klass.const_get(c)
  11. res << c if cv == value
  12. end
  13. return res
  14. end
  15. def signal_syms(value)
  16. return const_syms(Signal, value)
  17. end
  18. def woe_on_healing_tick
  19. # p "healing"
  20. end
  21. def woe_on_motion_tick
  22. # p "motion"
  23. end
  24. def woe_on_battle_tick
  25. # p "battle"
  26. end
  27. def woe_on_weather_tick
  28. # p "weather"
  29. end
  30. def start_timers
  31. @started_timers ||= false
  32. if @started_timers
  33. log "Timers already started."
  34. else
  35. log "Staring timer(s)..."
  36. Timer.add("healing" , 30.0, 30.0) { woe_on_healing_tick }
  37. Timer.add("motion" , 5.0, 5.0) { woe_on_motion_tick }
  38. Timer.add("battle" , 1.0, 1.0) { woe_on_battle_tick }
  39. Timer.add("weather" , 90.0, 90.0) { woe_on_weather_tick }
  40. #@timer_id = Woe::Server.new_timer()
  41. #Woe::Server.set_timer(@timer_id, 1.0, 1.0);
  42. end
  43. @started_timers = true
  44. end
  45. def woe_on_connect(client_id)
  46. p "Client #{client_id} connected"
  47. Client.add(client_id)
  48. end
  49. def woe_on_disconnect(client_id)
  50. p "Client #{client_id} disconnected"
  51. Client.remove(client_id)
  52. end
  53. def woe_on_input(client_id, buf)
  54. p "Client #{client_id} input #{buf}"
  55. client = Client.get(client_id)
  56. unless client
  57. log "Unknown client #{client_id} in woe_on_input."
  58. Woe::Server.disconnect(client_id)
  59. else
  60. p "Client #{client} #{client.id} ok."
  61. client.on_input(buf)
  62. end
  63. end
  64. def woe_on_negotiate(client_id, how, option)
  65. p "Client #{client_id} negotiating."
  66. end
  67. def woe_on_subnegotiate(client_id, option, buffer)
  68. p "Client #{client_id} subnegotiating."
  69. end
  70. def woe_on_iac(client_id, option, command)
  71. p "Client #{client_id} iac #{command}."
  72. end
  73. def woe_on_ttype(client_id, cmd, name)
  74. p "Client #{client_id} ttype #{cmd} #{name}."
  75. end
  76. def woe_on_error(client_id, code, message)
  77. end
  78. def woe_on_warning(client_id, code, message)
  79. end
  80. def woe_begin_compress(client_id, state)
  81. end
  82. def woe_begin_zmp(client_id, size)
  83. end
  84. def woe_zmp_arg(client_id, index, value)
  85. end
  86. def woe_finish_zmp(client_id, size)
  87. end
  88. def woe_begin_environ(client_id, size)
  89. end
  90. def woe_environ_arg(client_id, index, type, key, value)
  91. end
  92. def woe_finish_environ(client_id, size)
  93. end
  94. def woe_begin_mssp(client_id, size)
  95. end
  96. def woe_mssp_arg(client_id, index, type, key, value)
  97. end
  98. def woe_finish_mssp(client_id, size)
  99. end
  100. def woe_on_signal(signal)
  101. log "Received signal #{signal} #{signal_syms(signal)} in script"
  102. case signal
  103. when 10 # SIGUSR1
  104. log "Reloading main script."
  105. script "main.rb"
  106. when 28
  107. # ignore this signal
  108. else
  109. Woe::Server.quit
  110. end
  111. end
  112. def woe_on_timer(timer, value, interval)
  113. # log "Timer #{timer} #{value} #{interval} passed."
  114. Timer.on_timer(timer)
  115. end
  116. start_timers
  117. f = File.open("/account/B/Beoran/Beoran.account", "r");
  118. if f
  119. while (!f.eof?)
  120. lin = f.gets(255)
  121. log "Read line #{lin}"
  122. end
  123. f.close
  124. end
  125. Dir.mkdir("/account/C")
  126. Dir.mkdir("/account/C/Celia")
  127. f = File.open("/account/C/Celia/Celia.account", "w");
  128. if f
  129. f.puts("name=Celia\n")
  130. f.puts("algo=plain\n")
  131. f.puts("pass=hello1woe\n")
  132. f.close
  133. end
  134. f = File.open("/account/C/Celia/Celia.account", "r");
  135. if f
  136. while (!f.eof?)
  137. lin = f.gets(255)
  138. log "Read line #{lin}"
  139. end
  140. f.close
  141. end