2020-11-25 14:01:53 +03:00
|
|
|
package outbound
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2020-12-04 04:36:16 +03:00
|
|
|
"github.com/xtls/xray-core/common"
|
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
|
|
"github.com/xtls/xray-core/common/protocol"
|
|
|
|
"github.com/xtls/xray-core/proxy/vmess"
|
2020-11-25 14:01:53 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func (h *Handler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
|
|
|
|
rawAccount := &vmess.Account{
|
|
|
|
Id: cmd.ID.String(),
|
|
|
|
SecuritySettings: &protocol.SecurityConfig{
|
2023-06-12 17:32:25 +03:00
|
|
|
Type: protocol.SecurityType_AUTO,
|
2020-11-25 14:01:53 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
|
|
|
}
|
|
|
|
}
|