class Rsrb::Server

Attributes

settings[R]

Public Instance Methods

bind() click to toggle source

Binds the server socket and begins accepting player connections.

# File lib/rsrb/server.rb, line 67
def bind
  EventMachine.run do
    Signal.trap('INT') do
      WORLD.players.each { |p| WORLD.unregister(p) }
      EventMachine.stop if EventMachine.reactor_running?
      exit
    end

    Signal.trap('TERM') { EventMachine.stop; }

    if @settings[:jaggrab]
      log 'Launching JAGGRAB server.'
      EventMachine.start_server(@settings[:jaggrab_address], @settings[:jaggrab_port], Rsrb::Net::JaggrabConnection)
      log "JAGGRAB server listening and bound to #{@settings[:jaggrab_address]}@#{@settings[:jaggrab_port]}"
    end

    EventMachine.start_server(@settings[:server_address], @settings[:server_port], Rsrb::Net::Connection)
    log "Server listening and bound to #{@settings[:server_address]}@#{@settings[:server_port]}"
  end
end
load_hooks() click to toggle source

Load hooks

# File lib/rsrb/server.rb, line 26
def load_hooks
  Dir['plugins/*.rb'].each do |file|
    load file
    log! "Loaded #{file}" if @settings[:debug]
  end
end
load_int_hooks() click to toggle source
# File lib/rsrb/server.rb, line 33
def load_int_hooks
  Dir['plugins/internal/*.rb'].each do |file|
    load file
    log! "Loaded #{file}" if @settings[:debug]
  end
end
load_settings() click to toggle source

Load settings for the server.

# File lib/rsrb/server.rb, line 42
def load_settings
  Dotenv.load('assets/config/.server.env')
  @settings = { server_address: ENV['SERVER_ADDRESS'],
                server_port: ENV['SERVER_PORT'].to_i,
                jaggrab: ENV['JAGGRAB'].to_i.positive?,
                jaggrab_address: ENV['JAGGRAB_ADDRESS'],
                jaggrab_port: ENV['JAGGRAB_PORT'].to_i,
                update_mode: ENV['UPDATE_MODE'].to_i.positive?,
                max_players: ENV['MAX_PLAYERS'].to_i,
                protocol: ENV['PROTOCOL'].to_i,
                debug: ENV['SERVER_DEBUG'].to_i.positive? }.freeze
end
reload() click to toggle source
# File lib/rsrb/server.rb, line 16
def reload
  log! 'Reloading hooks!' if @settings[:debug]
  HOOKS.clear
  load_hooks
  load_int_hooks
  Rsrb::Net.load_packets
  log 'Reloaded hooks.'
end
start() click to toggle source
# File lib/rsrb/server.rb, line 7
def start
  # init_cache
  init_loggers
  load_settings
  load_int_hooks
  load_hooks
  bind
end