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