Patch #505 from Tomsik :
added whisper support for lobby and observers in game
This commit is contained in:
parent
2b55a11760
commit
af0becbd8a
5 changed files with 105 additions and 27 deletions
|
@ -43,6 +43,7 @@ SVN trunk (1.1.1+svn):
|
|||
* really fix bug 3388, now really centering on image when clicking it
|
||||
* tab completion now completes to smallest substring, and show possoble
|
||||
completions
|
||||
* added whisper support for lobby and observers in game
|
||||
|
||||
Version 1.1.1:
|
||||
* campaigns
|
||||
|
|
|
@ -463,6 +463,7 @@ text = "
|
|||
Frédéric Wagner
|
||||
Jeff Breidenbach (jab)
|
||||
Laurent Birtz
|
||||
Tomasz Sikorski (Tomsik)
|
||||
"
|
||||
[/about]
|
||||
|
||||
|
|
|
@ -267,13 +267,35 @@ void ui::handle_key_event(const SDL_KeyboardEvent& event)
|
|||
//if the text starts with '/query' it's a query to the server.
|
||||
//otherwise it's just a chat message
|
||||
static const std::string query = "/query ";
|
||||
|
||||
static const std::string whisper = "/msg ";
|
||||
|
||||
config data;
|
||||
|
||||
if(text.size() >= query.size() && std::equal(query.begin(),query.end(),text.begin())) {
|
||||
const std::string args = text.substr(query.size());
|
||||
|
||||
data.add_child("query")["type"] = args;
|
||||
|
||||
} else if (text.size() >= whisper.size() && std::equal(whisper.begin(),whisper.end(),text.begin())) {
|
||||
|
||||
int pos;
|
||||
pos = text.find(" ",whisper.size());
|
||||
|
||||
const std::string message = text.substr((pos+1),text.size());
|
||||
|
||||
const std::string receiver = text.substr(whisper.size(),
|
||||
(text.size()-message.size()-whisper.size()-1));
|
||||
|
||||
config cwhisper;
|
||||
cwhisper["message"] = message;
|
||||
cwhisper["sender"] = preferences::login();
|
||||
cwhisper["receiver"] = receiver;
|
||||
data.add_child("whisper", cwhisper);
|
||||
|
||||
chat_.add_message(("whisper to "+cwhisper["receiver"]),
|
||||
(entry_textbox_.text().substr(whisper.size()+receiver.size()+1)));
|
||||
|
||||
chat_.update_textbox(chat_textbox_);
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -310,40 +332,21 @@ void ui::handle_key_event(const SDL_KeyboardEvent& event)
|
|||
semiword.assign(text,last_space+1,text.size());
|
||||
}
|
||||
|
||||
std::string guess;
|
||||
|
||||
std::vector<std::string>& users = user_list_;
|
||||
std::vector<std::string> matches;
|
||||
std::sort<std::vector<std::string>::iterator>(users.begin(), users.end());
|
||||
std::string best_match = semiword;
|
||||
for(std::vector<std::string>::iterator i = users.begin(); i != users.end(); ++i) {
|
||||
for(std::vector<std::string>::const_iterator i = users.begin(); i != users.end(); ++i) {
|
||||
if( i->size() >= semiword.size() &&
|
||||
std::equal(semiword.begin(),semiword.end(),i->begin(),chars_equal_insensitive)) {
|
||||
if(matches.empty()) {
|
||||
best_match = *i;
|
||||
} else {
|
||||
int j=0;
|
||||
while(best_match[j] == (*i)[j]) j++;
|
||||
best_match.erase(best_match.begin()+j,best_match.end());
|
||||
}
|
||||
matches.push_back(*i);
|
||||
guess = *i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!matches.empty()) {
|
||||
if(guess.empty() == false) {
|
||||
std::string add = beginning ? ": " : " ";
|
||||
text.replace(last_space+1, semiword.size(), best_match);
|
||||
if(matches.size() == 1) {
|
||||
text.append(add);
|
||||
} else {
|
||||
std::string completion_list;
|
||||
std::vector<std::string>::iterator it;
|
||||
for(it =matches.begin();it!=matches.end();it++) {
|
||||
completion_list += " ";
|
||||
completion_list += *it;
|
||||
}
|
||||
chat_.add_message("",completion_list);
|
||||
chat_.update_textbox(chat_textbox_);
|
||||
}
|
||||
text.replace(last_space+1, semiword.size(), guess + add);
|
||||
entry_textbox_.set_text(text);
|
||||
}
|
||||
}
|
||||
|
@ -361,6 +364,14 @@ void ui::process_network_data(const config& data, const network::connection /*so
|
|||
chat_.add_message(msg["sender"], msg["message"]);
|
||||
chat_.update_textbox(chat_textbox_);
|
||||
}
|
||||
|
||||
if(data.child("whisper")){
|
||||
sound::play_sound(game_config::sounds::receive_message);
|
||||
|
||||
const config& cwhisper = *data.child("whisper");
|
||||
chat_.add_message("whisper: "+cwhisper["sender"], cwhisper["message"]);
|
||||
chat_.update_textbox(chat_textbox_);
|
||||
}
|
||||
|
||||
if(data.child("gamelist")) {
|
||||
if(!gamelist_initialized_)
|
||||
|
@ -449,4 +460,3 @@ const gui::widget& ui::title() const
|
|||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2219,6 +2219,27 @@ void turn_info::do_speak(const std::string& message, bool allies_only)
|
|||
return;
|
||||
}
|
||||
|
||||
static const std::string whisper = "/msg ";
|
||||
if (is_observer() && message.size() >= whisper.size() &&
|
||||
std::equal(whisper.begin(),whisper.end(),message.begin())) {
|
||||
|
||||
int pos;
|
||||
pos = message.find(" ",whisper.size());
|
||||
|
||||
const std::string text = message.substr((pos+1),message.size());
|
||||
|
||||
const std::string receiver = message.substr(whisper.size(),
|
||||
(message.size()-text.size()-whisper.size()-1));
|
||||
|
||||
config cwhisper,data;
|
||||
cwhisper["message"] = text;
|
||||
cwhisper["sender"] = preferences::login();
|
||||
cwhisper["receiver"] = receiver;
|
||||
data.add_child("whisper", cwhisper);
|
||||
gui_.add_chat_message("whisper to "+cwhisper["receiver"],0,cwhisper["message"], display::MESSAGE_PRIVATE);
|
||||
network::send_data(data);
|
||||
} else {
|
||||
|
||||
config cfg;
|
||||
cfg["description"] = preferences::login();
|
||||
cfg["message"] = message;
|
||||
|
@ -2237,6 +2258,7 @@ void turn_info::do_speak(const std::string& message, bool allies_only)
|
|||
recorder.speak(cfg);
|
||||
gui_.add_chat_message(cfg["description"],side,message,
|
||||
private_message ? display::MESSAGE_PRIVATE : display::MESSAGE_PUBLIC);
|
||||
}
|
||||
}
|
||||
|
||||
void turn_info::create_unit()
|
||||
|
@ -2788,6 +2810,12 @@ void turn_info::continue_move()
|
|||
|
||||
turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg, network::connection from, std::deque<config>& backlog)
|
||||
{
|
||||
if(cfg.child("whisper") != NULL && is_observer()){
|
||||
sound::play_sound(game_config::sounds::receive_message);
|
||||
|
||||
const config& cwhisper = *cfg.child("whisper");
|
||||
gui_.add_chat_message("whisper: "+cwhisper["sender"],0,cwhisper["message"], display::MESSAGE_PRIVATE);
|
||||
}
|
||||
if(cfg.child("observer") != NULL) {
|
||||
const config::child_list& observers = cfg.get_children("observer");
|
||||
for(config::child_list::const_iterator ob = observers.begin(); ob != observers.end(); ++ob) {
|
||||
|
|
|
@ -93,6 +93,7 @@ private:
|
|||
|
||||
void process_login(network::connection sock, const config& data, config& gamelist);
|
||||
void process_query(network::connection sock, const config& query, config& gamelist);
|
||||
void process_whisper(const network::connection sock, const config& whisper);
|
||||
void process_data_from_player_in_lobby(network::connection sock, config& data, config& gamelist);
|
||||
void process_data_from_player_in_game(network::connection sock, config& data, config& gamelist);
|
||||
|
||||
|
@ -483,6 +484,8 @@ void server::process_data(const network::connection sock, config& data, config&
|
|||
process_login(sock,data,gamelist);
|
||||
} else if(const config* query = data.child("query")) {
|
||||
process_query(sock,*query,gamelist);
|
||||
} else if(const config* whisper = data.child("whisper")) {
|
||||
process_whisper(sock,*whisper);
|
||||
} else if(lobby_players_.is_member(sock)) {
|
||||
process_data_from_player_in_lobby(sock,data,gamelist);
|
||||
} else {
|
||||
|
@ -490,6 +493,7 @@ void server::process_data(const network::connection sock, config& data, config&
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void server::process_login(const network::connection sock, const config& data, config& gamelist)
|
||||
{
|
||||
//see if client is sending their version number
|
||||
|
@ -649,6 +653,40 @@ void server::process_query(const network::connection sock, const config& query,
|
|||
network::send_data(construct_server_message(response.str(),lobby_players_),sock);
|
||||
}
|
||||
|
||||
void server::process_whisper(const network::connection sock, const config& whisper)
|
||||
{
|
||||
bool sent = false;
|
||||
if ((whisper["receiver"]!="") && (whisper["message"]!="") && (whisper["sender"]!="")){
|
||||
for(player_map::const_iterator i = players_.begin(); i != players_.end(); ++i) {
|
||||
if(i->second.name() == whisper["receiver"])
|
||||
{
|
||||
config cwhisper;
|
||||
cwhisper.add_child("whisper",whisper);
|
||||
network::send_data(cwhisper,i->first);
|
||||
sent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
config msg;
|
||||
config data;
|
||||
msg["message"] = "Invalid number of arguments";
|
||||
msg["sender"] = "server";
|
||||
data.add_child("message", msg);
|
||||
network::send_data(data,sock);
|
||||
sent = true;
|
||||
}
|
||||
|
||||
if (sent == false){
|
||||
config msg;
|
||||
config data;
|
||||
msg["message"] = "Can't find player "+whisper["receiver"];
|
||||
msg["sender"] = "server";
|
||||
data.add_child("message", msg);
|
||||
network::send_data(data,sock);
|
||||
}
|
||||
}
|
||||
|
||||
void server::process_data_from_player_in_lobby(const network::connection sock, config& data, config& gamelist)
|
||||
{
|
||||
const config* const create_game = data.child("create_game");
|
||||
|
|
Loading…
Add table
Reference in a new issue