Simplified calling conventions.

This commit is contained in:
Karol Nowak 2011-02-06 11:39:28 +00:00
parent 36d09851b1
commit 9d5edf7944
7 changed files with 117 additions and 96 deletions

View file

@ -194,7 +194,7 @@ void game::start_game(const player_map::const_iterator starter) {
std::stringstream msg;
msg << "Side " << side_num + 1 << " has no controller but should! The host needs to assign control for the game to proceed past that side's turn.";
LOG_GAME << msg.str() << " (game id: " << id_ << ")\n";
send_and_record_server_message(msg.str().c_str());
send_and_record_server_message(msg.str());
}
(*s)->set_attr("controller", "human");
}
@ -345,7 +345,7 @@ void game::transfer_side_control(const network::connection sock, const simple_wm
std::ostringstream msg;
msg << "The side number has to be between 1 and "
<< gamemap::MAX_PLAYERS << ".";
send_server_message(msg.str().c_str(), sock);
send_server_message(msg.str(), sock);
return;
}
@ -373,7 +373,7 @@ void game::transfer_side_control(const network::connection sock, const simple_wm
std::stringstream msg;
msg << "Wrong controller type received: '" << cfg["controller"] << "'";
DBG_GAME << msg.str() << "\n";
send_server_message(msg.str().c_str(), sock);
send_server_message(msg.str(), sock);
return;
}
change_controller(side_num - 1, old_player, old_player_name, false, cfg["controller"].to_string());
@ -386,7 +386,7 @@ void game::transfer_side_control(const network::connection sock, const simple_wm
msg << "You can't give away side " << side_num << ". It's controlled by '"
<< old_player_name << "' not you.";
DBG_GAME << msg.str() << "\n";
send_server_message(msg.str().c_str(), sock);
send_server_message(msg.str(), sock);
return;
}
//find the player that is passed control
@ -394,14 +394,14 @@ void game::transfer_side_control(const network::connection sock, const simple_wm
// Is he in this game?
if (newplayer == player_info_->end() || !is_member(newplayer->first)) {
send_server_message((newplayer_name.to_string() + " is not in this game").c_str(), sock);
send_server_message(newplayer_name.to_string() + " is not in this game", sock);
return;
}
if (newplayer->first == old_player) {
std::stringstream msg;
msg << "That's already " << newplayer_name << "'s side, silly.";
send_server_message(msg.str().c_str(), sock);
send_server_message(msg.str(), sock);
return;
}
sides_[side_num - 1] = 0;
@ -412,7 +412,7 @@ void game::transfer_side_control(const network::connection sock, const simple_wm
oldplayer->second.set_status(player::OBSERVING);
players_.erase(std::remove(players_.begin(), players_.end(), old_player), players_.end());
// Tell others that the player becomes an observer.
send_and_record_server_message((old_player_name + " becomes an observer.").c_str());
send_and_record_server_message(old_player_name + " becomes an observer.");
// Update the client side observer list for everyone except old player.
simple_wml::document observer_join;
observer_join.root().add_child("observer").set_attr_dup("name", old_player_name.c_str());
@ -444,12 +444,11 @@ void game::change_controller(const size_t side_num,
if (player_left && side_controllers_[side_num] == "ai") {
// Automatic AI side transfer.
} else if (controller.empty()) {
send_and_record_server_message((player_name
+ " takes control of side " + side + ".").c_str());
send_and_record_server_message(player_name + " takes control of side " + side + ".");
side_controllers_[side_num] = "human";
} else {
send_and_record_server_message((player_name + (controller == "human_ai" ? " " : " un")
+ "droids side " + side + ".").c_str());
send_and_record_server_message(player_name + (controller == "human_ai" ? " " : " un")
+ "droids side " + side + ".");
side_controllers_[side_num] = (controller == "human_ai" ? "ai" : "human");
}
@ -493,7 +492,7 @@ void game::notify_new_host(){
if (!wesnothd::send_to_one(cfg, owner_)) {
message += " But an internal error occurred. You probably have to abandon this game.";
}
send_and_record_server_message(message.c_str());
send_and_record_server_message(message);
}
bool game::describe_slots() {
@ -545,7 +544,7 @@ void game::send_muted_observers(const player_map::const_iterator user) const
}
std::string muted_nicks = list_users(muted_observers_, __func__);
send_server_message(("Muted observers: " + muted_nicks).c_str(), user->first);
send_server_message("Muted observers: " + muted_nicks, user->first);
}
void game::mute_observer(const simple_wml::node& mute,
@ -567,7 +566,7 @@ void game::mute_observer(const simple_wml::node& mute,
* also allow muting of usernames not in the game.
*/
if (user == player_info_->end() || !is_observer(user->first)) {
send_server_message(("Observer '" + username.to_string() + "' not found.").c_str(), muter->first);
send_server_message("Observer '" + username.to_string() + "' not found.", muter->first);
return;
}
@ -577,7 +576,7 @@ void game::mute_observer(const simple_wml::node& mute,
return;
}
if (is_muted_observer(user->first)) {
send_server_message((username.to_string() + " is already muted.").c_str(), muter->first);
send_server_message(username.to_string() + " is already muted.", muter->first);
return;
}
LOG_GAME << network::ip_address(muter->first) << "\t"
@ -585,7 +584,7 @@ void game::mute_observer(const simple_wml::node& mute,
<< network::ip_address(user->first) << ")\tin game:\t\""
<< name_ << "\" (" << id_ << ")\n";
muted_observers_.push_back(user->first);
send_and_record_server_message((username.to_string() + " has been muted.").c_str());
send_and_record_server_message(username.to_string() + " has been muted.");
}
void game::unmute_observer(const simple_wml::node& unmute,
@ -604,12 +603,12 @@ void game::unmute_observer(const simple_wml::node& unmute,
const player_map::const_iterator user = find_user(username);
if (user == player_info_->end() || !is_observer(user->first)) {
send_server_message(("Observer '" + username.to_string() + "' not found.").c_str(), unmuter->first);
send_server_message("Observer '" + username.to_string() + "' not found.", unmuter->first);
return;
}
if (!is_muted_observer(user->first)) {
send_server_message((username.to_string() + " is not muted.").c_str(), unmuter->first);
send_server_message(username.to_string() + " is not muted.", unmuter->first);
return;
}
@ -619,7 +618,7 @@ void game::unmute_observer(const simple_wml::node& unmute,
<< name_ << "\" (" << id_ << ")\n";
muted_observers_.erase(std::remove(muted_observers_.begin(),
muted_observers_.end(), user->first), muted_observers_.end());
send_and_record_server_message((username.to_string() + " has been unmuted.").c_str());
send_and_record_server_message(username.to_string() + " has been unmuted.");
}
void game::send_leave_game(network::connection user) const
@ -638,7 +637,7 @@ network::connection game::kick_member(const simple_wml::node& kick,
const simple_wml::string_span& username = kick["username"];
const player_map::const_iterator user = find_user(username);
if (user == player_info_->end() || !is_member(user->first)) {
send_server_message(("'" + username.to_string() + "' is not a member of this game.").c_str(), kicker->first);
send_server_message("'" + username.to_string() + "' is not a member of this game.", kicker->first);
return 0;
} else if (user->first == kicker->first) {
send_server_message("Don't kick yourself, silly.", kicker->first);
@ -651,7 +650,7 @@ network::connection game::kick_member(const simple_wml::node& kick,
<< kicker->second.name() << "\tkicked: " << username << " ("
<< network::ip_address(user->first) << ")\tfrom game:\t\""
<< name_ << "\" (" << id_ << ")\n";
send_and_record_server_message((username.to_string() + " has been kicked.").c_str());
send_and_record_server_message(username.to_string() + " has been kicked.");
// Tell the user to leave the game.
send_leave_game(user->first);
@ -669,13 +668,13 @@ network::connection game::ban_user(const simple_wml::node& ban,
const simple_wml::string_span& username = ban["username"];
const player_map::const_iterator user = find_user(username);
if (user == player_info_->end()) {
send_server_message(("User '" + username.to_string() + "' not found.").c_str(), banner->first);
send_server_message("User '" + username.to_string() + "' not found.", banner->first);
return 0;
} else if (user->first == banner->first) {
send_server_message("Don't ban yourself, silly.", banner->first);
return 0;
} else if (player_is_banned(user->first)) {
send_server_message(("'" + username.to_string() + "' is already banned.").c_str(), banner->first);
send_server_message("'" + username.to_string() + "' is already banned.", banner->first);
return 0;
} else if (user->second.is_moderator()) {
send_server_message("You're not allowed to ban a moderator.", banner->first);
@ -686,7 +685,7 @@ network::connection game::ban_user(const simple_wml::node& ban,
<< network::ip_address(user->first) << ")\tfrom game:\t\""
<< name_ << "\" (" << id_ << ")\n";
bans_.push_back(network::ip_address(user->first));
send_and_record_server_message((username.to_string() + " has been banned.").c_str());
send_and_record_server_message(username.to_string() + " has been banned.");
if (is_member(user->first)) {
//tell the user to leave the game.
send_leave_game(user->first);
@ -707,11 +706,11 @@ void game::unban_user(const simple_wml::node& unban,
const simple_wml::string_span& username = unban["username"];
const player_map::const_iterator user = find_user(username);
if (user == player_info_->end()) {
send_server_message(("User '" + username.to_string() + "' not found.").c_str(), unbanner->first);
send_server_message("User '" + username.to_string() + "' not found.", unbanner->first);
return;
}
if (!player_is_banned(user->first)) {
send_server_message(("'" + username.to_string() + "' is not banned.").c_str(), unbanner->first);
send_server_message("'" + username.to_string() + "' is not banned.", unbanner->first);
return;
}
LOG_GAME << network::ip_address(unbanner->first) << "\t"
@ -719,7 +718,7 @@ void game::unban_user(const simple_wml::node& unban,
<< network::ip_address(user->first) << ")\tfrom game:\t\""
<< name_ << "\" (" << id_ << ")\n";
bans_.erase(std::remove(bans_.begin(), bans_.end(), network::ip_address(user->first)), bans_.end());
send_and_record_server_message((username.to_string() + " has been unbanned.").c_str());
send_and_record_server_message(username.to_string() + " has been unbanned.");
}
void game::process_message(simple_wml::document& data, const player_map::iterator user) {
@ -790,7 +789,7 @@ bool game::process_turn(simple_wml::document& data, const player_map::const_iter
<< " (" << end_turn_ + 1 << "/" << nsides_ << ").";
LOG_GAME << msg.str() << " (socket: " << current_player()
<< ") (game id: " << id_ << ")\n";
send_and_record_server_message(msg.str().c_str());
send_and_record_server_message(msg.str());
marked.push_back(index - marked.size());
} else if ((**command).child("speak")) {
@ -869,7 +868,7 @@ bool game::process_turn(simple_wml::document& data, const player_map::const_iter
msg << "Removing illegal message from " << user->second.name() << " to " << std::string(team_name.begin(), team_name.end()) << ".";
const std::string& msg_str = msg.str();
LOG_GAME << msg_str << std::endl;
send_and_record_server_message(msg_str.c_str());
send_and_record_server_message(msg_str);
continue;
}
@ -934,7 +933,7 @@ bool game::add_player(const network::connection player, bool observer) {
DBG_GAME << "adding player...\n";
players_.push_back(player);
user->second.set_status(player::PLAYING);
send_and_record_server_message((user->second.name() + " has joined the game.").c_str(), player);
send_and_record_server_message(user->second.name() + " has joined the game.", player);
} else if (!allow_observers() && !user->second.is_moderator()) {
return false;
} else {
@ -944,7 +943,7 @@ bool game::add_player(const network::connection player, bool observer) {
}
DBG_GAME << "adding observer...\n";
observers_.push_back(player);
if (!allow_observers()) send_and_record_server_message((user->second.name() + " is now observing the game.").c_str(), player);
if (!allow_observers()) send_and_record_server_message(user->second.name() + " is now observing the game.", player);
simple_wml::document observer_join;
observer_join.root().add_child("observer").set_attr_dup("name", user->second.name().c_str());
@ -978,7 +977,7 @@ bool game::add_player(const network::connection player, bool observer) {
const std::string clones = has_same_ip(player, observer);
if (!clones.empty()) {
send_and_record_server_message((user->second.name() + " has the same IP as: " + clones).c_str());
send_and_record_server_message(user->second.name() + " has the same IP as: " + clones);
}
if (became_observer) {
@ -1018,7 +1017,7 @@ bool game::remove_player(const network::connection player, const bool disconnect
<< (disconnect ? " and disconnected" : "")
<< ". (socket: " << user->first << ")\n";
if (game_ended && started_ && !(observer && destruct)) {
send_server_message_to_all((user->second.name() + " ended the game.").c_str(), player);
send_server_message_to_all(user->second.name() + " ended the game.", player);
}
if (game_ended || destruct) return game_ended;
@ -1030,8 +1029,8 @@ bool game::remove_player(const network::connection player, const bool disconnect
if (observer) {
send_observerquit(user);
} else {
send_and_record_server_message((user->second.name()
+ (disconnect ? " has disconnected." : " has left the game.")).c_str(), player);
send_and_record_server_message(user->second.name()
+ (disconnect ? " has disconnected." : " has left the game."), player);
}
// If the player was host choose a new one.
if (host) {
@ -1094,7 +1093,7 @@ void game::send_user_list(const network::connection exclude) const {
}
void game::load_next_scenario(const player_map::const_iterator user) const {
send_server_message_to_all((user->second.name() + " advances to the next scenario").c_str(), user->first);
send_server_message_to_all(user->second.name() + " advances to the next scenario", user->first);
simple_wml::document cfg_scenario;
level_.root().copy_into(cfg_scenario.root().add_child("next_scenario"));
if (!wesnothd::send_to_one(cfg_scenario, user->first)) return;
@ -1366,8 +1365,7 @@ player_map::iterator game::find_user(const simple_wml::string_span& name)
return pl;
}
void game::send_and_record_server_message(const char* message,
const network::connection exclude)
void game::send_and_record_server_message(const char* message, const network::connection exclude)
{
simple_wml::document* doc = new simple_wml::document;
send_server_message(message, 0, doc);
@ -1402,6 +1400,7 @@ void game::send_server_message(const char* message, network::connection sock, si
msg.set_attr_dup("message", message);
}
if(sock) {
wesnothd::send_to_one(doc, sock, "message");
}

View file

@ -140,11 +140,24 @@ public:
bool describe_slots();
void send_server_message_to_all(const char* message, network::connection exclude=0) const;
void send_server_message_to_all(const std::string& message, network::connection exclude=0) const
{
send_server_message_to_all(message.c_str(), exclude);
}
void send_server_message(const char* message, network::connection sock=0, simple_wml::document* doc=NULL) const;
void send_server_message(const std::string& message, network::connection sock=0, simple_wml::document* doc=NULL) const
{
send_server_message(message.c_str(), sock, doc);
}
/** Send data to all players in this game except 'exclude'. */
void send_and_record_server_message(const char* message,
const network::connection exclude=0);
void send_and_record_server_message(const char* message, const network::connection exclude=0);
void send_and_record_server_message(const std::string& message, const network::connection exclude=0)
{
send_and_record_server_message(message.c_str(), exclude);
}
void send_data(simple_wml::document& data, const network::connection exclude=0, std::string packet_type = "") const;
void clear_history();

View file

@ -120,17 +120,15 @@ void room::send_data(simple_wml::document& data,
wesnothd::send_to_many(data, members(), exclude, packet_type);
}
void room::send_server_message_to_all(const char* message,
network::connection exclude) const
void room::send_server_message_to_all(const char* message, network::connection exclude) const
{
simple_wml::document doc;
send_server_message(message, 0, &doc);
send_data(doc, exclude, "message");
}
void room::send_server_message(const char* message,
network::connection sock,
simple_wml::document* docptr) const
void room::send_server_message(const char* message, network::connection sock,
simple_wml::document* docptr) const
{
simple_wml::document docbuf;
if(docptr == NULL) {

View file

@ -143,6 +143,10 @@ public:
* @param exclude if nonzero, do not send to this player
*/
void send_server_message_to_all(const char* message, network::connection exclude=0) const;
void send_server_message_to_all(const std::string& message, network::connection exclude=0) const
{
send_server_message_to_all(message.c_str(), exclude);
}
/**
* Prepare a text message and/or send it to a player. If a nonzero sock
@ -156,6 +160,12 @@ public:
void send_server_message(const char* message, network::connection sock,
simple_wml::document* docptr = NULL) const;
void send_server_message(const std::string& message, network::connection sock,
simple_wml::document* docptr = NULL) const
{
send_server_message(message.c_str(), sock, docptr);
}
private:
std::string name_;

View file

@ -365,7 +365,7 @@ void room_manager::process_message(simple_wml::document &data, const player_map:
std::stringstream ss;
ss << "You are not a member of the room '" << room_name << "'. "
<< "Your message has not been relayed.";
lobby_->send_server_message(ss.str().c_str(), user->first);
lobby_->send_server_message(ss.str(), user->first);
return;
}
if (user->second.is_message_flooding()) {

View file

@ -420,7 +420,7 @@ void server::send_error(network::connection sock, const char* msg, const char* e
send_doc(doc, sock, "error");
}
void server::send_password_request(network::connection sock, const char* msg,
void server::send_password_request(network::connection sock, const std::string& msg,
const std::string& user, const char* error_code, bool force_confirmation)
{
std::string salt = user_handler_->create_salt();
@ -438,7 +438,7 @@ void server::send_password_request(network::connection sock, const char* msg,
simple_wml::document doc;
simple_wml::node& e = doc.root().add_child("error");
e.set_attr("message", msg);
e.set_attr("message", msg.c_str());
e.set_attr("password_request", "yes");
e.set_attr("phpbb_encryption", user_handler_->use_phpbb_encryption() ? "yes" : "no");
e.set_attr("salt", spices.c_str());
@ -711,7 +711,7 @@ void server::run() {
const std::string reason = is_ip_banned(ip);
if (!reason.empty()) {
LOG_SERVER << ip << "\trejected banned user. Reason: " << reason << "\n";
send_error(sock, ("You are banned. Reason: " + reason).c_str());
send_error(sock, "You are banned. Reason: " + reason);
network::disconnect(sock);
} else if (ip_exceeds_connection_limit(ip)) {
LOG_SERVER << ip << "\trejected ip due to excessive connections\n";
@ -751,7 +751,7 @@ void server::run() {
} catch (simple_wml::error& e) {
WRN_CONFIG << "simple_wml error in received data: " << e.message << std::endl;
send_error(sock, ("Invalid WML received: " + e.message).c_str());
send_error(sock, "Invalid WML received: " + e.message);
delete [] buf_ptr;
continue;
} catch(...) {
@ -1010,13 +1010,13 @@ void server::process_login(const network::connection sock,
// Check if the username is valid (all alpha-numeric plus underscore and hyphen)
std::string username = (*login)["username"].to_string();
if (!utils::isvalid_username(username)) {
send_error(sock, ("The nick '" + username + "' contains invalid "
send_error(sock, "The nick '" + username + "' contains invalid "
"characters. Only alpha-numeric characters, underscores and hyphens"
"are allowed.").c_str(), MP_INVALID_CHARS_IN_NAME_ERROR);
"are allowed.", MP_INVALID_CHARS_IN_NAME_ERROR);
return;
}
if (username.size() > 20) {
send_error(sock, ("The nick '" + username + "' is too long. Nicks must be 20 characters or less.").c_str(),
send_error(sock, "The nick '" + username + "' is too long. Nicks must be 20 characters or less.",
MP_NAME_TOO_LONG_ERROR);
return;
}
@ -1027,7 +1027,7 @@ void server::process_login(const network::connection sock,
if (utils::wildcard_string_match(utils::lowercase(username),
utils::lowercase(*d_it)))
{
send_error(sock, ("The nick '" + username + "' is reserved and cannot be used by players").c_str(),
send_error(sock, "The nick '" + username + "' is reserved and cannot be used by players",
MP_NAME_RESERVED_ERROR);
return;
}
@ -1041,8 +1041,8 @@ void server::process_login(const network::connection sock,
user_handler_->password_reminder(username);
send_error(sock, "Your password reminder email has been sent.");
} catch (user_handler::error e) {
send_error(sock, ("There was an error sending your password reminder email. The error message was: " +
e.message).c_str());
send_error(sock, "There was an error sending your password reminder email. The error message was: " +
e.message);
}
return;
}
@ -1075,12 +1075,12 @@ void server::process_login(const network::connection sock,
// This name is registered and no password provided
if(password.empty()) {
if(p == players_.end()) {
send_password_request(sock, ("The nick '" + username +"' is registered on this server.").c_str(),
send_password_request(sock, "The nick '" + username +"' is registered on this server.",
username, MP_PASSWORD_REQUEST);
} else {
send_password_request(sock, ("The nick '" + username + "' is registered on this server."
send_password_request(sock, "The nick '" + username + "' is registered on this server."
"\n\nWARNING: There is already a client using this username, "
"logging in will cause that client to be kicked!").c_str(),
"logging in will cause that client to be kicked!",
username, MP_PASSWORD_REQUEST_FOR_LOGGED_IN_NAME, true);
}
return;
@ -1095,8 +1095,8 @@ void server::process_login(const network::connection sock,
else if(!(user_handler_->login(username, password, seeds_[sock]))) {
// Reset the random seed
seeds_.erase(sock);
send_password_request(sock, ("The password you provided for the nick '" + username +
"' was incorrect.").c_str(), username, MP_INCORRECT_PASSWORD_ERROR);
send_password_request(sock, "The password you provided for the nick '" + username +
"' was incorrect.", username, MP_INCORRECT_PASSWORD_ERROR);
LOG_SERVER << network::ip_address(sock) << "\t"
<< "Login attempt with incorrect password for nick '" << username << "'.\n";
@ -1112,8 +1112,8 @@ void server::process_login(const network::connection sock,
// If we disallow unregistered users and this user is not registered send an error
if(user_handler_ && !registered && deny_unregistered_login_) {
send_error(sock, ("The nick '" + username + "' is not registered. "
"This server disallows unregistered nicks.").c_str(), MP_NAME_UNREGISTERED_ERROR);
send_error(sock, "The nick '" + username + "' is not registered. "
"This server disallows unregistered nicks.", MP_NAME_UNREGISTERED_ERROR);
return;
}
@ -1122,7 +1122,7 @@ void server::process_login(const network::connection sock,
// If there is already a client using this username kick it
process_command("kick " + p->second.name() + " autokick by registered user", username);
} else {
send_error(sock, ("The nick '" + username + "' is already taken.").c_str(), MP_NAME_TAKEN_ERROR);
send_error(sock, "The nick '" + username + "' is already taken.", MP_NAME_TAKEN_ERROR);
return;
}
}
@ -1158,7 +1158,7 @@ void server::process_login(const network::connection sock,
send_doc(games_and_users_list_, sock);
if (motd_ != "") {
rooms_.lobby().send_server_message(motd_.c_str(), sock);
rooms_.lobby().send_server_message(motd_, sock);
}
// Send other players in the lobby the update that the player has joined
@ -1172,7 +1172,7 @@ void server::process_login(const network::connection sock,
for (std::vector<wesnothd::game*>::const_iterator g = games_.begin(); g != games_.end(); ++g) {
// Note: This string is parsed by the client to identify lobby join messages!
(*g)->send_server_message_to_all((username + " has logged into the lobby").c_str());
(*g)->send_server_message_to_all(username + " has logged into the lobby");
}
if(user_handler_ && user_handler_->user_is_moderator(username)) {
@ -1266,7 +1266,7 @@ void server::process_query(const network::connection sock,
} else {
response << "Error: unrecognized query: '" << command << "'\n" << help_msg;
}
rooms_.lobby().send_server_message(response.str().c_str(), sock);
rooms_.lobby().send_server_message(response.str(), sock);
}
void server::start_new_server() {
@ -1504,9 +1504,9 @@ std::string server::process_command(std::string query, std::string issuer_name)
return;
}
rooms_.lobby().send_server_message_to_all(parameters.c_str());
rooms_.lobby().send_server_message_to_all(parameters);
for (std::vector<wesnothd::game*>::const_iterator g = games_.begin(); g != games_.end(); ++g) {
(*g)->send_server_message_to_all(parameters.c_str());
(*g)->send_server_message_to_all(parameters);
}
LOG_SERVER << "<server" << (parameters.find("/me ") == 0
@ -1524,7 +1524,7 @@ std::string server::process_command(std::string query, std::string issuer_name)
return;
}
rooms_.lobby().send_server_message_to_all(parameters.c_str());
rooms_.lobby().send_server_message_to_all(parameters);
LOG_SERVER << "<server" << (parameters.find("/me ") == 0
? std::string(parameters.begin() + 3, parameters.end()) + ">"
: "> " + parameters) << "\n";
@ -1720,7 +1720,7 @@ std::string server::process_command(std::string query, std::string issuer_name)
if (utils::wildcard_string_match(network::ip_address(pl->first), target)) {
*out << "\nKicked " << pl->second.name() << " ("
<< network::ip_address(pl->first) << ").";
send_error(pl->first, ("You have been banned. Reason: " + reason).c_str());
send_error(pl->first, "You have been banned. Reason: " + reason);
network::queue_disconnect(pl->first);
}
}
@ -1734,7 +1734,7 @@ std::string server::process_command(std::string query, std::string issuer_name)
const std::string ip = network::ip_address(pl->first);
*out << ban_manager_.ban(ip, parsed_time, reason, issuer_name, dummy_group, target);
*out << "\nKicked " << pl->second.name() << " (" << ip << ").";
send_error(pl->first, ("You have been banned. Reason: " + reason).c_str());
send_error(pl->first, "You have been banned. Reason: " + reason);
network::queue_disconnect(pl->first);
}
}
@ -1876,7 +1876,7 @@ std::string server::process_command(std::string query, std::string issuer_name)
*out << "Kicked " << pl->second.name() << " ("
<< network::ip_address(pl->first) << "). '"
<< kick_message << "'";
send_error(pl->first, kick_message.c_str());
send_error(pl->first, kick_message);
network::queue_disconnect(pl->first);
}
}
@ -1968,7 +1968,7 @@ void server::process_nickserv(const network::connection sock, simple_wml::node&
// Warn that providing an email address might be a good idea
((*data.child("register"))["mail"].empty() ?
" It is recommended that you provide an email address for password recovery." : "");
rooms_.lobby().send_server_message(msg.str().c_str(), sock);
rooms_.lobby().send_server_message(msg.str(), sock);
// Mark the player as registered and send the other clients
// an update to dislpay this change
@ -1980,8 +1980,8 @@ void server::process_nickserv(const network::connection sock, simple_wml::node&
rooms_.lobby().send_data(diff);
} catch (user_handler::error e) {
rooms_.lobby().send_server_message(("There was an error registering your username. The error message was: "
+ e.message).c_str(), sock);
rooms_.lobby().send_server_message("There was an error registering your username. The error message was: "
+ e.message, sock);
}
return;
}
@ -1989,8 +1989,7 @@ void server::process_nickserv(const network::connection sock, simple_wml::node&
// A user requested to update his password or mail
if(data.child("set")) {
if(!(user_handler_->user_exists(pl->second.name()))) {
rooms_.lobby().send_server_message("You are not registered. Please register first.",
sock);
rooms_.lobby().send_server_message("You are not registered. Please register first.", sock);
return;
}
@ -2002,8 +2001,8 @@ void server::process_nickserv(const network::connection sock, simple_wml::node&
rooms_.lobby().send_server_message("Your details have been updated.", sock);
} catch (user_handler::error e) {
rooms_.lobby().send_server_message(("There was an error updating your details. The error message was: "
+ e.message).c_str(), sock);
rooms_.lobby().send_server_message("There was an error updating your details. The error message was: "
+ e.message, sock);
}
return;
@ -2011,8 +2010,8 @@ void server::process_nickserv(const network::connection sock, simple_wml::node&
// A user requested information about another user
if(data.child("details")) {
rooms_.lobby().send_server_message(("Valid details for this server are: " +
user_handler_->get_valid_details()).c_str(), sock);
rooms_.lobby().send_server_message("Valid details for this server are: " +
user_handler_->get_valid_details(), sock);
return;
}
@ -2020,11 +2019,11 @@ void server::process_nickserv(const network::connection sock, simple_wml::node&
if(data.child("info")) {
try {
std::string res = user_handler_->user_info((*data.child("info"))["name"].to_string());
rooms_.lobby().send_server_message(res.c_str(), sock);
rooms_.lobby().send_server_message(res, sock);
} catch (user_handler::error e) {
rooms_.lobby().send_server_message(("There was an error looking up the details of the user '" +
rooms_.lobby().send_server_message("There was an error looking up the details of the user '" +
(*data.child("info"))["name"].to_string() + "'. " +" The error message was: "
+ e.message).c_str(), sock);
+ e.message, sock);
}
return;
}
@ -2032,8 +2031,7 @@ void server::process_nickserv(const network::connection sock, simple_wml::node&
// A user requested to delete his nick
if(data.child("drop")) {
if(!(user_handler_->user_exists(pl->second.name()))) {
rooms_.lobby().send_server_message("You are not registered.",
sock);
rooms_.lobby().send_server_message("You are not registered.", sock);
return;
}
@ -2041,8 +2039,7 @@ void server::process_nickserv(const network::connection sock, simple_wml::node&
// registerd username without the password we should never get
// to call this
if(!(pl->second.registered())) {
rooms_.lobby().send_server_message("You are not logged in.",
sock);
rooms_.lobby().send_server_message("You are not logged in.", sock);
return;
}
@ -2059,8 +2056,8 @@ void server::process_nickserv(const network::connection sock, simple_wml::node&
"user", pl->second.config_address(), diff);
rooms_.lobby().send_data(diff);
} catch (user_handler::error e) {
rooms_.lobby().send_server_message(("There was an error dropping your username. The error message was: "
+ e.message).c_str(), sock);
rooms_.lobby().send_server_message("There was an error dropping your username. The error message was: "
+ e.message, sock);
}
return;
}
@ -2306,7 +2303,7 @@ void server::process_data_game(const network::connection sock,
std::stringstream msg;
msg << "This server does not support games with more than "
<< gamemap::MAX_PLAYERS << " sides. Game aborted.";
rooms_.lobby().send_server_message(msg.str().c_str(), sock);
rooms_.lobby().send_server_message(msg.str(), sock);
return;
}
@ -2406,7 +2403,7 @@ void server::process_data_game(const network::connection sock,
std::stringstream msg;
msg << "This server does not support games with more than "
<< gamemap::MAX_PLAYERS << " sides.";
rooms_.lobby().send_server_message(msg.str().c_str(), sock);
rooms_.lobby().send_server_message(msg.str(), sock);
return;
}
// Record the full scenario in g->level()
@ -2574,7 +2571,7 @@ void server::process_data_game(const network::connection sock,
if ((*info)["type"] == "termination") {
g->set_termination_reason((*info)["condition"].to_string());
if ((*info)["condition"].to_string() == "out of sync") {
g->send_server_message_to_all((pl->second.name() + " reports out of sync errors.").c_str());
g->send_server_message_to_all(pl->second.name() + " reports out of sync errors.");
}
}
return;

View file

@ -21,12 +21,16 @@ public:
void run();
private:
void send_error(network::connection sock, const char* msg, const char* error_code ="") const;
void send_error(network::connection sock, const std::string &msg, const char* error_code = "") const
{
send_error(sock, msg.c_str(), error_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 char* msg,
void send_password_request(network::connection sock, const std::string& msg,
const std::string& user, const char* error_code ="",
bool force_confirmation =false);
bool force_confirmation = false);
const network::manager net_manager_;
network::server_manager server_;