Use the MP Moderators forum group to check for mod authority.
People who have MP mod authority for testing or other reasons can continue to use the existing user_is_moderator column check, but for people who are supposed to moderate the server, now the forum group will be used.
This will make it easier to add/remove people to/from the group, and also ensure that the list of actual moderators matches up with the list available to users.
New config attributes added for this are:
* db_group_table - should be, based on the phpbb documentation I found, phpbb_user_group
* mp_mod_group - should be set to Multiplayer Moderators group ID
Backport of 02ebcff06c
This commit is contained in:
parent
887bfe88aa
commit
afab04ddf4
4 changed files with 31 additions and 3 deletions
|
@ -247,6 +247,12 @@ section is present in the configuration the server will run without any nick reg
|
|||
.B db_game_modification_info_table
|
||||
(for user_handler=forum) The name of the table in which wesnothd will save its own data about the modifications used in a game.
|
||||
.TP
|
||||
.B db_group_table
|
||||
(for user_handler=forum) The name of the table in which your phpbb forums saves its user group data. Most likely this will be <table-prefix>_user_group (e.g. phpbb3_user_group).
|
||||
.TP
|
||||
.B mp_mod_group
|
||||
(for user_handler=forum) The ID of the forum group to be considered as having moderation authority.
|
||||
.TP
|
||||
.B user_expiration
|
||||
(for user_handler=sample) The time after which a registered nick expires (in days).
|
||||
.RE
|
||||
|
|
|
@ -45,6 +45,8 @@ fuh::fuh(const config& c)
|
|||
, db_game_info_table_(c["db_game_info_table"].str())
|
||||
, db_game_player_info_table_(c["db_game_player_info_table"].str())
|
||||
, db_game_modification_info_table_(c["db_game_modification_info_table"].str())
|
||||
, db_group_table_(c["db_group_table"].str())
|
||||
, mp_mod_group_(std::stoi(c["mp_mod_group"]))
|
||||
, conn(mysql_init(nullptr))
|
||||
{
|
||||
mysql_options(conn, MYSQL_SET_CHARSET_NAME, "utf8mb4");
|
||||
|
@ -157,9 +159,9 @@ bool fuh::user_is_moderator(const std::string& name) {
|
|||
if(!user_exists(name)) return false;
|
||||
|
||||
try {
|
||||
return get_writable_detail_for_user<int>(name, "user_is_moderator") == 1;
|
||||
return get_writable_detail_for_user<int>(name, "user_is_moderator") == 1 || is_user_in_group(name, mp_mod_group_);
|
||||
} catch (const sql_error& e) {
|
||||
ERR_UH << "Could not query user_is_moderator for user '" << name << "' :" << e.message << std::endl;
|
||||
ERR_UH << "Could not query user_is_moderator/MP Moderators group for user '" << name << "' :" << e.message << std::endl;
|
||||
// If the database is down mark nobody as a mod
|
||||
return false;
|
||||
}
|
||||
|
@ -407,6 +409,15 @@ void fuh::write_detail(const std::string& name, const std::string& detail, T&& v
|
|||
}
|
||||
}
|
||||
|
||||
bool fuh::is_user_in_group(const std::string& name, unsigned int group_id) {
|
||||
try {
|
||||
return prepared_statement<bool>("SELECT 1 FROM `" + db_users_table_ + "` u, `" + db_group_table_ + "` ug WHERE UPPER(u.username)=UPPER(?) AND u.USER_ID = ug.USER_ID AND ug.GROUP_ID = ?", name, group_id);
|
||||
} catch (const sql_error& e) {
|
||||
ERR_UH << "Could not execute test query for user group '" << group_id << "' and username '" << name << "'" << e.message << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool fuh::extra_row_exists(const std::string& name) {
|
||||
|
||||
// Make a test query for this username
|
||||
|
|
|
@ -105,7 +105,8 @@ class fuh : public user_handler {
|
|||
std::time_t retrieve_ban_duration_internal(const std::string& col, const std::string& detail);
|
||||
std::time_t retrieve_ban_duration_internal(const std::string& col, unsigned int detail);
|
||||
|
||||
std::string db_name_, db_host_, db_user_, db_password_, db_users_table_, db_banlist_table_, db_extra_table_, db_game_info_table_, db_game_player_info_table_, db_game_modification_info_table_;
|
||||
std::string db_name_, db_host_, db_user_, db_password_, db_users_table_, db_banlist_table_, db_extra_table_, db_game_info_table_, db_game_player_info_table_, db_game_modification_info_table_, db_group_table_;
|
||||
unsigned int mp_mod_group_;
|
||||
|
||||
MYSQL *conn;
|
||||
|
||||
|
@ -123,4 +124,6 @@ class fuh : public user_handler {
|
|||
|
||||
// Same as user_exists() but checks if we have a row for this user in the extra table
|
||||
bool extra_row_exists(const std::string& name);
|
||||
|
||||
bool is_user_in_group(const std::string& name, unsigned int group_id);
|
||||
};
|
||||
|
|
|
@ -10,6 +10,14 @@
|
|||
-- KEY user_type (user_type)
|
||||
-- ) ENGINE=InnoDB AUTO_INCREMENT=50 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||
|
||||
-- a minimal groups table, if not using a phpbb3 installation
|
||||
-- CREATE TABLE user_groups
|
||||
-- (
|
||||
-- group_id mediumint(8) unsigned NOT NULL,
|
||||
-- user_id mediumint(8) unsigned NOT NULL,
|
||||
-- PRIMARY KEY (user_id, group_id)
|
||||
-- ) ENGINE=InnoDB;
|
||||
|
||||
-- table which the forum inserts bans into, which wesnothd checks during login
|
||||
-- CREATE TABLE ban
|
||||
-- (
|
||||
|
|
Loading…
Add table
Reference in a new issue