command.go 1017 B

12345678910111213141516171819202122232425262728293031323334
  1. package outbound
  2. import (
  3. "time"
  4. v2net "github.com/v2ray/v2ray-core/common/net"
  5. "github.com/v2ray/v2ray-core/common/protocol"
  6. "github.com/v2ray/v2ray-core/proxy/vmess"
  7. )
  8. func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
  9. primary := protocol.NewID(cmd.ID)
  10. alters := protocol.NewAlterIDs(primary, cmd.AlterIds)
  11. account := &vmess.Account{
  12. ID: primary,
  13. AlterIDs: alters,
  14. }
  15. user := protocol.NewUser(cmd.Level, "")
  16. user.Account = account
  17. dest := v2net.TCPDestination(cmd.Host, cmd.Port)
  18. until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
  19. this.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user))
  20. }
  21. func (this *VMessOutboundHandler) handleCommand(dest v2net.Destination, cmd protocol.ResponseCommand) {
  22. switch typedCommand := cmd.(type) {
  23. case *protocol.CommandSwitchAccount:
  24. if typedCommand.Host == nil {
  25. typedCommand.Host = dest.Address()
  26. }
  27. this.handleSwitchAccount(typedCommand)
  28. default:
  29. }
  30. }