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

     1  package session
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
     6  )
     7  
     8  // TextHandler handles the Text packet.
     9  type TextHandler struct{}
    10  
    11  // Handle ...
    12  func (TextHandler) Handle(p packet.Packet, s *Session) error {
    13  	pk := p.(*packet.Text)
    14  
    15  	if pk.TextType != packet.TextTypeChat {
    16  		return fmt.Errorf("TextType should always be Chat (%v), but got %v", packet.TextTypeChat, pk.TextType)
    17  	}
    18  	if pk.SourceName != s.conn.IdentityData().DisplayName {
    19  		return fmt.Errorf("SourceName must be equal to DisplayName")
    20  	}
    21  	if pk.XUID != s.conn.IdentityData().XUID {
    22  		return fmt.Errorf("XUID must be equal to player's XUID")
    23  	}
    24  	s.c.Chat(pk.Message)
    25  	return nil
    26  }