-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from PyQt5.QtCore import Qt, QPoint, QAbstractTableModel, QVariant | ||
class ServerInfoModel(QAbstractTableModel): | ||
def __init__(self, data, parent=None): | ||
super(ServerInfoModel, self).__init__(parent) | ||
self._data = data | ||
self._headers = ['IP', 'Name', 'Map', 'Players', 'Max Players'] | ||
|
||
def rowCount(self, parent=None): | ||
return len(self._data) | ||
|
||
def columnCount(self, parent=None): | ||
return len(self._headers) | ||
|
||
def data(self, index, role=Qt.DisplayRole): | ||
if not index.isValid() or role != Qt.DisplayRole: | ||
return QVariant() | ||
|
||
row = index.row() | ||
column = index.column() | ||
|
||
if row >= len(self._data) or column >= len(self._headers): | ||
return QVariant() | ||
|
||
item = self._data[row] | ||
|
||
# Map columns to data | ||
if column == 0: | ||
return QVariant(f"{item.get('ip', 'N/A')}:{item.get('port', 'N/A')}") | ||
elif column == 1: | ||
return QVariant(item.get('name', 'N/A')) | ||
elif column == 2: | ||
return QVariant(item.get('map', 'N/A')) | ||
elif column == 3: | ||
return QVariant(item.get('players', 'N/A')) | ||
elif column == 4: | ||
return QVariant(item.get('max_players', '64')) | ||
else: | ||
return QVariant() | ||
|
||
def headerData(self, section, orientation, role=Qt.DisplayRole): | ||
if role != Qt.DisplayRole: | ||
return QVariant() | ||
|
||
if orientation == Qt.Horizontal: | ||
return QVariant(self._headers[section]) | ||
return QVariant() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import itertools | ||
from steam import SteamQuery | ||
|
||
# 定义 IP 和端口列表 | ||
server_ip = ["110.42.9.149", "110.42.9.181"] | ||
port = [27015, 27016] | ||
|
||
|
||
def ZombiEden_Server_Query(): | ||
server_info = [] | ||
|
||
# 遍历 IP 和端口组合 | ||
for ip, p in itertools.product(server_ip, port): | ||
try: | ||
server_obj = SteamQuery(ip, p) | ||
|
||
# 使用公开方法获取服务器信息 | ||
info = server_obj.query_server_info() | ||
|
||
server_info.append({ | ||
'ip': ip, | ||
'port': p, | ||
'name': info.get('name', 'N/A'), | ||
'map': info.get('map', 'N/A'), | ||
'players': info.get('players', 'N/A') | ||
}) | ||
except Exception as e: | ||
print(f"查询 {ip}:{p} 时出错: {e}") | ||
# 返回 server_info 列表 | ||
return server_info | ||
|
||
|
||
if __name__ == "__main__": | ||
# 调用 ZombiEden_Server_Query 函数并获取结果 | ||
result = ZombiEden_Server_Query() | ||
|
||
# 打印结果 | ||
for info in result: | ||
print(info) |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
from PyQt5.QtWidgets import QApplication, QMainWindow, QTableView, QVBoxLayout, QWidget, QPushButton, QMenu, QAction | ||
from PyQt5.QtCore import Qt, QPoint | ||
from PyQt5.QtGui import QIcon, QClipboard | ||
import sys | ||
import Query | ||
import PyqtFormModel | ||
import subprocess | ||
|
||
class MyWindow(QMainWindow): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
# 设置窗体标题 | ||
self.setWindowTitle("僵尸乐园登录器(暂时) ——By 717qwq") | ||
|
||
# 设置窗口图标 | ||
self.setWindowIcon(QIcon('./icon.ico')) # 替换为你的图标文件路径 | ||
|
||
# 获取服务器信息 | ||
server_info = Query.ZombiEden_Server_Query() | ||
|
||
# 创建模型 | ||
self.model = PyqtFormModel.ServerInfoModel(server_info) | ||
|
||
# 创建视图 | ||
self.table_view = QTableView() | ||
self.table_view.setModel(self.model) | ||
|
||
# 设置选择模式为行选择 | ||
self.table_view.setSelectionMode(QTableView.SingleSelection) | ||
self.table_view.setSelectionBehavior(QTableView.SelectRows) | ||
|
||
# 连接选择变化信号 | ||
self.table_view.selectionModel().selectionChanged.connect(self.on_selection_changed) | ||
|
||
# 创建按钮 | ||
self.refresh_button = QPushButton('刷新') | ||
self.exit_button = QPushButton('退出') | ||
|
||
# 连接按钮点击事件 | ||
self.refresh_button.clicked.connect(self.on_refresh) | ||
self.exit_button.clicked.connect(self.close) | ||
|
||
# 创建布局 | ||
button_layout = QVBoxLayout() | ||
button_layout.addWidget(self.refresh_button) | ||
button_layout.addWidget(self.exit_button) | ||
|
||
main_layout = QVBoxLayout() | ||
main_layout.addWidget(self.table_view) | ||
main_layout.addLayout(button_layout) | ||
|
||
# 设置中央窗口小部件 | ||
central_widget = QWidget() | ||
central_widget.setLayout(main_layout) | ||
self.setCentralWidget(central_widget) | ||
|
||
# 设置窗口初始大小 | ||
self.resize(800, 600) # 设置窗口宽度为 800,高度为 600 | ||
|
||
# 连接右键菜单事件 | ||
self.table_view.setContextMenuPolicy(Qt.CustomContextMenu) | ||
self.table_view.customContextMenuRequested.connect(self.show_context_menu) | ||
|
||
def resizeEvent(self, event): | ||
# 先调用父类的 resizeEvent 方法 | ||
super().resizeEvent(event) | ||
# 调整列宽以适应窗口大小 | ||
self.adjust_table_columns() | ||
|
||
def adjust_table_columns(self): | ||
# 调整列宽以适应窗口大小 | ||
total_width = self.table_view.viewport().width() | ||
column_count = self.table_view.model().columnCount() | ||
if column_count > 0: | ||
# 每列分配宽度 | ||
width_per_column = total_width // column_count | ||
for column in range(column_count): | ||
self.table_view.setColumnWidth(column, width_per_column) | ||
def on_refresh(self): | ||
# 处理刷新按钮点击事件 | ||
print("Refresh button clicked") | ||
# 重新获取数据并更新模型 | ||
server_info = Query.ZombiEden_Server_Query() | ||
self.model = PyqtFormModel.ServerInfoModel(server_info) | ||
self.table_view.setModel(self.model) | ||
self.adjust_table_columns() | ||
|
||
def show_context_menu(self, pos: QPoint): | ||
# 创建上下文菜单 | ||
context_menu = QMenu(self) | ||
|
||
# 添加菜单项 | ||
action1 = QAction('连接服务器', self) | ||
action1.triggered.connect(self.action1_triggered) | ||
context_menu.addAction(action1) | ||
|
||
action2 = QAction('复制IP', self) | ||
action2.triggered.connect(self.action2_triggered) | ||
context_menu.addAction(action2) | ||
|
||
# 显示菜单 | ||
context_menu.exec_(self.table_view.viewport().mapToGlobal(pos)) | ||
|
||
def action1_triggered(self): | ||
# 获取选中的行 | ||
selection = self.table_view.selectionModel().selectedRows() | ||
if selection: | ||
selected_row = selection[0].row() | ||
item = self.model._data[selected_row] | ||
ip = item.get('ip', 'N/A') | ||
port = item.get('port', 'N/A') | ||
connect_url = f"steam://rungame/730/76561202255233023/+connect%20{ip}:{port}" | ||
print(f"Connecting to: {connect_url}") | ||
# 使用系统命令打开链接 | ||
# 根据操作系统选择合适的命令 | ||
if sys.platform == 'win32': | ||
subprocess.run(["start", connect_url], check=True, shell=True) # Windows | ||
elif sys.platform == 'darwin': | ||
subprocess.run(["open", connect_url], check=True) # macOS | ||
else: | ||
subprocess.run(["xdg-open", connect_url], check=True) # Linux | ||
|
||
def action2_triggered(self): | ||
# 处理复制IP和端口的点击事件 | ||
selection = self.table_view.selectionModel().selectedRows() | ||
if selection: | ||
selected_row = selection[0].row() | ||
item = self.model._data[selected_row] | ||
ip = item.get('ip', 'N/A') | ||
port = item.get('port', 'N/A') | ||
|
||
# 格式化 IP 和端口 | ||
ip_port = f"{ip}:{port}" | ||
|
||
# 获取剪贴板对象 | ||
clipboard = QApplication.clipboard() | ||
# 将 IP 和端口复制到剪贴板 | ||
clipboard.setText(ip_port) | ||
print(f"Copied IP and Port: {ip_port}") | ||
|
||
def on_selection_changed(self): | ||
# 处理选择变化 | ||
selection = self.table_view.selectionModel().selectedRows() | ||
if selection: | ||
selected_row = selection[0].row() | ||
print(f"Selected Row: {selected_row}") | ||
|
||
if __name__ == "__main__": | ||
app = QApplication(sys.argv) | ||
window = MyWindow() | ||
window.show() | ||
window.adjust_table_columns() | ||
sys.exit(app.exec_()) |