Philipp15b / go-steam

Steam's protocol in Go to allow automation of different actions on the Steam network without running an actual Steam client. Includes APIs for friends, chatting, trading, trade offers and TF2 crafting.
https://pkg.go.dev/github.com/Philipp15b/go-steam/v3
Other
391 stars 131 forks source link

Fixes Auth Panic #138

Closed Step7750 closed 1 year ago

berkanaslan commented 10 months ago

I've got the same panic. What was the reason that you closed the PR?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x8 pc=0x1046aa6b0]

goroutine 23 [running]:
github.com/Philipp15b/go-steam/v3.(*Auth).handleLogOnResponse(0x1400019bce0, 0x140004b15c0)
        /Users/berkan/go/pkg/mod/github.com/!philipp15b/go-steam/v3@v3.0.0/auth.go:113 +0xe0
github.com/Philipp15b/go-steam/v3.(*Auth).HandlePacket(0x70?, 0x14000180000?)
        /Users/berkan/go/pkg/mod/github.com/!philipp15b/go-steam/v3@v3.0.0/auth.go:87 +0x50
github.com/Philipp15b/go-steam/v3.(*Client).handlePacket(0x140003f6000, 0x140004b15c0)
        /Users/berkan/go/pkg/mod/github.com/!philipp15b/go-steam/v3@v3.0.0/client.go:300 +0x13c
github.com/Philipp15b/go-steam/v3.(*Client).handleMulti(0x140003f6000, 0x140004b11a0)
        /Users/berkan/go/pkg/mod/github.com/!philipp15b/go-steam/v3@v3.0.0/client.go:372 +0x3d8
github.com/Philipp15b/go-steam/v3.(*Client).handlePacket(0x140003f6000, 0x140004b11a0)
        /Users/berkan/go/pkg/mod/github.com/!philipp15b/go-steam/v3@v3.0.0/client.go:292 +0x58
github.com/Philipp15b/go-steam/v3.(*Client).readLoop(0x140003f6000)
        /Users/berkan/go/pkg/mod/github.com/!philipp15b/go-steam/v3@v3.0.0/client.go:234 +0x2c
created by github.com/Philipp15b/go-steam/v3.(*Client).ConnectToBind in goroutine 1
        /Users/berkan/go/pkg/mod/github.com/!philipp15b/go-steam/v3@v3.0.0/client.go:178 +0x184
exit status 2
berkanaslan commented 10 months ago

Yeah, probably I'm confused.

func (s *GameCoordinatorService) Connect(username, password, twoFactorSecret string) {
    developerLoginInformation := new(steam.LogOnDetails)
    developerLoginInformation.Username = username
    developerLoginInformation.Password = password

    totpInstance := totp.NewTotp(twoFactorSecret)
    twoFactorCode, err := totpInstance.GenerateCode()

    if err != nil {
        log.Println("Error generating 2FA code: ", err)
    }

    developerLoginInformation.TwoFactorCode = twoFactorCode
    developerLoginInformation.ShouldRememberPassword = true

    client := steam.NewClient()

    if _, connectErr := client.Connect(); connectErr != nil {
        log.Panic(connectErr)
    }

    var connected sync.WaitGroup
    connected.Add(1)

    go func() {
        for event := range client.Events() {
            switch e := event.(type) {
            case *steam.ConnectedEvent:
                log.Println("Connected to steam. logging on...")
                client.Auth.LogOn(developerLoginInformation)
            case *steam.LogOnDetails:
                log.Println("Logging on...")
            case *steam.LoggedOnEvent:
                log.Println("Logged on successfully.")
                s.client = client
                client.Social.SetPersonaState(steamlang.EPersonaState_Invisible)
                s.connectToGameCoordinator()
                connected.Done()
            case steam.DisconnectedEvent:
                log.Println("Disconnected from Steam.")
            case steam.FatalErrorEvent:
                log.Fatal(e)
            case steam.LogOnFailedEvent:
                log.Println("Log on failed: ", e.Result)
            default:
                log.Printf("%T: %v\n", e, e)
            }
        }
    }()

    connected.Wait()
}

And it gives me the error that I put in the above comment. Any thoughts?