Icon []byte // TODO: make fixed size of 2
Version []byte // TODO: make fixed size of 2
- flagsMU sync.Mutex // TODO: move into UserFlags struct
+ FlagsMU sync.Mutex // TODO: move into UserFlags struct
Flags UserFlags
UserName []byte
ClientFileTransferMgr ClientFileTransferMgr
- logger *slog.Logger
+ Logger *slog.Logger
mu sync.RWMutex
}
+func (cc *ClientConn) FileRoot() string {
+ if cc.Account.FileRoot != "" {
+ return cc.Account.FileRoot
+ }
+ return cc.Server.Config.FileRoot
+}
+
type ClientFileTransferMgr struct {
transfers map[FileTransferType]map[FileTransferID]*FileTransfer
cftm.mu.Lock()
defer cftm.mu.Unlock()
- cftm.transfers[ftType][ft.refNum] = ft
+ cftm.transfers[ftType][ft.RefNum] = ft
}
func (cftm *ClientFileTransferMgr) Get(ftType FileTransferType) []FileTransfer {
}
func (cc *ClientConn) handleTransaction(transaction Transaction) {
- if handler, ok := TransactionHandlers[transaction.Type]; ok {
+ if handler, ok := cc.Server.handlers[transaction.Type]; ok {
if transaction.Type != TranKeepAlive {
- cc.logger.Info(tranTypeNames[transaction.Type])
+ cc.Logger.Info(tranTypeNames[transaction.Type])
}
for _, t := range handler(cc, &transaction) {
return cc.Account.Access.IsSet(access)
}
-// Disconnect notifies other clients that a client has disconnected
+// Disconnect notifies other clients that a client has disconnected and closes the connection.
func (cc *ClientConn) Disconnect() {
cc.Server.ClientMgr.Delete(cc.ID)
}
if err := cc.Connection.Close(); err != nil {
- cc.Server.Logger.Error("error closing client connection", "RemoteAddr", cc.RemoteAddr)
+ cc.Server.Logger.Debug("error closing client connection", "RemoteAddr", cc.RemoteAddr)
}
}
func (cc *ClientConn) NotifyOthers(t Transaction) (trans []Transaction) {
for _, c := range cc.Server.ClientMgr.List() {
if c.ID != cc.ID {
- t.clientID = c.ID
+ t.ClientID = c.ID
trans = append(trans, t)
}
}
return Transaction{
IsReply: 1,
ID: t.ID,
- clientID: cc.ID,
+ ClientID: cc.ID,
Fields: fields,
}
}
func (cc *ClientConn) NewErrReply(t *Transaction, errMsg string) []Transaction {
return []Transaction{
{
- clientID: cc.ID,
+ ClientID: cc.ID,
IsReply: 1,
ID: t.ID,
ErrorCode: [4]byte{0, 0, 0, 1},