Class: Steam::Csgo::Base

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

Overview

Handles CSGO related events

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Base

The Steam gem will instantiate the plugin and provide the client.

Parameters:

  • client (Steam::Client)

    the steam client



12
13
14
# File 'lib/steam/csgo/base.rb', line 12

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

The Steam Client



7
8
9
# File 'lib/steam/csgo/base.rb', line 7

def client
  @client
end

Instance Method Details

#gc_message(msg) ⇒ Object

The client will give us each gc message. We handle the ones we care about. A notice is printed on skipped emsgs



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/steam/csgo/base.rb', line 58

def gc_message(msg)
  case msg.emsg
  when ::Csgo::EGCBaseClientMsg::K_EMsgGCClientWelcome
    client.csgo_ready
  when ::Csgo::ECsgoGCMsg::K_EMsgGCCStrike15_v2_MatchList
    match_list = msg.as(::Csgo::CMsgGCCStrike15_v2_MatchList)
    client.csgo_match_info(match_list)
  else
    Steam.logger.debug("[CS:GO] Ignoring msg: #{msg.emsg}")
  end
end

#request_match_info(match_id, outcome_id, token) ⇒ Bool

Request match info for a given match.

Parameters:

  • match_id (String)

    the match id

  • outcome_id (String)

    the outcome id

  • token (String)

    the token

Returns:

  • (Bool)


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/steam/csgo/base.rb', line 23

def request_match_info(match_id, outcome_id, token)
  msg = ::Csgo::CMsgGCCStrike15_v2_MatchListRequestFullGameInfo.new
  msg.matchid = match_id
  msg.outcomeid = outcome_id
  msg.token = token

  msg = GcProtobufMessage.new(
    MsgGCHdrProtoBuf.new,
    msg,
    ::Csgo::ECsgoGCMsg::K_EMsgGCCStrike15_v2_MatchListRequestFullGameInfo
  )
  client.game_coordinator.send_msg(msg)
end

#startBool

Starts the plugin. Sets the Client to online and puts the Client into CS:GO

Returns:

  • (Bool)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/steam/csgo/base.rb', line 41

def start
  client.steam_user.change_persona_state(EPersonaState::OFFLINE)
  client.game_coordinator.play(730)

  # actually ask and wait if we are in gc, but just sleep 10 seconds for
  # now
  sleep(5)

  client.game_coordinator.send_msg(
    GcProtobufMessage.new(MsgGCHdrProtoBuf.new,
                          ::Csgo::CMsgClientHello.new,
                          ::Csgo::EGCBaseClientMsg::K_EMsgGCClientHello)
  )
end