2024-01-20 21:18:58 +00:00
|
|
|
extends NetworkNode
|
|
|
|
|
2024-01-26 21:02:25 +00:00
|
|
|
@export var host := "127.0.0.1"
|
|
|
|
@export var port := 4242
|
2024-01-20 21:18:58 +00:00
|
|
|
|
2024-01-26 18:00:59 +00:00
|
|
|
signal download_changed(down: int)
|
|
|
|
signal upload_changed(up: int)
|
|
|
|
|
2024-01-20 21:18:58 +00:00
|
|
|
var socket := PacketPeerUDP.new()
|
2024-01-26 18:00:59 +00:00
|
|
|
var upload := 0
|
2024-01-20 21:18:58 +00:00
|
|
|
|
2024-01-25 11:10:29 +00:00
|
|
|
func _enter_tree():
|
|
|
|
socket.connect_to_host(host, port)
|
|
|
|
|
|
|
|
for child in get_children():
|
|
|
|
if !(child is PacketHandler):
|
|
|
|
continue
|
|
|
|
|
|
|
|
set_handler(child.packet_type, child)
|
2024-01-20 21:18:58 +00:00
|
|
|
|
|
|
|
func _process(_delta):
|
|
|
|
while socket.get_available_packet_count() > 0:
|
|
|
|
var packet := socket.get_packet()
|
2024-01-26 18:00:59 +00:00
|
|
|
handle_packet(packet, socket)
|
|
|
|
|
|
|
|
func update_statistics():
|
|
|
|
download_changed.emit(download)
|
|
|
|
upload_changed.emit(upload)
|
|
|
|
download = 0
|
|
|
|
upload = 0
|
|
|
|
|
|
|
|
func send(data: PackedByteArray):
|
|
|
|
socket.put_packet(data)
|
|
|
|
upload += data.size()
|