From 1db4d18ed1c04548ce8414adfb4e7cf830b39279 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 6 Jan 2015 18:27:23 +0300 Subject: Move servertype enum into separate file. --- src/CMakeLists.txt | 1 + src/Makefile.am | 1 + src/enums/net/servertype.h | 38 ++++++++++++++++++++++++++++++++++ src/gui/windows/editserverdialog.cpp | 26 +++++++++++------------ src/gui/windows/serverdialog.cpp | 34 +++++++++++++++--------------- src/net/eathena/serverfeatures.cpp | 2 +- src/net/net.cpp | 16 +++++++-------- src/net/net.h | 2 +- src/net/serverinfo.h | 40 ++++++++++++++++-------------------- 9 files changed, 98 insertions(+), 62 deletions(-) create mode 100644 src/enums/net/servertype.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f41093291..b47099ec9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -564,6 +564,7 @@ SET(SRCS net/netconsts.h net/partyhandler.h enums/net/partyshare.h + enums/net/servertype.h net/pethandler.h net/playerhandler.h net/registrationoptions.h diff --git a/src/Makefile.am b/src/Makefile.am index 236247095..6bcd74d67 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -694,6 +694,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ net/npchandler.h \ net/partyhandler.h \ enums/net/partyshare.h \ + enums/net/servertype.h \ net/pethandler.h \ net/playerhandler.h \ net/questhandler.h \ diff --git a/src/enums/net/servertype.h b/src/enums/net/servertype.h new file mode 100644 index 000000000..d0ae2cdb9 --- /dev/null +++ b/src/enums/net/servertype.h @@ -0,0 +1,38 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef ENUMS_NET_SERVERTYPE_H +#define ENUMS_NET_SERVERTYPE_H + +namespace ServerType +{ + enum Type + { + UNKNOWN = 0, + TMWATHENA, + EVOL, + EATHENA, + EVOL2 + }; +} + +#endif // ENUMS_NET_SERVERTYPE_H diff --git a/src/gui/windows/editserverdialog.cpp b/src/gui/windows/editserverdialog.cpp index 7a33d9a99..9de90ed91 100644 --- a/src/gui/windows/editserverdialog.cpp +++ b/src/gui/windows/editserverdialog.cpp @@ -143,7 +143,7 @@ EditServerDialog::EditServerDialog(ServerDialog *const parent, switch (mServer.type) { - case ServerInfo::EATHENA: + case ServerType::EATHENA: #ifdef EATHENA_SUPPORT #ifdef TMWA_SUPPORT mTypeField->setSelected(2); @@ -155,18 +155,18 @@ EditServerDialog::EditServerDialog(ServerDialog *const parent, #endif // EATHENA_SUPPORT break; default: - case ServerInfo::UNKNOWN: - case ServerInfo::TMWATHENA: + case ServerType::UNKNOWN: + case ServerType::TMWATHENA: mTypeField->setSelected(0); break; - case ServerInfo::EVOL: + case ServerType::EVOL: #ifdef TMWA_SUPPORT mTypeField->setSelected(1); #else // TMWA_SUPPORT mTypeField->setSelected(0); #endif // TMWA_SUPPORT break; - case ServerInfo::EVOL2: + case ServerType::EVOL2: #ifdef EATHENA_SUPPORT #ifdef TMWA_SUPPORT mTypeField->setSelected(3); @@ -239,38 +239,38 @@ void EditServerDialog::action(const ActionEvent &event) { #ifdef TMWA_SUPPORT case 0: - mServer.type = ServerInfo::TMWATHENA; + mServer.type = ServerType::TMWATHENA; break; case 1: - mServer.type = ServerInfo::EVOL; + mServer.type = ServerType::EVOL; break; #ifdef EATHENA_SUPPORT case 2: - mServer.type = ServerInfo::EATHENA; + mServer.type = ServerType::EATHENA; break; case 3: - mServer.type = ServerInfo::EVOL2; + mServer.type = ServerType::EVOL2; break; #endif #else #ifdef EATHENA_SUPPORT case 0: - mServer.type = ServerInfo::EATHENA; + mServer.type = ServerType::EATHENA; break; case 1: - mServer.type = ServerInfo::EVOL2; + mServer.type = ServerType::EVOL2; break; #endif #endif default: - mServer.type = ServerInfo::UNKNOWN; + mServer.type = ServerType::UNKNOWN; break; } } else #endif // defined(TMWA_SUPPORT) || defined(EATHENA_SUPPORT) { - mServer.type = ServerInfo::TMWATHENA; + mServer.type = ServerType::TMWATHENA; } // Tell the server has to be saved diff --git a/src/gui/windows/serverdialog.cpp b/src/gui/windows/serverdialog.cpp index 808fde152..fab444050 100644 --- a/src/gui/windows/serverdialog.cpp +++ b/src/gui/windows/serverdialog.cpp @@ -60,50 +60,50 @@ static const int MAX_SERVERLIST = 15; -static std::string serverTypeToString(const ServerInfo::Type type) +static std::string serverTypeToString(const ServerType::Type type) { switch (type) { #ifdef TMWA_SUPPORT - case ServerInfo::TMWATHENA: + case ServerType::TMWATHENA: return "TmwAthena"; - case ServerInfo::EVOL: + case ServerType::EVOL: return "Evol"; #else - case ServerInfo::TMWATHENA: - case ServerInfo::EVOL: + case ServerType::TMWATHENA: + case ServerType::EVOL: return ""; #endif #ifdef EATHENA_SUPPORT - case ServerInfo::EATHENA: + case ServerType::EATHENA: return "eAthena"; - case ServerInfo::EVOL2: + case ServerType::EVOL2: return "Evol2"; #else - case ServerInfo::EATHENA: - case ServerInfo::EVOL2: + case ServerType::EATHENA: + case ServerType::EVOL2: return ""; #endif default: - case ServerInfo::UNKNOWN: + case ServerType::UNKNOWN: return ""; } } -static uint16_t defaultPortForServerType(const ServerInfo::Type type) +static uint16_t defaultPortForServerType(const ServerType::Type type) { switch (type) { default: - case ServerInfo::EATHENA: - case ServerInfo::EVOL2: + case ServerType::EATHENA: + case ServerType::EVOL2: #ifdef EATHENA_SUPPORT return 6900; #endif - case ServerInfo::UNKNOWN: + case ServerType::UNKNOWN: #ifdef TMWA_SUPPORT - case ServerInfo::TMWATHENA: - case ServerInfo::EVOL: + case ServerType::TMWATHENA: + case ServerType::EVOL: #endif return 6901; } @@ -492,7 +492,7 @@ void ServerDialog::loadServers(const bool addNew) server.type = ServerInfo::parseType(type); // Ignore unknown server types - if (server.type == ServerInfo::UNKNOWN) + if (server.type == ServerType::UNKNOWN) { logger->log("Ignoring server entry with unknown type: %s", type.c_str()); diff --git a/src/net/eathena/serverfeatures.cpp b/src/net/eathena/serverfeatures.cpp index 8cf172d20..956c134e3 100644 --- a/src/net/eathena/serverfeatures.cpp +++ b/src/net/eathena/serverfeatures.cpp @@ -162,7 +162,7 @@ bool ServerFeatures::haveBankApi() const bool ServerFeatures::haveServerVersion() const { - return Net::getNetworkType() == ServerInfo::EVOL2; + return Net::getNetworkType() == ServerType::EVOL2; } bool ServerFeatures::haveMapServerVersion() const diff --git a/src/net/net.cpp b/src/net/net.cpp index 6c832e5f4..e744786cd 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -102,7 +102,7 @@ Net::MarketHandler *marketHandler = nullptr; namespace Net { -ServerInfo::Type networkType = ServerInfo::UNKNOWN; +ServerType::Type networkType = ServerType::UNKNOWN; std::set ignorePackets; void connectToServer(const ServerInfo &server) @@ -114,22 +114,22 @@ void connectToServer(const ServerInfo &server) } else { - if (networkType != ServerInfo::UNKNOWN && generalHandler) + if (networkType != ServerType::UNKNOWN && generalHandler) generalHandler->unload(); switch (server.type) { - case ServerInfo::EATHENA: - case ServerInfo::EVOL2: + case ServerType::EATHENA: + case ServerType::EVOL2: #ifdef EATHENA_SUPPORT new EAthena::GeneralHandler; #else new TmwAthena::GeneralHandler; #endif break; - case ServerInfo::TMWATHENA: - case ServerInfo::EVOL: - case ServerInfo::UNKNOWN: + case ServerType::TMWATHENA: + case ServerType::EVOL: + case ServerType::UNKNOWN: default: #ifdef TMWA_SUPPORT new TmwAthena::GeneralHandler; @@ -160,7 +160,7 @@ void unload() ignorePackets.clear(); } -ServerInfo::Type getNetworkType() +ServerType::Type getNetworkType() { return networkType; } diff --git a/src/net/net.h b/src/net/net.h index 9c8b3f4de..ccd363b81 100644 --- a/src/net/net.h +++ b/src/net/net.h @@ -36,7 +36,7 @@ namespace Net { -ServerInfo::Type getNetworkType() A_WARN_UNUSED; +ServerType::Type getNetworkType() A_WARN_UNUSED; /** * Handles server detection and connection diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h index 35e40e889..a1b0c5b41 100644 --- a/src/net/serverinfo.h +++ b/src/net/serverinfo.h @@ -23,6 +23,8 @@ #ifndef NET_SERVERINFO_H #define NET_SERVERINFO_H +#include "enums/net/servertype.h" + #include "utils/stringutils.h" #include @@ -35,18 +37,9 @@ class ServerInfo final { public: - enum Type - { - UNKNOWN = 0, - TMWATHENA, - EVOL, - EATHENA, - EVOL2 - }; - typedef std::pair VersionString; - Type type; + ServerType::Type type; std::string name; std::string hostname; std::string althostname; @@ -61,7 +54,7 @@ class ServerInfo final bool persistentIp; ServerInfo() : - type(TMWATHENA), + type(ServerType::TMWATHENA), name(), hostname(), althostname(), @@ -103,12 +96,14 @@ class ServerInfo final bool isValid() const A_WARN_UNUSED { - return !(hostname.empty() || port == 0 || type == UNKNOWN); + return !(hostname.empty() + || port == 0 + || type == ServerType::UNKNOWN); } void clear() { - type = UNKNOWN; + type = ServerType::UNKNOWN; name.clear(); hostname.clear(); althostname.clear(); @@ -136,30 +131,31 @@ class ServerInfo final port != other.port); } - static Type parseType(const std::string &serverType) A_WARN_UNUSED + static ServerType::Type parseType(const std::string &serverType) + A_WARN_UNUSED { #ifdef TMWA_SUPPORT if (compareStrI(serverType, "tmwathena") == 0) - return TMWATHENA; + return ServerType::TMWATHENA; if (compareStrI(serverType, "evol") == 0) - return EVOL; + return ServerType::EVOL; #else if (compareStrI(serverType, "tmwathena") == 0 || compareStrI(serverType, "evol") == 0) - return EATHENA; + return ServerType::EATHENA; #endif #ifdef EATHENA_SUPPORT else if (compareStrI(serverType, "eathena") == 0) - return EATHENA; + return ServerType::EATHENA; else if (compareStrI(serverType, "evol2") == 0) - return EVOL2; + return ServerType::EVOL2; #else else if (compareStrI(serverType, "eathena") == 0) - return TMWATHENA; + return ServerType::TMWATHENA; else if (compareStrI(serverType, "evol2") == 0) - return TMWATHENA; + return ServerType::TMWATHENA; #endif - return UNKNOWN; + return ServerType::UNKNOWN; } }; -- cgit v1.2.3-70-g09d2