command.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //go:build !confonly
  2. // +build !confonly
  3. package outbound
  4. import (
  5. "time"
  6. "github.com/v2fly/v2ray-core/v4/common"
  7. "github.com/v2fly/v2ray-core/v4/common/net"
  8. "github.com/v2fly/v2ray-core/v4/common/protocol"
  9. "github.com/v2fly/v2ray-core/v4/proxy/vmess"
  10. )
  11. func (h *Handler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
  12. rawAccount := &vmess.Account{
  13. Id: cmd.ID.String(),
  14. AlterId: uint32(cmd.AlterIds),
  15. SecuritySettings: &protocol.SecurityConfig{
  16. Type: protocol.SecurityType_LEGACY,
  17. },
  18. }
  19. account, err := rawAccount.AsAccount()
  20. common.Must(err)
  21. user := &protocol.MemoryUser{
  22. Email: "",
  23. Level: cmd.Level,
  24. Account: account,
  25. }
  26. dest := net.TCPDestination(cmd.Host, cmd.Port)
  27. until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
  28. h.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user))
  29. }
  30. func (h *Handler) handleCommand(dest net.Destination, cmd protocol.ResponseCommand) {
  31. switch typedCommand := cmd.(type) {
  32. case *protocol.CommandSwitchAccount:
  33. if typedCommand.Host == nil {
  34. typedCommand.Host = dest.Address
  35. }
  36. h.handleSwitchAccount(typedCommand)
  37. default:
  38. }
  39. }