Class: ServerInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/messages/server_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServerInfo

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

#flagsObject

Returns the value of attribute flags.



8
9
10
# File 'lib/messages/server_info.rb', line 8

def flags
  @flags
end

#gametypeObject

Returns the value of attribute gametype.



8
9
10
# File 'lib/messages/server_info.rb', line 8

def gametype
  @gametype
end

#hostnameObject

Returns the value of attribute hostname.



8
9
10
# File 'lib/messages/server_info.rb', line 8

def hostname
  @hostname
end

#mapObject

Returns the value of attribute map.



8
9
10
# File 'lib/messages/server_info.rb', line 8

def map
  @map
end

#max_clientsObject

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_playersObject

Returns the value of attribute max_players.



8
9
10
# File 'lib/messages/server_info.rb', line 8

def max_players
  @max_players
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/messages/server_info.rb', line 8

def name
  @name
end

#num_clientsObject

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_playersObject

Returns the value of attribute num_players.



8
9
10
# File 'lib/messages/server_info.rb', line 8

def num_players
  @num_players
end

#playersObject

Returns the value of attribute players.



8
9
10
# File 'lib/messages/server_info.rb', line 8

def players
  @players
end

#versionObject

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_aObject

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_sObject



37
38
39
# File 'lib/messages/server_info.rb', line 37

def to_s
  "version=#{@version} gametype=#{gametype} map=#{map} name=#{name}"
end