Accept currently waiting clients and return them as an array

If add_to_clients, the default, the new clients are added to clients. Otherwise, the return value of accept_clients may be added to clients explicitly by the caller after an extra verification or sorting.

Property definitions

gamnit $ Server :: accept_clients
	# Accept currently waiting clients and return them as an array
	#
	# If `add_to_clients`, the default, the new clients are added to `clients`.
	# Otherwise, the return value of `accept_clients` may be added to `clients`
	# explicitly by the caller after an extra verification or sorting.
	fun accept_clients(add_to_clients: nullable Bool): Array[RemoteClient]
	do
		add_to_clients = add_to_clients or else true
		assert not listening_socket.closed

		var new_clients = new Array[RemoteClient]
		loop
			var client_socket = listening_socket.accept
			if client_socket == null then break

			var rc = new RemoteClient(client_socket)

			var handshake_success = rc.handshake
			if handshake_success then
				new_clients.add rc
				print "Server: Client at {client_socket.address} passed the handshake"
			else
				print_error "Server Error: Client at {client_socket.address} failed the handshake"
				client_socket.close
			end
		end

		if add_to_clients then clients.add_all new_clients

		return new_clients
	end
lib/gamnit/network/server.nit:69,2--99,4