mirror of
https://github.com/hubHarmony/servii-backend.git
synced 2024-11-17 21:40:31 +00:00
Merge branch 'master' of https://github.com/charleslemaux/servii-backend
This commit is contained in:
commit
e5b2de8116
2
.gitignore
vendored
2
.gitignore
vendored
@ -161,7 +161,7 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
/server/
|
||||
/servers/
|
||||
/users/
|
||||
unit_test.py
|
||||
!*.py
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,6 +2,17 @@ import os
|
||||
import shutil
|
||||
import re
|
||||
|
||||
supported_versions = ["bukkit", "paper", "spigot"]
|
||||
|
||||
def get_all_versions(folder_path="servers/paper"):
|
||||
return [name for name in os.listdir(folder_path) if os.path.isdir(os.path.join(folder_path, name))]
|
||||
|
||||
def version_exists(version, framework = "paper")->bool:
|
||||
if framework not in supported_versions:
|
||||
return False
|
||||
folder_names = get_all_versions("servers/"+framework)
|
||||
return any(version in name for name in folder_names)
|
||||
|
||||
def create_folder(path):
|
||||
os.makedirs(path, exist_ok=True)
|
||||
|
||||
|
@ -3,35 +3,36 @@ import file_manager
|
||||
|
||||
mc_manager: MinecraftServerManager = MinecraftServerManager()
|
||||
|
||||
def AccountCreate(port) -> bool:
|
||||
def AccountCreate(port : str) -> bool:
|
||||
file_manager.create_folder("users/"+port)
|
||||
|
||||
def ServerCreate(port, name, version) -> bool:
|
||||
def ServerCreate(port : str, name : str, version : str) -> bool:
|
||||
server_path: str = f"users/{port}/{name}"
|
||||
server_template_path: str = "servers/"+version
|
||||
server_template_path: str = "servers/paper/"+version
|
||||
file_manager.create_folder(server_path)
|
||||
file_manager.copy_folder_contents(server_template_path, server_path)
|
||||
file_manager.copy_folder_contents("servers/shared", server_path)
|
||||
file_manager.update_server_property(server_path+"/server.properties", "server-port", port)
|
||||
|
||||
def ServerDelete(port, name) -> bool:
|
||||
def ServerDelete(port : str, name : str) -> bool:
|
||||
server_path: str = f"users/{port}/{name}"
|
||||
file_manager.delete_non_empty_folder(server_path)
|
||||
|
||||
def AccountDelete(port) -> bool:
|
||||
def AccountDelete(port : str) -> bool:
|
||||
file_manager.delete_non_empty_folder("users/"+port)
|
||||
|
||||
def ServerRun(port, name) -> bool:
|
||||
def ServerRun(port : str, name : str) -> bool:
|
||||
server_id = mc_manager.start_server(f"users/{port}/{name}")
|
||||
mc_manager.servers[server_id]['port'] = int(port)
|
||||
|
||||
def ServerStop(port, name) -> bool:
|
||||
def ServerStop(port : str, name : str) -> bool:
|
||||
server_id = mc_manager.get_server_id_by_port(int(port))
|
||||
mc_manager.stop_server(server_id)
|
||||
|
||||
def UpdateProperty(port, name, prop, value) -> bool:
|
||||
def UpdateProperty(port : str, name : str, prop : str, value : str) -> bool:
|
||||
property_file_path: str = f"users/{port}/{name}/server.properties"
|
||||
file_manager.update_server_property(property_file_path, prop, value)
|
||||
|
||||
def RunCommand(port, command) -> bool:
|
||||
def RunCommand(port : str, command : str) -> bool:
|
||||
server_id = mc_manager.get_server_id_by_port(int(port))
|
||||
mc_manager.execute_server_command(server_id, command)
|
@ -22,7 +22,6 @@ class MinecraftServerManager:
|
||||
def execute_server_command(self, server_id, command):
|
||||
if server_id in self.servers:
|
||||
process = self.servers[server_id]['process']
|
||||
#process.communicate(input=(command + "\n").encode())
|
||||
process.stdin.write(command.encode() + b'\n')
|
||||
print(f"Server {server_id} executed command : {command}")
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user