Class: Steam::Client
- Inherits:
-
Object
- Object
- Steam::Client
- Defined in:
- lib/steam/client.rb
Overview
Represents a Client on the Steam Network. The Client creates a connection to the Steam networks, and send and receives Message objects to that connection.
The Client holds a collection of handlers that react to received packets, if they care about the packet data.
Instance Attribute Summary collapse
-
#connect_tokens ⇒ Object
readonly
A list of tokens requires for the game coordinator to launch games.
-
#connection ⇒ Object
readonly
The internal connection to Steam.
-
#game_coordinator ⇒ Object
readonly
The Handler for the game coordinator events (playing game, etc).
-
#plugins ⇒ Object
readonly
The plugin engine.
-
#session_id ⇒ Object
readonly
The session id for the current user, nilt if not logged in.
-
#steam_apps ⇒ Object
readonly
The Handler for Steam app related events (play tokens, etc).
-
#steam_id ⇒ Object
readonly
The SteamId for the current user, nil if not logged in.
-
#steam_user ⇒ Object
readonly
The Handler for Steam user related events (changing name, login, etc).
Instance Method Summary collapse
-
#create_session(steam_id, session_id) ⇒ Object
Creates a new session for the Client.
-
#gc_message(msg) ⇒ Object
Passes each GC message to any plugins.
-
#initialize(connection = nil) ⇒ Client
constructor
A new instance of Client.
-
#on_logon(_msg) ⇒ Object
Called by SteamUser handler when the logon message is to be handled.
-
#plugin(plugin) ⇒ Object
Registers a plugin with the Client via the plugin name.
-
#ready ⇒ Object
Called by SteamUser handler when the user is fully logged in.
-
#restart ⇒ Object
Stop and start the Client.
-
#send_msg(msg) ⇒ Object
Sends a Message to the underlying Steam connection.
-
#session_key=(key) ⇒ Object
Sets the Client's connection session key.
-
#start ⇒ Object
Create a new Connection object, and start listening and handling received packets.
-
#start_heartbeat(tick) ⇒ Object
Starts the background heartbeat thread.
-
#stop ⇒ Object
Disconnect the Client.
-
#update_connect_tokens(tokens, max) ⇒ Object
Update the Client's internal connection token list.
Constructor Details
#initialize(connection = nil) ⇒ Client
Returns a new instance of Client.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/steam/client.rb', line 34 def initialize(connection = nil) connection ||= Networking::Connection.new(ServerList.new.to_a.sample) @connect_tokens = [] @steam_user = nil @steam_apps = nil @game_coordinator = nil @steam_id = default_steam_id @connection = connection @plugins = Plugins.new(self) init_handlers end |
Instance Attribute Details
#connect_tokens ⇒ Object (readonly)
A list of tokens requires for the game coordinator to launch games
23 24 25 |
# File 'lib/steam/client.rb', line 23 def connect_tokens @connect_tokens end |
#connection ⇒ Object (readonly)
The internal connection to Steam
11 12 13 |
# File 'lib/steam/client.rb', line 11 def connection @connection end |
#game_coordinator ⇒ Object (readonly)
The Handler for the game coordinator events (playing game, etc)
20 21 22 |
# File 'lib/steam/client.rb', line 20 def game_coordinator @game_coordinator end |
#plugins ⇒ Object (readonly)
The plugin engine
32 33 34 |
# File 'lib/steam/client.rb', line 32 def plugins @plugins end |
#session_id ⇒ Object (readonly)
The session id for the current user, nilt if not logged in
29 30 31 |
# File 'lib/steam/client.rb', line 29 def session_id @session_id end |
#steam_apps ⇒ Object (readonly)
The Handler for Steam app related events (play tokens, etc)
17 18 19 |
# File 'lib/steam/client.rb', line 17 def steam_apps @steam_apps end |
#steam_id ⇒ Object (readonly)
The SteamId for the current user, nil if not logged in
26 27 28 |
# File 'lib/steam/client.rb', line 26 def steam_id @steam_id end |
#steam_user ⇒ Object (readonly)
The Handler for Steam user related events (changing name, login, etc)
14 15 16 |
# File 'lib/steam/client.rb', line 14 def steam_user @steam_user end |
Instance Method Details
#create_session(steam_id, session_id) ⇒ Object
Creates a new session for the Client
112 113 114 115 |
# File 'lib/steam/client.rb', line 112 def create_session(steam_id, session_id) @steam_id = CommunityId.new(steam_id) @session_id = session_id end |
#gc_message(msg) ⇒ Object
Passes each GC message to any plugins.
151 152 153 154 155 |
# File 'lib/steam/client.rb', line 151 def (msg) @plugins.loaded_plugins.each do |plugin| send(plugin).(msg) end end |
#on_logon(_msg) ⇒ Object
Called by SteamUser handler when the logon message is to be handled. This must be implemented by the subclass
48 49 50 |
# File 'lib/steam/client.rb', line 48 def on_logon(_msg) raise NotImplementedError end |
#plugin(plugin) ⇒ Object
Registers a plugin with the Client via the plugin name
61 62 63 |
# File 'lib/steam/client.rb', line 61 def plugin(plugin) @plugins.plugin(plugin.to_sym) end |
#ready ⇒ Object
Called by SteamUser handler when the user is fully logged in. This must be implemented by the subclass.
54 55 56 |
# File 'lib/steam/client.rb', line 54 def ready raise NotImplementedError end |
#restart ⇒ Object
Stop and start the Client
66 67 68 69 |
# File 'lib/steam/client.rb', line 66 def restart stop start end |
#send_msg(msg) ⇒ Object
Sends a Message to the underlying Steam connection. If we have an active session, the session id and steam id is automatically associated with the request
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/steam/client.rb', line 97 def send_msg(msg) Steam.logger.debug("Sending #{msg.body.class.name} to Steam") if msg.proto? msg.session_id = session_id msg.steam_id = steam_id.to_i end connection.send_msg(msg).nonzero? end |
#session_key=(key) ⇒ Object
Sets the Client's connection session key. Used for encrypting and decrypting packets
130 131 132 |
# File 'lib/steam/client.rb', line 130 def session_key=(key) connection.session_key = key end |
#start ⇒ Object
Create a new Connection object, and start listening and handling received packets.
83 84 85 86 87 88 89 90 |
# File 'lib/steam/client.rb', line 83 def start @plugins.load connection.open connection.each_packet do |packet| handle_net_msg(packet) end end |
#start_heartbeat(tick) ⇒ Object
Starts the background heartbeat thread.
138 139 140 141 142 143 144 145 146 |
# File 'lib/steam/client.rb', line 138 def start_heartbeat(tick) Thread.new do |t| t.abort_on_exception = true until connection.disconnected? send_msg() sleep(tick) end end end |
#stop ⇒ Object
Disconnect the Client
72 73 74 75 76 77 |
# File 'lib/steam/client.rb', line 72 def stop steam_user.logoff if @steam_id && @session_id connection.disconnect @steam_id = default_steam_id @session_id = nil end |
#update_connect_tokens(tokens, max) ⇒ Object
Update the Client's internal connection token list
121 122 123 124 |
# File 'lib/steam/client.rb', line 121 def update_connect_tokens(tokens, max) tokens.each { |t| @connect_tokens.insert(0, t) } @connect_tokens = @connect_tokens.take(max) end |