v2fly/proxy/vmess/outbound/command.go

43 lines
1.1 KiB
Go
Raw Normal View History

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