move src/lobby_data.?pp to src/gui/dialogs/lobby/ and split...
...lobby_info to a separate c/hpp
This commit is contained in:
parent
810ad660d9
commit
776f27f5ca
11 changed files with 528 additions and 452 deletions
|
@ -473,10 +473,6 @@
|
|||
RelativePath="..\..\src\loadscreen.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\lobby_data.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\lobby_preferences.cpp"
|
||||
>
|
||||
|
@ -2383,6 +2379,18 @@
|
|||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<Filter
|
||||
Name="Lobby"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\src\gui\dialogs\lobby\lobby_data.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\gui\dialogs\lobby\lobby_info.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Auxiliary"
|
||||
|
@ -5360,10 +5368,6 @@
|
|||
RelativePath="..\..\src\loadscreen.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\lobby_data.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\lobby_preferences.hpp"
|
||||
>
|
||||
|
@ -5866,6 +5870,18 @@
|
|||
RelativePath="..\..\src\gui\dialogs\wml_message.hpp"
|
||||
>
|
||||
</File>
|
||||
<Filter
|
||||
Name="Lobby"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\src\gui\dialogs\lobby\lobby_data.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\gui\dialogs\lobby\lobby_info.hpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Widgets"
|
||||
|
|
|
@ -285,6 +285,8 @@ set(wesnoth-main_SRC
|
|||
gui/dialogs/game_save.cpp
|
||||
gui/dialogs/gamestate_inspector.cpp
|
||||
gui/dialogs/language_selection.cpp
|
||||
gui/dialogs/lobby/lobby_data.cpp
|
||||
gui/dialogs/lobby/lobby_info.cpp
|
||||
gui/dialogs/lobby_main.cpp
|
||||
gui/dialogs/lobby_player_info.cpp
|
||||
gui/dialogs/message.cpp
|
||||
|
@ -439,7 +441,6 @@ SET(libwesnoth-game_STAT_SRC
|
|||
key.cpp
|
||||
language.cpp
|
||||
loadscreen.cpp
|
||||
lobby_data.cpp
|
||||
lobby_preferences.cpp
|
||||
map_create.cpp
|
||||
map_label.cpp
|
||||
|
|
|
@ -165,6 +165,8 @@ wesnoth_source = \
|
|||
gui/dialogs/game_save.cpp \
|
||||
gui/dialogs/gamestate_inspector.cpp \
|
||||
gui/dialogs/language_selection.cpp \
|
||||
gui/dialogs/lobby/lobby_data.cpp \
|
||||
gui/dialogs/lobby/lobby_info.cpp \
|
||||
gui/dialogs/lobby_main.cpp \
|
||||
gui/dialogs/lobby_player_info.cpp \
|
||||
gui/dialogs/message.cpp \
|
||||
|
@ -214,7 +216,6 @@ wesnoth_source = \
|
|||
halo.cpp \
|
||||
help.cpp \
|
||||
intro.cpp \
|
||||
lobby_data.cpp \
|
||||
lobby_preferences.cpp \
|
||||
leader_list.cpp \
|
||||
menu_events.cpp \
|
||||
|
|
|
@ -208,7 +208,6 @@ wesnoth_sources = Split("""
|
|||
help.cpp
|
||||
intro.cpp
|
||||
leader_list.cpp
|
||||
lobby_data.cpp
|
||||
lobby_preferences.cpp
|
||||
menu_events.cpp
|
||||
mouse_events.cpp
|
||||
|
@ -326,6 +325,8 @@ wesnoth_sources = Split("""
|
|||
gui/dialogs/game_save.cpp
|
||||
gui/dialogs/gamestate_inspector.cpp
|
||||
gui/dialogs/language_selection.cpp
|
||||
gui/dialogs/lobby/lobby_data.cpp
|
||||
gui/dialogs/lobby/lobby_info.cpp
|
||||
gui/dialogs/lobby_main.cpp
|
||||
gui/dialogs/lobby_player_info.cpp
|
||||
gui/dialogs/message.cpp
|
||||
|
|
412
src/gui/dialogs/lobby/lobby_data.cpp
Normal file
412
src/gui/dialogs/lobby/lobby_data.cpp
Normal file
|
@ -0,0 +1,412 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2009 - 2010 by Tomasz Sniatowski <kailoran@gmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "lobby_data.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "foreach.hpp"
|
||||
#include "formula_string_utils.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "network.hpp"
|
||||
#include "log.hpp"
|
||||
#include "map.hpp"
|
||||
#include "map_exception.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
static lg::log_domain log_config("config");
|
||||
#define ERR_CF LOG_STREAM(err, log_config)
|
||||
static lg::log_domain log_engine("engine");
|
||||
#define WRN_NG LOG_STREAM(warn, log_engine)
|
||||
|
||||
static lg::log_domain log_lobby("lobby");
|
||||
#define DBG_LB LOG_STREAM(info, log_lobby)
|
||||
#define LOG_LB LOG_STREAM(info, log_lobby)
|
||||
#define ERR_LB LOG_STREAM(err, log_lobby)
|
||||
|
||||
chat_message::chat_message(const time_t& timestamp, const std::string& user, const std::string& message)
|
||||
: timestamp(timestamp), user(user), message(message)
|
||||
{
|
||||
}
|
||||
|
||||
chat_log::chat_log()
|
||||
: history_()
|
||||
{
|
||||
}
|
||||
|
||||
void chat_log::add_message(const time_t& timestamp, const std::string& user, const std::string& message)
|
||||
{
|
||||
history_.push_back(chat_message(timestamp, user, message));
|
||||
}
|
||||
|
||||
|
||||
void chat_log::add_message(const std::string& user, const std::string& message) {
|
||||
add_message(time(NULL), user, message);
|
||||
}
|
||||
|
||||
void chat_log::clear()
|
||||
{
|
||||
history_.clear();
|
||||
}
|
||||
|
||||
room_info::room_info(const std::string& name)
|
||||
: name_(name)
|
||||
, members_()
|
||||
, log_()
|
||||
{
|
||||
}
|
||||
|
||||
bool room_info::is_member(const std::string& user) const
|
||||
{
|
||||
return members_.find(user) != members_.end();
|
||||
}
|
||||
|
||||
void room_info::add_member(const std::string& user)
|
||||
{
|
||||
members_.insert(user);
|
||||
}
|
||||
|
||||
void room_info::remove_member(const std::string& user)
|
||||
{
|
||||
members_.erase(user);
|
||||
}
|
||||
|
||||
void room_info::process_room_members(const config& data)
|
||||
{
|
||||
members_.clear();
|
||||
foreach (const config& m, data.child_range("member")) {
|
||||
members_.insert(m["name"]);
|
||||
}
|
||||
}
|
||||
|
||||
user_info::user_info(const config& c)
|
||||
: name(c["name"])
|
||||
, game_id(lexical_cast_default<int>(c["game_id"]))
|
||||
, relation(ME)
|
||||
, state(game_id == 0 ? LOBBY : GAME)
|
||||
, registered(utils::string_bool(c["registered"]))
|
||||
, observing(c["status"] == "observing")
|
||||
{
|
||||
update_relation();
|
||||
}
|
||||
|
||||
void user_info::update_state(int selected_game_id, const room_info* current_room /*= NULL*/)
|
||||
{
|
||||
if (game_id != 0) {
|
||||
if (game_id == selected_game_id) {
|
||||
state = SEL_GAME;
|
||||
} else {
|
||||
state = GAME;
|
||||
}
|
||||
} else {
|
||||
if (current_room != NULL && current_room->is_member(name)) {
|
||||
state = SEL_ROOM;
|
||||
} else {
|
||||
state = LOBBY;
|
||||
}
|
||||
}
|
||||
update_relation();
|
||||
}
|
||||
|
||||
void user_info::update_relation()
|
||||
{
|
||||
if (name == preferences::login()) {
|
||||
relation = ME;
|
||||
} else if (preferences::is_ignored(name)) {
|
||||
relation = IGNORED;
|
||||
} else if (preferences::is_friend(name)) {
|
||||
relation = FRIEND;
|
||||
} else {
|
||||
relation = NEUTRAL;
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
std::string make_short_name(const std::string& long_name)
|
||||
{
|
||||
if (long_name.empty()) return "";
|
||||
std::string sh;
|
||||
bool had_space = true;
|
||||
for (size_t i = 1; i < long_name.size(); ++i) {
|
||||
if (long_name[i] == ' ') {
|
||||
had_space = true;
|
||||
} else if (had_space && long_name[i] != '?') {
|
||||
sh += long_name[i];
|
||||
had_space = false;
|
||||
}
|
||||
}
|
||||
return sh;
|
||||
}
|
||||
|
||||
} //end anonymous namespace
|
||||
|
||||
game_info::game_info(const config& game, const config& game_config)
|
||||
: mini_map()
|
||||
, id(lexical_cast_default<int>(game["id"]))
|
||||
, map_data(game["map_data"])
|
||||
, name(game["name"])
|
||||
, scenario()
|
||||
, remote_scenario(false)
|
||||
, map_info()
|
||||
, map_size_info()
|
||||
, era()
|
||||
, era_short()
|
||||
, gold(game["mp_village_gold"])
|
||||
, xp(game["experience_modifier"] + "%")
|
||||
, vision()
|
||||
, status()
|
||||
, time_limit()
|
||||
, vacant_slots(lexical_cast_default<size_t>(game["slots"], 0))
|
||||
, current_turn(0)
|
||||
, reloaded(game["savegame"] == "yes")
|
||||
, started(false)
|
||||
, fog(game["mp_fog"] == "yes")
|
||||
, shroud(game["mp_shroud"] == "yes")
|
||||
, observers(game["observer"] != "no")
|
||||
, use_map_settings(game["mp_use_map_settings"] == "yes")
|
||||
, verified(true)
|
||||
, password_required(game["password"] == "yes")
|
||||
, have_era(true)
|
||||
, has_friends(false)
|
||||
, has_ignored(false)
|
||||
, display_status(NEW)
|
||||
{
|
||||
std::string turn = game["turn"];
|
||||
std::string slots = game["slots"];
|
||||
if (!game["mp_era"].empty())
|
||||
{
|
||||
const config &era_cfg = game_config.find_child("era", "id", game["mp_era"]);
|
||||
utils::string_map symbols;
|
||||
symbols["era_id"] = game["mp_era"];
|
||||
if (era_cfg) {
|
||||
era = era_cfg["name"];
|
||||
era_short = era_cfg["short_name"];
|
||||
if (era_short.empty()) {
|
||||
era_short = make_short_name(era);
|
||||
}
|
||||
} else {
|
||||
have_era = (game["require_era"] == "no");
|
||||
era = vgettext("Unknown era: $era_id", symbols);
|
||||
era_short = "?" + make_short_name(era);
|
||||
verified = false;
|
||||
}
|
||||
} else {
|
||||
era = _("Unknown era");
|
||||
era_short = "??";
|
||||
verified = false;
|
||||
}
|
||||
map_info = era;
|
||||
|
||||
if (map_data.empty()) {
|
||||
map_data = read_map(game["mp_scenario"]);
|
||||
}
|
||||
|
||||
if (map_data.empty()) {
|
||||
map_info += " - ??x??";
|
||||
} else {
|
||||
try {
|
||||
gamemap map(game_config, map_data);
|
||||
//mini_map = image::getMinimap(minimap_size_, minimap_size_, map, 0);
|
||||
map_size_info = lexical_cast_default<std::string, int>(map.w(), "??")
|
||||
+ std::string("x") + lexical_cast_default<std::string, int>(map.h(), "??");
|
||||
map_info += " - " + map_size_info;
|
||||
} catch (incorrect_map_format_exception &e) {
|
||||
ERR_CF << "illegal map: " << e.msg_ << "\n";
|
||||
verified = false;
|
||||
} catch (twml_exception& e) {
|
||||
ERR_CF << "map could not be loaded: " << e.dev_message << '\n';
|
||||
verified = false;
|
||||
}
|
||||
}
|
||||
map_info += " ";
|
||||
if (!game["mp_scenario"].empty())
|
||||
{
|
||||
// check if it's a multiplayer scenario
|
||||
const config *level_cfg = &game_config.find_child("multiplayer", "id", game["mp_scenario"]);
|
||||
if (!*level_cfg) {
|
||||
// check if it's a user map
|
||||
level_cfg = &game_config.find_child("generic_multiplayer", "id", game["mp_scenario"]);
|
||||
}
|
||||
if (*level_cfg) {
|
||||
scenario = level_cfg->get_attribute("name");
|
||||
map_info += scenario;
|
||||
// reloaded games do not match the original scenario hash,
|
||||
// so it makes no sense to test them, they always would appear
|
||||
// as remote scenarios
|
||||
if (!reloaded) {
|
||||
if (const config& hashes = game_config.child("multiplayer_hashes")) {
|
||||
std::string hash = game["hash"];
|
||||
bool hash_found = false;
|
||||
foreach (const config::attribute &i, hashes.attribute_range()) {
|
||||
if (i.first == game["mp_scenario"] && i.second == hash) {
|
||||
hash_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!hash_found) {
|
||||
remote_scenario = true;
|
||||
map_info += " - ";
|
||||
map_info += _("Remote scenario");
|
||||
verified = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
utils::string_map symbols;
|
||||
symbols["scenario_id"] = game["mp_scenario"];
|
||||
scenario = vgettext("Unknown scenario: $scenario_id", symbols);
|
||||
map_info += scenario;
|
||||
verified = false;
|
||||
}
|
||||
} else {
|
||||
scenario = _("Unknown scenario");
|
||||
map_info += scenario;
|
||||
verified = false;
|
||||
}
|
||||
if (reloaded) {
|
||||
map_info += " - ";
|
||||
map_info += _("Reloaded game");
|
||||
verified = false;
|
||||
}
|
||||
|
||||
if (!turn.empty()) {
|
||||
started = true;
|
||||
int index = turn.find_first_of('/');
|
||||
if (index > -1){
|
||||
const std::string current_turn_string = turn.substr(0, index);
|
||||
current_turn = lexical_cast<unsigned int>(current_turn_string);
|
||||
}
|
||||
status = _("Turn ") + turn;
|
||||
} else {
|
||||
started = false;
|
||||
if (vacant_slots > 0) {
|
||||
status = std::string(_n("Vacant Slot:", "Vacant Slots:",
|
||||
vacant_slots)) + " " + game["slots"];
|
||||
}
|
||||
}
|
||||
|
||||
if (fog) {
|
||||
vision = _("Fog");
|
||||
if (shroud) {
|
||||
vision += "/";
|
||||
vision += _("Shroud");
|
||||
}
|
||||
} else if (shroud) {
|
||||
vision = _("Shroud");
|
||||
} else {
|
||||
vision = _("none");
|
||||
}
|
||||
if (game["mp_countdown"] == "yes" ) {
|
||||
time_limit = game["mp_countdown_init_time"] + "+"
|
||||
+ game["mp_countdown_turn_bonus"] + "/"
|
||||
+ game["mp_countdown_action_bonus"];
|
||||
} else {
|
||||
time_limit = "";
|
||||
}
|
||||
}
|
||||
|
||||
bool game_info::can_join() const
|
||||
{
|
||||
return have_era && !started && vacant_slots > 0;
|
||||
}
|
||||
|
||||
bool game_info::can_observe() const
|
||||
{
|
||||
return (have_era && observers) || preferences::is_authenticated();
|
||||
}
|
||||
|
||||
const char* game_info::display_status_string() const
|
||||
{
|
||||
switch (display_status) {
|
||||
case game_info::CLEAN:
|
||||
return "clean";
|
||||
case game_info::NEW:
|
||||
return "new";
|
||||
case game_info::DELETED:
|
||||
return "deleted";
|
||||
case game_info::UPDATED:
|
||||
return "updated";
|
||||
default:
|
||||
ERR_CF << "BAD display_status " << display_status
|
||||
<< " in game " << id << "\n";
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
game_filter_stack::game_filter_stack()
|
||||
: filters_()
|
||||
{
|
||||
}
|
||||
|
||||
game_filter_stack::~game_filter_stack()
|
||||
{
|
||||
foreach (game_filter_base* f, filters_) {
|
||||
delete f;
|
||||
}
|
||||
}
|
||||
|
||||
void game_filter_stack::append(game_filter_base *f)
|
||||
{
|
||||
filters_.push_back(f);
|
||||
}
|
||||
|
||||
void game_filter_stack::clear()
|
||||
{
|
||||
foreach (game_filter_base* f, filters_) {
|
||||
delete f;
|
||||
}
|
||||
filters_.clear();
|
||||
}
|
||||
|
||||
bool game_filter_and_stack::match(const game_info &game) const
|
||||
{
|
||||
foreach (game_filter_base* f, filters_) {
|
||||
if (!f->match(game)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool game_filter_or_stack::match(const game_info &game) const
|
||||
{
|
||||
foreach (game_filter_base* f, filters_) {
|
||||
if (f->match(game)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool game_filter_string_part::match(const game_info &game) const
|
||||
{
|
||||
const std::string& gs = game.*member_;
|
||||
return std::search(gs.begin(), gs.end(), value_.begin(), value_.end(),
|
||||
chars_equal_insensitive) != gs.end();
|
||||
}
|
||||
|
||||
bool game_filter_general_string_part::match(const game_info &game) const
|
||||
{
|
||||
const std::string& s1 = game.map_info;
|
||||
const std::string& s2 = game.name;
|
||||
return
|
||||
std::search(
|
||||
s1.begin(), s1.end(), value_.begin(), value_.end(), chars_equal_insensitive
|
||||
) != s1.end()
|
||||
||
|
||||
std::search(
|
||||
s2.begin(), s2.end(), value_.begin(), value_.end(), chars_equal_insensitive
|
||||
) != s2.end();
|
||||
}
|
||||
|
|
@ -240,69 +240,4 @@ private:
|
|||
std::string value_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the collective information the client has
|
||||
* about the players and games on the server
|
||||
*/
|
||||
class lobby_info
|
||||
{
|
||||
public:
|
||||
lobby_info(const config& game_config);
|
||||
|
||||
void process_gamelist(const config &data);
|
||||
bool process_gamelist_diff(const config &data);
|
||||
|
||||
void sync_games_display_status();
|
||||
|
||||
const config& gamelist() const { return gamelist_; }
|
||||
|
||||
void clear_game_filter();
|
||||
void add_game_filter(game_filter_base* f);
|
||||
void set_game_filter_invert(bool value);
|
||||
void apply_game_filter();
|
||||
|
||||
game_info* get_game_by_id(int id);
|
||||
const game_info* get_game_by_id(int id) const;
|
||||
|
||||
void sort_users(bool by_name, bool by_relation);
|
||||
|
||||
void open_room(const std::string& name);
|
||||
void close_room(const std::string& name);
|
||||
bool has_room(const std::string& name) const;
|
||||
room_info* get_room(const std::string& name);
|
||||
const room_info* get_room(const std::string& name) const;
|
||||
|
||||
user_info& get_user(const std::string& name);
|
||||
|
||||
chat_log& get_whisper_log(const std::string& name);
|
||||
|
||||
void update_user_statuses(int game_id, const room_info* room);
|
||||
|
||||
const std::vector<room_info>& rooms() const { return rooms_; }
|
||||
const std::vector<game_info>& games() const { return games_; }
|
||||
const std::vector<bool>& games_shown() const { return games_shown_; }
|
||||
const std::vector<game_info*>& games_filtered() const;
|
||||
int games_shown_count() const;
|
||||
const std::vector<user_info>& users() const { return users_; }
|
||||
const std::vector<user_info*>& users_sorted() const;
|
||||
private:
|
||||
void parse_gamelist();
|
||||
|
||||
const config& game_config_;
|
||||
config gamelist_;
|
||||
bool gamelist_initialized_;
|
||||
std::vector<room_info> rooms_;
|
||||
std::vector<game_info> games_;
|
||||
std::map<int, game_info*> games_by_id_;
|
||||
std::vector<game_info*> games_filtered_;
|
||||
std::vector<user_info> users_;
|
||||
std::vector<user_info*> users_sorted_;
|
||||
std::map<std::string, chat_log> whispers_;
|
||||
game_filter_and_stack game_filter_;
|
||||
bool game_filter_invert_;
|
||||
std::vector<bool> games_shown_;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "lobby_data.hpp"
|
||||
#include "gui/dialogs/lobby/lobby_info.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
|
@ -38,378 +38,6 @@ static lg::log_domain log_lobby("lobby");
|
|||
#define LOG_LB LOG_STREAM(info, log_lobby)
|
||||
#define ERR_LB LOG_STREAM(err, log_lobby)
|
||||
|
||||
chat_message::chat_message(const time_t& timestamp, const std::string& user, const std::string& message)
|
||||
: timestamp(timestamp), user(user), message(message)
|
||||
{
|
||||
}
|
||||
|
||||
chat_log::chat_log()
|
||||
: history_()
|
||||
{
|
||||
}
|
||||
|
||||
void chat_log::add_message(const time_t& timestamp, const std::string& user, const std::string& message)
|
||||
{
|
||||
history_.push_back(chat_message(timestamp, user, message));
|
||||
}
|
||||
|
||||
|
||||
void chat_log::add_message(const std::string& user, const std::string& message) {
|
||||
add_message(time(NULL), user, message);
|
||||
}
|
||||
|
||||
void chat_log::clear()
|
||||
{
|
||||
history_.clear();
|
||||
}
|
||||
|
||||
room_info::room_info(const std::string& name)
|
||||
: name_(name)
|
||||
, members_()
|
||||
, log_()
|
||||
{
|
||||
}
|
||||
|
||||
bool room_info::is_member(const std::string& user) const
|
||||
{
|
||||
return members_.find(user) != members_.end();
|
||||
}
|
||||
|
||||
void room_info::add_member(const std::string& user)
|
||||
{
|
||||
members_.insert(user);
|
||||
}
|
||||
|
||||
void room_info::remove_member(const std::string& user)
|
||||
{
|
||||
members_.erase(user);
|
||||
}
|
||||
|
||||
void room_info::process_room_members(const config& data)
|
||||
{
|
||||
members_.clear();
|
||||
foreach (const config& m, data.child_range("member")) {
|
||||
members_.insert(m["name"]);
|
||||
}
|
||||
}
|
||||
|
||||
user_info::user_info(const config& c)
|
||||
: name(c["name"])
|
||||
, game_id(lexical_cast_default<int>(c["game_id"]))
|
||||
, relation(ME)
|
||||
, state(game_id == 0 ? LOBBY : GAME)
|
||||
, registered(utils::string_bool(c["registered"]))
|
||||
, observing(c["status"] == "observing")
|
||||
{
|
||||
update_relation();
|
||||
}
|
||||
|
||||
void user_info::update_state(int selected_game_id, const room_info* current_room /*= NULL*/)
|
||||
{
|
||||
if (game_id != 0) {
|
||||
if (game_id == selected_game_id) {
|
||||
state = SEL_GAME;
|
||||
} else {
|
||||
state = GAME;
|
||||
}
|
||||
} else {
|
||||
if (current_room != NULL && current_room->is_member(name)) {
|
||||
state = SEL_ROOM;
|
||||
} else {
|
||||
state = LOBBY;
|
||||
}
|
||||
}
|
||||
update_relation();
|
||||
}
|
||||
|
||||
void user_info::update_relation()
|
||||
{
|
||||
if (name == preferences::login()) {
|
||||
relation = ME;
|
||||
} else if (preferences::is_ignored(name)) {
|
||||
relation = IGNORED;
|
||||
} else if (preferences::is_friend(name)) {
|
||||
relation = FRIEND;
|
||||
} else {
|
||||
relation = NEUTRAL;
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
std::string make_short_name(const std::string& long_name)
|
||||
{
|
||||
if (long_name.empty()) return "";
|
||||
std::string sh;
|
||||
bool had_space = true;
|
||||
for (size_t i = 1; i < long_name.size(); ++i) {
|
||||
if (long_name[i] == ' ') {
|
||||
had_space = true;
|
||||
} else if (had_space && long_name[i] != '?') {
|
||||
sh += long_name[i];
|
||||
had_space = false;
|
||||
}
|
||||
}
|
||||
return sh;
|
||||
}
|
||||
|
||||
} //end anonymous namespace
|
||||
|
||||
game_info::game_info(const config& game, const config& game_config)
|
||||
: mini_map()
|
||||
, id(lexical_cast_default<int>(game["id"]))
|
||||
, map_data(game["map_data"])
|
||||
, name(game["name"])
|
||||
, scenario()
|
||||
, remote_scenario(false)
|
||||
, map_info()
|
||||
, map_size_info()
|
||||
, era()
|
||||
, era_short()
|
||||
, gold(game["mp_village_gold"])
|
||||
, xp(game["experience_modifier"] + "%")
|
||||
, vision()
|
||||
, status()
|
||||
, time_limit()
|
||||
, vacant_slots(lexical_cast_default<size_t>(game["slots"], 0))
|
||||
, current_turn(0)
|
||||
, reloaded(game["savegame"] == "yes")
|
||||
, started(false)
|
||||
, fog(game["mp_fog"] == "yes")
|
||||
, shroud(game["mp_shroud"] == "yes")
|
||||
, observers(game["observer"] != "no")
|
||||
, use_map_settings(game["mp_use_map_settings"] == "yes")
|
||||
, verified(true)
|
||||
, password_required(game["password"] == "yes")
|
||||
, have_era(true)
|
||||
, has_friends(false)
|
||||
, has_ignored(false)
|
||||
, display_status(NEW)
|
||||
{
|
||||
std::string turn = game["turn"];
|
||||
std::string slots = game["slots"];
|
||||
if (!game["mp_era"].empty())
|
||||
{
|
||||
const config &era_cfg = game_config.find_child("era", "id", game["mp_era"]);
|
||||
utils::string_map symbols;
|
||||
symbols["era_id"] = game["mp_era"];
|
||||
if (era_cfg) {
|
||||
era = era_cfg["name"];
|
||||
era_short = era_cfg["short_name"];
|
||||
if (era_short.empty()) {
|
||||
era_short = make_short_name(era);
|
||||
}
|
||||
} else {
|
||||
have_era = (game["require_era"] == "no");
|
||||
era = vgettext("Unknown era: $era_id", symbols);
|
||||
era_short = "?" + make_short_name(era);
|
||||
verified = false;
|
||||
}
|
||||
} else {
|
||||
era = _("Unknown era");
|
||||
era_short = "??";
|
||||
verified = false;
|
||||
}
|
||||
map_info = era;
|
||||
|
||||
if (map_data.empty()) {
|
||||
map_data = read_map(game["mp_scenario"]);
|
||||
}
|
||||
|
||||
if (map_data.empty()) {
|
||||
map_info += " - ??x??";
|
||||
} else {
|
||||
try {
|
||||
gamemap map(game_config, map_data);
|
||||
//mini_map = image::getMinimap(minimap_size_, minimap_size_, map, 0);
|
||||
map_size_info = lexical_cast_default<std::string, int>(map.w(), "??")
|
||||
+ std::string("x") + lexical_cast_default<std::string, int>(map.h(), "??");
|
||||
map_info += " - " + map_size_info;
|
||||
} catch (incorrect_map_format_exception &e) {
|
||||
ERR_CF << "illegal map: " << e.msg_ << "\n";
|
||||
verified = false;
|
||||
} catch (twml_exception& e) {
|
||||
ERR_CF << "map could not be loaded: " << e.dev_message << '\n';
|
||||
verified = false;
|
||||
}
|
||||
}
|
||||
map_info += " ";
|
||||
if (!game["mp_scenario"].empty())
|
||||
{
|
||||
// check if it's a multiplayer scenario
|
||||
const config *level_cfg = &game_config.find_child("multiplayer", "id", game["mp_scenario"]);
|
||||
if (!*level_cfg) {
|
||||
// check if it's a user map
|
||||
level_cfg = &game_config.find_child("generic_multiplayer", "id", game["mp_scenario"]);
|
||||
}
|
||||
if (*level_cfg) {
|
||||
scenario = level_cfg->get_attribute("name");
|
||||
map_info += scenario;
|
||||
// reloaded games do not match the original scenario hash,
|
||||
// so it makes no sense to test them, they always would appear
|
||||
// as remote scenarios
|
||||
if (!reloaded) {
|
||||
if (const config& hashes = game_config.child("multiplayer_hashes")) {
|
||||
std::string hash = game["hash"];
|
||||
bool hash_found = false;
|
||||
foreach (const config::attribute &i, hashes.attribute_range()) {
|
||||
if (i.first == game["mp_scenario"] && i.second == hash) {
|
||||
hash_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!hash_found) {
|
||||
remote_scenario = true;
|
||||
map_info += " - ";
|
||||
map_info += _("Remote scenario");
|
||||
verified = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
utils::string_map symbols;
|
||||
symbols["scenario_id"] = game["mp_scenario"];
|
||||
scenario = vgettext("Unknown scenario: $scenario_id", symbols);
|
||||
map_info += scenario;
|
||||
verified = false;
|
||||
}
|
||||
} else {
|
||||
scenario = _("Unknown scenario");
|
||||
map_info += scenario;
|
||||
verified = false;
|
||||
}
|
||||
if (reloaded) {
|
||||
map_info += " - ";
|
||||
map_info += _("Reloaded game");
|
||||
verified = false;
|
||||
}
|
||||
|
||||
if (!turn.empty()) {
|
||||
started = true;
|
||||
int index = turn.find_first_of('/');
|
||||
if (index > -1){
|
||||
const std::string current_turn_string = turn.substr(0, index);
|
||||
current_turn = lexical_cast<unsigned int>(current_turn_string);
|
||||
}
|
||||
status = _("Turn ") + turn;
|
||||
} else {
|
||||
started = false;
|
||||
if (vacant_slots > 0) {
|
||||
status = std::string(_n("Vacant Slot:", "Vacant Slots:",
|
||||
vacant_slots)) + " " + game["slots"];
|
||||
}
|
||||
}
|
||||
|
||||
if (fog) {
|
||||
vision = _("Fog");
|
||||
if (shroud) {
|
||||
vision += "/";
|
||||
vision += _("Shroud");
|
||||
}
|
||||
} else if (shroud) {
|
||||
vision = _("Shroud");
|
||||
} else {
|
||||
vision = _("none");
|
||||
}
|
||||
if (game["mp_countdown"] == "yes" ) {
|
||||
time_limit = game["mp_countdown_init_time"] + "+"
|
||||
+ game["mp_countdown_turn_bonus"] + "/"
|
||||
+ game["mp_countdown_action_bonus"];
|
||||
} else {
|
||||
time_limit = "";
|
||||
}
|
||||
}
|
||||
|
||||
bool game_info::can_join() const
|
||||
{
|
||||
return have_era && !started && vacant_slots > 0;
|
||||
}
|
||||
|
||||
bool game_info::can_observe() const
|
||||
{
|
||||
return (have_era && observers) || preferences::is_authenticated();
|
||||
}
|
||||
|
||||
const char* game_info::display_status_string() const
|
||||
{
|
||||
switch (display_status) {
|
||||
case game_info::CLEAN:
|
||||
return "clean";
|
||||
case game_info::NEW:
|
||||
return "new";
|
||||
case game_info::DELETED:
|
||||
return "deleted";
|
||||
case game_info::UPDATED:
|
||||
return "updated";
|
||||
default:
|
||||
ERR_CF << "BAD display_status " << display_status
|
||||
<< " in game " << id << "\n";
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
game_filter_stack::game_filter_stack()
|
||||
: filters_()
|
||||
{
|
||||
}
|
||||
|
||||
game_filter_stack::~game_filter_stack()
|
||||
{
|
||||
foreach (game_filter_base* f, filters_) {
|
||||
delete f;
|
||||
}
|
||||
}
|
||||
|
||||
void game_filter_stack::append(game_filter_base *f)
|
||||
{
|
||||
filters_.push_back(f);
|
||||
}
|
||||
|
||||
void game_filter_stack::clear()
|
||||
{
|
||||
foreach (game_filter_base* f, filters_) {
|
||||
delete f;
|
||||
}
|
||||
filters_.clear();
|
||||
}
|
||||
|
||||
bool game_filter_and_stack::match(const game_info &game) const
|
||||
{
|
||||
foreach (game_filter_base* f, filters_) {
|
||||
if (!f->match(game)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool game_filter_or_stack::match(const game_info &game) const
|
||||
{
|
||||
foreach (game_filter_base* f, filters_) {
|
||||
if (f->match(game)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool game_filter_string_part::match(const game_info &game) const
|
||||
{
|
||||
const std::string& gs = game.*member_;
|
||||
return std::search(gs.begin(), gs.end(), value_.begin(), value_.end(),
|
||||
chars_equal_insensitive) != gs.end();
|
||||
}
|
||||
|
||||
bool game_filter_general_string_part::match(const game_info &game) const
|
||||
{
|
||||
const std::string& s1 = game.map_info;
|
||||
const std::string& s2 = game.name;
|
||||
return
|
||||
std::search(
|
||||
s1.begin(), s1.end(), value_.begin(), value_.end(), chars_equal_insensitive
|
||||
) != s1.end()
|
||||
||
|
||||
std::search(
|
||||
s2.begin(), s2.end(), value_.begin(), value_.end(), chars_equal_insensitive
|
||||
) != s2.end();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
std::string dump_games_vector(const std::vector<game_info>& games)
|
83
src/gui/dialogs/lobby/lobby_info.hpp
Normal file
83
src/gui/dialogs/lobby/lobby_info.hpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2009 - 2010 by Tomasz Sniatowski <kailoran@gmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef INC_LOBBY_INFO
|
||||
#define INC_LOBBY_INFO
|
||||
|
||||
#include "src/gui/dialogs/lobby/lobby_data.hpp"
|
||||
|
||||
/**
|
||||
* This class represents the collective information the client has
|
||||
* about the players and games on the server
|
||||
*/
|
||||
class lobby_info
|
||||
{
|
||||
public:
|
||||
lobby_info(const config& game_config);
|
||||
|
||||
void process_gamelist(const config &data);
|
||||
bool process_gamelist_diff(const config &data);
|
||||
|
||||
void sync_games_display_status();
|
||||
|
||||
const config& gamelist() const { return gamelist_; }
|
||||
|
||||
void clear_game_filter();
|
||||
void add_game_filter(game_filter_base* f);
|
||||
void set_game_filter_invert(bool value);
|
||||
void apply_game_filter();
|
||||
|
||||
game_info* get_game_by_id(int id);
|
||||
const game_info* get_game_by_id(int id) const;
|
||||
|
||||
void sort_users(bool by_name, bool by_relation);
|
||||
|
||||
void open_room(const std::string& name);
|
||||
void close_room(const std::string& name);
|
||||
bool has_room(const std::string& name) const;
|
||||
room_info* get_room(const std::string& name);
|
||||
const room_info* get_room(const std::string& name) const;
|
||||
|
||||
user_info& get_user(const std::string& name);
|
||||
|
||||
chat_log& get_whisper_log(const std::string& name);
|
||||
|
||||
void update_user_statuses(int game_id, const room_info* room);
|
||||
|
||||
const std::vector<room_info>& rooms() const { return rooms_; }
|
||||
const std::vector<game_info>& games() const { return games_; }
|
||||
const std::vector<bool>& games_shown() const { return games_shown_; }
|
||||
const std::vector<game_info*>& games_filtered() const;
|
||||
int games_shown_count() const;
|
||||
const std::vector<user_info>& users() const { return users_; }
|
||||
const std::vector<user_info*>& users_sorted() const;
|
||||
private:
|
||||
void parse_gamelist();
|
||||
|
||||
const config& game_config_;
|
||||
config gamelist_;
|
||||
bool gamelist_initialized_;
|
||||
std::vector<room_info> rooms_;
|
||||
std::vector<game_info> games_;
|
||||
std::map<int, game_info*> games_by_id_;
|
||||
std::vector<game_info*> games_filtered_;
|
||||
std::vector<user_info> users_;
|
||||
std::vector<user_info*> users_sorted_;
|
||||
std::map<std::string, chat_log> whispers_;
|
||||
game_filter_and_stack game_filter_;
|
||||
bool game_filter_invert_;
|
||||
std::vector<bool> games_shown_;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -36,7 +36,6 @@
|
|||
#include "formula_string_utils.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "lobby_data.hpp"
|
||||
#include "lobby_preferences.hpp"
|
||||
#include "log.hpp"
|
||||
#include "network.hpp"
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "gui/widgets/tree_view.hpp"
|
||||
#include "config.hpp"
|
||||
#include "chat_events.hpp"
|
||||
#include "lobby_data.hpp"
|
||||
#include "src/gui/dialogs/lobby/lobby_info.hpp"
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "config.hpp"
|
||||
#include "chat_events.hpp"
|
||||
#include "lobby_data.hpp"
|
||||
#include "gui/dialogs/lobby/lobby_info.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue