Class: Steam::Handler::SteamUser

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/steam/handler/steam_user.rb

Overview

Note:

You need to handle the LogonResponse to catch Steam Guard prompts and 2FA

Handles messages releated to a Steam user

Examples:

Logging in

steam_user = client.steam_user
steam_user.(username, password, token, hash)

Instance Attribute Summary

Attributes included from Base

#client

Instance Method Summary collapse

Methods included from Base

#handles?, included, #initialize, #send_msg

Instance Method Details

#change_persona_name(name) ⇒ Object

Change the Client's name

Examples:

Setting a Client as "Jimbo"

steam_user = client.steam_user
steam_user.change_persona_name("Jimbo")

Parameters:

  • name (String)

    the new client name

Returns:

  • True if the message was sent, false otherwise



81
82
83
84
85
86
87
88
89
# File 'lib/steam/handler/steam_user.rb', line 81

def change_persona_name(name)
  client_status = Steamclient::CMsgClientChangeStatus.new
  client_status.player_name = name

  client_change_status = ProtobufMessage.new(MsgHdrProtoBuf.new,
                                             client_status,
                                             EMsg::CLIENT_CHANGE_STATUS)
  send_msg(client_change_status)
end

#change_persona_state(state) ⇒ Object

Change the Client's persona state.

Examples:

Setting a Client as "Online"

steam_user = client.steam_user
steam_user.change_persona_state(EPersonaState::ONLINE)

Parameters:

  • state (EMsg::E_PERSONA_STATE)

    the new client state

Returns:

  • True if the message was sent, false otherwise



63
64
65
66
67
68
69
70
71
# File 'lib/steam/handler/steam_user.rb', line 63

def change_persona_state(state)
  client_status = Steamclient::CMsgClientChangeStatus.new
  client_status.persona_state = state

  client_change_status = ProtobufMessage.new(MsgHdrProtoBuf.new,
                                             client_status,
                                             EMsg::CLIENT_CHANGE_STATUS)
  send_msg(client_change_status)
end

#handle(packet) ⇒ Object

Handles a given packet

Parameters:



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/steam/handler/steam_user.rb', line 104

def handle(packet)
  case packet.msg_type
  when EMsg::CLIENT_LOG_ON_RESPONSE
    handle_client_logon_response(packet)
  when EMsg::CLIENT_UPDATE_MACHINE_AUTH
    handle_machine_auth_update(packet)
  when EMsg::CLIENT_NEW_LOGIN_KEY
    (packet)
  when EMsg::CLIENT_LOGGED_OFF
    handle_client_logoff(packet)
  end
end

#login(username, password, token = nil, hash = nil) ⇒ Object

rubocop:disable MethodLength rubocop:disable AbcSize

Log a Client in

Parameters:

  • username (String)

    the username

  • password (String)

    the password

  • token (String) (defaults to: nil)

    the SteamGuard token or nil

  • hash (String) (defaults to: nil)

    the SteamGuard hash or nil

Returns:

  • True or false if the message was sent. You must handle the ClientLogonResponse to know the real logon result



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/steam/handler/steam_user.rb', line 31

def (username, password, token = nil, hash = nil)
  msg = ProtobufMessage.new(MsgHdrProtoBuf.new,
                            Steamclient::CMsgClientLogon.new,
                            EMsg::CLIENT_LOGON)

  msg.body.auth_code = token if token
  msg.body.eresult_sentryfile = EResult::FILE_NOT_FOUND

  if hash
    msg.body.sha_sentryfile = hash
    msg.body.eresult_sentryfile = EResult::OK
  end

  ip = LocalIp.new.to_i ^ MsgClientLogon::OBFUSCATION_MASK
  msg.body.obfustucated_private_ip = ip
  msg.body. = username
  msg.body.password = password
  msg.body.protocol_version = MsgClientLogon::CURRENT_PROTOCOL
  msg.body.client_os_type = EOSType::WIN311
  msg.body.client_package_version = 1771

  send_msg(msg)
end

#logoffBool

Logs the Client off the Steam network

Returns:

  • (Bool)


94
95
96
97
98
99
# File 'lib/steam/handler/steam_user.rb', line 94

def logoff
  logoff = ProtobufMessage.new(MsgHdrProtoBuf.new,
                               Steamclient::CMsgClientLogOff.new,
                               EMsg::CLIENT_LOG_OFF)
  send_msg(logoff)
end