diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-06-12 21:41:41 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-06-13 20:22:51 +0800 |
| commit | 6f7b994684032060f0a2d7af82f4f3572293b8d6 (patch) | |
| tree | 793d328cbcd6761365267550b55db45aee9b21fc | |
| parent | 6a51ab4525c59e9fe2bdbd92493019b0a98c6b94 (diff) | |
internal!: organized internal structure, using cmake now
| -rw-r--r-- | CMakeLists.txt | 54 | ||||
| -rw-r--r-- | Makefile | 189 | ||||
| -rw-r--r-- | src/command/commandHandler.cpp (renamed from src/commandHandler.cpp) | 4 | ||||
| -rw-r--r-- | src/command/commandHandler.hpp (renamed from src/commandHandler.hpp) | 2 | ||||
| -rw-r--r-- | src/command/commands.cpp (renamed from src/commands.cpp) | 6 | ||||
| -rw-r--r-- | src/command/commands.hpp (renamed from src/commands.hpp) | 0 | ||||
| -rw-r--r-- | src/core/chatManager.cpp (renamed from src/chatManager.cpp) | 6 | ||||
| -rw-r--r-- | src/core/chatManager.hpp (renamed from src/chatManager.hpp) | 0 | ||||
| -rw-r--r-- | src/core/chatServer.cpp (renamed from src/chatServer.cpp) | 12 | ||||
| -rw-r--r-- | src/core/chatServer.hpp (renamed from src/chatServer.hpp) | 0 | ||||
| -rw-r--r-- | src/core/server.cpp (renamed from src/server.cpp) | 2 | ||||
| -rw-r--r-- | src/core/server.hpp (renamed from src/server.hpp) | 2 | ||||
| -rw-r--r-- | src/core/session.cpp (renamed from src/session.cpp) | 6 | ||||
| -rw-r--r-- | src/core/session.hpp (renamed from src/session.hpp) | 4 | ||||
| -rw-r--r-- | src/core/sessionManager.cpp (renamed from src/sessionManager.cpp) | 6 | ||||
| -rw-r--r-- | src/core/sessionManager.hpp | 16 | ||||
| -rw-r--r-- | src/debug/format.hpp (renamed from src/format.hpp) | 0 | ||||
| -rw-r--r-- | src/debug/log.hpp (renamed from src/log.hpp) | 2 | ||||
| -rw-r--r-- | src/io/IOManager.cpp (renamed from src/IOManager.cpp) | 2 | ||||
| -rw-r--r-- | src/io/IOManager.hpp (renamed from src/IOManager.hpp) | 4 | ||||
| -rw-r--r-- | src/io/inputManager.cpp (renamed from src/inputManager.cpp) | 6 | ||||
| -rw-r--r-- | src/io/inputManager.hpp (renamed from src/inputManager.hpp) | 0 | ||||
| -rw-r--r-- | src/io/renderManager.cpp (renamed from src/renderManager.cpp) | 2 | ||||
| -rw-r--r-- | src/io/renderManager.hpp (renamed from src/renderManager.hpp) | 0 | ||||
| -rw-r--r-- | src/io/scroller.cpp (renamed from src/scroller.cpp) | 2 | ||||
| -rw-r--r-- | src/io/scroller.hpp (renamed from src/scroller.hpp) | 0 | ||||
| -rw-r--r-- | src/main.cpp | 4 | ||||
| -rw-r--r-- | src/misc/FileDescriptor.cpp (renamed from src/FileDescriptor.cpp) | 0 | ||||
| -rw-r--r-- | src/misc/FileDescriptor.hpp (renamed from src/FileDescriptor.hpp) | 0 | ||||
| -rw-r--r-- | src/sessionManager.hpp | 40 |
30 files changed, 118 insertions, 253 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6e3dc35 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required(VERSION 4.0.2) + +project( + chat-server + VERSION 1.0.0 + DESCRIPTION "chat server via socket" + LANGUAGES CXX) + +include(GNUInstallDirs) + +set(CMAKE_CXX_STANDARD 26) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG) + message(STATUS "Configuring chat-server in Debug with CMake") + add_compile_definitions(DEBUG) +else() + message(STATUS "Configuring chat-server in Release with CMake") +endif() + +message(STATUS "Checking dependencies...") + +find_package(PkgConfig REQUIRED) +pkg_check_modules(FTXUI REQUIRED IMPORTED_TARGET ftxui) + +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "src/*.cpp") + +add_executable(${PROJECT_NAME} ${SOURCES}) + +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_26) + +add_compile_options(-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion + -Wno-unused-parameter) + +if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG) + message(STATUS "Setting debug flags") + add_compile_options(-g3 -O0 -fno-omit-frame-pointer) + add_compile_options(-fsanitize=address,undefined) + target_link_options(${PROJECT_NAME} PRIVATE -fsanitize=address,undefined) +else() + add_compile_options(-O3 -flto -DNDEBUG) + target_link_options(${PROJECT_NAME} PRIVATE -flto -Wl,--gc-sections) +endif() + +target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::FTXUI) +target_include_directories(${PROJECT_NAME} PRIVATE src) + +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -1,179 +1,30 @@ -BIN = chat-server -SRCS = $(wildcard src/*.cpp) -HEADERS = $(wildcard src/*.hpp) +PREFIX ?= /usr/local -PREFIX ?= /usr -BINDIR ?= $(PREFIX)/bin -DATADIR ?= $(PREFIX)/share -BUILDDIR ?= build +stub: + @echo "Use 'make release' or 'make debug' to build the project." -OBJS = $(patsubst src/%, $(BUILDDIR)/%, $(SRCS:.cpp=.o)) +release: + cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:STRING=${PREFIX} -S . -B ./build + cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF` -CXXFLAGS += -std=c++26 -Oz -s -Wall -Wextra -flto -fPIC -Wpedantic -LDFLAGS += -Wl,--as-needed,-z,now,-z,pack-relative-relocs - -# Debug flags -DEBUG_CXXFLAGS = -std=c++26 -g3 -O0 -Wall -Wextra -fno-lto -fPIC -DDEBUG -fsanitize=thread -fno-omit-frame-pointer -pthread -DEBUG_LDFLAGS = -Wl,--no-as-needed,-z,now,-z,pack-relative-relocs -fsanitize=thread -lpthread - -# Address Sanitizer Debug flags (run with make asan) -ASAN_CXXFLAGS = -std=c++26 -g3 -O0 -Wall -Wextra -fno-lto -fPIC -DDEBUG -fsanitize=address -fno-omit-frame-pointer -pthread -ASAN_LDFLAGS = -Wl,--no-as-needed,-z,now,-z,pack-relative-relocs -fsanitize=address -lpthread - -# Memory Sanitizer Debug flags (run with make msan) -MSAN_CXXFLAGS = -std=c++26 -g3 -O0 -Wall -Wextra -fno-lto -fPIC -DDEBUG -fsanitize=memory -fno-omit-frame-pointer -fsanitize-memory-track-origins=2 -pthread -MSAN_LDFLAGS = -Wl,--no-as-needed,-z,now,-z,pack-relative-relocs -fsanitize=memory -lpthread - -# UB Sanitizer Debug flags (run with make ubsan) -UBSAN_CXXFLAGS = -std=c++26 -g3 -O0 -Wall -Wextra -fno-lto -fPIC -DDEBUG -fsanitize=undefined -fno-omit-frame-pointer -pthread -UBSAN_LDFLAGS = -Wl,--no-as-needed,-z,now,-z,pack-relative-relocs -fsanitize=undefined -lpthread - -CXXFLAGS += $(shell pkg-config --cflags ftxui) -LDFLAGS += $(shell pkg-config --libs ftxui) -DEBUG_CXXFLAGS += $(shell pkg-config --cflags ftxui) -DEBUG_LDFLAGS += $(shell pkg-config --libs ftxui) - -$(shell mkdir -p $(BUILDDIR)) -JOB_COUNT := $(BIN) $(OBJS) -JOBS_DONE := $(shell ls -l $(JOB_COUNT) 2> /dev/null | wc -l) - -NPROC := $(shell nproc 2>/dev/null || getconf NPROCESSORS_CONF || echo 2) -MAKEFLAGS += -j$(NPROC) - -define progress - $(eval JOBS_DONE := $(shell echo $$(($(JOBS_DONE) + 1)))) - @printf "[$(JOBS_DONE)/$(shell echo $(JOB_COUNT) | wc -w)] %s %s\n" $(1) $(2) -endef - -all: $(BIN) - -install: $(all) - @echo "Installing..." - @install -D -t $(DESTDIR)$(BINDIR) $(BUILDDIR)/$(BIN) +debug: + cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_INSTALL_PREFIX:STRING=${PREFIX} -S . -B ./build + cmake --build ./build --config Debug --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF` clean: - @echo "Cleaning up" - -@rm -rf $(OBJS) - -clean-all: clean - @echo "Cleaning up all" - -@rm -rf $(BUILDDIR)/$(BIN) - -$(BUILDDIR)/$(BIN): $(OBJS) - $(call progress, Linking $@) - @$(CXX) -o $@ \ - $(OBJS) \ - $(CXXFLAGS) \ - $(LDFLAGS) - -$(BIN): $(BUILDDIR)/$(BIN) - - -$(BUILDDIR)/%.o: src/%.cpp - $(call progress, Compiling $@) - @$(CXX) -c $< -o $@ \ - $(CXXFLAGS) - -clang-format: - @echo "Formatting code..." - @clang-format -i $(SRCS) $(HEADERS) - -clang-tidy: - @echo "Running clang-tidy..." - @clang-tidy -fix-errors $(SRCS) -- $(CXXFLAGS) - -.PHONY: all install clean clean-all $(BIN) debug asan msan ubsan helgrind valgrind drd threadcheck compile_commands dchecks dthread live_tsan llvm_libfuzzer stack_combo deadlock pgo-gen pgo-use perf-analysis clang-format clang-tidy - -debug: CXXFLAGS = $(DEBUG_CXXFLAGS) -debug: LDFLAGS = $(DEBUG_LDFLAGS) -# debug: CC = afl-g++ -# debug: CXX = afl-g++ -# debug: export AFL_USE_ASAN = 1 -debug: $(BIN) - @echo "Debug build complete (Thread Sanitizer enabled)" - -asan: CXXFLAGS = $(ASAN_CXXFLAGS) -asan: LDFLAGS = $(ASAN_LDFLAGS) -asan: $(BIN) - @echo "Debug build complete (Address Sanitizer enabled)" - -msan: CXXFLAGS = $(MSAN_CXXFLAGS) -msan: LDFLAGS = $(MSAN_LDFLAGS) -msan: $(BIN) - @echo "Debug build complete (Memory Sanitizer enabled)" - -ubsan: CXXFLAGS = $(UBSAN_CXXFLAGS) -ubsan: LDFLAGS = $(UBSAN_LDFLAGS) -ubsan: $(BIN) - @echo "Debug build complete (Undefined Behavior Sanitizer enabled)" - -dthread: CXXFLAGS = $(DEBUG_CXXFLAGS) -dthread: LDFLAGS = $(DEBUG_LDFLAGS) -dthread: $(BIN) - @echo "Debug build complete (Enhanced Thread Sanitizer enabled)" - TSAN_OPTIONS="history_size=10 report_thread_leaks=1 report_signal_unsafe=1 halt_on_error=1 second_deadlock_stack=1" $(BUILDDIR)/$(BIN) $(ARGS) - -helgrind: debug - @echo "Running with Valgrind Helgrind thread checker" - valgrind --tool=helgrind --read-var-info=yes --track-lockorders=yes $(BUILDDIR)/$(BIN) $(ARGS) - -valgrind: debug - @echo "Running with Valgrind memory checker" - valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes $(BUILDDIR)/$(BIN) $(ARGS) - -drd: debug - @echo "Running with Valgrind DRD (Data Race Detector)" - valgrind --tool=drd --check-stack-var=yes --first-race-only=yes $(BUILDDIR)/$(BIN) $(ARGS) - -dchecks: CXXFLAGS = -std=c++26 -g3 -O0 -Wall -Wextra -fno-lto -fPIC -DDEBUG -fsanitize=thread,undefined -fno-omit-frame-pointer -pthread -dchecks: LDFLAGS = -Wl,--no-as-needed,-z,now,-z,pack-relative-relocs -fsanitize=thread,undefined -lpthread -dchecks: $(BIN) - @echo "Debug build complete (Thread & UB Sanitizers enabled)" - -threadcheck: debug - @echo "Running with Thread Sanitizer" - TSAN_OPTIONS="history_size=7 halt_on_error=1 second_deadlock_stack=1" $(BUILDDIR)/$(BIN) $(ARGS) - -live_tsan: CXXFLAGS = $(DEBUG_CXXFLAGS) -live_tsan: LDFLAGS = $(DEBUG_LDFLAGS) -live_tsan: $(BIN) - @echo "Running with live Thread Sanitizer (continues after errors)" - TSAN_OPTIONS="history_size=15 report_thread_leaks=1 report_signal_unsafe=1 halt_on_error=0 second_deadlock_stack=1" $(BUILDDIR)/$(BIN) $(ARGS) - -llvm_libfuzzer: CXXFLAGS = -std=c++26 -g -O1 -Wall -Wextra -fno-lto -fPIC -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=fuzzer,address -fno-omit-frame-pointer -llvm_libfuzzer: LDFLAGS = -Wl,--no-as-needed,-z,now,-z,pack-relative-relocs -fsanitize=fuzzer,address -llvm_libfuzzer: $(BIN) - @echo "Fuzzer build complete (note: requires clang compiler)" - -stack_combo: CXXFLAGS = -std=c++26 -g3 -O0 -Wall -Wextra -fno-lto -fPIC -DDEBUG -fsanitize=address,undefined -fno-omit-frame-pointer -pthread -stack_combo: LDFLAGS = -Wl,--no-as-needed,-z,now,-z,pack-relative-relocs -fsanitize=address,undefined -lpthread -stack_combo: $(BIN) - @echo "Debug build complete (Combined ASan and UBSan)" - ASAN_OPTIONS="detect_leaks=1:check_initialization_order=1:detect_stack_use_after_return=1" $(BUILDDIR)/$(BIN) $(ARGS) - -compile_commands: - compiledb -n make + rm -rf build +all: + $(MAKE) clean + $(MAKE) release -deadlock: CXXFLAGS = $(DEBUG_CXXFLAGS) -DENABLE_DEADLOCK_DETECTION -deadlock: LDFLAGS = $(DEBUG_LDFLAGS) -deadlock: $(BIN) - @echo "Debug build complete (with deadlock detection)" - TSAN_OPTIONS="detect_deadlocks=1:second_deadlock_stack=1:report_thread_leaks=1:halt_on_error=0" $(BUILDDIR)/$(BIN) $(ARGS) +install: + cmake --install ./build -pgo-gen: CXXFLAGS = -std=c++26 -O2 -Wall -Wextra -fprofile-generate -fPIC -pgo-gen: LDFLAGS = -Wl,--as-needed,-z,now,-z,pack-relative-relocs -fprofile-generate -pgo-gen: $(BIN) - @echo "Profile generation build complete (run app with typical workload)" +uninstall: + xargs rm < ./build/install_manifest.txt -pgo-use: CXXFLAGS = -std=c++26 -Oz -Wall -Wextra -fprofile-use -fprofile-correction -fPIC -pgo-use: LDFLAGS = -Wl,--as-needed,-z,now,-z,pack-relative-relocs -fprofile-use -pgo-use: $(BIN) - @echo "Optimized build using profile data complete" +format: + find src -name "*.cpp" -o -name "*.hpp" | xargs clang-format -i -perf-analysis: CXXFLAGS = -std=c++26 -g -O2 -Wall -Wextra -fno-lto -fno-omit-frame-pointer -perf-analysis: LDFLAGS = -Wl,--as-needed,-z,now,-z,pack-relative-relocs -perf-analysis: $(BIN) - @echo "Performance analysis build complete" - valgrind --tool=callgrind --callgrind-out-file=callgrind.out $(BUILDDIR)/$(BIN) $(ARGS) - @echo "Run 'callgrind_annotate callgrind.out' to view results" +.PHONY: stub release debug clean all install uninstall format diff --git a/src/commandHandler.cpp b/src/command/commandHandler.cpp index e459ee0..4aa6723 100644 --- a/src/commandHandler.cpp +++ b/src/command/commandHandler.cpp @@ -1,6 +1,6 @@ #include "commandHandler.hpp" -#include "log.hpp" -#include "session.hpp" +#include "../debug/log.hpp" +#include "../core/session.hpp" #include <algorithm> #include <memory> diff --git a/src/commandHandler.hpp b/src/command/commandHandler.hpp index 89d19d6..7fc20d5 100644 --- a/src/commandHandler.hpp +++ b/src/command/commandHandler.hpp @@ -1,6 +1,6 @@ #pragma once -#include "session.hpp" +#include "../core/session.hpp" #include <any> #include <functional> #include <memory> diff --git a/src/commands.cpp b/src/command/commands.cpp index e7894db..6f3db68 100644 --- a/src/commands.cpp +++ b/src/command/commands.cpp @@ -1,8 +1,8 @@ #include "commands.hpp" #include "commandHandler.hpp" -#include "format.hpp" -#include "log.hpp" -#include "sessionManager.hpp" +#include "../debug/format.hpp" +#include "../debug/log.hpp" +#include "../core/sessionManager.hpp" #define NOREASON "No reason specified"; diff --git a/src/commands.hpp b/src/command/commands.hpp index b49b6dc..b49b6dc 100644 --- a/src/commands.hpp +++ b/src/command/commands.hpp diff --git a/src/chatManager.cpp b/src/core/chatManager.cpp index 8439673..e981e7f 100644 --- a/src/chatManager.cpp +++ b/src/core/chatManager.cpp @@ -1,7 +1,7 @@ #include "chatManager.hpp" -#include "IOManager.hpp" -#include "inputManager.hpp" -#include "log.hpp" +#include "../io/IOManager.hpp" +#include "../io/inputManager.hpp" +#include "../debug/log.hpp" #include "sessionManager.hpp" CChatManager::CChatManager() { diff --git a/src/chatManager.hpp b/src/core/chatManager.hpp index bd305de..bd305de 100644 --- a/src/chatManager.hpp +++ b/src/core/chatManager.hpp diff --git a/src/chatServer.cpp b/src/core/chatServer.cpp index 458fc09..4a16c56 100644 --- a/src/chatServer.cpp +++ b/src/core/chatServer.cpp @@ -1,11 +1,11 @@ #include "chatServer.hpp" -#include "IOManager.hpp" +#include "../io/IOManager.hpp" #include "chatManager.hpp" -#include "commandHandler.hpp" -#include "commands.hpp" -#include "inputManager.hpp" -#include "log.hpp" -#include "renderManager.hpp" +#include "../command/commandHandler.hpp" +#include "../command/commands.hpp" +#include "../io/inputManager.hpp" +#include "../debug/log.hpp" +#include "../io/renderManager.hpp" #include "server.hpp" #include "sessionManager.hpp" diff --git a/src/chatServer.hpp b/src/core/chatServer.hpp index 00d2979..00d2979 100644 --- a/src/chatServer.hpp +++ b/src/core/chatServer.hpp diff --git a/src/server.cpp b/src/core/server.cpp index db92481..a78c217 100644 --- a/src/server.cpp +++ b/src/core/server.cpp @@ -1,5 +1,5 @@ #include "server.hpp" -#include "log.hpp" +#include "../debug/log.hpp" #include <cstring> #include <memory> #include <sys/socket.h> diff --git a/src/server.hpp b/src/core/server.hpp index ce375de..c42192b 100644 --- a/src/server.hpp +++ b/src/core/server.hpp @@ -1,6 +1,6 @@ #pragma once -#include "FileDescriptor.hpp" +#include "../misc/FileDescriptor.hpp" #include <memory> #include <netinet/in.h> diff --git a/src/session.cpp b/src/core/session.cpp index 126d547..7b0b459 100644 --- a/src/session.cpp +++ b/src/core/session.cpp @@ -1,8 +1,8 @@ #include "session.hpp" #include "chatManager.hpp" -#include "commandHandler.hpp" -#include "format.hpp" -#include "log.hpp" +#include "../command/commandHandler.hpp" +#include "../debug/format.hpp" +#include "../debug/log.hpp" #include "server.hpp" #include "sessionManager.hpp" #include <algorithm> diff --git a/src/session.hpp b/src/core/session.hpp index 2ca274e..ca951d1 100644 --- a/src/session.hpp +++ b/src/core/session.hpp @@ -1,8 +1,8 @@ #pragma once -#include "FileDescriptor.hpp" +#include "../misc/FileDescriptor.hpp" #include "chatManager.hpp" -#include "format.hpp" +#include "../debug/format.hpp" #include <format> #include <memory> #include <netinet/in.h> diff --git a/src/sessionManager.cpp b/src/core/sessionManager.cpp index 7ed1a8e..6c002a5 100644 --- a/src/sessionManager.cpp +++ b/src/core/sessionManager.cpp @@ -1,8 +1,8 @@ #include "sessionManager.hpp" -#include "IOManager.hpp" +#include "../io/IOManager.hpp" #include "chatServer.hpp" -#include "format.hpp" -#include "log.hpp" +#include "../debug/format.hpp" +#include "../debug/log.hpp" #include "session.hpp" #include <algorithm> #include <ranges> diff --git a/src/core/sessionManager.hpp b/src/core/sessionManager.hpp index e84226c..71bcc5f 100644 --- a/src/core/sessionManager.hpp +++ b/src/core/sessionManager.hpp @@ -1,9 +1,9 @@ #pragma once #include "../debug/format.hpp" -#include "../misc/memory.hpp" #include "chatManager.hpp" #include "session.hpp" +#include <memory> #include <thread> #include <vector> @@ -15,22 +15,22 @@ class CSessionManager { void newSession(); void run(); - void broadcast(const std::string &msg, std::optional<WP<CSession>> self = std::nullopt) const; // second param only specified when we want to exclude the sender - void kick(WP<CSession> session, const bool kill = false, const std::string &reason = ""); + void broadcast(const std::string &msg, std::optional<std::weak_ptr<CSession>> self = std::nullopt) const; // second param only specified when we want to exclude the sender + void kick(std::weak_ptr<CSession> session, const bool kill = false, const std::string &reason = ""); void addSession(const CSession &session); bool nameExists(const std::string &name); void shutdownSessions(); - SP<CSession> getByName(const std::string &name) const; - SP<CSession> getByIp(const std::string &ip) const; - std::vector<SP<CSession>> getSessions() const; + std::shared_ptr<CSession> getByName(const std::string &name) const; + std::shared_ptr<CSession> getByIp(const std::string &ip) const; + std::vector<std::shared_ptr<CSession>> getSessions() const; private: void broadcast(const CChatManager::SMessage &msg) const; - std::vector<std::pair<std::jthread, SP<CSession>>> m_vSessions; + std::vector<std::pair<std::jthread, std::shared_ptr<CSession>>> m_vSessions; friend class CChatManager; }; -inline SP<CSessionManager> g_pSessionManager; +inline std::shared_ptr<CSessionManager> g_pSessionManager; diff --git a/src/format.hpp b/src/debug/format.hpp index f857f96..f857f96 100644 --- a/src/format.hpp +++ b/src/debug/format.hpp diff --git a/src/log.hpp b/src/debug/log.hpp index a4654c4..71a958e 100644 --- a/src/log.hpp +++ b/src/debug/log.hpp @@ -1,5 +1,5 @@ #pragma once -#include "IOManager.hpp" +#include "../io/IOManager.hpp" #include "format.hpp" #include <print> #include <string> diff --git a/src/IOManager.cpp b/src/io/IOManager.cpp index eb648e5..be29adf 100644 --- a/src/IOManager.cpp +++ b/src/io/IOManager.cpp @@ -1,6 +1,6 @@ #include "IOManager.hpp" #include "inputManager.hpp" -#include "log.hpp" +#include "../debug/log.hpp" CIOManager::CIOManager() { log(LOG, "IOManager: initialized"); diff --git a/src/IOManager.hpp b/src/io/IOManager.hpp index 670e597..d1d891d 100644 --- a/src/IOManager.hpp +++ b/src/io/IOManager.hpp @@ -1,7 +1,7 @@ #pragma once -#include "chatManager.hpp" -#include "format.hpp" +#include "../core/chatManager.hpp" +#include "../debug/format.hpp" #include <optional> class CIOManager { diff --git a/src/inputManager.cpp b/src/io/inputManager.cpp index d392081..09a7729 100644 --- a/src/inputManager.cpp +++ b/src/io/inputManager.cpp @@ -1,8 +1,8 @@ #include "inputManager.hpp" #include "IOManager.hpp" -#include "chatManager.hpp" -#include "commandHandler.hpp" -#include "log.hpp" +#include "../core/chatManager.hpp" +#include "../command/commandHandler.hpp" +#include "../debug/log.hpp" #include "renderManager.hpp" #include "scroller.hpp" diff --git a/src/inputManager.hpp b/src/io/inputManager.hpp index a81e39d..a81e39d 100644 --- a/src/inputManager.hpp +++ b/src/io/inputManager.hpp diff --git a/src/renderManager.cpp b/src/io/renderManager.cpp index 18b0664..a8dff68 100644 --- a/src/renderManager.cpp +++ b/src/io/renderManager.cpp @@ -1,5 +1,5 @@ #include "renderManager.hpp" -#include "log.hpp" +#include "../debug/log.hpp" CRenderManager::CRenderManager() : screen(ftxui::ScreenInteractive::TerminalOutput()) { diff --git a/src/renderManager.hpp b/src/io/renderManager.hpp index 7a14cc0..7a14cc0 100644 --- a/src/renderManager.hpp +++ b/src/io/renderManager.hpp diff --git a/src/scroller.cpp b/src/io/scroller.cpp index e841401..c595a39 100644 --- a/src/scroller.cpp +++ b/src/io/scroller.cpp @@ -1,6 +1,6 @@ #include "scroller.hpp" -#include "log.hpp" +#include "../debug/log.hpp" #include <algorithm> // for max, min #include <ftxui/component/component_base.hpp> // for Component, ComponentBase #include <ftxui/component/event.hpp> // for Event, Event::ArrowDown, Event::ArrowUp, Event::End, Event::Home, Event::PageDown, Event::PageUp diff --git a/src/scroller.hpp b/src/io/scroller.hpp index b8b39b1..b8b39b1 100644 --- a/src/scroller.hpp +++ b/src/io/scroller.hpp diff --git a/src/main.cpp b/src/main.cpp index 0ee7b3a..c4a6ce4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ -#include "chatServer.hpp" -#include "log.hpp" +#include "core/chatServer.hpp" +#include "debug/log.hpp" #include <algorithm> #include <csignal> #include <unistd.h> diff --git a/src/FileDescriptor.cpp b/src/misc/FileDescriptor.cpp index 92505f5..92505f5 100644 --- a/src/FileDescriptor.cpp +++ b/src/misc/FileDescriptor.cpp diff --git a/src/FileDescriptor.hpp b/src/misc/FileDescriptor.hpp index 75aeb73..75aeb73 100644 --- a/src/FileDescriptor.hpp +++ b/src/misc/FileDescriptor.hpp diff --git a/src/sessionManager.hpp b/src/sessionManager.hpp deleted file mode 100644 index 179d7d8..0000000 --- a/src/sessionManager.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include "chatManager.hpp" -#include "format.hpp" -#include "session.hpp" -#include <memory> -#include <thread> -#include <vector> - -class CSessionManager { - public: - CSessionManager(); - ~CSessionManager(); - - void newSession(); - - void run(); - void broadcast(const std::string &msg, std::optional<std::weak_ptr<CSession>> self = std::nullopt) const; // second param only specified when we want to exclude the sender - void kick(std::weak_ptr<CSession> session, const bool kill = false, const std::string &reason = ""); - void addSession(const CSession &session); - - bool nameExists(const std::string &name); - void shutdownSessions(); - - std::shared_ptr<CSession> getByName(const std::string &name) const; - std::shared_ptr<CSession> getByIp(const std::string &ip) const; - std::vector<std::shared_ptr<CSession>> getSessions() const; - - // Safer weak_ptr versions - recommended for most use cases to avoid accidental lifetime extension - std::weak_ptr<CSession> getByNameWeak(const std::string &name) const; - std::weak_ptr<CSession> getByIpWeak(const std::string &ip) const; - - private: - void broadcast(const CChatManager::SMessage &msg) const; - - std::vector<std::pair<std::jthread, std::shared_ptr<CSession>>> m_vSessions; - - friend class CChatManager; -}; -inline std::shared_ptr<CSessionManager> g_pSessionManager; |
