Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime Error on handleLogOnResponse #139

Open
berkanaslan opened this issue Jan 30, 2024 · 2 comments
Open

Runtime Error on handleLogOnResponse #139

berkanaslan opened this issue Jan 30, 2024 · 2 comments

Comments

@berkanaslan
Copy link

berkanaslan commented Jan 30, 2024

The code is throwing panic with a "runtime error: invalid memory address or nil pointer dereference" during the execution of the Connect method. The panic is occurring in the Auth module, more precisely in the handleLogOnResponse function.

Steps to Reproduce:
Call the Connect method with valid username, password, and twoFactorSecret parameters.

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()
}

Error:

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/[email protected]/auth.go:113 +0xe0
github.com/Philipp15b/go-steam/v3.(*Auth).HandlePacket(0x70?, 0x14000180000?)
        /Users/berkan/go/pkg/mod/github.com/!philipp15b/go-steam/[email protected]/auth.go:87 +0x50
github.com/Philipp15b/go-steam/v3.(*Client).handlePacket(0x140003f6000, 0x140004b15c0)
        /Users/berkan/go/pkg/mod/github.com/!philipp15b/go-steam/[email protected]/client.go:300 +0x13c
github.com/Philipp15b/go-steam/v3.(*Client).handleMulti(0x140003f6000, 0x140004b11a0)
        /Users/berkan/go/pkg/mod/github.com/!philipp15b/go-steam/[email protected]/client.go:372 +0x3d8
github.com/Philipp15b/go-steam/v3.(*Client).handlePacket(0x140003f6000, 0x140004b11a0)
        /Users/berkan/go/pkg/mod/github.com/!philipp15b/go-steam/[email protected]/client.go:292 +0x58
github.com/Philipp15b/go-steam/v3.(*Client).readLoop(0x140003f6000)
        /Users/berkan/go/pkg/mod/github.com/!philipp15b/go-steam/[email protected]/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/[email protected]/client.go:178 +0x184
exit status 2

go 1.21
macOS 14.2.1

@Andrew-Savin-msk
Copy link

Andrew-Savin-msk commented Mar 9, 2024

If an arror comes after disconnect event you must recreate the client

@petar-yotsev
Copy link

I also have this problem with just the example code. I found a quick fix, you can just comment out this line in auth.go:
a.client.Web.webLoginKey = *body.WebapiAuthenticateUserNonce
There are checks for webLoginKey and WebapiAuthenticateUserNonce in case it's empty but not before this assignment. I haven't tested it further as I'm just getting into this library but I might do a pull request with a fix at a later point in time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants