Improve Server
This commit is contained in:
parent
39b226685e
commit
fd003d8df2
@ -9,7 +9,6 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <netinet/in.h>
|
|
||||||
|
|
||||||
#include <SDL/SDL_events.h>
|
#include <SDL/SDL_events.h>
|
||||||
|
|
||||||
@ -18,30 +17,6 @@
|
|||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "server_properties.h"
|
#include "server_properties.h"
|
||||||
|
|
||||||
typedef void (*Minecraft_update_t)(unsigned char *minecraft);
|
|
||||||
static Minecraft_update_t Minecraft_update = (Minecraft_update_t) 0x16b74;
|
|
||||||
static void *Minecraft_update_original = NULL;
|
|
||||||
|
|
||||||
struct LevelSettings {
|
|
||||||
unsigned long seed;
|
|
||||||
int32_t game_type;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef void (*Minecraft_selectLevel_t)(unsigned char *minecraft, std::string const& level_dir, std::string const& level_name, LevelSettings const& vsettings);
|
|
||||||
static Minecraft_selectLevel_t Minecraft_selectLevel = (Minecraft_selectLevel_t) 0x16f38;
|
|
||||||
|
|
||||||
typedef void (*Minecraft_hostMultiplayer_t)(unsigned char *minecraft, int32_t port);
|
|
||||||
static Minecraft_hostMultiplayer_t Minecraft_hostMultiplayer = (Minecraft_hostMultiplayer_t) 0x16664;
|
|
||||||
|
|
||||||
typedef void *(*ProgressScreen_t)(unsigned char *obj);
|
|
||||||
static ProgressScreen_t ProgressScreen = (ProgressScreen_t) 0x37044;
|
|
||||||
|
|
||||||
typedef void (*Minecraft_setScreen_t)(unsigned char *minecraft, unsigned char *screen);
|
|
||||||
static Minecraft_setScreen_t Minecraft_setScreen = (Minecraft_setScreen_t) 0x15d6c;
|
|
||||||
|
|
||||||
// Store Minecraft For Exit
|
|
||||||
static unsigned char *stored_minecraft = NULL;
|
|
||||||
|
|
||||||
// Server Properties
|
// Server Properties
|
||||||
static ServerProperties &get_server_properties() {
|
static ServerProperties &get_server_properties() {
|
||||||
static ServerProperties properties;
|
static ServerProperties properties;
|
||||||
@ -82,6 +57,27 @@ static void *read_stdin_thread(__attribute__((unused)) void *data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef void (*Minecraft_update_t)(unsigned char *minecraft);
|
||||||
|
static Minecraft_update_t Minecraft_update = (Minecraft_update_t) 0x16b74;
|
||||||
|
static void *Minecraft_update_original = NULL;
|
||||||
|
|
||||||
|
struct LevelSettings {
|
||||||
|
unsigned long seed;
|
||||||
|
int32_t game_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void (*Minecraft_selectLevel_t)(unsigned char *minecraft, std::string const& level_dir, std::string const& level_name, LevelSettings const& vsettings);
|
||||||
|
static Minecraft_selectLevel_t Minecraft_selectLevel = (Minecraft_selectLevel_t) 0x16f38;
|
||||||
|
|
||||||
|
typedef void (*Minecraft_hostMultiplayer_t)(unsigned char *minecraft, int32_t port);
|
||||||
|
static Minecraft_hostMultiplayer_t Minecraft_hostMultiplayer = (Minecraft_hostMultiplayer_t) 0x16664;
|
||||||
|
|
||||||
|
typedef void *(*ProgressScreen_t)(unsigned char *obj);
|
||||||
|
static ProgressScreen_t ProgressScreen = (ProgressScreen_t) 0x37044;
|
||||||
|
|
||||||
|
typedef void (*Minecraft_setScreen_t)(unsigned char *minecraft, unsigned char *screen);
|
||||||
|
static Minecraft_setScreen_t Minecraft_setScreen = (Minecraft_setScreen_t) 0x15d6c;
|
||||||
|
|
||||||
// Create/Start World
|
// Create/Start World
|
||||||
static void start_world(unsigned char *minecraft) {
|
static void start_world(unsigned char *minecraft) {
|
||||||
INFO("%s", "Starting Minecraft: Pi Edition Dedicated Server");
|
INFO("%s", "Starting Minecraft: Pi Edition Dedicated Server");
|
||||||
@ -102,8 +98,6 @@ static void start_world(unsigned char *minecraft) {
|
|||||||
void *screen = ::operator new(0x4c);
|
void *screen = ::operator new(0x4c);
|
||||||
screen = (*ProgressScreen)((unsigned char *) screen);
|
screen = (*ProgressScreen)((unsigned char *) screen);
|
||||||
(*Minecraft_setScreen)(minecraft, (unsigned char *) screen);
|
(*Minecraft_setScreen)(minecraft, (unsigned char *) screen);
|
||||||
|
|
||||||
stored_minecraft = minecraft;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef const char *(*Minecraft_getProgressMessage_t)(unsigned char *minecraft);
|
typedef const char *(*Minecraft_getProgressMessage_t)(unsigned char *minecraft);
|
||||||
@ -159,14 +153,10 @@ static void print_progress(unsigned char *minecraft) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct RakNet_RakNetGUID {
|
struct RakNet_RakNetGUID {
|
||||||
uint64_t g;
|
unsigned char data[10];
|
||||||
unsigned short SystemIndex;
|
|
||||||
};
|
};
|
||||||
struct RakNet_SystemAddress {
|
struct RakNet_SystemAddress {
|
||||||
union {
|
unsigned char data[20];
|
||||||
sockaddr_in addr4;
|
|
||||||
} address;
|
|
||||||
unsigned short debugPort;
|
|
||||||
};
|
};
|
||||||
typedef RakNet_SystemAddress (*RakNet_RakPeer_GetSystemAddressFromGuid_t)(unsigned char *rak_peer, RakNet_RakNetGUID guid);
|
typedef RakNet_SystemAddress (*RakNet_RakPeer_GetSystemAddressFromGuid_t)(unsigned char *rak_peer, RakNet_RakNetGUID guid);
|
||||||
|
|
||||||
@ -176,8 +166,6 @@ static ServerSideNetworkHandler_displayGameMessage_t ServerSideNetworkHandler_di
|
|||||||
typedef char *(*RakNet_SystemAddress_ToString_t)(RakNet_SystemAddress *system_address, bool print_delimiter, char delimiter);
|
typedef char *(*RakNet_SystemAddress_ToString_t)(RakNet_SystemAddress *system_address, bool print_delimiter, char delimiter);
|
||||||
static RakNet_SystemAddress_ToString_t RakNet_SystemAddress_ToString = (RakNet_SystemAddress_ToString_t) 0xd6198;
|
static RakNet_SystemAddress_ToString_t RakNet_SystemAddress_ToString = (RakNet_SystemAddress_ToString_t) 0xd6198;
|
||||||
|
|
||||||
typedef void (*ServerSideNetworkHandler_onDisconnect_t)(unsigned char *server_side_network_handler, RakNet_RakNetGUID const& guid);
|
|
||||||
|
|
||||||
static std::string get_banned_ips_file() {
|
static std::string get_banned_ips_file() {
|
||||||
std::string file(getenv("HOME"));
|
std::string file(getenv("HOME"));
|
||||||
file.append("/.minecraft/banned-ips.txt");
|
file.append("/.minecraft/banned-ips.txt");
|
||||||
@ -206,15 +194,25 @@ static void find_players(unsigned char *minecraft, std::string target_username,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get IP From Player
|
static RakNet_RakNetGUID *get_rak_net_guid(unsigned char *player) {
|
||||||
static char *get_player_ip(unsigned char *minecraft, unsigned char *player) {
|
return (RakNet_RakNetGUID *) (player + 0xc08);
|
||||||
RakNet_RakNetGUID guid = *(RakNet_RakNetGUID *) (player + 0xc08);
|
}
|
||||||
unsigned char *rak_net_instance = *(unsigned char **) (minecraft + 0x170);
|
static RakNet_SystemAddress get_system_address(unsigned char *rak_peer, RakNet_RakNetGUID guid) {
|
||||||
unsigned char *rak_peer = *(unsigned char **) (rak_net_instance + 0x4);
|
|
||||||
unsigned char *rak_peer_vtable = *(unsigned char **) rak_peer;
|
unsigned char *rak_peer_vtable = *(unsigned char **) rak_peer;
|
||||||
RakNet_RakPeer_GetSystemAddressFromGuid_t RakNet_RakPeer_GetSystemAddressFromGuid = *(RakNet_RakPeer_GetSystemAddressFromGuid_t *) (rak_peer_vtable + 0xd0);
|
RakNet_RakPeer_GetSystemAddressFromGuid_t RakNet_RakPeer_GetSystemAddressFromGuid = *(RakNet_RakPeer_GetSystemAddressFromGuid_t *) (rak_peer_vtable + 0xd0);
|
||||||
// Get SystemAddress
|
// Get SystemAddress
|
||||||
RakNet_SystemAddress address = (*RakNet_RakPeer_GetSystemAddressFromGuid)(rak_peer, guid);
|
return (*RakNet_RakPeer_GetSystemAddressFromGuid)(rak_peer, guid);
|
||||||
|
}
|
||||||
|
static unsigned char *get_rak_peer(unsigned char *minecraft) {
|
||||||
|
unsigned char *rak_net_instance = *(unsigned char **) (minecraft + 0x170);
|
||||||
|
return *(unsigned char **) (rak_net_instance + 0x4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get IP From Player
|
||||||
|
static char *get_player_ip(unsigned char *minecraft, unsigned char *player) {
|
||||||
|
RakNet_RakNetGUID guid = *get_rak_net_guid(player);
|
||||||
|
unsigned char *rak_peer = get_rak_peer(minecraft);
|
||||||
|
RakNet_SystemAddress address = get_system_address(rak_peer, guid);
|
||||||
// Get IP
|
// Get IP
|
||||||
return (*RakNet_SystemAddress_ToString)(&address, false, '|');
|
return (*RakNet_SystemAddress_ToString)(&address, false, '|');
|
||||||
}
|
}
|
||||||
@ -266,27 +264,40 @@ static void Level_saveLevelData_injection(unsigned char *level) {
|
|||||||
revert_overwrite((void *) Level_saveLevelData, Level_saveLevelData_original);
|
revert_overwrite((void *) Level_saveLevelData, Level_saveLevelData_original);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef void (*Minecraft_leaveGame_t)(unsigned char *minecraft, bool save_remote_level);
|
||||||
|
static Minecraft_leaveGame_t Minecraft_leaveGame = (Minecraft_leaveGame_t) 0x15ea0;
|
||||||
|
|
||||||
// Stop Server
|
// Stop Server
|
||||||
|
static bool exit_requested = false;
|
||||||
static void exit_handler(__attribute__((unused)) int data) {
|
static void exit_handler(__attribute__((unused)) int data) {
|
||||||
INFO("%s", "Stopping Server");
|
exit_requested = true;
|
||||||
if (stored_minecraft != NULL) {
|
}
|
||||||
unsigned char *level = *(unsigned char **) (stored_minecraft + 0x188);
|
static void handle_server_stop(unsigned char *minecraft) {
|
||||||
if (level != NULL) {
|
if (exit_requested) {
|
||||||
// Save Game
|
INFO("%s", "Stopping Server");
|
||||||
(*Level_saveLevelData)(level);
|
// Save And Exit
|
||||||
}
|
unsigned char *level = *(unsigned char **) (minecraft + 0x188);
|
||||||
|
(*Level_saveLevelData)(level);
|
||||||
|
(*Minecraft_leaveGame)(minecraft, false);
|
||||||
|
// Stop Game
|
||||||
|
SDL_Event event;
|
||||||
|
event.type = SDL_QUIT;
|
||||||
|
SDL_PushEvent(&event);
|
||||||
|
|
||||||
|
exit_requested = false;
|
||||||
}
|
}
|
||||||
// Stop Game
|
}
|
||||||
SDL_Event event;
|
|
||||||
event.type = SDL_QUIT;
|
// Get ServerSideNetworkHandler From Minecraft
|
||||||
SDL_PushEvent(&event);
|
static unsigned char *get_server_side_network_handler(unsigned char *minecraft) {
|
||||||
|
return *(unsigned char **) (minecraft + 0x174);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Commands
|
// Handle Commands
|
||||||
static void handle_commands(unsigned char *minecraft) {
|
static void handle_commands(unsigned char *minecraft) {
|
||||||
if (stdin_buffer_complete) {
|
if ((*Minecraft_isLevelGenerated)(minecraft) && stdin_buffer_complete) {
|
||||||
if (stdin_buffer != NULL) {
|
if (stdin_buffer != NULL) {
|
||||||
unsigned char *server_side_network_handler = *(unsigned char **) (minecraft + 0x174);
|
unsigned char *server_side_network_handler = get_server_side_network_handler(minecraft);
|
||||||
if (server_side_network_handler != NULL) {
|
if (server_side_network_handler != NULL) {
|
||||||
std::string data((char *) stdin_buffer);
|
std::string data((char *) stdin_buffer);
|
||||||
|
|
||||||
@ -355,6 +366,9 @@ static void Minecraft_update_injection(unsigned char *minecraft) {
|
|||||||
|
|
||||||
// Handle Commands
|
// Handle Commands
|
||||||
handle_commands(minecraft);
|
handle_commands(minecraft);
|
||||||
|
|
||||||
|
// Server Stop
|
||||||
|
handle_server_stop(minecraft);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef void (*Gui_addMessage_t)(unsigned char *gui, std::string const& text);
|
typedef void (*Gui_addMessage_t)(unsigned char *gui, std::string const& text);
|
||||||
|
Loading…
Reference in New Issue
Block a user