From 3be6bb041f1520c441adc927ed8f9a48b2ae32a8 Mon Sep 17 00:00:00 2001 From: James Eagle Date: Sat, 24 Apr 2021 23:31:14 +0100 Subject: [PATCH 1/3] Remove dot aliases --- auth.go | 78 +++---- auth_events.go | 18 +- client.go | 64 +++--- connection.go | 8 +- gamecoordinator.go | 28 +-- keys.go | 12 +- notifications.go | 14 +- protocol/gamecoordinator/msg.go | 50 ++-- protocol/gamecoordinator/packet.go | 24 +- protocol/internal.go | 10 +- protocol/msg.go | 42 ++-- protocol/packet.go | 22 +- protocol/steamlang/messages.go | 10 +- social.go | 356 ++++++++++++++--------------- social_events.go | 88 +++---- socialcache/chats.go | 44 ++-- socialcache/friends.go | 44 ++-- socialcache/groups.go | 38 +-- tf2/tf2.go | 16 +- trading.go | 40 ++-- trading_events.go | 12 +- web.go | 26 +-- 22 files changed, 522 insertions(+), 522 deletions(-) diff --git a/auth.go b/auth.go index ea738dc8..bb62972c 100644 --- a/auth.go +++ b/auth.go @@ -5,10 +5,10 @@ import ( "sync/atomic" "time" - . "github.com/Philipp15b/go-steam/v2/protocol" - . "github.com/Philipp15b/go-steam/v2/protocol/protobuf" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" - . "github.com/Philipp15b/go-steam/v2/steamid" + "github.com/Philipp15b/go-steam/v2/protocol" + "github.com/Philipp15b/go-steam/v2/protocol/protobuf" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/steamid" "github.com/golang/protobuf/proto" ) @@ -57,7 +57,7 @@ func (a *Auth) LogOn(details *LogOnDetails) { panic("Password or LoginKey must be set!") } - logon := new(CMsgClientLogon) + logon := new(protobuf.CMsgClientLogon) logon.AccountName = &details.Username logon.Password = &details.Password if details.AuthCode != "" { @@ -67,7 +67,7 @@ func (a *Auth) LogOn(details *LogOnDetails) { logon.TwoFactorCode = proto.String(details.TwoFactorCode) } logon.ClientLanguage = proto.String("english") - logon.ProtocolVersion = proto.Uint32(MsgClientLogon_CurrentProtocol) + logon.ProtocolVersion = proto.Uint32(steamlang.MsgClientLogon_CurrentProtocol) logon.ShaSentryfile = details.SentryFileHash if details.LoginKey != "" { logon.LoginKey = proto.String(details.LoginKey) @@ -76,38 +76,38 @@ func (a *Auth) LogOn(details *LogOnDetails) { logon.ShouldRememberPassword = proto.Bool(details.ShouldRememberPassword) } - atomic.StoreUint64(&a.client.steamId, uint64(NewIdAdv(0, 1, int32(EUniverse_Public), int32(EAccountType_Individual)))) + atomic.StoreUint64(&a.client.steamId, uint64(steamid.NewIdAdv(0, 1, int32(steamlang.EUniverse_Public), int32(steamlang.EAccountType_Individual)))) - a.client.Write(NewClientMsgProtobuf(EMsg_ClientLogon, logon)) + a.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientLogon, logon)) } -func (a *Auth) HandlePacket(packet *Packet) { +func (a *Auth) HandlePacket(packet *protocol.Packet) { switch packet.EMsg { - case EMsg_ClientLogOnResponse: + case steamlang.EMsg_ClientLogOnResponse: a.handleLogOnResponse(packet) - case EMsg_ClientNewLoginKey: + case steamlang.EMsg_ClientNewLoginKey: a.handleLoginKey(packet) - case EMsg_ClientSessionToken: - case EMsg_ClientLoggedOff: + case steamlang.EMsg_ClientSessionToken: + case steamlang.EMsg_ClientLoggedOff: a.handleLoggedOff(packet) - case EMsg_ClientUpdateMachineAuth: + case steamlang.EMsg_ClientUpdateMachineAuth: a.handleUpdateMachineAuth(packet) - case EMsg_ClientAccountInfo: + case steamlang.EMsg_ClientAccountInfo: a.handleAccountInfo(packet) } } -func (a *Auth) handleLogOnResponse(packet *Packet) { +func (a *Auth) handleLogOnResponse(packet *protocol.Packet) { if !packet.IsProto { a.client.Fatalf("Got non-proto logon response!") return } - body := new(CMsgClientLogonResponse) + body := new(protobuf.CMsgClientLogonResponse) msg := packet.ReadProtoMsg(body) - result := EResult(body.GetEresult()) - if result == EResult_OK { + result := steamlang.EResult(body.GetEresult()) + if result == steamlang.EResult_OK { atomic.StoreInt32(&a.client.sessionId, msg.Header.Proto.GetClientSessionid()) atomic.StoreUint64(&a.client.steamId, msg.Header.Proto.GetSteamid()) a.client.Web.webLoginKey = *body.WebapiAuthenticateUserNonce @@ -115,14 +115,14 @@ func (a *Auth) handleLogOnResponse(packet *Packet) { go a.client.heartbeatLoop(time.Duration(body.GetOutOfGameHeartbeatSeconds())) a.client.Emit(&LoggedOnEvent{ - Result: EResult(body.GetEresult()), - ExtendedResult: EResult(body.GetEresultExtended()), + Result: steamlang.EResult(body.GetEresult()), + ExtendedResult: steamlang.EResult(body.GetEresultExtended()), OutOfGameSecsPerHeartbeat: body.GetOutOfGameHeartbeatSeconds(), InGameSecsPerHeartbeat: body.GetInGameHeartbeatSeconds(), PublicIp: body.GetDeprecatedPublicIp(), ServerTime: body.GetRtime32ServerTime(), - AccountFlags: EAccountFlags(body.GetAccountFlags()), - ClientSteamId: SteamId(body.GetClientSuppliedSteamid()), + AccountFlags: steamlang.EAccountFlags(body.GetAccountFlags()), + ClientSteamId: steamid.SteamId(body.GetClientSuppliedSteamid()), EmailDomain: body.GetEmailDomain(), CellId: body.GetCellId(), CellIdPingThreshold: body.GetCellIdPingThreshold(), @@ -134,20 +134,20 @@ func (a *Auth) handleLogOnResponse(packet *Packet) { NumLoginFailuresToMigrate: body.GetCountLoginfailuresToMigrate(), NumDisconnectsToMigrate: body.GetCountDisconnectsToMigrate(), }) - } else if result == EResult_Fail || result == EResult_ServiceUnavailable || result == EResult_TryAnotherCM { + } else if result == steamlang.EResult_Fail || result == steamlang.EResult_ServiceUnavailable || result == steamlang.EResult_TryAnotherCM { // some error on Steam's side, we'll get an EOF later } else { a.client.Emit(&LogOnFailedEvent{ - Result: EResult(body.GetEresult()), + Result: steamlang.EResult(body.GetEresult()), }) a.client.Disconnect() } } -func (a *Auth) handleLoginKey(packet *Packet) { - body := new(CMsgClientNewLoginKey) +func (a *Auth) handleLoginKey(packet *protocol.Packet) { + body := new(protobuf.CMsgClientNewLoginKey) packet.ReadProtoMsg(body) - a.client.Write(NewClientMsgProtobuf(EMsg_ClientNewLoginKeyAccepted, &CMsgClientNewLoginKeyAccepted{ + a.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientNewLoginKeyAccepted, &protobuf.CMsgClientNewLoginKeyAccepted{ UniqueId: proto.Uint32(body.GetUniqueId()), })) a.client.Emit(&LoginKeyEvent{ @@ -156,28 +156,28 @@ func (a *Auth) handleLoginKey(packet *Packet) { }) } -func (a *Auth) handleLoggedOff(packet *Packet) { - result := EResult_Invalid +func (a *Auth) handleLoggedOff(packet *protocol.Packet) { + result := steamlang.EResult_Invalid if packet.IsProto { - body := new(CMsgClientLoggedOff) + body := new(protobuf.CMsgClientLoggedOff) packet.ReadProtoMsg(body) - result = EResult(body.GetEresult()) + result = steamlang.EResult(body.GetEresult()) } else { - body := new(MsgClientLoggedOff) + body := new(steamlang.MsgClientLoggedOff) packet.ReadClientMsg(body) result = body.Result } a.client.Emit(&LoggedOffEvent{Result: result}) } -func (a *Auth) handleUpdateMachineAuth(packet *Packet) { - body := new(CMsgClientUpdateMachineAuth) +func (a *Auth) handleUpdateMachineAuth(packet *protocol.Packet) { + body := new(protobuf.CMsgClientUpdateMachineAuth) packet.ReadProtoMsg(body) hash := sha1.New() hash.Write(packet.Data) sha := hash.Sum(nil) - msg := NewClientMsgProtobuf(EMsg_ClientUpdateMachineAuthResponse, &CMsgClientUpdateMachineAuthResponse{ + msg := protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientUpdateMachineAuthResponse, &protobuf.CMsgClientUpdateMachineAuthResponse{ ShaFile: sha, }) msg.SetTargetJobId(packet.SourceJobId) @@ -186,14 +186,14 @@ func (a *Auth) handleUpdateMachineAuth(packet *Packet) { a.client.Emit(&MachineAuthUpdateEvent{sha}) } -func (a *Auth) handleAccountInfo(packet *Packet) { - body := new(CMsgClientAccountInfo) +func (a *Auth) handleAccountInfo(packet *protocol.Packet) { + body := new(protobuf.CMsgClientAccountInfo) packet.ReadProtoMsg(body) a.client.Emit(&AccountInfoEvent{ PersonaName: body.GetPersonaName(), Country: body.GetIpCountry(), CountAuthedComputers: body.GetCountAuthedComputers(), - AccountFlags: EAccountFlags(body.GetAccountFlags()), + AccountFlags: steamlang.EAccountFlags(body.GetAccountFlags()), FacebookId: body.GetFacebookId(), FacebookName: body.GetFacebookName(), }) diff --git a/auth_events.go b/auth_events.go index 36433c98..d9d804bc 100644 --- a/auth_events.go +++ b/auth_events.go @@ -1,19 +1,19 @@ package steam import ( - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" - . "github.com/Philipp15b/go-steam/v2/steamid" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/steamid" ) type LoggedOnEvent struct { - Result EResult - ExtendedResult EResult + Result steamlang.EResult + ExtendedResult steamlang.EResult OutOfGameSecsPerHeartbeat int32 InGameSecsPerHeartbeat int32 PublicIp uint32 ServerTime uint32 - AccountFlags EAccountFlags - ClientSteamId SteamId `json:",string"` + AccountFlags steamlang.EAccountFlags + ClientSteamId steamid.SteamId `json:",string"` EmailDomain string CellId uint32 CellIdPingThreshold uint32 @@ -27,7 +27,7 @@ type LoggedOnEvent struct { } type LogOnFailedEvent struct { - Result EResult + Result steamlang.EResult } type LoginKeyEvent struct { @@ -36,7 +36,7 @@ type LoginKeyEvent struct { } type LoggedOffEvent struct { - Result EResult + Result steamlang.EResult } type MachineAuthUpdateEvent struct { @@ -47,7 +47,7 @@ type AccountInfoEvent struct { PersonaName string Country string CountAuthedComputers int32 - AccountFlags EAccountFlags + AccountFlags steamlang.EAccountFlags FacebookId uint64 `json:",string"` FacebookName string } diff --git a/client.go b/client.go index 76c5b360..36692afa 100644 --- a/client.go +++ b/client.go @@ -15,10 +15,10 @@ import ( "github.com/Philipp15b/go-steam/v2/cryptoutil" "github.com/Philipp15b/go-steam/v2/netutil" - . "github.com/Philipp15b/go-steam/v2/protocol" - . "github.com/Philipp15b/go-steam/v2/protocol/protobuf" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" - . "github.com/Philipp15b/go-steam/v2/steamid" + "github.com/Philipp15b/go-steam/v2/protocol" + "github.com/Philipp15b/go-steam/v2/protocol/protobuf" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/steamid" ) // Represents a client to the Steam network. @@ -51,13 +51,13 @@ type Client struct { mutex sync.RWMutex // guarding conn and writeChan conn connection - writeChan chan IMsg + writeChan chan protocol.IMsg writeBuf *bytes.Buffer heartbeat *time.Ticker } type PacketHandler interface { - HandlePacket(*Packet) + HandlePacket(*protocol.Packet) } func NewClient() *Client { @@ -108,12 +108,12 @@ func (c *Client) RegisterPacketHandler(handler PacketHandler) { c.handlers = append(c.handlers, handler) } -func (c *Client) GetNextJobId() JobId { - return JobId(atomic.AddUint64(&c.currentJobId, 1)) +func (c *Client) GetNextJobId() protocol.JobId { + return protocol.JobId(atomic.AddUint64(&c.currentJobId, 1)) } -func (c *Client) SteamId() SteamId { - return SteamId(atomic.LoadUint64(&c.steamId)) +func (c *Client) SteamId() steamid.SteamId { + return steamid.SteamId(atomic.LoadUint64(&c.steamId)) } func (c *Client) SessionId() int32 { @@ -166,7 +166,7 @@ func (c *Client) ConnectToBind(addr *netutil.PortAddr, local *net.TCPAddr) error return err } c.conn = conn - c.writeChan = make(chan IMsg, 5) + c.writeChan = make(chan protocol.IMsg, 5) go c.readLoop() go c.writeLoop() @@ -196,8 +196,8 @@ func (c *Client) Disconnect() { // writing are not allowed (possible race conditions). // // Writes to this client when not connected are ignored. -func (c *Client) Write(msg IMsg) { - if cm, ok := msg.(IClientMsg); ok { +func (c *Client) Write(msg protocol.IMsg) { + if cm, ok := msg.(protocol.IClientMsg); ok { cm.SetSessionId(c.SessionId()) cm.SetSteamId(c.SteamId()) } @@ -270,20 +270,20 @@ func (c *Client) heartbeatLoop(seconds time.Duration) { if !ok { break } - c.Write(NewClientMsgProtobuf(EMsg_ClientHeartBeat, new(CMsgClientHeartBeat))) + c.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientHeartBeat, new(protobuf.CMsgClientHeartBeat))) } c.heartbeat = nil } -func (c *Client) handlePacket(packet *Packet) { +func (c *Client) handlePacket(packet *protocol.Packet) { switch packet.EMsg { - case EMsg_ChannelEncryptRequest: + case steamlang.EMsg_ChannelEncryptRequest: c.handleChannelEncryptRequest(packet) - case EMsg_ChannelEncryptResult: + case steamlang.EMsg_ChannelEncryptResult: c.handleChannelEncryptResult(packet) - case EMsg_Multi: + case steamlang.EMsg_Multi: c.handleMulti(packet) - case EMsg_ClientCMList: + case steamlang.EMsg_ClientCMList: c.handleClientCMList(packet) } @@ -294,17 +294,17 @@ func (c *Client) handlePacket(packet *Packet) { } } -func (c *Client) handleChannelEncryptRequest(packet *Packet) { - body := NewMsgChannelEncryptRequest() +func (c *Client) handleChannelEncryptRequest(packet *protocol.Packet) { + body := steamlang.NewMsgChannelEncryptRequest() packet.ReadMsg(body) - if body.Universe != EUniverse_Public { + if body.Universe != steamlang.EUniverse_Public { c.Fatalf("Invalid univserse %v!", body.Universe) } c.tempSessionKey = make([]byte, 32) rand.Read(c.tempSessionKey) - encryptedKey := cryptoutil.RSAEncrypt(GetPublicKey(EUniverse_Public), c.tempSessionKey) + encryptedKey := cryptoutil.RSAEncrypt(GetPublicKey(steamlang.EUniverse_Public), c.tempSessionKey) payload := new(bytes.Buffer) payload.Write(encryptedKey) @@ -314,14 +314,14 @@ func (c *Client) handleChannelEncryptRequest(packet *Packet) { payload.WriteByte(0) payload.WriteByte(0) - c.Write(NewMsg(NewMsgChannelEncryptResponse(), payload.Bytes())) + c.Write(protocol.NewMsg(steamlang.NewMsgChannelEncryptResponse(), payload.Bytes())) } -func (c *Client) handleChannelEncryptResult(packet *Packet) { - body := NewMsgChannelEncryptResult() +func (c *Client) handleChannelEncryptResult(packet *protocol.Packet) { + body := steamlang.NewMsgChannelEncryptResult() packet.ReadMsg(body) - if body.Result != EResult_OK { + if body.Result != steamlang.EResult_OK { c.Fatalf("Encryption failed: %v", body.Result) return } @@ -331,8 +331,8 @@ func (c *Client) handleChannelEncryptResult(packet *Packet) { c.Emit(&ConnectedEvent{}) } -func (c *Client) handleMulti(packet *Packet) { - body := new(CMsgMulti) +func (c *Client) handleMulti(packet *protocol.Packet) { + body := new(protobuf.CMsgMulti) packet.ReadProtoMsg(body) payload := body.GetMessageBody() @@ -357,7 +357,7 @@ func (c *Client) handleMulti(packet *Packet) { binary.Read(pr, binary.LittleEndian, &length) packetData := make([]byte, length) pr.Read(packetData) - p, err := NewPacket(packetData) + p, err := protocol.NewPacket(packetData) if err != nil { c.Errorf("Error reading packet in Multi msg %v: %v", packet, err) continue @@ -366,8 +366,8 @@ func (c *Client) handleMulti(packet *Packet) { } } -func (c *Client) handleClientCMList(packet *Packet) { - body := new(CMsgClientCMList) +func (c *Client) handleClientCMList(packet *protocol.Packet) { + body := new(protobuf.CMsgClientCMList) packet.ReadProtoMsg(body) l := make([]*netutil.PortAddr, 0) diff --git a/connection.go b/connection.go index d9902a23..d0085805 100644 --- a/connection.go +++ b/connection.go @@ -10,11 +10,11 @@ import ( "sync" "github.com/Philipp15b/go-steam/v2/cryptoutil" - . "github.com/Philipp15b/go-steam/v2/protocol" + "github.com/Philipp15b/go-steam/v2/protocol" ) type connection interface { - Read() (*Packet, error) + Read() (*protocol.Packet, error) Write([]byte) error Close() error SetEncryptionKey([]byte) @@ -40,7 +40,7 @@ func dialTCP(laddr, raddr *net.TCPAddr) (*tcpConnection, error) { }, nil } -func (c *tcpConnection) Read() (*Packet, error) { +func (c *tcpConnection) Read() (*protocol.Packet, error) { // All packets begin with a packet length var packetLen uint32 err := binary.Read(c.conn, binary.LittleEndian, &packetLen) @@ -74,7 +74,7 @@ func (c *tcpConnection) Read() (*Packet, error) { } c.cipherMutex.RUnlock() - return NewPacket(buf) + return protocol.NewPacket(buf) } // Writes a message. This may only be used by one goroutine at a time. diff --git a/gamecoordinator.go b/gamecoordinator.go index 65a8124b..ef54cca4 100644 --- a/gamecoordinator.go +++ b/gamecoordinator.go @@ -3,10 +3,10 @@ package steam import ( "bytes" - . "github.com/Philipp15b/go-steam/v2/protocol" - . "github.com/Philipp15b/go-steam/v2/protocol/gamecoordinator" - . "github.com/Philipp15b/go-steam/v2/protocol/protobuf" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/protocol" + "github.com/Philipp15b/go-steam/v2/protocol/gamecoordinator" + "github.com/Philipp15b/go-steam/v2/protocol/protobuf" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" "github.com/golang/protobuf/proto" ) @@ -23,22 +23,22 @@ func newGC(client *Client) *GameCoordinator { } type GCPacketHandler interface { - HandleGCPacket(*GCPacket) + HandleGCPacket(*gamecoordinator.GCPacket) } func (g *GameCoordinator) RegisterPacketHandler(handler GCPacketHandler) { g.handlers = append(g.handlers, handler) } -func (g *GameCoordinator) HandlePacket(packet *Packet) { - if packet.EMsg != EMsg_ClientFromGC { +func (g *GameCoordinator) HandlePacket(packet *protocol.Packet) { + if packet.EMsg != steamlang.EMsg_ClientFromGC { return } - msg := new(CMsgGCClient) + msg := new(protobuf.CMsgGCClient) packet.ReadProtoMsg(msg) - p, err := NewGCPacket(msg) + p, err := gamecoordinator.NewGCPacket(msg) if err != nil { g.client.Errorf("Error reading GC message: %v", err) return @@ -49,7 +49,7 @@ func (g *GameCoordinator) HandlePacket(packet *Packet) { } } -func (g *GameCoordinator) Write(msg IGCMsg) { +func (g *GameCoordinator) Write(msg gamecoordinator.IGCMsg) { buf := new(bytes.Buffer) msg.Serialize(buf) @@ -58,7 +58,7 @@ func (g *GameCoordinator) Write(msg IGCMsg) { msgType = msgType | 0x80000000 // mask with protoMask } - g.client.Write(NewClientMsgProtobuf(EMsg_ClientToGC, &CMsgGCClient{ + g.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientToGC, &protobuf.CMsgGCClient{ Msgtype: proto.Uint32(msgType), Appid: proto.Uint32(msg.GetAppId()), Payload: buf.Bytes(), @@ -67,14 +67,14 @@ func (g *GameCoordinator) Write(msg IGCMsg) { // Sets you in the given games. Specify none to quit all games. func (g *GameCoordinator) SetGamesPlayed(appIds ...uint64) { - games := make([]*CMsgClientGamesPlayed_GamePlayed, 0) + games := make([]*protobuf.CMsgClientGamesPlayed_GamePlayed, 0) for _, appId := range appIds { - games = append(games, &CMsgClientGamesPlayed_GamePlayed{ + games = append(games, &protobuf.CMsgClientGamesPlayed_GamePlayed{ GameId: proto.Uint64(appId), }) } - g.client.Write(NewClientMsgProtobuf(EMsg_ClientGamesPlayed, &CMsgClientGamesPlayed{ + g.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientGamesPlayed, &protobuf.CMsgClientGamesPlayed{ GamesPlayed: games, })) } diff --git a/keys.go b/keys.go index e48bdc37..d5b7f156 100644 --- a/keys.go +++ b/keys.go @@ -4,11 +4,11 @@ import ( "crypto/rsa" "github.com/Philipp15b/go-steam/v2/cryptoutil" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" ) -var publicKeys = map[EUniverse][]byte{ - EUniverse_Public: []byte{ +var publicKeys = map[steamlang.EUniverse][]byte{ + steamlang.EUniverse_Public: { 0x30, 0x81, 0x9D, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8B, 0x00, 0x30, 0x81, 0x87, 0x02, 0x81, 0x81, 0x00, 0xDF, 0xEC, 0x1A, 0xD6, 0x2C, 0x10, 0x66, 0x2C, 0x17, 0x35, 0x3A, 0x14, 0xB0, 0x7C, 0x59, 0x11, 0x7F, 0x9D, 0xD3, @@ -21,7 +21,7 @@ var publicKeys = map[EUniverse][]byte{ 0xE9, 0x63, 0xA2, 0xBB, 0x88, 0x19, 0x28, 0xE0, 0xE7, 0x14, 0xC0, 0x42, 0x89, 0x02, 0x01, 0x11, }, - EUniverse_Beta: []byte{ + steamlang.EUniverse_Beta: { 0x30, 0x81, 0x9D, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8B, 0x00, 0x30, 0x81, 0x87, 0x02, 0x81, 0x81, 0x00, 0xAE, 0xD1, 0x4B, 0xC0, 0xA3, 0x36, 0x8B, 0xA0, 0x39, 0x0B, 0x43, 0xDC, 0xED, 0x6A, 0xC8, 0xF2, 0xA3, 0xE4, 0x7E, @@ -33,7 +33,7 @@ var publicKeys = map[EUniverse][]byte{ 0x78, 0x3F, 0x17, 0x4B, 0xCB, 0xC9, 0x01, 0x5D, 0x3E, 0x37, 0x70, 0xEC, 0x67, 0x5A, 0x33, 0x48, }, - EUniverse_Internal: []byte{ + steamlang.EUniverse_Internal: { 0x30, 0x81, 0x9D, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8B, 0x00, 0x30, 0x81, 0x87, 0x02, 0x81, 0x81, 0x00, 0xA8, 0xFE, 0x01, 0x3B, 0xB6, 0xD7, 0x21, 0x4B, 0x53, 0x23, 0x6F, 0xA1, 0xAB, 0x4E, 0xF1, 0x07, 0x30, 0xA7, 0xC6, @@ -46,7 +46,7 @@ var publicKeys = map[EUniverse][]byte{ }, } -func GetPublicKey(universe EUniverse) *rsa.PublicKey { +func GetPublicKey(universe steamlang.EUniverse) *rsa.PublicKey { bytes, ok := publicKeys[universe] if !ok { return nil diff --git a/notifications.go b/notifications.go index 5b73046c..a01c49ac 100644 --- a/notifications.go +++ b/notifications.go @@ -1,9 +1,9 @@ package steam import ( - . "github.com/Philipp15b/go-steam/v2/protocol" - . "github.com/Philipp15b/go-steam/v2/protocol/protobuf" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/protocol" + "github.com/Philipp15b/go-steam/v2/protocol/protobuf" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" ) type Notifications struct { @@ -20,9 +20,9 @@ func newNotifications(client *Client) *Notifications { } } -func (n *Notifications) HandlePacket(packet *Packet) { +func (n *Notifications) HandlePacket(packet *protocol.Packet) { switch packet.EMsg { - case EMsg_ClientUserNotifications: + case steamlang.EMsg_ClientUserNotifications: n.handleClientUserNotifications(packet) } } @@ -33,8 +33,8 @@ const ( TradeOffer NotificationType = 1 ) -func (n *Notifications) handleClientUserNotifications(packet *Packet) { - msg := new(CMsgClientUserNotifications) +func (n *Notifications) handleClientUserNotifications(packet *protocol.Packet) { + msg := new(protobuf.CMsgClientUserNotifications) packet.ReadProtoMsg(msg) for _, notification := range msg.GetNotifications() { diff --git a/protocol/gamecoordinator/msg.go b/protocol/gamecoordinator/msg.go index 59bf5bb0..604d6eb2 100644 --- a/protocol/gamecoordinator/msg.go +++ b/protocol/gamecoordinator/msg.go @@ -3,32 +3,32 @@ package gamecoordinator import ( "io" - . "github.com/Philipp15b/go-steam/v2/protocol" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/protocol" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" "github.com/golang/protobuf/proto" ) // An outgoing message to the Game Coordinator. type IGCMsg interface { - Serializer + protocol.Serializer IsProto() bool GetAppId() uint32 GetMsgType() uint32 - GetTargetJobId() JobId - SetTargetJobId(JobId) - GetSourceJobId() JobId - SetSourceJobId(JobId) + GetTargetJobId() protocol.JobId + SetTargetJobId(protocol.JobId) + GetSourceJobId() protocol.JobId + SetSourceJobId(protocol.JobId) } type GCMsgProtobuf struct { AppId uint32 - Header *MsgGCHdrProtoBuf + Header *steamlang.MsgGCHdrProtoBuf Body proto.Message } func NewGCMsgProtobuf(appId, msgType uint32, body proto.Message) *GCMsgProtobuf { - hdr := NewMsgGCHdrProtoBuf() + hdr := steamlang.NewMsgGCHdrProtoBuf() hdr.Msg = msgType return &GCMsgProtobuf{ AppId: appId, @@ -49,19 +49,19 @@ func (g *GCMsgProtobuf) GetMsgType() uint32 { return g.Header.Msg } -func (g *GCMsgProtobuf) GetTargetJobId() JobId { - return JobId(g.Header.Proto.GetJobidTarget()) +func (g *GCMsgProtobuf) GetTargetJobId() protocol.JobId { + return protocol.JobId(g.Header.Proto.GetJobidTarget()) } -func (g *GCMsgProtobuf) SetTargetJobId(job JobId) { +func (g *GCMsgProtobuf) SetTargetJobId(job protocol.JobId) { g.Header.Proto.JobidTarget = proto.Uint64(uint64(job)) } -func (g *GCMsgProtobuf) GetSourceJobId() JobId { - return JobId(g.Header.Proto.GetJobidSource()) +func (g *GCMsgProtobuf) GetSourceJobId() protocol.JobId { + return protocol.JobId(g.Header.Proto.GetJobidSource()) } -func (g *GCMsgProtobuf) SetSourceJobId(job JobId) { +func (g *GCMsgProtobuf) SetSourceJobId(job protocol.JobId) { g.Header.Proto.JobidSource = proto.Uint64(uint64(job)) } @@ -81,15 +81,15 @@ func (g *GCMsgProtobuf) Serialize(w io.Writer) error { type GCMsg struct { AppId uint32 MsgType uint32 - Header *MsgGCHdr - Body Serializer + Header *steamlang.MsgGCHdr + Body protocol.Serializer } -func NewGCMsg(appId, msgType uint32, body Serializer) *GCMsg { +func NewGCMsg(appId, msgType uint32, body protocol.Serializer) *GCMsg { return &GCMsg{ AppId: appId, MsgType: msgType, - Header: NewMsgGCHdr(), + Header: steamlang.NewMsgGCHdr(), Body: body, } } @@ -106,19 +106,19 @@ func (g *GCMsg) IsProto() bool { return false } -func (g *GCMsg) GetTargetJobId() JobId { - return JobId(g.Header.TargetJobID) +func (g *GCMsg) GetTargetJobId() protocol.JobId { + return protocol.JobId(g.Header.TargetJobID) } -func (g *GCMsg) SetTargetJobId(job JobId) { +func (g *GCMsg) SetTargetJobId(job protocol.JobId) { g.Header.TargetJobID = uint64(job) } -func (g *GCMsg) GetSourceJobId() JobId { - return JobId(g.Header.SourceJobID) +func (g *GCMsg) GetSourceJobId() protocol.JobId { + return protocol.JobId(g.Header.SourceJobID) } -func (g *GCMsg) SetSourceJobId(job JobId) { +func (g *GCMsg) SetSourceJobId(job protocol.JobId) { g.Header.SourceJobID = uint64(job) } diff --git a/protocol/gamecoordinator/packet.go b/protocol/gamecoordinator/packet.go index 16e2903f..1d6c4a5a 100644 --- a/protocol/gamecoordinator/packet.go +++ b/protocol/gamecoordinator/packet.go @@ -3,9 +3,9 @@ package gamecoordinator import ( "bytes" - . "github.com/Philipp15b/go-steam/v2/protocol" - . "github.com/Philipp15b/go-steam/v2/protocol/protobuf" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/protocol" + "github.com/Philipp15b/go-steam/v2/protocol/protobuf" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" "github.com/golang/protobuf/proto" ) @@ -16,10 +16,10 @@ type GCPacket struct { IsProto bool GCName string Body []byte - TargetJobId JobId + TargetJobId protocol.JobId } -func NewGCPacket(wrapper *CMsgGCClient) (*GCPacket, error) { +func NewGCPacket(wrapper *protobuf.CMsgGCClient) (*GCPacket, error) { packet := &GCPacket{ AppId: wrapper.GetAppid(), MsgType: wrapper.GetMsgtype(), @@ -27,23 +27,23 @@ func NewGCPacket(wrapper *CMsgGCClient) (*GCPacket, error) { } r := bytes.NewReader(wrapper.GetPayload()) - if IsProto(wrapper.GetMsgtype()) { - packet.MsgType = packet.MsgType & EMsgMask + if steamlang.IsProto(wrapper.GetMsgtype()) { + packet.MsgType = packet.MsgType & steamlang.EMsgMask packet.IsProto = true - header := NewMsgGCHdrProtoBuf() + header := steamlang.NewMsgGCHdrProtoBuf() err := header.Deserialize(r) if err != nil { return nil, err } - packet.TargetJobId = JobId(header.Proto.GetJobidTarget()) + packet.TargetJobId = protocol.JobId(header.Proto.GetJobidTarget()) } else { - header := NewMsgGCHdr() + header := steamlang.NewMsgGCHdr() err := header.Deserialize(r) if err != nil { return nil, err } - packet.TargetJobId = JobId(header.TargetJobID) + packet.TargetJobId = protocol.JobId(header.TargetJobID) } body := make([]byte, r.Len()) @@ -57,6 +57,6 @@ func (g *GCPacket) ReadProtoMsg(body proto.Message) { proto.Unmarshal(g.Body, body) } -func (g *GCPacket) ReadMsg(body MessageBody) { +func (g *GCPacket) ReadMsg(body protocol.MessageBody) { body.Deserialize(bytes.NewReader(g.Body)) } diff --git a/protocol/internal.go b/protocol/internal.go index c0b1e013..3bb194f8 100644 --- a/protocol/internal.go +++ b/protocol/internal.go @@ -6,7 +6,7 @@ import ( "math" "strconv" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" ) type JobId uint64 @@ -33,13 +33,13 @@ type Serializable interface { type MessageBody interface { Serializable - GetEMsg() EMsg + GetEMsg() steamlang.EMsg } // the default details to request in most situations -const EClientPersonaStateFlag_DefaultInfoRequest = EClientPersonaStateFlag_PlayerName | - EClientPersonaStateFlag_Presence | EClientPersonaStateFlag_SourceID | - EClientPersonaStateFlag_GameExtraInfo +const EClientPersonaStateFlag_DefaultInfoRequest = steamlang.EClientPersonaStateFlag_PlayerName | + steamlang.EClientPersonaStateFlag_Presence | steamlang.EClientPersonaStateFlag_SourceID | + steamlang.EClientPersonaStateFlag_GameExtraInfo const DefaultAvatar = "fef49e7fa7e1997310d705b2a6158ff8dc1cdfeb" diff --git a/protocol/msg.go b/protocol/msg.go index e34888d7..477cd586 100644 --- a/protocol/msg.go +++ b/protocol/msg.go @@ -3,8 +3,8 @@ package protocol import ( "io" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" - . "github.com/Philipp15b/go-steam/v2/steamid" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/steamid" "github.com/golang/protobuf/proto" ) @@ -13,7 +13,7 @@ import ( type IMsg interface { Serializer IsProto() bool - GetMsgType() EMsg + GetMsgType() steamlang.EMsg GetTargetJobId() JobId SetTargetJobId(JobId) GetSourceJobId() JobId @@ -26,18 +26,18 @@ type IClientMsg interface { IMsg GetSessionId() int32 SetSessionId(int32) - GetSteamId() SteamId - SetSteamId(SteamId) + GetSteamId() steamid.SteamId + SetSteamId(steamid.SteamId) } // Represents a protobuf backed client message with session data. type ClientMsgProtobuf struct { - Header *MsgHdrProtoBuf + Header *steamlang.MsgHdrProtoBuf Body proto.Message } -func NewClientMsgProtobuf(eMsg EMsg, body proto.Message) *ClientMsgProtobuf { - hdr := NewMsgHdrProtoBuf() +func NewClientMsgProtobuf(eMsg steamlang.EMsg, body proto.Message) *ClientMsgProtobuf { + hdr := steamlang.NewMsgHdrProtoBuf() hdr.Msg = eMsg return &ClientMsgProtobuf{ Header: hdr, @@ -49,8 +49,8 @@ func (c *ClientMsgProtobuf) IsProto() bool { return true } -func (c *ClientMsgProtobuf) GetMsgType() EMsg { - return NewEMsg(uint32(c.Header.Msg)) +func (c *ClientMsgProtobuf) GetMsgType() steamlang.EMsg { + return steamlang.NewEMsg(uint32(c.Header.Msg)) } func (c *ClientMsgProtobuf) GetSessionId() int32 { @@ -61,11 +61,11 @@ func (c *ClientMsgProtobuf) SetSessionId(session int32) { c.Header.Proto.ClientSessionid = &session } -func (c *ClientMsgProtobuf) GetSteamId() SteamId { - return SteamId(c.Header.Proto.GetSteamid()) +func (c *ClientMsgProtobuf) GetSteamId() steamid.SteamId { + return steamid.SteamId(c.Header.Proto.GetSteamid()) } -func (c *ClientMsgProtobuf) SetSteamId(s SteamId) { +func (c *ClientMsgProtobuf) SetSteamId(s steamid.SteamId) { c.Header.Proto.Steamid = proto.Uint64(uint64(s)) } @@ -100,13 +100,13 @@ func (c *ClientMsgProtobuf) Serialize(w io.Writer) error { // Represents a struct backed client message. type ClientMsg struct { - Header *ExtendedClientMsgHdr + Header *steamlang.ExtendedClientMsgHdr Body MessageBody Payload []byte } func NewClientMsg(body MessageBody, payload []byte) *ClientMsg { - hdr := NewExtendedClientMsgHdr() + hdr := steamlang.NewExtendedClientMsgHdr() hdr.Msg = body.GetEMsg() return &ClientMsg{ Header: hdr, @@ -119,7 +119,7 @@ func (c *ClientMsg) IsProto() bool { return true } -func (c *ClientMsg) GetMsgType() EMsg { +func (c *ClientMsg) GetMsgType() steamlang.EMsg { return c.Header.Msg } @@ -131,11 +131,11 @@ func (c *ClientMsg) SetSessionId(session int32) { c.Header.SessionID = session } -func (c *ClientMsg) GetSteamId() SteamId { +func (c *ClientMsg) GetSteamId() steamid.SteamId { return c.Header.SteamID } -func (c *ClientMsg) SetSteamId(s SteamId) { +func (c *ClientMsg) SetSteamId(s steamid.SteamId) { c.Header.SteamID = s } @@ -169,13 +169,13 @@ func (c *ClientMsg) Serialize(w io.Writer) error { } type Msg struct { - Header *MsgHdr + Header *steamlang.MsgHdr Body MessageBody Payload []byte } func NewMsg(body MessageBody, payload []byte) *Msg { - hdr := NewMsgHdr() + hdr := steamlang.NewMsgHdr() hdr.Msg = body.GetEMsg() return &Msg{ Header: hdr, @@ -184,7 +184,7 @@ func NewMsg(body MessageBody, payload []byte) *Msg { } } -func (m *Msg) GetMsgType() EMsg { +func (m *Msg) GetMsgType() steamlang.EMsg { return m.Header.Msg } diff --git a/protocol/packet.go b/protocol/packet.go index 25850077..3a28ad54 100644 --- a/protocol/packet.go +++ b/protocol/packet.go @@ -5,7 +5,7 @@ import ( "encoding/binary" "fmt" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" "github.com/golang/protobuf/proto" ) @@ -13,7 +13,7 @@ import ( // Represents an incoming, partially unread message. type Packet struct { - EMsg EMsg + EMsg steamlang.EMsg IsProto bool TargetJobId JobId SourceJobId JobId @@ -26,10 +26,10 @@ func NewPacket(data []byte) (*Packet, error) { if err != nil { return nil, err } - eMsg := NewEMsg(rawEMsg) + eMsg := steamlang.NewEMsg(rawEMsg) buf := bytes.NewReader(data) - if eMsg == EMsg_ChannelEncryptRequest || eMsg == EMsg_ChannelEncryptResult { - header := NewMsgHdr() + if eMsg == steamlang.EMsg_ChannelEncryptRequest || eMsg == steamlang.EMsg_ChannelEncryptResult { + header := steamlang.NewMsgHdr() header.Msg = eMsg err = header.Deserialize(buf) if err != nil { @@ -42,8 +42,8 @@ func NewPacket(data []byte) (*Packet, error) { SourceJobId: JobId(header.SourceJobID), Data: data, }, nil - } else if IsProto(rawEMsg) { - header := NewMsgHdrProtoBuf() + } else if steamlang.IsProto(rawEMsg) { + header := steamlang.NewMsgHdrProtoBuf() header.Msg = eMsg err = header.Deserialize(buf) if err != nil { @@ -57,7 +57,7 @@ func NewPacket(data []byte) (*Packet, error) { Data: data, }, nil } else { - header := NewExtendedClientMsgHdr() + header := steamlang.NewExtendedClientMsgHdr() header.Msg = eMsg err = header.Deserialize(buf) if err != nil { @@ -78,7 +78,7 @@ func (p *Packet) String() string { } func (p *Packet) ReadProtoMsg(body proto.Message) *ClientMsgProtobuf { - header := NewMsgHdrProtoBuf() + header := steamlang.NewMsgHdrProtoBuf() buf := bytes.NewBuffer(p.Data) header.Deserialize(buf) proto.Unmarshal(buf.Bytes(), body) @@ -89,7 +89,7 @@ func (p *Packet) ReadProtoMsg(body proto.Message) *ClientMsgProtobuf { } func (p *Packet) ReadClientMsg(body MessageBody) *ClientMsg { - header := NewExtendedClientMsgHdr() + header := steamlang.NewExtendedClientMsgHdr() buf := bytes.NewReader(p.Data) header.Deserialize(buf) body.Deserialize(buf) @@ -103,7 +103,7 @@ func (p *Packet) ReadClientMsg(body MessageBody) *ClientMsg { } func (p *Packet) ReadMsg(body MessageBody) *Msg { - header := NewMsgHdr() + header := steamlang.NewMsgHdr() buf := bytes.NewReader(p.Data) header.Deserialize(buf) body.Deserialize(buf) diff --git a/protocol/steamlang/messages.go b/protocol/steamlang/messages.go index 4b2e32d8..20c0e48d 100644 --- a/protocol/steamlang/messages.go +++ b/protocol/steamlang/messages.go @@ -7,7 +7,7 @@ import ( "encoding/binary" "io" - . "github.com/Philipp15b/go-steam/v2/protocol/protobuf" + "github.com/Philipp15b/go-steam/v2/protocol/protobuf" "github.com/Philipp15b/go-steam/v2/rwu" "github.com/Philipp15b/go-steam/v2/steamid" "github.com/golang/protobuf/proto" @@ -372,13 +372,13 @@ func (d *ExtendedClientMsgHdr) Deserialize(r io.Reader) error { type MsgHdrProtoBuf struct { Msg EMsg HeaderLength int32 - Proto *CMsgProtoBufHeader + Proto *protobuf.CMsgProtoBufHeader } func NewMsgHdrProtoBuf() *MsgHdrProtoBuf { return &MsgHdrProtoBuf{ Msg: EMsg_Invalid, - Proto: new(CMsgProtoBufHeader), + Proto: new(protobuf.CMsgProtoBufHeader), } } @@ -424,13 +424,13 @@ func (d *MsgHdrProtoBuf) Deserialize(r io.Reader) error { type MsgGCHdrProtoBuf struct { Msg uint32 HeaderLength int32 - Proto *CMsgProtoBufHeader + Proto *protobuf.CMsgProtoBufHeader } func NewMsgGCHdrProtoBuf() *MsgGCHdrProtoBuf { return &MsgGCHdrProtoBuf{ Msg: 0, - Proto: new(CMsgProtoBufHeader), + Proto: new(protobuf.CMsgProtoBufHeader), } } diff --git a/social.go b/social.go index d7caf17b..a707be97 100644 --- a/social.go +++ b/social.go @@ -7,12 +7,12 @@ import ( "sync" "time" - . "github.com/Philipp15b/go-steam/v2/protocol" - . "github.com/Philipp15b/go-steam/v2/protocol/protobuf" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" - . "github.com/Philipp15b/go-steam/v2/rwu" + "github.com/Philipp15b/go-steam/v2/protocol" + "github.com/Philipp15b/go-steam/v2/protocol/protobuf" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/rwu" "github.com/Philipp15b/go-steam/v2/socialcache" - . "github.com/Philipp15b/go-steam/v2/steamid" + "github.com/Philipp15b/go-steam/v2/steamid" "github.com/golang/protobuf/proto" ) @@ -22,7 +22,7 @@ type Social struct { name string avatar []byte - personaState EPersonaState + personaState steamlang.EPersonaState Friends *socialcache.FriendsList Groups *socialcache.GroupsList @@ -59,42 +59,42 @@ func (s *Social) SetPersonaName(name string) { s.mutex.Lock() defer s.mutex.Unlock() s.name = name - s.client.Write(NewClientMsgProtobuf(EMsg_ClientChangeStatus, &CMsgClientChangeStatus{ + s.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientChangeStatus, &protobuf.CMsgClientChangeStatus{ PersonaState: proto.Uint32(uint32(s.personaState)), PlayerName: proto.String(name), })) } // Gets the local user's persona state -func (s *Social) GetPersonaState() EPersonaState { +func (s *Social) GetPersonaState() steamlang.EPersonaState { s.mutex.RLock() defer s.mutex.RUnlock() return s.personaState } // Sets the local user's persona state and broadcasts it over the network -func (s *Social) SetPersonaState(state EPersonaState) { +func (s *Social) SetPersonaState(state steamlang.EPersonaState) { s.mutex.Lock() defer s.mutex.Unlock() s.personaState = state - s.client.Write(NewClientMsgProtobuf(EMsg_ClientChangeStatus, &CMsgClientChangeStatus{ + s.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientChangeStatus, &protobuf.CMsgClientChangeStatus{ PersonaState: proto.Uint32(uint32(state)), })) } // Sends a chat message to ether a room or friend -func (s *Social) SendMessage(to SteamId, entryType EChatEntryType, message string) { +func (s *Social) SendMessage(to steamid.SteamId, entryType steamlang.EChatEntryType, message string) { // Friend - if to.GetAccountType() == int32(EAccountType_Individual) || to.GetAccountType() == int32(EAccountType_ConsoleUser) { - s.client.Write(NewClientMsgProtobuf(EMsg_ClientFriendMsg, &CMsgClientFriendMsg{ + if to.GetAccountType() == int32(steamlang.EAccountType_Individual) || to.GetAccountType() == int32(steamlang.EAccountType_ConsoleUser) { + s.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientFriendMsg, &protobuf.CMsgClientFriendMsg{ Steamid: proto.Uint64(to.ToUint64()), ChatEntryType: proto.Int32(int32(entryType)), Message: []byte(message), })) // Chat room - } else if to.GetAccountType() == int32(EAccountType_Clan) || to.GetAccountType() == int32(EAccountType_Chat) { + } else if to.GetAccountType() == int32(steamlang.EAccountType_Clan) || to.GetAccountType() == int32(steamlang.EAccountType_Chat) { chatId := to.ClanToChat() - s.client.Write(NewClientMsg(&MsgClientChatMsg{ + s.client.Write(protocol.NewClientMsg(&steamlang.MsgClientChatMsg{ ChatMsgType: entryType, SteamIdChatRoom: chatId, SteamIdChatter: s.client.SteamId(), @@ -104,26 +104,26 @@ func (s *Social) SendMessage(to SteamId, entryType EChatEntryType, message strin // Adds a friend to your friends list or accepts a friend. You'll receive a FriendStateEvent // for every new/changed friend -func (s *Social) AddFriend(id SteamId) { - s.client.Write(NewClientMsgProtobuf(EMsg_ClientAddFriend, &CMsgClientAddFriend{ +func (s *Social) AddFriend(id steamid.SteamId) { + s.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientAddFriend, &protobuf.CMsgClientAddFriend{ SteamidToAdd: proto.Uint64(id.ToUint64()), })) } // Removes a friend from your friends list -func (s *Social) RemoveFriend(id SteamId) { - s.client.Write(NewClientMsgProtobuf(EMsg_ClientRemoveFriend, &CMsgClientRemoveFriend{ +func (s *Social) RemoveFriend(id steamid.SteamId) { + s.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientRemoveFriend, &protobuf.CMsgClientRemoveFriend{ Friendid: proto.Uint64(id.ToUint64()), })) } // Ignores or unignores a friend on Steam -func (s *Social) IgnoreFriend(id SteamId, setIgnore bool) { +func (s *Social) IgnoreFriend(id steamid.SteamId, setIgnore bool) { ignore := uint8(1) // True if !setIgnore { ignore = uint8(0) // False } - s.client.Write(NewClientMsg(&MsgClientSetIgnoreFriend{ + s.client.Write(protocol.NewClientMsg(&steamlang.MsgClientSetIgnoreFriend{ MySteamId: s.client.SteamId(), SteamIdFriend: id, Ignore: ignore, @@ -131,135 +131,135 @@ func (s *Social) IgnoreFriend(id SteamId, setIgnore bool) { } // Requests persona state for a list of specified SteamIds -func (s *Social) RequestFriendListInfo(ids []SteamId, requestedInfo EClientPersonaStateFlag) { +func (s *Social) RequestFriendListInfo(ids []steamid.SteamId, requestedInfo steamlang.EClientPersonaStateFlag) { var friends []uint64 for _, id := range ids { friends = append(friends, id.ToUint64()) } - s.client.Write(NewClientMsgProtobuf(EMsg_ClientRequestFriendData, &CMsgClientRequestFriendData{ + s.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientRequestFriendData, &protobuf.CMsgClientRequestFriendData{ PersonaStateRequested: proto.Uint32(uint32(requestedInfo)), Friends: friends, })) } // Requests persona state for a specified SteamId -func (s *Social) RequestFriendInfo(id SteamId, requestedInfo EClientPersonaStateFlag) { - s.RequestFriendListInfo([]SteamId{id}, requestedInfo) +func (s *Social) RequestFriendInfo(id steamid.SteamId, requestedInfo steamlang.EClientPersonaStateFlag) { + s.RequestFriendListInfo([]steamid.SteamId{id}, requestedInfo) } // Requests profile information for a specified SteamId -func (s *Social) RequestProfileInfo(id SteamId) { - s.client.Write(NewClientMsgProtobuf(EMsg_ClientFriendProfileInfo, &CMsgClientFriendProfileInfo{ +func (s *Social) RequestProfileInfo(id steamid.SteamId) { + s.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientFriendProfileInfo, &protobuf.CMsgClientFriendProfileInfo{ SteamidFriend: proto.Uint64(id.ToUint64()), })) } // Requests all offline messages and marks them as read func (s *Social) RequestOfflineMessages() { - s.client.Write(NewClientMsgProtobuf(EMsg_ClientChatGetFriendMessageHistoryForOfflineMessages, &CMsgClientChatGetFriendMessageHistoryForOfflineMessages{})) + s.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientChatGetFriendMessageHistoryForOfflineMessages, &protobuf.CMsgClientChatGetFriendMessageHistoryForOfflineMessages{})) } // Attempts to join a chat room -func (s *Social) JoinChat(id SteamId) { +func (s *Social) JoinChat(id steamid.SteamId) { chatId := id.ClanToChat() - s.client.Write(NewClientMsg(&MsgClientJoinChat{ + s.client.Write(protocol.NewClientMsg(&steamlang.MsgClientJoinChat{ SteamIdChat: chatId, }, make([]byte, 0))) } // Attempts to leave a chat room -func (s *Social) LeaveChat(id SteamId) { +func (s *Social) LeaveChat(id steamid.SteamId) { chatId := id.ClanToChat() payload := new(bytes.Buffer) - binary.Write(payload, binary.LittleEndian, s.client.SteamId().ToUint64()) // ChatterActedOn - binary.Write(payload, binary.LittleEndian, uint32(EChatMemberStateChange_Left)) // StateChange - binary.Write(payload, binary.LittleEndian, s.client.SteamId().ToUint64()) // ChatterActedBy - s.client.Write(NewClientMsg(&MsgClientChatMemberInfo{ + binary.Write(payload, binary.LittleEndian, s.client.SteamId().ToUint64()) // ChatterActedOn + binary.Write(payload, binary.LittleEndian, uint32(steamlang.EChatMemberStateChange_Left)) // StateChange + binary.Write(payload, binary.LittleEndian, s.client.SteamId().ToUint64()) // ChatterActedBy + s.client.Write(protocol.NewClientMsg(&steamlang.MsgClientChatMemberInfo{ SteamIdChat: chatId, - Type: EChatInfoType_StateChange, + Type: steamlang.EChatInfoType_StateChange, }, payload.Bytes())) } // Kicks the specified chat member from the given chat room -func (s *Social) KickChatMember(room SteamId, user SteamId) { +func (s *Social) KickChatMember(room steamid.SteamId, user steamid.SteamId) { chatId := room.ClanToChat() - s.client.Write(NewClientMsg(&MsgClientChatAction{ + s.client.Write(protocol.NewClientMsg(&steamlang.MsgClientChatAction{ SteamIdChat: chatId, SteamIdUserToActOn: user, - ChatAction: EChatAction_Kick, + ChatAction: steamlang.EChatAction_Kick, }, make([]byte, 0))) } // Bans the specified chat member from the given chat room -func (s *Social) BanChatMember(room SteamId, user SteamId) { +func (s *Social) BanChatMember(room steamid.SteamId, user steamid.SteamId) { chatId := room.ClanToChat() - s.client.Write(NewClientMsg(&MsgClientChatAction{ + s.client.Write(protocol.NewClientMsg(&steamlang.MsgClientChatAction{ SteamIdChat: chatId, SteamIdUserToActOn: user, - ChatAction: EChatAction_Ban, + ChatAction: steamlang.EChatAction_Ban, }, make([]byte, 0))) } // Unbans the specified chat member from the given chat room -func (s *Social) UnbanChatMember(room SteamId, user SteamId) { +func (s *Social) UnbanChatMember(room steamid.SteamId, user steamid.SteamId) { chatId := room.ClanToChat() - s.client.Write(NewClientMsg(&MsgClientChatAction{ + s.client.Write(protocol.NewClientMsg(&steamlang.MsgClientChatAction{ SteamIdChat: chatId, SteamIdUserToActOn: user, - ChatAction: EChatAction_UnBan, + ChatAction: steamlang.EChatAction_UnBan, }, make([]byte, 0))) } -func (s *Social) HandlePacket(packet *Packet) { +func (s *Social) HandlePacket(packet *protocol.Packet) { switch packet.EMsg { - case EMsg_ClientPersonaState: + case steamlang.EMsg_ClientPersonaState: s.handlePersonaState(packet) - case EMsg_ClientClanState: + case steamlang.EMsg_ClientClanState: s.handleClanState(packet) - case EMsg_ClientFriendsList: + case steamlang.EMsg_ClientFriendsList: s.handleFriendsList(packet) - case EMsg_ClientFriendMsgIncoming: + case steamlang.EMsg_ClientFriendMsgIncoming: s.handleFriendMsg(packet) - case EMsg_ClientAccountInfo: + case steamlang.EMsg_ClientAccountInfo: s.handleAccountInfo(packet) - case EMsg_ClientAddFriendResponse: + case steamlang.EMsg_ClientAddFriendResponse: s.handleFriendResponse(packet) - case EMsg_ClientChatEnter: + case steamlang.EMsg_ClientChatEnter: s.handleChatEnter(packet) - case EMsg_ClientChatMsg: + case steamlang.EMsg_ClientChatMsg: s.handleChatMsg(packet) - case EMsg_ClientChatMemberInfo: + case steamlang.EMsg_ClientChatMemberInfo: s.handleChatMemberInfo(packet) - case EMsg_ClientChatActionResult: + case steamlang.EMsg_ClientChatActionResult: s.handleChatActionResult(packet) - case EMsg_ClientChatInvite: + case steamlang.EMsg_ClientChatInvite: s.handleChatInvite(packet) - case EMsg_ClientSetIgnoreFriendResponse: + case steamlang.EMsg_ClientSetIgnoreFriendResponse: s.handleIgnoreFriendResponse(packet) - case EMsg_ClientFriendProfileInfoResponse: + case steamlang.EMsg_ClientFriendProfileInfoResponse: s.handleProfileInfoResponse(packet) - case EMsg_ClientFSGetFriendMessageHistoryResponse: + case steamlang.EMsg_ClientFSGetFriendMessageHistoryResponse: s.handleFriendMessageHistoryResponse(packet) } } -func (s *Social) handleAccountInfo(packet *Packet) { +func (s *Social) handleAccountInfo(packet *protocol.Packet) { // Just fire the personainfo, Auth handles the callback - flags := EClientPersonaStateFlag_PlayerName | EClientPersonaStateFlag_Presence | EClientPersonaStateFlag_SourceID - s.RequestFriendInfo(s.client.SteamId(), EClientPersonaStateFlag(flags)) + flags := steamlang.EClientPersonaStateFlag_PlayerName | steamlang.EClientPersonaStateFlag_Presence | steamlang.EClientPersonaStateFlag_SourceID + s.RequestFriendInfo(s.client.SteamId(), steamlang.EClientPersonaStateFlag(flags)) } -func (s *Social) handleFriendsList(packet *Packet) { - list := new(CMsgClientFriendsList) +func (s *Social) handleFriendsList(packet *protocol.Packet) { + list := new(protobuf.CMsgClientFriendsList) packet.ReadProtoMsg(list) - var friends []SteamId + var friends []steamid.SteamId for _, friend := range list.GetFriends() { - steamId := SteamId(friend.GetUlfriendid()) - isClan := steamId.GetAccountType() == int32(EAccountType_Clan) + steamId := steamid.SteamId(friend.GetUlfriendid()) + isClan := steamId.GetAccountType() == int32(steamlang.EAccountType_Clan) if isClan { - rel := EClanRelationship(friend.GetEfriendrelationship()) - if rel == EClanRelationship_None { + rel := steamlang.EClanRelationship(friend.GetEfriendrelationship()) + if rel == steamlang.EClanRelationship_None { s.Groups.Remove(steamId) } else { s.Groups.Add(socialcache.Group{ @@ -272,8 +272,8 @@ func (s *Social) handleFriendsList(packet *Packet) { s.client.Emit(&GroupStateEvent{steamId, rel}) } } else { - rel := EFriendRelationship(friend.GetEfriendrelationship()) - if rel == EFriendRelationship_None { + rel := steamlang.EFriendRelationship(friend.GetEfriendrelationship()) + if rel == steamlang.EFriendRelationship_None { s.Friends.Remove(steamId) } else { s.Friends.Add(socialcache.Friend{ @@ -291,55 +291,55 @@ func (s *Social) handleFriendsList(packet *Packet) { } } if !list.GetBincremental() { - s.RequestFriendListInfo(friends, EClientPersonaStateFlag_DefaultInfoRequest) + s.RequestFriendListInfo(friends, protocol.EClientPersonaStateFlag_DefaultInfoRequest) s.client.Emit(&FriendsListEvent{}) } } -func (s *Social) handlePersonaState(packet *Packet) { - list := new(CMsgClientPersonaState) +func (s *Social) handlePersonaState(packet *protocol.Packet) { + list := new(protobuf.CMsgClientPersonaState) packet.ReadProtoMsg(list) - flags := EClientPersonaStateFlag(list.GetStatusFlags()) + flags := steamlang.EClientPersonaStateFlag(list.GetStatusFlags()) for _, friend := range list.GetFriends() { - id := SteamId(friend.GetFriendid()) + id := steamid.SteamId(friend.GetFriendid()) if id == s.client.SteamId() { // this is our client id s.mutex.Lock() if friend.GetPlayerName() != "" { s.name = friend.GetPlayerName() } avatar := friend.GetAvatarHash() - if ValidAvatar(avatar) { + if protocol.ValidAvatar(avatar) { s.avatar = avatar } s.mutex.Unlock() - } else if id.GetAccountType() == int32(EAccountType_Individual) { - if (flags & EClientPersonaStateFlag_PlayerName) == EClientPersonaStateFlag_PlayerName { + } else if id.GetAccountType() == int32(steamlang.EAccountType_Individual) { + if (flags & steamlang.EClientPersonaStateFlag_PlayerName) == steamlang.EClientPersonaStateFlag_PlayerName { if friend.GetPlayerName() != "" { s.Friends.SetName(id, friend.GetPlayerName()) } } - if (flags & EClientPersonaStateFlag_Presence) == EClientPersonaStateFlag_Presence { + if (flags & steamlang.EClientPersonaStateFlag_Presence) == steamlang.EClientPersonaStateFlag_Presence { avatar := friend.GetAvatarHash() - if ValidAvatar(avatar) { + if protocol.ValidAvatar(avatar) { s.Friends.SetAvatar(id, avatar) } - s.Friends.SetPersonaState(id, EPersonaState(friend.GetPersonaState())) - s.Friends.SetPersonaStateFlags(id, EPersonaStateFlag(friend.GetPersonaStateFlags())) + s.Friends.SetPersonaState(id, steamlang.EPersonaState(friend.GetPersonaState())) + s.Friends.SetPersonaStateFlags(id, steamlang.EPersonaStateFlag(friend.GetPersonaStateFlags())) } - if (flags & EClientPersonaStateFlag_GameDataBlob) == EClientPersonaStateFlag_GameDataBlob { + if (flags & steamlang.EClientPersonaStateFlag_GameDataBlob) == steamlang.EClientPersonaStateFlag_GameDataBlob { s.Friends.SetGameAppId(id, friend.GetGamePlayedAppId()) s.Friends.SetGameId(id, friend.GetGameid()) s.Friends.SetGameName(id, friend.GetGameName()) } - } else if id.GetAccountType() == int32(EAccountType_Clan) { - if (flags & EClientPersonaStateFlag_PlayerName) == EClientPersonaStateFlag_PlayerName { + } else if id.GetAccountType() == int32(steamlang.EAccountType_Clan) { + if (flags & steamlang.EClientPersonaStateFlag_PlayerName) == steamlang.EClientPersonaStateFlag_PlayerName { if friend.GetPlayerName() != "" { s.Groups.SetName(id, friend.GetPlayerName()) } } - if (flags & EClientPersonaStateFlag_Presence) == EClientPersonaStateFlag_Presence { + if (flags & steamlang.EClientPersonaStateFlag_Presence) == steamlang.EClientPersonaStateFlag_Presence { avatar := friend.GetAvatarHash() - if ValidAvatar(avatar) { + if protocol.ValidAvatar(avatar) { s.Groups.SetAvatar(id, avatar) } } @@ -347,15 +347,15 @@ func (s *Social) handlePersonaState(packet *Packet) { s.client.Emit(&PersonaStateEvent{ StatusFlags: flags, FriendId: id, - State: EPersonaState(friend.GetPersonaState()), - StateFlags: EPersonaStateFlag(friend.GetPersonaStateFlags()), + State: steamlang.EPersonaState(friend.GetPersonaState()), + StateFlags: steamlang.EPersonaStateFlag(friend.GetPersonaStateFlags()), GameAppId: friend.GetGamePlayedAppId(), GameId: friend.GetGameid(), GameName: friend.GetGameName(), GameServerIp: friend.GetGameServerIp(), GameServerPort: friend.GetGameServerPort(), QueryPort: friend.GetQueryPort(), - SourceSteamId: SteamId(friend.GetSteamidSource()), + SourceSteamId: steamid.SteamId(friend.GetSteamidSource()), GameDataBlob: friend.GetGameDataBlob(), Name: friend.GetPlayerName(), Avatar: friend.GetAvatarHash(), @@ -369,8 +369,8 @@ func (s *Social) handlePersonaState(packet *Packet) { } } -func (s *Social) handleClanState(packet *Packet) { - body := new(CMsgClientClanState) +func (s *Social) handleClanState(packet *protocol.Packet) { + body := new(protobuf.CMsgClientClanState) packet.ReadProtoMsg(body) var name string var avatar []byte @@ -407,7 +407,7 @@ func (s *Social) handleClanState(packet *Packet) { } // Add stuff to group - clanid := SteamId(body.GetSteamidClan()) + clanid := steamid.SteamId(body.GetSteamidClan()) if body.NameInfo != nil { info := body.NameInfo s.Groups.SetName(clanid, info.GetClanName()) @@ -421,7 +421,7 @@ func (s *Social) handleClanState(packet *Packet) { } s.client.Emit(&ClanStateEvent{ ClanId: clanid, - AccountFlags: EAccountFlags(body.GetClanAccountFlags()), + AccountFlags: steamlang.EAccountFlags(body.GetClanAccountFlags()), ClanName: name, Avatar: avatar, MemberTotalCount: totalCount, @@ -433,159 +433,159 @@ func (s *Social) handleClanState(packet *Packet) { }) } -func (s *Social) handleFriendResponse(packet *Packet) { - body := new(CMsgClientAddFriendResponse) +func (s *Social) handleFriendResponse(packet *protocol.Packet) { + body := new(protobuf.CMsgClientAddFriendResponse) packet.ReadProtoMsg(body) s.client.Emit(&FriendAddedEvent{ - Result: EResult(body.GetEresult()), - SteamId: SteamId(body.GetSteamIdAdded()), + Result: steamlang.EResult(body.GetEresult()), + SteamId: steamid.SteamId(body.GetSteamIdAdded()), PersonaName: body.GetPersonaNameAdded(), }) } -func (s *Social) handleFriendMsg(packet *Packet) { - body := new(CMsgClientFriendMsgIncoming) +func (s *Social) handleFriendMsg(packet *protocol.Packet) { + body := new(protobuf.CMsgClientFriendMsgIncoming) packet.ReadProtoMsg(body) message := string(bytes.Split(body.GetMessage(), []byte{0x0})[0]) s.client.Emit(&ChatMsgEvent{ - ChatterId: SteamId(body.GetSteamidFrom()), + ChatterId: steamid.SteamId(body.GetSteamidFrom()), Message: message, - EntryType: EChatEntryType(body.GetChatEntryType()), + EntryType: steamlang.EChatEntryType(body.GetChatEntryType()), Timestamp: time.Unix(int64(body.GetRtime32ServerTimestamp()), 0), }) } -func (s *Social) handleChatMsg(packet *Packet) { - body := new(MsgClientChatMsg) +func (s *Social) handleChatMsg(packet *protocol.Packet) { + body := new(steamlang.MsgClientChatMsg) payload := packet.ReadClientMsg(body).Payload message := string(bytes.Split(payload, []byte{0x0})[0]) s.client.Emit(&ChatMsgEvent{ - ChatRoomId: SteamId(body.SteamIdChatRoom), - ChatterId: SteamId(body.SteamIdChatter), + ChatRoomId: steamid.SteamId(body.SteamIdChatRoom), + ChatterId: steamid.SteamId(body.SteamIdChatter), Message: message, - EntryType: EChatEntryType(body.ChatMsgType), + EntryType: steamlang.EChatEntryType(body.ChatMsgType), }) } -func (s *Social) handleChatEnter(packet *Packet) { - body := new(MsgClientChatEnter) +func (s *Social) handleChatEnter(packet *protocol.Packet) { + body := new(steamlang.MsgClientChatEnter) payload := packet.ReadClientMsg(body).Payload reader := bytes.NewBuffer(payload) - name, _ := ReadString(reader) - ReadByte(reader) // 0 + name, _ := rwu.ReadString(reader) + rwu.ReadByte(reader) // 0 count := body.NumMembers - chatId := SteamId(body.SteamIdChat) - clanId := SteamId(body.SteamIdClan) + chatId := steamid.SteamId(body.SteamIdChat) + clanId := steamid.SteamId(body.SteamIdClan) s.Chats.Add(socialcache.Chat{SteamId: chatId, GroupId: clanId}) for i := 0; i < int(count); i++ { id, chatPerm, clanPerm := readChatMember(reader) - ReadBytes(reader, 6) // No idea what this is + rwu.ReadBytes(reader, 6) // No idea what this is s.Chats.AddChatMember(chatId, socialcache.ChatMember{ - SteamId: SteamId(id), + SteamId: steamid.SteamId(id), ChatPermissions: chatPerm, ClanPermissions: clanPerm, }) } s.client.Emit(&ChatEnterEvent{ - ChatRoomId: SteamId(body.SteamIdChat), - FriendId: SteamId(body.SteamIdFriend), - ChatRoomType: EChatRoomType(body.ChatRoomType), - OwnerId: SteamId(body.SteamIdOwner), - ClanId: SteamId(body.SteamIdClan), + ChatRoomId: steamid.SteamId(body.SteamIdChat), + FriendId: steamid.SteamId(body.SteamIdFriend), + ChatRoomType: steamlang.EChatRoomType(body.ChatRoomType), + OwnerId: steamid.SteamId(body.SteamIdOwner), + ClanId: steamid.SteamId(body.SteamIdClan), ChatFlags: byte(body.ChatFlags), - EnterResponse: EChatRoomEnterResponse(body.EnterResponse), + EnterResponse: steamlang.EChatRoomEnterResponse(body.EnterResponse), Name: name, }) } -func (s *Social) handleChatMemberInfo(packet *Packet) { - body := new(MsgClientChatMemberInfo) +func (s *Social) handleChatMemberInfo(packet *protocol.Packet) { + body := new(steamlang.MsgClientChatMemberInfo) payload := packet.ReadClientMsg(body).Payload reader := bytes.NewBuffer(payload) - chatId := SteamId(body.SteamIdChat) - if body.Type == EChatInfoType_StateChange { - actedOn, _ := ReadUint64(reader) - state, _ := ReadInt32(reader) - actedBy, _ := ReadUint64(reader) - ReadByte(reader) // 0 - stateChange := EChatMemberStateChange(state) - if stateChange == EChatMemberStateChange_Entered { + chatId := steamid.SteamId(body.SteamIdChat) + if body.Type == steamlang.EChatInfoType_StateChange { + actedOn, _ := rwu.ReadUint64(reader) + state, _ := rwu.ReadInt32(reader) + actedBy, _ := rwu.ReadUint64(reader) + rwu.ReadByte(reader) // 0 + stateChange := steamlang.EChatMemberStateChange(state) + if stateChange == steamlang.EChatMemberStateChange_Entered { _, chatPerm, clanPerm := readChatMember(reader) s.Chats.AddChatMember(chatId, socialcache.ChatMember{ - SteamId: SteamId(actedOn), + SteamId: steamid.SteamId(actedOn), ChatPermissions: chatPerm, ClanPermissions: clanPerm, }) - } else if stateChange == EChatMemberStateChange_Banned || stateChange == EChatMemberStateChange_Kicked || - stateChange == EChatMemberStateChange_Disconnected || stateChange == EChatMemberStateChange_Left { - s.Chats.RemoveChatMember(chatId, SteamId(actedOn)) + } else if stateChange == steamlang.EChatMemberStateChange_Banned || stateChange == steamlang.EChatMemberStateChange_Kicked || + stateChange == steamlang.EChatMemberStateChange_Disconnected || stateChange == steamlang.EChatMemberStateChange_Left { + s.Chats.RemoveChatMember(chatId, steamid.SteamId(actedOn)) } stateInfo := StateChangeDetails{ - ChatterActedOn: SteamId(actedOn), - StateChange: EChatMemberStateChange(stateChange), - ChatterActedBy: SteamId(actedBy), + ChatterActedOn: steamid.SteamId(actedOn), + StateChange: steamlang.EChatMemberStateChange(stateChange), + ChatterActedBy: steamid.SteamId(actedBy), } s.client.Emit(&ChatMemberInfoEvent{ - ChatRoomId: SteamId(body.SteamIdChat), - Type: EChatInfoType(body.Type), + ChatRoomId: steamid.SteamId(body.SteamIdChat), + Type: steamlang.EChatInfoType(body.Type), StateChangeInfo: stateInfo, }) } } -func readChatMember(r io.Reader) (SteamId, EChatPermission, EClanPermission) { - ReadString(r) // MessageObject - ReadByte(r) // 7 - ReadString(r) // steamid - id, _ := ReadUint64(r) - ReadByte(r) // 2 - ReadString(r) // Permissions - chat, _ := ReadInt32(r) - ReadByte(r) // 2 - ReadString(r) // Details - clan, _ := ReadInt32(r) - return SteamId(id), EChatPermission(chat), EClanPermission(clan) +func readChatMember(r io.Reader) (steamid.SteamId, steamlang.EChatPermission, steamlang.EClanPermission) { + rwu.ReadString(r) // MessageObject + rwu.ReadByte(r) // 7 + rwu.ReadString(r) // steamid + id, _ := rwu.ReadUint64(r) + rwu.ReadByte(r) // 2 + rwu.ReadString(r) // Permissions + chat, _ := rwu.ReadInt32(r) + rwu.ReadByte(r) // 2 + rwu.ReadString(r) // Details + clan, _ := rwu.ReadInt32(r) + return steamid.SteamId(id), steamlang.EChatPermission(chat), steamlang.EClanPermission(clan) } -func (s *Social) handleChatActionResult(packet *Packet) { - body := new(MsgClientChatActionResult) +func (s *Social) handleChatActionResult(packet *protocol.Packet) { + body := new(steamlang.MsgClientChatActionResult) packet.ReadClientMsg(body) s.client.Emit(&ChatActionResultEvent{ - ChatRoomId: SteamId(body.SteamIdChat), - ChatterId: SteamId(body.SteamIdUserActedOn), - Action: EChatAction(body.ChatAction), - Result: EChatActionResult(body.ActionResult), + ChatRoomId: steamid.SteamId(body.SteamIdChat), + ChatterId: steamid.SteamId(body.SteamIdUserActedOn), + Action: steamlang.EChatAction(body.ChatAction), + Result: steamlang.EChatActionResult(body.ActionResult), }) } -func (s *Social) handleChatInvite(packet *Packet) { - body := new(CMsgClientChatInvite) +func (s *Social) handleChatInvite(packet *protocol.Packet) { + body := new(protobuf.CMsgClientChatInvite) packet.ReadProtoMsg(body) s.client.Emit(&ChatInviteEvent{ - InvitedId: SteamId(body.GetSteamIdInvited()), - ChatRoomId: SteamId(body.GetSteamIdChat()), - PatronId: SteamId(body.GetSteamIdPatron()), - ChatRoomType: EChatRoomType(body.GetChatroomType()), - FriendChatId: SteamId(body.GetSteamIdFriendChat()), + InvitedId: steamid.SteamId(body.GetSteamIdInvited()), + ChatRoomId: steamid.SteamId(body.GetSteamIdChat()), + PatronId: steamid.SteamId(body.GetSteamIdPatron()), + ChatRoomType: steamlang.EChatRoomType(body.GetChatroomType()), + FriendChatId: steamid.SteamId(body.GetSteamIdFriendChat()), ChatRoomName: body.GetChatName(), GameId: body.GetGameId(), }) } -func (s *Social) handleIgnoreFriendResponse(packet *Packet) { - body := new(MsgClientSetIgnoreFriendResponse) +func (s *Social) handleIgnoreFriendResponse(packet *protocol.Packet) { + body := new(steamlang.MsgClientSetIgnoreFriendResponse) packet.ReadClientMsg(body) s.client.Emit(&IgnoreFriendEvent{ - Result: EResult(body.Result), + Result: steamlang.EResult(body.Result), }) } -func (s *Social) handleProfileInfoResponse(packet *Packet) { - body := new(CMsgClientFriendProfileInfoResponse) +func (s *Social) handleProfileInfoResponse(packet *protocol.Packet) { + body := new(protobuf.CMsgClientFriendProfileInfoResponse) packet.ReadProtoMsg(body) s.client.Emit(&ProfileInfoEvent{ - Result: EResult(body.GetEresult()), - SteamId: SteamId(body.GetSteamidFriend()), + Result: steamlang.EResult(body.GetEresult()), + SteamId: steamid.SteamId(body.GetSteamidFriend()), TimeCreated: body.GetTimeCreated(), RealName: body.GetRealName(), CityName: body.GetCityName(), @@ -596,10 +596,10 @@ func (s *Social) handleProfileInfoResponse(packet *Packet) { }) } -func (s *Social) handleFriendMessageHistoryResponse(packet *Packet) { - body := new(CMsgClientChatGetFriendMessageHistoryResponse) +func (s *Social) handleFriendMessageHistoryResponse(packet *protocol.Packet) { + body := new(protobuf.CMsgClientChatGetFriendMessageHistoryResponse) packet.ReadProtoMsg(body) - steamid := SteamId(body.GetSteamid()) + steamid := steamid.SteamId(body.GetSteamid()) for _, message := range body.GetMessages() { if !message.GetUnread() { continue // Skip already read messages @@ -607,7 +607,7 @@ func (s *Social) handleFriendMessageHistoryResponse(packet *Packet) { s.client.Emit(&ChatMsgEvent{ ChatterId: steamid, Message: message.GetMessage(), - EntryType: EChatEntryType_ChatMsg, + EntryType: steamlang.EChatEntryType_ChatMsg, Timestamp: time.Unix(int64(message.GetTimestamp()), 0), Offline: true, // GetUnread is true }) diff --git a/social_events.go b/social_events.go index c8009bc9..6dd30990 100644 --- a/social_events.go +++ b/social_events.go @@ -3,43 +3,43 @@ package steam import ( "time" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" - . "github.com/Philipp15b/go-steam/v2/steamid" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/steamid" ) type FriendsListEvent struct{} type FriendStateEvent struct { - SteamId SteamId `json:",string"` - Relationship EFriendRelationship + SteamId steamid.SteamId `json:",string"` + Relationship steamlang.EFriendRelationship } func (f *FriendStateEvent) IsFriend() bool { - return f.Relationship == EFriendRelationship_Friend + return f.Relationship == steamlang.EFriendRelationship_Friend } type GroupStateEvent struct { - SteamId SteamId `json:",string"` - Relationship EClanRelationship + SteamId steamid.SteamId `json:",string"` + Relationship steamlang.EClanRelationship } func (g *GroupStateEvent) IsMember() bool { - return g.Relationship == EClanRelationship_Member + return g.Relationship == steamlang.EClanRelationship_Member } // Fired when someone changing their friend details type PersonaStateEvent struct { - StatusFlags EClientPersonaStateFlag - FriendId SteamId `json:",string"` - State EPersonaState - StateFlags EPersonaStateFlag + StatusFlags steamlang.EClientPersonaStateFlag + FriendId steamid.SteamId `json:",string"` + State steamlang.EPersonaState + StateFlags steamlang.EPersonaStateFlag GameAppId uint32 GameId uint64 `json:",string"` GameName string GameServerIp uint32 GameServerPort uint32 QueryPort uint32 - SourceSteamId SteamId `json:",string"` + SourceSteamId steamid.SteamId `json:",string"` GameDataBlob []byte Name string Avatar []byte @@ -53,8 +53,8 @@ type PersonaStateEvent struct { // Fired when a clan's state has been changed type ClanStateEvent struct { - ClanId SteamId `json:",string"` - AccountFlags EAccountFlags + ClanId steamid.SteamId `json:",string"` + AccountFlags steamlang.EAccountFlags ClanName string Avatar []byte MemberTotalCount uint32 @@ -75,79 +75,79 @@ type ClanEventDetails struct { // Fired in response to adding a friend to your friends list type FriendAddedEvent struct { - Result EResult - SteamId SteamId `json:",string"` + Result steamlang.EResult + SteamId steamid.SteamId `json:",string"` PersonaName string } // Fired when the client receives a message from either a friend or a chat room type ChatMsgEvent struct { - ChatRoomId SteamId `json:",string"` // not set for friend messages - ChatterId SteamId `json:",string"` + ChatRoomId steamid.SteamId `json:",string"` // not set for friend messages + ChatterId steamid.SteamId `json:",string"` Message string - EntryType EChatEntryType + EntryType steamlang.EChatEntryType Timestamp time.Time Offline bool } // Whether the type is ChatMsg func (c *ChatMsgEvent) IsMessage() bool { - return c.EntryType == EChatEntryType_ChatMsg + return c.EntryType == steamlang.EChatEntryType_ChatMsg } // Fired in response to joining a chat type ChatEnterEvent struct { - ChatRoomId SteamId `json:",string"` - FriendId SteamId `json:",string"` - ChatRoomType EChatRoomType - OwnerId SteamId `json:",string"` - ClanId SteamId `json:",string"` + ChatRoomId steamid.SteamId `json:",string"` + FriendId steamid.SteamId `json:",string"` + ChatRoomType steamlang.EChatRoomType + OwnerId steamid.SteamId `json:",string"` + ClanId steamid.SteamId `json:",string"` ChatFlags byte - EnterResponse EChatRoomEnterResponse + EnterResponse steamlang.EChatRoomEnterResponse Name string } // Fired in response to a chat member's info being received type ChatMemberInfoEvent struct { - ChatRoomId SteamId `json:",string"` - Type EChatInfoType + ChatRoomId steamid.SteamId `json:",string"` + Type steamlang.EChatInfoType StateChangeInfo StateChangeDetails } type StateChangeDetails struct { - ChatterActedOn SteamId `json:",string"` - StateChange EChatMemberStateChange - ChatterActedBy SteamId `json:",string"` + ChatterActedOn steamid.SteamId `json:",string"` + StateChange steamlang.EChatMemberStateChange + ChatterActedBy steamid.SteamId `json:",string"` } // Fired when a chat action has completed type ChatActionResultEvent struct { - ChatRoomId SteamId `json:",string"` - ChatterId SteamId `json:",string"` - Action EChatAction - Result EChatActionResult + ChatRoomId steamid.SteamId `json:",string"` + ChatterId steamid.SteamId `json:",string"` + Action steamlang.EChatAction + Result steamlang.EChatActionResult } // Fired when a chat invite is received type ChatInviteEvent struct { - InvitedId SteamId `json:",string"` - ChatRoomId SteamId `json:",string"` - PatronId SteamId `json:",string"` - ChatRoomType EChatRoomType - FriendChatId SteamId `json:",string"` + InvitedId steamid.SteamId `json:",string"` + ChatRoomId steamid.SteamId `json:",string"` + PatronId steamid.SteamId `json:",string"` + ChatRoomType steamlang.EChatRoomType + FriendChatId steamid.SteamId `json:",string"` ChatRoomName string GameId uint64 `json:",string"` } // Fired in response to ignoring a friend type IgnoreFriendEvent struct { - Result EResult + Result steamlang.EResult } // Fired in response to requesting profile info for a user type ProfileInfoEvent struct { - Result EResult - SteamId SteamId `json:",string"` + Result steamlang.EResult + SteamId steamid.SteamId `json:",string"` TimeCreated uint32 RealName string CityName string diff --git a/socialcache/chats.go b/socialcache/chats.go index 4a62ec2a..687bdec7 100644 --- a/socialcache/chats.go +++ b/socialcache/chats.go @@ -4,8 +4,8 @@ import ( "errors" "sync" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" - . "github.com/Philipp15b/go-steam/v2/steamid" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/steamid" ) // Chats list is a thread safe map @@ -15,12 +15,12 @@ import ( // } type ChatsList struct { mutex sync.RWMutex - byId map[SteamId]*Chat + byId map[steamid.SteamId]*Chat } // Returns a new chats list func NewChatsList() *ChatsList { - return &ChatsList{byId: make(map[SteamId]*Chat)} + return &ChatsList{byId: make(map[steamid.SteamId]*Chat)} } // Adds a chat to the chat list @@ -28,52 +28,52 @@ func (list *ChatsList) Add(chat Chat) { list.mutex.Lock() defer list.mutex.Unlock() _, exists := list.byId[chat.SteamId] - if !exists { //make sure this doesnt already exist + if !exists { // make sure this doesnt already exist list.byId[chat.SteamId] = &chat } } // Removes a chat from the chat list -func (list *ChatsList) Remove(id SteamId) { +func (list *ChatsList) Remove(id steamid.SteamId) { list.mutex.Lock() defer list.mutex.Unlock() delete(list.byId, id) } // Adds a chat member to a given chat -func (list *ChatsList) AddChatMember(id SteamId, member ChatMember) { +func (list *ChatsList) AddChatMember(id steamid.SteamId, member ChatMember) { list.mutex.Lock() defer list.mutex.Unlock() chat := list.byId[id] - if chat == nil { //Chat doesn't exist + if chat == nil { // Chat doesn't exist chat = &Chat{SteamId: id} list.byId[id] = chat } - if chat.ChatMembers == nil { //New chat - chat.ChatMembers = make(map[SteamId]ChatMember) + if chat.ChatMembers == nil { // New chat + chat.ChatMembers = make(map[steamid.SteamId]ChatMember) } chat.ChatMembers[member.SteamId] = member } // Removes a chat member from a given chat -func (list *ChatsList) RemoveChatMember(id SteamId, member SteamId) { +func (list *ChatsList) RemoveChatMember(id steamid.SteamId, member steamid.SteamId) { list.mutex.Lock() defer list.mutex.Unlock() chat := list.byId[id] - if chat == nil { //Chat doesn't exist + if chat == nil { // Chat doesn't exist return } - if chat.ChatMembers == nil { //New chat + if chat.ChatMembers == nil { // New chat return } delete(chat.ChatMembers, member) } // Returns a copy of the chats map -func (list *ChatsList) GetCopy() map[SteamId]Chat { +func (list *ChatsList) GetCopy() map[steamid.SteamId]Chat { list.mutex.RLock() defer list.mutex.RUnlock() - glist := make(map[SteamId]Chat) + glist := make(map[steamid.SteamId]Chat) for key, chat := range list.byId { glist[key] = *chat } @@ -81,7 +81,7 @@ func (list *ChatsList) GetCopy() map[SteamId]Chat { } // Returns a copy of the chat of a given SteamId -func (list *ChatsList) ById(id SteamId) (Chat, error) { +func (list *ChatsList) ById(id steamid.SteamId) (Chat, error) { list.mutex.RLock() defer list.mutex.RUnlock() if val, ok := list.byId[id]; ok { @@ -99,14 +99,14 @@ func (list *ChatsList) Count() int { // A Chat type Chat struct { - SteamId SteamId `json:",string"` - GroupId SteamId `json:",string"` - ChatMembers map[SteamId]ChatMember + SteamId steamid.SteamId `json:",string"` + GroupId steamid.SteamId `json:",string"` + ChatMembers map[steamid.SteamId]ChatMember } // A Chat Member type ChatMember struct { - SteamId SteamId `json:",string"` - ChatPermissions EChatPermission - ClanPermissions EClanPermission + SteamId steamid.SteamId `json:",string"` + ChatPermissions steamlang.EChatPermission + ClanPermissions steamlang.EClanPermission } diff --git a/socialcache/friends.go b/socialcache/friends.go index e3329742..c4b82e9b 100644 --- a/socialcache/friends.go +++ b/socialcache/friends.go @@ -4,8 +4,8 @@ import ( "errors" "sync" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" - . "github.com/Philipp15b/go-steam/v2/steamid" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/steamid" ) // Friends list is a thread safe map @@ -15,12 +15,12 @@ import ( // } type FriendsList struct { mutex sync.RWMutex - byId map[SteamId]*Friend + byId map[steamid.SteamId]*Friend } // Returns a new friends list func NewFriendsList() *FriendsList { - return &FriendsList{byId: make(map[SteamId]*Friend)} + return &FriendsList{byId: make(map[steamid.SteamId]*Friend)} } // Adds a friend to the friend list @@ -28,23 +28,23 @@ func (list *FriendsList) Add(friend Friend) { list.mutex.Lock() defer list.mutex.Unlock() _, exists := list.byId[friend.SteamId] - if !exists { //make sure this doesnt already exist + if !exists { // make sure this doesnt already exist list.byId[friend.SteamId] = &friend } } // Removes a friend from the friend list -func (list *FriendsList) Remove(id SteamId) { +func (list *FriendsList) Remove(id steamid.SteamId) { list.mutex.Lock() defer list.mutex.Unlock() delete(list.byId, id) } // Returns a copy of the friends map -func (list *FriendsList) GetCopy() map[SteamId]Friend { +func (list *FriendsList) GetCopy() map[steamid.SteamId]Friend { list.mutex.RLock() defer list.mutex.RUnlock() - flist := make(map[SteamId]Friend) + flist := make(map[steamid.SteamId]Friend) for key, friend := range list.byId { flist[key] = *friend } @@ -52,7 +52,7 @@ func (list *FriendsList) GetCopy() map[SteamId]Friend { } // Returns a copy of the friend of a given SteamId -func (list *FriendsList) ById(id SteamId) (Friend, error) { +func (list *FriendsList) ById(id steamid.SteamId) (Friend, error) { list.mutex.RLock() defer list.mutex.RUnlock() if val, ok := list.byId[id]; ok { @@ -68,8 +68,8 @@ func (list *FriendsList) Count() int { return len(list.byId) } -//Setter methods -func (list *FriendsList) SetName(id SteamId, name string) { +// Setter methods +func (list *FriendsList) SetName(id steamid.SteamId, name string) { list.mutex.Lock() defer list.mutex.Unlock() if val, ok := list.byId[id]; ok { @@ -77,7 +77,7 @@ func (list *FriendsList) SetName(id SteamId, name string) { } } -func (list *FriendsList) SetAvatar(id SteamId, hash []byte) { +func (list *FriendsList) SetAvatar(id steamid.SteamId, hash []byte) { list.mutex.Lock() defer list.mutex.Unlock() if val, ok := list.byId[id]; ok { @@ -85,7 +85,7 @@ func (list *FriendsList) SetAvatar(id SteamId, hash []byte) { } } -func (list *FriendsList) SetRelationship(id SteamId, relationship EFriendRelationship) { +func (list *FriendsList) SetRelationship(id steamid.SteamId, relationship steamlang.EFriendRelationship) { list.mutex.Lock() defer list.mutex.Unlock() if val, ok := list.byId[id]; ok { @@ -93,7 +93,7 @@ func (list *FriendsList) SetRelationship(id SteamId, relationship EFriendRelatio } } -func (list *FriendsList) SetPersonaState(id SteamId, state EPersonaState) { +func (list *FriendsList) SetPersonaState(id steamid.SteamId, state steamlang.EPersonaState) { list.mutex.Lock() defer list.mutex.Unlock() if val, ok := list.byId[id]; ok { @@ -101,7 +101,7 @@ func (list *FriendsList) SetPersonaState(id SteamId, state EPersonaState) { } } -func (list *FriendsList) SetPersonaStateFlags(id SteamId, flags EPersonaStateFlag) { +func (list *FriendsList) SetPersonaStateFlags(id steamid.SteamId, flags steamlang.EPersonaStateFlag) { list.mutex.Lock() defer list.mutex.Unlock() if val, ok := list.byId[id]; ok { @@ -109,7 +109,7 @@ func (list *FriendsList) SetPersonaStateFlags(id SteamId, flags EPersonaStateFla } } -func (list *FriendsList) SetGameAppId(id SteamId, gameappid uint32) { +func (list *FriendsList) SetGameAppId(id steamid.SteamId, gameappid uint32) { list.mutex.Lock() defer list.mutex.Unlock() if val, ok := list.byId[id]; ok { @@ -117,7 +117,7 @@ func (list *FriendsList) SetGameAppId(id SteamId, gameappid uint32) { } } -func (list *FriendsList) SetGameId(id SteamId, gameid uint64) { +func (list *FriendsList) SetGameId(id steamid.SteamId, gameid uint64) { list.mutex.Lock() defer list.mutex.Unlock() if val, ok := list.byId[id]; ok { @@ -125,7 +125,7 @@ func (list *FriendsList) SetGameId(id SteamId, gameid uint64) { } } -func (list *FriendsList) SetGameName(id SteamId, name string) { +func (list *FriendsList) SetGameName(id steamid.SteamId, name string) { list.mutex.Lock() defer list.mutex.Unlock() if val, ok := list.byId[id]; ok { @@ -135,12 +135,12 @@ func (list *FriendsList) SetGameName(id SteamId, name string) { // A Friend type Friend struct { - SteamId SteamId `json:",string"` + SteamId steamid.SteamId `json:",string"` Name string Avatar []byte - Relationship EFriendRelationship - PersonaState EPersonaState - PersonaStateFlags EPersonaStateFlag + Relationship steamlang.EFriendRelationship + PersonaState steamlang.EPersonaState + PersonaStateFlags steamlang.EPersonaStateFlag GameAppId uint32 GameId uint64 `json:",string"` GameName string diff --git a/socialcache/groups.go b/socialcache/groups.go index b229112e..95c74c3a 100644 --- a/socialcache/groups.go +++ b/socialcache/groups.go @@ -4,8 +4,8 @@ import ( "errors" "sync" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" - . "github.com/Philipp15b/go-steam/v2/steamid" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/steamid" ) // Groups list is a thread safe map @@ -15,12 +15,12 @@ import ( // } type GroupsList struct { mutex sync.RWMutex - byId map[SteamId]*Group + byId map[steamid.SteamId]*Group } // Returns a new groups list func NewGroupsList() *GroupsList { - return &GroupsList{byId: make(map[SteamId]*Group)} + return &GroupsList{byId: make(map[steamid.SteamId]*Group)} } // Adds a group to the group list @@ -28,23 +28,23 @@ func (list *GroupsList) Add(group Group) { list.mutex.Lock() defer list.mutex.Unlock() _, exists := list.byId[group.SteamId] - if !exists { //make sure this doesnt already exist + if !exists { // make sure this doesnt already exist list.byId[group.SteamId] = &group } } // Removes a group from the group list -func (list *GroupsList) Remove(id SteamId) { +func (list *GroupsList) Remove(id steamid.SteamId) { list.mutex.Lock() defer list.mutex.Unlock() delete(list.byId, id) } // Returns a copy of the groups map -func (list *GroupsList) GetCopy() map[SteamId]Group { +func (list *GroupsList) GetCopy() map[steamid.SteamId]Group { list.mutex.RLock() defer list.mutex.RUnlock() - glist := make(map[SteamId]Group) + glist := make(map[steamid.SteamId]Group) for key, group := range list.byId { glist[key] = *group } @@ -52,7 +52,7 @@ func (list *GroupsList) GetCopy() map[SteamId]Group { } // Returns a copy of the group of a given SteamId -func (list *GroupsList) ById(id SteamId) (Group, error) { +func (list *GroupsList) ById(id steamid.SteamId) (Group, error) { list.mutex.RLock() defer list.mutex.RUnlock() id = id.ChatToClan() @@ -69,8 +69,8 @@ func (list *GroupsList) Count() int { return len(list.byId) } -//Setter methods -func (list *GroupsList) SetName(id SteamId, name string) { +// Setter methods +func (list *GroupsList) SetName(id steamid.SteamId, name string) { list.mutex.Lock() defer list.mutex.Unlock() id = id.ChatToClan() @@ -79,7 +79,7 @@ func (list *GroupsList) SetName(id SteamId, name string) { } } -func (list *GroupsList) SetAvatar(id SteamId, hash []byte) { +func (list *GroupsList) SetAvatar(id steamid.SteamId, hash []byte) { list.mutex.Lock() defer list.mutex.Unlock() id = id.ChatToClan() @@ -88,7 +88,7 @@ func (list *GroupsList) SetAvatar(id SteamId, hash []byte) { } } -func (list *GroupsList) SetRelationship(id SteamId, relationship EClanRelationship) { +func (list *GroupsList) SetRelationship(id steamid.SteamId, relationship steamlang.EClanRelationship) { list.mutex.Lock() defer list.mutex.Unlock() id = id.ChatToClan() @@ -97,7 +97,7 @@ func (list *GroupsList) SetRelationship(id SteamId, relationship EClanRelationsh } } -func (list *GroupsList) SetMemberTotalCount(id SteamId, count uint32) { +func (list *GroupsList) SetMemberTotalCount(id steamid.SteamId, count uint32) { list.mutex.Lock() defer list.mutex.Unlock() id = id.ChatToClan() @@ -106,7 +106,7 @@ func (list *GroupsList) SetMemberTotalCount(id SteamId, count uint32) { } } -func (list *GroupsList) SetMemberOnlineCount(id SteamId, count uint32) { +func (list *GroupsList) SetMemberOnlineCount(id steamid.SteamId, count uint32) { list.mutex.Lock() defer list.mutex.Unlock() id = id.ChatToClan() @@ -115,7 +115,7 @@ func (list *GroupsList) SetMemberOnlineCount(id SteamId, count uint32) { } } -func (list *GroupsList) SetMemberChattingCount(id SteamId, count uint32) { +func (list *GroupsList) SetMemberChattingCount(id steamid.SteamId, count uint32) { list.mutex.Lock() defer list.mutex.Unlock() id = id.ChatToClan() @@ -124,7 +124,7 @@ func (list *GroupsList) SetMemberChattingCount(id SteamId, count uint32) { } } -func (list *GroupsList) SetMemberInGameCount(id SteamId, count uint32) { +func (list *GroupsList) SetMemberInGameCount(id steamid.SteamId, count uint32) { list.mutex.Lock() defer list.mutex.Unlock() id = id.ChatToClan() @@ -135,10 +135,10 @@ func (list *GroupsList) SetMemberInGameCount(id SteamId, count uint32) { // A Group type Group struct { - SteamId SteamId `json:",string"` + SteamId steamid.SteamId `json:",string"` Name string Avatar []byte - Relationship EClanRelationship + Relationship steamlang.EClanRelationship MemberTotalCount uint32 MemberOnlineCount uint32 MemberChattingCount uint32 diff --git a/tf2/tf2.go b/tf2/tf2.go index df58c700..638289e2 100644 --- a/tf2/tf2.go +++ b/tf2/tf2.go @@ -5,8 +5,8 @@ package tf2 import ( "github.com/Philipp15b/go-steam/v2" - . "github.com/Philipp15b/go-steam/v2/protocol/gamecoordinator" - . "github.com/Philipp15b/go-steam/v2/tf2/protocol" + "github.com/Philipp15b/go-steam/v2/protocol/gamecoordinator" + "github.com/Philipp15b/go-steam/v2/tf2/protocol" "github.com/Philipp15b/go-steam/v2/tf2/protocol/protobuf" ) @@ -34,32 +34,32 @@ func (t *TF2) SetPlaying(playing bool) { } func (t *TF2) SetItemPosition(itemId, position uint64) { - t.client.GC.Write(NewGCMsg(AppId, uint32(protobuf.EGCItemMsg_k_EMsgGCSetSingleItemPosition), &MsgGCSetItemPosition{ + t.client.GC.Write(gamecoordinator.NewGCMsg(AppId, uint32(protobuf.EGCItemMsg_k_EMsgGCSetSingleItemPosition), &protocol.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{ + t.client.GC.Write(gamecoordinator.NewGCMsg(AppId, uint32(protobuf.EGCItemMsg_k_EMsgGCCraft), &protocol.MsgGCCraft{ Recipe: recipe, Items: items, })) } func (t *TF2) DeleteItem(itemId uint64) { - t.client.GC.Write(NewGCMsg(AppId, uint32(protobuf.EGCItemMsg_k_EMsgGCDelete), &MsgGCDeleteItem{itemId})) + t.client.GC.Write(gamecoordinator.NewGCMsg(AppId, uint32(protobuf.EGCItemMsg_k_EMsgGCDelete), &protocol.MsgGCDeleteItem{itemId})) } func (t *TF2) NameItem(toolId, target uint64, name string) { - t.client.GC.Write(NewGCMsg(AppId, uint32(protobuf.EGCItemMsg_k_EMsgGCNameItem), &MsgGCNameItem{ + t.client.GC.Write(gamecoordinator.NewGCMsg(AppId, uint32(protobuf.EGCItemMsg_k_EMsgGCNameItem), &protocol.MsgGCNameItem{ toolId, target, name, })) } type GCReadyEvent struct{} -func (t *TF2) HandleGCPacket(packet *GCPacket) { +func (t *TF2) HandleGCPacket(packet *gamecoordinator.GCPacket) { if packet.AppId != AppId { return } @@ -69,7 +69,7 @@ func (t *TF2) HandleGCPacket(packet *GCPacket) { } } -func (t *TF2) handleWelcome(packet *GCPacket) { +func (t *TF2) handleWelcome(packet *gamecoordinator.GCPacket) { // the packet's body is pretty useless t.client.Emit(&GCReadyEvent{}) } diff --git a/trading.go b/trading.go index 47316a39..638202ee 100644 --- a/trading.go +++ b/trading.go @@ -1,10 +1,10 @@ package steam import ( - . "github.com/Philipp15b/go-steam/v2/protocol" - . "github.com/Philipp15b/go-steam/v2/protocol/protobuf" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" - . "github.com/Philipp15b/go-steam/v2/steamid" + "github.com/Philipp15b/go-steam/v2/protocol" + "github.com/Philipp15b/go-steam/v2/protocol/protobuf" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/steamid" "github.com/golang/protobuf/proto" ) @@ -21,41 +21,41 @@ type Trading struct { type TradeRequestId uint32 -func (t *Trading) HandlePacket(packet *Packet) { +func (t *Trading) HandlePacket(packet *protocol.Packet) { switch packet.EMsg { - case EMsg_EconTrading_InitiateTradeProposed: - msg := new(CMsgTrading_InitiateTradeRequest) + case steamlang.EMsg_EconTrading_InitiateTradeProposed: + msg := new(protobuf.CMsgTrading_InitiateTradeRequest) packet.ReadProtoMsg(msg) t.client.Emit(&TradeProposedEvent{ RequestId: TradeRequestId(msg.GetTradeRequestId()), - Other: SteamId(msg.GetOtherSteamid()), + Other: steamid.SteamId(msg.GetOtherSteamid()), }) - case EMsg_EconTrading_InitiateTradeResult: - msg := new(CMsgTrading_InitiateTradeResponse) + case steamlang.EMsg_EconTrading_InitiateTradeResult: + msg := new(protobuf.CMsgTrading_InitiateTradeResponse) packet.ReadProtoMsg(msg) t.client.Emit(&TradeResultEvent{ RequestId: TradeRequestId(msg.GetTradeRequestId()), - Response: EEconTradeResponse(msg.GetResponse()), - Other: SteamId(msg.GetOtherSteamid()), + Response: steamlang.EEconTradeResponse(msg.GetResponse()), + Other: steamid.SteamId(msg.GetOtherSteamid()), NumDaysSteamGuardRequired: msg.GetSteamguardRequiredDays(), NumDaysNewDeviceCooldown: msg.GetNewDeviceCooldownDays(), DefaultNumDaysPasswordResetProbation: msg.GetDefaultPasswordResetProbationDays(), NumDaysPasswordResetProbation: msg.GetPasswordResetProbationDays(), }) - case EMsg_EconTrading_StartSession: - msg := new(CMsgTrading_StartSession) + case steamlang.EMsg_EconTrading_StartSession: + msg := new(protobuf.CMsgTrading_StartSession) packet.ReadProtoMsg(msg) t.client.Emit(&TradeSessionStartEvent{ - Other: SteamId(msg.GetOtherSteamid()), + Other: steamid.SteamId(msg.GetOtherSteamid()), }) } } // Requests a trade. You'll receive a TradeResultEvent if the request fails or // if the friend accepted the trade. -func (t *Trading) RequestTrade(other SteamId) { - t.client.Write(NewClientMsgProtobuf(EMsg_EconTrading_InitiateTradeRequest, &CMsgTrading_InitiateTradeRequest{ +func (t *Trading) RequestTrade(other steamid.SteamId) { + t.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_EconTrading_InitiateTradeRequest, &protobuf.CMsgTrading_InitiateTradeRequest{ OtherSteamid: proto.Uint64(uint64(other)), })) } @@ -69,15 +69,15 @@ func (t *Trading) RespondRequest(requestId TradeRequestId, accept bool) { resp = 1 } - t.client.Write(NewClientMsgProtobuf(EMsg_EconTrading_InitiateTradeResponse, &CMsgTrading_InitiateTradeResponse{ + t.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_EconTrading_InitiateTradeResponse, &protobuf.CMsgTrading_InitiateTradeResponse{ TradeRequestId: proto.Uint32(uint32(requestId)), Response: proto.Uint32(resp), })) } // This cancels a request made with RequestTrade. -func (t *Trading) CancelRequest(other SteamId) { - t.client.Write(NewClientMsgProtobuf(EMsg_EconTrading_CancelTradeRequest, &CMsgTrading_CancelTradeRequest{ +func (t *Trading) CancelRequest(other steamid.SteamId) { + t.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_EconTrading_CancelTradeRequest, &protobuf.CMsgTrading_CancelTradeRequest{ OtherSteamid: proto.Uint64(uint64(other)), })) } diff --git a/trading_events.go b/trading_events.go index 6ec511e7..1e0ef351 100644 --- a/trading_events.go +++ b/trading_events.go @@ -1,19 +1,19 @@ package steam import ( - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" - . "github.com/Philipp15b/go-steam/v2/steamid" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/steamid" ) type TradeProposedEvent struct { RequestId TradeRequestId - Other SteamId `json:",string"` + Other steamid.SteamId `json:",string"` } type TradeResultEvent struct { RequestId TradeRequestId - Response EEconTradeResponse - Other SteamId `json:",string"` + Response steamlang.EEconTradeResponse + Other steamid.SteamId `json:",string"` // Number of days Steam Guard is required to have been active NumDaysSteamGuardRequired uint32 // Number of days a new device cannot trade for. @@ -25,5 +25,5 @@ type TradeResultEvent struct { } type TradeSessionStartEvent struct { - Other SteamId `json:",string"` + Other steamid.SteamId `json:",string"` } diff --git a/web.go b/web.go index a7bef081..b158e847 100644 --- a/web.go +++ b/web.go @@ -12,9 +12,9 @@ import ( "sync/atomic" "github.com/Philipp15b/go-steam/v2/cryptoutil" - . "github.com/Philipp15b/go-steam/v2/protocol" - . "github.com/Philipp15b/go-steam/v2/protocol/protobuf" - . "github.com/Philipp15b/go-steam/v2/protocol/steamlang" + "github.com/Philipp15b/go-steam/v2/protocol" + "github.com/Philipp15b/go-steam/v2/protocol/protobuf" + "github.com/Philipp15b/go-steam/v2/protocol/steamlang" "github.com/golang/protobuf/proto" ) @@ -39,11 +39,11 @@ type Web struct { client *Client } -func (w *Web) HandlePacket(packet *Packet) { +func (w *Web) HandlePacket(packet *protocol.Packet) { switch packet.EMsg { - case EMsg_ClientNewLoginKey: + case steamlang.EMsg_ClientNewLoginKey: w.handleNewLoginKey(packet) - case EMsg_ClientRequestWebAPIAuthenticateUserNonceResponse: + case steamlang.EMsg_ClientRequestWebAPIAuthenticateUserNonceResponse: w.handleAuthNonceResponse(packet) } } @@ -75,7 +75,7 @@ func (w *Web) apiLogOn() error { sessionKey := make([]byte, 32) rand.Read(sessionKey) - cryptedSessionKey := cryptoutil.RSAEncrypt(GetPublicKey(EUniverse_Public), sessionKey) + cryptedSessionKey := cryptoutil.RSAEncrypt(GetPublicKey(steamlang.EUniverse_Public), sessionKey) ciph, _ := aes.NewCipher(sessionKey) cryptedLoginKey := cryptoutil.SymmetricEncrypt(ciph, []byte(w.webLoginKey)) data := make(url.Values) @@ -92,7 +92,7 @@ func (w *Web) apiLogOn() error { if resp.StatusCode == 401 { // our web login key has expired, request a new one atomic.StoreUint32(&w.relogOnNonce, 1) - w.client.Write(NewClientMsgProtobuf(EMsg_ClientRequestWebAPIAuthenticateUserNonce, new(CMsgClientRequestWebAPIAuthenticateUserNonce))) + w.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientRequestWebAPIAuthenticateUserNonce, new(protobuf.CMsgClientRequestWebAPIAuthenticateUserNonce))) return nil } else if resp.StatusCode != 200 { return errors.New("steam.Web.apiLogOn: request failed with status " + resp.Status) @@ -116,11 +116,11 @@ func (w *Web) apiLogOn() error { return nil } -func (w *Web) handleNewLoginKey(packet *Packet) { - msg := new(CMsgClientNewLoginKey) +func (w *Web) handleNewLoginKey(packet *protocol.Packet) { + msg := new(protobuf.CMsgClientNewLoginKey) packet.ReadProtoMsg(msg) - w.client.Write(NewClientMsgProtobuf(EMsg_ClientNewLoginKeyAccepted, &CMsgClientNewLoginKeyAccepted{ + w.client.Write(protocol.NewClientMsgProtobuf(steamlang.EMsg_ClientNewLoginKeyAccepted, &protobuf.CMsgClientNewLoginKeyAccepted{ UniqueId: proto.Uint32(msg.GetUniqueId()), })) @@ -130,9 +130,9 @@ func (w *Web) handleNewLoginKey(packet *Packet) { w.client.Emit(new(WebSessionIdEvent)) } -func (w *Web) handleAuthNonceResponse(packet *Packet) { +func (w *Web) handleAuthNonceResponse(packet *protocol.Packet) { // this has to be the best name for a message yet. - msg := new(CMsgClientRequestWebAPIAuthenticateUserNonceResponse) + msg := new(protobuf.CMsgClientRequestWebAPIAuthenticateUserNonceResponse) packet.ReadProtoMsg(msg) w.webLoginKey = msg.GetWebapiAuthenticateUserNonce() From 6d42ef4841d0b50fb8e24be2495d624398927287 Mon Sep 17 00:00:00 2001 From: James Eagle Date: Sun, 25 Apr 2021 22:11:06 +0100 Subject: [PATCH 2/3] Update generator --- generator/GoSteamLanguageGenerator/GoGen.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/generator/GoSteamLanguageGenerator/GoGen.cs b/generator/GoSteamLanguageGenerator/GoGen.cs index 0742da0a..2632e065 100644 --- a/generator/GoSteamLanguageGenerator/GoGen.cs +++ b/generator/GoSteamLanguageGenerator/GoGen.cs @@ -60,7 +60,7 @@ public void EmitClasses(Node root, StringBuilder sb) sb.AppendLine(" \"github.com/golang/protobuf/proto\""); sb.AppendLine(" \"github.com/Philipp15b/go-steam/v2/steamid\""); sb.AppendLine(" \"github.com/Philipp15b/go-steam/v2/rwu\""); - sb.AppendLine(" . \"github.com/Philipp15b/go-steam/v2/protocol/protobuf\""); + sb.AppendLine(" \"github.com/Philipp15b/go-steam/v2/protocol/protobuf\""); sb.AppendLine(")"); sb.AppendLine(); @@ -283,7 +283,7 @@ private void EmitClassDef(ClassNode cnode, StringBuilder sb) } else if (node.Flags == "proto") { - sb.AppendLine(" " + GetUpperName(node.Name) + " *" + EmitType(node.Type)); + sb.AppendLine(" " + GetUpperName(node.Name) + " *protobuf." + EmitType(node.Type)); } else { @@ -315,7 +315,7 @@ private void EmitClassConstructor(ClassNode cnode, StringBuilder sb) } else if (node.Flags == "proto") { - ctor = "new(" + GetUpperName(EmitType(node.Type)) + ")"; + ctor = "new(protobuf." + GetUpperName(EmitType(node.Type)) + ")"; } else if (firstDefault == null) { From 70c092ed253a0a0396898045702611420971cce7 Mon Sep 17 00:00:00 2001 From: James Eagle Date: Mon, 26 Apr 2021 21:21:26 +0100 Subject: [PATCH 3/3] Reorder imports --- protocol/steamlang/messages.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/protocol/steamlang/messages.go b/protocol/steamlang/messages.go index 20c0e48d..7c81c8cc 100644 --- a/protocol/steamlang/messages.go +++ b/protocol/steamlang/messages.go @@ -5,12 +5,11 @@ package steamlang import ( "encoding/binary" - "io" - "github.com/Philipp15b/go-steam/v2/protocol/protobuf" "github.com/Philipp15b/go-steam/v2/rwu" "github.com/Philipp15b/go-steam/v2/steamid" "github.com/golang/protobuf/proto" + "io" ) const UdpHeader_MAGIC uint32 = 0x31305356