steam

package module
v0.0.0-...-7d00897 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2014 License: BSD-3-Clause Imports: 30 Imported by: 0

README

Steam for Go

This library allows you to interact with Steam as if it was an actual Steam client. It's a port of SteamKit2 to Go.

Installation

go get github.com/manveru/go-steam

Usage

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

When updating, always check the CHANGELOG.md first.

Updating go-steam for a new SteamKit version

To update go-steam for a new version of SteamKit, do the following:

go get code.google.com/p/goprotobuf/protoc-gen-go
git submodule init && git submodule update
cd generator
go run generator.go clean proto steamlang

Replace steamlang with steamlang:nodebug if you want to exclude the String() string methods for the generated SteamLanguage enums.

Make sure that protoc-gen-go/$GOPATH/bin is in your $PATH. On Windows you also have to have .NET Framework installed, on other operating systems mono is used (must be in $PATH too).

Apply the protocol changes where necessary.

License

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

Documentation

Overview

This package provides access to Steam as if it was an actual Steam client.

To login, you'll have to create a new Client first. Then connect to the Steam network and wait for a ConnectedCallback. This means you can now 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.

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(internal.EPersonaState_Online)
	case steam.FatalError:
		client.Connect() // please do some real error handling here
		log.Print(e)
	case error:
		log.Print(e)
	}
}

Index

Constants

This section is empty.

Variables

View Source
var CMServers = []string{

	"72.165.61.174:27017",
	"72.165.61.174:27018",
	"72.165.61.175:27017",
	"72.165.61.175:27018",
	"72.165.61.176:27017",
	"72.165.61.176:27018",
	"72.165.61.185:27017",
	"72.165.61.185:27018",
	"72.165.61.187:27017",
	"72.165.61.187:27018",
	"72.165.61.188:27017",
	"72.165.61.188:27018",

	"146.66.152.12:27017",
	"146.66.152.12:27018",
	"146.66.152.12:27019",
	"146.66.152.13:27017",
	"146.66.152.13:27018",
	"146.66.152.13:27019",
	"146.66.152.14:27017",
	"146.66.152.14:27018",
	"146.66.152.14:27019",
	"146.66.152.15:27017",
	"146.66.152.15:27018",
	"146.66.152.15:27019",

	"209.197.29.196:27017",
	"209.197.29.197:27017",
}

Functions

func GetPublicKey

func GetPublicKey(universe EUniverse) *rsa.PublicKey

Types

type Auth

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

func (*Auth) HandlePacket

func (a *Auth) HandlePacket(packet *PacketMsg)

func (*Auth) LogOn

func (a *Auth) LogOn(details *LogOnDetails)

Log on with the given details. You must always specify username and password. For the first login, don't set an authcode or a hash and you'll receive an error and Steam will send you an authcode. Then you have to login again, this time with the authcode. Shortly after logging in, you'll receive a MachineAuthUpdateEvent with a hash which allows you to login without using an authcode in the future.

If you don't use Steam Guard, username and password are enough.

type ChatMsgEvent

type ChatMsgEvent struct {
	Chatroom SteamId // not set for friend messages
	Sender   SteamId
	Message  string
	Type     EChatEntryType
}

func (*ChatMsgEvent) IsMessage

func (c *ChatMsgEvent) IsMessage() bool

Whether the type is ChatMsg

type Client

type Client struct {
	Auth    *Auth
	Social  *Social
	Web     *Web
	Trading *Trading
	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 FatalError 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() string

Connects to a random server of the Steam network and returns the server. If this client is already connected, it is disconnected first.

func (*Client) ConnectTo

func (c *Client) ConnectTo(address string)

Connects to a specific server. 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.

func (*Client) Fatalf

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

Emits a FatalError formatted with fmt.Errorf and disconnects.

func (*Client) GetNextJobId

func (c *Client) GetNextJobId() JobId

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) SteamId

func (c *Client) SteamId() SteamId

func (*Client) Write

func (c *Client) Write(msg 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 ConnectedEvent

type ConnectedEvent struct{}

type FatalError

type FatalError error

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

type Friend

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

A thread-safe friend in a friend list which contains references to its predecessor and successor. It is mutable and will be changed by Social.

func (*Friend) GameAppId

func (f *Friend) GameAppId() uint64

func (*Friend) Name

func (f *Friend) Name() string

func (*Friend) Next

func (f *Friend) Next() *Friend

func (*Friend) PersonaStateFlags

func (f *Friend) PersonaStateFlags() EPersonaStateFlag

func (*Friend) Prev

func (f *Friend) Prev() *Friend

func (*Friend) Relationship

func (f *Friend) Relationship() EFriendRelationship

func (*Friend) SteamId

func (f *Friend) SteamId() SteamId

type FriendListEvent

type FriendListEvent struct{}

type FriendStateEvent

type FriendStateEvent struct {
	SteamId      SteamId
	Relationship EFriendRelationship
}

func (*FriendStateEvent) IsFriend

func (f *FriendStateEvent) IsFriend() bool

func (*FriendStateEvent) IsMember

func (f *FriendStateEvent) IsMember() bool

type FriendsList

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

func (*FriendsList) ById

func (f *FriendsList) ById(id SteamId) *Friend

func (*FriendsList) First

func (f *FriendsList) First() *Friend

func (*FriendsList) Last

func (f *FriendsList) Last() *Friend

type GCPacketHandler

type GCPacketHandler interface {
	HandleGCPacket(*GCPacketMsg)
}

type GameCoordinator

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

func (*GameCoordinator) HandlePacket

func (g *GameCoordinator) HandlePacket(packet *PacketMsg)

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 IGCMsg)

type Group

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

Represents a group within a doubly-linked group list.

func (*Group) Name

func (g *Group) Name() string

func (*Group) Next

func (g *Group) Next() *Group

Returns the next element in the group list or nil if this group is the last in the list.

func (*Group) Prev

func (g *Group) Prev() *Group

Returns the previous element in the group list or nil if this group is the first in the list.

func (*Group) Relationship

func (g *Group) Relationship() EClanRelationship

func (*Group) SteamId

func (g *Group) SteamId() SteamId

type GroupStateEvent

type GroupStateEvent struct {
	SteamId      SteamId
	Relationship EClanRelationship
}

type GroupsList

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

func (*GroupsList) ById

func (list *GroupsList) ById(id SteamId) *Group

Returns the group by a SteamId or nil if there is no such group.

func (*GroupsList) First

func (list *GroupsList) First() *Group

Returns the first group in the group list or nil if the list is empty.

func (*GroupsList) Last

func (list *GroupsList) Last() *Group

Returns the last group in the group list or nil if the list is empty.

type LogOnDetails

type LogOnDetails struct {
	Username       string
	Password       string
	AuthCode       string
	SentryFileHash []byte
}

type LoggedOnEvent

type LoggedOnEvent struct{}

type MachineAuthUpdateEvent

type MachineAuthUpdateEvent struct {
	Hash []byte
}

type PacketHandler

type PacketHandler interface {
	HandlePacket(*PacketMsg)
}

type Social

type Social struct {
	Friends *FriendsList
	Groups  *GroupsList
	// contains filtered or unexported fields
}

Provides access to social aspects of Steam.

Friend and group lists are implemented as doubly-linked lists for thread-safety. They can be iterated over like so:

for friend := client.Social.Friends.First(); friend != nil; friend = friend.Next() {
	log.Println(friend.SteamId())
}

func (*Social) AddFriend

func (s *Social) AddFriend(id SteamId)

Adds a friend to your friends list or accepts a friend. You'll receive a FriendStateEvent for every new/changed friend.

func (*Social) ChangeStatus

func (s *Social) ChangeStatus(status *CMsgClientChangeStatus)

func (*Social) HandlePacket

func (s *Social) HandlePacket(packet *PacketMsg)

func (*Social) RemoveFriend

func (s *Social) RemoveFriend(id SteamId)

func (*Social) SendChatMessage

func (s *Social) SendChatMessage(to SteamId, message string)

Sends a chat message to the given friend. Chatrooms/Group chats are not supported yet. This just calls SendMessage with EChatEntryType_ChatMsg as the entry type.

func (*Social) SendMessage

func (s *Social) SendMessage(to SteamId, message string, entryType EChatEntryType)

Sends a chat message to the given friend. Chatrooms/Group chats are not supported yet.

func (*Social) SetPersonaName

func (s *Social) SetPersonaName(name string)

func (*Social) SetPersonaState

func (s *Social) SetPersonaState(state EPersonaState)

type TradeProposedEvent

type TradeProposedEvent struct {
	RequestId TradeRequestId
	Other     SteamId
	OtherName string
}

type TradeRequestId

type TradeRequestId uint32

type TradeResultEvent

type TradeResultEvent struct {
	RequestId TradeRequestId
	Response  EEconTradeResponse
	Other     SteamId
}

type TradeSessionStartEvent

type TradeSessionStartEvent struct {
	Other SteamId
}

type Trading

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

Provides access to the Steam client's part of Steam Trading, that is bootstrapping the trade. The trade itself is not handled by the Steam client itself, but it's a part of the Steam website.

You'll receive a TradeProposedEvent when a friend proposes a trade. You can accept it with the RespondRequest method. You can request a trade yourself with RequestTrade.

func (*Trading) CancelRequest

func (t *Trading) CancelRequest(other SteamId)

This cancels a request made with RequestTrade.

func (*Trading) HandlePacket

func (t *Trading) HandlePacket(packet *PacketMsg)

func (*Trading) RequestTrade

func (t *Trading) RequestTrade(other SteamId)

Requests a trade. You'll receive a TradeResultEvent if the request fails or if the friend accepted the trade.

func (*Trading) RespondRequest

func (t *Trading) RespondRequest(requestId TradeRequestId, accept bool)

Responds to a TradeProposedEvent.

type Web

type Web struct {
	// The `sessionid` cookie required to use the steam website.
	WebSessionId string
	// The `steamLogin` cookie required to use the steam website.
	// It is only available after calling LogOn().
	SteamLogin string
	// contains filtered or unexported fields
}

func (*Web) HandlePacket

func (w *Web) HandlePacket(packet *PacketMsg)

func (*Web) LogOn

func (w *Web) LogOn()

Fetches the `steamLogin` cookie. This may only be called after the first WebSessionIdEvent or it will panic.

type WebLoggedOnEvent

type WebLoggedOnEvent struct{}

type WebSessionIdEvent

type WebSessionIdEvent struct{}

Directories

Path Synopsis
This program generates the protobuf and SteamLanguage files from the SteamKit data.
This program generates the protobuf and SteamLanguage files from the SteamKit data.
Package content_manifest is a generated protocol buffer package.
Package content_manifest is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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