From f6c6a40aba3acbfb663c912c6efe83a3fac631f0 Mon Sep 17 00:00:00 2001 From: sawka Date: Tue, 4 Apr 2023 21:52:20 -0700 Subject: [PATCH] add client:accepttos command --- pkg/cmdrunner/cmdrunner.go | 22 ++++++++++++++++++++++ pkg/cmdrunner/shparse.go | 2 ++ pkg/sstore/dbops.go | 4 ++-- pkg/sstore/sstore.go | 3 ++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/pkg/cmdrunner/cmdrunner.go b/pkg/cmdrunner/cmdrunner.go index a48e3eb9d..e2728cffe 100644 --- a/pkg/cmdrunner/cmdrunner.go +++ b/pkg/cmdrunner/cmdrunner.go @@ -177,6 +177,7 @@ func init() { registerCmdFn("client:show", ClientShowCommand) registerCmdFn("client:set", ClientSetCommand) registerCmdFn("client:notifyupdatewriter", ClientNotifyUpdateWriterCommand) + registerCmdFn("client:accepttos", ClientAcceptTosCommand) registerCmdFn("telemetry", TelemetryCommand) registerCmdFn("telemetry:on", TelemetryOnCommand) @@ -2798,6 +2799,27 @@ func boolToStr(v bool, trueStr string, falseStr string) string { return falseStr } +func ClientAcceptTosCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) { + clientData, err := sstore.EnsureClientData(ctx) + if err != nil { + return nil, fmt.Errorf("cannot retrieve client data: %v", err) + } + clientOpts := clientData.ClientOpts + clientOpts.AcceptedTos = time.Now().UnixMilli() + err = sstore.SetClientOpts(ctx, clientOpts) + if err != nil { + return nil, fmt.Errorf("error updating client data: %v", err) + } + clientData, err = sstore.EnsureClientData(ctx) + if err != nil { + return nil, fmt.Errorf("cannot retrieve updated client data: %v", err) + } + update := sstore.ModelUpdate{ + ClientData: clientData, + } + return update, nil +} + func ClientSetCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) { clientData, err := sstore.EnsureClientData(ctx) if err != nil { diff --git a/pkg/cmdrunner/shparse.go b/pkg/cmdrunner/shparse.go index 70b62d71e..fcd9c293c 100644 --- a/pkg/cmdrunner/shparse.go +++ b/pkg/cmdrunner/shparse.go @@ -77,6 +77,8 @@ func SubMetaCmd(cmd string) string { return "eval" case "export": return "setenv" + case "connection": + return "remote" default: return cmd } diff --git a/pkg/sstore/dbops.go b/pkg/sstore/dbops.go index 3ddd7c94a..8397b9a39 100644 --- a/pkg/sstore/dbops.go +++ b/pkg/sstore/dbops.go @@ -2499,10 +2499,10 @@ func insertScreenUpdate(tx *TxWrap, screenId string, updateType string) { func insertScreenNewUpdate(tx *TxWrap, screenId string) { nowTs := time.Now().UnixMilli() query := `INSERT INTO screenupdate (screenid, lineid, updatetype, updatets) - SELECT screenid, lineid, ?, ? FROM line WHERE screenid = ? AND NOT archived ORDER BY linenum` + SELECT screenid, lineid, ?, ? FROM line WHERE screenid = ? AND NOT archived ORDER BY linenum DESC` tx.Exec(query, UpdateType_LineNew, nowTs, screenId) query = `INSERT INTO screenupdate (screenid, lineid, updatetype, updatets) - SELECT c.screenid, l.lineid, ?, ? FROM cmd c, line l WHERE c.screenid = ? AND l.cmdid = c.cmdid AND NOT l.archived` + SELECT c.screenid, l.lineid, ?, ? FROM cmd c, line l WHERE c.screenid = ? AND l.cmdid = c.cmdid AND NOT l.archived ORDER BY l.linenum DESC` tx.Exec(query, UpdateType_PtyPos, nowTs, screenId) NotifyUpdateWriter() } diff --git a/pkg/sstore/sstore.go b/pkg/sstore/sstore.go index 6715ce39b..6b706c148 100644 --- a/pkg/sstore/sstore.go +++ b/pkg/sstore/sstore.go @@ -212,7 +212,8 @@ func (tdata *TelemetryData) Scan(val interface{}) error { } type ClientOptsType struct { - NoTelemetry bool `json:"notelemetry,omitempty"` + NoTelemetry bool `json:"notelemetry,omitempty"` + AcceptedTos int64 `json:"acceptedtos,omitempty"` } type FeOptsType struct {