aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/shared')
-rw-r--r--src/server/shared/CMakeLists.txt103
-rw-r--r--src/server/shared/DataStores/DB2StorageLoader.h4
-rw-r--r--src/server/shared/DataStores/DBCFileLoader.h2
-rw-r--r--src/server/shared/Networking/AsyncAcceptor.h1
-rw-r--r--src/server/shared/Networking/Socket.h25
-rw-r--r--src/server/shared/Packets/ByteBuffer.h8
-rw-r--r--src/server/shared/Realm/Realm.h4
-rw-r--r--src/server/shared/Service/ServiceWin32.cpp264
-rw-r--r--src/server/shared/Service/ServiceWin32.h29
9 files changed, 74 insertions, 366 deletions
diff --git a/src/server/shared/CMakeLists.txt b/src/server/shared/CMakeLists.txt
index fd6ff91e135..ce6c13bd932 100644
--- a/src/server/shared/CMakeLists.txt
+++ b/src/server/shared/CMakeLists.txt
@@ -8,74 +8,61 @@
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-if( USE_COREPCH )
- include_directories(${CMAKE_CURRENT_BINARY_DIR})
-endif()
-
-file(GLOB_RECURSE sources_Cryptography Cryptography/*.cpp Cryptography/*.h)
-file(GLOB_RECURSE sources_DataStores DataStores/*.cpp DataStores/*.h)
-file(GLOB_RECURSE sources_Dynamic Dynamic/*.cpp Dynamic/*.h)
-file(GLOB_RECURSE sources_Networking Networking/*.cpp Networking/*.h)
-file(GLOB_RECURSE sources_Packets Packets/*.cpp Packets/*.h)
-file(GLOB_RECURSE sources_Realm Realm/*.cpp Realm/*.h)
-if(WIN32)
- file(GLOB_RECURSE sources_Service Service/*.cpp Service/*.h)
-endif(WIN32)
-
-file(GLOB sources_localdir *.cpp *.h)
-
-# Manually set sources for Debugging directory as we don't want to include WheatyExceptionReport in shared project
-# It needs to be included both in bnetserver and worldserver for the static global variable to be properly initialized
-# and to handle crash logs on windows
-set(sources_Debugging Debugging/Errors.cpp Debugging/Errors.h)
-
-#
-# Build shared sourcelist
-#
+CollectSourceFiles(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ PRIVATE_SOURCES
+ # Exclude
+ ${CMAKE_CURRENT_SOURCE_DIR}/PrecompiledHeaders)
if (USE_COREPCH)
- set(shared_STAT_PCH_HDR PrecompiledHeaders/sharedPCH.h)
- set(shared_STAT_PCH_SRC PrecompiledHeaders/sharedPCH.cpp)
+ set(PRIVATE_PCH_HEADER PrecompiledHeaders/sharedPCH.h)
+ set(PRIVATE_PCH_SOURCE PrecompiledHeaders/sharedPCH.cpp)
endif()
-set(shared_STAT_SRCS
- ${shared_STAT_SRCS}
- ${sources_Cryptography}
- ${sources_DataStores}
- ${sources_Dynamic}
- ${sources_Networking}
- ${sources_Packets}
- ${sources_Realm}
- ${sources_Service}
- ${sources_localdir}
-)
+GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
+
+add_definitions(-DTRINITY_API_EXPORT_SHARED)
-include_directories(
- ${CMAKE_CURRENT_SOURCE_DIR}/Dynamic
- ${CMAKE_CURRENT_SOURCE_DIR}/Networking
- ${CMAKE_SOURCE_DIR}/dep/cppformat
- ${CMAKE_SOURCE_DIR}/src/common/
- ${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
- ${MYSQL_INCLUDE_DIR}
- ${OPENSSL_INCLUDE_DIR}
- ${VALGRIND_INCLUDE_DIR}
+add_library(shared
+ ${PRIVATE_SOURCES}
+ ${PRIVATE_PCH_SOURCE}
)
-GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
+CollectIncludeDirectories(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ PUBLIC_INCLUDES
+ # Exclude
+ ${CMAKE_CURRENT_SOURCE_DIR}/PrecompiledHeaders)
-add_library(shared STATIC
- ${shared_STAT_SRCS}
- ${shared_STAT_PCH_SRC}
-)
+target_include_directories(shared
+ PUBLIC
+ ${PUBLIC_INCLUDES}
+ PRIVATE
+ ${CMAKE_CURRENT_BINARY_DIR})
-add_dependencies(shared revision_data.h)
+target_link_libraries(shared
+ PUBLIC
+ database
+ rapidjson)
+
+set_target_properties(shared
+ PROPERTIES
+ FOLDER
+ "server")
+
+if( BUILD_SHARED_LIBS )
+ if( UNIX )
+ install(TARGETS shared
+ LIBRARY
+ DESTINATION lib)
+ elseif( WIN32 )
+ install(TARGETS shared
+ RUNTIME
+ DESTINATION "${CMAKE_INSTALL_PREFIX}")
+ endif()
+endif()
# Generate precompiled header
if (USE_COREPCH)
- add_cxx_pch(shared ${shared_STAT_PCH_HDR} ${shared_STAT_PCH_SRC})
+ add_cxx_pch(shared ${PRIVATE_PCH_HEADER} ${PRIVATE_PCH_SOURCE})
endif ()
diff --git a/src/server/shared/DataStores/DB2StorageLoader.h b/src/server/shared/DataStores/DB2StorageLoader.h
index 0b83bc43dc4..41705c67f19 100644
--- a/src/server/shared/DataStores/DB2StorageLoader.h
+++ b/src/server/shared/DataStores/DB2StorageLoader.h
@@ -24,7 +24,7 @@
#include <cassert>
#include <list>
-class DB2FileLoader
+class TC_SHARED_API DB2FileLoader
{
public:
DB2FileLoader();
@@ -114,7 +114,7 @@ private:
int unk5; // WDB2
};
-class DB2DatabaseLoader
+class TC_SHARED_API DB2DatabaseLoader
{
public:
explicit DB2DatabaseLoader(std::string const& storageName) : _storageName(storageName) { }
diff --git a/src/server/shared/DataStores/DBCFileLoader.h b/src/server/shared/DataStores/DBCFileLoader.h
index cbbd786337c..e58031e6ccc 100644
--- a/src/server/shared/DataStores/DBCFileLoader.h
+++ b/src/server/shared/DataStores/DBCFileLoader.h
@@ -23,7 +23,7 @@
#include "Utilities/ByteConverter.h"
#include <cassert>
-class DBCFileLoader
+class TC_SHARED_API DBCFileLoader
{
public:
DBCFileLoader();
diff --git a/src/server/shared/Networking/AsyncAcceptor.h b/src/server/shared/Networking/AsyncAcceptor.h
index d21801a64ac..e2f4045ccff 100644
--- a/src/server/shared/Networking/AsyncAcceptor.h
+++ b/src/server/shared/Networking/AsyncAcceptor.h
@@ -21,6 +21,7 @@
#include "Log.h"
#include <boost/asio.hpp>
#include <functional>
+#include <atomic>
using boost::asio::ip::tcp;
diff --git a/src/server/shared/Networking/Socket.h b/src/server/shared/Networking/Socket.h
index 07f427652aa..0674ede57d8 100644
--- a/src/server/shared/Networking/Socket.h
+++ b/src/server/shared/Networking/Socket.h
@@ -55,11 +55,11 @@ public:
virtual bool Update()
{
- if (!IsOpen())
+ if (_closed)
return false;
#ifndef TC_SOCKET_USE_IOCP
- if (_isWritingAsync || _writeQueue.empty())
+ if (_isWritingAsync || (_writeQueue.empty() && !_closing))
return true;
for (; HandleQueue();)
@@ -90,6 +90,17 @@ public:
std::bind(&Socket<T>::ReadHandlerInternal, this->shared_from_this(), std::placeholders::_1, std::placeholders::_2));
}
+ void AsyncReadWithCallback(void (T::*callback)(boost::system::error_code, std::size_t))
+ {
+ if (!IsOpen())
+ return;
+
+ _readBuffer.Normalize();
+ _readBuffer.EnsureFreeSpace();
+ _socket.async_read_some(boost::asio::buffer(_readBuffer.GetWritePointer(), _readBuffer.GetRemainingSpace()),
+ std::bind(callback, this->shared_from_this(), std::placeholders::_1, std::placeholders::_2));
+ }
+
void QueuePacket(MessageBuffer&& buffer)
{
_writeQueue.push(std::move(buffer));
@@ -153,7 +164,6 @@ protected:
GetRemoteIpAddress().to_string().c_str(), err.value(), err.message().c_str());
}
-
private:
void ReadHandlerInternal(boost::system::error_code error, size_t transferredBytes)
{
@@ -197,9 +207,6 @@ private:
bool HandleQueue()
{
- if (!IsOpen())
- return false;
-
if (_writeQueue.empty())
return false;
@@ -216,11 +223,15 @@ private:
return AsyncProcessQueue();
_writeQueue.pop();
+ if (_closing && _writeQueue.empty())
+ CloseSocket();
return false;
}
else if (bytesSent == 0)
{
_writeQueue.pop();
+ if (_closing && _writeQueue.empty())
+ CloseSocket();
return false;
}
else if (bytesSent < bytesToSend) // now n > 0
@@ -230,6 +241,8 @@ private:
}
_writeQueue.pop();
+ if (_closing && _writeQueue.empty())
+ CloseSocket();
return !_writeQueue.empty();
}
diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h
index b8c6ee1c36e..2373e632c44 100644
--- a/src/server/shared/Packets/ByteBuffer.h
+++ b/src/server/shared/Packets/ByteBuffer.h
@@ -37,7 +37,7 @@
class MessageBuffer;
// Root of ByteBuffer exception hierarchy
-class ByteBufferException : public std::exception
+class TC_SHARED_API ByteBufferException : public std::exception
{
public:
~ByteBufferException() throw() { }
@@ -51,7 +51,7 @@ private:
std::string msg_;
};
-class ByteBufferPositionException : public ByteBufferException
+class TC_SHARED_API ByteBufferPositionException : public ByteBufferException
{
public:
ByteBufferPositionException(bool add, size_t pos, size_t size, size_t valueSize);
@@ -59,7 +59,7 @@ public:
~ByteBufferPositionException() throw() { }
};
-class ByteBufferSourceException : public ByteBufferException
+class TC_SHARED_API ByteBufferSourceException : public ByteBufferException
{
public:
ByteBufferSourceException(size_t pos, size_t size, size_t valueSize);
@@ -67,7 +67,7 @@ public:
~ByteBufferSourceException() throw() { }
};
-class ByteBuffer
+class TC_SHARED_API ByteBuffer
{
public:
static size_t const DEFAULT_SIZE = 0x1000;
diff --git a/src/server/shared/Realm/Realm.h b/src/server/shared/Realm/Realm.h
index 585a98e4569..87d333a4bf6 100644
--- a/src/server/shared/Realm/Realm.h
+++ b/src/server/shared/Realm/Realm.h
@@ -41,7 +41,7 @@ enum RealmFlags
namespace Battlenet
{
- struct RealmHandle
+ struct TC_SHARED_API RealmHandle
{
RealmHandle() : Region(0), Site(0), Realm(0) { }
RealmHandle(uint8 region, uint8 battlegroup, uint32 index)
@@ -78,7 +78,7 @@ enum RealmType
};
// Storage object for a realm
-struct Realm
+struct TC_SHARED_API Realm
{
Battlenet::RealmHandle Id;
uint32 Build;
diff --git a/src/server/shared/Service/ServiceWin32.cpp b/src/server/shared/Service/ServiceWin32.cpp
deleted file mode 100644
index b6a1682993b..00000000000
--- a/src/server/shared/Service/ServiceWin32.cpp
+++ /dev/null
@@ -1,264 +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/>.
- */
-
-#ifdef _WIN32
-
-#include "Common.h"
-#include "Log.h"
-#include <cstring>
-#include <windows.h>
-#include <winsvc.h>
-
-#if !defined(WINADVAPI)
-#if !defined(_ADVAPI32_)
-#define WINADVAPI DECLSPEC_IMPORT
-#else
-#define WINADVAPI
-#endif
-#endif
-
-extern int main(int argc, char ** argv);
-extern char serviceLongName[];
-extern char serviceName[];
-extern char serviceDescription[];
-
-extern int m_ServiceStatus;
-
-SERVICE_STATUS serviceStatus;
-
-SERVICE_STATUS_HANDLE serviceStatusHandle = 0;
-
-typedef WINADVAPI BOOL (WINAPI *CSD_T)(SC_HANDLE, DWORD, LPCVOID);
-
-bool WinServiceInstall()
-{
- SC_HANDLE serviceControlManager = OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE);
-
- if (serviceControlManager)
- {
- char path[_MAX_PATH + 10];
- if (GetModuleFileName( 0, path, sizeof(path)/sizeof(path[0]) ) > 0)
- {
- SC_HANDLE service;
- std::strcat(path, " --service run");
- service = CreateService(serviceControlManager,
- serviceName, // name of service
- serviceLongName, // service name to display
- SERVICE_ALL_ACCESS, // desired access
- // service type
- SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
- SERVICE_AUTO_START, // start type
- SERVICE_ERROR_IGNORE, // error control type
- path, // service's binary
- 0, // no load ordering group
- 0, // no tag identifier
- 0, // no dependencies
- 0, // LocalSystem account
- 0); // no password
- if (service)
- {
- HMODULE advapi32 = GetModuleHandle("ADVAPI32.DLL");
- if (!advapi32)
- {
- CloseServiceHandle(service);
- CloseServiceHandle(serviceControlManager);
- return false;
- }
-
- CSD_T ChangeService_Config2 = (CSD_T) GetProcAddress(advapi32, "ChangeServiceConfig2A");
- if (!ChangeService_Config2)
- {
- CloseServiceHandle(service);
- CloseServiceHandle(serviceControlManager);
- return false;
- }
-
- SERVICE_DESCRIPTION sdBuf;
- sdBuf.lpDescription = serviceDescription;
- ChangeService_Config2(
- service, // handle to service
- SERVICE_CONFIG_DESCRIPTION, // change: description
- &sdBuf); // new data
-
- SC_ACTION _action[1];
- _action[0].Type = SC_ACTION_RESTART;
- _action[0].Delay = 10000;
- SERVICE_FAILURE_ACTIONS sfa;
- ZeroMemory(&sfa, sizeof(SERVICE_FAILURE_ACTIONS));
- sfa.lpsaActions = _action;
- sfa.cActions = 1;
- sfa.dwResetPeriod =INFINITE;
- ChangeService_Config2(
- service, // handle to service
- SERVICE_CONFIG_FAILURE_ACTIONS, // information level
- &sfa); // new data
-
- CloseServiceHandle(service);
-
- }
- }
- CloseServiceHandle(serviceControlManager);
- }
-
- printf("Service installed\n");
- return true;
-}
-
-bool WinServiceUninstall()
-{
- SC_HANDLE serviceControlManager = OpenSCManager(0, 0, SC_MANAGER_CONNECT);
-
- if (serviceControlManager)
- {
- SC_HANDLE service = OpenService(serviceControlManager,
- serviceName, SERVICE_QUERY_STATUS | DELETE);
- if (service)
- {
- SERVICE_STATUS serviceStatus2;
- if (QueryServiceStatus(service, &serviceStatus2))
- {
- if (serviceStatus2.dwCurrentState == SERVICE_STOPPED)
- DeleteService(service);
- }
- CloseServiceHandle(service);
- }
-
- CloseServiceHandle(serviceControlManager);
- }
-
- printf("Service uninstalled\n");
- return true;
-}
-
-void WINAPI ServiceControlHandler(DWORD controlCode)
-{
- switch (controlCode)
- {
- case SERVICE_CONTROL_INTERROGATE:
- break;
-
- case SERVICE_CONTROL_SHUTDOWN:
- case SERVICE_CONTROL_STOP:
- serviceStatus.dwCurrentState = SERVICE_STOP_PENDING;
- SetServiceStatus(serviceStatusHandle, &serviceStatus);
-
- m_ServiceStatus = 0;
- return;
-
- case SERVICE_CONTROL_PAUSE:
- m_ServiceStatus = 2;
- serviceStatus.dwCurrentState = SERVICE_PAUSED;
- SetServiceStatus(serviceStatusHandle, &serviceStatus);
- break;
-
- case SERVICE_CONTROL_CONTINUE:
- serviceStatus.dwCurrentState = SERVICE_RUNNING;
- SetServiceStatus(serviceStatusHandle, &serviceStatus);
- m_ServiceStatus = 1;
- break;
-
- default:
- if ( controlCode >= 128 && controlCode <= 255 )
- // user defined control code
- break;
- else
- // unrecognized control code
- break;
- }
-
- SetServiceStatus(serviceStatusHandle, &serviceStatus);
-}
-
-void WINAPI ServiceMain(DWORD argc, char *argv[])
-{
- // initialise service status
- serviceStatus.dwServiceType = SERVICE_WIN32;
- serviceStatus.dwCurrentState = SERVICE_START_PENDING;
- serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE;
- serviceStatus.dwWin32ExitCode = NO_ERROR;
- serviceStatus.dwServiceSpecificExitCode = NO_ERROR;
- serviceStatus.dwCheckPoint = 0;
- serviceStatus.dwWaitHint = 0;
-
- serviceStatusHandle = RegisterServiceCtrlHandler(serviceName, ServiceControlHandler);
-
- if ( serviceStatusHandle )
- {
- char path[_MAX_PATH + 1];
- unsigned int i, last_slash = 0;
-
- GetModuleFileName(0, path, sizeof(path)/sizeof(path[0]));
-
- size_t pathLen = std::strlen(path);
- for (i = 0; i < pathLen; i++)
- {
- if (path[i] == '\\') last_slash = i;
- }
-
- path[last_slash] = 0;
-
- // service is starting
- serviceStatus.dwCurrentState = SERVICE_START_PENDING;
- SetServiceStatus(serviceStatusHandle, &serviceStatus);
-
- // do initialisation here
- SetCurrentDirectory(path);
-
- // running
- serviceStatus.dwControlsAccepted |= (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN);
- serviceStatus.dwCurrentState = SERVICE_RUNNING;
- SetServiceStatus( serviceStatusHandle, &serviceStatus );
-
- ////////////////////////
- // service main cycle //
- ////////////////////////
-
- m_ServiceStatus = 1;
- argc = 1;
- main(argc, argv);
-
- // service was stopped
- serviceStatus.dwCurrentState = SERVICE_STOP_PENDING;
- SetServiceStatus(serviceStatusHandle, &serviceStatus);
-
- // do cleanup here
-
- // service is now stopped
- serviceStatus.dwControlsAccepted &= ~(SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN);
- serviceStatus.dwCurrentState = SERVICE_STOPPED;
- SetServiceStatus(serviceStatusHandle, &serviceStatus);
- }
-}
-
-bool WinServiceRun()
-{
- SERVICE_TABLE_ENTRY serviceTable[] =
- {
- { serviceName, ServiceMain },
- { 0, 0 }
- };
-
- if (!StartServiceCtrlDispatcher(serviceTable))
- {
- TC_LOG_ERROR("server.worldserver", "StartService Failed. Error [%u]", uint32(::GetLastError()));
- return false;
- }
- return true;
-}
-#endif
-
diff --git a/src/server/shared/Service/ServiceWin32.h b/src/server/shared/Service/ServiceWin32.h
deleted file mode 100644
index 3d67bfe5445..00000000000
--- a/src/server/shared/Service/ServiceWin32.h
+++ /dev/null
@@ -1,29 +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/>.
- */
-
-#ifdef _WIN32
-#ifndef _WIN32_SERVICE_
-#define _WIN32_SERVICE_
-
-bool WinServiceInstall();
-bool WinServiceUninstall();
-bool WinServiceRun();
-
-#endif // _WIN32_SERVICE_
-#endif // _WIN32
-