github.com/v2fly/v2ray-core/v4@v4.45.2/proxy/vmess/outbound/command.go (about)

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