Commit graph

59 commits

Author SHA1 Message Date
David Kindl
ab2f8d29cb Fix building on MSVC 18 (2026) 2025-12-02 20:20:46 +01:00
cbnolok
af895d5fb6 Added support for CppCheck static analysis and utility script to run clang-tidy. 2025-05-25 23:38:48 +02:00
cbnolok
642e88d9e5 CMake: fix MSVC toolchain generator expression 2025-05-10 07:14:20 +02:00
cbnolok
6cdf242da1 CMake: external libs are now compiled as obj files, without an intermediate link-in-a-library stage.
This speeds up overall compilation, since only one link pass is done,
instead of one per target.
2025-05-09 20:08:22 +02:00
cbnolok
205549abc2 CMake toolchains: moved some flags from CompilerFlagsChecker to CompilerFlagsBase.
The one moved are supported since a long time/older compiler versions
and from both Clang and GCC, so they can be safely moved.
Also, not having to check them, CMake configuration is a bit faster.
2025-04-26 17:34:59 +02:00
cbnolok
53dc2f144d Windows-MSVC.cmake: fixed compilation with ASan and WIN32_SPAWN_CONSOLE. 2025-03-21 14:50:38 +01:00
cbnolok
43ca74b5a2 Renamed CMake flags CXX_FLAGS_EXTRA and CMAKE_EXE_LINFER_FLAGS_EXTRA
to CUSTOM_CXX_FLAGS and CUSTOM_EXE_LINKER_FLAGS.
Added -Wdouble-promotion.
2025-02-15 13:27:05 +01:00
cbnolok
0b19f79b99 Moved fixed GCC/Clang compilation flags to separate cmake files. Fixed a
CMake parsing error causing optimizations not being applied correctly to
Nightly and Release build.
2025-02-14 07:27:23 +01:00
cbnolok
69302c6f19 Fixed MacOS compilation error
Caused by changes in mariadb-c-connector homebrew packaging.
2024-11-27 20:03:30 +01:00
cbnolok
e194ba7daf Fixed path concat regression and fixed come cmake options being loaded before being set. 2024-10-13 18:30:13 +02:00
cbnolok
b75a9c949e Refactoring and small additions to CompilerFlagsChecker.cmake. 2024-10-13 18:30:12 +02:00
cbnolok
250cae76f0 Moved all the compiler/linker flags selection for GCC/Clang in CompilerFlagsChecker.cmake. 2024-10-13 18:30:11 +02:00
cbnolok
16f3030be6 Fixed Linux x86 compilation, broken after upgrading the minimum CMake required version due to a new policy. 2024-09-21 12:01:28 +02:00
cbnolok
55f9688159 Changed compiler flags for debug builds, to enable better line-to-line debugging. 2024-09-21 12:01:28 +02:00
cbnolok
013287ba17 Huge cleanup of header files, now removing useless includes.
Other than removing a lot of clangd/clang-tidy warnings, it should speed
up a little compilation.
2024-09-21 12:01:27 +02:00
cbnolok
b0584d08fd Renamed a couple of cmake utility files. 2024-09-21 12:01:27 +02:00
cbnolok
5b03df7671 Fixed exception on Linux when stdin was not a terminal (i.e. debugging
from some IDEs or other apps). Set debug build optimization flags again to minimal (Og)
Using O1 sometimes combined statements and inlined variables, making
line-by-line debugging harder.
Updated Windows-GNU toolchain warning flags.
2024-09-21 12:01:27 +02:00
cbnolok
01be47ec07 Added stricter warning flags for GCC and Clang.
Fixed some function calls getting as argument a null pointer instead of
a string, and similar issues found with a new warning flag.
Also minimal refactoring to CSQLite, encapsulated zlib includes in a
zlib namespace.
2024-09-21 12:01:27 +02:00
cbnolok
8dece16d96 CMake files (cmake_format_gersemi.sh): added tab conversion to 4 spaces also for commented lines. 2024-09-08 14:48:12 +02:00
cbnolok
eae1a45276 Formatted cmake files with gersemi. 2024-09-08 14:33:56 +02:00
cbnolok
0d95e68c3a Treat compiler/linker warnings as errors. 2024-09-05 13:57:41 +02:00
cbnolok
ba4fcea446 Moved FACTION/SLAYER code into a CComponentProps.
Removed legacy/unused SLAYER* properties.
Added log message when a new thread is created or a thread is being renamed.
Added more methods for enum conversion in stypecast.h.
Made more resilient to rare mutex locking errors the threads-managing code.
Made more threads.h methods noexcept.
Reordered CChar members to reduce memory usage.
Added ensure_comptime() in common.h.
Fixed Windows compilation error.
2024-09-05 11:55:56 +02:00
cbnolok
844c61b1ec Fixed ARM compilation warnings (compiler defaults char to uchar instead of signed char) and initialization order fiasco for g_Srv 2024-08-26 18:42:39 +02:00
cbnolok
c0727c690d Fix library search path. 2024-08-26 17:29:11 +02:00
cbnolok
dffa6fb84f Added Linux-AArch64 and OSX-AArch64 toolchains, cleanup of other toolchains. 2024-08-26 16:30:59 +02:00
cbnolok
68caf992a2 - Fixed: script cacher ignored newlines, causing wrong script line context data in server logs.
- Fixed: custom triggers not firing.
- Fixed: CUOClientVersion not parsing correctly new string format.
- Fixed: TOOLTIP Dialog keyword sending the cliloc number in hex notation if ini DecimalVariables == 0 (unsupported by client, making some of them crash).
- Fixed: some integer data type size inconsistencies.
- Fixed: initialization order fiasco for CAccounts at server shutdown.
- Changed: Str_To* functions to return a std::optional value, in order to get the best error handling (before, it depended on errno and there were ambiguous return values for invalid or "0" zero strings.
- Changed: Refactored CUOMobTypes.
- Changed: replaced localtime function with thread-safe alternatives, avoiding data race conditions.
- Added: stypecast.h. It has utilities to cast numbers with strong guarantees and error checking at compile time, to avoid undefined behaviors, involuntary wrong sign/size cast or overflowing.
2024-08-17 10:35:42 +02:00
cbnolok
4ea4325320 Fixed script parsing regression with empty strings, fixed undefined behaviors 2024-08-06 09:56:32 +02:00
cbnolok
75a07b4498 Several stability fixes
- Fixed: ini CommandPrefix being overwritten by data from other ini settings.
- Fixed: function call stack sometimes being subject to a race condition between two writing threads, corrupting it.
- Fixed: lots of memory corruption errors leaving the server unstable when loading a broken save file and recovering by loading a backup save.
- Fixed: CCacheableScriptFile sometimes not reading the last character.
- Fixed: .clang_format.
- Changed: RES_GET_INDEX macro to ResGetIndex function, allowing more integer type safety. Same for RES_GET_TYPE.
- Changed: Renamed THREAD_* macros to MT_*. Split them in always active macros (MT_*) and macros active only when MT_ENGINE is set to 1 (MT_ENGINE_*). There are some situations where we still need a mutex
even if not working with multithreaded script/networking engines (which are NOT complete).
- Changed: Disable signal handlers under Linux if running with ASAN or a debugger.
- Added: NOEXCEPT_DEBUG, it's simply the noexcept specifier, but it's ignored if running in a debug build (useful if we're using DEBUG_ASSERT inside a function which wouldn't otherwise throw an exception).
- Fixed: some undefined behaviors, like signed to unsigned conversion and vice versa.
- Added: additional checks for GCC and Clang ASAN builds.
2024-08-06 09:56:32 +02:00
cbnolok
e3db3e4753 Fix CMakeDetectArch for x86 2024-08-06 09:56:32 +02:00
cbnolok
21ccef9388 - Improvement: optimized various C++ core subsystems, resulting in a significantly reduced CPU usage and (slightly) reduced startup time.
- Fixed: RAM usage always increasing during uptime. Caused by a couple of memory leaks, the greatest happening because the cached map blocks were not properly released.
- Fixed: adopted a more conservative memory allocation policy for strings, resulting in reduced RAM usage.
- Changed: I_MEMORY (ITEMID_MEMORY) items won't have anymore the ComponentProps Faction, ItemChar, Item, reducing their memory footprint.
2024-08-06 09:56:32 +02:00
cbnolok
9829fcbcc2 Improved how triggers are interrogated, reducing CPU load.
Fixed some Linux compilation warnings and errors.
MSVC will compile by default with SSE2 CPU extensions enabled on x86_64. Updated CMakeDetectArch.cmake with 3rd party code.
2024-08-06 09:56:32 +02:00
cbnolok
743dda9900 Started rework of timed object ticking system (trying to change the default container from map of vectors to a multimap, also trying to delete elements as little as possible, to avoid cpu usage, reallocations and tree rebalancing).
Added #define MT_ENGINES: it doesn't make sense to keep unneeded mutex locks, at least until (if ever) we'll have a fully multithreaded engine.
Some advancement in making ASAN work on Windows with Clang.
Added .cmake-format
2024-08-06 09:56:32 +02:00
cbnolok
945ce47fc0 Fixed a case of wrong << parsing inside other angular brackets.
Changes to functions to retrieve the monotonic clock value: on non-Windows OSes they now use faster backends according to the time precision needed.
2024-06-13 15:22:49 +02:00
cbnolok
c7f4eb52f1 - Added: client commands ADDITEM and ADDCHAR, to be used in place of .ADD when there's the need to force the argument to be an item or a char.
This can be useful when using raw IDs (like 01, 0bd1, etc) instead of defnames.
- Improvement: changed the logic behind script files reading and caching, now it will be faster and require less memory.
- Fixed: correct thread name not being shown in the stack trace.
- Renamed ResourceGetID_Advance to ResourceGetID_EatStr, added fCanFail argument.
- Added some string functions, starting from POSIX C getline and getdelim (got the source from NetBSD and renamed to fReadUntilDelimiter), then added some more custom functions to help read from file or string buffers.
2024-06-04 13:56:45 +02:00
cbnolok
cc8d5d2593 Added ini settings for network security: MaxConnectRequestsPerIP, TimeoutIncompleteConn.
Added serv_trigger functions: f_onserver_connectreq_ex, f_onserver_connection_acquired.
Fixed version string with git versioning disabled.
Updated .editorconfig.
Added more AddressSanitizer compiler/linker flags.
2024-06-03 17:42:05 +02:00
cbnolok
08bf180f05 Fixed sign/str format warnings, MinGW compilation, ASan Nightly MSVC builds 2024-05-29 19:14:11 +02:00
cbnolok
9f39def7dd Disabled some unuseful warnings for AppleClang toolchain and GCC on 32bits, fixed Windows phmap compilation error 2024-05-28 21:29:38 +02:00
cbnolok
da942a685b CMake additions, fixed used memory estimation on Linux, more optimizations.
Added: CMake switch to statically link C/C++ runtime libraries (on
Linux, glibc still isn't included); fixed linker flags when using
sanitizers.
Added: asan symbolizer setting in configure_asan.sh, to be able to see
the function names.
Further optimized CWorldSearch::Get* methods and CItem/CChar::GetHeight.
Added checks to avoid buffer overflows using sprintf (and removed the
compiler warnings).
Fixed some invalid memory reads when the server is closing (reading from
deleted thread data).
2024-05-27 11:26:31 +02:00
cbnolok
80929e0e24 Added static linking of (a)san library. Fixed C library target arch. 2024-05-23 23:02:59 +02:00
cbnolok
66ef50b3c6 Some more optimizations, changed rand algorithm to the fast one for trivial tasks, fixed MSVC, typo for OSX toolchains and rigid cast making the Linux build fail. 2024-05-23 19:10:16 +02:00
cbnolok
d66675e40a Added separated linker options for each C 3rd party lib.
Fixed twofish compilation error on Windows. That library wasn't really meant to be used as-is...
Made _GITVERSION define macro available only when enabling git versioning from CMake.
Modernized and fixed MSVC CMake toolchain.
Removed mariadb_version.h from git index.
2024-05-20 11:16:23 +02:00
cbnolok
84888279c9 Updated toolchains to set options per target, instead of globally.
Windows and OS X not yet tested.
Moved toolchains .inc files to include/ folder.
Renamed folder lib/bin into _bin.
Moved bcrypt and twofish library into lib folder and into new cmake projects. Restored twofish library to the original version.


Fixed some format warnings.
2024-05-19 14:04:53 +02:00
cbnolok
4533f80f4c Moved each third-party library to a separate CMake project
This will allow setting per-project (build) settings and to build/link
Sphere using system-provided library source/headers/precompiled lib
(like the ones provided with -devel packages on Linux) instead of the
ones shipped with the projects.
This is also a necessary step to use git submodules.
2024-05-17 11:10:17 +02:00
cbnolok
3b2c4d9c6d Updated zlib to v1.3.1
Added Apple Silicon ARM build for Mac OS
Fixed Clang 15 compilation on newer MacOS images
2024-05-06 10:59:10 +02:00
cbnolok
41b9dcc806 Fixed GCC compilation error, fixed some warnings. 2024-05-05 22:59:38 +02:00
cbnolok
93b4a9881e Updated c++ std version to c++20.
Updated CMake toolchains: improved library search (link phase).
Updated gitignore to add KDevelop files.
Fixed unused parameters, now using them as fault check.
Added include guards to some headers.
2024-05-04 12:46:34 +02:00
cbnolok
7750d98e71 Fixed temporary strings allocation bugs and thread data retrieval upon server start.
Immediately after server start, the global objects are initialized in spheresvr.cpp. This happens before calling main().
Global objects initialization sometimes requires the allocation of temporary strings and the retrieval of the current thread state data (ThreadHolder class stuff).
Both of those things aren't yet created, so we can write to invalid memory instead of using the expected buffer.
When thread state data is not available, so we can't get a temporary string buffer in a thread-safe way, now it will be used the string buffer allocated for thread-unsafe access (for a minimum example, check Str_GetTemp code).
Also, when the server closes, also the temporary string pool and the thread state data are deleted, but there might be some code still requiring thread state data.
So it was added some code accounting of this special application state, avoiding reading or writing to the thread state data location, which doesn't hold anymore valid data.
2023-11-01 21:18:01 +01:00
cbnolok
ef2d63c48b Revert "Fixed temporary strings allocation bugs and thread data retrieval upon server start."
This reverts commit 14a4651e20.
2023-11-01 21:14:08 +01:00
cbnolok
14a4651e20 Fixed temporary strings allocation bugs and thread data retrieval upon server start.
Immediately after server start, the global objects are initialized in spheresvr.cpp. This happens before calling main().
Global objects initialization sometimes requires the allocation of temporary strings and the retrieval of the current thread state data (ThreadHolder class stuff).
Both of those things aren't yet created, so we can write to invalid memory instead of using the expected buffer.
When thread state data is not available, so we can't get a temporary string buffer in a thread-safe way, now it will be used the string buffer allocated for thread-unsafe access (for a minimum example, check Str_GetTemp code).
Also, when the server closes, also the temporary string pool and the thread state data are deleted, but there might be some code still requiring thread state data.
So it was added some code accounting of this special application state, avoiding reading or writing to the thread state data location, which doesn't hold anymore valid data.
2023-10-31 15:25:15 +01:00
cbnolok
e89c01ca3d - Fixed: Removing from client's view an object while it's being deleted, in some corner cases made the server crash (Issue #1119).
- Fixed: Guildstone removal caused an exception (Issue #1165).
- Fixed: In-game chat not working correctly and generating exceptions since last update (Issue #1140).
2023-10-28 19:54:39 +02:00