@@ -2,16 +2,16 @@ package commandclient
22
33import (
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
1211var 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 }
0 commit comments