2024-01-28 21:08:08 +00:00
|
|
|
extends PacketHandler
|
|
|
|
|
2024-02-28 20:44:24 +00:00
|
|
|
signal message_received(player: Player, message: String)
|
2024-01-28 21:08:08 +00:00
|
|
|
|
|
|
|
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)
|
2024-02-28 20:44:24 +00:00
|
|
|
|
|
|
|
if !player:
|
|
|
|
return
|
|
|
|
|
2024-01-28 21:08:08 +00:00
|
|
|
var message := buffer.get_utf8_string()
|
2024-02-28 12:23:17 +00:00
|
|
|
message = escape_bbcode(message)
|
2024-01-28 21:08:08 +00:00
|
|
|
|
2024-02-27 22:21:44 +00:00
|
|
|
Log.info("%s: %s" % [player.name, message])
|
2024-02-28 20:44:24 +00:00
|
|
|
emit.call_deferred(player, message)
|
2024-02-28 12:23:17 +00:00
|
|
|
|
2024-02-28 20:44:24 +00:00
|
|
|
func emit(player: Player, message: String):
|
|
|
|
message_received.emit(player, message)
|
2024-02-25 18:47:13 +00:00
|
|
|
|
|
|
|
func escape_bbcode(text: String) -> String:
|
|
|
|
return text.replace("[", "[lb]")
|
2024-01-28 21:08:08 +00:00
|
|
|
|