// DisplayMessage responds with a disconnect message to the player // when they attempt to connect to the server. func DisplayMessage(s protocol.Stream, message string) error { responsePacket := protocol.NewPacketWithID(0x00) chatMessage := message data, err := json.Marshal(chatMessage) if err != nil { return err } responsePacket.WriteString(string(data)) err = s.WritePacket(responsePacket) return err }
// HandlePingPacket handles a ping packet used by the Minecraft client // used to measure the round trip time of the connection. func HandlePingPacket(s protocol.Stream, status Status) error { if !status.ShowConnection { s.ReadInt64() return nil } time, err := s.ReadInt64() if err != nil { return err } responsePacket := protocol.NewPacketWithID(0x01) responsePacket.WriteInt64(time) err = s.WritePacket(responsePacket) return err }
// WriteHandshakeResponse writes a response with a status that will be // displayed on the requesting player's server list menu. func WriteHandshakeResponse(s protocol.Stream, status Status) error { statusResponse := statusResponse{ Version: version{ Name: "1lann/beacon " + getReleaseName(status.ProtocolNumber), Protocol: status.ProtocolNumber, }, Players: players{ Max: status.MaxPlayers, Online: status.OnlinePlayers, }, Description: status.Message, } data, err := json.Marshal(statusResponse) if err != nil { return err } responsePacket := protocol.NewPacketWithID(0x00) responsePacket.WriteString(string(data)) err = s.WritePacket(responsePacket) return err }