21 lines
634 B
GDScript3
Raw Normal View History

2024-01-28 21:08:08 +00:00
extends PacketHandler
signal message_received(message: String)
func send_message(message: String):
var buffer := StreamPeerBuffer.new()
2024-02-16 14:51:23 +00:00
buffer.put_u8(Packet.CHAT)
2024-01-28 21:08:08 +00:00
buffer.put_data(message.to_utf8_buffer())
%Client.send(buffer.data_array)
2024-01-29 22:16:06 +00:00
func handle_packet(data: PackedByteArray):
2024-01-28 21:08:08 +00:00
var buffer := StreamPeerBuffer.new()
buffer.data_array = data
var player_id := buffer.get_string()
var player := Global.players.get_player(player_id)
var message := buffer.get_utf8_string()
2024-02-16 19:04:50 +00:00
print("[%s] %s: %s" % [Global.account.name, player.name, message])
2024-01-28 21:08:08 +00:00
message_received.emit("[color=#808080]%s:[/color] %s" % [player.name, message])