Skip to content

Commit

Permalink
Merge pull request #114 from Nexure/master
Browse files Browse the repository at this point in the history
Fix gs-bot connect
  • Loading branch information
Philipp15b authored Mar 1, 2021
2 parents 91111a5 + 88c8920 commit f5f3f40
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*.so

# Folders
.idea
.vscode
_obj
_test

Expand Down
16 changes: 9 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (c *Client) Connected() bool {
// This method tries to use an address from the Steam Directory and falls
// back to the built-in server list if the Steam Directory can't be reached.
// If you want to connect to a specific server, use `ConnectTo`.
func (c *Client) Connect() *netutil.PortAddr {
func (c *Client) Connect() (*netutil.PortAddr, error) {
var server *netutil.PortAddr

// try to initialize the directory cache
Expand All @@ -144,32 +144,34 @@ func (c *Client) Connect() *netutil.PortAddr {
server = GetRandomCM()
}

c.ConnectTo(server)
return server
err := c.ConnectTo(server)
return server, err
}

// Connects to a specific server.
// You may want to use one of the `GetRandom*CM()` functions in this package.
// If this client is already connected, it is disconnected first.
func (c *Client) ConnectTo(addr *netutil.PortAddr) {
c.ConnectToBind(addr, nil)
func (c *Client) ConnectTo(addr *netutil.PortAddr) error {
return c.ConnectToBind(addr, nil)
}

// Connects to a specific server, and binds to a specified local IP
// If this client is already connected, it is disconnected first.
func (c *Client) ConnectToBind(addr *netutil.PortAddr, local *net.TCPAddr) {
func (c *Client) ConnectToBind(addr *netutil.PortAddr, local *net.TCPAddr) error {
c.Disconnect()

conn, err := dialTCP(local, addr.ToTCPAddr())
if err != nil {
c.Fatalf("Connect failed: %v", err)
return
return err
}
c.conn = conn
c.writeChan = make(chan IMsg, 5)

go c.readLoop()
go c.writeLoop()

return nil
}

func (c *Client) Disconnect() {
Expand Down
8 changes: 4 additions & 4 deletions gsbot/gsbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ func (s *ServerList) ConnectBind(laddr *net.TCPAddr) (bool, error) {
d, err := ioutil.ReadFile(s.listPath)
if err != nil {
s.bot.Log.Println("Connecting to random server.")
s.bot.Client.Connect()
return false, nil
_, err := s.bot.Client.Connect()
return err == nil, err
}
var addrs []*netutil.PortAddr
err = json.Unmarshal(d, &addrs)
Expand All @@ -146,8 +146,8 @@ func (s *ServerList) ConnectBind(laddr *net.TCPAddr) (bool, error) {
}
raddr := addrs[rand.Intn(len(addrs))]
s.bot.Log.Printf("Connecting to %v from server list\n", raddr)
s.bot.Client.ConnectToBind(raddr, laddr)
return true, nil
err = s.bot.Client.ConnectToBind(raddr, laddr)
return err == nil, err
}

// This module logs incoming packets and events to a directory.
Expand Down

0 comments on commit f5f3f40

Please sign in to comment.