command.go 1002 B

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