2015-12-04 11:42:56 +00:00
|
|
|
package outbound
|
|
|
|
|
2016-01-20 16:31:43 +00:00
|
|
|
import (
|
2016-07-25 14:48:09 +00:00
|
|
|
"time"
|
|
|
|
|
2017-01-13 22:42:39 +00:00
|
|
|
"v2ray.com/core/common/net"
|
2016-08-20 18:55:45 +00:00
|
|
|
"v2ray.com/core/common/protocol"
|
2016-12-15 10:51:09 +00:00
|
|
|
"v2ray.com/core/common/serial"
|
2016-08-20 18:55:45 +00:00
|
|
|
"v2ray.com/core/proxy/vmess"
|
2016-01-20 16:31:43 +00:00
|
|
|
)
|
|
|
|
|
2017-09-19 21:27:49 +00:00
|
|
|
func (h *Handler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
|
2016-10-12 16:43:55 +00:00
|
|
|
account := &vmess.Account{
|
2016-09-17 22:41:21 +00:00
|
|
|
Id: cmd.ID.String(),
|
|
|
|
AlterId: uint32(cmd.AlterIds),
|
2017-02-11 06:29:29 +00:00
|
|
|
SecuritySettings: &protocol.SecurityConfig{
|
|
|
|
Type: protocol.SecurityType_LEGACY,
|
|
|
|
},
|
2016-09-17 22:41:21 +00:00
|
|
|
}
|
2016-10-16 12:22:21 +00:00
|
|
|
|
2016-09-17 22:41:21 +00:00
|
|
|
user := &protocol.User{
|
|
|
|
Email: "",
|
|
|
|
Level: cmd.Level,
|
2016-12-15 10:51:09 +00:00
|
|
|
Account: serial.ToTypedMessage(account),
|
2016-05-28 11:44:11 +00:00
|
|
|
}
|
2017-01-13 22:42:39 +00:00
|
|
|
dest := net.TCPDestination(cmd.Host, cmd.Port)
|
2016-07-25 14:48:09 +00:00
|
|
|
until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
|
2017-09-19 21:27:49 +00:00
|
|
|
h.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user))
|
2016-01-20 16:31:43 +00:00
|
|
|
}
|
|
|
|
|
2017-09-19 21:27:49 +00:00
|
|
|
func (h *Handler) handleCommand(dest net.Destination, cmd protocol.ResponseCommand) {
|
2016-01-20 16:31:43 +00:00
|
|
|
switch typedCommand := cmd.(type) {
|
2016-02-27 15:41:21 +00:00
|
|
|
case *protocol.CommandSwitchAccount:
|
2016-01-21 16:22:56 +00:00
|
|
|
if typedCommand.Host == nil {
|
2016-09-20 09:53:05 +00:00
|
|
|
typedCommand.Host = dest.Address
|
2016-01-21 16:22:56 +00:00
|
|
|
}
|
2017-09-19 21:27:49 +00:00
|
|
|
h.handleSwitchAccount(typedCommand)
|
2016-01-20 16:31:43 +00:00
|
|
|
default:
|
|
|
|
}
|
2015-12-04 11:42:56 +00:00
|
|
|
}
|