Removed --new-uploader and associated code since new uploader is now default.

This commit is contained in:
Gregory Shikhman 2009-09-03 13:03:51 +00:00
parent fcdd0674ef
commit 6ae2943df6
4 changed files with 34 additions and 198 deletions

View file

@ -428,9 +428,6 @@ game_controller::game_controller(int argc, char** argv) :
} else if(val == "--new-widgets") {
// This is a hidden option to enable the new widget toolkit.
gui2::new_widgets = true;
} else if(val == "--new-uploader") {
//hidden option to test experimental game log upload changes
uploader_settings::new_uploader = true;
#ifndef DISABLE_EDITOR
} else if(val == "-e" || val == "--editor") {
jump_to_editor_ = true;
@ -930,7 +927,7 @@ bool game_controller::play_multiplayer_mode()
}
}
upload_log log( all_ai && uploader_settings::new_uploader );
upload_log log( all_ai );
recorder.add_log_data("ai_log","ai_label",label);
state_.snapshot = level;
@ -1816,8 +1813,6 @@ static int process_command_args(int argc, char** argv) {
<< " file bug reports since most are known).\n"
<< " Parts of the library are deemed stable and will\n"
<< " work without this switch.\n"
<< " --new-uploader Enables the new experimental game log uploader.\n"
<< " Under development - expect things not to work.\n"
;
return 0;
} else if(val == "--version" || val == "-v") {

View file

@ -325,9 +325,10 @@ LEVEL_RESULT playsingle_controller::play_scenario(
LOG_NG << "entering try... " << (SDL_GetTicks() - ticks_) << "\n";
try {
// Log before prestart events: they do weird things.
if (first_human_team_ != -1) {
log.start(gamestate_, teams_[first_human_team_], first_human_team_ + 1, units_,
loading_game_ ? gamestate_.get_variable("turn_number") : "", number_of_turns(), resources::game_map->write());
if (first_human_team_ != -1) { //sp logs
log.start(gamestate_, teams_[first_human_team_],
loading_game_ ? gamestate_.get_variable("turn_number") : "",
number_of_turns(), resources::game_map->write());
} else { //ai vs. ai upload logs
log.start(gamestate_, resources::game_map->write());
}

View file

@ -44,15 +44,9 @@ static lg::log_domain log_uploader("uploader");
extern replay recorder;
namespace uploader_settings {
bool new_uploader = false;
const std::string target_host = "www.wesnoth.org";
const std::string target_url = "/cgi-bin/upload";
const Uint16 target_port = 80;
const std::string target_host_dev = "www.wesnoth.org";
const std::string target_url_dev = "/wesstats/upload";
const Uint16 target_port_dev = 80;
} //namespace uploader_settings
const std::string TARGET_HOST = "www.wesnoth.org";
const std::string TARGET_URL = "/cgi-bin/upload";
const Uint16 TARGET_PORT = 80;
struct upload_log::thread_info upload_log::thread_;
upload_log::manager* upload_log::manager_ = 0;
@ -98,8 +92,8 @@ static int upload_logs(void *_ti)
int numfiles = 0;
const std::string header =
"POST " + uploader_settings::target_url + " HTTP/1.1\n"
"Host: " + uploader_settings::target_host + "\n"
"POST " + TARGET_URL + " HTTP/1.1\n"
"Host: " + TARGET_HOST + "\n"
"User-Agent: Wesnoth " VERSION "\n"
"Content-Type: text/plain\n";
@ -112,83 +106,7 @@ static int upload_logs(void *_ti)
IPaddress ip;
network::manager ensure_net_initialized;
if (SDLNet_ResolveHost(&ip, uploader_settings::target_host.c_str(), uploader_settings::target_port) == 0) {
std::vector<std::string>::iterator i;
for (i = files.begin(); i!=files.end() && *i!=ti->lastfile; i++) {
std::string contents;
char response[10]; //This needs to be strlen("HTTP/1.1 2");
contents = read_file(*i);
sock = SDLNet_TCP_Open(&ip);
if (!sock) {
ERR_UPLD << "error connecting to log server\n";
break;
} else {
DBG_UPLD << "successfully connected to log server\n";
}
send_string(sock, header.c_str());
send_string(sock, "Content-length: ");
send_string(sock, lexical_cast<std::string>(contents.length()));
send_string(sock, "\n\n");
send_string(sock, contents.c_str());
// As long as we can actually send the data, delete the file.
// Even if the server gives a bad response, we don't want to
// be sending the same bad data over and over to the server.
delete_directory(*i);
numfiles++;
if (SDLNet_TCP_Recv(sock, response, sizeof(response))
!= sizeof(response))
break;
// Must be version 1.x, must start with 2 (eg. 200) for success
if (memcmp(response, "HTTP/1.", strlen("HTTP/1.")) != 0)
break;
if (memcmp(response+8, " 2", strlen(" 2")) != 0)
break;
SDLNet_TCP_Close(sock);
sock = NULL;
}
}
} catch(...) { }
if (sock)
SDLNet_TCP_Close(sock);
ti->shutdown = true;
DBG_UPLD << numfiles << " game logs successfully sent to server\n";
return 0;
}
// Function which runs in a background thread to upload logs to server.
// Uses http POST to port 80 for maximum firewall penetration & other-end
// compatibility.
static int upload_logs_dev(void *_ti)
{
DBG_UPLD << "using experimental uploader\n";
DBG_UPLD << "attempting to upload game logs\n";
TCPsocket sock = NULL;
upload_log::thread_info *ti = static_cast<upload_log::thread_info*>(_ti);
int numfiles = 0;
const std::string header =
"POST " + uploader_settings::target_url_dev + " HTTP/1.1\n"
"Host: " + uploader_settings::target_host_dev + "\n"
"User-Agent: Wesnoth " VERSION "\n"
"Content-Type: text/plain\n";
try {
std::vector<std::string> files;
// These are sorted: send them one at a time until we get to lastfile.
get_files_in_dir(get_upload_dir(), &files, NULL, ENTIRE_FILE_PATH);
IPaddress ip;
network::manager ensure_net_initialized;
if (SDLNet_ResolveHost(&ip, uploader_settings::target_host_dev.c_str(), uploader_settings::target_port_dev) == 0) {
if (SDLNet_ResolveHost(&ip, TARGET_HOST.c_str(), TARGET_PORT) == 0) {
std::vector<std::string>::iterator i;
for (i = files.begin(); i!=files.end() && *i!=ti->lastfile; i++) {
std::string contents;
@ -251,17 +169,13 @@ upload_log::upload_log(bool enable) :
// Thread can outlive us; it uploads everything up to the
// next filename, and unsets thread_.t when it's finished.
thread_.lastfile = filename_;
if(uploader_settings::new_uploader) {
thread_.t = new threading::thread(upload_logs_dev, &thread_);
} else {
thread_.t = new threading::thread(upload_logs, &thread_);
}
thread_.t = new threading::thread(upload_logs, &thread_);
}
}
void upload_log::read_replay()
{
if( !uploader_settings::new_uploader || !enabled_ || game_config::debug ) {
if( !enabled_ || game_config::debug ) {
return;
}
@ -300,11 +214,7 @@ upload_log::~upload_log()
if (enabled_ && !config_.empty() && !game_config::debug) {
config_["version"] = VERSION;
if(uploader_settings::new_uploader) {
config_["format_version"] = "2";
} else {
config_["format_version"] = "1";
}
config_["format_version"] = "2";
config_["id"] = preferences::upload_id();
config_["serial"] = lexical_cast<std::string>(time(NULL)) + file_name(filename_);
config_["language"] = preferences::language();
@ -318,14 +228,11 @@ upload_log::~upload_log()
#endif
std::ostream *out = ostream_file(filename_);
if(uploader_settings::new_uploader) {
{
boost::iostreams::filtering_stream<boost::iostreams::output> filter;
filter.push(boost::iostreams::gzip_compressor());
filter.push(*out);
write(filter, config_);
} else {
write(*out, config_);
}
delete out;
@ -335,11 +242,7 @@ upload_log::~upload_log()
// Try to upload latest log before exit.
if (preferences::upload_log() && !thread_.t) {
thread_.lastfile = next_filename(get_upload_dir(), 1000);
if(uploader_settings::new_uploader) {
thread_.t = new threading::thread(upload_logs_dev, &thread_);
} else {
thread_.t = new threading::thread(upload_logs, &thread_);
}
thread_.t = new threading::thread(upload_logs, &thread_);
}
}
}
@ -366,8 +269,6 @@ config &upload_log::add_game_result(const std::string &str, int turn)
// User starts a game (may be new campaign or saved).
void upload_log::start(game_state &state, const team &team,
int side_number,
const unit_map &units,
const t_string &turn,
int num_turns,
const std::string map_data)
@ -387,78 +288,21 @@ void upload_log::start(game_state &state, const team &team,
(*game_)["campaign"] = state.classification().campaign_define;
(*game_)["difficulty"] = state.classification().difficulty;
(*game_)["scenario"] = state.classification().scenario;
if(uploader_settings::new_uploader) {
//replace newlines in map definition with semicolons so that braindead server-side wml parser doesn't get confused
std::string encoded_map(map_data);
for(size_t idx = 0; idx < encoded_map.length(); idx++) {
if(encoded_map[idx] == '\n')
encoded_map[idx] = ';';
}
(*game_)["map_data"] = encoded_map;
//replace newlines in map definition with semicolons so that braindead server-side wml parser doesn't get confused
std::string encoded_map(map_data);
for(size_t idx = 0; idx < encoded_map.length(); idx++) {
if(encoded_map[idx] == '\n')
encoded_map[idx] = ';';
}
(*game_)["map_data"] = encoded_map;
if (!state.classification().version.empty())
(*game_)["version"] = state.classification().version;
if (!turn.empty())
(*game_)["start_turn"] = turn;
(*game_)["gold"] = lexical_cast<std::string>(team.gold());
(*game_)["num_turns"] = lexical_cast<std::string>(num_turns);
//deprecating this data in new upload logs
if(!uploader_settings::new_uploader) {
// We seem to have to walk the map to find some units,
// and the player's recall list for the rest.
for (unit_map::const_iterator un = units.begin(); un != units.end(); ++un){
if (un->second.side() == side_number) {
all_units.push_back(&un->second);
}
}
/** @todo FIXME: Assumes first player is "us"; is that valid? */
for (std::vector<unit>::const_iterator it = team.recall_list().begin();
it != team.recall_list().end();
++it) {
all_units.push_back(&*it);
}
// Record details of any special units.
std::vector<const unit*>::const_iterator i;
for (i = all_units.begin(); i != all_units.end(); ++i) {
if ((*i)->can_recruit()) {
config &sp = game_->add_child("special-unit");
sp["name"] = (*i)->id();
sp["level"] = lexical_cast<std::string>((*i)->level());
sp["experience"] = lexical_cast<std::string>((*i)->experience());
}
}
// Record summary of all units.
config &summ = game_->add_child("units-by-level");
bool higher_units = true;
for (int level = 0; higher_units; level++) {
std::map<std::string, int> tally;
higher_units = false;
for (i = all_units.begin(); i != all_units.end(); ++i) {
if ((*i)->level() > level)
higher_units = true;
else if ((*i)->level() == level) {
if (tally.find((*i)->type_id()) == tally.end())
tally[(*i)->type_id()] = 1;
else
tally[(*i)->type_id()]++;
}
}
if (!tally.empty()) {
config &tc = summ.add_child(lexical_cast<std::string>(level));
for (std::map<std::string, int>::iterator t = tally.begin();
t != tally.end();
t++) {
config &uc = tc.add_child(t->first);
uc["count"] = lexical_cast<std::string>(t->second);
}
}
}
}
}
void upload_log::start(game_state &state, const std::string map_data)
@ -476,15 +320,15 @@ void upload_log::start(game_state &state, const std::string map_data)
(*game_)["campaign"] = state.classification().campaign_type;
(*game_)["difficulty"] = state.classification().difficulty;
(*game_)["scenario"] = state.classification().label;
if(uploader_settings::new_uploader) {
//replace newlines in map definition with semicolons so that braindead server-side wml parser doesn't get confused
std::string encoded_map(map_data);
for(size_t idx = 0; idx < encoded_map.length(); idx++) {
if(encoded_map[idx] == '\n')
encoded_map[idx] = ';';
}
(*game_)["map_data"] = encoded_map;
//replace newlines in map definition with semicolons so that braindead server-side wml parser doesn't get confused
std::string encoded_map(map_data);
for(size_t idx = 0; idx < encoded_map.length(); idx++) {
if(encoded_map[idx] == '\n')
encoded_map[idx] = ';';
}
(*game_)["map_data"] = encoded_map;
if (!state.classification().version.empty())
(*game_)["version"] = state.classification().version;
}

View file

@ -28,10 +28,6 @@ class t_string;
class team;
class unit_map;
namespace uploader_settings {
extern bool new_uploader;
} //namespace uploader_settings
struct upload_log
{
public:
@ -47,8 +43,8 @@ public:
// User starts a game (may be new campaign or saved).
void start(game_state &state, const team &team,
int side_number, const unit_map &map, const t_string &turn,
int num_turns, const std::string map_data);
const t_string &turn, int num_turns,
const std::string map_data);
void start(game_state &state, const std::string map_data);
// User finishes a level.