File tree Expand file tree Collapse file tree 3 files changed +48
-2
lines changed Expand file tree Collapse file tree 3 files changed +48
-2
lines changed Original file line number Diff line number Diff line change 3
3
class Config
4
4
def initialize ( options = { } )
5
5
filepath = options [ :file ] || 'autoexec.cfg'
6
+ @type = options [ :type ] || :client
6
7
init_configs
7
8
load_cfg ( filepath )
8
9
end
9
10
10
- def init_configs
11
+ def init_client_configs
11
12
@configs = {
12
13
password : { help : 'Password to the server' , default : '' }
13
14
}
14
15
@commands = {
15
16
echo : { help : 'Echo the text' , callback : proc { |arg | puts arg } } ,
16
17
quit : { help : 'Quit' , callback : proc { |_ | exit } }
17
18
}
19
+ end
20
+
21
+ def init_server_configs
22
+ @configs = {
23
+ sv_map : { help : 'map' , default : 'dm1' }
24
+ }
25
+ @commands = {
26
+ shutdown : { help : 'shutdown server' , callback : proc { |_ | exit } }
27
+ }
28
+ end
29
+
30
+ def init_configs
31
+ if @type == :client
32
+ init_client_configs
33
+ else
34
+ init_server_configs
35
+ end
18
36
@configs . each do |cfg , data |
19
37
self . class . send ( :attr_accessor , cfg )
20
38
instance_variable_set ( "@#{ cfg } " , data [ :default ] )
Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ class GameServer
18
18
19
19
def initialize ( server )
20
20
@server = server
21
+ @config = server . config
22
+ @map_path = nil
21
23
@ack_game_tick = -1
22
24
@pred_game_tick = 0
23
25
@map = Map . new (
@@ -28,6 +30,29 @@ def initialize(server)
28
30
)
29
31
end
30
32
33
+ def load_map
34
+ puts "loading map '#{ @config . sv_map } ' ..."
35
+ map_path = nil
36
+ if File . exist? "data/#{ @config . sv_map } .map"
37
+ map_path = "data/#{ @config . sv_map } .map"
38
+ elsif File . exist? "data/maps/#{ @config . sv_map } .map"
39
+ map_path = "data/maps/#{ @config . sv_map } .map"
40
+ elsif File . exist? "maps/#{ @config . sv_map } .map"
41
+ map_path = "maps/#{ @config . sv_map } .map"
42
+ elsif File . exist? "#{ Dir . home } /.teeworlds/maps/#{ @config . sv_map } .map"
43
+ map_path = "#{ Dir . home } /.teeworlds/maps/#{ @config . sv_map } .map"
44
+ end
45
+
46
+ if map_path . nil?
47
+ puts "map not found '#{ @config . sv_map } '"
48
+ # TODO: this should error when the feature is done
49
+ # exit 1
50
+ else
51
+ puts "found at #{ map_path } "
52
+ @map_path = map_path
53
+ end
54
+ end
55
+
31
56
##
32
57
# call_hook
33
58
#
Original file line number Diff line number Diff line change 11
11
require_relative 'net_base'
12
12
require_relative 'models/net_addr'
13
13
require_relative 'packer'
14
+ require_relative 'config'
14
15
require_relative 'game_server'
15
16
require_relative 'models/token'
16
17
require_relative 'messages/sv_emoticon'
@@ -65,14 +66,16 @@ def seq
65
66
end
66
67
67
68
class TeeworldsServer
68
- attr_accessor :clients
69
+ attr_accessor :clients , :config
69
70
attr_reader :hooks , :shutdown_reason , :current_game_tick
70
71
71
72
def initialize ( options = { } )
72
73
@verbose = options [ :verbose ] || false
73
74
@ip = '127.0.0.1'
74
75
@port = 8303
76
+ @config = Config . new ( file : options [ :config ] , type : :server )
75
77
@game_server = GameServer . new ( self )
78
+ @game_server . load_map
76
79
# @type clients [Hash<Integer, Client>]
77
80
@clients = { }
78
81
@current_game_tick = 0
You can’t perform that action at this time.
0 commit comments