command.go 1.1 KB

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