Let the server resolve the map path
This commit is contained in:
parent
aa5b755204
commit
7e45bbe038
|
@ -3,11 +3,12 @@
|
||||||
class Config
|
class Config
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
filepath = options[:file] || 'autoexec.cfg'
|
filepath = options[:file] || 'autoexec.cfg'
|
||||||
|
@type = options[:type] || :client
|
||||||
init_configs
|
init_configs
|
||||||
load_cfg(filepath)
|
load_cfg(filepath)
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_configs
|
def init_client_configs
|
||||||
@configs = {
|
@configs = {
|
||||||
password: { help: 'Password to the server', default: '' }
|
password: { help: 'Password to the server', default: '' }
|
||||||
}
|
}
|
||||||
|
@ -15,6 +16,23 @@ class Config
|
||||||
echo: { help: 'Echo the text', callback: proc { |arg| puts arg } },
|
echo: { help: 'Echo the text', callback: proc { |arg| puts arg } },
|
||||||
quit: { help: 'Quit', callback: proc { |_| exit } }
|
quit: { help: 'Quit', callback: proc { |_| exit } }
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def init_server_configs
|
||||||
|
@configs = {
|
||||||
|
sv_map: { help: 'map', default: 'dm1' }
|
||||||
|
}
|
||||||
|
@commands = {
|
||||||
|
shutdown: { help: 'shutdown server', callback: proc { |_| exit } }
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def init_configs
|
||||||
|
if @type == :client
|
||||||
|
init_client_configs
|
||||||
|
else
|
||||||
|
init_server_configs
|
||||||
|
end
|
||||||
@configs.each do |cfg, data|
|
@configs.each do |cfg, data|
|
||||||
self.class.send(:attr_accessor, cfg)
|
self.class.send(:attr_accessor, cfg)
|
||||||
instance_variable_set("@#{cfg}", data[:default])
|
instance_variable_set("@#{cfg}", data[:default])
|
||||||
|
|
|
@ -18,6 +18,8 @@ class GameServer
|
||||||
|
|
||||||
def initialize(server)
|
def initialize(server)
|
||||||
@server = server
|
@server = server
|
||||||
|
@config = server.config
|
||||||
|
@map_path = nil
|
||||||
@ack_game_tick = -1
|
@ack_game_tick = -1
|
||||||
@pred_game_tick = 0
|
@pred_game_tick = 0
|
||||||
@map = Map.new(
|
@map = Map.new(
|
||||||
|
@ -28,6 +30,29 @@ class GameServer
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_map
|
||||||
|
puts "loading map '#{@config.sv_map}' ..."
|
||||||
|
map_path = nil
|
||||||
|
if File.exist? "data/#{@config.sv_map}.map"
|
||||||
|
map_path = "data/#{@config.sv_map}.map"
|
||||||
|
elsif File.exist? "data/maps/#{@config.sv_map}.map"
|
||||||
|
map_path = "data/maps/#{@config.sv_map}.map"
|
||||||
|
elsif File.exist? "maps/#{@config.sv_map}.map"
|
||||||
|
map_path = "maps/#{@config.sv_map}.map"
|
||||||
|
elsif File.exist? "#{Dir.home}/.teeworlds/maps/#{@config.sv_map}.map"
|
||||||
|
map_path = "#{Dir.home}/.teeworlds/maps/#{@config.sv_map}.map"
|
||||||
|
end
|
||||||
|
|
||||||
|
if map_path.nil?
|
||||||
|
puts "map not found '#{@config.sv_map}'"
|
||||||
|
# TODO: this should error when the feature is done
|
||||||
|
# exit 1
|
||||||
|
else
|
||||||
|
puts "found at #{map_path}"
|
||||||
|
@map_path = map_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# call_hook
|
# call_hook
|
||||||
#
|
#
|
||||||
|
|
|
@ -11,6 +11,7 @@ require_relative 'chunk'
|
||||||
require_relative 'net_base'
|
require_relative 'net_base'
|
||||||
require_relative 'models/net_addr'
|
require_relative 'models/net_addr'
|
||||||
require_relative 'packer'
|
require_relative 'packer'
|
||||||
|
require_relative 'config'
|
||||||
require_relative 'game_server'
|
require_relative 'game_server'
|
||||||
require_relative 'models/token'
|
require_relative 'models/token'
|
||||||
require_relative 'messages/sv_emoticon'
|
require_relative 'messages/sv_emoticon'
|
||||||
|
@ -65,14 +66,16 @@ class Client
|
||||||
end
|
end
|
||||||
|
|
||||||
class TeeworldsServer
|
class TeeworldsServer
|
||||||
attr_accessor :clients
|
attr_accessor :clients, :config
|
||||||
attr_reader :hooks, :shutdown_reason, :current_game_tick
|
attr_reader :hooks, :shutdown_reason, :current_game_tick
|
||||||
|
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@verbose = options[:verbose] || false
|
@verbose = options[:verbose] || false
|
||||||
@ip = '127.0.0.1'
|
@ip = '127.0.0.1'
|
||||||
@port = 8303
|
@port = 8303
|
||||||
|
@config = Config.new(file: options[:config], type: :server)
|
||||||
@game_server = GameServer.new(self)
|
@game_server = GameServer.new(self)
|
||||||
|
@game_server.load_map
|
||||||
# @type clients [Hash<Integer, Client>]
|
# @type clients [Hash<Integer, Client>]
|
||||||
@clients = {}
|
@clients = {}
|
||||||
@current_game_tick = 0
|
@current_game_tick = 0
|
||||||
|
|
Loading…
Reference in a new issue