Writes hunt results from a given client as part of a given hunt.

def WriteHuntResults(client_id, hunt_id, responses):
  """Writes hunt results from a given client as part of a given hunt."""

  if not hunt.IsLegacyHunt(hunt_id):
    data_store.REL_DB.WriteFlowResults(responses)

    hunt.StopHuntIfCPUOrNetworkLimitsExceeded(hunt_id)
    return

  hunt_id_urn = rdfvalue.RDFURN("hunts").Add(hunt_id)

  msgs = []
  for response in responses:
    if isinstance(response, rdf_flow_objects.FlowStatus):
      continue

    msgs.append(
        rdf_flows.GrrMessage(payload=response.payload, source=client_id))

  with data_store.DB.GetMutationPool() as pool:
    for msg in msgs:
      hunts_results.HuntResultCollection.StaticAdd(
          hunt_id_urn.Add("Results"), msg, mutation_pool=pool)

    for msg in msgs:
      multi_type_collection.MultiTypeCollection.StaticAdd(
          hunt_id_urn.Add("ResultsPerType"), msg, mutation_pool=pool)

  stats_collector_instance.Get().IncrementCounter(
      "hunt_results_added", delta=len(responses))