steam-condenser 0.13.1 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/lib/exceptions/packet_format_exception.rb +12 -5
  2. data/lib/exceptions/rcon_ban_exception.rb +11 -3
  3. data/lib/exceptions/rcon_no_auth_exception.rb +10 -3
  4. data/lib/exceptions/steam_condenser_exception.rb +8 -5
  5. data/lib/exceptions/timeout_exception.rb +13 -3
  6. data/lib/exceptions/web_api_exception.rb +31 -23
  7. data/lib/steam-condenser.rb +9 -3
  8. data/lib/steam-condenser/community.rb +8 -1
  9. data/lib/steam-condenser/servers.rb +7 -1
  10. data/lib/steam-condenser/version.rb +2 -1
  11. data/lib/steam/community/cacheable.rb +4 -4
  12. data/lib/steam/community/game_inventory.rb +119 -0
  13. data/lib/steam/community/game_item.rb +38 -0
  14. data/lib/steam/community/game_stats.rb +10 -4
  15. data/lib/steam/community/portal2/portal2_inventory.rb +21 -0
  16. data/lib/steam/community/portal2/portal2_item.rb +35 -0
  17. data/lib/steam/community/portal2/portal2_stats.rb +28 -0
  18. data/lib/steam/community/tf2/tf2_inventory.rb +7 -37
  19. data/lib/steam/community/tf2/tf2_item.rb +8 -79
  20. data/lib/steam/community/tf2/tf2_stats.rb +10 -13
  21. data/lib/steam/community/web_api.rb +1 -0
  22. data/lib/steam/packets/a2m_get_servers_batch2_packet.rb +37 -4
  23. data/lib/steam/packets/a2s_info_packet.rb +10 -5
  24. data/lib/steam/packets/a2s_player_packet.rb +16 -6
  25. data/lib/steam/packets/a2s_rules_packet.rb +16 -4
  26. data/lib/steam/packets/a2s_serverquery_getchallenge_packet.rb +11 -5
  27. data/lib/steam/packets/c2m_checkmd5_packet.rb +10 -4
  28. data/lib/steam/packets/m2a_server_batch_packet.rb +19 -3
  29. data/lib/steam/packets/m2c_isvalidmd5_packet.rb +14 -5
  30. data/lib/steam/packets/m2s_requestrestart_packet.rb +14 -4
  31. data/lib/steam/packets/rcon/rcon_auth_request.rb +15 -3
  32. data/lib/steam/packets/rcon/rcon_auth_response.rb +17 -3
  33. data/lib/steam/packets/rcon/rcon_exec_request.rb +15 -3
  34. data/lib/steam/packets/rcon/rcon_exec_response.rb +20 -3
  35. data/lib/steam/packets/rcon/rcon_goldsrc_request.rb +18 -3
  36. data/lib/steam/packets/rcon/rcon_goldsrc_response.rb +17 -3
  37. data/lib/steam/packets/rcon/rcon_packet.rb +31 -3
  38. data/lib/steam/packets/rcon/rcon_packet_factory.rb +15 -5
  39. data/lib/steam/packets/rcon/rcon_terminator.rb +14 -5
  40. data/lib/steam/packets/request_with_challenge.rb +10 -5
  41. data/lib/steam/packets/s2a_info2_packet.rb +14 -5
  42. data/lib/steam/packets/s2a_info_base_packet.rb +16 -6
  43. data/lib/steam/packets/s2a_info_detailed_packet.rb +15 -8
  44. data/lib/steam/packets/s2a_logstring_packet.rb +11 -5
  45. data/lib/steam/packets/s2a_player_packet.rb +14 -6
  46. data/lib/steam/packets/s2a_rules_packet.rb +15 -5
  47. data/lib/steam/packets/s2c_challenge_packet.rb +17 -6
  48. data/lib/steam/packets/s2m_heartbeat2_packet.rb +18 -4
  49. data/lib/steam/packets/steam_packet.rb +14 -5
  50. data/lib/steam/packets/steam_packet_factory.rb +25 -2
  51. data/lib/steam/servers/game_server.rb +154 -25
  52. data/lib/steam/servers/goldsrc_server.rb +35 -3
  53. data/lib/steam/servers/master_server.rb +77 -23
  54. data/lib/steam/servers/server.rb +42 -3
  55. data/lib/steam/servers/source_server.rb +35 -11
  56. data/lib/stringio_additions.rb +48 -3
  57. data/test/query_tests.rb +4 -4
  58. metadata +11 -6
@@ -1,12 +1,18 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2008-2010, Sebastian Staudt
4
+ # Copyright (c) 2008-2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/packets/steam_packet'
7
7
 
8
- # The A2S_SERVERQUERY_GETCHALLENGE_Packet class represents a
9
- # A2S_SERVERQUERY_GETCHALLENGE request send to the server.
8
+ # This packet class represents a A2S_SERVERQUERY_GETCHALLENGE request send to
9
+ # a game server
10
+ #
11
+ # It is used to retrieve a challenge number from the game server, which helps
12
+ # to identify the requesting client.
13
+ #
14
+ # @author Sebastian Staudt
15
+ # @see GameServer#update_challenge_number
10
16
  class A2S_SERVERQUERY_GETCHALLENGE_Packet
11
17
 
12
18
  include SteamPacket
@@ -5,18 +5,24 @@
5
5
 
6
6
  require 'steam/packets/steam_packet'
7
7
 
8
- # The C2M_CHECKMD5 packet type is used to initialize (challenge) master server
9
- # communication.
8
+ # This packet class represents a C2M_CHECKMD5 request sent to a master server
9
+ #
10
+ # It is used to initialize (challenge) master server communication.
11
+ #
12
+ # @author Sebastian Staudt
13
+ # @see MasterServer#challenge
10
14
  class C2M_CHECKMD5_Packet
11
15
 
12
16
  include SteamPacket
13
17
 
14
- # Creates a new challenge request packet for master server communication
18
+ # Creates a new C2M_CHECKMD5 request object
15
19
  def initialize
16
20
  super C2M_CHECKMD5_HEADER
17
21
  end
18
22
 
19
- # Returns a byte array representation of the packet data
23
+ # Returns the raw data representing this packet
24
+ #
25
+ # @return string A string containing the raw data of this request packet
20
26
  def to_s
21
27
  [@header_data, 0xFF].pack('c2')
22
28
  end
@@ -1,16 +1,32 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2008-2010, Sebastian Staudt
4
+ # Copyright (c) 2008-2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/packets/steam_packet'
7
7
 
8
+ # This packet class represents a M2A_SERVER_BATCH response replied by a master
9
+ # server
10
+ #
11
+ # It contains a list of IP addresses and ports of game servers matching the
12
+ # requested criteria.
13
+ #
14
+ # @author Sebastian Staudt
15
+ # @see MasterServer#servers
8
16
  class M2A_SERVER_BATCH_Packet
9
17
 
10
18
  include SteamPacket
11
19
 
20
+ # Returns the list of servers returned from the server in this packet
21
+ #
22
+ # @return [Array<String>] An array of server addresses (i.e. IP addresses +
23
+ # port numbers)
12
24
  attr_reader :servers
13
25
 
26
+ # Creates a new M2A_SERVER_BATCH response object based on the given data
27
+ #
28
+ # @param [String] data The raw packet data replied from the server
29
+ # @raises PacketFormatException if the packet data is not well formatted
14
30
  def initialize(data)
15
31
  super M2A_SERVER_BATCH_HEADER, data
16
32
 
@@ -1,20 +1,29 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
4
  # Copyright (c) 2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/packets/steam_packet'
7
7
 
8
- # A packet of type M2S_ISVALIDMD5 is used by the master server to provide a
9
- # challenge number to a game server
8
+ # This packet class represents a M2S_ISVALIDMD5 response replied by a master
9
+ # server
10
+ #
11
+ # It is used to provide a challenge number to a game server
12
+ #
13
+ # @author Sebastian Staudt
14
+ # @see MasterServer#challenge
10
15
  class M2C_ISVALIDMD5_Packet
11
16
 
12
17
  include SteamPacket
13
18
 
14
19
  # Returns the challenge number to use for master server communication
20
+ #
21
+ # @return [Fixnum] The challenge number
15
22
  attr_reader :challenge
16
23
 
17
- # Creates a new response packet with the data from the master server
24
+ # Creates a new M2S_ISVALIDMD5 response object based on the given data
25
+ #
26
+ # @param [String] data The raw packet data replied from the server
18
27
  def initialize(data)
19
28
  super M2C_ISVALIDMD5_HEADER, data
20
29
 
@@ -5,18 +5,28 @@
5
5
 
6
6
  require 'steam/packets/steam_packet'
7
7
 
8
- # The M2S_REQUESTRESTART packet type is used to by master servers to request a
9
- # game server restart, e.g. when using outdated versions.
8
+ # This packet class represent a M2S_REQUESTRESTART response replied from a
9
+ # master server
10
+ #
11
+ # It is used to request a game server restart, e.g. when the server is
12
+ # outdated.
13
+ #
14
+ # @author Sebastian Staudt
15
+ # @see MasterServer#sendHeartbeat
10
16
  class M2S_REQUESTRESTART_Packet
11
17
 
12
18
  include SteamPacket
13
19
 
14
20
  # Returns the challenge number used for master server communication
21
+ #
22
+ # @return [Fixnum] The challenge number
15
23
  attr_reader :challenge
16
24
 
17
- # Creates a new server restart request packet sent by a master server
25
+ # Creates a new M2S_REQUESTRESTART response object based on the given data
26
+ #
27
+ # @param [String] data The raw packet data replied from the server
18
28
  def initialize(data)
19
- super C2M_CHECKMD5_HEADER, data
29
+ super M2S_REQUESTRESTART_HEADER, data
20
30
 
21
31
  @challenge = @content_data.long
22
32
  end
@@ -1,14 +1,26 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2008-2010, Sebastian Staudt
4
+ # Copyright (c) 2008-2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/packets/rcon/rcon_packet'
7
7
 
8
+ # This packet class represents a SERVERDATA_AUTH request sent to a Source
9
+ # server
10
+ #
11
+ # It is used to authenticate the client for RCON communication.
12
+ #
13
+ # @author Sebastian Staudt
14
+ # @see SourceServer#rcon_auth
8
15
  class RCONAuthRequest
9
16
 
10
17
  include RCONPacket
11
18
 
19
+ # Creates a RCON authentication request for the given request ID and RCON
20
+ # password
21
+ #
22
+ # @param [Fixnum] request_id The request ID of the RCON connection
23
+ # @param [String] rcon_password The RCON password of the server
12
24
  def initialize(request_id, rcon_password)
13
25
  super request_id, SERVERDATA_AUTH, rcon_password
14
26
  end
@@ -1,14 +1,28 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2008-2010, Sebastian Staudt
4
+ # Copyright (c) 2008-2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/packets/rcon/rcon_packet'
7
7
 
8
+ # This packet class represents a SERVERDATA_AUTH_RESPONSE packet sent by a
9
+ # Source server
10
+ #
11
+ # It is used to indicate the success or failure of an authentication attempt
12
+ # of a client for RCON communication.
13
+ #
14
+ # @author Sebastian Staudt
15
+ # @see SourceServer#rcon_auth
8
16
  class RCONAuthResponse
9
17
 
10
18
  include RCONPacket
11
19
 
20
+ # Creates a RCON authentication response for the given request ID
21
+ #
22
+ # The request ID of the packet will match the client's request if
23
+ # authentication was successful
24
+ #
25
+ # @param [Fixnum] request_id The request ID of the RCON connection
12
26
  def initialize(request_id)
13
27
  super request_id, SERVERDATA_AUTH_RESPONSE, ''
14
28
  end
@@ -1,14 +1,26 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2008-2010, Sebastian Staudt
4
+ # Copyright (c) 2008-2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/packets/rcon/rcon_packet'
7
7
 
8
+ # This packet class represents a SERVERDATA_EXECCOMMAND packet sent to a
9
+ # Source server
10
+ #
11
+ # It is used to request a command execution on the server.
12
+ #
13
+ # @author Sebastian Staudt
14
+ # @see SourceServer#rcon_exec
8
15
  class RCONExecRequest
9
16
 
10
17
  include RCONPacket
11
18
 
19
+ # Creates a RCON command execution request for the given request ID and
20
+ # command
21
+ #
22
+ # @param [Fixnum] request_id The request ID of the RCON connection
23
+ # @param [String] rcon_command The command to execute on the server
12
24
  def initialize(request_id, rcon_command)
13
25
  super request_id, SERVERDATA_EXECCOMMAND, rcon_command
14
26
  end
@@ -1,18 +1,35 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2008-2010, Sebastian Staudt
4
+ # Copyright (c) 2008-2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/packets/rcon/rcon_packet'
7
7
 
8
+ # This packet class represents a SERVERDATA_RESPONSE_VALUE packet sent by a
9
+ # Source server
10
+ #
11
+ # It is used to transport the output of a command from the server to the client
12
+ # which requested the command execution.
13
+ #
14
+ # @author Sebastian Staudt
15
+ # @see SourceServer#rcon_exec
8
16
  class RCONExecResponse
9
17
 
10
18
  include RCONPacket
11
19
 
20
+ # Creates a RCON command response for the given request ID and command
21
+ # output
22
+ #
23
+ # @param [Fixnum] request_id The request ID of the RCON connection
24
+ # @param [String] command_response The output of the command executed on the
25
+ # server
12
26
  def initialize(request_id, command_response)
13
27
  super request_id, SERVERDATA_RESPONSE_VALUE, command_response
14
28
  end
15
29
 
30
+ # Returns the output of the command execution
31
+ #
32
+ # @return [String] The output of the command
16
33
  def response
17
34
  @content_data.string[0..-3]
18
35
  end
@@ -1,18 +1,33 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2008-2010, Sebastian Staudt
4
+ # Copyright (c) 2008-2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/packets/steam_packet'
7
7
 
8
+ # This packet class represents a RCON request packet sent to a GoldSrc server
9
+ #
10
+ # It is used to request a command execution on the server.
11
+ #
12
+ # @author Sebastian Staudt
13
+ # @see GoldSrcServer#rcon_exec
8
14
  class RCONGoldSrcRequest
9
15
 
10
16
  include SteamPacket
11
17
 
18
+ # Creates a request for the given request string
19
+ #
20
+ # The request string has the form `rcon {challenge number} {RCON password}
21
+ # {command}`.
22
+ #
23
+ # @param [String] request The request string to send to the server
12
24
  def initialize(request)
13
25
  super 0x00, request
14
26
  end
15
27
 
28
+ # Returns the raw data representing this packet
29
+ #
30
+ # @return [String] A string containing the raw data of this request packet
16
31
  def to_s
17
32
  [0xFFFFFFFF, @content_data.string].pack('Va*')
18
33
  end
@@ -1,18 +1,32 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2008-2010, Sebastian Staudt
4
+ # Copyright (c) 2008-2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/packets/steam_packet'
7
7
 
8
+ # This packet class represents a RCON response packet sent by a GoldSrc server
9
+ #
10
+ # It is used to transport the output of a command from the server to the client
11
+ # which requested the command execution.
12
+ #
13
+ # @author Sebastian Staudt
14
+ # @see GoldSrcServer#rcon_exec
8
15
  class RCONGoldSrcResponse
9
16
 
10
17
  include SteamPacket
11
18
 
19
+ # Creates a RCON command response for the given command output
20
+ #
21
+ # @param [String] command_response The output of the command executed on the
22
+ # server
12
23
  def initialize(command_response)
13
24
  super RCON_GOLDSRC_RESPONSE_HEADER, command_response
14
25
  end
15
26
 
27
+ # Returns the output of the command execution
28
+ #
29
+ # @return [String] The output of the command
16
30
  def response
17
31
  @content_data.string[0..-3]
18
32
  end
@@ -1,27 +1,55 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2008-2010, Sebastian Staudt
4
+ # Copyright (c) 2008-2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/packets/steam_packet'
7
7
 
8
+ # This module is included by all classes representing a packet used by Source's
9
+ # RCON protocol
10
+ #
11
+ # It provides a basic implementation for initializing and serializing such a
12
+ # packet.
13
+ #
14
+ # @author Sebastian Staudt
15
+ # @see RCONPacketFactory
8
16
  module RCONPacket
9
17
 
10
18
  include SteamPacket
11
19
 
20
+ # Header for authentication requests
12
21
  SERVERDATA_AUTH = 3
22
+
23
+ # Header for replies to authentication attempts
13
24
  SERVERDATA_AUTH_RESPONSE = 2
25
+
26
+ # Header for command execution requests
14
27
  SERVERDATA_EXECCOMMAND = 2
28
+
29
+ # Header for packets with the output of a command execution
15
30
  SERVERDATA_RESPONSE_VALUE = 0
16
31
 
32
+ # Returns the request ID used to identify the RCON communication
33
+ #
34
+ # @return [Fixnum] The request ID used to identify the RCON communication
17
35
  attr_reader :request_id
18
36
 
37
+ # Creates a new RCON packet object with the given request ID, type and
38
+ # content data
39
+ #
40
+ # @param [Fixnum] request_id The request ID for the current RCON
41
+ # communication
42
+ # @param [Fixnum] rcon_header The header for the packet type
43
+ # @param [String] rcon_data The raw packet data
19
44
  def initialize(request_id, rcon_header, rcon_data)
20
45
  super rcon_header, "#{rcon_data}\0\0"
21
46
 
22
47
  @request_id = request_id
23
48
  end
24
49
 
50
+ # Returns the raw data representing this packet
51
+ #
52
+ # @return [String] A string containing the raw data of this RCON packet
25
53
  def to_s
26
54
  [@content_data.length + 8, @request_id, @header_data, @content_data.string].pack('V3a*')
27
55
  end
@@ -1,7 +1,7 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2008-2010, Sebastian Staudt
4
+ # Copyright (c) 2008-2011, Sebastian Staudt
5
5
 
6
6
  require 'stringio_additions'
7
7
  require 'exceptions/packet_format_exception'
@@ -9,10 +9,20 @@ require 'steam/packets/steam_packet_factory'
9
9
  require 'steam/packets/rcon/rcon_auth_response'
10
10
  require 'steam/packets/rcon/rcon_exec_response'
11
11
 
12
+ # This module provides functionality to handle raw packet data for Source RCON
13
+ #
14
+ # It's is used to transform data bytes into packet objects for RCON
15
+ # communication with Source servers.
16
+ #
17
+ # @author Sebastian Staudt
18
+ # @see RCONPacket
12
19
  module RCONPacketFactory
13
20
 
14
- include SteamPacketFactory
15
-
21
+ # Creates a new packet object based on the header byte of the given raw data
22
+ #
23
+ # @param [String] raw_data The raw data of the packet
24
+ # @raise [PacketFormatException] if the packet header is not recognized
25
+ # @return [RCONPacket] The packet object generated from the packet data
16
26
  def self.packet_from_data(raw_data)
17
27
  byte_buffer = StringIO.new raw_data
18
28