1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 18:06:15 -05:00
v2fly/proxy/vmess/outbound/command.go

45 lines
1.1 KiB
Go
Raw Normal View History

2019-02-01 14:08:21 -05:00
// +build !confonly
package outbound
import (
2016-07-25 10:48:09 -04:00
"time"
2021-02-16 15:31:50 -05:00
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/net"
"github.com/v2fly/v2ray-core/v4/common/protocol"
"github.com/v2fly/v2ray-core/v4/proxy/vmess"
)
2017-09-19 17:27:49 -04:00
func (h *Handler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
2018-08-26 18:11:32 -04:00
rawAccount := &vmess.Account{
2016-09-17 18:41:21 -04:00
Id: cmd.ID.String(),
AlterId: uint32(cmd.AlterIds),
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_LEGACY,
},
2016-09-17 18:41:21 -04:00
}
2016-10-16 08:22:21 -04:00
2018-08-26 18:11:32 -04:00
account, err := rawAccount.AsAccount()
common.Must(err)
user := &protocol.MemoryUser{
2016-09-17 18:41:21 -04:00
Email: "",
Level: cmd.Level,
2018-08-26 18:11:32 -04:00
Account: account,
2016-05-28 07:44:11 -04:00
}
2017-01-13 17:42:39 -05:00
dest := net.TCPDestination(cmd.Host, cmd.Port)
2016-07-25 10:48:09 -04:00
until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
2017-09-19 17:27:49 -04:00
h.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user))
}
2017-09-19 17:27:49 -04:00
func (h *Handler) handleCommand(dest net.Destination, cmd protocol.ResponseCommand) {
switch typedCommand := cmd.(type) {
2016-02-27 10:41:21 -05:00
case *protocol.CommandSwitchAccount:
2016-01-21 11:22:56 -05:00
if typedCommand.Host == nil {
2016-09-20 05:53:05 -04:00
typedCommand.Host = dest.Address
2016-01-21 11:22:56 -05:00
}
2017-09-19 17:27:49 -04:00
h.handleSwitchAccount(typedCommand)
default:
}
}