main.rb 3.7 KB

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