summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/Philipp15b/go-steam/tf2/tf2.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-06-22 01:00:27 +0200
committerWim <wim@42.be>2017-06-22 01:00:27 +0200
commit1f914618538920db4bfec7b106ee97038b157c9b (patch)
tree6bd0ab107fe1673dbacdf9dfd10004289cd7bfab /vendor/github.com/Philipp15b/go-steam/tf2/tf2.go
parent1f9874102aaca09ce5e0289beff376c307b8c57b (diff)
downloadmatterbridge-msglm-1f914618538920db4bfec7b106ee97038b157c9b.tar.gz
matterbridge-msglm-1f914618538920db4bfec7b106ee97038b157c9b.tar.bz2
matterbridge-msglm-1f914618538920db4bfec7b106ee97038b157c9b.zip
Add vendor (steam)
Diffstat (limited to 'vendor/github.com/Philipp15b/go-steam/tf2/tf2.go')
-rw-r--r--vendor/github.com/Philipp15b/go-steam/tf2/tf2.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/github.com/Philipp15b/go-steam/tf2/tf2.go b/vendor/github.com/Philipp15b/go-steam/tf2/tf2.go
new file mode 100644
index 00000000..334362de
--- /dev/null
+++ b/vendor/github.com/Philipp15b/go-steam/tf2/tf2.go
@@ -0,0 +1,75 @@
+/*
+Provides access to TF2 Game Coordinator functionality.
+*/
+package tf2
+
+import (
+ "github.com/Philipp15b/go-steam"
+ . "github.com/Philipp15b/go-steam/protocol/gamecoordinator"
+ . "github.com/Philipp15b/go-steam/tf2/protocol"
+ "github.com/Philipp15b/go-steam/tf2/protocol/protobuf"
+)
+
+const AppId = 440
+
+// To use any methods of this, you'll need to SetPlaying(true) and wait for
+// the GCReadyEvent.
+type TF2 struct {
+ client *steam.Client
+}
+
+// Creates a new TF2 instance and registers it as a packet handler
+func New(client *steam.Client) *TF2 {
+ t := &TF2{client}
+ client.GC.RegisterPacketHandler(t)
+ return t
+}
+
+func (t *TF2) SetPlaying(playing bool) {
+ if playing {
+ t.client.GC.SetGamesPlayed(AppId)
+ } else {
+ t.client.GC.SetGamesPlayed()
+ }
+}
+
+func (t *TF2) SetItemPosition(itemId, position uint64) {
+ t.client.GC.Write(NewGCMsg(AppId, uint32(protobuf.EGCItemMsg_k_EMsgGCSetSingleItemPosition), &MsgGCSetItemPosition{
+ itemId, position,
+ }))
+}
+
+// recipe -2 = wildcard
+func (t *TF2) CraftItems(items []uint64, recipe int16) {
+ t.client.GC.Write(NewGCMsg(AppId, uint32(protobuf.EGCItemMsg_k_EMsgGCCraft), &MsgGCCraft{
+ Recipe: recipe,
+ Items: items,
+ }))
+}
+
+func (t *TF2) DeleteItem(itemId uint64) {
+ t.client.GC.Write(NewGCMsg(AppId, uint32(protobuf.EGCItemMsg_k_EMsgGCDelete), &MsgGCDeleteItem{itemId}))
+}
+
+func (t *TF2) NameItem(toolId, target uint64, name string) {
+ t.client.GC.Write(NewGCMsg(AppId, uint32(protobuf.EGCItemMsg_k_EMsgGCNameItem), &MsgGCNameItem{
+ toolId, target, name,
+ }))
+}
+
+type GCReadyEvent struct{}
+
+func (t *TF2) HandleGCPacket(packet *GCPacket) {
+ if packet.AppId != AppId {
+ return
+ }
+ switch protobuf.EGCBaseClientMsg(packet.MsgType) {
+ case protobuf.EGCBaseClientMsg_k_EMsgGCClientWelcome:
+ t.handleWelcome(packet)
+ }
+}
+
+func (t *TF2) handleWelcome(packet *GCPacket) {
+ // the packet's body is pretty useless
+ t.client.Emit(&GCReadyEvent{})
+}