Cache Blacklist/Whitelist
This commit is contained in:
parent
2f64552926
commit
53f602403a
@ -178,6 +178,7 @@ static char *get_player_ip(unsigned char *minecraft, unsigned char *player) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ban Player
|
// Ban Player
|
||||||
|
static bool is_ip_in_blacklist(const char *ip);
|
||||||
static void ban_callback(unsigned char *minecraft, std::string username, unsigned char *player) {
|
static void ban_callback(unsigned char *minecraft, std::string username, unsigned char *player) {
|
||||||
// Get IP
|
// Get IP
|
||||||
char *ip = get_player_ip(minecraft, player);
|
char *ip = get_player_ip(minecraft, player);
|
||||||
@ -194,6 +195,8 @@ static void ban_callback(unsigned char *minecraft, std::string username, unsigne
|
|||||||
blacklist_output.close();
|
blacklist_output.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Reload
|
||||||
|
is_ip_in_blacklist(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kill Player
|
// Kill Player
|
||||||
@ -305,6 +308,7 @@ static void handle_commands(unsigned char *minecraft) {
|
|||||||
static std::string say_command("say ");
|
static std::string say_command("say ");
|
||||||
static std::string kill_command("kill ");
|
static std::string kill_command("kill ");
|
||||||
static std::string list_command("list");
|
static std::string list_command("list");
|
||||||
|
static std::string reload_command("reload");
|
||||||
static std::string tps_command("tps");
|
static std::string tps_command("tps");
|
||||||
static std::string stop_command("stop");
|
static std::string stop_command("stop");
|
||||||
static std::string help_command("help");
|
static std::string help_command("help");
|
||||||
@ -312,6 +316,9 @@ static void handle_commands(unsigned char *minecraft) {
|
|||||||
// IP-Ban Target Username
|
// IP-Ban Target Username
|
||||||
std::string ban_username = data.substr(ban_command.length());
|
std::string ban_username = data.substr(ban_command.length());
|
||||||
find_players(minecraft, ban_username, ban_callback, false);
|
find_players(minecraft, ban_username, ban_callback, false);
|
||||||
|
} else if (data == reload_command) {
|
||||||
|
INFO("Reloading %s", is_whitelist() ? "Whitelist" : "Blacklist");
|
||||||
|
is_ip_in_blacklist(NULL);
|
||||||
} else if (data.rfind(kill_command, 0) == 0) {
|
} else if (data.rfind(kill_command, 0) == 0) {
|
||||||
// Kill Target Username
|
// Kill Target Username
|
||||||
std::string kill_username = data.substr(kill_command.length());
|
std::string kill_username = data.substr(kill_command.length());
|
||||||
@ -336,6 +343,7 @@ static void handle_commands(unsigned char *minecraft) {
|
|||||||
if (!is_whitelist()) {
|
if (!is_whitelist()) {
|
||||||
INFO(" ban <Username> - IP-Ban All Players With Specifed Username");
|
INFO(" ban <Username> - IP-Ban All Players With Specifed Username");
|
||||||
}
|
}
|
||||||
|
INFO(" reload - Reload The %s", is_whitelist() ? "Whitelist" : "Blacklist");
|
||||||
INFO(" kill <Username> - Kill All Players With Specifed Username");
|
INFO(" kill <Username> - Kill All Players With Specifed Username");
|
||||||
INFO(" say <Message> - Print Specified Message To Chat");
|
INFO(" say <Message> - Print Specified Message To Chat");
|
||||||
INFO(" list - List All Players");
|
INFO(" list - List All Players");
|
||||||
@ -379,39 +387,51 @@ static void Minecraft_update_injection(unsigned char *minecraft) {
|
|||||||
handle_server_stop(minecraft);
|
handle_server_stop(minecraft);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ban Players
|
// Check Blacklist/Whitelist
|
||||||
static bool RakNet_RakPeer_IsBanned_injection(__attribute__((unused)) unsigned char *rakpeer, const char *ip) {
|
static bool is_ip_in_blacklist(const char *ip) {
|
||||||
// Check banned-ips.txt
|
static std::vector<std::string> ips;
|
||||||
std::string blacklist_file_path = get_blacklist_file();
|
if (ip == NULL) {
|
||||||
std::ifstream blacklist_file(blacklist_file_path);
|
// Reload
|
||||||
if (blacklist_file) {
|
ips.clear();
|
||||||
bool ret = false;
|
// Check banned-ips.txt
|
||||||
if (blacklist_file.good()) {
|
std::string blacklist_file_path = get_blacklist_file();
|
||||||
std::string line;
|
std::ifstream blacklist_file(blacklist_file_path);
|
||||||
while (std::getline(blacklist_file, line)) {
|
if (blacklist_file) {
|
||||||
// Check Line
|
if (blacklist_file.good()) {
|
||||||
if (line.length() > 0) {
|
std::string line;
|
||||||
if (line[0] == '#') {
|
while (std::getline(blacklist_file, line)) {
|
||||||
continue;
|
// Check Line
|
||||||
}
|
if (line.length() > 0 && line[0] != '#') {
|
||||||
if (strcmp(line.c_str(), ip) == 0) {
|
ips.push_back(line);
|
||||||
// Is In File
|
|
||||||
ret = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (blacklist_file.is_open()) {
|
||||||
if (blacklist_file.is_open()) {
|
blacklist_file.close();
|
||||||
blacklist_file.close();
|
}
|
||||||
}
|
|
||||||
if (is_whitelist()) {
|
|
||||||
return !ret;
|
|
||||||
} else {
|
} else {
|
||||||
return ret;
|
ERR("Unable To Read Blacklist/Whitelist");
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
ERR("Unable To Read Blacklist/Whitelist");
|
// Check List
|
||||||
|
for (std::string x : ips) {
|
||||||
|
if (x.compare(ip) == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ban Players
|
||||||
|
static bool RakNet_RakPeer_IsBanned_injection(__attribute__((unused)) unsigned char *rakpeer, const char *ip) {
|
||||||
|
// Check List
|
||||||
|
bool ret = is_ip_in_blacklist(ip);
|
||||||
|
if (is_whitelist()) {
|
||||||
|
return !ret;
|
||||||
|
} else {
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,6 +550,8 @@ static void server_init() {
|
|||||||
if (blacklist_file.is_open()) {
|
if (blacklist_file.is_open()) {
|
||||||
blacklist_file.close();
|
blacklist_file.close();
|
||||||
}
|
}
|
||||||
|
// Load Blacklist/Whitelist
|
||||||
|
is_ip_in_blacklist(NULL);
|
||||||
|
|
||||||
// Prevent Main Player From Loading
|
// Prevent Main Player From Loading
|
||||||
unsigned char player_patch[4] = {0x00, 0x20, 0xa0, 0xe3}; // "mov r2, #0x0"
|
unsigned char player_patch[4] = {0x00, 0x20, 0xa0, 0xe3}; // "mov r2, #0x0"
|
||||||
|
Loading…
Reference in New Issue
Block a user