Reduce Server Patches

This commit is contained in:
TheBrokenRail 2020-12-01 12:02:48 -05:00
parent a83cb6d211
commit 6e18ee44fb
3 changed files with 39 additions and 27 deletions

View File

@ -151,11 +151,7 @@ static int is_server = 0;
// Check For Feature // Check For Feature
int extra_has_feature(const char *name) { int extra_has_feature(const char *name) {
if (is_server) { char *env = is_server ? (char *) server_get_features() : getenv("MCPI_FEATURES");
// Enable All Features In Server
return 1;
} else {
char *env = getenv("MCPI_FEATURES");
char *features = strdup(env != NULL ? env : ""); char *features = strdup(env != NULL ? env : "");
char *tok = strtok(features, "|"); char *tok = strtok(features, "|");
int ret = 0; int ret = 0;
@ -167,9 +163,10 @@ int extra_has_feature(const char *name) {
tok = strtok(NULL, "|"); tok = strtok(NULL, "|");
} }
free(features); free(features);
if (!is_server) {
INFO("Feature: %s: %s", name, ret ? "Enabled" : "Disabled"); INFO("Feature: %s: %s", name, ret ? "Enabled" : "Disabled");
return ret;
} }
return ret;
} }
// Get Graphics Mode // Get Graphics Mode
@ -259,11 +256,7 @@ __attribute__((constructor)) static void init() {
patch_address(MouseBuildInput_tickBuild_vtable_addr, (void *) MouseBuildInput_tickBuild_injection); patch_address(MouseBuildInput_tickBuild_vtable_addr, (void *) MouseBuildInput_tickBuild_injection);
} }
if (is_server) {
mob_spawning = server_get_mob_spawning();
} else {
mob_spawning = extra_has_feature("Mob Spawning"); mob_spawning = extra_has_feature("Mob Spawning");
}
// Set Mob Spawning // Set Mob Spawning
overwrite((void *) LevelData_getSpawnMobs, LevelData_getSpawnMobs_injection); overwrite((void *) LevelData_getSpawnMobs, LevelData_getSpawnMobs_injection);

View File

@ -34,6 +34,7 @@ static ServerProperties &get_server_properties() {
#define DEFAULT_PORT "19132" #define DEFAULT_PORT "19132"
#define DEFAULT_SEED "" #define DEFAULT_SEED ""
#define DEFAULT_MOB_SPAWNING "true" #define DEFAULT_MOB_SPAWNING "true"
#define DEFAULT_PEACEFUL_MODE "false"
#define DEFAULT_WORLD_NAME "world" #define DEFAULT_WORLD_NAME "world"
#define DEFAULT_MAX_PLAYERS "4" #define DEFAULT_MAX_PLAYERS "4"
@ -390,10 +391,25 @@ const char *server_get_motd() {
std::string *motd = new std::string(get_server_properties().get_string("motd", DEFAULT_MOTD)); std::string *motd = new std::string(get_server_properties().get_string("motd", DEFAULT_MOTD));
return motd->c_str(); return motd->c_str();
} }
int server_get_mob_spawning() {
return get_server_properties().get_bool("spawn-mobs", DEFAULT_MOB_SPAWNING); static bool loaded_features = false;
const char *server_get_features() {
static std::string features;
if (!loaded_features) {
loaded_features = true;
features = "";
if (get_server_properties().get_bool("spawn-mobs", DEFAULT_MOB_SPAWNING)) {
features += "Mob Spawning|";
} }
static unsigned char server_get_max_players() { if (get_server_properties().get_bool("peaceful-mode", DEFAULT_PEACEFUL_MODE)) {
features += "Peaceful Mode|";
}
}
return features.c_str();
}
static unsigned char get_max_players() {
int val = get_server_properties().get_int("max-players", DEFAULT_MAX_PLAYERS); int val = get_server_properties().get_int("max-players", DEFAULT_MAX_PLAYERS);
if (val < 0) { if (val < 0) {
val = 0; val = 0;
@ -426,6 +442,8 @@ void server_init() {
properties_file_output << "seed=" DEFAULT_SEED "\n"; properties_file_output << "seed=" DEFAULT_SEED "\n";
properties_file_output << "# Mob Spawning (false = Disabled, true = Enabled)\n"; properties_file_output << "# Mob Spawning (false = Disabled, true = Enabled)\n";
properties_file_output << "spawn-mobs=" DEFAULT_MOB_SPAWNING "\n"; properties_file_output << "spawn-mobs=" DEFAULT_MOB_SPAWNING "\n";
properties_file_output << "# Peaceful Mode (false = Disabled, true = Enabled)\n";
properties_file_output << "peaceful-mode=" DEFAULT_PEACEFUL_MODE "\n";
properties_file_output << "# World To Select\n"; properties_file_output << "# World To Select\n";
properties_file_output << "world-name=" DEFAULT_WORLD_NAME "\n"; properties_file_output << "world-name=" DEFAULT_WORLD_NAME "\n";
properties_file_output << "# Maximum Player Count\n"; properties_file_output << "# Maximum Player Count\n";
@ -472,7 +490,7 @@ void server_init() {
unsigned char allow_all_ip_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; unsigned char allow_all_ip_patch[4] = {0x00, 0xf0, 0x20, 0xe3};
patch((void *) 0xe1f6c, allow_all_ip_patch); patch((void *) 0xe1f6c, allow_all_ip_patch);
// Set Max Players // Set Max Players
unsigned char max_players_patch[4] = {server_get_max_players(), 0x30, 0xa0, 0xe3}; unsigned char max_players_patch[4] = {get_max_players(), 0x30, 0xa0, 0xe3};
patch((void *) 0x166d0, max_players_patch); patch((void *) 0x166d0, max_players_patch);
// Custom Banned IP List // Custom Banned IP List
overwrite((void *) RakNet_RakPeer_IsBanned, (void *) RakNet_RakPeer_IsBanned_injection); overwrite((void *) RakNet_RakPeer_IsBanned, (void *) RakNet_RakPeer_IsBanned_injection);

View File

@ -9,7 +9,8 @@ extern "C" {
void server_init(); void server_init();
const char *server_get_motd(); const char *server_get_motd();
int server_get_mob_spawning();
const char *server_get_features();
#ifdef __cplusplus #ifdef __cplusplus
} }