Skip to content

Commit a876078

Browse files
committed
feat(server): Rustdesk Id Server Port & Relay Server Port lejianwen#104
1 parent 495f2ae commit a876078

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

config/rustdesk.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ const (
1212
)
1313

1414
type Rustdesk struct {
15-
IdServer string `mapstructure:"id-server"`
16-
IdServerPort int `mapstructure:"-"`
17-
RelayServer string `mapstructure:"relay-server"`
18-
RelayPort int `mapstructure:"-"`
19-
ApiServer string `mapstructure:"api-server"`
20-
Key string `mapstructure:"key"`
21-
KeyFile string `mapstructure:"key-file"`
22-
Personal int `mapstructure:"personal"`
15+
IdServer string `mapstructure:"id-server"`
16+
IdServerPort int `mapstructure:"-"`
17+
RelayServer string `mapstructure:"relay-server"`
18+
RelayServerPort int `mapstructure:"-"`
19+
ApiServer string `mapstructure:"api-server"`
20+
Key string `mapstructure:"key"`
21+
KeyFile string `mapstructure:"key-file"`
22+
Personal int `mapstructure:"personal"`
2323
//webclient-magic-queryonline
2424
WebclientMagicQueryonline int `mapstructure:"webclient-magic-queryonline"`
2525
}
@@ -50,8 +50,8 @@ func (rd *Rustdesk) ParsePort() {
5050

5151
relayres := strings.Split(rd.RelayServer, ":")
5252
if len(relayres) == 1 {
53-
rd.RelayPort = DefaultRelayServerPort
53+
rd.RelayServerPort = DefaultRelayServerPort
5454
} else if len(relayres) == 2 {
55-
rd.RelayPort, _ = strconv.Atoi(relayres[1])
55+
rd.RelayServerPort, _ = strconv.Atoi(relayres[1])
5656
}
5757
}

service/serverCmd.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ func (is *ServerCmdService) Create(u *model.ServerCmd) error {
4141
}
4242

4343
// SendCmd 发送命令
44-
func (is *ServerCmdService) SendCmd(port string, cmd string, arg string) (string, error) {
44+
func (is *ServerCmdService) SendCmd(target string, cmd string, arg string) (string, error) {
45+
port := 0
46+
switch target {
47+
case model.ServerCmdTargetIdServer:
48+
port = global.Config.Rustdesk.IdServerPort - 1
49+
case model.ServerCmdTargetRelayServer:
50+
port = global.Config.Rustdesk.RelayServerPort
51+
}
4552
//组装命令
4653
cmd = cmd + " " + arg
4754
res, err := is.SendSocketCmd("v6", port, cmd)
@@ -57,14 +64,14 @@ func (is *ServerCmdService) SendCmd(port string, cmd string, arg string) (string
5764
}
5865

5966
// SendSocketCmd
60-
func (is *ServerCmdService) SendSocketCmd(ty string, port string, cmd string) (string, error) {
67+
func (is *ServerCmdService) SendSocketCmd(ty string, port int, cmd string) (string, error) {
6168
addr := "[::1]"
6269
tcp := "tcp6"
6370
if ty == "v4" {
6471
tcp = "tcp"
6572
addr = "127.0.0.1"
6673
}
67-
conn, err := net.Dial(tcp, fmt.Sprintf("%s:%s", addr, port))
74+
conn, err := net.Dial(tcp, fmt.Sprintf("%s:%v", addr, port))
6875
if err != nil {
6976
global.Logger.Debugf("%s connect to id server failed: %v", ty, err)
7077
return "", err

0 commit comments

Comments
 (0)