first commit

This commit is contained in:
LanShui 2024-05-06 02:27:06 +08:00
commit 1bf0066b1f
11 changed files with 561 additions and 0 deletions

Binary file not shown.

Binary file not shown.

233
apps.py Normal file
View File

@ -0,0 +1,233 @@
from PySide2.QtCore import QObject
from module import *
window_title_apps_name = "CRA-SERVER CLIENT"
login_headers = {"Content-Type": "application/json"}
login_user_key = "f0649fc2aeb411eda71f00163e095b49"
aotu_user_url = f"https://auth.mc-user.com:233/{login_user_key}/"
cra_mc_server_api = ""
server_list_configfile = "config_app/server_list_config.db"
login_json_file = "config_app/login_user.json"
window_size_int = (950, 560)
style_qss_stylesheet_body_file_dir = "style/style.qss"
id_key_sqlite = "INTEGER PRIMARY KEY AUTOINCREMENT"
@staticmethod
def readQSS(style: str):
with open(file=style, mode='r', encoding="UTF-8") as f:
return f.read()
def sqlite_shell(sql_db: str, sql_code: str):
sqlite_connect = sqlite3.connect(sql_db)
sqlite_cursor = sqlite_connect.cursor()
sqlite_cursor.execute(sql_code)
print_sql = sqlite_cursor.fetchall()
sqlite_cursor.close()
sqlite_connect.commit()
sqlite_connect.close()
return print_sql
class Message_ok(QMessageBox):
def __init__(self, message: str):
super().__init__()
self.draggable = False
self.offset = None
self.setWindowFlags(Qt.FramelessWindowHint)
self.setWindowTitle(window_title_apps_name)
self.setText(message)
self.setStandardButtons(QMessageBox.Ok)
button_yes = self.button(QMessageBox.Ok)
button_yes.setText("好的")
self.exec_()
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = True
self.offset = event.pos()
def mouseMoveEvent(self, event):
if self.draggable:
self.move(event.globalPos() - self.offset)
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = False
class Message_yes_no(QMessageBox):
def __init__(self, message: str):
super().__init__()
self.draggable = False
self.offset = None
self.setWindowFlags(Qt.FramelessWindowHint)
self.setWindowTitle(window_title_apps_name)
self.setText(message)
self.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
self.button_yes = self.button(QMessageBox.Yes)
self.button_yes.setText("确定")
button_no = self.button(QMessageBox.No)
button_no.setText("取消")
self.exec_()
def value(self):
if self.clickedButton() == self.button_yes:
return True
return False
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = True
self.offset = event.pos()
def mouseMoveEvent(self, event):
if self.draggable:
self.move(event.globalPos() - self.offset)
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = False
class Thread_appcode_login_user(QThread):
data_th = Signal(dict)
def __init__(self):
super(Thread_appcode_login_user, self).__init__()
def run(self):
data = dict()
code = int(0)
if os.path.isfile(server_list_configfile) is False:
data_serverlistdbfile = [
f'''
CREATE TABLE SERVER_LIST (
ID {id_key_sqlite},
NAME TEXT,
SERVER_FILE_NAME TEXT,
SERVER_TEST TEXT,
IMAGE TEXT
);
''',
'''
CREATE TABLE SERVER_PLAY (
NAME TEXT,
VERSION TEXT
);
''',
'''
INSERT INTO SERVER_LIST (
NAME, SERVER_FILE_NAME, SERVER_TEST, IMAGE
) VALUES (
"CRA-MC", "cramc", "HELLO WORLD", "https://s21.ax1x.com/2024/05/06/pkEPVmV.jpg"
);
''',
'''
INSERT INTO SERVER_PLAY (
VERSION
) VALUES (
"v1.0"
);
'''
]
sql_file_config = sqlite3.connect(server_list_configfile)
sql_file_config_csr = sql_file_config.cursor()
for i_db in data_serverlistdbfile:
sql_file_config_csr.execute(i_db)
sql_file_config_csr.close()
sql_file_config.commit()
sql_file_config.close()
if os.system("ping www.baidu.com -n 1") == 1:
data = dict()
code = int(2)
data_config = {
"data_config": data,
"code": code
}
return self.data_th.emit(data_config)
with open(file=login_json_file, mode='r', encoding="UTF-8", newline='') as f_read:
login_json_user = json.load(f_read)
login_user = {
"accessToken": login_json_user.get("accessToken"),
"clientToken": login_json_user.get("clientToken")
}
json_login_crauser = requests.post(url=aotu_user_url + "authserver/validate", headers=login_headers, json=login_user)
if json_login_crauser.status_code != 204:
ref_login_key = requests.post(url=aotu_user_url + "authserver/refresh", headers=login_headers, json=login_user)
if ref_login_key.status_code != 204:
data = dict()
code = int(1)
data_config = {
"data_config": data,
"code": code
}
return self.data_th.emit(data_config)
url_https_mc_login_json = requests.post(url=aotu_user_url + "authserver/refresh", headers=login_headers, json=login_user)
data_login_file = {
"accessToken": url_https_mc_login_json.get("accessToken"),
"clientToken": url_https_mc_login_json.get("clientToken"),
"id": url_https_mc_login_json["selectedProfile"]["id"],
"name": url_https_mc_login_json["selectedProfile"]["name"]
}
with open(file=login_json_file, mode='w', encoding="UTF-8", newline='') as dump_f:
json.dump(data_login_file, dump_f)
print_server_list = sqlite_shell(sql_db=server_list_configfile, sql_code="SELECT * FROM SERVER_LIST;")
data_server_list_dicts = list()
for dict_server_list in print_server_list:
data_server_list_dict = dict()
data_server_list_dict["name"] = dict_server_list[1]
data_server_list_dict["server_file_name"] = dict_server_list[2]
data_server_list_dict["server_test"] = dict_server_list[3]
req_image = requests.get(url=dict_server_list[4])
image_print = req_image.content
data_server_list_dict["image"] = image_print
data_server_list_dicts.append(data_server_list_dict)
data = {
"name": login_json_user.get("name"),
"server_list": data_server_list_dicts
}
data_config = {
"data_config": data,
"code": code
}
return self.data_th.emit(data_config)
class customQListWidgetItem(QListWidgetItem):
def __init__(self, image, names: str, tests: str):
super().__init__()
self.item_widget = QWidget()
images = QImage.fromData(image)
image = QLabel()
image.setPixmap(QPixmap.fromImage(images).scaled(144, 60))
name = QLabel()
name.setText(str(names))
test = QLabel()
test.setText(str(tests))
vbox_server_test = QVBoxLayout()
vbox_server_test.addWidget(name, alignment=Qt.AlignLeft | Qt.AlignTop)
vbox_server_test.addWidget(test, alignment=Qt.AlignTop | Qt.AlignLeft)
hb_box = QHBoxLayout()
hb_box.setSpacing(10)
hb_box.setContentsMargins(0, 0, 0, 0)
hb_box.addWidget(image, alignment=Qt.AlignLeft | Qt.AlignLeft)
hb_box.addLayout(vbox_server_test)
hb_box.addStretch(1)
self.item_widget.setLayout(hb_box)
self.setSizeHint(self.item_widget.sizeHint())

View File

@ -0,0 +1 @@
{"accessToken": "336491270a1611ef92c5e252f2c508d4", "clientToken": "32cbdf4d-0a16-11ef-92c5-e252f2c508d4", "id": "a6143eb7a7883daab9a05dbe052879a1", "name": "GameDaBai"}

Binary file not shown.

282
main.py Normal file
View File

@ -0,0 +1,282 @@
from PySide2.QtGui import QCloseEvent
from module import *
class Login_Window_app(QWidget):
def __init__(self):
super().__init__()
self.run_myapp()
self.run_app()
def run_app(self):
self.setWindowTitle(apps.window_title_apps_name)
self.setWindowFlags(Qt.FramelessWindowHint)
self.setFixedSize(250, 110)
hbox = QHBoxLayout()
self.title = QLabel(text="正在启动 CRA-SERVER CLIENT")
self.title.setStyleSheet("font-size: 15px;")
hbox.addWidget(self.title, alignment=Qt.AlignCenter | Qt.AlignCenter)
self.setLayout(hbox)
def run_myapp(self):
self.th_start_config = apps.Thread_appcode_login_user()
self.th_start_config.data_th.connect(self.run_th_app)
self.th_start_config.start()
return None
def run_th_app(self, data_config: dict):
self.destroy()
if data_config.get("code") == 2:
apps.Message_ok(message="网络出问题了,请检查完网络连接再来哦主人")
return sys.exit(0)
if data_config.get("code") != 1:
self.start_cramc_server_client_myapp = My_APP_Window(data=data_config.get("data_config"), code=data_config.get("code"))
self.start_cramc_server_client_myapp.show()
return None
apps.Message_ok(message="CRA-USER已过期请重新登录")
self.login_user_window = Login_users_window_app()
self.login_user_window.show()
return None
def closeEvent(self, event: QCloseEvent) -> None:
self.destroy()
return sys.exit(0)
class Login_users_window_app(QWidget):
def __init__(self):
super().__init__()
self.setWindowFlags(Qt.FramelessWindowHint)
self.setFixedSize(apps.window_size_int[0], apps.window_size_int[1])
self.setWindowTitle(apps.window_title_apps_name + " - 登录")
self.draggable = False
self.offset = None
window_box = QGridLayout()
title_hbox = QHBoxLayout()
title_hbox.addWidget(QLabel(apps.window_title_apps_name), alignment=Qt.AlignLeft | Qt.AlignTop)
close_app_button = QToolButton()
close_app_button.setIcon(QIcon("style/exit.png"))
close_app_button.clicked.connect(self.close_apps_button_ttols)
title_hbox.addWidget(close_app_button, alignment=Qt.AlignRight | Qt.AlignTop)
login_user_box_hbox = QVBoxLayout()
login_user_box_hbox.setContentsMargins(250, 0, 250, 0)
login_user_box = QGridLayout()
login_user_box.setSpacing(15)
login_user_box.addWidget(QLabel(text="用户名:"), 0, 0, alignment=Qt.AlignTop)
self.username = QLineEdit()
login_user_box.addWidget(self.username, 0, 1, alignment=Qt.AlignTop)
login_user_box.addWidget(QLabel(text="密码:"), 1, 0, alignment=Qt.AlignTop)
self.password = QLineEdit()
self.password.setEchoMode(QLineEdit.Password)
login_user_box.addWidget(self.password, 1, 1, alignment=Qt.AlignTop)
login_user_button = QPushButton(text="登录")
login_user_button.clicked.connect(self.login_users_mcgames)
login_user_box.addWidget(login_user_button, 2, 0, 1, 0)
register_user = QToolButton(text="注册")
reload_password = QToolButton(text="忘记密码?")
login_user_box.addWidget(register_user, 3, 0, alignment=Qt.AlignTop | Qt.AlignLeft)
login_user_box.addWidget(reload_password, 3, 1, alignment=Qt.AlignTop | Qt.AlignRight)
login_user_box_hbox.addLayout(login_user_box)
window_box.addLayout(title_hbox, 0, 0, alignment=Qt.AlignTop)
window_box.addLayout(login_user_box_hbox, 1, 0, alignment=Qt.AlignTop | Qt.AlignCenter)
self.setLayout(window_box)
def login_users_mcgames(self):
if self.username.text() == "" or self.password.text() == "":
return apps.Message_ok(message="请填写完整的账号信息用户名和密码")
login_json = {
"username": self.username.text(),
"password": self.password.text()
}
url_https_mc_login = requests.post(url=apps.aotu_user_url + "authserver/authenticate", headers=apps.login_headers, json=login_json)
url_https_mc_login_json = url_https_mc_login.json()
if url_https_mc_login_json.get("error") == "ForbiddenOperationException":
return apps.Message_ok(message=url_https_mc_login_json.get("errorMessage"))
data_login_file = {
"accessToken": url_https_mc_login_json.get("accessToken"),
"clientToken": url_https_mc_login_json.get("clientToken"),
"id": url_https_mc_login_json["selectedProfile"]["id"],
"name": url_https_mc_login_json["selectedProfile"]["name"]
}
with open(file=apps.login_json_file, mode='w', encoding="UTF-8", newline='') as f_write:
json.dump(data_login_file, f_write)
self.destroy()
self.start_craserver_client_window = My_APP_Window(data=data_login_file, code=0)
self.start_craserver_client_window.show()
return None
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = True
self.offset = event.pos()
def mouseMoveEvent(self, event):
if self.draggable:
self.move(event.globalPos() - self.offset)
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = False
def closeEvent(self, event: QCloseEvent) -> None:
self.destroy()
return sys.exit(0)
def close_apps_button_ttols(self):
self.destroy()
return sys.exit(0)
class My_APP_Window(QTabWidget):
def __init__(self, data: dict, code: int):
super().__init__()
self.data = data
self.code = code
self.server_list_dict = self.data.get("server_list")
self.setWindowFlags(Qt.FramelessWindowHint)
self.setFixedSize(apps.window_size_int[0], apps.window_size_int[1])
self.setWindowTitle(apps.window_title_apps_name)
self.draggable = False
self.offset = None
self.run_my_gui()
def run_my_gui(self):
gui_box_grid = QGridLayout()
gui_box_grid.setColumnMinimumWidth(0, 0)
title_name = QLabel(text=apps.window_title_apps_name)
gui_box_grid.addWidget(title_name, 0, 0, alignment=Qt.AlignTop | Qt.AlignLeft)
zxh_button = QToolButton()
zxh_button.setIcon(QIcon("style/zxh.png"))
zxh_button.clicked.connect(self.zxh_apps)
exit_button = QToolButton()
exit_button.setIcon(QIcon("style/exit.png"))
exit_button.clicked.connect(self.exit_window_apps)
window_header_gridbox = QHBoxLayout()
window_header_gridbox.setContentsMargins(0, 0, 0, 0)
window_header_gridbox.addStretch(0)
window_header_gridbox.addWidget(zxh_button, alignment=Qt.AlignTop | Qt.AlignRight)
window_header_gridbox.addWidget(exit_button, alignment=Qt.AlignTop | Qt.AlignRight)
gui_box_grid.addLayout(window_header_gridbox, 0, 1)
self.index_home = QWidget()
self.craserver_client_settings = Craserver_client_settings()
self.craserver_client_game_settings = QWidget()
self.craserver_client_user_settings = QWidget()
self.header_tab = QTabWidget()
self.header_tab.setContentsMargins(0, 0, 0, 0)
self.header_tab.addTab(self.index_home, "主页")
self.header_tab.addTab(self.craserver_client_settings, "管理")
self.header_tab.addTab(self.craserver_client_game_settings, "设置")
self.header_tab.addTab(self.craserver_client_user_settings, "CRA-USER")
gui_box_grid.addWidget(self.header_tab, 1, 0, 1, 0)
self.setLayout(gui_box_grid)
self.index_home_page()
self.craserver_client_game_settings_page()
self.craserver_client_user_settings_page()
def craserver_client_user_settings_page(self):
pass
def craserver_client_game_settings_page(self):
pass
def index_home_page(self):
index_home_grid_box = QGridLayout()
self.server_list = QListWidget()
self.start_game_button = QPushButton(text="启动CRA-SERVER")
self.start_game_button.clicked.connect(self.start_games_apps)
self.start_game_button.setFixedSize(200, 55)
index_home_grid_box.addWidget(self.server_list, 0, 0)
index_home_grid_box.addWidget(self.start_game_button, 1, 0, alignment=Qt.AlignRight | Qt.AlignBottom)
for i_server_list in self.server_list_dict:
item = apps.customQListWidgetItem(image=i_server_list.get("image"), names=i_server_list.get("name"), tests=i_server_list.get("server_test"))
self.server_list.addItem(item)
self.server_list.setItemWidget(item, item.item_widget)
self.index_home.setLayout(index_home_grid_box)
def start_games_apps(self):
if self.server_list.currentRow() == -1:
return apps.Message_ok(message="请先选择需要加入的服务器")
return None
def zxh_apps(self):
return self.showMinimized()
def exit_window_apps(self):
self.destroy()
return sys.exit(0)
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = True
self.offset = event.pos()
def mouseMoveEvent(self, event):
if self.draggable:
self.move(event.globalPos() - self.offset)
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = False
def closeEvent(self, event: QCloseEvent) -> None:
self.destroy()
return sys.exit(0)
class Craserver_client_settings(QTabWidget):
def __init__(self):
super().__init__()
self.mods_settings = QWidget()
self.sh_settings = QWidget()
self.addTab(self.mods_settings, "MODS列表")
self.addTab(self.sh_settings, "光影管理")
self.mods_settings_page()
self.sh_settings_page()
def mods_settings_page(self):
pass
def sh_settings_page(self):
pass
if __name__ == '__main__':
is_json_none = False
QGuiApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough
)
QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
app = QApplication()
if os.path.exists("config_app") is False:
os.mkdir("config_app")
if os.path.isfile(apps.login_json_file) is False:
window = Login_users_window_app()
if os.path.isfile(apps.login_json_file) is True:
with open(file=apps.login_json_file, mode='r', encoding="UTF-8", newline='') as f_read:
json_test = json.load(f_read)
is_json_none = all(json_test)
if is_json_none is False:
window = Login_users_window_app()
if os.path.isfile(apps.login_json_file) is True & is_json_none is True:
window = Login_Window_app()
window.show()
sys.exit(app.exec_())

19
module.py Normal file
View File

@ -0,0 +1,19 @@
from PySide2.QtWidgets import QWidget, QTabWidget, QApplication, QHBoxLayout, QVBoxLayout, QGridLayout
from PySide2.QtGui import QGuiApplication, QPixmap, QImage, QIcon
from PySide2.QtCore import QCoreApplication, Qt, QThread, QSettings, Signal
from PySide2.QtWidgets import (
QPushButton, QToolButton, QListWidget, QLineEdit, QLabel, QTableWidget, QCheckBox, QComboBox, QMessageBox, QSlider, QProgressBar,
QFileDialog, QListWidgetItem
)
import sys
import os
import queue
import requests
import json
import datetime
import sqlite3
from time import sleep
import zipfile
from shutil import rmtree
import subprocess
import apps

BIN
style/exit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

1
style/message.qss Normal file
View File

@ -0,0 +1 @@

25
style/style.qss Normal file
View File

@ -0,0 +1,25 @@
QWidget {
font-family: "Microsoft YaHei";
outline: none;
background-color: #111;
color: #f5f5f5;
border: none;
}
QTabWidget {
font-family: "Microsoft YaHei";
outline: none;
background-color: #111;
color: #f5f5f5;
border: none;
}
QToolButton {
border: none;
color: none;
background-color: none;
}
QLineEdit {
height: 25px;
}

BIN
style/zxh.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B