本贴是给PK服的服主看的
我可以实现一个小功能 就是使用python自动遍历加入服务器用户的17位(steamid)并且可以指定时间重启服务器
当然 这些17位id都是有存档的人才有
一下是脚本代码:
import os
import json
from time import sleep
while True:
# 遍历所有用户17位
result = []
def search(path=".", name=""):
for item in os.listdir(path):
item_path = os.path.join(path, item)
if os.path.isdir(item_path):
search(item_path, name)
elif os.path.isfile(item_path):
if name in item:
global result
result.append(item_path)
# print (item_path + "\n", end="")
search(path=r"C:\\steamcmd\\steamapps\\common\\The Isle Dedicated Server\\TheIsle\\Saved\\Databases\\Sandbox\\Players",name="json")
# 读取原有配置文件 写入现在配置文件
with open('C:\\steamcmd\\steamapps\\common\\The Isle Dedicated Server\\TheIsle\\Saved\\Config\\WindowsServer\\Game.txt','r') as ww1:
duqu = ww1.read()
print('读取原有配置文件 写入现在配置文件')
with open('C:\\steamcmd\\steamapps\\common\\The Isle Dedicated Server\\TheIsle\\Saved\\Config\\WindowsServer\\Game.ini','w') as ww2:
ww2.write(duqu)
# 追加用户到配置文件
with open('C:\\steamcmd\\steamapps\\common\\The Isle Dedicated Server\\TheIsle\\Saved\\Config\\WindowsServer\\Game.ini','a') as ww:
for i in result:
data = i[104:121]
ww.write('\n' + 'ServerAdmins=' + data)
print('追加用户到配置文件')
# 自动重启服务器
while True:
# 启动服务器
os.system('start TheIsleServer.exe /Game/TheIsle/Maps/Developer/DV_TestLevel?MultiHome=110.42.129.247?Port=7777?QueryPort=7778?MaxPlayers=50?game=Sandbox -log')
print('启动服务器')
# 等待秒
print('等待秒')
sleep(5400)
# 关闭服务器
print('关闭服务器')
os.system('taskkill /f /t /im TheIsleServer.exe')
break
# C:\\steamcmd\\steamapps\\common\\The Isle Dedicated Server\\TheIsle\\Saved\\Databases\\Sandbox\\Players
# C:\\steamcmd\\steamapps\\common\\The Isle Dedicated Server\\TheIsle\\Saved\\Config\\WindowsServer\\Game.ini
---------------------------------------------------------------------------------------------------------------------
如果你是小白 可以留言
Ps:因为本人也玩岛 所有写了这个脚本 纯属娱乐 还可以锻炼锻炼自己的代码能力
我可以实现一个小功能 就是使用python自动遍历加入服务器用户的17位(steamid)并且可以指定时间重启服务器
当然 这些17位id都是有存档的人才有
一下是脚本代码:
import os
import json
from time import sleep
while True:
# 遍历所有用户17位
result = []
def search(path=".", name=""):
for item in os.listdir(path):
item_path = os.path.join(path, item)
if os.path.isdir(item_path):
search(item_path, name)
elif os.path.isfile(item_path):
if name in item:
global result
result.append(item_path)
# print (item_path + "\n", end="")
search(path=r"C:\\steamcmd\\steamapps\\common\\The Isle Dedicated Server\\TheIsle\\Saved\\Databases\\Sandbox\\Players",name="json")
# 读取原有配置文件 写入现在配置文件
with open('C:\\steamcmd\\steamapps\\common\\The Isle Dedicated Server\\TheIsle\\Saved\\Config\\WindowsServer\\Game.txt','r') as ww1:
duqu = ww1.read()
print('读取原有配置文件 写入现在配置文件')
with open('C:\\steamcmd\\steamapps\\common\\The Isle Dedicated Server\\TheIsle\\Saved\\Config\\WindowsServer\\Game.ini','w') as ww2:
ww2.write(duqu)
# 追加用户到配置文件
with open('C:\\steamcmd\\steamapps\\common\\The Isle Dedicated Server\\TheIsle\\Saved\\Config\\WindowsServer\\Game.ini','a') as ww:
for i in result:
data = i[104:121]
ww.write('\n' + 'ServerAdmins=' + data)
print('追加用户到配置文件')
# 自动重启服务器
while True:
# 启动服务器
os.system('start TheIsleServer.exe /Game/TheIsle/Maps/Developer/DV_TestLevel?MultiHome=110.42.129.247?Port=7777?QueryPort=7778?MaxPlayers=50?game=Sandbox -log')
print('启动服务器')
# 等待秒
print('等待秒')
sleep(5400)
# 关闭服务器
print('关闭服务器')
os.system('taskkill /f /t /im TheIsleServer.exe')
break
# C:\\steamcmd\\steamapps\\common\\The Isle Dedicated Server\\TheIsle\\Saved\\Databases\\Sandbox\\Players
# C:\\steamcmd\\steamapps\\common\\The Isle Dedicated Server\\TheIsle\\Saved\\Config\\WindowsServer\\Game.ini
---------------------------------------------------------------------------------------------------------------------
如果你是小白 可以留言
Ps:因为本人也玩岛 所有写了这个脚本 纯属娱乐 还可以锻炼锻炼自己的代码能力