Class: SteamPlayer

Inherits:
Object
  • Object
show all
Defined in:
lib/steam/steam_player.rb

Overview

The SteamPlayer class represents a player connected to a server

Author:

  • Sebastian Staudt

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, score, connect_time) ⇒ SteamPlayer

Creates a new player instance with the given information

Parameters:

  • id (Fixnum)

    The ID of the player on the server

  • name (String)

    The name of the player

  • score (Fixnum)

    The score of the player

  • connect_time (Float)

    The time the player is connected to the server



79
80
81
82
83
84
85
# File 'lib/steam/steam_player.rb', line 79

def initialize(id, name, score, connect_time)
  @connect_time = connect_time
  @id = id
  @name = name
  @score = score
  @extended = false
end

Instance Attribute Details

#client_portFixnum (readonly)

Returns the client port of this player

Returns:

  • (Fixnum)

    The client port of the player



16
17
18
# File 'lib/steam/steam_player.rb', line 16

def client_port
  @client_port
end

#connect_timeFloat (readonly)

Returns the time this player is connected to the server

Returns:

  • (Float)

    The connection time of the player



21
22
23
# File 'lib/steam/steam_player.rb', line 21

def connect_time
  @connect_time
end

#idFixnum (readonly)

Returns the ID of this player

Returns:

  • (Fixnum)

    The ID of this player



26
27
28
# File 'lib/steam/steam_player.rb', line 26

def id
  @id
end

#ip_addressString (readonly)

Returns the IP address of this player

Returns:

  • (String)

    The IP address of this player



31
32
33
# File 'lib/steam/steam_player.rb', line 31

def ip_address
  @ip_address
end

#lossString (readonly)

Returns the packet loss of this player’s connection

Returns:

  • (String)

    The packet loss of this player’s connection



41
42
43
# File 'lib/steam/steam_player.rb', line 41

def loss
  @loss
end

#nameString (readonly)

Returns the nickname of this player

Returns:

  • (String)

    The name of this player



36
37
38
# File 'lib/steam/steam_player.rb', line 36

def name
  @name
end

#pingFixnum (readonly)

Returns the ping of this player

Returns:

  • (Fixnum)

    The ping of this player



46
47
48
# File 'lib/steam/steam_player.rb', line 46

def ping
  @ping
end

#rateFixnum (readonly)

Returns the rate of this player

Returns:

  • (Fixnum)

    The rate of this player



51
52
53
# File 'lib/steam/steam_player.rb', line 51

def rate
  @rate
end

#real_idFixnum (readonly)

Returns the real ID (as used on the server) of this player

Returns:

  • (Fixnum)

    The real ID of this player



56
57
58
# File 'lib/steam/steam_player.rb', line 56

def real_id
  @real_id
end

#scoreFixnum (readonly)

Returns the score of this player

Returns:

  • (Fixnum)

    The score of this player



61
62
63
# File 'lib/steam/steam_player.rb', line 61

def score
  @score
end

#stateString (readonly)

Returns the connection state of this player

Returns:

  • (String)

    The connection state of this player



66
67
68
# File 'lib/steam/steam_player.rb', line 66

def state
  @state
end

#steam_idString (readonly)

Returns the SteamID of this player

Returns:

  • (String)

    The SteamID of this player



71
72
73
# File 'lib/steam/steam_player.rb', line 71

def steam_id
  @steam_id
end

Instance Method Details

#add_info(player_data) ⇒ Object

Extends a player object with information retrieved from a RCON call to the status command

Parameters:

  • player_data (String)

    The player data retrieved from ‘rcon status`

Raises:



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/steam/steam_player.rb', line 93

def add_info(player_data)
  unless player_data[:name] == @name
    raise SteamCondenserError, 'Information to add belongs to a different player.'
  end

  @extended = true

  @real_id  = player_data[:userid].to_i
  @steam_id = player_data[:uniqueid]
  @state    = player_data[:state] if player_data.key? :state

  if !bot?
    @loss = player_data[:loss].to_i
    @ping = player_data[:ping].to_i

    if player_data.key? :adr
      @ip_address, @client_port  = player_data[:adr].split(':')
      @client_port = @client_port.to_i
    end

    @rate  = player_data[:rate].to_i if player_data.key? :rate
  end
end

#bot?Boolean

Returns whether this player is a bot

Returns:

  • (Boolean)

    bool ‘true` if this player is a bot



120
121
122
# File 'lib/steam/steam_player.rb', line 120

def bot?
  @steam_id == 'BOT'
end

#extended?Boolean

Returns whether this player object has extended information gathered using RCON

Returns:

  • (Boolean)

    bool ‘true` if extended information for this player is available



128
129
130
# File 'lib/steam/steam_player.rb', line 128

def extended?
  @extended
end

#to_sString

Returns a string representation of this player

Returns:

  • (String)

    A string representing this player



135
136
137
138
139
140
141
# File 'lib/steam/steam_player.rb', line 135

def to_s
  if @extended
    "\##@real_id \"#@name\", SteamID: #@steam_id, Score: #@score, Time: #@connect_time"
  else
    "\##@id \"#@name\", Score: #@score, Time: #@connect_time"
  end
end