Class: ServerInfo
- Inherits:
-
Object
- Object
- ServerInfo
- Defined in:
- lib/messages/server_info.rb
Instance Attribute Summary collapse
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#gametype ⇒ Object
Returns the value of attribute gametype.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#map ⇒ Object
Returns the value of attribute map.
-
#max_clients ⇒ Object
Returns the value of attribute max_clients.
-
#max_players ⇒ Object
Returns the value of attribute max_players.
-
#name ⇒ Object
Returns the value of attribute name.
-
#num_clients ⇒ Object
Returns the value of attribute num_clients.
-
#num_players ⇒ Object
Returns the value of attribute num_players.
-
#players ⇒ Object
Returns the value of attribute players.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize ⇒ ServerInfo
constructor
A new instance of ServerInfo.
-
#to_a ⇒ Object
basically to_network int array the server sends to the client.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ ServerInfo
Returns a new instance of ServerInfo.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/messages/server_info.rb', line 11 def initialize # short tokenless version @version = GAME_VERSION # '0.7.5' @name = 'unnamed ruby server' @hostname = 'localhost' @map = 'dm1' @gametype = 'dm' @flags = 0 @num_players = 1 @max_players = MAX_PLAYERS @num_clients = 1 @max_clients = MAX_CLIENTS # token only @players = [ Player.new( id: 0, local: 0, team: 0, name: 'sample player', clan: '', country: -1 ) ] end |
Instance Attribute Details
#flags ⇒ Object
Returns the value of attribute flags.
8 9 10 |
# File 'lib/messages/server_info.rb', line 8 def flags @flags end |
#gametype ⇒ Object
Returns the value of attribute gametype.
8 9 10 |
# File 'lib/messages/server_info.rb', line 8 def gametype @gametype end |
#hostname ⇒ Object
Returns the value of attribute hostname.
8 9 10 |
# File 'lib/messages/server_info.rb', line 8 def hostname @hostname end |
#map ⇒ Object
Returns the value of attribute map.
8 9 10 |
# File 'lib/messages/server_info.rb', line 8 def map @map end |
#max_clients ⇒ Object
Returns the value of attribute max_clients.
8 9 10 |
# File 'lib/messages/server_info.rb', line 8 def max_clients @max_clients end |
#max_players ⇒ Object
Returns the value of attribute max_players.
8 9 10 |
# File 'lib/messages/server_info.rb', line 8 def max_players @max_players end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/messages/server_info.rb', line 8 def name @name end |
#num_clients ⇒ Object
Returns the value of attribute num_clients.
8 9 10 |
# File 'lib/messages/server_info.rb', line 8 def num_clients @num_clients end |
#num_players ⇒ Object
Returns the value of attribute num_players.
8 9 10 |
# File 'lib/messages/server_info.rb', line 8 def num_players @num_players end |
#players ⇒ Object
Returns the value of attribute players.
8 9 10 |
# File 'lib/messages/server_info.rb', line 8 def players @players end |
#version ⇒ Object
Returns the value of attribute version.
8 9 10 |
# File 'lib/messages/server_info.rb', line 8 def version @version end |
Instance Method Details
#to_a ⇒ Object
basically to_network int array the server sends to the client
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/messages/server_info.rb', line 43 def to_a data = [] data = Packer.pack_str(@version) + Packer.pack_str(@name) + Packer.pack_str(@hostname) + Packer.pack_str(@map) + Packer.pack_str(@gametype) + Packer.pack_int(@flags) + Packer.pack_int(@num_players) + Packer.pack_int(@max_players) + Packer.pack_int(@num_clients) + Packer.pack_int(@max_clients) @players.each do |player| data += Packer.pack_str(player.name) data += Packer.pack_str(player.clan) data += Packer.pack_int(player.country) data += Packer.pack_int(player.score) data += Packer.pack_int(0) # TODO: bot and spec flag end data end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/messages/server_info.rb', line 37 def to_s "version=#{@version} gametype=#{gametype} map=#{map} name=#{name}" end |