diff --git a/src/websocketd.cr b/src/websocketd.cr index d76e209..97b202d 100644 --- a/src/websocketd.cr +++ b/src/websocketd.cr @@ -166,9 +166,22 @@ def websocket_client_connection(client, context : InstanceStorage) context.is_json[client.fd] = false end - websocket_connection_procedure req_service, client.fd, context + # TODO: if trackerd, send the IP address of the client + if req_service == "tracker" + puts "tracker - sending the IP address" + puts "connection from #{client.remote_address}" + sfd = context.switchtable[client.fd] + # message = IPC::Message.from_json(JSON).to_packet + # => JSON has to include these attributes: mtype, utype, payload + # message = IPC::Message.new mtype, utype, payload + remote_address = client.remote_address.address + message = IPC::Message.new 1, 1.to_u8, "{\"ip-address\": \"#{remote_address}\"}" + serv = WrappedTCPFileDescriptor.new(fd: sfd, family: Socket::Family::INET) + serv.send message.to_packet + end + # puts "#{headers_header}\n#{headers.to_s}\r\n" client.send "#{headers_header}\n#{headers.to_s}\r\n"