diff --git a/AUTO_MAA.exe b/AUTO_MAA.exe new file mode 100644 index 0000000..9377276 Binary files /dev/null and b/AUTO_MAA.exe differ diff --git a/AUTO_MAA.py b/AUTO_MAA.py new file mode 100644 index 0000000..c3cd287 --- /dev/null +++ b/AUTO_MAA.py @@ -0,0 +1,29 @@ +import sqlite3 +import subprocess +import datetime +import time +import os +from termcolor import colored + +DATABASE="data/data.db" +db=sqlite3.connect(DATABASE) +cur=db.cursor() +cur.execute("SELECT * FROM timeset WHERE True") +timeset=cur.fetchall() +timeset=[list(row) for row in timeset] +while True: + curtime=datetime.datetime.now().strftime("%H:%M") + print(colored("当前时间:"+curtime,'green')) + timenew=[] + timenew.append(curtime) + if timenew in timeset: + print(colored("开始执行",'yellow')) + maa=subprocess.Popen(["run.exe"]) + maapid=maa.pid + while True: + if os.path.exists("OVER"): + os.system('taskkill /F /T /PID '+str(maapid)) + os.remove("OVER") + print(colored("执行完毕",'yellow')) + break + time.sleep(1) \ No newline at end of file diff --git a/KillSpecifiedProcess.cpp b/KillSpecifiedProcess.cpp deleted file mode 100644 index b3cbc1b..0000000 --- a/KillSpecifiedProcess.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include"stdafx.h" -#include -#include -#include "boost/filesystem.hpp" -#include "boost/iostreams/stream.hpp" -#include "boost/format.hpp" -#include "boost/algorithm/algorithm.hpp" -#include "boost/algorithm/string.hpp" -using namespace std; - -#define READ_ONE_NUM 1024 - -/* - ɱָ·н -*/ -BOOL KillSpecifiedProcess(const std::string& p_strPath) -{ - /* - C:\Users\10139>wmic process where name="notepad.exe" get executablepath,processid - ExecutablePath ProcessId - C:\WINDOWS\system32\notepad.exe 6196 - C:\WINDOWS\system32\notepad.exe 6056 - - - C:\Users\10139>taskkill /F /PID 6196 /PID 6056 - ɹ: ֹ PID Ϊ 6196 Ľ̡ - ɹ: ֹ PID Ϊ 6056 Ľ̡ - */ - if(!boost::filesystem::exists(p_strPath)) - { - cout << p_strPath << " not exist" << endl; - return FALSE; - } - int index = p_strPath.rfind("\\"); - std::string strName = p_strPath.substr(index + 1); - SECURITY_ATTRIBUTES sa; - sa.nLength = sizeof(SECURITY_ATTRIBUTES); - sa.bInheritHandle = TRUE; - sa.lpSecurityDescriptor = NULL; - HANDLE hStdOutRead = NULL, hStdOutWrite = NULL; - if (!CreatePipe(&hStdOutRead, &hStdOutWrite, &sa, 0)) - { - cout << "create pipe error," << GetLastError() << endl; - return FALSE; - } - STARTUPINFOA startInfo; - PROCESS_INFORMATION procInfo; - BOOL bSuccess = FALSE; - ZeroMemory(&procInfo, sizeof(PROCESS_INFORMATION)); - ZeroMemory(&startInfo, sizeof(STARTUPINFOA)); - startInfo.cb = sizeof(STARTUPINFOA); - startInfo.hStdOutput = hStdOutWrite; - startInfo.dwFlags |= (STARTF_USESTDHANDLES |STARTF_USESHOWWINDOW) ; - startInfo.wShowWindow = SW_HIDE; - - boost::format fmt("wmic process where name=\"%1%\" get executablepath,processid"); - fmt % strName; - std::string strSQL = fmt.str(); - bSuccess = CreateProcessA(NULL, (char*)strSQL.data(), NULL, NULL, TRUE, 0, NULL, NULL, &startInfo, &procInfo); - if (!bSuccess) - { - cout << "create process error," << GetLastError() << endl; - return FALSE; - } - WaitForSingleObject(procInfo.hProcess,INFINITE); - CloseHandle(hStdOutWrite); - DWORD byteRead = 0; - std::string strContent; - char buffer[READ_ONE_NUM] = {0}; - while (true) - { - byteRead = 0; - memset(buffer, 0, READ_ONE_NUM); - BOOL bRead = ReadFile(hStdOutRead, buffer, (READ_ONE_NUM-1)* sizeof(buffer[0]) , &byteRead, NULL); - if (!bRead) - { - break; - } - strContent.append(buffer); - } - CloseHandle(hStdOutRead); - std::vector splitVec; - boost::split(splitVec, strContent, boost::is_any_of("\r\n"), boost::token_compress_on); - if(splitVec.size() > 0) - { - if( !boost::icontains(splitVec[0], "ExecutablePath") ) - { - // û - cout << strName << " is not runing" << endl; - return FALSE; - } - // for룺Żʹʽȡ·ͳPID - // 1к1ж - for(int i = 1; i < splitVec.size() -1; i++) - { - std::vector splitVec2; - boost::split(splitVec2, splitVec[i], boost::is_any_of(" "), boost::token_compress_on); - int size = splitVec2.size(); - if(size >= 3) - { - std::string exePath; - // ȡͬ· - for(int i = 0; i < size -1 -1; i++) - { - exePath.append(splitVec2[i]); - exePath.append(" "); - } - // ж·Ƿȫƥ - if( !boost::icontains(exePath, p_strPath) ) - { - continue; - } - - // ·пո񣬵2Ϊpid - std::string pId = splitVec2[size -1 -1]; - std::string cmd = "taskkill /F /PID "; - cmd.append(pId); - cout << p_strPath << "->" << cmd << endl; - WinExec(cmd.c_str(), SW_HIDE); - } - } - } - return TRUE; -} - -int main(int argc, char* argv[]) -{ - for(int i = 1; i < argc ; i++) - { - KillSpecifiedProcess(argv[i]); - } - return 0; -} \ No newline at end of file diff --git a/manage.exe b/manage.exe new file mode 100644 index 0000000..43cf865 Binary files /dev/null and b/manage.exe differ diff --git a/manage.py b/manage.py index 692533c..7e5094e 100644 --- a/manage.py +++ b/manage.py @@ -42,13 +42,30 @@ def delete(id): def search(id,book): db=sqlite3.connect(DATABASE) cur=db.cursor() + #处理启动时间查询 + if id=="time": + cur.execute("SELECT * FROM timeset WHERE True") + timex=cur.fetchall() + timex=[list(row) for row in timex] + cur.close() + db.close() + if len(timex)==0: + return "启动时间未设置" + else: + for i in range(len(timex)): + print(timex[i][0]) + return "" #处理MAA路径查询 if id=="maa": - cur.execute("SELECT * FROM setting WHERE True") + cur.execute("SELECT * FROM pathset WHERE True") pathx=cur.fetchall() if len(pathx)>0: + cur.close() + db.close() return pathx[0][0] else: + cur.close() + db.close() return "MAA路径未设置" #处理用户查询与全部信息查询 if id=="all": @@ -56,13 +73,24 @@ def search(id,book): else: cur.execute("SELECT * FROM adminx WHERE admin='%s'" %(id)) data=cur.fetchall() + #处理全部信息查询时的MAA路径与启动时间查询 if id=="all": - cur.execute("SELECT * FROM setting WHERE True") + cur.execute("SELECT * FROM pathset WHERE True") pathx=cur.fetchall() if len(pathx)>0: print("\nMAA路径:"+pathx[0][0]) else: print("\nMAA路径未设置") + cur.execute("SELECT * FROM timeset WHERE True") + timex=cur.fetchall() + timex=[list(row) for row in timex] + if len(timex)==0: + print("\n启动时间未设置") + else: + print("启动时间:",end='') + for i in range(len(timex)): + print(timex[i][0],end=' ') + print('') cur.close() db.close() data=[list(row) for row in data] @@ -89,7 +117,7 @@ def search(id,book): print(unit(data[i][0],15),unit(data[i][1],12),unit(data[i][2],8),unit(data[i][3],4),unit(data[i][4],10),unit(data[i][5],10),unit(data[i][6],25)) return "" elif id=="all": - return "当前没有用户记录" + return "\n当前没有用户记录" else: return "未找到"+id @@ -107,6 +135,8 @@ def renewal(readxx): cur.execute("SELECT * FROM adminx WHERE admin='%s'" %(id)) data=cur.fetchall() if len(data)==0: + cur.close() + db.close() return "未找到"+id #应用更新 cur.execute("UPDATE adminx SET day=%d WHERE admin='%s'" %(data[0][2]+dayp,id)) @@ -123,10 +153,11 @@ def turn(id,t): cur.execute("SELECT * FROM adminx WHERE admin='%s'" %(id)) data=cur.fetchall() if len(data)==0: + cur.close() + db.close() return "未找到"+id #应用更新 - if t=='y' or t=='n': - cur.execute("UPDATE adminx SET status='%s' WHERE admin='%s'" %(t,id)) + cur.execute("UPDATE adminx SET status='%s' WHERE admin='%s'" %(t,id)) db.commit() cur.close() db.close() @@ -149,6 +180,8 @@ def gameid(readxx): cur.execute("SELECT * FROM adminx WHERE admin='%s'" %(id)) data=cur.fetchall() if len(data)==0: + cur.close() + db.close() return "未找到"+id #导入与应用特殊关卡规则 games={} @@ -174,17 +207,52 @@ def gameid(readxx): def setpath(pathx): db=sqlite3.connect(DATABASE) cur=db.cursor() - cur.execute("SELECT * FROM setting WHERE True") + cur.execute("SELECT * FROM pathset WHERE True") pathold=cur.fetchall() if len(pathold)>0: - cur.execute("UPDATE setting SET path='%s' WHERE True" %(pathx)) + cur.execute("UPDATE pathset SET path='%s' WHERE True" %(pathx)) else: - cur.execute("INSERT INTO setting(path) VALUES('%s')" %(pathx)) + cur.execute("INSERT INTO pathset(path) VALUES('%s')" %(pathx)) db.commit() cur.close() db.close() return "MAA路径已设置为"+pathx +#设置启动时间 +def settime(book,timex): + db=sqlite3.connect(DATABASE) + cur=db.cursor() + #检查待操作对象存在情况 + cur.execute("SELECT * FROM timeset WHERE True") + timeold=cur.fetchall() + timeold=[list(row) for row in timeold] + timenew=[] + timenew.append(timex) + #添加时间设置 + if book=='+': + if timenew in timeold: + cur.close() + db.close() + return "已存在"+timex + else: + cur.execute("INSERT INTO timeset(time) VALUES('%s')" %(timex)) + db.commit() + cur.close() + db.close() + return "已添加"+timex + #删除时间设置 + elif book=='-': + if timenew in timeold: + cur.execute("DELETE FROM timeset WHERE time='%s'" %(timex)) + db.commit() + cur.close() + db.close() + return "已删除"+timex + else: + cur.close() + db.close() + return "未找到"+timex + #统一制表单元 def unit(x,m): #字母与连接符占1位,中文占2位 @@ -201,9 +269,10 @@ if not os.path.exists(DATABASE): db=sqlite3.connect(DATABASE) cur=db.cursor() db.execute("CREATE TABLE adminx(admin text,number text,day int,status text,last date,game text,password text)") - db.execute("CREATE TABLE setting(path text)") + db.execute("CREATE TABLE pathset(path text)") + db.execute("CREATE TABLE timeset(time text)") readx=input("首次启动,请设置MAA路径:") - cur.execute("INSERT INTO setting(path) VALUES('%s')" %(readx)) + cur.execute("INSERT INTO pathset(path) VALUES('%s')" %(readx)) db.commit() cur.close() db.close() @@ -223,6 +292,8 @@ while True: exit() elif read[0]=='/': print(setpath(read[1:])) + elif read[0]==':' and (read[1]=='+' or read[1]=='-'): + print(settime(read[1],read[2:])) else: if read[-1]=='?': print(search(read[:-2],1)) diff --git a/mytaskkill.exe b/mytaskkill.exe deleted file mode 100644 index bb5e3ca..0000000 Binary files a/mytaskkill.exe and /dev/null differ diff --git a/res/AUTO_MAA.ico b/res/AUTO_MAA.ico new file mode 100644 index 0000000..96dff01 Binary files /dev/null and b/res/AUTO_MAA.ico differ diff --git a/res/AUTO_MAA.png b/res/AUTO_MAA.png new file mode 100644 index 0000000..12fe2db Binary files /dev/null and b/res/AUTO_MAA.png differ diff --git a/run.exe b/run.exe new file mode 100644 index 0000000..b2af8d5 Binary files /dev/null and b/run.exe differ diff --git a/run.py b/run.py index 4ef57e3..548ac0b 100644 --- a/run.py +++ b/run.py @@ -1,10 +1,12 @@ import os +import subprocess import sqlite3 import datetime import time import json from termcolor import colored +#判断MAA程序运行状态 def ifoff(): while True: time.sleep(10) @@ -17,16 +19,9 @@ def ifoff(): elif ("请检查连接设置或尝试重启模拟器与 ADB 或重启电脑" in log) or ("已停止" in log): return False -def killpath(maapath): - kpath='.\\mytaskkill.exe ' - for i in maapath: - if i=='/': - kpath=kpath+'\\' - else: - kpath=kpath+i - return kpath - -def runmaa(tel,game): +#执行MAA任务 +def runmaa(tel,game,num=2): + #配置MAA运行参数 with open(setpath,"r",encoding="utf-8") as f: data = json.load(f) data["Configurations"]["Default"]["Start.AccountName"]=tel[:3]+"****"+tel[7:] @@ -37,22 +32,18 @@ def runmaa(tel,game): data["Configurations"]["Default"]["MainFunction.Stage1"]=game with open(setpath,"w",encoding="utf-8") as f: json.dump(data,f) - os.system('start '+maapath) - time.sleep(60) - if ifoff(): - return True - else: - command=killpath(maapath) - os.system(command) - os.system('start '+maapath) + #开始运行 + for i in range(num): + maa=subprocess.Popen([maapath]) + maapid=maa.pid time.sleep(60) if ifoff(): return True else: - command=killpath(maapath) - os.system(command) - return False + os.system('taskkill /F /T /PID '+str(maapid)) + return False +#更新已完成用户的数据 def updata(id): db=sqlite3.connect(DATABASE) cur=db.cursor() @@ -71,7 +62,7 @@ def updata(id): DATABASE="data/data.db" db=sqlite3.connect(DATABASE) cur=db.cursor() -cur.execute("SELECT * FROM setting WHERE True") +cur.execute("SELECT * FROM pathset WHERE True") path=cur.fetchall() path=str(path[0][0]) setpath=path+"/config/gui.json" @@ -109,4 +100,6 @@ with open("log.txt","w", encoding="utf-8") as f: if len(idfail)!=0: print("代理未完成的用户:",file=f) for i in range(len(idfail)): - print(idfail[i],file=f) \ No newline at end of file + print(idfail[i],file=f) +with open("OVER","w", encoding="utf-8") as f: + print("OVER",file=f) \ No newline at end of file diff --git a/toexe.py b/toexe.py new file mode 100644 index 0000000..3cd5b11 --- /dev/null +++ b/toexe.py @@ -0,0 +1,5 @@ +import os + +os.system("pyinstaller -F -i res/AUTO_MAA.ico manage.py") +os.system("pyinstaller -F -i res/AUTO_MAA.ico run.py") +os.system("pyinstaller -F -i res/AUTO_MAA.ico AUTO_MAA.py") \ No newline at end of file diff --git a/部分代码的版权声明.txt b/部分代码的版权声明.txt deleted file mode 100644 index e05ee7e..0000000 --- a/部分代码的版权声明.txt +++ /dev/null @@ -1,7 +0,0 @@ - 声明: - -KillSpecifiedProcess.cpp与mytaskkill.exe来自CSDN博主的文章,遵循CC 4.0 BY-SA 版权协议附加以下信息: - -版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 - -原文链接:https://blog.csdn.net/qq_29542611/article/details/122003681 \ No newline at end of file