implements a new command "mute" to mute observers

This commit is contained in:
Jörg Hinrichs 2006-05-04 23:54:29 +00:00
parent e4f226997d
commit 3c6eb8b3f1
6 changed files with 60 additions and 4 deletions

View File

@ -1425,10 +1425,18 @@ namespace events{
preferences::show_theme_dialog(*gui_);
} else if(cmd == "ban" || cmd == "kick") {
config cfg;
config& ban = cfg.add_child(cmd);
ban["username"] = data;
config& ban = cfg.add_child(cmd);
ban["username"] = data;
network::send_data(cfg);
network::send_data(cfg);
} else if (cmd == "mute") {
config cfg;
config& mute = cfg.add_child(cmd);
if (! (data == str.end())){
mute["username"] = data;
}
network::send_data(cfg);
} else if(cmd == "control") {
const std::string::const_iterator j = std::find(data.begin(),data.end(),' ');
if(j != data.end()) {

View File

@ -384,6 +384,16 @@ bool game::player_is_banned(network::connection sock) const
return false;
}
bool game::observer_is_muted(network::connection observer) const{
const player_map::const_iterator itor = player_info_->find(observer);
if(itor == player_info_->end()) {
return false;
}
const player& info = itor->second;
return info.is_muted();
}
void game::ban_player(network::connection sock)
{
const player_map::const_iterator itor = player_info_->find(sock);

View File

@ -61,6 +61,7 @@ public:
bool describe_slots();
bool player_is_banned(network::connection player) const;
bool observer_is_muted(network::connection observer) const;
void ban_player(network::connection player);
void add_player(network::connection player, bool observer = false);

View File

@ -15,7 +15,7 @@
#include "player.hpp"
player::player(const std::string& n, config& cfg,size_t max_messages,size_t time_period) : name_(n), cfg_(cfg), flood_start_(0), messages_since_flood_start_(0), MaxMessages(max_messages), TimePeriod(time_period)
player::player(const std::string& n, config& cfg,size_t max_messages,size_t time_period) : name_(n), cfg_(cfg), flood_start_(0), messages_since_flood_start_(0), MaxMessages(max_messages), TimePeriod(time_period), muted_(false)
{
cfg_["name"] = n;
mark_available(true,"");
@ -62,3 +62,11 @@ bool player::is_message_flooding()
return false;
}
bool player::is_muted() const{
return muted_;
}
void player::set_muted(bool muted){
muted_ = muted;
}

View File

@ -33,6 +33,8 @@ public:
bool silenced() const;
bool is_message_flooding();
bool is_muted() const;
void set_muted(bool muted);
private:
std::string name_;
@ -40,6 +42,7 @@ private:
time_t flood_start_;
int messages_since_flood_start_;
bool muted_;
size_t MaxMessages;
size_t TimePeriod;
};

View File

@ -837,6 +837,27 @@ void server::process_data_from_player_in_game(const network::connection sock, co
return;
}
//if an observer is muted
if(g->is_owner(sock) && (data.child("mute") != NULL)) {
const config& u = *data.child("mute");
std::string name = u["username"];
player_map::iterator pl;
for(pl = players_.begin(); pl != players_.end(); ++pl) {
if(pl->second.name() == name) {
break;
}
}
if(pl->first != sock && pl != players_.end() && g->is_observer(pl->first)) {
pl->second.set_muted(true);
const config& msg = construct_server_message("You have been muted",*g);
network::send_data(msg, pl->first);
const config& p_msg = construct_server_message(pl->second.name() + " has been muted",*g);
g->send_data(p_msg, pl->first);
}
}
//if the owner is banning someone from the game
if(g->is_owner(sock) && (data.child("ban") != NULL || data.child("kick") != NULL)) {
std::string name;
@ -1136,6 +1157,11 @@ void server::process_data_from_player_in_game(const network::connection sock, co
//spoofing of messages
const player_map::const_iterator pl = players_.find(sock);
wassert(pl != players_.end());
if (pl->second.is_muted()){
const config& msg = construct_server_message("You have been muted, others can't see your message!",*g);
network::send_data(msg, pl->first);
return;
}
(*speak)["description"] = pl->second.name();
if((*speak)["team_name"] == "") {