Skip to content

Commit

Permalink
优化代码,限制通关次数小于10,防止对服务器造成压力,大佬看代码可忽略,增加友好提示,连接超时6s直接结束程序。
Browse files Browse the repository at this point in the history
  • Loading branch information
Lcry committed Sep 16, 2022
1 parent 6345ab5 commit 3f22526
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"header_user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.33",
# 设定的完成耗时,单位s,默认-1随机表示随机生成1s~1h之内的随机数,设置为正数则为固定
"cost_time": -1,
# 需要通关的次数,默认1
# 需要通关的次数,最大支持10,默认1
"cycle_count": 1
}

Expand Down
16 changes: 14 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@time : 2022/9/15 12:00
"""
import random
import sys

import requests

Expand Down Expand Up @@ -33,7 +34,7 @@


def finish_game(state, rank_time):
res = requests.get(finish_api % (state, rank_time), headers=request_header)
res = requests.get(finish_api % (state, rank_time), headers=request_header, timeout=6)
# err_code为0则成功
if res.json()["err_code"] == 0:
print("状态成功")
Expand All @@ -44,11 +45,22 @@ def finish_game(state, rank_time):

if __name__ == '__main__':
print("【羊了个羊一键闯关开始启动】")
# 前置判断,程序员何必为难程序员呢,针对恶意刷次数对服务器造成压力的进行拦截
if cycle_count > 10:
print("程序员何必为难程序员,请勿恶意刷次数对服务器造成压力,请设定cycle_count的值小于10以下的值,本次程序运行结束")
print("【羊了个羊一键闯关开始结束】")
sys.exit(0)

for i in range(cycle_count):
print(f"...第{i + 1}次开始完成闯关...")
if cost_time == -1:
cost_time = random.randint(1, 3600)
print(f"生成随机完成耗时:{cost_time} s")
finish_game(1, cost_time)
try:
finish_game(1, cost_time)
except Exception as e:
print(f"游戏服务器响应超时或崩溃中未及时响应,缓缓吧,等待服务器恢复后再试!本次程序运行结束,错误日志: {e}")
print("【羊了个羊一键闯关开始结束】")
sys.exit(0)
print(f"...第{i + 1}次完成闯关...")
print("【羊了个羊一键闯关开始结束】")

0 comments on commit 3f22526

Please sign in to comment.