Skip to content

Commit

Permalink
Improve log messages
Browse files Browse the repository at this point in the history
Commit 702a98d accidentally put the campaign size on its own line. This commit
prints the complete log message only if the campaign is actually sent out.

No changes in program logic. Just an early return added to reduce indentation.
  • Loading branch information
soliton- committed Mar 18, 2020
1 parent d68c8de commit b520e1c
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/campaign_server/campaign_server.cpp
Expand Up @@ -670,32 +670,29 @@ void server::handle_request_campaign_list(const server::request& req)

void server::handle_request_campaign(const server::request& req)
{
LOG_CS << "sending campaign '" << req.cfg["name"] << "' to " << req.addr << " using gzip\n";

config& campaign = get_campaign(req.cfg["name"]);

if(!campaign || campaign["hidden"].to_bool()) {
send_error("Add-on '" + req.cfg["name"].str() + "' not found.", req.sock);
} else {
const int size = filesystem::file_size(campaign["filename"]);

if(size < 0) {
std::cerr << " size: <unknown> KiB\n";
ERR_CS << "File size unknown, aborting send.\n";
send_error("Add-on '" + req.cfg["name"].str() + "' could not be read by the server.", req.sock);
return;
}
return;
}

const int size = filesystem::file_size(campaign["filename"]);

std::cerr << " size: " << size/1024 << "KiB\n";
async_send_file(req.sock, campaign["filename"],
std::bind(&server::handle_new_client, this, _1), null_handler);
// Clients doing upgrades or some other specific thing shouldn't bump
// the downloads count. Default to true for compatibility with old
// clients that won't tell us what they are trying to do.
if(req.cfg["increase_downloads"].to_bool(true) && !ignore_address_stats(req.addr)) {
const int downloads = campaign["downloads"].to_int() + 1;
campaign["downloads"] = downloads;
}
if(size < 0) {
send_error("Add-on '" + req.cfg["name"].str() + "' could not be read by the server.", req.sock);
return;
}

LOG_CS << "sending campaign '" << req.cfg["name"] << "' to " << req.addr << " size: " << size/1024 << "KiB\n";
async_send_file(req.sock, campaign["filename"], std::bind(&server::handle_new_client, this, _1), null_handler);

// Clients doing upgrades or some other specific thing shouldn't bump
// the downloads count. Default to true for compatibility with old
// clients that won't tell us what they are trying to do.
if(req.cfg["increase_downloads"].to_bool(true) && !ignore_address_stats(req.addr)) {
const int downloads = campaign["downloads"].to_int() + 1;
campaign["downloads"] = downloads;
}
}

Expand Down

0 comments on commit b520e1c

Please sign in to comment.