Skip to content

Commit 32a910a

Browse files
committed
perf: 项目目录优化
1 parent ee8ff85 commit 32a910a

14 files changed

+84
-66
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ _✨ 适用于palworld windows轮询自动重启服务端自动发送关服通
2424
https://github.com/Cassianvale/palworld-python-script/releases
2525
2.有两个exe程序,一个是`task_scheduler.exe`轮询重启守护进程等,一个是`backup.exe`独立的定时备份存档,必须与`config.ini`配置文件放在同一目录下运行
2626
3.修改`config.ini`配置文件,配置文件中有详细的说明
27-
![img.png](img.png)
27+
![img.png](data/img.png)
2828

2929
## 二次开发
3030

Diff for: README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ _✨ Suitable for palworld windows polling auto-restart server and auto-send shu
2424
https://github.com/Cassianvale/palworld-python-script/releases
2525
2. There are two exe programs, one is `task_scheduler.exe` for polling, restarting daemon processes, etc., and the other is `backup.exe` for independent timed backup of archives. Both must be run in the same directory as the `config.ini` configuration file.
2626
3. Modify the `config.ini` configuration file. Detailed instructions are provided in the configuration file.
27-
![img.png](img.png)
27+
![img.png](data/img.png)
2828

2929
## Usage
3030

Diff for: img.png renamed to data/img.png

File renamed without changes.

Diff for: data/pal-plugin-loader.dll

444 KB
Binary file not shown.

Diff for: pyinstaller.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@ def remove_ds_store(dir):
1818

1919
def package_scripts():
2020

21-
scripts = ['task_scheduler.py', 'backup.py']
22-
23-
for script in scripts:
24-
print('打包', scripts)
25-
command = ['pyinstaller', '--onefile', script]
26-
subprocess.run(command)
27-
28-
shutil.copy('config.ini', 'dist')
29-
3021
if os.path.exists('dist/palworld-python-script.zip'):
3122
os.remove('dist/palworld-python-script.zip')
32-
23+
print('已删除原dist/palworld-python-script.zip')
3324
if os.path.exists('palworld-python-script.zip'):
3425
os.remove('palworld-python-script.zip')
26+
print('已删除原palworld-python-script.zip')
27+
28+
scripts = ['src/task_scheduler.py', 'src/backup.py']
29+
print('正在打包:', scripts)
30+
31+
for script in scripts:
32+
33+
command = 'pyinstaller', '--onefile', script
34+
subprocess.run(command)
35+
36+
shutil.copy('src/config.ini', 'dist')
3537

3638
shutil.make_archive('palworld-python-script', 'zip', 'dist')
3739
print("palworld-python-script 打包成功!")

Diff for: backup.py renamed to src/backup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import time
66
import datetime
77
import os
8-
import read_conf
9-
from utils.log_control import INFO
8+
from src import read_conf
9+
from src.utils.log_control import INFO
1010

1111

1212
class Backup:

Diff for: config.ini renamed to src/config.ini

File renamed without changes.

Diff for: read_conf.py renamed to src/read_conf.py

File renamed without changes.

Diff for: src/utils/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
File renamed without changes.

Diff for: tests/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+

Diff for: tests/test_rcon.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
from rcon.source.proto import Packet
5+
from rcon.source import Client
6+
from src.utils.log_control import INFO
7+
from rcon.exceptions import WrongPassword, EmptyResponse, UserAbort
8+
9+
10+
class TestRcon:
11+
def __init__(self, rcon_host, rcon_port, rcon_passwd):
12+
self.rcon_host = rcon_host
13+
self.rcon_port = rcon_port
14+
self.rcon_passwd = rcon_passwd
15+
16+
def patched_run(self, command: str, *args: str, encoding: str = "utf-8") -> str:
17+
"""Patched run method that ignores SessionTimeout exceptions."""
18+
request = Packet.make_command(command, *args, encoding=encoding)
19+
response = self.communicate(request)
20+
21+
return response.payload.decode(encoding)
22+
23+
Client.run = patched_run
24+
25+
def send_command(self, command):
26+
try:
27+
with Client(host=self.rcon_host,
28+
port=self.rcon_port,
29+
passwd=self.rcon_passwd,
30+
timeout=1) as client:
31+
response = client.run(command)
32+
return True, response
33+
except WrongPassword:
34+
INFO.logger.warning("[ RCON ] RCON密码错误,请检查相关设置")
35+
return False, "[ RCON ] RCON密码错误,请检查相关设置"
36+
except EmptyResponse:
37+
INFO.logger.warning("[ RCON ] 服务器响应为空")
38+
return False, "[ RCON ] 服务器响应为空"
39+
except UserAbort:
40+
INFO.logger.warning("[RCON] 用户中断")
41+
return False, "[RCON] 用户中断"
42+
except TimeoutError:
43+
INFO.logger.warning("[ RCON ] RCON连接超时")
44+
return False, "[ RCON ] RCON连接超时"
45+
except ConnectionResetError:
46+
INFO.logger.warning("[ RCON ] 连接已被远程主机关闭,请重新连接RCON")
47+
return False, "[ RCON ] 连接已被远程主机关闭,请重新连接RCON"
48+
except ConnectionRefusedError:
49+
INFO.logger.warning("[ RCON ] 连接已被远程主机拒绝")
50+
return False, "[ RCON ] 连接已被远程主机拒绝"
51+
except Exception as e:
52+
INFO.logger.warning(f"[ RCON ] 未知错误: {str(e)}")
53+
return False, f"[ RCON ] 未知错误: {str(e)}"
54+
55+
56+
if __name__ == '__main__':
57+
rcon = TestRcon(
58+
rcon_host="127.0.0.1",
59+
rcon_port=25575,
60+
rcon_passwd="qr14"
61+
)
62+
result, response = rcon.send_command("ShowPlayers")
63+
print(result, response)

Diff for: utils/__init__.py

Whitespace-only changes.

Diff for: utils/test_rcon.py

-52
This file was deleted.

0 commit comments

Comments
 (0)