command.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package inbound
  2. import (
  3. "v2ray.com/core/common/log"
  4. "v2ray.com/core/common/protocol"
  5. "v2ray.com/core/proxy/vmess"
  6. )
  7. func (this *VMessInboundHandler) generateCommand(request *protocol.RequestHeader) protocol.ResponseCommand {
  8. if this.detours != nil {
  9. tag := this.detours.To
  10. if this.inboundHandlerManager != nil {
  11. handler, availableMin := this.inboundHandlerManager.GetHandler(tag)
  12. inboundHandler, ok := handler.(*VMessInboundHandler)
  13. if ok {
  14. if availableMin > 255 {
  15. availableMin = 255
  16. }
  17. log.Info("VMessIn: Pick detour handler for port ", inboundHandler.Port(), " for ", availableMin, " minutes.")
  18. user := inboundHandler.GetUser(request.User.Email)
  19. if user == nil {
  20. return nil
  21. }
  22. account, _ := user.GetTypedAccount()
  23. return &protocol.CommandSwitchAccount{
  24. Port: inboundHandler.Port(),
  25. ID: account.(*vmess.InternalAccount).ID.UUID(),
  26. AlterIds: uint16(len(account.(*vmess.InternalAccount).AlterIDs)),
  27. Level: user.Level,
  28. ValidMin: byte(availableMin),
  29. }
  30. }
  31. }
  32. }
  33. return nil
  34. }