Don't re-send all reports all the time.

develop
Japa 2017-12-20 17:11:01 +05:30
parent c4f9f6edb2
commit 04b1a80654
1 changed files with 2326 additions and 2312 deletions

@ -2860,9 +2860,22 @@ static command_result GetVersionInfo(color_ostream & stream, const EmptyMessage
return CR_OK; return CR_OK;
} }
int lastSentReportID = -1;
static command_result GetReports(color_ostream & stream, const EmptyMessage * in, RemoteFortressReader::Status * out) static command_result GetReports(color_ostream & stream, const EmptyMessage * in, RemoteFortressReader::Status * out)
{ {
for (int i = 0; i < world->status.reports.size(); i++) //First find the last report we sent, so it doesn't get resent.
int lastSentIndex = -1;
for (int i = world->status.reports.size() - 1; i >= 0; i--)
{
auto local_rep = world->status.reports[i];
if (local_rep->id <= lastSentReportID)
{
lastSentIndex = i;
break;
}
}
for (int i = lastSentIndex + 1; i < world->status.reports.size(); i++)
{ {
auto local_rep = world->status.reports[i]; auto local_rep = world->status.reports[i];
if (!local_rep) if (!local_rep)
@ -2880,6 +2893,7 @@ static command_result GetReports(color_ostream & stream, const EmptyMessage * in
send_rep->set_id(local_rep->id); send_rep->set_id(local_rep->id);
send_rep->set_year(local_rep->year); send_rep->set_year(local_rep->year);
send_rep->set_time(local_rep->time); send_rep->set_time(local_rep->time);
lastSentReportID = local_rep->id;
} }
return CR_OK; return CR_OK;
} }