Idle bool
AutoReply *[]byte
Transfers map[int][]*FileTransfer
+ Agreed bool
}
func (cc *ClientConn) sendAll(t int, fields ...Field) {
// NotifyOthers sends transaction t to other clients connected to the server
func (cc ClientConn) NotifyOthers(t Transaction) {
for _, c := range sortedClients(cc.Server.Clients) {
- if c.ID != cc.ID {
+ if c.ID != cc.ID && c.Agreed {
t.clientID = c.ID
cc.Server.outbox <- t
}
client := s.Clients[uint16(clientID)]
s.mux.Unlock()
if client == nil {
- return errors.New("invalid client")
+ return fmt.Errorf("invalid client id %v", *t.clientID)
}
userName := string(client.UserName)
login := client.Account.Login
IdleTime: new(int),
AutoReply: &[]byte{},
Transfers: make(map[int][]*FileTransfer),
+ Agreed: false,
}
*s.NextGuestID++
ID := *s.NextGuestID
var connectedUsers []Field
for _, c := range sortedClients(s.Clients) {
+ if c.Agreed == false {
+ continue
+ }
user := User{
ID: *c.ID,
Icon: *c.Icon,
// Show agreement to client
c.Server.outbox <- *NewTransaction(tranShowAgreement, c.ID, NewField(fieldData, s.Agreement))
- if _, err := c.notifyNewUserHasJoined(); err != nil {
- return err
+ // assume simplified hotline v1.2.3 login flow that does not require agreement
+ if *c.Version == nil {
+ c.Agreed = true
+ if _, err := c.notifyNewUserHasJoined(); err != nil {
+ return err
+ }
}
+
c.Server.Stats.LoginCount += 1
const readBuffSize = 1024000 // 1KB - TODO: what should this be?
}
func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
- bs := make([]byte, 2)
- binary.BigEndian.PutUint16(bs, *cc.Server.NextGuestID)
-
+ cc.Agreed = true
cc.UserName = t.GetField(fieldUserName).Data
- *cc.ID = bs
*cc.Icon = t.GetField(fieldUserIconID).Data
options := t.GetField(fieldOptions).Data
"io/fs"
"math/rand"
"os"
- "reflect"
"testing"
)
Icon: &[]byte{0, 2},
Flags: &[]byte{0, 3},
UserName: []byte{0, 4},
+ Agreed: true,
},
uint16(2): {
ID: &[]byte{0, 2},
Icon: &[]byte{0, 2},
Flags: &[]byte{0, 3},
UserName: []byte{0, 4},
+ Agreed: true,
+ },
+ uint16(3): {
+ ID: &[]byte{0, 3},
+ Icon: &[]byte{0, 2},
+ Flags: &[]byte{0, 3},
+ UserName: []byte{0, 4},
+ Agreed: false,
},
},
},
t.Errorf("HandleGetUserNameList() error = %v, wantErr %v", err, tt.wantErr)
return
}
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("HandleGetUserNameList() got = %v, want %v", got, tt.want)
- }
+ assert.Equal(t, tt.want, got)
})
}
}