github.com/xmplusdev/xray-core@v1.8.10/proxy/vmess/outbound/command.go (about)

     1  package outbound
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/xmplusdev/xray-core/common"
     7  	"github.com/xmplusdev/xray-core/common/net"
     8  	"github.com/xmplusdev/xray-core/common/protocol"
     9  	"github.com/xmplusdev/xray-core/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  }