steam

package module
v0.0.0-...-1587682 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2024 License: BSD-3-Clause Imports: 28 Imported by: 0

README

Steam for Go

This library implements Steam's protocol to allow automation of different actions on Steam without running an actual Steam client. It is based on SteamKit2, a .NET library.

In addition, it contains APIs to Steam Community features, like trade offers and inventories.

Some of the currently implemented features:

  • Trading and trade offers, including inventories and notifications
  • Friend and group management
  • Chatting with friends
  • Persona states (online, offline, looking to trade, etc.)
  • SteamGuard with two-factor authentication
  • Team Fortress 2: Crafting, moving, naming and deleting items

If this is useful to you, there's also the go-steamapi package that wraps some of the official Steam Web API's types.

Installation

go get github.com/Philipp15b/go-steam

Usage

You can view the documentation with the godoc tool or online on godoc.org.

You should also take a look at the following sub-packages:

Working with go-steam

Whether you want to develop your own Steam bot or directly work on go-steam itself, there are are few things to know.

  • If something is not working, check first if the same operation works (under the same conditions!) in the Steam client on that account. Maybe there's something go-steam doesn't handle correctly or you're missing a warning that's not obviously shown in go-steam. This is particularly important when working with trading since there are restrictions, for example newly authorized devices will not be able to trade for seven days.
  • Since Steam does not maintain a public API for most of the things go-steam implements, you can expect that sometimes things break randomly. Especially the trade and tradeoffer packages have been affected in the past.
  • Always gather as much information as possible. When you file an issue, be as precise and complete as you can. This makes debugging way easier.
  • If you haven't noticed yet, expect to find lots of things out yourself. Debugging can be complicated and Steam's internals are too.
  • Sometimes things break and other SteamKit ports are fixed already. Maybe take a look what people are saying over there? There's also the SteamKit IRC channel.

Updating go-steam to a new SteamKit version

Go source code is generated with code in the generator directory. Look at generator/README.md for more information on how to use the generator.

Then, after generating new Go source files, update go-steam as necessary.

License

Steam for Go is licensed under the New BSD License. More information can be found in LICENSE.txt.

Documentation

Overview

This package allows you to automate actions on Valve's Steam network. It is a Go port of SteamKit.

To login, you'll have to create a new Client first. Then connect to the Steam network and wait for a ConnectedCallback. Then you may call the Login method in the Auth module with your login information. This is covered in more detail in the method's documentation. After you've received the LoggedOnEvent, you should set your persona state to online to receive friend lists etc.

Example code

You can also find a running example in the `gsbot` package.

package main

import (
	"io/ioutil"
	"log"

	"github.com/WirStaff/go-steam"
	"github.com/WirStaff/go-steam/protocol/steamlang"
)

func main() {
	myLoginInfo := new(steam.LogOnDetails)
	myLoginInfo.Username = "Your username"
	myLoginInfo.Password = "Your password"

	client := steam.NewClient()
	client.Connect()
	for event := range client.Events() {
		switch e := event.(type) {
		case *steam.ConnectedEvent:
			client.Auth.LogOn(myLoginInfo)
		case *steam.MachineAuthUpdateEvent:
			ioutil.WriteFile("sentry", e.Hash, 0666)
		case *steam.LoggedOnEvent:
			client.Social.SetPersonaState(steamlang.EPersonaState_Online)
		case steam.FatalErrorEvent:
			log.Print(e)
		case error:
			log.Print(e)
		}
	}
}

Events

go-steam emits events that can be read via Client.Events(). Although the channel has the type interface{}, only types from this package ending with "Event" and errors will be emitted.

Index

Constants

This section is empty.

Variables

View Source
var CMServers = []string{
	"103.10.124.123:27018",
	"103.10.124.122:27018",
	"103.10.124.122:27017",
	"103.10.124.123:27017",
	"103.10.124.124:27017",
	"103.10.124.124:27018",
	"103.10.124.125:27017",
	"103.10.124.125:27018",
	"103.28.54.162:27018",
	"103.28.54.162:27017",
	"103.28.54.178:27017",
	"103.28.54.178:27018",
	"103.28.54.181:27017",
	"103.28.54.165:27018",
	"103.28.54.165:27017",
	"103.28.54.171:27018",
	"103.28.54.181:27018",
	"103.28.54.171:27017",
	"155.133.239.20:27018",
	"155.133.239.20:27017",
	"155.133.245.36:27017",
	"155.133.245.36:27018",
	"155.133.239.51:27017",
	"155.133.239.51:27018",
	"155.133.245.37:27017",
	"155.133.245.37:27018",
	"162.254.195.71:27017",
	"162.254.195.71:27018",
	"162.254.195.66:27017",
	"162.254.195.66:27018",
	"205.196.6.214:27017",
	"205.196.6.214:27018",
	"205.196.6.215:27017",
	"155.133.253.34:27017",
	"155.133.253.50:27018",
	"155.133.253.50:27017",
	"155.133.253.34:27018",
	"162.254.193.102:27017",
	"162.254.193.102:27018",
	"162.254.193.74:27017",
	"162.254.193.74:27018",
	"205.196.6.215:27018",
	"162.254.192.74:27017",
	"162.254.192.74:27018",
	"162.254.199.181:27018",
	"162.254.199.163:27018",
	"162.254.199.181:27017",
	"162.254.192.75:27017",
	"162.254.192.75:27018",
	"162.254.199.163:27017",
	"162.254.192.71:27017",
	"162.254.192.71:27018",
	"162.254.192.87:27018",
	"162.254.192.87:27017",
	"103.10.125.156:27018",
	"103.10.125.156:27017",
	"103.10.125.148:27018",
	"103.10.125.148:27017",
	"162.254.196.83:27017",
	"162.254.196.83:27018",
	"162.254.196.68:27018",
	"162.254.196.68:27017",
	"162.254.196.67:27017",
	"162.254.196.67:27018",
	"162.254.196.84:27018",
	"162.254.196.84:27017",
	"155.133.248.39:27018",
	"155.133.248.39:27017",
	"155.133.248.38:27018",
	"155.133.248.38:27017",
	"155.133.226.78:27018",
	"155.133.226.78:27017",
	"162.254.197.39:27017",
	"162.254.197.39:27018",
	"162.254.197.54:27018",
	"162.254.197.54:27017",
	"155.133.226.75:27018",
	"155.133.226.75:27017",
	"185.25.182.52:27018",
	"185.25.182.52:27017",
	"185.25.182.20:27017",
	"185.25.182.20:27018",
	"162.254.198.44:27018",
	"162.254.198.44:27017",
	"155.133.252.39:27018",
	"155.133.252.39:27017",
	"155.133.252.54:27017",
	"155.133.252.54:27018",
	"162.254.198.104:27018",
	"162.254.198.104:27017",
	"155.133.246.36:27017",
	"155.133.246.36:27018",
	"155.133.246.52:27017",
	"155.133.246.52:27018",
	"146.66.152.39:27018",
	"155.133.246.51:27017",
	"146.66.152.38:27017",
	"146.66.152.39:27017",
	"146.66.152.44:27018",
	"146.66.152.44:27017",
}

CMServers contains a list of worlwide servers

Functions

func GetPublicKey

func GetPublicKey(universe steamlang.EUniverse) *rsa.PublicKey

func GetRandomCM

func GetRandomCM() *netutil.PortAddr

GetRandomCM returns a random server from a built-in IP list.

Prefer Client.Connect(), which uses IPs from the Steam Directory, which is always more up-to-date.

func InitializeSteamDirectory

func InitializeSteamDirectory(cellId uint32) error

Load initial server list from Steam Directory Web API. Call InitializeSteamDirectory() before Connect() to use steam directory server list instead of static one.

Types

type Client

type Client struct {
	GC *GameCoordinator

	ConnectionTimeout time.Duration
	// contains filtered or unexported fields
}

Represents a client to the Steam network. Always poll events from the channel returned by Events() or receiving messages will stop. All access, unless otherwise noted, should be threadsafe.

When a FatalErrorEvent is emitted, the connection is automatically closed. The same client can be used to reconnect. Other errors don't have any effect.

func NewClient

func NewClient() *Client

func (*Client) Connect

func (c *Client) Connect(cellId uint32, proxy *ProxyConnection) (*netutil.PortAddr, error)

Connects to a random Steam server and returns its address. If this client is already connected, it is disconnected first. This method tries to use an address from the Steam Directory and falls back to the built-in server list if the Steam Directory can't be reached. If you want to connect to a specific server, use `ConnectTo`.

func (*Client) ConnectTo

func (c *Client) ConnectTo(addr *netutil.PortAddr, proxy *ProxyConnection) error

Connects to a specific server. You may want to use one of the `GetRandom*CM()` functions in this package. If this client is already connected, it is disconnected first.

func (*Client) ConnectToBind

func (c *Client) ConnectToBind(addr *netutil.PortAddr, local *net.TCPAddr, proxy *ProxyConnection) error

Connects to a specific server, and binds to a specified local IP If this client is already connected, it is disconnected first.

func (*Client) Connected

func (c *Client) Connected() bool

func (*Client) Disconnect

func (c *Client) Disconnect()

func (*Client) Emit

func (c *Client) Emit(event interface{})

func (*Client) Errorf

func (c *Client) Errorf(format string, a ...interface{})

Emits an error formatted with fmt.Errorf.

func (*Client) Events

func (c *Client) Events() <-chan interface{}

Get the event channel. By convention all events are pointers, except for errors. It is never closed.

func (*Client) Fatalf

func (c *Client) Fatalf(format string, a ...interface{})

Emits a FatalErrorEvent formatted with fmt.Errorf and disconnects.

func (*Client) GetNextJobId

func (c *Client) GetNextJobId() protocol.JobId

func (*Client) HeartbeatLoop

func (c *Client) HeartbeatLoop(seconds time.Duration)

func (*Client) RegisterPacketHandler

func (c *Client) RegisterPacketHandler(handler PacketHandler)

Registers a PacketHandler that receives all incoming packets.

func (*Client) SessionId

func (c *Client) SessionId() int32

func (*Client) SetSessionId

func (c *Client) SetSessionId(id int32)

func (*Client) SetSteamId

func (c *Client) SetSteamId(steamId uint64)

func (*Client) SetSteamIdForAuth

func (c *Client) SetSteamIdForAuth(instance uint32, univerve steamlang.EUniverse, steamType steamlang.EAccountType)

func (*Client) SteamId

func (c *Client) SteamId() steamid.SteamId

func (*Client) Write

func (c *Client) Write(msg protocol.IMsg)

Adds a message to the send queue. Modifications to the given message after writing are not allowed (possible race conditions).

Writes to this client when not connected are ignored.

type ClientCMListEvent

type ClientCMListEvent struct {
	Addresses []*netutil.PortAddr
}

A list of connection manager addresses to connect to in the future. You should always save them and then select one of these instead of the builtin ones for the next connection.

type ConnectedEvent

type ConnectedEvent struct{}

type DisconnectedEvent

type DisconnectedEvent struct{}

type FatalErrorEvent

type FatalErrorEvent error

When this event is emitted by the Client, the connection is automatically closed. This may be caused by a network error, for example.

type GCPacketHandler

type GCPacketHandler interface {
	HandleGCPacket(*gamecoordinator.GCPacket)
}

type GameCoordinator

type GameCoordinator struct {
	// contains filtered or unexported fields
}

func (*GameCoordinator) HandlePacket

func (g *GameCoordinator) HandlePacket(packet *protocol.Packet)

func (*GameCoordinator) RegisterPacketHandler

func (g *GameCoordinator) RegisterPacketHandler(handler GCPacketHandler)

func (*GameCoordinator) SetGamesPlayed

func (g *GameCoordinator) SetGamesPlayed(appIds ...uint64)

Sets you in the given games. Specify none to quit all games.

func (*GameCoordinator) Write

func (g *GameCoordinator) Write(msg gamecoordinator.IGCMsg)

type PacketHandler

type PacketHandler interface {
	HandlePacket(*protocol.Packet)
}

type ProxyConnection

type ProxyConnection struct {
	Addr     string
	Username string
	Password string
}

Directories

Path Synopsis
csgo
dota
This program generates the protobuf and SteamLanguage files from the SteamKit data.
This program generates the protobuf and SteamLanguage files from the SteamKit data.
Includes helper types for working with JSON data
Includes helper types for working with JSON data
This package includes some basics for the Steam protocol.
This package includes some basics for the Steam protocol.
steamlang
Contains code generated from SteamKit's SteamLanguage data.
Contains code generated from SteamKit's SteamLanguage data.
Utilities for reading and writing of binary data
Utilities for reading and writing of binary data
tf2

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL