Change the client to send gzipped data to the MP server now.

This works with older clients on the server as well.
New client directly with old client probably won't work (untested).
This commit is contained in:
Mark de Wever 2007-12-08 19:47:43 +00:00
parent 36f2553963
commit a20027e829
10 changed files with 43 additions and 129 deletions

View file

@ -1852,9 +1852,7 @@ private:
cwhisper["receiver"] = arg1;
data.add_child("whisper", cwhisper);
add_chat_message("whisper to "+cwhisper["receiver"],0,cwhisper["message"], game_display::MESSAGE_PRIVATE);
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(data, 0, false);
network::send_data(data, 0, true);
} else if (cmd == help) {
@ -2111,9 +2109,7 @@ private:
config& ban = cfg.add_child(cmd);
ban["username"] = data;
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
} else if (cmd == "mute" && network::nconnections() != 0) {
config cfg;
config& mute = cfg.add_child(cmd);
@ -2121,13 +2117,9 @@ private:
mute["username"] = data;
}
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
} else if (cmd == "muteall" && network::nconnections() != 0) {
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(config(cmd), 0, false);
network::send_data(config(cmd), 0, true);
} else if(cmd == "control" && network::nconnections() != 0) {
const std::string::const_iterator j = std::find(data.begin(),data.end(),' ');
if(j == data.end())
@ -2293,9 +2285,7 @@ private:
change["own_side"] = "yes";
}
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
}
} // end namespace events

View file

@ -54,9 +54,7 @@ public:
LOG_NW << "sending leave_game\n";
config cfg;
cfg.add_child("leave_game");
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
LOG_NW << "sent leave_game\n";
}
};
@ -213,9 +211,7 @@ static server_type open_connection(game_display& disp, const std::string& origin
config res;
cfg["version"] = game_config::version;
res.add_child("version", cfg);
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(res, 0, false);
network::send_data(res, 0, true);
}
//if we got a direction to login
@ -244,9 +240,7 @@ static server_type open_connection(game_display& disp, const std::string& origin
config response;
response.add_child("login")["username"] = login;
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(response, 0, false);
network::send_data(response, 0, true);
network::connection data_res = network::receive_data(data, 0, 3000);
if(!data_res) {
@ -389,9 +383,7 @@ static void enter_create_mode(game_display& disp, const config& game_config, gam
case mp::ui::QUIT:
default:
//update lobby content
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(config("refresh_lobby"), 0, false);
network::send_data(config("refresh_lobby"), 0, true);
break;
}
}
@ -416,9 +408,7 @@ static void enter_lobby_mode(game_display& disp, const config& game_config, game
gui::show_error_message(disp, error.message);
}
//update lobby content
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(config("refresh_lobby"), 0, false);
network::send_data(config("refresh_lobby"), 0, true);
}
break;
case mp::ui::OBSERVE:
@ -428,9 +418,7 @@ static void enter_lobby_mode(game_display& disp, const config& game_config, game
if(!error.message.empty()) {
gui::show_error_message(disp, error.message);
//update lobby content
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(config("refresh_lobby"), 0, false);
network::send_data(config("refresh_lobby"), 0, true);
}
}
break;
@ -441,9 +429,7 @@ static void enter_lobby_mode(game_display& disp, const config& game_config, game
if (!error.message.empty())
gui::show_error_message(disp, error.message);
//update lobby content
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(config("refresh_lobby"), 0, false);
network::send_data(config("refresh_lobby"), 0, true);
}
break;
case mp::ui::QUIT:
@ -453,9 +439,7 @@ static void enter_lobby_mode(game_display& disp, const config& game_config, game
const preferences::display_manager disp_manager(&disp);
preferences::show_preferences_dialog(disp,game_config);
//update lobby content
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(config("refresh_lobby"), 0, false);
network::send_data(config("refresh_lobby"), 0, true);
}
break;
default:

View file

@ -898,9 +898,7 @@ connect::connect(game_display& disp, const config& game_config, const game_data&
}
}
create_game["human_sides"] = lexical_cast<std::string>(human_sides);*/
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(response, 0, false);
network::send_data(response, 0, true);
// Adds the current user as default user.
users_.push_back(connected_user(preferences::login(), CNTR_LOCAL, 0));
@ -928,9 +926,7 @@ connect::connect(game_display& disp, const config& game_config, const game_data&
gamelist_updated(true);
// If we are connected, send data to the connected host
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(level_, 0, false);
network::send_data(level_, 0, true);
}
void connect::process_event()
@ -983,17 +979,13 @@ void connect::start_game()
// Make other clients not show the results of resolve_random().
config lock;
lock.add_child("stop_updates");
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(lock, 0, false);
network::send_data(lock, 0, true);
update_and_send_diff(true);
// Build the gamestate object after updating the level
level_to_gamestate(level_, state_, params_.saved_game);
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(config("start_game"), 0, false);
network::send_data(config("start_game"), 0, true);
}
void connect::hide_children(bool hide)
@ -1049,9 +1041,7 @@ void connect::process_network_data(const config& data, const network::connection
if(name.empty()) {
config response;
response.values["failed"] = "yes";
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(response, sock, false);
network::send_data(response, sock, true);
ERR_CF << "ERROR: No username provided with the side.\n";
return;
}
@ -1062,17 +1052,13 @@ void connect::process_network_data(const config& data, const network::connection
config response;
response.values["failed"] = "yes";
response["message"] = "The nick '" + name + "' is already in use.";
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(response, sock, false);
network::send_data(response, sock, true);
return;
} else {
users_.erase(player);
config observer_quit;
observer_quit.add_child("observer_quit").values["name"] = name;
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(observer_quit, 0, false);
network::send_data(observer_quit, 0, true);
update_user_combos();
}
}
@ -1093,16 +1079,12 @@ void connect::process_network_data(const config& data, const network::connection
if(itor == sides_.end()) {
config response;
response.values["failed"] = "yes";
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(response, sock, false);
network::send_data(response, sock, true);
config kick;
kick["username"] = data["name"];
config res;
res.add_child("kick", kick);
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(res, 0, false);
network::send_data(res, 0, true);
update_user_combos();
update_and_send_diff();
ERR_CF << "ERROR: Couldn't assign a side to '" << name << "'\n";
@ -1127,9 +1109,7 @@ void connect::process_network_data(const config& data, const network::connection
ERR_CF << "tried to take illegal side: " << side_taken << '\n';
config response;
response.values["failed"] = "yes";
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(response, sock, false);
network::send_data(response, sock, true);
}
}
@ -1222,13 +1202,9 @@ void connect::process_network_connection(const network::connection sock)
{
ui::process_network_connection(sock);
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(config("join_game"), 0, false);
network::send_data(config("join_game"), 0, true);
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(level_, sock, false);
network::send_data(level_, sock, true);
}
void connect::layout_children(const SDL_Rect& rect)
@ -1545,9 +1521,7 @@ void connect::update_and_send_diff(bool update_time_of_day)
config diff;
diff.add_child("scenario_diff",level_.get_diff(old_level));
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(diff, 0, false);
network::send_data(diff, 0, true);
}
bool connect::sides_available()
@ -1631,9 +1605,7 @@ void connect::kick_player(const std::string& name)
kick["username"] = name;
config res;
res.add_child("kick", kick);
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(res, 0, false);
network::send_data(res, 0, true);
}
int side = find_player_side(name);

View file

@ -721,9 +721,7 @@ void lobby::process_event()
else{
join["observe"] = "no";
}
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(response, 0, false);
network::send_data(response, 0, true);
if(observe) {
if (game.started){

View file

@ -372,9 +372,7 @@ void ui::handle_event(const SDL_Event& event)
//if the dialog has been open for a long time, refresh the lobby
config request;
request.add_child("refresh_lobby");
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(request, 0, false);
network::send_data(request, 0, true);
}
}
}
@ -383,9 +381,7 @@ void ui::send_chat_query(const std::string& args)
{
config data;
data.add_child("query")["type"] = args;
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(data, 0, false);
network::send_data(data, 0, true);
}
void ui::add_chat_message(const std::string& speaker, int /*side*/, const std::string& message, game_display::MESSAGE_TYPE /*type*/)
@ -402,9 +398,7 @@ void ui::send_chat_message(const std::string& message, bool /*allies_only*/)
data.add_child("message", msg);
add_chat_message(preferences::login(),0, message); //local echo
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(data, 0, false);
network::send_data(data, 0, true);
}

View file

@ -258,9 +258,7 @@ void wait::join_game(bool observe)
cfg["faction"] = "random";
cfg["leader"] = "random";
cfg["gender"] = "random";
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
if(allow_changes) {
events::event_context context;
@ -306,9 +304,7 @@ void wait::join_game(bool observe)
change["faction"] = lexical_cast<std::string>(faction_choice);
change["leader"] = leader_choice;
change["gender"] = gender_choice;
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(faction, 0, false);
network::send_data(faction, 0, true);
}
}

View file

@ -191,9 +191,7 @@ void notify_next_scenario(const io_type_t io_type){
cfg_notify["is_host"] = "1";
else
cfg_notify["is_host"] = "0";
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
}
LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_config,
@ -457,9 +455,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
config cfg;
std::string msg = _("Downloading next scenario...");
config cfg_load = cfg.add_child("load_next_scenario");
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
do {
cfg.clear();
@ -522,9 +518,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
// information, to the configuration object
wassert(cfg.child("store_next_scenario") != NULL);
write_game(gamestate, *cfg.child("store_next_scenario"), WRITE_SNAPSHOT_ONLY);
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
//notifies the clients that the host advanced to the next scenario
notify_next_scenario(IO_SERVER);

View file

@ -292,9 +292,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& st
info["type"] = "termination";
info["condition"] = "game over";
info["result"] = gamestate_.completion;
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
} else {
gui::message_dialog(*gui_,_("Game Over"),
_("The game is over.")).show();

View file

@ -100,9 +100,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
const config::child_list& turns = cfg.get_children("turn");
if(turns.empty() == false && from != network::null_connection) {
//forward the data to other peers
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data_all_except(cfg, from, false);
network::send_data_all_except(cfg, from, true);
}
for(config::child_list::const_iterator t = turns.begin(); t != turns.end(); ++t) {
@ -122,9 +120,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
config& info = cfg.add_child("info");
info["type"] = "termination";
info["condition"] = "out of sync";
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
replay::last_replay_error = e.message; //FIXME: some better way to pass this?
replay_error_.notify_observers();
@ -315,9 +311,7 @@ void turn_info::change_side_controller(const std::string& side, const std::strin
change["own_side"] = "yes";
}
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
}
void turn_info::take_side(const std::string& side, const std::string& controller)
@ -326,7 +320,5 @@ void turn_info::take_side(const std::string& side, const std::string& controller
cfg.values["side"] = side;
cfg.values["controller"] = controller;
cfg.values["name"] = controller+side;
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
}

View file

@ -1144,9 +1144,7 @@ void replay_network_sender::sync_non_undoable()
config cfg;
const config& data = cfg.add_child("turn",obj_.get_data_range(upto_,obj_.ncommands(),replay::NON_UNDO_DATA));
if(data.empty() == false) {
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
}
}
}
@ -1157,9 +1155,7 @@ void replay_network_sender::commit_and_sync()
config cfg;
const config& data = cfg.add_child("turn",obj_.get_data_range(upto_,obj_.ncommands()));
if(data.empty() == false) {
//! @todo To avoid chicken and egg first enable the server to receive
//! gzipped data.
network::send_data(cfg, 0, false);
network::send_data(cfg, 0, true);
}
upto_ = obj_.ncommands();