command.go 1.0 KB

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