command.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package inbound
  2. import (
  3. "github.com/v2ray/v2ray-core/common/alloc"
  4. "github.com/v2ray/v2ray-core/common/serial"
  5. "github.com/v2ray/v2ray-core/proxy/vmess/command"
  6. )
  7. func (this *VMessInboundHandler) generateCommand(buffer *alloc.Buffer) {
  8. cmd := byte(0)
  9. commandBytes := alloc.NewSmallBuffer().Clear()
  10. defer commandBytes.Release()
  11. if this.features != nil && this.features.Detour != nil {
  12. tag := this.features.Detour.ToTag
  13. if this.space.HasInboundHandlerManager() {
  14. handlerManager := this.space.InboundHandlerManager()
  15. handler, availableSec := handlerManager.GetHandler(tag)
  16. inboundHandler, ok := handler.(*VMessInboundHandler)
  17. if ok {
  18. user := inboundHandler.GetUser()
  19. availableMin := availableSec / 60
  20. if availableMin > 255 {
  21. availableMin = 255
  22. }
  23. saCmd := &command.SwitchAccount{
  24. Port: inboundHandler.Port(),
  25. ID: user.ID.UUID(),
  26. AlterIds: serial.Uint16Literal(len(user.AlterIDs)),
  27. Level: user.Level,
  28. ValidMin: byte(availableMin),
  29. }
  30. saCmd.Marshal(commandBytes)
  31. }
  32. }
  33. }
  34. if commandBytes.Len() > 256 {
  35. buffer.AppendBytes(byte(0), byte(0))
  36. } else {
  37. buffer.AppendBytes(cmd, byte(commandBytes.Len()))
  38. buffer.Append(commandBytes.Value)
  39. }
  40. }