-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbims.py
186 lines (168 loc) · 7.79 KB
/
bims.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# БИМС
import tkinter as tk
from tkinter.ttk import Combobox
from threading import Thread
import pydustry
import pyglet
import time
import wget
import json
import sys
import os
import re
# Перемены для работы
class operation:
TimeUpdate = True
InfoServerUpdate = True
ServersListUpdate = True
cfgd_std = {
"attributes": False
}
class config_data:
if "config.json" in os.listdir():
try:
with open("config.json") as config_data_file:
config_data_dict = json.load(config_data_file)
attributes = config_data_dict["attributes"]
except:
attributes = cfgd_std["attributes"]
config_data_dict = cfgd_std
with open("config.json", "w") as config_data_file:
json.dump(config_data_dict, config_data_file)
else:
attributes = cfgd_std["attributes"]
config_data_dict = cfgd_std
with open("config.json", "w") as config_data_file:
json.dump(config_data_dict, config_data_file)
hosts = {}
host = None
port = None
# Загрузка данных
try:
if not("Minecraft.ttf" in os.listdir()):
FontFileName = wget.download("https://raw.githubusercontent.com/RCR-OOP/basic-information-mindustry-server/main/Minecraft.ttf")
pyglet.font.add_file(os.path.abspath(FontFileName))
else:
pyglet.font.add_file(os.path.abspath("Minecraft.ttf"))
except:
pass
# Инфомация программы
class proginfo:
name = "БИМС"
version = "0.2.2-release"
versionint = 0.22
author = "Роман Слабицкий"
company = "RCR"
# Создание окна и настройка
root = tk.Tk()
root.title("{0} v{1} ({2})".format(proginfo.name, proginfo.version, proginfo.versionint))
root.geometry("500x130")
root.resizable(0, 0)
root.attributes("-topmost", config_data.attributes)
# Объекты
try:
TimeLabel = tk.Label(root, text = "Загрузка", font = ('Minecraft Rus', 8), bg = "black", fg = "white", width = 10)
NameServerLabel = tk.Label(root, text = "Имя севрера: Загрузка...", font = ('Minecraft Rus', 8))
MapServerLabel = tk.Label(root, text = "Карта: Загрузка...", font = ('Minecraft Rus', 8))
PlayersServerLabel = tk.Label(root, text = "Игроков: Загрузка...", font = ('Minecraft Rus', 8))
WaveServerLabel = tk.Label(root, text = "Волна: Загрузка...", font = ('Minecraft Rus', 8))
VersionServerLabel = tk.Label(root, text = "Версия ядра: Загрузка...", font = ('Minecraft Rus', 8))
ButtonSwitchingOptionsAttributes = tk.Label(root, text = "📌", font = ('Minecraft Rus', 12))
ComboboxListServers = Combobox(root, width = 78)
except:
TimeLabel = tk.Label(root, text = "Загрузка", font = 'helvetica 10 bold', bg = "black", fg = "white", width = 10)
NameServerLabel = tk.Label(root, text = "Имя севрера: Загрузка...", font = 'helvetica 10 bold')
MapServerLabel = tk.Label(root, text = "Карта: Загрузка...", font = 'helvetica 10 bold')
PlayersServerLabel = tk.Label(root, text = "Игроков: Загрузка...", font = 'helvetica 10 bold')
WaveServerLabel = tk.Label(root, text = "Волна: Загрузка...", font = 'helvetica 10 bold')
VersionServerLabel = tk.Label(root, text = "Версия ядра: Загрузка...", font = 'helvetica 10 bold')
ButtonSwitchingOptionsAttributes = tk.Label(root, text = "📌", font = 'helvetica 12 bold')
ComboboxListServers = Combobox(root, width = 78)
if config_data.attributes:
ButtonSwitchingOptionsAttributes["fg"] = "green"
else:
ButtonSwitchingOptionsAttributes["fg"] = "red"
# Постановка объектов
TimeLabel.place(x = 415, y = 0)
NameServerLabel.place(x = 5, y = 0)
MapServerLabel.place(x = 5, y = 20)
PlayersServerLabel.place(x = 5, y = 40)
WaveServerLabel.place(x = 5, y = 60)
VersionServerLabel.place(x = 5, y = 80)
ButtonSwitchingOptionsAttributes.place(x = 390, y = -5)
ComboboxListServers.place(x = 5, y = 105)
# Логика
def UpdateTimeHandler():
while operation.TimeUpdate:
try:
TimeLabel["text"] = str(time.strftime("%H:%M:%S", time.localtime()))
except:
TimeLabel["text"] = "Ошибка"
time.sleep(0.5)
def HandlerComboBoxLS():
ls_filename = str(wget.download("https://raw.githubusercontent.com/Anuken/Mindustry/master/servers_v6.json"))
with open(ls_filename) as ls_file:
ls_data = json.load(ls_file)
os.remove(ls_filename)
for i in ls_data:
for n in i["address"]:
ServerData = n.split(":")
if len(ServerData) > 1:
config_data.hosts["({0}) {1}".format((re.sub(r"(?<=\[).*?(?=\])", "", i["name"])).replace("[", "").replace("]", ""), n)] = {"host": str(ServerData[0]), "port": int(ServerData[1])}
else:
config_data.hosts["({0}) {1}".format((re.sub(r"(?<=\[).*?(?=\])", "", i["name"])).replace("[", "").replace("]", ""), n)] = {"host": str(ServerData[0]), "port": 6567}
ComboboxListServers['value'] = tuple(config_data.hosts)
ComboboxListServers.current(0)
while operation.ServersListUpdate:
name = str(ComboboxListServers.get())
if name in list(config_data.hosts):
config_data.host = config_data.hosts[name]["host"]
config_data.port = config_data.hosts[name]["port"]
time.sleep(0.5)
def UpdateServerInfoLabels():
while operation.InfoServerUpdate:
if (config_data.host != None) and (config_data.port != None):
MindServer = pydustry.Server(str(config_data.host), int(config_data.port))
try:
mind_status = MindServer.get_status(timeout = 3.0)
NameServerLabel["text"] = "Имя севрера: {0}".format((re.sub(r"(?<=\[).*?(?=\])", "", mind_status["name"])).replace("[", "").replace("]", ""))
MapServerLabel["text"] = "Карта: " + str((re.sub(r"(?<=\[).*?(?=\])", "", mind_status["map"])).replace("[", "").replace("]", ""))
PlayersServerLabel["text"] = "Игроков: " + str(mind_status["players"])
WaveServerLabel["text"] = "Волна: " + str(mind_status["wave"])
VersionServerLabel["text"] = "Версия ядра: " + str(mind_status["version"])
except:
NameServerLabel["text"] = "Имя севрера: Сервер не доступен"
MapServerLabel["text"] = "Карта: Сервер не доступен"
PlayersServerLabel["text"] = "Игроков: Сервер не доступен"
WaveServerLabel["text"] = "Волна: Сервер не доступен"
VersionServerLabel["text"] = "Версия ядра: Сервер не доступен"
else:
NameServerLabel["text"] = "Имя севрера: Секунду..."
MapServerLabel["text"] = "Карта: Секунду..."
PlayersServerLabel["text"] = "Игроков: Секунду..."
WaveServerLabel["text"] = "Волна: Секунду..."
VersionServerLabel["text"] = "Версия ядра: Секунду..."
time.sleep(0.5)
def SwitchingOptionsAttributes(event):
global config_data
if config_data.attributes:
config_data.attributes = False
config_data.config_data_dict["attributes"] = False
root.attributes("-topmost", config_data.attributes)
ButtonSwitchingOptionsAttributes["fg"] = "red"
else:
config_data.attributes = True
config_data.config_data_dict["attributes"] = True
root.attributes("-topmost", config_data.attributes)
ButtonSwitchingOptionsAttributes["fg"] = "green"
with open("config.json", "w") as config_data_file:
json.dump(config_data.config_data_dict, config_data_file)
# Привязка объектов у логике
ButtonSwitchingOptionsAttributes.bind('<Button-1>', SwitchingOptionsAttributes)
# Запуск в фоне
Thread(target = UpdateTimeHandler, args = (), daemon = True).start()
Thread(target = UpdateServerInfoLabels, args = (), daemon = True).start()
Thread(target = HandlerComboBoxLS, args = (), daemon = True).start()
# Конец
root.mainloop()
operation.TimeUpdate = False