let the wesnoth server send the game id and not only the game name
if a player joins a game to avoid ambiguity
This commit is contained in:
parent
4ecc58a542
commit
3b5c2d8a45
7 changed files with 37 additions and 23 deletions
|
@ -650,7 +650,7 @@ void lobby::process_event()
|
|||
if (games_menu_.empty()) {
|
||||
set_selected_game("");
|
||||
} else {
|
||||
set_selected_game(games_menu_.selected_game().name);
|
||||
set_selected_game(games_menu_.selected_game().id);
|
||||
}
|
||||
ui::gamelist_updated();
|
||||
last_selected_game_ = selected_game;
|
||||
|
|
|
@ -647,14 +647,18 @@ void ui::gamelist_updated(bool silent)
|
|||
for (user = users.begin(); user != users.end(); ++user) {
|
||||
user_info u_elem;
|
||||
u_elem.name = (**user)["name"];
|
||||
u_elem.game_id = "";
|
||||
u_elem.location = "";
|
||||
u_elem.state = (**user)["available"] == "no" ? GAME : LOBBY;
|
||||
if(!(**user)["location"].empty()) {
|
||||
u_elem.location = (**user)["location"];
|
||||
if (u_elem.location == selected_game_) {
|
||||
if(!(**user)["game_id"].empty()) {
|
||||
u_elem.game_id = (**user)["game_id"];
|
||||
if (u_elem.game_id == selected_game_) {
|
||||
u_elem.state = SEL_GAME;
|
||||
}
|
||||
}
|
||||
if(!(**user)["location"].empty()) {
|
||||
u_elem.location = (**user)["location"];
|
||||
}
|
||||
if (u_elem.name == preferences::login()) {
|
||||
u_elem.relation = ME;
|
||||
} else if ((*cignore)[u_elem.name] == "ignored") {
|
||||
|
@ -708,13 +712,13 @@ void ui::gamelist_updated(bool silent)
|
|||
set_user_menu_items(menu_strings);
|
||||
}
|
||||
|
||||
void ui::set_selected_game(const std::string game_name)
|
||||
void ui::set_selected_game(const std::string game_id)
|
||||
{
|
||||
// reposition the player list to show the players in the selected game
|
||||
if (preferences::sort_list() && (selected_game_ != game_name)) {
|
||||
if (preferences::sort_list() && (selected_game_ != game_id)) {
|
||||
users_menu_.move_selection(0);
|
||||
}
|
||||
selected_game_ = game_name;
|
||||
selected_game_ = game_id;
|
||||
}
|
||||
|
||||
void ui::set_user_menu_items(const std::vector<std::string>& list)
|
||||
|
|
|
@ -209,6 +209,7 @@ private:
|
|||
struct user_info
|
||||
{
|
||||
std::string name;
|
||||
std::string game_id;
|
||||
std::string location;
|
||||
user_relation relation;
|
||||
user_state state;
|
||||
|
|
|
@ -19,13 +19,15 @@
|
|||
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)
|
||||
{
|
||||
cfg_["name"] = n;
|
||||
mark_available(true,"");
|
||||
mark_available();
|
||||
}
|
||||
|
||||
void player::mark_available(bool val,std::string location )
|
||||
// keep 'available' and game name ('location') for backward compatibility
|
||||
void player::mark_available(std::string game_id, std::string location)
|
||||
{
|
||||
cfg_.values["available"] = (val ? "yes" : "no");
|
||||
cfg_.values["location"] = location;
|
||||
cfg_.values["available"] = game_id.empty() ? "yes" : "no";
|
||||
cfg_.values["game_id"] = game_id;
|
||||
cfg_.values["location"] = location;
|
||||
}
|
||||
|
||||
const std::string& player::name() const
|
||||
|
|
|
@ -26,7 +26,8 @@ class player
|
|||
public:
|
||||
player(const std::string& n, config& cfg,size_t max_messages=4,size_t time_period=10);
|
||||
|
||||
void mark_available(bool val,std::string location);
|
||||
// mark a player as member of the game 'game_id' or as located in the lobby
|
||||
void mark_available(std::string game_id="", std::string location="");
|
||||
|
||||
const std::string& name() const;
|
||||
|
||||
|
|
|
@ -487,7 +487,7 @@ void server::run()
|
|||
//set the availability status for all quitting players
|
||||
for(player_map::iterator pl = players_.begin(); pl != players_.end(); ++pl) {
|
||||
if(i->is_member(pl->first)) {
|
||||
pl->second.mark_available(true,"");
|
||||
pl->second.mark_available();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -803,8 +803,8 @@ void server::process_data_from_player_in_lobby(const network::connection sock, c
|
|||
|
||||
// Mark the player as unavailable in the lobby
|
||||
if(pl != players_.end()) {
|
||||
pl->second.mark_available(false,games_.back().level()["name"]);
|
||||
|
||||
pl->second.mark_available(games_.back().level()["id"],
|
||||
games_.back().level()["name"]);
|
||||
lobby_players_.send_data(sync_initial_response());
|
||||
}
|
||||
|
||||
|
@ -845,7 +845,8 @@ void server::process_data_from_player_in_lobby(const network::connection sock, c
|
|||
// Mark the player as unavailable in the lobby
|
||||
const player_map::iterator pl = players_.find(sock);
|
||||
if(pl != players_.end()) {
|
||||
pl->second.mark_available(false,(*it->description())["name"]);
|
||||
pl->second.mark_available((*it->description())["id"],
|
||||
(*it->description())["name"]);
|
||||
|
||||
lobby_players_.send_data(sync_initial_response());
|
||||
} else {
|
||||
|
@ -1032,7 +1033,7 @@ void server::process_data_from_player_in_game(const network::connection sock, co
|
|||
lobby_players_.add_player(pl->first);
|
||||
|
||||
// Mark the player as available in the lobby
|
||||
pl->second.mark_available(true,"");
|
||||
pl->second.mark_available();
|
||||
|
||||
// Send the player who was banned the lobby game list
|
||||
network::send_data(initial_response_,pl->first);
|
||||
|
@ -1209,7 +1210,7 @@ void server::process_data_from_player_in_game(const network::connection sock, co
|
|||
// set the availability status for all quitting players
|
||||
for(player_map::iterator pl = players_.begin(); pl != players_.end(); ++pl) {
|
||||
if(g->is_member(pl->first)) {
|
||||
pl->second.mark_available(true,"");
|
||||
pl->second.mark_available();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1243,7 +1244,7 @@ void server::process_data_from_player_in_game(const network::connection sock, co
|
|||
// Mark the player as available in the lobby
|
||||
const player_map::iterator pl = players_.find(sock);
|
||||
if(pl != players_.end()) {
|
||||
pl->second.mark_available(true,"");
|
||||
pl->second.mark_available();
|
||||
} else {
|
||||
LOG_SERVER << "ERROR: Could not find player in map\n";
|
||||
}
|
||||
|
|
|
@ -256,14 +256,19 @@ while (1) {
|
|||
if ($_->{'name'} eq 'insert') {
|
||||
my $username = $users[$userindex]->{'attr'}->{'name'};
|
||||
if ($_->{'attr'}->{'available'} eq "yes") {
|
||||
my $game_id = $users[$userindex]->{'attr'}->{'game_id'};
|
||||
my $location = $users[$userindex]->{'attr'}->{'location'};
|
||||
print STDERR ×tamp . "++> $username has left a game: \"$location\"\n" if $showjoins and $showgames;
|
||||
print LOG &logtimestamp . "++> $username has left a game: \"$location\"\n" if $logfile;
|
||||
$users[$userindex]->{'attr'}->{'game_id'} = "";
|
||||
$users[$userindex]->{'attr'}->{'location'} = "";
|
||||
print STDERR ×tamp . "++> $username has left a game: \"$location\" ($game_id)\n" if $showjoins and $showgames;
|
||||
print LOG &logtimestamp . "++> $username has left a game: \"$location\" ($game_id)\n" if $logfile;
|
||||
} elsif ($_->{'attr'}->{'available'} eq "no") {
|
||||
my $game_id = $_->{'attr'}->{'game_id'};
|
||||
my $location = $_->{'attr'}->{'location'};
|
||||
$users[$userindex]->{'attr'}->{'game_id'} = $game_id;
|
||||
$users[$userindex]->{'attr'}->{'location'} = $location;
|
||||
print STDERR ×tamp . "<++ $username has joined a game: \"$location\"\n" if $showjoins and $showgames;
|
||||
print LOG &logtimestamp . "<++ $username has joined a game: \"$location\"\n" if $logfile;
|
||||
print STDERR ×tamp . "<++ $username has joined a game: \"$location\" ($game_id)\n" if $showjoins and $showgames;
|
||||
print LOG &logtimestamp . "<++ $username has joined a game: \"$location\" ($game_id)\n" if $logfile;
|
||||
}
|
||||
} elsif ($_->{'name'} eq 'delete') {
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue