ManaPlus
Functions | Variables
serverdialog.cpp File Reference

(986a3bf)

#include "gui/windows/serverdialog.h"
#include "chatlogger.h"
#include "client.h"
#include "configuration.h"
#include "main.h"
#include "settings.h"
#include "net/download.h"
#include "fs/paths.h"
#include "gui/widgets/checkbox.h"
#include "gui/widgets/createwidget.h"
#include "gui/widgets/desktop.h"
#include "gui/windows/editserverdialog.h"
#include "gui/windows/logindialog.h"
#include "gui/windows/serverinfowindow.h"
#include "gui/widgets/button.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/serverslistbox.h"
#include "gui/widgets/scrollarea.h"
#include "utils/delete2.h"
#include "utils/foreach.h"
#include "utils/langs.h"
#include "debug.h"

Go to the source code of this file.

Functions

static std::string serverTypeToString (const ServerTypeT type)
 
static uint16_t defaultPortForServerType (const ServerTypeT type)
 
static void loadHostsGroup (const xmlNodePtr node, ServerInfo &server)
 
static void loadServerSourcesList (const xmlNodePtr node, std::vector< ServerUrlInfo > &list)
 
static void loadServerSources (const xmlNodePtr node, ServerInfo &server)
 

Variables

static const int MAX_SERVERLIST = 15
 

Function Documentation

◆ defaultPortForServerType()

static uint16_t defaultPortForServerType ( const ServerTypeT  type)
static

Definition at line 83 of file serverdialog.cpp.

84 {
85  switch (type)
86  {
87  default:
89  case ServerType::EVOL2:
90  return 6900;
93  return 6901;
94  }
95 }

References ServerType::EATHENA, ServerType::EVOL2, ServerType::TMWATHENA, and ServerType::UNKNOWN.

Referenced by ServerDialog::loadCustomServers(), and ServerDialog::loadServers().

◆ loadHostsGroup()

static void loadHostsGroup ( const xmlNodePtr  node,
ServerInfo server 
)
static

Definition at line 491 of file serverdialog.cpp.

493 {
494  HostsGroup group;
495  group.name = XML::langProperty(node,
496  "name",
497  // TRANSLATORS: unknown hosts group name
498  _("Unknown"));
499  for_each_xml_child_node(hostNode, node)
500  {
501  if (!xmlNameEqual(hostNode, "host") ||
502  !XmlHaveChildContent(hostNode))
503  {
504  continue;
505  }
506  const std::string host = XmlChildContent(hostNode);
507  if (host.empty())
508  continue;
509  if (!checkPath(host))
510  {
511  logger->log1("Warning: incorrect update server name");
512  continue;
513  }
514 
515  group.hosts.push_back(host);
516  }
517  if (!group.hosts.empty())
518  server.updateHosts.push_back(group);
519 }
void log1(const char *const log_text)
Definition: logger.cpp:238
std::vector< HostsGroup > updateHosts
Definition: serverinfo.h:54
#define _(s)
Definition: gettext.h:35
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
Logger * logger
Definition: logger.cpp:89
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:258
bool checkPath(const std::string &path)
Definition: paths.cpp:121
std::string name
Definition: hostsgroup.h:39
StringVect hosts
Definition: hostsgroup.h:40

References _, checkPath(), for_each_xml_child_node, HostsGroup::hosts, XML::langProperty(), Logger::log1(), logger, HostsGroup::name, and ServerInfo::updateHosts.

Referenced by ServerDialog::loadServers().

◆ loadServerSources()

static void loadServerSources ( const xmlNodePtr  node,
ServerInfo server 
)
static

Definition at line 543 of file serverdialog.cpp.

545 {
546  for_each_xml_child_node(subNode, node)
547  {
548  if (xmlNameEqual(subNode, "free"))
549  {
550  loadServerSourcesList(subNode, server.freeSources);
551  }
552  else if (xmlNameEqual(subNode, "nonfree"))
553  {
554  loadServerSourcesList(subNode, server.nonFreeSources);
555  }
556  }
557 }
std::vector< ServerUrlInfo > nonFreeSources
Definition: serverinfo.h:56
std::vector< ServerUrlInfo > freeSources
Definition: serverinfo.h:55
static void loadServerSourcesList(const xmlNodePtr node, std::vector< ServerUrlInfo > &list)

References for_each_xml_child_node, ServerInfo::freeSources, loadServerSourcesList(), and ServerInfo::nonFreeSources.

Referenced by ServerDialog::loadServers().

◆ loadServerSourcesList()

static void loadServerSourcesList ( const xmlNodePtr  node,
std::vector< ServerUrlInfo > &  list 
)
static

Definition at line 521 of file serverdialog.cpp.

523 {
524  for_each_xml_child_node(urlNode, node)
525  {
526  if (!xmlNameEqual(urlNode, "url") ||
527  !XmlHaveChildContent(urlNode))
528  {
529  continue;
530  }
531  const std::string name = XML::langProperty(urlNode,
532  "name",
533  "");
534  if (name.empty())
535  continue;
536  const std::string url = XmlChildContent(urlNode);
537  if (url.empty())
538  continue;
539  list.push_back(ServerUrlInfo(name, url));
540  }
541 }
bool url(InputEvent &event)
Definition: commands.cpp:64

References for_each_xml_child_node, XML::langProperty(), and Actions::url().

Referenced by ServerDialog::loadServers(), and loadServerSources().

◆ serverTypeToString()

static std::string serverTypeToString ( const ServerTypeT  type)
static

Definition at line 61 of file serverdialog.cpp.

62 {
63  switch (type)
64  {
66 #ifdef TMWA_SUPPORT
67  return "TmwAthena";
68 #else // TMWA_SUPPORT
69 
70  return "";
71 #endif // TMWA_SUPPORT
72 
74  return "eAthena";
75  case ServerType::EVOL2:
76  return "Evol2";
77  default:
79  return "";
80  }
81 }

References ServerType::EATHENA, ServerType::EVOL2, ServerType::TMWATHENA, and ServerType::UNKNOWN.

Referenced by ServerDialog::saveCustomServers().

Variable Documentation

◆ MAX_SERVERLIST

const int MAX_SERVERLIST = 15
static