command.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. SecuritySettings: &protocol.SecurityConfig{
  13. Type: protocol.SecurityType_AUTO,
  14. },
  15. }
  16. account, err := rawAccount.AsAccount()
  17. common.Must(err)
  18. user := &protocol.MemoryUser{
  19. Email: "",
  20. Level: cmd.Level,
  21. Account: account,
  22. }
  23. dest := net.TCPDestination(cmd.Host, cmd.Port)
  24. until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
  25. h.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user))
  26. }
  27. func (h *Handler) handleCommand(dest net.Destination, cmd protocol.ResponseCommand) {
  28. switch typedCommand := cmd.(type) {
  29. case *protocol.CommandSwitchAccount:
  30. if typedCommand.Host == nil {
  31. typedCommand.Host = dest.Address
  32. }
  33. h.handleSwitchAccount(typedCommand)
  34. default:
  35. }
  36. }