class Rsrb::Tasks::SystemUpdateEvent

Attributes

seconds[R]
state[R]

Public Class Methods

new(seconds) click to toggle source
Calls superclass method Rsrb::Engine::Event::new
# File lib/rsrb/tasks/sysupdate_event.rb, line 6
def initialize(seconds)
  super(0)
  @seconds = seconds
  @state = :wait
end

Public Instance Methods

execute() click to toggle source
# File lib/rsrb/tasks/sysupdate_event.rb, line 12
def execute
  case @state
  when :wait
    wait
  when :kick
    kick
  when :wait_for_saves
    wait_for_saves
  end
end
kick() click to toggle source
# File lib/rsrb/tasks/sysupdate_event.rb, line 32
def kick
  # Disallow logins
  SERVER.updatemode = true

  # Kick all users
  WORLD.players.delete_if {|p|
    WORLD.unregister(p, false)
    true
  }
  
  @state = :wait_for_saves
  @delay = 1000
end
wait() click to toggle source
# File lib/rsrb/tasks/sysupdate_event.rb, line 23
def wait
  @state = :kick
  @delay = @seconds * 1000
  
  WORLD.players.each {|p|
    p.io.send_system_update @seconds
  }
end
wait_for_saves() click to toggle source
# File lib/rsrb/tasks/sysupdate_event.rb, line 46
def wait_for_saves
  log = Logging.logger['sysupdate']

  if WORLD.work_thread.busy
    log.warn "Waiting for profiles to save..."
  else
    log.warn "Shutting down"
    stop
    Kernel.exit!
  end
end