main.rb 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. script "log.rb"
  2. log "Main mruby script loaded OK."
  3. p Signal.constants
  4. script "motd.rb"
  5. script "sitef.rb"
  6. script "account.rb"
  7. script "security.rb"
  8. script "mode.rb"
  9. script "mode/setup.rb"
  10. script "mode/login.rb"
  11. script "mode/normal.rb"
  12. script "mode/character.rb"
  13. script "client.rb"
  14. script "timer.rb"
  15. # Return an array of symbols of constants of klass that match value
  16. def const_syms(klass, value)
  17. res = []
  18. klass.constants.each do |c|
  19. cv = klass.const_get(c)
  20. res << c if cv == value
  21. end
  22. return res
  23. end
  24. def signal_syms(value)
  25. return const_syms(Signal, value)
  26. end
  27. def woe_on_healing_tick
  28. # p "healing"
  29. end
  30. def woe_on_motion_tick
  31. # p "motion"
  32. end
  33. def woe_on_battle_tick
  34. # p "battle"
  35. end
  36. def woe_on_weather_tick
  37. # p "weather"
  38. end
  39. def woe_on_save_tick
  40. # p "weather"
  41. end
  42. def start_timers
  43. @started_timers ||= false
  44. if @started_timers
  45. log "Timers already started."
  46. else
  47. log "Staring timer(s)..."
  48. Timer.add("healing" , 30.0 , 30.0) { woe_on_healing_tick }
  49. Timer.add("motion" , 5.0 , 5.0) { woe_on_motion_tick }
  50. Timer.add("battle" , 1.0 , 1.0) { woe_on_battle_tick }
  51. Timer.add("weather" , 90.0 , 90.0) { woe_on_weather_tick }
  52. Timer.add("save" , 15 * 60.0 , 15 * 60.0) { woe_on_save_tick }
  53. #@timer_id = Woe::Server.new_timer()
  54. #Woe::Server.set_timer(@timer_id, 1.0, 1.0);
  55. end
  56. @started_timers = true
  57. end
  58. def woe_on_connect(client_id)
  59. p "Client #{client_id} connected"
  60. client = Client.add(client_id)
  61. client.on_start
  62. end
  63. def woe_on_disconnect(client_id)
  64. p "Client #{client_id} disconnected"
  65. Client.remove(client_id)
  66. end
  67. def woe_forward_to_client(client_id, method, *args)
  68. client = Client.get(client_id)
  69. if client
  70. p "Client #{client} #{client.id} ok."
  71. if client.respond_to?(method)
  72. client.send(method, *args)
  73. else
  74. log "Client cannot handle #{method}."
  75. end
  76. else
  77. log "Unknown client #{client_id} for #{method}."
  78. Woe::Server.disconnect(client_id)
  79. end
  80. end
  81. def woe_on_input(client_id, buf)
  82. woe_forward_to_client(client_id, :on_input, buf)
  83. end
  84. def woe_on_negotiate(client_id, how, option)
  85. woe_forward_to_client(client_id, :on_negotiate, how, option)
  86. end
  87. def woe_on_subnegotiate(client_id, option, buffer)
  88. woe_forward_to_client(client_id, :on_subnegotiate, option, buffer)
  89. end
  90. def woe_on_iac(client_id, option, command)
  91. woe_forward_to_client(client_id, :on_iac, option, command)
  92. end
  93. def woe_on_ttype(client_id, cmd, name)
  94. woe_forward_to_client(client_id, :on_ttype, cmd, name)
  95. end
  96. def woe_on_error(client_id, code, message)
  97. woe_forward_to_client(client_id, :on_error, code, message)
  98. end
  99. def woe_on_warning(client_id, code, message)
  100. woe_forward_to_client(client_id, :on_warning, code, message)
  101. end
  102. def woe_begin_compress(client_id, state)
  103. woe_forward_to_client(client_id, :on_compress, state)
  104. end
  105. def woe_begin_zmp(client_id, size)
  106. woe_forward_to_client(client_id, :on_begin_zmp, size)
  107. end
  108. def woe_zmp_arg(client_id, index, value)
  109. woe_forward_to_client(client_id, :on_zmp_arg, index, value)
  110. end
  111. def woe_finish_zmp(client_id, size)
  112. woe_forward_to_client(client_id, :on_finish_zmp, size)
  113. end
  114. def woe_begin_environ(client_id, size)
  115. woe_forward_to_client(client_id, :on_begin_environ, size)
  116. end
  117. def woe_environ_arg(client_id, index, type, key, value)
  118. woe_forward_to_client(client_id, :on_environ_arg, index, type, key, value)
  119. end
  120. def woe_finish_environ(client_id, size)
  121. woe_forward_to_client(client_id, :on_finish_environ, size)
  122. end
  123. def woe_begin_mssp(client_id, size)
  124. woe_forward_to_client(client_id, :on_begin_mssp, size)
  125. end
  126. def woe_mssp_arg(client_id, index, type, key, value)
  127. woe_forward_to_client(client_id, :on_mssp_arg, index, type, key, value)
  128. end
  129. def woe_finish_mssp(client_id, size)
  130. woe_forward_to_client(client_id, :on_finish_mssp, size)
  131. end
  132. def woe_on_signal(signal)
  133. log "Received signal #{signal} #{signal_syms(signal)} in script"
  134. case signal
  135. when 10 # SIGUSR1
  136. log "Reloading main script."
  137. script "main.rb"
  138. when 28 # SIGWINCH
  139. # ignore this signal
  140. else
  141. Woe::Server.quit
  142. end
  143. end
  144. def woe_on_timer(timer, value, interval)
  145. # log "Timer #{timer} #{value} #{interval} passed."
  146. Timer.on_timer(timer)
  147. end
  148. start_timers
  149. =begin
  150. f = File.open("/account/B/Beoran/Beoran.account", "r");
  151. if f
  152. while (!f.eof?)
  153. lin = f.gets(255)
  154. log "Read line #{lin}"
  155. end
  156. f.close
  157. end
  158. Dir.mkdir("/account/C")
  159. Dir.mkdir("/account/C/Celia")
  160. f = File.open("/account/C/Celia/Celia.account", "w");
  161. if f
  162. f.puts("name=Celia\n")
  163. f.puts("algo=plain\n")
  164. f.puts("pass=hello1woe\n")
  165. f.close
  166. end
  167. f = File.open("/account/C/Celia/Celia.account", "r");
  168. if f
  169. while (!f.eof?)
  170. lin = f.gets(255)
  171. log "Read line #{lin}"
  172. end
  173. f.close
  174. end
  175. =end
  176. =begin
  177. a = Account.new(:id => 'Dyon', :pass => 'DN33Fbe/OGrM6',
  178. :algo => 'crypt'
  179. )
  180. p a.id
  181. a.save
  182. d = Account.serdes_fetch('Dyon')
  183. p d
  184. Account.serdes_forget('Dyon')
  185. d = Account.serdes_fetch('Dyon')
  186. p d
  187. =end
  188. p crypt("noyd8pass")