#pragma comment(linker, "/subsystem:\"Windows\" /entry:\"mainCRTStartup\"") #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; ofstream logFile; // 日志文件 vector blackList; // 黑名单 int blackListTimeCount = 0; // 黑名单时间计数 const int MAX_BLACKLIST_TIME_COUNT = 1800; // 黑名单最大时间 const int TOLENT_MORE_TIME = 1200; // 超出黑名单时间后,多长时间禁止摸鱼 const int PUNISH_CLICKS = 20; // 连续点击次数超过多少次后允许继续 const int PUNISH_CLICKS_RND = 10; // 连续点击次数向上飘逸上限 // 从字符串中读取黑名单 void getBlackList(string str){ if(str.substr(0, 10)!="BLACK_LIST") return; str = str.substr(str.find("=")+1); stringstream ss(str); string item; while(ss>>quoted(item)){ if(item==",") continue; blackList.push_back(item); } } // 保存黑名单时间 void saveData(){ // 保存黑名单时间到save.txt FILE *fp = fopen("save.txt", "w"); if(fp!=NULL){ time_t timeNow = time(0); tm *curTime = localtime(&timeNow); if(curTime->tm_hour<4){ timeNow -= 86400; curTime = localtime(&timeNow); } fprintf(fp, "%d %d %d %d", blackListTimeCount,curTime->tm_year,curTime->tm_mon,curTime->tm_mday); fclose(fp); } } // 加载黑名单时间 void loadData(){ FILE *fp = fopen("save.txt", "r"); if(fp!=NULL){ int curYear,curMonth,curDay; fscanf(fp, "%d%d%d%d", &blackListTimeCount,&curYear,&curMonth,&curDay); time_t timeNow = time(0); tm *curTime = localtime(&timeNow); if(curTime->tm_hour<4){ timeNow -= 86400; curTime = localtime(&timeNow); } if(curTime->tm_year!=curYear||curTime->tm_mon!=curMonth||curTime->tm_mday!=curDay){ blackListTimeCount = 0; } fclose(fp); } } // 获取当前时间字符串 string getTimeStr(){ time_t now = time(0); tm *ltm = localtime(&now); char timeStr[1024]; strftime(timeStr, sizeof(timeStr), "[%Y-%m-%d %H:%M:%S]", ltm); return (string)timeStr; } // 初始化程序 void initMonitor(){ ShowWindow(GetConsoleWindow(), SW_HIDE); // 隐藏控制台窗口 system("chcp 936 >>nul"); // 设置编码为GBK FreeConsole(); // 隐藏控制台窗口 srand((unsigned)time(0)); // 初始化随机数种子 logFile.open("selfMonitor.log", ios::out); // 打开日志文件 ifstream ifs(".env"); if(ifs.is_open()){ string line; while(getline(ifs, line)) getBlackList(line); ifs.close(); } loadData(); logFile<tm_hour==4&<m->tm_min<5) return true; return false; } // 获取当前窗口标题 string getForegroundTitle(HWND hwnd){ char title[1024]; if (hwnd == NULL) return ""; if(GetWindowTextA(hwnd, title, 1024) == 0){ logFile<0;i--){ if(rand()&1) isContinue = MessageBoxA(hwnd, "先思考一下,你现在真的有用电脑的必要吗?\n你现在应该做什么?\n想好了按确认", "请思考请思考", MB_YESNO) == IDYES; else isContinue = MessageBoxA(hwnd, "先思考一下,你现在真的有用电脑的必要吗?\n你现在应该做什么?\n想好了按取消", "请思考请思考", MB_YESNO) == IDNO; if(!isContinue){ MessageBoxA(hwnd, "看来你并没有真正下定决心呢……", "叹气……", MB_OK); return false; } } return true; } map warningSet; // 启动超出时间限制禁言程序 void operateTimeExceeded(HWND hwnd){ logFile<=MAX_BLACKLIST_TIME_COUNT) operateTimeExceeded(hwnd); else if (blackListTimeCount%600==0) operateTimeWarning(hwnd,"你摸鱼已经十分钟了,冰澄命令你停下!"); else if (blackListTimeCount%300==0) operateTimeWarning(hwnd,"你在摸鱼吗,又摸了五分钟了,冰澄提醒你正确休息"); } Sleep(1000); // 休眠1秒钟 static int clockCount = 0; // 存档计时器 if((++clockCount)%60==0) // 每分钟存档一次 saveData(); } return 0; }