aboutsummaryrefslogtreecommitdiff
path: root/src/server/authserver
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/authserver')
-rw-r--r--src/server/authserver/CMakeLists.txt95
-rw-r--r--src/server/authserver/Main.cpp7
-rw-r--r--src/server/authserver/Realms/RealmList.cpp153
-rw-r--r--src/server/authserver/Realms/RealmList.h97
-rw-r--r--src/server/authserver/Server/AuthSession.cpp36
-rw-r--r--src/server/authserver/Server/AuthSocketMgr.h4
-rw-r--r--src/server/authserver/authserver.conf.dist7
7 files changed, 67 insertions, 332 deletions
diff --git a/src/server/authserver/CMakeLists.txt b/src/server/authserver/CMakeLists.txt
index d87847d6740..d1f0e4460e9 100644
--- a/src/server/authserver/CMakeLists.txt
+++ b/src/server/authserver/CMakeLists.txt
@@ -10,66 +10,29 @@
########### authserver ###############
-file(GLOB_RECURSE sources_authentication Authentication/*.cpp Authentication/*.h)
-file(GLOB_RECURSE sources_realms Realms/*.cpp Realms/*.h)
-file(GLOB_RECURSE sources_server Server/*.cpp Server/*.h)
-file(GLOB sources_localdir *.cpp *.h)
-
-if (USE_COREPCH)
- set(authserver_PCH_HDR PrecompiledHeaders/authPCH.h)
- set(authserver_PCH_SRC PrecompiledHeaders/authPCH.cpp)
-endif()
-
-set(authserver_SRCS
- ${authserver_SRCS}
- ${sources_authentication}
- ${sources_realms}
- ${sources_server}
- ${sources_localdir}
-)
+CollectSourceFiles(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ PRIVATE_SOURCES
+ # Exclude
+ ${CMAKE_CURRENT_SOURCE_DIR}/PrecompiledHeaders)
if( WIN32 )
- set(authserver_SRCS
- ${authserver_SRCS}
- ${sources_windows_Debugging}
- )
+ list(APPEND PRIVATE_SOURCES ${sources_windows})
if ( MSVC )
- set(authserver_SRCS
- ${authserver_SRCS}
- authserver.rc
- )
- endif ()
+ list(APPEND PRIVATE_SOURCES authserver.rc)
+ endif()
endif()
-include_directories(
- ${CMAKE_BINARY_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/Authentication
- ${CMAKE_CURRENT_SOURCE_DIR}/Realms
- ${CMAKE_CURRENT_SOURCE_DIR}/Server
- ${CMAKE_SOURCE_DIR}/dep/cppformat
- ${CMAKE_SOURCE_DIR}/src/common/
- ${CMAKE_SOURCE_DIR}/src/common/Configuration
- ${CMAKE_SOURCE_DIR}/src/common/Cryptography
- ${CMAKE_SOURCE_DIR}/src/common/Debugging
- ${CMAKE_SOURCE_DIR}/src/common/Logging
- ${CMAKE_SOURCE_DIR}/src/common/Threading
- ${CMAKE_SOURCE_DIR}/src/common/Utilities
- ${CMAKE_SOURCE_DIR}/src/server/database
- ${CMAKE_SOURCE_DIR}/src/server/database/Database
- ${CMAKE_SOURCE_DIR}/src/server/database/Logging
- ${CMAKE_SOURCE_DIR}/src/server/shared/Networking
- ${CMAKE_SOURCE_DIR}/src/server/shared/Packets
- ${CMAKE_SOURCE_DIR}/src/server/shared/Service
- ${MYSQL_INCLUDE_DIR}
- ${OPENSSL_INCLUDE_DIR}
- ${VALGRIND_INCLUDE_DIR}
-)
+if (USE_COREPCH)
+ set(PRIVATE_PCH_HEADER PrecompiledHeaders/authPCH.h)
+ set(PRIVATE_PCH_SOURCE PrecompiledHeaders/authPCH.cpp)
+endif()
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
add_executable(authserver
- ${authserver_SRCS}
- ${authserver_PCH_SRC}
+ ${PRIVATE_PCH_SOURCE}
+ ${PRIVATE_SOURCES}
)
if( NOT WIN32 )
@@ -79,15 +42,25 @@ if( NOT WIN32 )
endif()
target_link_libraries(authserver
- shared
- database
- common
- format
- ${MYSQL_LIBRARY}
- ${OPENSSL_LIBRARIES}
- ${CMAKE_THREAD_LIBS_INIT}
- ${Boost_LIBRARIES}
-)
+ PUBLIC
+ shared)
+
+CollectIncludeDirectories(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ PUBLIC_INCLUDES
+ # Exclude
+ ${CMAKE_CURRENT_SOURCE_DIR}/PrecompiledHeaders)
+
+target_include_directories(authserver
+ PUBLIC
+ ${PUBLIC_INCLUDES}
+ PRIVATE
+ ${CMAKE_CURRENT_BINARY_DIR})
+
+set_target_properties(authserver
+ PROPERTIES
+ FOLDER
+ "server")
if( WIN32 )
if ( MSVC )
@@ -113,5 +86,5 @@ endif()
# Generate precompiled header
if (USE_COREPCH)
- add_cxx_pch(authserver ${authserver_PCH_HDR} ${authserver_PCH_SRC})
+ add_cxx_pch(authserver ${PRIVATE_PCH_HEADER} ${PRIVATE_PCH_SOURCE})
endif()
diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp
index 0618ec437b6..a53187ad737 100644
--- a/src/server/authserver/Main.cpp
+++ b/src/server/authserver/Main.cpp
@@ -76,10 +76,11 @@ boost::asio::deadline_timer* _dbPingTimer;
uint32 _dbPingInterval;
boost::asio::deadline_timer* _banExpiryCheckTimer;
uint32 _banExpiryCheckInterval;
-LoginDatabaseWorkerPool LoginDatabase;
int main(int argc, char** argv)
{
+ signal(SIGABRT, &Trinity::AbortHandler);
+
std::string configFile = _TRINITY_REALM_CONFIG;
std::string configService;
auto vm = GetConsoleArguments(argc, argv, configFile, configService);
@@ -134,7 +135,7 @@ int main(int argc, char** argv)
// Get the list of realms for the server
sRealmList->Initialize(*_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 20));
- if (sRealmList->size() == 0)
+ if (sRealmList->GetRealms().empty())
{
TC_LOG_ERROR("server.authserver", "No valid realms specified.");
StopDB();
@@ -194,6 +195,8 @@ int main(int argc, char** argv)
sAuthSocketMgr.StopNetwork();
+ sRealmList->Close();
+
// Close the Database Pool and library
StopDB();
diff --git a/src/server/authserver/Realms/RealmList.cpp b/src/server/authserver/Realms/RealmList.cpp
deleted file mode 100644
index 53aeff6133b..00000000000
--- a/src/server/authserver/Realms/RealmList.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * 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 (at your
- * option) 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 <http://www.gnu.org/licenses/>.
- */
-
-#include <boost/asio/ip/tcp.hpp>
-#include "Common.h"
-#include "RealmList.h"
-#include "Database/DatabaseEnv.h"
-
-namespace boost { namespace asio { namespace ip { class address; } } }
-
-RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL)), _resolver(nullptr) { }
-RealmList::~RealmList()
-{
- delete _resolver;
-}
-
-// Load the realm list from the database
-void RealmList::Initialize(boost::asio::io_service& ioService, uint32 updateInterval)
-{
- _resolver = new boost::asio::ip::tcp::resolver(ioService);
- m_UpdateInterval = updateInterval;
-
- // Get the content of the realmlist table in the database
- UpdateRealms(true);
-}
-
-void RealmList::UpdateRealm(uint32 id, const std::string& name, ip::address const& address, ip::address const& localAddr,
- ip::address const& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population, uint32 build)
-{
- // Create new if not exist or update existed
- Realm& realm = m_realms[name];
-
- realm.m_ID = id;
- realm.name = name;
- realm.icon = icon;
- realm.flag = flag;
- realm.timezone = timezone;
- realm.allowedSecurityLevel = allowedSecurityLevel;
- realm.populationLevel = population;
-
- // Append port to IP address.
-
- realm.ExternalAddress = address;
- realm.LocalAddress = localAddr;
- realm.LocalSubnetMask = localSubmask;
- realm.port = port;
- realm.gamebuild = build;
-}
-
-void RealmList::UpdateIfNeed()
-{
- // maybe disabled or updated recently
- if (!m_UpdateInterval || m_NextUpdateTime > time(NULL))
- return;
-
- m_NextUpdateTime = time(NULL) + m_UpdateInterval;
-
- // Clears Realm list
- m_realms.clear();
-
- // Get the content of the realmlist table in the database
- UpdateRealms();
-}
-
-void RealmList::UpdateRealms(bool init)
-{
- TC_LOG_INFO("server.authserver", "Updating Realm List...");
-
- PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_REALMLIST);
- PreparedQueryResult result = LoginDatabase.Query(stmt);
-
- // Circle through results and add them to the realm map
- if (result)
- {
- do
- {
- try
- {
- boost::asio::ip::tcp::resolver::iterator end;
-
- Field* fields = result->Fetch();
- uint32 realmId = fields[0].GetUInt32();
- std::string name = fields[1].GetString();
- boost::asio::ip::tcp::resolver::query externalAddressQuery(ip::tcp::v4(), fields[2].GetString(), "");
-
- boost::system::error_code ec;
- boost::asio::ip::tcp::resolver::iterator endPoint = _resolver->resolve(externalAddressQuery, ec);
- if (endPoint == end || ec)
- {
- TC_LOG_ERROR("server.authserver", "Could not resolve address %s", fields[2].GetString().c_str());
- return;
- }
-
- ip::address externalAddress = (*endPoint).endpoint().address();
-
- boost::asio::ip::tcp::resolver::query localAddressQuery(ip::tcp::v4(), fields[3].GetString(), "");
- endPoint = _resolver->resolve(localAddressQuery, ec);
- if (endPoint == end || ec)
- {
- TC_LOG_ERROR("server.authserver", "Could not resolve address %s", fields[3].GetString().c_str());
- return;
- }
-
- ip::address localAddress = (*endPoint).endpoint().address();
-
- boost::asio::ip::tcp::resolver::query localSubmaskQuery(ip::tcp::v4(), fields[4].GetString(), "");
- endPoint = _resolver->resolve(localSubmaskQuery, ec);
- if (endPoint == end || ec)
- {
- TC_LOG_ERROR("server.authserver", "Could not resolve address %s", fields[4].GetString().c_str());
- return;
- }
-
- ip::address localSubmask = (*endPoint).endpoint().address();
-
- uint16 port = fields[5].GetUInt16();
- uint8 icon = fields[6].GetUInt8();
- RealmFlags flag = RealmFlags(fields[7].GetUInt8());
- uint8 timezone = fields[8].GetUInt8();
- uint8 allowedSecurityLevel = fields[9].GetUInt8();
- float pop = fields[10].GetFloat();
- uint32 build = fields[11].GetUInt32();
-
- UpdateRealm(realmId, name, externalAddress, localAddress, localSubmask, port, icon, flag, timezone,
- (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop, build);
-
- if (init)
- TC_LOG_INFO("server.authserver", "Added realm \"%s\" at %s:%u.", name.c_str(), m_realms[name].ExternalAddress.to_string().c_str(), port);
- }
- catch (std::exception& ex)
- {
- TC_LOG_ERROR("server.authserver", "Realmlist::UpdateRealms has thrown an exception: %s", ex.what());
- ABORT();
- }
- }
- while (result->NextRow());
- }
-}
diff --git a/src/server/authserver/Realms/RealmList.h b/src/server/authserver/Realms/RealmList.h
deleted file mode 100644
index cc5c88c01f2..00000000000
--- a/src/server/authserver/Realms/RealmList.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * 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 (at your
- * option) 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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef _REALMLIST_H
-#define _REALMLIST_H
-
-#include <boost/asio/ip/address.hpp>
-#include <boost/asio/ip/tcp.hpp>
-#include <boost/asio/io_service.hpp>
-#include "Common.h"
-
-using namespace boost::asio;
-
-enum RealmFlags
-{
- REALM_FLAG_NONE = 0x00,
- REALM_FLAG_INVALID = 0x01,
- REALM_FLAG_OFFLINE = 0x02,
- REALM_FLAG_SPECIFYBUILD = 0x04,
- REALM_FLAG_UNK1 = 0x08,
- REALM_FLAG_UNK2 = 0x10,
- REALM_FLAG_RECOMMENDED = 0x20,
- REALM_FLAG_NEW = 0x40,
- REALM_FLAG_FULL = 0x80
-};
-
-// Storage object for a realm
-struct Realm
-{
- ip::address ExternalAddress;
- ip::address LocalAddress;
- ip::address LocalSubnetMask;
- uint16 port;
- std::string name;
- uint8 icon;
- RealmFlags flag;
- uint8 timezone;
- uint32 m_ID;
- AccountTypes allowedSecurityLevel;
- float populationLevel;
- uint32 gamebuild;
-};
-
-/// Storage object for the list of realms on the server
-class RealmList
-{
-public:
- typedef std::map<std::string, Realm> RealmMap;
-
- static RealmList* instance()
- {
- static RealmList instance;
- return &instance;
- }
-
- ~RealmList();
-
- void Initialize(boost::asio::io_service& ioService, uint32 updateInterval);
-
- void UpdateIfNeed();
-
- void AddRealm(const Realm& NewRealm) { m_realms[NewRealm.name] = NewRealm; }
-
- RealmMap::const_iterator begin() const { return m_realms.begin(); }
- RealmMap::const_iterator end() const { return m_realms.end(); }
- uint32 size() const { return m_realms.size(); }
-
-private:
- RealmList();
-
- void UpdateRealms(bool init = false);
- void UpdateRealm(uint32 id, const std::string& name, ip::address const& address, ip::address const& localAddr,
- ip::address const& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population, uint32 build);
-
- RealmMap m_realms;
- uint32 m_UpdateInterval;
- time_t m_NextUpdateTime;
- boost::asio::ip::tcp::resolver* _resolver;
-};
-
-#define sRealmList RealmList::instance()
-#endif
diff --git a/src/server/authserver/Server/AuthSession.cpp b/src/server/authserver/Server/AuthSession.cpp
index 57e5d6682f2..f044e0cea94 100644
--- a/src/server/authserver/Server/AuthSession.cpp
+++ b/src/server/authserver/Server/AuthSession.cpp
@@ -146,6 +146,11 @@ void AccountInfo::LoadResult(Field* fields)
IsBanned = fields[6].GetUInt64() != 0;
IsPermanenetlyBanned = fields[7].GetUInt64() != 0;
SecurityLevel = AccountTypes(fields[8].GetUInt8());
+
+ // Use our own uppercasing of the account name instead of using UPPER() in mysql query
+ // This is how the account was created in the first place and changing it now would result in breaking
+ // login for all accounts having accented characters in their name
+ Utf8ToUpperOnlyLatin(Login);
}
AuthSession::AuthSession(tcp::socket&& socket) : Socket(std::move(socket)),
@@ -844,7 +849,7 @@ tcp::endpoint const GetAddressForClient(Realm const& realm, ip::address const& c
realmIp = realm.ExternalAddress;
}
- tcp::endpoint endpoint(realmIp, realm.port);
+ tcp::endpoint endpoint(realmIp, realm.Port);
// Return external IP
return endpoint;
@@ -880,22 +885,19 @@ void AuthSession::RealmListCallback(PreparedQueryResult result)
} while (result->NextRow());
}
- // Update realm list if need
- sRealmList->UpdateIfNeed();
-
// Circle through realms in the RealmList and construct the return packet (including # of user characters in each realm)
ByteBuffer pkt;
size_t RealmListSize = 0;
- for (RealmList::RealmMap::const_iterator i = sRealmList->begin(); i != sRealmList->end(); ++i)
+ for (RealmList::RealmMap::value_type const& i : sRealmList->GetRealms())
{
- const Realm &realm = i->second;
+ const Realm &realm = i.second;
// don't work with realms which not compatible with the client
- bool okBuild = ((_expversion & POST_BC_EXP_FLAG) && realm.gamebuild == _build) || ((_expversion & PRE_BC_EXP_FLAG) && !AuthHelper::IsPreBCAcceptedClientBuild(realm.gamebuild));
+ bool okBuild = ((_expversion & POST_BC_EXP_FLAG) && realm.Build == _build) || ((_expversion & PRE_BC_EXP_FLAG) && !AuthHelper::IsPreBCAcceptedClientBuild(realm.Build));
// No SQL injection. id of realm is controlled by the database.
- uint32 flag = realm.flag;
- RealmBuildInfo const* buildInfo = AuthHelper::GetBuildInfo(realm.gamebuild);
+ uint32 flag = realm.Flags;
+ RealmBuildInfo const* buildInfo = AuthHelper::GetBuildInfo(realm.Build);
if (!okBuild)
{
if (!buildInfo)
@@ -907,7 +909,7 @@ void AuthSession::RealmListCallback(PreparedQueryResult result)
if (!buildInfo)
flag &= ~REALM_FLAG_SPECIFYBUILD;
- std::string name = i->first;
+ std::string name = realm.Name;
if (_expversion & PRE_BC_EXP_FLAG && flag & REALM_FLAG_SPECIFYBUILD)
{
std::ostringstream ss;
@@ -915,19 +917,19 @@ void AuthSession::RealmListCallback(PreparedQueryResult result)
name = ss.str();
}
- uint8 lock = (realm.allowedSecurityLevel > _accountInfo.SecurityLevel) ? 1 : 0;
+ uint8 lock = (realm.AllowedSecurityLevel > _accountInfo.SecurityLevel) ? 1 : 0;
- pkt << uint8(realm.icon); // realm type
+ pkt << uint8(realm.Type); // realm type
if (_expversion & POST_BC_EXP_FLAG) // only 2.x and 3.x clients
pkt << uint8(lock); // if 1, then realm locked
pkt << uint8(flag); // RealmFlags
pkt << name;
- pkt << boost::lexical_cast<std::string>(GetAddressForClient(realm, GetRemoteIpAddress()));
- pkt << float(realm.populationLevel);
- pkt << uint8(characterCounts[realm.m_ID]);
- pkt << uint8(realm.timezone); // realm category
+ pkt << boost::lexical_cast<std::string>(realm.GetAddressForClient(GetRemoteIpAddress()));
+ pkt << float(realm.PopulationLevel);
+ pkt << uint8(characterCounts[realm.Id.Realm]);
+ pkt << uint8(realm.Timezone); // realm category
if (_expversion & POST_BC_EXP_FLAG) // 2.x and 3.x clients
- pkt << uint8(realm.m_ID);
+ pkt << uint8(realm.Id.Realm);
else
pkt << uint8(0x0); // 1.12.1 and 1.12.2 clients
diff --git a/src/server/authserver/Server/AuthSocketMgr.h b/src/server/authserver/Server/AuthSocketMgr.h
index a16b7d405b9..9923f2b2f11 100644
--- a/src/server/authserver/Server/AuthSocketMgr.h
+++ b/src/server/authserver/Server/AuthSocketMgr.h
@@ -32,9 +32,9 @@ public:
return instance;
}
- bool StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port) override
+ bool StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port, int threadCount = 1) override
{
- if (!BaseSocketMgr::StartNetwork(service, bindIp, port))
+ if (!BaseSocketMgr::StartNetwork(service, bindIp, port, threadCount))
return false;
_acceptor->AsyncAcceptWithCallback<&AuthSocketMgr::OnSocketAccept>();
diff --git a/src/server/authserver/authserver.conf.dist b/src/server/authserver/authserver.conf.dist
index a97d75b3f57..db60e3b3ece 100644
--- a/src/server/authserver/authserver.conf.dist
+++ b/src/server/authserver/authserver.conf.dist
@@ -184,6 +184,13 @@ LoginDatabaseInfo = "127.0.0.1;3306;trinity;trinity;auth"
LoginDatabase.WorkerThreads = 1
#
+# LoginDatabase.SynchThreads
+# Description: The amount of MySQL connections spawned to handle.
+# Default: 1 - (LoginDatabase.WorkerThreads)
+
+LoginDatabase.SynchThreads = 1
+
+#
###################################################################################################
###################################################################################################