39 lines
1.0 KiB
Go
Raw Normal View History

package outbound
import (
2016-07-25 16:48:09 +02:00
"time"
2016-08-20 20:55:45 +02:00
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/proxy/vmess"
2016-09-18 00:41:21 +02:00
"github.com/golang/protobuf/ptypes"
)
2016-02-27 16:41:21 +01:00
func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
2016-09-18 00:41:21 +02:00
account := &vmess.AccountPB{
Id: cmd.ID.String(),
AlterId: uint32(cmd.AlterIds),
}
anyAccount, _ := ptypes.MarshalAny(account)
user := &protocol.User{
Email: "",
Level: cmd.Level,
Account: anyAccount,
2016-05-28 13:44:11 +02:00
}
dest := v2net.TCPDestination(cmd.Host, cmd.Port)
2016-07-25 16:48:09 +02:00
until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
2016-09-18 00:41:21 +02:00
this.serverList.AddServer(protocol.NewServerSpec(vmess.NewAccount, dest, protocol.BeforeTime(until), user))
}
2016-02-27 16:41:21 +01:00
func (this *VMessOutboundHandler) handleCommand(dest v2net.Destination, cmd protocol.ResponseCommand) {
switch typedCommand := cmd.(type) {
2016-02-27 16:41:21 +01:00
case *protocol.CommandSwitchAccount:
2016-01-21 16:22:56 +00:00
if typedCommand.Host == nil {
typedCommand.Host = dest.Address()
}
this.handleSwitchAccount(typedCommand)
default:
}
}