github.com/df-mc/dragonfly@v0.9.13/server/session/handler_command_request.go (about)

     1  package session
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/sandertv/gophertunnel/minecraft/protocol"
     6  	"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
     7  )
     8  
     9  // CommandRequestHandler handles the CommandRequest packet.
    10  type CommandRequestHandler struct {
    11  	origin protocol.CommandOrigin
    12  }
    13  
    14  // Handle ...
    15  func (h *CommandRequestHandler) Handle(p packet.Packet, s *Session) error {
    16  	pk := p.(*packet.CommandRequest)
    17  	if pk.Internal {
    18  		return fmt.Errorf("command request packet must never have the internal field set to true")
    19  	}
    20  
    21  	h.origin = pk.CommandOrigin
    22  	s.c.ExecuteCommand(pk.CommandLine)
    23  	return nil
    24  }