summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--CMakeLists.txt66
-rw-r--r--config.h.in17
-rw-r--r--data/config.nbted (renamed from config.nbted)0
-rw-r--r--data/dimension_registry.datbin587 -> 0 bytes
-rw-r--r--main.c43
-rw-r--r--main.h2
7 files changed, 112 insertions, 20 deletions
diff --git a/.gitignore b/.gitignore
index 3177470..6dc2d9f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,5 +19,5 @@ DerivedData
# Pods - for those of you who use CocoaPods
Pods
-xcode
-builddir
+build
+config.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 36731ef..8592b8c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,6 +9,9 @@ endif()
set(CMAKE_C_FLAGS_DEBUG "-DDEBUG -g")
set(CMAKE_MACOSX_RPATH OFF)
+set(mcc_VERSION_MAJOR 0)
+set(mcc_VERSION_MINOR 1)
+
find_package(PkgConfig REQUIRED)
pkg_search_module(PKG_libevent REQUIRED IMPORTED_TARGET libevent)
pkg_search_module(PKG_json_c REQUIRED IMPORTED_TARGET json-c)
@@ -17,14 +20,39 @@ find_package(ZLIB)
add_subdirectory(subprojects/cNBT)
include_directories(subprojects)
+include_directories("${PROJECT_BINARY_DIR}")
-if(NOT ${CMAKE_GENERATOR} STREQUAL "Xcode")
- message(STATUS "generator: Not Xcode")
- message(STATUS "set entitlements for mcc")
- set_target_properties(mcc PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_CURRENT_LIST_DIR}/mcc.entitlements")
+find_program(
+ nbted
+ nbted
+)
+add_custom_command(
+ OUTPUT "${PROJECT_BINARY_DIR}/config.dat"
+ COMMAND ${nbted} -r -i ${PROJECT_SOURCE_DIR}/data/config.nbted > ${PROJECT_BINARY_DIR}/config.dat
+ DEPENDS "${PROJECT_SOURCE_DIR}/data/config.nbted"
+)
+add_custom_command(
+ OUTPUT "${PROJECT_BINARY_DIR}/dimension_registry.dat"
+ COMMAND ${nbted} -r -i ${PROJECT_SOURCE_DIR}/data/dimension_registry.nbted > ${PROJECT_BINARY_DIR}/dimension_registry.dat
+ DEPENDS "${PROJECT_SOURCE_DIR}/data/dimension_registry.nbted"
+)
+
+if (NOT DEFINED mcc_RESOURCE_PATH)
+if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+ message(STATUS "building on macOS with ../Resource path")
+ set(mcc_RESOURCE_PATH ../Resources)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ message(STATUS "building on linux with ./Resource path")
+ set(mcc_RESOURCE_PATH ./Resources)
endif()
+endif()
+
+configure_file(
+ "${PROJECT_SOURCE_DIR}/config.h.in"
+ "${PROJECT_BINARY_DIR}/config.h"
+)
-ADD_EXECUTABLE(mcc
+add_executable(mcc
main.c
main.h
socket.c
@@ -37,6 +65,33 @@ ADD_EXECUTABLE(mcc
package.h
world.c
world.h
+ ${PROJECT_SOURCE_DIR}/config.h.in
+
+
+ # config source
+ ${PROJECT_SOURCE_DIR}/data/config.nbted
+ ${PROJECT_SOURCE_DIR}/data/dimension_registry.nbted
+
+ # config
+ ${PROJECT_BINARY_DIR}/config.dat
+ ${PROJECT_BINARY_DIR}/dimension_registry.dat
+)
+
+set(RESOURCE_FILES
+ ${PROJECT_BINARY_DIR}/config.dat
+ ${PROJECT_BINARY_DIR}/dimension_registry.dat
+)
+
+if(NOT ${CMAKE_GENERATOR} STREQUAL "Xcode")
+ message(STATUS "generator: Not Xcode")
+ message(STATUS "set entitlements for mcc")
+ set_target_properties(mcc PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_CURRENT_LIST_DIR}/mcc.entitlements")
+endif()
+
+set_target_properties(mcc PROPERTIES
+ MACOSX_BUNDLE TRUE
+ MACOSX_FRAMEWORK_IDENTIFIER dev.kloenk.mcc
+ RESOURCE "${RESOURCE_FILES}"
)
#TARGET_LINK_LIBRARIES(mcc PkgConfig::PKG_json_c PkgConfig::PKG_libevent )
@@ -45,5 +100,4 @@ TARGET_LINK_LIBRARIES(mcc PkgConfig::PKG_libevent)
TARGET_LINK_LIBRARIES(mcc nbt)
TARGET_LINK_LIBRARIES(mcc ZLIB::ZLIB)
-
install(TARGETS mcc DESTINATION "${CMAKE_INSTALL_PREFIX}")
diff --git a/config.h.in b/config.h.in
new file mode 100644
index 0000000..f182962
--- /dev/null
+++ b/config.h.in
@@ -0,0 +1,17 @@
+//
+// config.h
+// mcc
+//
+// Created by Finn Behrens on 28.02.21.
+//
+
+#ifndef config_h
+#define config_h
+
+// the configured options and settings for hello
+#define mcc_VERSION_MAJOR @mcc_VERSION_MAJOR@
+#define mcc_VERSION_MINOR @mcc_VERSION_MINOR@
+
+#define mcc_RESOURCE_PATH "@mcc_RESOURCE_PATH@"
+
+#endif /* config_h */
diff --git a/config.nbted b/data/config.nbted
index 2e7c1de..2e7c1de 100644
--- a/config.nbted
+++ b/data/config.nbted
diff --git a/data/dimension_registry.dat b/data/dimension_registry.dat
deleted file mode 100644
index 3fbe7c4..0000000
--- a/data/dimension_registry.dat
+++ /dev/null
Binary files differ
diff --git a/main.c b/main.c
index 36f359a..d2063ec 100644
--- a/main.c
+++ b/main.c
@@ -6,9 +6,11 @@
/* Required by event.h. */
#include <sys/time.h>
+#include <sys/syslimits.h>
#include <stdlib.h>
#include <stdio.h>
+#include <libgen.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
@@ -19,9 +21,6 @@
#include "socket.h"
#include "world.h"
-/* Port to listen on. */
-#define SERVER_PORT 25565
-
mc_config_t *config;
int read_config(char *filename)
@@ -123,6 +122,11 @@ int start_server()
int main(int argc, char **argv)
{
int c, option_index;
+ char *configfile;
+ char *datadir;
+ datadir = malloc(PATH_MAX);
+ if (datadir == NULL)
+ fprintf(stderr, "could not alloc datadir\n");
static struct option long_options[] =
{
{"version", no_argument, NULL, 'v'},
@@ -141,7 +145,7 @@ int main(int argc, char **argv)
break;
break;
case 'v':
- printf("%s 1.2 (%s, %s\n", argv[0], __DATE__, __TIME__);
+ printf("%s %d.%d\n", argv[0], mcc_VERSION_MAJOR, mcc_VERSION_MINOR);
return 0;
@@ -150,16 +154,31 @@ int main(int argc, char **argv)
}
}
+ // set pwd to path of binary
+ strncpy(datadir, argv[0], PATH_MAX);
+ fprintf(stderr, "argv[0]: %s\n", datadir);
+ fprintf(stderr, "argv[0]: %s\n", argv[0]);
+ datadir = dirname(datadir);
+ strncat(datadir, "/" mcc_RESOURCE_PATH, PATH_MAX - 1);
+ fprintf(stderr, "chdir to %s\n", datadir);
+ if (chdir(datadir) < 0) {
+ fprintf(stderr, "coud not set cwd: %s", strerror(errno));
+ }
+
+
if (optind < argc)
{
- if ((errno = read_config(argv[optind])) < 0) {
- fprintf(stderr, "could not read config: %s", strerror(-errno));
- return -errno;
- }
- if ((errno = start_server()) < 0) {
- fprintf(stderr, "could not start server: %s", strerror(-errno));
- return -errno;
- }
+ configfile = argv[optind];
+ } else {
+ configfile = "config.dat";
+ }
+ if ((errno = read_config(configfile)) < 0) {
+ fprintf(stderr, "could not read config: %s", strerror(-errno));
+ return -errno;
+ }
+ if ((errno = start_server()) < 0) {
+ fprintf(stderr, "could not start server: %s", strerror(-errno));
+ return -errno;
}
diff --git a/main.h b/main.h
index 3f6f324..6dedd3f 100644
--- a/main.h
+++ b/main.h
@@ -10,6 +10,8 @@
#include <cNBT/nbt.h>
+#include "config.h"
+
typedef struct mc_config {
uint16_t port;
int max_user;