mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-30 22:51:17 +00:00
removed the admins_ set and added a moderator property to player instead
disallowed banning or kicking of moderators
This commit is contained in:
parent
e1fd583ec6
commit
5d82a290a0
@ -639,10 +639,12 @@ network::connection game::kick_member(const simple_wml::node& kick,
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
if (user->first == kicker->first) {
|
||||
} else if (user->first == kicker->first) {
|
||||
send_server_message("Don't kick yourself, silly.", kicker->first);
|
||||
return 0;
|
||||
} else if (user->second.is_moderator()) {
|
||||
send_server_message("You're not allowed to kick a moderator.", kicker->first);
|
||||
return 0;
|
||||
}
|
||||
LOG_GAME << network::ip_address(kicker->first) << "\t"
|
||||
<< kicker->second.name() << "\tkicked: " << username << " ("
|
||||
@ -670,14 +672,15 @@ network::connection game::ban_user(const simple_wml::node& ban,
|
||||
if (user == player_info_->end()) {
|
||||
send_server_message(("User '" + username.to_string() + "' not found.").c_str(), banner->first);
|
||||
return 0;
|
||||
}
|
||||
if (user->first == banner->first) {
|
||||
} else if (user->first == banner->first) {
|
||||
send_server_message("Don't ban yourself, silly.", banner->first);
|
||||
return 0;
|
||||
}
|
||||
if (player_is_banned(user->first)) {
|
||||
} else if (player_is_banned(user->first)) {
|
||||
send_server_message(("'" + username.to_string() + "' is already banned.").c_str(), banner->first);
|
||||
return 0;
|
||||
} else if (user->second.is_moderator()) {
|
||||
send_server_message("You're not allowed to ban a moderator.", banner->first);
|
||||
return 0;
|
||||
}
|
||||
LOG_GAME << network::ip_address(banner->first) << "\t"
|
||||
<< banner->second.name() << "\tbanned: " << username << " ("
|
||||
@ -914,7 +917,7 @@ bool game::end_turn() {
|
||||
|
||||
//@todo differentiate between "observers not allowed" and "player already in the game" errors.
|
||||
// maybe return a string with an error message.
|
||||
bool game::add_player(const network::connection player, bool observer, bool admin) {
|
||||
bool game::add_player(const network::connection player, bool observer) {
|
||||
if(is_member(player)) {
|
||||
ERR_GAME << "ERROR: Player is already in this game. (socket: "
|
||||
<< player << ")\n";
|
||||
@ -933,7 +936,7 @@ bool game::add_player(const network::connection player, bool observer, bool admi
|
||||
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);
|
||||
} else if (!allow_observers() && !admin) {
|
||||
} else if (!allow_observers() && !user->second.is_moderator()) {
|
||||
return false;
|
||||
} else {
|
||||
if (!observer) became_observer = true;
|
||||
|
@ -93,7 +93,7 @@ public:
|
||||
*
|
||||
* @return True iff the user successfully joined the game.
|
||||
*/
|
||||
bool add_player(const network::connection player, bool observer = false, bool admin = false);
|
||||
bool add_player(const network::connection player, bool observer = false);
|
||||
|
||||
/**
|
||||
* Removes a user from the game.
|
||||
|
@ -18,7 +18,8 @@
|
||||
|
||||
wesnothd::player::player(const std::string& n, simple_wml::node& cfg,
|
||||
bool registered, const size_t max_messages,
|
||||
const size_t time_period, const bool sp)
|
||||
const size_t time_period, const bool sp,
|
||||
const bool moderator)
|
||||
: name_(n)
|
||||
, cfg_(cfg)
|
||||
, selective_ping_(sp)
|
||||
@ -28,12 +29,14 @@ wesnothd::player::player(const std::string& n, simple_wml::node& cfg,
|
||||
, MaxMessages(max_messages)
|
||||
, TimePeriod(time_period)
|
||||
, status_(LOBBY)
|
||||
, moderator_(moderator)
|
||||
{
|
||||
cfg_.set_attr_dup("name", n.c_str());
|
||||
mark_available();
|
||||
mark_registered(registered);
|
||||
}
|
||||
|
||||
|
||||
void wesnothd::player::set_status(wesnothd::player::STATUS status)
|
||||
{
|
||||
status_ = status;
|
||||
|
@ -36,7 +36,9 @@ public:
|
||||
OBSERVING
|
||||
};
|
||||
|
||||
player(const std::string& n, simple_wml::node& cfg, bool registered, const size_t max_messages=4, const size_t time_period=10, const bool sp=false);
|
||||
player(const std::string& n, simple_wml::node& cfg, bool registered,
|
||||
const size_t max_messages=4, const size_t time_period=10,
|
||||
const bool sp=false, const bool moderator=false);
|
||||
|
||||
void set_status(STATUS status);
|
||||
|
||||
@ -69,6 +71,9 @@ public:
|
||||
|
||||
void set_game(game* g);
|
||||
|
||||
void set_moderator(bool moderator) { moderator_ = moderator; }
|
||||
bool is_moderator() const { return moderator_; }
|
||||
|
||||
private:
|
||||
const std::string name_;
|
||||
simple_wml::node& cfg_;
|
||||
@ -81,6 +86,7 @@ private:
|
||||
const size_t MaxMessages;
|
||||
const time_t TimePeriod;
|
||||
STATUS status_;
|
||||
bool moderator_;
|
||||
};
|
||||
|
||||
} //namespace wesnothd
|
||||
|
@ -37,8 +37,8 @@ namespace wesnothd {
|
||||
|
||||
const char* const room_manager::lobby_name_ = "lobby";
|
||||
|
||||
room_manager::room_manager(player_map &all_players, const std::set<network::connection>& admins)
|
||||
: all_players_(all_players), admins_(admins), lobby_(NULL), filename_(),
|
||||
room_manager::room_manager(player_map &all_players)
|
||||
: all_players_(all_players), lobby_(NULL), filename_(),
|
||||
compress_stored_rooms_(true), new_room_policy_(PP_EVERYONE), dirty_(false)
|
||||
{
|
||||
}
|
||||
@ -187,7 +187,12 @@ room* room_manager::get_create_room(const std::string &name, network::connection
|
||||
}
|
||||
break;
|
||||
case PP_ADMINS:
|
||||
can_create = admins_.find(player) != admins_.end();
|
||||
{
|
||||
player_map::iterator i = all_players_.find(player);
|
||||
if (i != all_players_.end()) {
|
||||
can_create = i->second.is_moderator();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -485,8 +490,8 @@ void room_manager::process_room_query(simple_wml::document& data, const player_m
|
||||
}
|
||||
q = msg->child("persist");
|
||||
if (q != NULL) {
|
||||
if (admins_.find(user->first) == admins_.end()) {
|
||||
WRN_LOBBY << "Attempted room set persistent by non-admin";
|
||||
if (user->second.is_moderator()) {
|
||||
WRN_LOBBY << "Attempted room set persistent by non-moderator";
|
||||
} else {
|
||||
if (q->attr("value").empty()) {
|
||||
if (r->persistent()) {
|
||||
@ -509,8 +514,8 @@ void room_manager::process_room_query(simple_wml::document& data, const player_m
|
||||
}
|
||||
q = msg->child("logged");
|
||||
if (q != NULL) {
|
||||
if (admins_.find(user->first) == admins_.end()) {
|
||||
WRN_LOBBY << "Attempted room set logged by non-admin";
|
||||
if (user->second.is_moderator()) {
|
||||
WRN_LOBBY << "Attempted room set logged by non-moderator.";
|
||||
} else {
|
||||
if (q->attr("value").empty()) {
|
||||
if (r->persistent()) {
|
||||
@ -537,8 +542,8 @@ void room_manager::process_room_query(simple_wml::document& data, const player_m
|
||||
resp.set_attr_dup("topic", r->topic().c_str());
|
||||
send_to_one(doc, user->first);
|
||||
} else {
|
||||
if (admins_.find(user->first) == admins_.end()) {
|
||||
WRN_LOBBY << "Attempted room set topic by non-admin";
|
||||
if (user->second.is_moderator()) {
|
||||
WRN_LOBBY << "Attempted room set topic by non-moderator.";
|
||||
} else {
|
||||
r->set_topic(q->attr("value").to_string());
|
||||
resp.set_attr("message", "Room topic changed.");
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
/**
|
||||
* Room manager constructor
|
||||
*/
|
||||
room_manager(player_map& all_players, const std::set<network::connection>& admins);
|
||||
room_manager(player_map& all_players);
|
||||
|
||||
/**
|
||||
* Room manager destructor
|
||||
@ -221,9 +221,6 @@ private:
|
||||
/** Reference to the all players map */
|
||||
player_map& all_players_;
|
||||
|
||||
/** Reference to the set of admins */
|
||||
const std::set<network::connection>& admins_;
|
||||
|
||||
/** The lobby-room, treated separetely */
|
||||
room* lobby_;
|
||||
|
||||
|
@ -299,7 +299,7 @@ server::server(int port, const std::string& config_file, size_t min_threads,
|
||||
ghost_players_(),
|
||||
games_(),
|
||||
not_logged_in_(),
|
||||
rooms_(players_, admins_),
|
||||
rooms_(players_),
|
||||
input_(),
|
||||
config_file_(config_file),
|
||||
cfg_(read_config()),
|
||||
@ -308,7 +308,6 @@ server::server(int port, const std::string& config_file, size_t min_threads,
|
||||
proxy_versions_(),
|
||||
disallowed_names_(),
|
||||
admin_passwd_(),
|
||||
admins_(),
|
||||
motd_(),
|
||||
default_max_messages_(0),
|
||||
default_time_period_(0),
|
||||
@ -743,7 +742,6 @@ void server::run() {
|
||||
continue;
|
||||
}
|
||||
DBG_SERVER << "socket closed: " << e.message << "\n";
|
||||
admins_.erase(e.socket);
|
||||
const std::string ip = network::ip_address(e.socket);
|
||||
if (proxy::is_proxy(e.socket)) {
|
||||
LOG_SERVER << ip << "\tProxy user disconnected.\n";
|
||||
@ -1078,7 +1076,8 @@ void server::process_login(const network::connection sock,
|
||||
|
||||
simple_wml::node& player_cfg = games_and_users_list_.root().add_child("user");
|
||||
const wesnothd::player new_player(username, player_cfg, registered,
|
||||
default_max_messages_, default_time_period_, selective_ping);
|
||||
default_max_messages_, default_time_period_, selective_ping,
|
||||
user_handler_ && user_handler_->user_is_moderator(username));
|
||||
|
||||
// If the new player does not have selective ping enabled, immediately
|
||||
// add the player to the ghost player's list. This ensures a client won't
|
||||
@ -1115,7 +1114,6 @@ void server::process_login(const network::connection sock,
|
||||
LOG_SERVER << "Admin automatically recognized: IP: "
|
||||
<< network::ip_address(sock) << "\tnick: "
|
||||
<< username << std::endl;
|
||||
admins_.insert(sock);
|
||||
// This string is parsed by the client!
|
||||
rooms_.lobby().send_server_message("You are now recognized as an administrator. "
|
||||
"If you no longer want to be automatically authenticated use '/query signout'.", sock);
|
||||
@ -1129,7 +1127,7 @@ void server::process_login(const network::connection sock,
|
||||
|
||||
void server::process_query(const network::connection sock,
|
||||
simple_wml::node& query) {
|
||||
const wesnothd::player_map::const_iterator pl = players_.find(sock);
|
||||
const wesnothd::player_map::iterator pl = players_.find(sock);
|
||||
if (pl == players_.end()) {
|
||||
DBG_SERVER << "ERROR: process_query(): Could not find player with socket: " << sock << "\n";
|
||||
return;
|
||||
@ -1153,12 +1151,12 @@ void server::process_query(const network::connection sock,
|
||||
|| command == "wml")
|
||||
{
|
||||
response << process_command(command.to_string(), pl->second.name());
|
||||
} else if (admins_.find(sock) != admins_.end()) {
|
||||
} else if (pl->second.is_moderator()) {
|
||||
if (command == "signout") {
|
||||
LOG_SERVER << "Admin signed out: IP: "
|
||||
<< network::ip_address(sock) << "\tnick: "
|
||||
<< pl->second.name() << std::endl;
|
||||
admins_.erase(sock);
|
||||
pl->second.set_moderator(false);
|
||||
// This string is parsed by the client!
|
||||
response << "You are no longer recognized as an administrator.";
|
||||
if(user_handler_) {
|
||||
@ -1178,7 +1176,7 @@ void server::process_query(const network::connection sock,
|
||||
LOG_SERVER << "New Admin recognized: IP: "
|
||||
<< network::ip_address(sock) << "\tnick: "
|
||||
<< pl->second.name() << std::endl;
|
||||
admins_.insert(sock);
|
||||
pl->second.set_moderator(true);
|
||||
// This string is parsed by the client!
|
||||
response << "You are now recognized as an administrator.";
|
||||
if (user_handler_) {
|
||||
@ -1308,16 +1306,20 @@ std::string server::process_command(std::string query, std::string issuer_name)
|
||||
LOG_SERVER << "Admin message: <" << sender << (message.find("/me ") == 0
|
||||
? std::string(message.begin() + 3, message.end()) + ">"
|
||||
: "> " + message) << "\n";
|
||||
if (admins_.size() < 1) return "Sorry, no admin available right now. But your message got logged.";
|
||||
|
||||
simple_wml::document data;
|
||||
simple_wml::node& msg = data.root().add_child("whisper");
|
||||
msg.set_attr_dup("sender", ("admin message from " + sender).c_str());
|
||||
msg.set_attr_dup("message", message.c_str());
|
||||
for (std::set<network::connection>::const_iterator i = admins_.begin(); i != admins_.end(); ++i) {
|
||||
send_doc(data, *i);
|
||||
int n = 0;
|
||||
for (wesnothd::player_map::const_iterator pl = players_.begin(); pl != players_.end(); ++pl) {
|
||||
if (pl->second.is_moderator()) {
|
||||
++n;
|
||||
send_doc(data, pl->first);
|
||||
}
|
||||
}
|
||||
out << "Message sent to " << admins_.size() << " admins.";
|
||||
if (n == 0) return "Sorry, no admin available right now. But your message got logged.";
|
||||
out << "Message sent to " << n << " admins.";
|
||||
} else if (command == "msg" || command == "lobbymsg") {
|
||||
if (parameters == "") {
|
||||
return "You must type a message.";
|
||||
@ -1815,7 +1817,6 @@ void server::process_data_lobby(const network::connection sock,
|
||||
const std::vector<wesnothd::game*>::iterator g =
|
||||
std::find_if(games_.begin(),games_.end(), wesnothd::game_id_matches(game_id));
|
||||
|
||||
bool admin = (admins_.find(sock) != admins_.end());
|
||||
static simple_wml::document leave_game_doc("[leave_game]\n[/leave_game]\n", simple_wml::INIT_COMPRESSED);
|
||||
if (g == games_.end()) {
|
||||
WRN_SERVER << network::ip_address(sock) << "\t" << pl->second.name()
|
||||
@ -1832,7 +1833,7 @@ void server::process_data_lobby(const network::connection sock,
|
||||
rooms_.lobby().send_server_message("Attempt to join an uninitialized game.", sock);
|
||||
send_doc(games_and_users_list_, sock);
|
||||
return;
|
||||
} else if (admin) {
|
||||
} else if (pl->second.is_moderator()) {
|
||||
// Admins are always allowed to join.
|
||||
} else if ((*g)->player_is_banned(sock)) {
|
||||
DBG_SERVER << network::ip_address(sock) << "\tReject banned player: "
|
||||
@ -1863,7 +1864,7 @@ void server::process_data_lobby(const network::connection sock,
|
||||
<< "Removing him from that game to fix the inconsistency...\n";
|
||||
(*g2)->remove_player(sock);
|
||||
}
|
||||
bool joined = (*g)->add_player(sock, observer, admin);
|
||||
bool joined = (*g)->add_player(sock, observer);
|
||||
if (!joined) {
|
||||
WRN_SERVER << network::ip_address(sock) << "\t" << pl->second.name()
|
||||
<< "\tattempted to observe game:\t\"" << (*g)->name() << "\" ("
|
||||
|
Loading…
x
Reference in New Issue
Block a user