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