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

how can I disconnect correctly without a data race? #134

Open
pashatag opened this issue Aug 3, 2023 · 0 comments
Open

how can I disconnect correctly without a data race? #134

pashatag opened this issue Aug 3, 2023 · 0 comments

Comments

@pashatag
Copy link

pashatag commented Aug 3, 2023

func (c *Client) Launch(ctx context.Context, username, password string) {
	go func() {
		events := c.client.Events()
		for event := range events {
			switch event.(type) {
			case *steam.ConnectedEvent:
				c.client.Auth.LogOn(&steam.LogOnDetails{
					Username: username,
					Password: password,
				})

			case *steam.LoggedOnEvent:
				c.client.Social.SetPersonaState(steamlang.EPersonaState_Online)
				if c.onLoggin != nil {
					c.onLoggin()
				}

			case *steam.DisconnectedEvent:
				log.Println("disconnected")

			default:
				if c.onRaw != nil {
					c.onRaw(event)
				}
			}
		}
	}()

	steam.InitializeSteamDirectory()
	c.client.Connect()

	go func() {
		<-ctx.Done()
		c.client.Disconnect()
	}()
}
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

1 participant