wesnothd: Add support for sending login warnings that the client can dismiss

This commit is contained in:
Ignacio R. Morelle 2011-06-24 08:47:33 +00:00
parent 928d55e61b
commit bf906de800
3 changed files with 31 additions and 0 deletions

View File

@ -226,6 +226,20 @@ static server_type open_connection(game_display& disp, const std::string& origin
throw network::error(_("Connection timed out"));
}
config *warning = &data.child("warning");
if(*warning) {
std::string warning_msg;
warning_msg = (*warning)["message"].str();
warning_msg += "\n\n";
warning_msg += _("Do you want to continue?");
if(gui2::show_message(disp.video(), _("Warning"), warning_msg, gui2::tmessage::yes_no_buttons) != gui2::twindow::OK) {
return ABORT_SERVER;
}
}
config *error = &data.child("error");
// ... and get us out of here if the server did not complain

View File

@ -424,6 +424,17 @@ void server::send_error(network::connection sock, const char* msg, const char* e
send_doc(doc, sock, "error");
}
void server::send_warning(network::connection sock, const char* msg, const char* warning_code) const
{
simple_wml::document doc;
doc.root().add_child("warning").set_attr("message", msg);
if(*warning_code != '\0') {
doc.child("warning")->set_attr("warning_code", warning_code);
}
send_doc(doc, sock, "warning");
}
void server::send_password_request(network::connection sock, const std::string& msg,
const std::string& user, const char* error_code, bool force_confirmation)
{

View File

@ -26,6 +26,12 @@ private:
send_error(sock, msg.c_str(), error_code);
}
void send_warning(network::connection sock, const char* msg, const char* warning_code ="") const;
void send_warning(network::connection sock, const std::string &msg, const char* warning_code = "") const
{
send_warning(sock, msg.c_str(), warning_code);
}
// The same as send_error(), we just add an extra child to the response
// telling the client the chosen username requires a password.
void send_password_request(network::connection sock, const std::string& msg,