minecraft-server 0.0.1.pre.31 → 0.0.1.pre.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/minecraft/server.rb +24 -7
- data/lib/minecraft/server/config.rb +7 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTM3ZjI4MGY3M2I4NzUwMTBmYTIwODYzZDNjMGMxODgxZGRhZmY2NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWJmNzYyNTAxOTk1YzFmNWY5MWRkYzI2YjVmN2E4N2JmYjY5NzM1Zg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2MxZTY0ZmVkOGYyYWM4ZDlkYTU5NWY1NWEyMmJlZWUyODgzZTZmZDRiNWY3
|
10
|
+
MWNlMTBhZDZhZWEwOGY5MDRlODI5NzM2YmNhMmQ1NDEyZWIxNzVjZDllZDI4
|
11
|
+
YTk4ZmNmNzExMTcwY2RiYzU4OGE2OGU5MWE3YmEzZWJlZGQ2MzE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjZlMjcyMmY5OWIwZDczZDU4N2QwMjY2YzNmYTkzNzAyOTdhNjAyYmQ3ZGNi
|
14
|
+
NWNiNTYzMjEwNDA4NDk3ODAwNzRlNjM3MDBiZGZlNWU2Nzg2MTRjMjFlYmNl
|
15
|
+
ODI0MDI2ZjM5MjY3ZTRjNTU5NmFlMWU5YTNjN2QzM2ZhMDgyZWM=
|
data/lib/minecraft/server.rb
CHANGED
@@ -30,6 +30,11 @@ module Minecraft
|
|
30
30
|
# @return [TCPServer] The TCP Server used for network communication
|
31
31
|
attr_reader :server
|
32
32
|
|
33
|
+
# @!attribute clients
|
34
|
+
# Instance variable representing the Array of Clients Currently Connected.
|
35
|
+
# @return [Array] The clients connected
|
36
|
+
attr_reader :clients
|
37
|
+
|
33
38
|
# @!attribute port
|
34
39
|
# Instance variable representing the port used for network communication.
|
35
40
|
# @return [Integer] The port used for network communication
|
@@ -40,6 +45,8 @@ module Minecraft
|
|
40
45
|
# @return [Log4r::Logger]
|
41
46
|
attr_accessor :logger
|
42
47
|
|
48
|
+
attr_reader :max_players
|
49
|
+
|
43
50
|
def initialize(config = {})
|
44
51
|
@logger = Log4r::Logger.new 'Minecraft Server'
|
45
52
|
@logger.outputters << Log4r::Outputter.stdout
|
@@ -89,13 +96,21 @@ module Minecraft
|
|
89
96
|
else
|
90
97
|
@port = 25565
|
91
98
|
end
|
99
|
+
|
100
|
+
if config[:max_players]
|
101
|
+
@max_players = config[:max_players]
|
102
|
+
else
|
103
|
+
@max_players = 20
|
104
|
+
end
|
105
|
+
|
92
106
|
@logger.info "Running on port: #{@port}"
|
93
107
|
end
|
94
108
|
|
95
109
|
# Starts this instance of {Minecraft::Server}
|
96
110
|
def start
|
97
111
|
@server = TCPServer.new(@port)
|
98
|
-
@
|
112
|
+
@clients = Array.new(max_players)
|
113
|
+
@logger.info 'Now Accepting Clients.'
|
99
114
|
accept_clients
|
100
115
|
end
|
101
116
|
|
@@ -103,18 +118,20 @@ module Minecraft
|
|
103
118
|
client_thread = Thread.new do
|
104
119
|
loop do
|
105
120
|
client = @server.accept
|
106
|
-
|
107
|
-
#client.puts "Time is #{Time.now}"
|
121
|
+
clients << client
|
108
122
|
@logger.info "Client connected: #{client}"
|
109
|
-
client.close
|
110
123
|
end
|
111
124
|
end
|
112
125
|
client_thread.join
|
113
126
|
end
|
114
127
|
|
115
|
-
|
116
|
-
|
117
|
-
|
128
|
+
def drop_clients
|
129
|
+
logger.info 'Now Dropping all Recorded Clients'
|
130
|
+
clients.each do |client|
|
131
|
+
client.close
|
132
|
+
clients.delete client
|
133
|
+
logger.info "Client Dropped and Removed from Client Array: #{client}"
|
134
|
+
end
|
118
135
|
end
|
119
136
|
|
120
137
|
end
|
@@ -33,6 +33,11 @@ module Minecraft
|
|
33
33
|
@config[:port] = port
|
34
34
|
end
|
35
35
|
|
36
|
+
def max_players(players = 20)
|
37
|
+
@config[:max_players] = players
|
38
|
+
end
|
39
|
+
alias_method :player_limit, :max_players
|
40
|
+
|
36
41
|
end
|
37
42
|
|
38
43
|
class ConfigFile
|
@@ -46,7 +51,8 @@ module Minecraft
|
|
46
51
|
'',
|
47
52
|
'## Network Settings',
|
48
53
|
'',
|
49
|
-
'port 25565'
|
54
|
+
'port 25565',
|
55
|
+
'max_players 20'
|
50
56
|
]
|
51
57
|
|
52
58
|
def initialize(file)
|