command.go 1.0 KB

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