made campaign server detect if client can receive gzipped data
This commit is contained in:
parent
85a7d66cb2
commit
2a9e737c4a
7 changed files with 30 additions and 20 deletions
|
@ -11,6 +11,7 @@ Version 1.4.2+svn:
|
|||
* fix [teleport] capturing villages with the wrong side (bug #11683)
|
||||
* campaignd
|
||||
* made campaign server use gzip compression for networking
|
||||
* made campaign server detect if client can receive gzipped data
|
||||
* miscellaneous and bug fixes:
|
||||
* fixed parser bug that prevented loading binary data strings
|
||||
* starting a campaing without any installed now gives an error.
|
||||
|
|
|
@ -238,6 +238,7 @@ namespace {
|
|||
|
||||
void campaign_server::run()
|
||||
{
|
||||
bool gzipped;
|
||||
for(int increment = 0; ; ++increment) {
|
||||
try {
|
||||
//write config to disk every ten minutes
|
||||
|
@ -254,7 +255,7 @@ namespace {
|
|||
}
|
||||
|
||||
config data;
|
||||
while((sock = network::receive_data(data)) != network::null_connection) {
|
||||
while((sock = network::receive_data(data, 0, &gzipped)) != network::null_connection) {
|
||||
if(const config* req = data.child("request_campaign_list")) {
|
||||
LOG_CS << "sending campaign list to " << network::ip_address(sock) << "\n";
|
||||
time_t epoch = time(NULL);
|
||||
|
@ -324,7 +325,7 @@ namespace {
|
|||
read_compressed(cfg, *stream);
|
||||
add_license(cfg);
|
||||
|
||||
network::send_data(cfg, sock, true);
|
||||
network::send_data(cfg, sock, gzipped);
|
||||
|
||||
const int downloads = lexical_cast_default<int>((*campaign)["downloads"],0)+1;
|
||||
(*campaign)["downloads"] = lexical_cast<std::string>(downloads);
|
||||
|
|
20
src/game.cpp
20
src/game.cpp
|
@ -1156,8 +1156,8 @@ void game_controller::download_campaigns(std::string host)
|
|||
|
||||
config cfg;
|
||||
cfg.add_child("request_campaign_list");
|
||||
// @todo Should be enabled once the campaign server can be recompiled.
|
||||
network::send_data(cfg, sock, false);
|
||||
|
||||
network::send_data(cfg, sock, true);
|
||||
|
||||
network::connection res = dialogs::network_receive_dialog(disp(),_("Asking for list of add-ons"),cfg,sock);
|
||||
if(!res) {
|
||||
|
@ -1303,8 +1303,8 @@ void game_controller::download_campaigns(std::string host)
|
|||
|
||||
config request;
|
||||
request.add_child("request_campaign")["name"] = campaigns[index];
|
||||
// @todo Should be enabled once the campaign server can be recompiled.
|
||||
network::send_data(request, sock, false);
|
||||
|
||||
network::send_data(request, sock, true);
|
||||
|
||||
res = dialogs::network_receive_dialog(disp(),_("Downloading add-on..."),cfg,sock);
|
||||
if(!res) {
|
||||
|
@ -1381,8 +1381,8 @@ void game_controller::upload_campaign(const std::string& campaign, network::conn
|
|||
{
|
||||
config request_terms;
|
||||
request_terms.add_child("request_terms");
|
||||
// @todo Should be enabled once the campaign server can be recompiled.
|
||||
network::send_data(request_terms, sock, false);
|
||||
|
||||
network::send_data(request_terms, sock, true);
|
||||
config data;
|
||||
sock = network::receive_data(data,sock,5000);
|
||||
if(!sock) {
|
||||
|
@ -1424,8 +1424,8 @@ void game_controller::upload_campaign(const std::string& campaign, network::conn
|
|||
data.add_child("upload",cfg).add_child("data",campaign_data);
|
||||
|
||||
LOG_NET << "uploading campaign...\n";
|
||||
// @todo Should be enabled once the campaign server can be recompiled.
|
||||
network::send_data(data, sock, false);
|
||||
|
||||
network::send_data(data, sock, true);
|
||||
|
||||
sock = dialogs::network_send_dialog(disp(),_("Sending add-on"),data,sock);
|
||||
if(!sock) {
|
||||
|
@ -1452,8 +1452,8 @@ void game_controller::delete_campaign(const std::string& campaign, network::conn
|
|||
config data;
|
||||
data.add_child("delete",msg);
|
||||
|
||||
// @todo Should be enabled once the campaign server can be recompiled.
|
||||
network::send_data(data, sock, false);
|
||||
|
||||
network::send_data(data, sock, true);
|
||||
|
||||
sock = network::receive_data(data,sock,5000);
|
||||
if(!sock) {
|
||||
|
|
|
@ -647,7 +647,7 @@ connection receive_data(config& cfg, connection connection_num, unsigned int tim
|
|||
return 0;
|
||||
}
|
||||
|
||||
connection receive_data(config& cfg, connection connection_num)
|
||||
connection receive_data(config& cfg, connection connection_num, bool* gzipped)
|
||||
{
|
||||
if(!socket_set) {
|
||||
return 0;
|
||||
|
@ -702,7 +702,7 @@ connection receive_data(config& cfg, connection connection_num)
|
|||
|
||||
TCPsocket sock = connection_num == 0 ? 0 : get_socket(connection_num);
|
||||
TCPsocket s = sock;
|
||||
sock = network_worker_pool::get_received_data(sock,cfg);
|
||||
sock = network_worker_pool::get_received_data(sock,cfg, gzipped);
|
||||
if (sock == NULL) {
|
||||
if (!is_server() && last_ping != 0 && ping_timeout != 0)
|
||||
{
|
||||
|
|
|
@ -129,7 +129,7 @@ void queue_disconnect(connection connection_num);
|
|||
//! Returns the connection that data was received from,
|
||||
//! or 0 if timeout occurred.
|
||||
//! Throws error if an error occurred.
|
||||
connection receive_data(config& cfg, connection connection_num=0);
|
||||
connection receive_data(config& cfg, connection connection_num=0, bool* gzipped = 0);
|
||||
connection receive_data(config& cfg, connection connection_num, unsigned int timeout);
|
||||
connection receive_data(std::vector<char>& buf);
|
||||
|
||||
|
|
|
@ -510,9 +510,10 @@ static int process_queue(void* shard_num)
|
|||
|
||||
if(sent_buf) {
|
||||
if(sent_buf->raw_buffer.empty()) {
|
||||
output_to_buffer(sent_buf->sock, sent_buf->config_buf, sent_buf->stream, sent_buf->gzipped);
|
||||
const std::string &value = sent_buf->stream.str();
|
||||
make_network_buffer(value.c_str(), value.size(), sent_buf->raw_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
result = send_buffer(sent_buf->sock, sent_buf->raw_buffer);
|
||||
delete sent_buf;
|
||||
|
@ -539,6 +540,7 @@ static int process_queue(void* shard_num)
|
|||
try {
|
||||
if(stream.peek() == 31) {
|
||||
read_gz(received_data->config_buf, stream);
|
||||
received_data->gzipped = true;
|
||||
} else {
|
||||
compression_schema *compress;
|
||||
{
|
||||
|
@ -546,6 +548,7 @@ static int process_queue(void* shard_num)
|
|||
compress = &schemas.insert(std::pair<TCPsocket,schema_pair>(sock,schema_pair())).first->second.incoming;
|
||||
}
|
||||
read_compressed(received_data->config_buf, stream, *compress);
|
||||
received_data->gzipped = false;
|
||||
}
|
||||
} catch(config::error &e)
|
||||
{
|
||||
|
@ -671,7 +674,7 @@ void receive_data(TCPsocket sock)
|
|||
}
|
||||
}
|
||||
|
||||
TCPsocket get_received_data(TCPsocket sock, config& cfg)
|
||||
TCPsocket get_received_data(TCPsocket sock, config& cfg, bool* gzipped)
|
||||
{
|
||||
assert(!raw_data_only);
|
||||
const threading::lock lock_received(*received_mutex);
|
||||
|
@ -696,6 +699,10 @@ TCPsocket get_received_data(TCPsocket sock, config& cfg)
|
|||
} else {
|
||||
cfg.swap((*itor)->config_buf);
|
||||
const TCPsocket res = (*itor)->sock;
|
||||
if (gzipped)
|
||||
{
|
||||
*gzipped = (*itor)->gzipped;
|
||||
}
|
||||
buffer* buf = *itor;
|
||||
received_data_queue.erase(itor);
|
||||
delete buf;
|
||||
|
@ -734,12 +741,13 @@ void queue_raw_data(TCPsocket sock, const char* buf, int len)
|
|||
|
||||
}
|
||||
|
||||
void queue_data(TCPsocket sock,const config& buf, const bool gzipped)
|
||||
void queue_data(TCPsocket sock,const config& buf, const bool gzipped)
|
||||
{
|
||||
DBG_NW << "queuing data...\n";
|
||||
|
||||
buffer* queued_buf = new buffer(sock);
|
||||
output_to_buffer(sock, buf, queued_buf->stream, gzipped);
|
||||
queued_buf->config_buf = buf;
|
||||
// output_to_buffer(sock, buf, queued_buf->stream, gzipped);
|
||||
queued_buf->gzipped = gzipped;
|
||||
{
|
||||
const size_t shard = get_shard(sock);
|
||||
|
|
|
@ -43,7 +43,7 @@ void set_raw_data_only();
|
|||
//! Function to asynchronously received data to the given socket.
|
||||
void receive_data(TCPsocket sock);
|
||||
|
||||
TCPsocket get_received_data(TCPsocket sock, config& cfg);
|
||||
TCPsocket get_received_data(TCPsocket sock, config& cfg, bool* gzipped = 0);
|
||||
TCPsocket get_received_data(std::vector<char>& buf);
|
||||
|
||||
void queue_raw_data(TCPsocket sock, const char* buf, int len);
|
||||
|
|
Loading…
Add table
Reference in a new issue