21 lines
648 B
GDScript3
21 lines
648 B
GDScript3
|
extends PacketHandler
|
||
|
|
||
|
signal message_received(message: String)
|
||
|
|
||
|
func send_message(message: String):
|
||
|
var buffer := StreamPeerBuffer.new()
|
||
|
buffer.put_8(Packet.CHAT)
|
||
|
buffer.put_data(message.to_utf8_buffer())
|
||
|
%Client.send(buffer.data_array)
|
||
|
|
||
|
func handle_packet(data: PackedByteArray, _peer: PacketPeer):
|
||
|
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()
|
||
|
|
||
|
print("[%s] %s: %s" % [Global.username, player.name, message])
|
||
|
message_received.emit("[color=#808080]%s:[/color] %s" % [player.name, message])
|
||
|
|