diff options
Diffstat (limited to 'vendor/github.com/Philipp15b/go-steam/gamecoordinator.go')
-rw-r--r-- | vendor/github.com/Philipp15b/go-steam/gamecoordinator.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/github.com/Philipp15b/go-steam/gamecoordinator.go b/vendor/github.com/Philipp15b/go-steam/gamecoordinator.go new file mode 100644 index 00000000..9e06dad2 --- /dev/null +++ b/vendor/github.com/Philipp15b/go-steam/gamecoordinator.go @@ -0,0 +1,79 @@ +package steam + +import ( + "bytes" + . "github.com/Philipp15b/go-steam/protocol" + . "github.com/Philipp15b/go-steam/protocol/gamecoordinator" + . "github.com/Philipp15b/go-steam/protocol/protobuf" + . "github.com/Philipp15b/go-steam/protocol/steamlang" + "github.com/golang/protobuf/proto" +) + +type GameCoordinator struct { + client *Client + handlers []GCPacketHandler +} + +func newGC(client *Client) *GameCoordinator { + return &GameCoordinator{ + client: client, + handlers: make([]GCPacketHandler, 0), + } +} + +type GCPacketHandler interface { + HandleGCPacket(*GCPacket) +} + +func (g *GameCoordinator) RegisterPacketHandler(handler GCPacketHandler) { + g.handlers = append(g.handlers, handler) +} + +func (g *GameCoordinator) HandlePacket(packet *Packet) { + if packet.EMsg != EMsg_ClientFromGC { + return + } + + msg := new(CMsgGCClient) + packet.ReadProtoMsg(msg) + + p, err := NewGCPacket(msg) + if err != nil { + g.client.Errorf("Error reading GC message: %v", err) + return + } + + for _, handler := range g.handlers { + handler.HandleGCPacket(p) + } +} + +func (g *GameCoordinator) Write(msg IGCMsg) { + buf := new(bytes.Buffer) + msg.Serialize(buf) + + msgType := msg.GetMsgType() + if msg.IsProto() { + msgType = msgType | 0x80000000 // mask with protoMask + } + + g.client.Write(NewClientMsgProtobuf(EMsg_ClientToGC, &CMsgGCClient{ + Msgtype: proto.Uint32(msgType), + Appid: proto.Uint32(msg.GetAppId()), + Payload: buf.Bytes(), + })) +} + +// Sets you in the given games. Specify none to quit all games. +func (g *GameCoordinator) SetGamesPlayed(appIds ...uint64) { + games := make([]*CMsgClientGamesPlayed_GamePlayed, 0) + for _, appId := range appIds { + games = append(games, &CMsgClientGamesPlayed_GamePlayed{ + GameId: proto.Uint64(appId), + }) + } + + g.client.Write(NewClientMsgProtobuf(EMsg_ClientGamesPlayed, &CMsgClientGamesPlayed{ + GamesPlayed: games, + })) +} |