Class: Teeworlds::Server
- Inherits:
-
Object
- Object
- Teeworlds::Server
- Defined in:
- lib/teeworlds/server.rb
Constant Summary collapse
- METHODS =
[:version, :name, :map, :gametype, :flags, :num_players, :max_players, :num_clients, :max_clients]
Instance Attribute Summary collapse
-
#players ⇒ Object
readonly
Returns the value of attribute players.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(arg) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(arg) ⇒ Server
Returns a new instance of Server.
6 7 8 9 10 |
# File 'lib/teeworlds/server.rb', line 6 def initialize(arg) @server = arg[:server] @port = arg[:port] || 8303 @players = [] end |
Instance Attribute Details
#players ⇒ Object (readonly)
Returns the value of attribute players.
4 5 6 |
# File 'lib/teeworlds/server.rb', line 4 def players @players end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
4 5 6 |
# File 'lib/teeworlds/server.rb', line 4 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
4 5 6 |
# File 'lib/teeworlds/server.rb', line 4 def server @server end |
Instance Method Details
#connect ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/teeworlds/server.rb', line 12 def connect Timeout.timeout(1) do udp = UDPSocket.new udp.connect(@server, @port) udp.send("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x67\x69\x65\x33\x00", 0) create_methods udp.recvfrom(1024).first.split("\x00")[1..-1] end end |