command.go 1.1 KB

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