This repository was archived by the owner on Jun 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.diff
More file actions
111 lines (106 loc) · 3.17 KB
/
patch.diff
File metadata and controls
111 lines (106 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
diff --git a/mods/src/override/override.c b/mods/src/override/override.c
index b585020..4d5c57d 100644
--- a/mods/src/override/override.c
+++ b/mods/src/override/override.c
@@ -1,73 +1,23 @@
-#define _GNU_SOURCE
-
+#define _GNU_SOURCE /* Required for asprintf */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
-
#include <unistd.h>
#include <fcntl.h>
+#include <errno.h>
+#include <dirent.h>
+#include <sys/stat.h>
#include <libreborn/libreborn.h>
-static int starts_with(const char *s, const char *t) {
- return strncmp(s, t, strlen(t)) == 0;
-}
-
-static char *get_override_path(const char *filename) {
- // Get Asset Override Path
- char *overrides = NULL;
- asprintf(&overrides, "%s/.minecraft-pi/overrides", getenv("HOME"));
- ALLOC_CHECK(overrides);
- // Get data Path
- char *data = NULL;
- char *cwd = getcwd(NULL, 0);
- asprintf(&data, "%s/data", cwd);
- ALLOC_CHECK(data);
- free(cwd);
- // Get Full Path
- char *new_path = NULL;
- char *full_path = realpath(filename, NULL);
- if (full_path != NULL) {
- if (starts_with(full_path, data)) {
- asprintf(&new_path, "%s%s", overrides, &full_path[strlen(data)]);
- ALLOC_CHECK(new_path);
- if (access(new_path, F_OK) == -1) {
- free(new_path);
- new_path = NULL;
- }
- }
- free(full_path);
- }
- // Free Variables
- free(overrides);
- free(data);
- // Return
- return new_path;
-}
-
-HOOK(fopen, FILE *, (const char *filename, const char *mode)) {
- char *new_path = get_override_path(filename);
- // Open File
- ensure_fopen();
- FILE *file = (*real_fopen)(new_path != NULL ? new_path : filename, mode);
- // Free Data
- if (new_path != NULL) {
- free(new_path);
- }
- // Return File
- return file;
+HOOK(fopen, FILE*, (const char* filename, const char* mode))
+{
+ ensure_fopen();
+ if (strcmp(basename(filename), "server.properties") == 0)
+ {
+ return (*real_fopen)("/home/container/server.properties", mode);
+ }
+ return (*real_fopen)(filename, mode);
}
-HOOK(fopen64, FILE *, (const char *filename, const char *mode)) {
- char *new_path = get_override_path(filename);
- // Open File
- ensure_fopen64();
- FILE *file = (*real_fopen64)(new_path != NULL ? new_path : filename, mode);
- // Free Data
- if (new_path != NULL) {
- free(new_path);
- }
- // Return File
- return file;
-}
\ No newline at end of file
diff --git a/mods/src/server/server.cpp b/mods/src/server/server.cpp
index e6525a4..ff0d7b7 100644
--- a/mods/src/server/server.cpp
+++ b/mods/src/server/server.cpp
@@ -426,7 +426,7 @@ static unsigned char get_max_players() {
static void server_init() {
// Open Properties File
std::string file(getenv("HOME"));
- file.append("/.minecraft-pi/server.properties");
+ file.append("/server.properties");
std::ifstream properties_file(file);
@@ -513,4 +513,4 @@ void init_server() {
setenv("MCPI_FEATURES", get_features(), 1);
setenv("MCPI_USERNAME", get_motd().c_str(), 1);
}
-}
\ No newline at end of file
+}