extends NetworkNode @export var host := "localhost" @export var port := 4242 signal download_changed(down: int) signal upload_changed(up: int) var socket := PacketPeerUDP.new() var upload := 0 func _enter_tree(): for child in get_children(): if !(child is PacketHandler): continue set_handler(child.packet_type, child) func _ready(): var ip := IP.resolve_hostname(host) socket.connect_to_host(ip, port) func _process(_delta): while socket.get_available_packet_count() > 0: var packet := socket.get_packet() handle_packet(packet) 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() func log(message: String): print_rich("[color=#808080][%s][/color] %s" % [Global.account.name, message])