Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN apt-get update && apt-get install -y \
libssl-dev \
libcurl4-openssl-dev \
zsh \
cmake \
&& apt remove -y nodejs npm libnode-dev \
&& curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
&& apt install -y nodejs \
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.vscode-typescript-tslint-plugin",
"GitHub.copilot"
"GitHub.copilot",
"twxs.cmake"
]
}
},
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/server-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ FROM ubuntu:noble AS build-game
RUN apt-get update && apt-get install -y \
build-essential \
clang \
cmake \
git \
libcurl4-openssl-dev \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /core
COPY ./server .

RUN make re
RUN make fclean
RUN make prod

FROM ubuntu:noble AS release
RUN apt-get update && apt-get install -y \
Expand Down
38 changes: 20 additions & 18 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
{
"configurations": [
{
"name": "Linux",
"compilerPath": "/usr/bin/cc",
"cStandard": "c23",
"intelliSenseMode": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/client_lib/inc",
"${workspaceFolder}/my-core-bot/gridmaster/inc",
"${workspaceFolder}/my-core-bot/my-core-bot/inc",
"${workspaceFolder}/server/inc/**",
"${workspaceFolder}/server/inc/**/**",
"${workspaceFolder}/server/inc/**/*"
],
"cppStandard": "c++17",
"configurations": [
{
"name": "Linux",
"compilerPath": "/usr/bin/cc",
"cStandard": "c23",
"intelliSenseMode": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/client_lib/inc",
"${workspaceFolder}/my-core-bot/gridmaster/inc",
"${workspaceFolder}/my-core-bot/my-core-bot/inc",
"${workspaceFolder}/server/inc/**",
"${workspaceFolder}/server/inc/**/**",
"${workspaceFolder}/server/inc/**/*",
"${workspaceFolder}/server/build/nlohmann_json/include",
"${workspaceFolder}/server/build/_deps/json_schema_validator-src/src/nlohmann"
],
"cppStandard": "c++17",
"defines": []
}
],
"version": 4
}
],
"version": 4
}
83 changes: 0 additions & 83 deletions .vscode/settings.json

This file was deleted.

34 changes: 21 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,43 @@ CONFIG_FOLDER := my-core-bot/configs
CONFIG_SERVER_FILE := $(CONFIG_FOLDER)/server-config.json
CONFIG_GAME_FILE := $(CONFIG_FOLDER)/soft-config.json

DATA_FOLDER_PATH := server/data

# Git info
CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)

# -------------------- Run targets --------------------
all: build
all: build_clients
re: fclean all

run: stop build
./$(SERVER_FOLDER)/$(SERVER_EXECUTABLE) $(CONFIG_SERVER_FILE) $(CONFIG_GAME_FILE) $(PLAYER1_ID) $(PLAYER2_ID) > /dev/null &
$(PLAYER_2_FOLDER)/$(PLAYER_2_EXECUTABLE) $(PLAYER1_ID) > /dev/null &
$(PLAYER_1_FOLDER)/$(PLAYER_1_EXECUTABLE) $(PLAYER2_ID)
ren: fclean run
run: prod
start: prod

debug: stop build
dev: stop build_clients server_build_dev
$(PLAYER_2_FOLDER)/$(PLAYER_2_EXECUTABLE) $(PLAYER1_ID) &
$(PLAYER_1_FOLDER)/$(PLAYER_1_EXECUTABLE) $(PLAYER2_ID) &
./$(SERVER_FOLDER)/$(SERVER_EXECUTABLE) $(CONFIG_SERVER_FILE) $(CONFIG_GAME_FILE) $(PLAYER1_ID) $(PLAYER2_ID)
rebug: fclean debug
./$(SERVER_FOLDER)/$(SERVER_EXECUTABLE) $(CONFIG_SERVER_FILE) $(CONFIG_GAME_FILE) $(DATA_FOLDER_PATH) $(PLAYER1_ID) $(PLAYER2_ID)
redev: fclean dev

prod: stop build_clients server_build_prod
$(PLAYER_2_FOLDER)/$(PLAYER_2_EXECUTABLE) $(PLAYER1_ID) &
$(PLAYER_1_FOLDER)/$(PLAYER_1_EXECUTABLE) $(PLAYER2_ID) &
./$(SERVER_FOLDER)/$(SERVER_EXECUTABLE) $(CONFIG_SERVER_FILE) $(CONFIG_GAME_FILE) $(DATA_FOLDER_PATH) $(PLAYER1_ID) $(PLAYER2_ID)
reprod: fclean prod

stop:
@pkill $(SERVER_EXECUTABLE) > /dev/null || true &
@pkill $(PLAYER_1_EXECUTABLE) > /dev/null || true &
@pkill $(PLAYER_2_EXECUTABLE) > /dev/null || true

# -------------------- Build targets --------------------
build: server_build player_1_build player_2_build visualizer_build
server_build_dev:
make -C $(SERVER_FOLDER) dev

server_build_prod:
make -C $(SERVER_FOLDER) prod

server_build:
make -C $(SERVER_FOLDER)
build_clients: player_1_build player_2_build

player_1_build:
make -C $(PLAYER_1_FOLDER) CONNECTIONDIR=/workspaces/monorepo/client_lib
Expand Down Expand Up @@ -80,4 +88,4 @@ vis:
visualizer:
cd visualizer && npm i && npm run dev

.PHONY: all re run ren debug rebug stop build server_build player_1_build player_2_build clean fclean update vis visualizer visualizer_build
.PHONY: all re run start dev redev prod reprod stop server_build_dev server_build_prod build_clients player_1_build player_2_build visualizer_build clean fclean update vis visualizer
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
1. Clone this via SSH
2. Run make update to initialize the my-core-bot submodule
3. Open this via Microsoft devcontainer extension in VSCode
4. Run make to build, make run to run, make vis to start the visualizer, and make debug to run with the outputs of server and the other bot, not just yours.
4. Run `make` to build, `make dev` / `make prod` to run with or without debug flags, `make vis` to start the visualizer.

---

Expand Down
4 changes: 3 additions & 1 deletion server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.o
.DS_Store
obj/
server
server
build/
.fc/
71 changes: 71 additions & 0 deletions server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
cmake_minimum_required(VERSION 3.20)
project(server CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE dev CACHE STRING "Choose build type: dev or prod" FORCE)
endif()
set(AVAILABLE_BUILD_TYPES dev prod)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${AVAILABLE_BUILD_TYPES}")

set(FETCHCONTENT_QUIET FALSE)

include(FetchContent)

set(NLOHMANN_JSON_VERSION 3.11.3)
set(NLOHMANN_JSON_URL "https://github.com/nlohmann/json/releases/download/v${NLOHMANN_JSON_VERSION}/json.hpp")
set(NLOHMANN_JSON_INC "${CMAKE_BINARY_DIR}/nlohmann_json/include")
file(MAKE_DIRECTORY "${NLOHMANN_JSON_INC}/nlohmann")
if(NOT EXISTS "${NLOHMANN_JSON_INC}/nlohmann/json.hpp")
file(DOWNLOAD "${NLOHMANN_JSON_URL}" "${NLOHMANN_JSON_INC}/nlohmann/json.hpp" TLS_VERIFY ON)
endif()
add_library(nlohmann_json INTERFACE)
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json)
target_include_directories(nlohmann_json INTERFACE "${NLOHMANN_JSON_INC}")

set(JSON_VALIDATOR_BUILD_TESTS OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
json_schema_validator
GIT_REPOSITORY https://github.com/pboettch/json-schema-validator.git
GIT_TAG 2.3.0
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
UPDATE_DISCONNECTED TRUE
)
FetchContent_MakeAvailable(json_schema_validator)

set(CMAKE_CXX_FLAGS_PROD "-O3 -DNDEBUG")
set(CMAKE_C_FLAGS_PROD "-O3 -DNDEBUG")
set(CMAKE_EXE_LINKER_FLAGS_PROD "")

set(CMAKE_CXX_FLAGS_DEV "${CMAKE_CXX_FLAGS_PROD} -g -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_C_FLAGS_DEV "${CMAKE_C_FLAGS_PROD} -g -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS_DEV "${CMAKE_EXE_LINKER_FLAGS_PROD} -fsanitize=address")

file(GLOB_RECURSE SERVER_SOURCES CONFIGURE_DEPENDS src/*.cpp)

add_executable(server ${SERVER_SOURCES})
set_target_properties(server PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}")

set(INC_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/inc)
file(GLOB_RECURSE INC_SUBDIRS LIST_DIRECTORIES true "${INC_ROOT}/*")
set(ALL_INC_DIRS ${INC_ROOT})
foreach(d ${INC_SUBDIRS})
if(IS_DIRECTORY "${d}")
list(APPEND ALL_INC_DIRS "${d}")
endif()
endforeach()
list(REMOVE_DUPLICATES ALL_INC_DIRS)
target_include_directories(server PRIVATE ${ALL_INC_DIRS})

target_include_directories(server PRIVATE
"${CMAKE_BINARY_DIR}/nlohmann_json/include/nlohmann"
"${CMAKE_BINARY_DIR}/_deps/json_schema_validator-src/src/nlohmann"
)

target_compile_options(server PRIVATE -Wall -Wextra -Werror)

target_link_libraries(server PRIVATE nlohmann_json nlohmann_json_schema_validator)
Loading