waveterm/pkg/scpacket/scpacket.go

88 lines
2.6 KiB
Go
Raw Normal View History

2022-07-01 21:17:19 +02:00
package scpacket
import (
"reflect"
2022-08-24 22:21:54 +02:00
"github.com/scripthaus-dev/mshell/pkg/base"
2022-07-01 21:17:19 +02:00
"github.com/scripthaus-dev/mshell/pkg/packet"
2022-08-24 22:21:54 +02:00
"github.com/scripthaus-dev/sh2-server/pkg/sstore"
2022-07-01 21:17:19 +02:00
)
const FeCommandPacketStr = "fecmd"
const WatchScreenPacketStr = "watchscreen"
2022-08-24 22:21:54 +02:00
const FeInputPacketStr = "feinput"
2022-07-01 21:17:19 +02:00
type FeCommandPacketType struct {
Type string `json:"type"`
MetaCmd string `json:"metacmd"`
MetaSubCmd string `json:"metasubcmd,omitempty"`
Args []string `json:"args,omitempty"`
Kwargs map[string]string `json:"kwargs,omitempty"`
UIContext *UIContextType `json:"uicontext,omitempty"`
}
type UIContextType struct {
SessionId string `json:"sessionid"`
ScreenId string `json:"screenid"`
WindowId string `json:"windowid"`
Remote *sstore.RemotePtrType `json:"remote,omitempty"`
2022-09-04 08:36:15 +02:00
TermOpts *packet.TermOpts `json:"termopts,omitempty"`
2022-07-01 21:17:19 +02:00
}
2022-08-24 22:21:54 +02:00
type FeInputPacketType struct {
Type string `json:"type"`
CK base.CommandKey `json:"ck"`
Remote sstore.RemotePtrType `json:"remote"`
InputData64 string `json:"inputdata"`
SigNum int `json:"signum,omitempty"`
WinSizeRows int `json:"winsizerows"`
WinSizeCols int `json:"winsizecols"`
}
2022-07-01 21:17:19 +02:00
func init() {
packet.RegisterPacketType(FeCommandPacketStr, reflect.TypeOf(FeCommandPacketType{}))
packet.RegisterPacketType(WatchScreenPacketStr, reflect.TypeOf(WatchScreenPacketType{}))
2022-08-24 22:21:54 +02:00
packet.RegisterPacketType(FeInputPacketStr, reflect.TypeOf(FeInputPacketType{}))
2022-07-01 21:17:19 +02:00
}
func (*FeCommandPacketType) GetType() string {
return FeCommandPacketStr
}
func MakeFeCommandPacket() *FeCommandPacketType {
return &FeCommandPacketType{Type: FeCommandPacketStr}
}
2022-08-24 22:21:54 +02:00
func (*FeInputPacketType) GetType() string {
return FeInputPacketStr
}
func MakeFeInputPacket() *FeInputPacketType {
return &FeInputPacketType{Type: FeInputPacketStr}
}
func (p *FeInputPacketType) ConvertToInputPacket() *packet.InputPacketType {
rtn := packet.MakeInputPacket()
rtn.CK = p.CK
rtn.RemoteId = p.Remote.RemoteId
rtn.InputData64 = p.InputData64
rtn.SigNum = p.SigNum
rtn.WinSizeRows = p.WinSizeRows
rtn.WinSizeCols = p.WinSizeCols
return rtn
}
type WatchScreenPacketType struct {
Type string `json:"type"`
SessionId string `json:"sessionid"`
ScreenId string `json:"screenid"`
}
func (*WatchScreenPacketType) GetType() string {
return WatchScreenPacketStr
}
func MakeWatchScreenPacket() *WatchScreenPacketType {
return &WatchScreenPacketType{Type: WatchScreenPacketStr}
}