github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/proxy/vmess/outbound/command.go (about) 1 package outbound 2 3 import ( 4 "time" 5 6 "github.com/v2fly/v2ray-core/v5/common" 7 "github.com/v2fly/v2ray-core/v5/common/net" 8 "github.com/v2fly/v2ray-core/v5/common/protocol" 9 "github.com/v2fly/v2ray-core/v5/proxy/vmess" 10 ) 11 12 func (h *Handler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) { 13 rawAccount := &vmess.Account{ 14 Id: cmd.ID.String(), 15 AlterId: uint32(cmd.AlterIds), 16 SecuritySettings: &protocol.SecurityConfig{ 17 Type: protocol.SecurityType_LEGACY, 18 }, 19 } 20 21 account, err := rawAccount.AsAccount() 22 common.Must(err) 23 user := &protocol.MemoryUser{ 24 Email: "", 25 Level: cmd.Level, 26 Account: account, 27 } 28 dest := net.TCPDestination(cmd.Host, cmd.Port) 29 until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute) 30 h.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user)) 31 } 32 33 func (h *Handler) handleCommand(dest net.Destination, cmd protocol.ResponseCommand) { 34 switch typedCommand := cmd.(type) { 35 case *protocol.CommandSwitchAccount: 36 if typedCommand.Host == nil { 37 typedCommand.Host = dest.Address 38 } 39 h.handleSwitchAccount(typedCommand) 40 default: 41 } 42 }