Cosmetic changes only.

This commit is contained in:
hiker 2015-11-10 08:08:41 +11:00
parent 36ebe29649
commit 0a23198be1
2 changed files with 138 additions and 129 deletions

View File

@ -26,10 +26,15 @@
namespace Online
{
Server::SortOrder Server::m_sort_order = Server::SO_NAME;
Server::SortOrder Server::m_sort_order = Server::SO_NAME;
Server::Server(const XMLNode & xml, bool is_lan)
{
/** Constructor based on XML data received from the stk server.
* \param xml The data for one server as received as part of the
* get-all stk-server request.
* \param is_lan If this is a lan only server.
*/
Server::Server(const XMLNode & xml, bool is_lan)
{
assert(xml.getName() == "server");
m_name = "";
@ -48,28 +53,34 @@ namespace Online
xml.get("max_players", &m_max_players);
xml.get("current_players", &m_current_players);
} // Server(const XML&)
} // Server(const XML&)
// ----------------------------------------------------------------------------
Server::Server(const core::stringw &name, bool is_lan, int max_players,
// ----------------------------------------------------------------------------
/** Manual server creation, based on data received from a LAN server discovery
* (see ServersManager::getLANRefresh).
* \param name Name of the server.
* \param is_lan If this is a lan-only server.
* \param max_players Maximum number of players allowed on this server.
* \param current_players The currently connected number of players.
*/
Server::Server(const core::stringw &name, bool is_lan, int max_players,
int current_players)
{
{
m_name = name;
m_satisfaction_score = 0;
m_server_id = 0;
m_current_players = current_players;
m_max_players = max_players;
m_is_lan = is_lan;
} // server(name, ...)
} // server(name, ...)
// ----------------------------------------------------------------------------
/**
* \brief Filter the add-on with a list of words.
// ----------------------------------------------------------------------------
/** \brief Filter the add-on with a list of words.
* \param words A list of words separated by ' '.
* \return true if the add-on contains one of the words, otherwise false.
*/
bool Server::filterByWords(const core::stringw words) const
{
bool Server::filterByWords(const core::stringw words) const
{
if (words == NULL || words.empty())
return true;
@ -86,5 +97,5 @@ namespace Online
}
return false;
} // filterByWords
} // filterByWords
} // namespace Online

View File

@ -33,12 +33,12 @@ class XMLNode;
namespace Online
{
/**
/**
* \ingroup online
*/
class Server
{
public:
class Server
{
public:
/** Set the sort order used in the comparison function. */
enum SortOrder
@ -48,10 +48,12 @@ namespace Online
SO_PLAYERS = 4
};
protected:
protected:
/** The server name to be displayed. */
irr::core::stringw m_name;
std::string m_lower_case_name; // Used for comparison
/** Name in lower case for comparisons. */
std::string m_lower_case_name;
uint32_t m_server_id;
uint32_t m_host_id;
@ -71,14 +73,13 @@ namespace Online
/** The sort order to be used in the comparison. */
static SortOrder m_sort_order;
Server() {}
public:
public:
/** Initialises the object from an XML node. */
Server(const XMLNode &xml, bool is_lan);
Server(const core::stringw &name, bool is_lan, int max_players,
int current_players);
bool filterByWords(const irr::core::stringw words) const;
// ------------------------------------------------------------------------
/** Sets the sort order used in the comparison function. It is static, so
* that each instance can access the sort order. */
@ -87,44 +88,41 @@ namespace Online
// ------------------------------------------------------------------------
/** Returns the name of the server. */
const irr::core::stringw& getName() const { return m_name; }
const std::string & getLowerCaseName() const { return m_lower_case_name; }
// ------------------------------------------------------------------------
const float getScore() const { return m_satisfaction_score; }
// ------------------------------------------------------------------------
/** Returns the ID of this server. */
const uint32_t getServerId() const { return m_server_id; }
const uint32_t getHostId() const { return m_host_id; }
const int getMaxPlayers() const { return m_max_players; }
const int getCurrentPlayers() const { return m_current_players; }
// ------------------------------------------------------------------------
bool filterByWords(const irr::core::stringw words) const;
/** Returns the unique host id of this server. */
const uint32_t getHostId() const { return m_host_id; }
// ------------------------------------------------------------------------
/** Returns the maximum number of players allowed on this server. */
const int getMaxPlayers() const { return m_max_players; }
// ------------------------------------------------------------------------
/** Returns the number of currently connected players. */
const int getCurrentPlayers() const { return m_current_players; }
// ------------------------------------------------------------------------
/** Compares two servers according to the sort order currently defined.
* \param a The addon to compare this addon to.
*/
bool operator<(const Server &server) const
{
switch(m_sort_order)
switch (m_sort_order)
{
case SO_SCORE:
return m_satisfaction_score < server.getScore();
return m_satisfaction_score < server.m_satisfaction_score;
break;
case SO_NAME:
// m_id is the lower case name
return m_lower_case_name < server.m_lower_case_name;
break;
case SO_PLAYERS:
return m_current_players < server.getCurrentPlayers();
return m_current_players < server.m_current_players;
break;
} // switch
return true;
} // operator<
}; // Server
}; // Server
} // namespace Online
#endif // HEADER_SERVER_HPP