command.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. cmd = byte(1)
  13. tag := this.features.Detour.ToTag
  14. if this.space.HasInboundHandlerManager() {
  15. handlerManager := this.space.InboundHandlerManager()
  16. handler, availableSec := handlerManager.GetHandler(tag)
  17. inboundHandler, ok := handler.(*VMessInboundHandler)
  18. if ok {
  19. user := inboundHandler.GetUser()
  20. availableMin := availableSec / 60
  21. if availableMin > 255 {
  22. availableMin = 255
  23. }
  24. saCmd := &command.SwitchAccount{
  25. Port: inboundHandler.Port(),
  26. ID: user.ID.UUID(),
  27. AlterIds: serial.Uint16Literal(len(user.AlterIDs)),
  28. Level: user.Level,
  29. ValidMin: byte(availableMin),
  30. }
  31. saCmd.Marshal(commandBytes)
  32. }
  33. }
  34. }
  35. if commandBytes.Len() > 256 {
  36. buffer.AppendBytes(byte(0), byte(0))
  37. } else {
  38. buffer.AppendBytes(cmd, byte(commandBytes.Len()))
  39. buffer.Append(commandBytes.Value)
  40. }
  41. }