Skip to content

Commit 3762249

Browse files
code tidy / cleanups
1 parent b334fca commit 3762249

File tree

7 files changed

+14
-20
lines changed

7 files changed

+14
-20
lines changed

cmd/client/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func main() {
5656
}
5757

5858
if !stalk {
59-
err = commandclient.Login(client, username, password)
59+
err = commandclient.Login(client, username, password, true)
6060
if err != nil {
6161
panic(err)
6262
}

cmd/client/ping.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func Ping(host string, port int) (*PingResult, error) {
4747
}
4848

4949
res := &PingResult{
50-
Delay: time.Now().Sub(start),
50+
Delay: time.Since(start),
5151
PeerID: binary.BigEndian.Uint16(buf[12:]),
5252
}
5353

commandclient/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func (c *CommandClient) Disconnect() error {
5252
return err
5353
}
5454
close(c.netrx)
55+
for _, l := range c.listeners {
56+
close(l)
57+
}
58+
5559
return c.conn.Close()
5660
}
5761

commandclient/clientready.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package commandclient
22

33
import (
44
"errors"
5-
"fmt"
65

76
"github.com/minetest-go/minetest_client/commands"
87
)
@@ -15,15 +14,11 @@ func ClientReady(cc *CommandClient) error {
1514
for o := range ch {
1615
switch o.(type) {
1716
case *commands.ServerCSMRestrictionFlags:
18-
fmt.Println("Server sends csm restriction flags")
19-
20-
fmt.Println("Sending CLIENT_READY")
2117
err := cc.SendCommand(commands.NewClientReady(5, 5, 5, "mt-bot", 4))
2218
if err != nil {
2319
return err
2420
}
2521

26-
fmt.Println("Sending PLAYERPOS")
2722
ppos := commands.NewClientPlayerPos()
2823
err = cc.SendCommand(ppos)
2924
return err

commandclient/init.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package commandclient
22

33
import (
44
"errors"
5-
"fmt"
65
"time"
76

87
"github.com/minetest-go/minetest_client/commands"
@@ -14,9 +13,8 @@ func Init(cc *CommandClient, username string) error {
1413
defer cc.RemoveListener(ch)
1514

1615
for o := range ch {
17-
switch cmd := o.(type) {
16+
switch o.(type) {
1817
case *commands.ServerSetPeer:
19-
fmt.Printf("Received set_peerid: %d\n", cmd.PeerID)
2018
time.Sleep(1 * time.Second)
2119
err := cc.SendOriginalCommand(commands.NewClientInit(username))
2220
return err

commandclient/login.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package commandclient
22

33
import (
44
"errors"
5-
"fmt"
65

76
"github.com/minetest-go/minetest_client/commands"
87
"github.com/minetest-go/minetest_client/packet"
98
"github.com/minetest-go/minetest_client/srp"
109
)
1110

1211
var ErrAccessDenied = errors.New("access denied")
12+
var ErrNotRegistered = errors.New("username not registered")
1313

14-
func Login(cc *CommandClient, username, password string) error {
14+
func Login(cc *CommandClient, username, password string, enable_registration bool) error {
1515
ch := make(chan commands.Command, 100)
1616
cc.AddListener(ch)
1717
defer cc.RemoveListener(ch)
@@ -31,28 +31,30 @@ func Login(cc *CommandClient, username, password string) error {
3131
return err
3232
}
3333

34-
fmt.Printf("Sending SRP bytes A, len=%d\n", len(srppub))
3534
err = cc.SendCommand(commands.NewClientSRPBytesA(srppub))
3635
if err != nil {
3736
return err
3837
}
3938
}
4039

4140
if cmd.AuthMechanismFirstSRP {
41+
if !enable_registration {
42+
// registration not enabled, fail
43+
return ErrNotRegistered
44+
}
45+
4246
// new client
4347
salt, verifier, err := srp.NewClient([]byte(username), []byte(password))
4448
if err != nil {
4549
return err
4650
}
4751

48-
fmt.Printf("Sending first SRP, salt-len=%d, verifier-len=%d\n", len(salt), len(verifier))
4952
err = cc.SendCommand(commands.NewClientFirstSRP(salt, verifier))
5053
if err != nil {
5154
return err
5255
}
5356
}
5457
case *commands.ServerAccessDenied:
55-
fmt.Println("Access denied")
5658
return ErrAccessDenied
5759

5860
case *commands.ServerSRPBytesSB:
@@ -66,14 +68,12 @@ func Login(cc *CommandClient, username, password string) error {
6668

6769
proof := srp.ClientProof(identifier, cmd.BytesS, srppub, cmd.BytesB, clientK)
6870

69-
fmt.Printf("Sending SRP bytes M, len=%d\n", len(proof))
7071
err = cc.SendCommand(commands.NewClientSRPBytesM(proof))
7172
if err != nil {
7273
return err
7374
}
7475

7576
case *commands.ServerAuthAccept:
76-
fmt.Println("Sending INIT2")
7777
err := cc.SendCommand(commands.NewClientInit2())
7878
return err
7979
}

commands/parse.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package commands
22

33
import (
44
"encoding/binary"
5-
"fmt"
65
)
76

87
func Parse(payload []byte) (Command, error) {
@@ -48,8 +47,6 @@ func Parse(payload []byte) (Command, error) {
4847
cmd = &ServerAccessDenied{}
4948
case ServerCommandNodeDefinitions:
5049
cmd = &ServerNodeDefinitions{}
51-
default:
52-
fmt.Printf("Unknown command received: %d\n", commandId)
5350
}
5451

5552
if cmd != nil {

0 commit comments

Comments
 (0)