Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit

Permalink
[add] wfhelper: Add multi session support
Browse files Browse the repository at this point in the history
  • Loading branch information
kmou424 committed Mar 5, 2022
1 parent 07a6144 commit 1c93767
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 243 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/configs
/prebuilt
/runners
/template
/tools
__pycache__
Expand Down
57 changes: 57 additions & 0 deletions create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os
import sys
from pathlib import Path

from lib.logger import Logger

VENV_PYTHON_PATH = 'tools/Scripts/python.exe'
RUNNER_DIR = 'runners/'
WIN_SCRIPT_NAME = '.bat'
LINUX_SCRIPT_NAME = '.sh'

if len(sys.argv) == 3:
if not 0 <= int(sys.argv[1]) <= 65536:
Logger.displayLog("端口号无效", Logger.LOG_LEVEL_ERROR, -1)
WIN_SCRIPT_NAME = sys.argv[2] + WIN_SCRIPT_NAME
LINUX_SCRIPT_NAME = sys.argv[2] + LINUX_SCRIPT_NAME
else:
print("Usage: {filename} [port] [session_name]"
.format(filename=os.path.basename(sys.argv[0])))
exit(-1)

if not Path(RUNNER_DIR).exists():
os.makedirs(RUNNER_DIR)


def generateRunScript(name):
if 'win' in sys.platform:
with open(RUNNER_DIR + WIN_SCRIPT_NAME, 'w') as run_bat:
run_bat.writelines('@title {name}\n'.format(name=name))
run_bat.writelines('cd ..\n')
run_bat.writelines('{python_path} wfhelper.py {port} {config_path}\n'
.format(
python_path=VENV_PYTHON_PATH.replace('/', '\\'),
port=sys.argv[1],
config_path='configs/{name}.ini'.format(name=name)
))
if 'linux' in sys.platform or 'mac' in sys.platform:
with open(RUNNER_DIR + LINUX_SCRIPT_NAME, 'w') as run_sh:
run_sh.writelines('#!/bin/bash\n')
run_sh.writelines('cd ..\n')
run_sh.writelines('{python_path} wfhelper.py {port} {config_path}\n'
.format(
python_path=VENV_PYTHON_PATH,
port=sys.argv[1],
config_path='configs/{name}.ini'.format(name=name)
))


def removeOldRunScript(name):
if Path(WIN_SCRIPT_NAME).exists():
os.remove(WIN_SCRIPT_NAME)
if Path(LINUX_SCRIPT_NAME).exists():
os.remove(LINUX_SCRIPT_NAME)


removeOldRunScript(sys.argv[2])
generateRunScript(sys.argv[2])
24 changes: 0 additions & 24 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,6 @@ def createToolsVenv():
os.system('python -m venv tools')


def generateRunScript():
if 'win' in sys.platform:
with open('run.bat', 'w') as run_bat:
run_bat.writelines('@title WFHelperPy\n')
run_bat.writelines('{python_path} wfhelper.py\n'
.format(python_path=VENV_PYTHON_PATH.replace('/', '\\')))
if 'linux' in sys.platform or 'mac' in sys.platform:
with open('run.sh', 'w') as run_sh:
run_sh.writelines('#!/bin/bash\n')
run_sh.writelines('{python_path} wfhelper.py\n'
.format(python_path=VENV_PYTHON_PATH))
Logger.displayLog("生成新的启动脚本", quit_code=0)


def removeOldRunScript():
if Path('run.bat').exists():
os.remove('run.bat')
if Path('run.sh').exists():
os.remove('run.sh')
Logger.displayLog("清除旧的启动脚本")


def installRequirements():
Logger.displayLog("检查并安装依赖")
os.system('{pip_path} install wheel'.format(pip_path=VENV_PIP_PATH.replace('/', PATH_DELIMITER)))
Expand All @@ -70,10 +48,8 @@ def installRequirements():
os.system('{pip_path} install {whl}'.format(pip_path=VENV_PIP_PATH.replace('/', PATH_DELIMITER), whl=whl))
_ret = os.system(
'{pip_path} install -r requirements.txt'.format(pip_path=VENV_PIP_PATH.replace('/', PATH_DELIMITER)))
removeOldRunScript()
if _ret == 0:
Logger.displayLog("安装依赖成功")
generateRunScript()
else:
Logger.displayLog("安装依赖失败", Logger.LOG_LEVEL_ERROR, quit_code=_ret)

Expand Down
160 changes: 80 additions & 80 deletions lib/base.py
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
import cv2
import numpy

from lib.times import Time


class Point:
def __init__(self, x: float, y: float):
self.x = x
self.y = y

def loadZoom(self, zoom: float):
if zoom > 1.0:
self.x = self.x * zoom
self.y = self.y * zoom


class Rect:
def __init__(self, left_top: Point, right_bottom: Point):
self.left_top = left_top
self.right_bottom = right_bottom


class Rgb:
def __init__(self, r, g, b):
self.red = r
self.green = g
self.blue = b

@staticmethod
def point2rgb(img: cv2.cv2, point: Point):
return Rgb.pixel2rgb(img[point.y, point.x])

@staticmethod
def pixel2rgb(pixel: numpy.ndarray):
return Rgb(pixel[2], pixel[1], pixel[0])


class Color:
def __init__(self, left: Rgb, right: Rgb):
self.left = left
self.right = right

def isMatch(self, src: Rgb):
return (self.left.red <= src.red <= self.right.red) and \
(self.left.green <= src.green <= self.right.green) and \
(self.left.blue <= src.blue <= self.right.blue)


class Boss:
BossLevels = {
'prim': '初级',
'mid': '中级',
'high': '高级',
'highp': '高级+',
'super': '超级'
}

def __init__(self, item: dict):
self.item = item

def isAvailable(self) -> bool:
end_time = Time.getTimeStampByStandardFormat(self.item['end'])
now_time = Time.getTimeStampForNow()
return end_time > now_time

def getName(self) -> str:
return self.item['name']

def getId(self) -> str:
return self.item['id']

def getType(self) -> str:
return self.item['type']

def getLevels(self) -> str:
return self.item['levels']

def getMinLevel(self):
return self.getLevels().split(' ')[0]
import cv2
import numpy

from lib.times import Time


class Point:
def __init__(self, x: float, y: float):
self.x = x
self.y = y

def loadZoom(self, zoom: float):
if zoom > 1.0:
self.x = self.x * zoom
self.y = self.y * zoom


class Rect:
def __init__(self, left_top: Point, right_bottom: Point):
self.left_top = left_top
self.right_bottom = right_bottom


class Rgb:
def __init__(self, r, g, b):
self.red = r
self.green = g
self.blue = b

@staticmethod
def point2rgb(img: cv2.cv2, point: Point):
return Rgb.pixel2rgb(img[point.y, point.x])

@staticmethod
def pixel2rgb(pixel: numpy.ndarray):
return Rgb(pixel[2], pixel[1], pixel[0])


class Color:
def __init__(self, left: Rgb, right: Rgb):
self.left = left
self.right = right

def isMatch(self, src: Rgb):
return (self.left.red <= src.red <= self.right.red) and \
(self.left.green <= src.green <= self.right.green) and \
(self.left.blue <= src.blue <= self.right.blue)


class Boss:
BossLevels = {
'prim': '初级',
'mid': '中级',
'high': '高级',
'highp': '高级+',
'super': '超级'
}

def __init__(self, item: dict):
self.item = item

def isAvailable(self) -> bool:
end_time = Time.getTimeStampByStandardFormat(self.item['end'])
now_time = Time.getTimeStampForNow()
return end_time > now_time

def getName(self) -> str:
return self.item['name']

def getId(self) -> str:
return self.item['id']

def getType(self) -> str:
return self.item['type']

def getLevels(self) -> str:
return self.item['levels']

def getMinLevel(self):
return self.getLevels().split(' ')[0]
3 changes: 3 additions & 0 deletions lib/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import configparser as ConfigParser
import os.path
from pathlib import Path


Expand All @@ -18,6 +19,8 @@ def __init__(self, filename: str, writable=False):
self.__initConfigParser()

def __initConfigParser(self):
if not Path(os.path.dirname(self.filename)).exists():
os.makedirs(os.path.dirname(self.filename))
if not Path(self.filename).exists():
self.config_parser.write(open(self.filename, 'w', encoding='utf-8'))
else:
Expand Down
11 changes: 6 additions & 5 deletions modules/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@


class TrackerThread(threading.Thread):
def __init__(self, adb):
def __init__(self, adb, config_file):
threading.Thread.__init__(self)
self.mTask = Task.NO_TASK
self.mStatus = StatusCode.NO_ERROR
cfgMan = ConfigManager('config.ini', writable=False)
cfgMan = ConfigManager(config_file, writable=False)
mGameServer = cfgMan \
.selectSection(ConfigSections.SECTION_SETTINGS.get()) \
.getString(ConfigOptions.GAME_SERVER.get(), default='cn')
Expand Down Expand Up @@ -155,9 +155,10 @@ def __back_to_home(self):


class Tracker:
def __init__(self):
def __init__(self, config_file):
self.adb_tools = None
self.trackerThread = TrackerThread(None)
self.trackerThread = TrackerThread(None, config_file)
self.__config_file = config_file

def run(self, address: str):
self.adb_tools = AdbTools(address)
Expand All @@ -171,7 +172,7 @@ def run(self, address: str):
return ResultCode.START_FAILED
# 开始运行线程
if not self.running():
self.trackerThread = TrackerThread(adb=self.adb_tools)
self.trackerThread = TrackerThread(self.adb_tools, self.__config_file)
self.trackerThread.start()
return ResultCode.START_SUCCEED

Expand Down
Loading

0 comments on commit 1c93767

Please sign in to comment.