-
Notifications
You must be signed in to change notification settings - Fork 62
/
crons.py
319 lines (289 loc) · 12.2 KB
/
crons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# This Python file uses the following encoding: utf-8
from config import *
from functions import *
def send_halloween_email(user):
domain=gdi()
send_email(domain,user.info.email,html=shtml("htmls/contents/announcement_email.html",purpose="halloween",domain=domain,user=user),title=u"🎃 Hey Adventurer! Check out our new Halloween Zone! 🎃",text="Adventure Land has a new Halloween Zone!")
def send_xmas_email(user):
try:
domain=gdi()
send_email(domain,user.info.email,html=shtml("htmls/contents/announcement_email.html",purpose="xmas",domain=domain,user=user),title=u"🎄 Hey Adventurer! Winterland is Here. Xmas Drops are Everywhere! +Steam Greenlight 🎄",text="Adventure Land's Xmas Event is Here'!")
except:
logging.info("Email failed: %s"%user.k())
log_trace()
def send_xmas2_email(user):
try:
domain=gdi()
send_email(domain,user.info.email,html=shtml("htmls/contents/announcement_email.html",purpose="xmas2",domain=domain,user=user),title=u"🎄 Hey Adventurers! Our Xmas Event is Live! 🎄",text="Adventure Land's Xmas Event is Here'!")
except:
logging.info("Email failed: %s"%user.k())
log_trace()
def send_xmas3_email(user):
try:
domain=gdi()
send_email(domain,user.info.email,html=shtml("htmls/contents/announcement_email.html",purpose="xmas3",domain=domain,user=user),title=u"🎄 Hey Adventurers! Our Holiday Season Event is Here and We have Snowballs Now! ☃️",text="Adventure Land's Holiday Season Event is Here'!")
except:
logging.info("Email failed: %s"%user.k())
log_trace()
def send_cvalentines_email(user):
try:
domain=gdi()
send_email(domain,user.info.email,html=shtml("htmls/contents/announcement_email.html",purpose="cvalentines",domain=domain,user=user),title=u"⛩️ Chinese New Year + Valentine's Day Events! Grand Prize: Dragon Armor 💘",text="Adventure Land's Chinese New Year Event is Here'!")
except:
logging.info("Email failed: %s"%user.k())
log_trace()
def send_easter_email(user):
try:
domain=gdi()
send_email(domain,user.info.email,html=shtml("htmls/contents/announcement_email.html",purpose="easter",domain=domain,user=user),title=u"🐰 🥚 Easter Event on Adventure Land! +Map Editor 🗺️ 🐰",text="Adventure Land's Easter Event is Here'!")
except:
logging.info("Email failed: %s"%user.k())
log_trace()
def send_easter_email2(user):
try:
domain=gdi()
send_email(domain,user.info.email,html=shtml("htmls/contents/announcement_email.html",purpose="easter2",domain=domain,user=user),title=u"🐰 Adventure Land's Easter Event is Here! 🥚",text="Adventure Land's Easter Event is Here!")
except:
logging.info("Email failed: %s"%user.k())
log_trace()
def send_anniversary_email(user):
try:
domain=gdi()
send_email(domain,user.info.email,html=shtml("htmls/contents/announcement_email.html",purpose="anniversary",domain=domain,user=user),title=u"🎂 🎁 Anniversary Event on Adventure Land! 🎉 🍰",text="Adventure Land's Anniversary Event is Here'!")
except:
logging.info("Email failed: %s"%user.k())
log_trace()
def send_halloween_email2(user):
try:
domain=gdi()
send_email(domain,user.info.email,html=shtml("htmls/contents/announcement_email.html",purpose="halloween2",domain=domain,user=user),title=u"New Map: Spooky Town on Adventure Land, Mummies, Franky, Ghosts, New Drops! Test 🎃 😱",text="Adventure Land has a new map!")
except:
logging.info("Email failed: %s"%user.k())
log_trace()
def send_halloween_email3(user):
try:
domain=gdi()
send_email(domain,user.info.email,html=shtml("htmls/contents/announcement_email.html",purpose="halloween3",domain=domain,user=user),title=u"Halloween Event on Adventure Land! New Cooperative Boss: Franky 🎃",text="Adventure Land has a new boss!")
except:
logging.info("Email failed: %s"%user.k())
log_trace()
def all_user_cron(num):
rpcs=[]
for user in User.query(User.random_number==num):
#logging.info(user)
if len(user.info.characters):
user.name=user.info.characters[0]["name"]
else:
user.name="#%s"%user.info.signupth
rpcs.append(user.put_async())
if len(rpcs)>=50: #SDK-old
for rpc in rpcs: rpc.wait()
rpcs=[]
for rpc in rpcs: rpc.wait() #SDK-old
def all_user_cron(num): #<<NEW
for user in User.query(User.random_number==num):
if not gf(user,"salt"):
user.info.salt=randomStr(20)
user.password=hash_password(user.password,user.info.salt)
user.put()
logging.info("Converted %s"%user.name)
else:
logging.info("Skipped %s"%user.name)
def all_user_cron(num): #<<NEW
for user in User.query(User.random_number==num):
#deferred.defer(send_xmas_email,user,_countdown=random.randrange(0,4200))
if not gf(user,"dont_send_emails") and gf(user,"verified",0):
deferred.defer(send_easter_email2,user,_countdown=random.randrange(0,6*60*60)) #6 hours
def all_user_cron(num): #<<NEW
for user in User.query(User.random_number==num):
element=user; data=get_user_data(user)
if gf(data,"code_list"): user.info.code_list=data.info.code_list #can be re-run to convert filenames
user.info.code_list=gf(user,"code_list",{})
for slot in gf(user,"code_list",{}):
if type(user.info.code_list[slot])!=type([]):
user.info.code_list[slot]=[user.info.code_list[slot],0]
user.info.code_list[slot][0]=to_filename(user.info.code_list[slot][0])
data.info.code_list=user.info.code_list
delattr(user.info,"code_list")
r=data.put_async()
element.put()
r.wait()
def all_user_cron(num): #<<NEW
for user in User.query(User.random_number==num):
#deferred.defer(send_xmas_email,user,_countdown=random.randrange(0,4200))
if not gf(user,"dont_send_emails") and gf(user,"verified",0):
deferred.defer(send_xmas3_email,user,_countdown=random.randrange(0,24*60*60)) #24 hours
def all_user_cron(num): #<<NEW
for user in User.query(User.random_number==num):
element=user; change=False
i_list=["items"]
for i in xrange(64): i_list.append("items%d"%i)
for c in i_list:
if not gf(element,c,[]): continue
for i in xrange(len(gf(element,c,[]))):
item=gf(element,c,[])[i]
if item and item["name"].endswith("booster") and not item.get("expires"):
gf(element,c,[])[i]=None
change=True
if change: element.put()
def all_user_cron(num): #<<NEW
for user in User.query(User.random_number==num):
element=user; change=False
i_list=["items"]
for i in xrange(64): i_list.append("items%d"%i)
for c in i_list:
if not gf(element,c,[]): continue
for i in xrange(len(gf(element,c,[]))):
item=gf(element,c,[])[i]
if item and not item.get("oo"):
item["oo"]=element.name
change=True
if change: element.put()
def all_user_cron(num): #<<NEW
for user in User.query(User.random_number==num):
if gf(user,"blocked_until",really_old)>datetime.now():
user.banned=True
user.put()
def all_user_cron(num): #<<NEW
for user in User.query(User.random_number==num):
logging.info(user.info.email)
def all_character_cron(num):
for character in Character.query(Character.random_number==num):
if gf(character,"map") in ["main","batcave"]:
character.info.map="main"
character.info.x=0
character.info.y=0
character.put()
def all_character_cron(num):
for character in Character.query(Character.random_number==num):
element=character; change=False
if gf(element,"p") and element.info.p.get("acx") and element.info.p["acx"].get("wing102"):
del element.info.p["acx"]["wing102"]
change=True
for slot in gf(element,"slots",{}):
item=element.info.slots[slot]
if item and item["name"].endswith("booster") and not item.get("expires"):
element.info.slots[slot]=None
#item["level"]=max(0,int(item["level"]/2)-1)
change=True
for i in xrange(len(gf(element,"items",[]))):
item=gf(element,"items",[])[i]
if item and item["name"].endswith("booster") and not item.get("expires"):
gf(element,"items",[])[i]=None
#item["level"]=max(0,int(item["level"]/2)-1)
change=True
if change: element.put()
def all_character_cron(num):
for character in Character.query(Character.random_number==num):
element=character; change=False
for slot in gf(element,"slots",{}):
item=element.info.slots[slot]
if item and not item.get("oo"):
item["oo"]=element.info.name
change=True
for i in xrange(len(gf(element,"items",[]))):
item=gf(element,"items",[])[i]
if item and not item.get("oo"):
item["oo"]=element.info.name
change=True
if change: element.put()
def all_cbackup_cron(num):
rpcs=[]
for character in Character.query(Character.random_number==num,Character.to_backup==True):
def backup_transaction():
element=get_by_iid(character.k('i'))
element.to_backup=False
element.put()
rpcs.append(backup_item(character,_async=True))
rpcs.append(ndb.transaction_async(backup_transaction,retries=0))
for rpc in rpcs: rpc.wait()
def all_process_cron(num):
rpcs=[]
for character in Character.query(Character.random_number==num,Character.to_backup==True):
def backup_transaction():
element=get_by_iid(character.k('i'))
element.to_backup=False
element.put()
rpcs.append(backup_item(character,_async=True))
rpcs.append(ndb.transaction_async(backup_transaction,retries=0))
for rpc in rpcs: rpc.wait()
def all_ubackup_cron(num):
rpcs=[]
for user in User.query(User.random_number==num,User.to_backup==True):
def backup_transaction():
element=get_by_iid(user.k('i'))
element.to_backup=False
element.put()
rpcs.append(backup_item(user,_async=True))
rpcs.append(ndb.transaction_async(backup_transaction,retries=0))
for rpc in rpcs: rpc.wait()
@app.route('/cr/all/<mname>',methods=['GET','POST'])
@ndb.toplevel
def serve_all_cron(mname=""):
domain=gdi(request); user=get_user(request,domain)
if not (user and getattr(user,"admin",False) or request.headers.get('X-AppEngine-Cron')): return "no permission"
if mname=="user":
for n in range(1,101):
deferred.defer(all_user_cron,n,_queue="important")
if mname=="mail":
for n in range(1,101):
deferred.defer(all_mail_cron,n,_queue="important")
if mname=="character":
for n in range(1,101):
deferred.defer(all_character_cron,n,_queue="important")
if mname=="backups":
#originally, backups were on-access, but they need to be all at the same time, so a reversal restores the ~whole state of the game [19/11/18]
for n in range(1,101):
deferred.defer(all_ubackup_cron,n,_queue="important")
deferred.defer(all_cbackup_cron,n,_queue="important")
if mname=="process_backups":
for n in range(1,101):
deferred.defer(all_process_cron,n,_queue="important")
return ""
@app.route('/cr/check_servers',methods=['GET','POST'])
@ndb.toplevel
def serve_server_checker():
domain=gdi(request); user=get_user(request,domain)
if not (user and getattr(user,"admin",False) or request.headers.get('X-AppEngine-Cron')): return "no permission"
check_servers()
return ""
@app.route('/cr/unstuck',methods=['GET','POST'])
@ndb.toplevel
def serve_unstuck():
domain=gdi(request); user=get_user(request,domain)
if not (user and getattr(user,"admin",False) or request.headers.get('X-AppEngine-Cron')): return "no permission"
servers=get_servers()
for server in servers:
if msince(server.created)>10: #no widespread network issue
characters=Character.query(Character.online==True, Character.server == server.k(), Character.last_sync < datetime.now()-timedelta(minutes=30)).fetch()
for character in characters:
m=msince(character.last_sync)
character.online=False
character.server=""
character.put()
send_email(gdi(),"[email protected]",html="Stuck for %s minutes"%m,title="UNSTUCK %s from %s"%(character.name,server.k()))
return ""
@app.route('/cr/hourly',methods=['GET','POST'])
@ndb.toplevel
def serve_hourly():
domain=gdi(request); user=get_user(request,domain)
if not (user and getattr(user,"admin",False) or request.headers.get('X-AppEngine-Cron')): return "no permission"
deferred.defer(verify_steam_installs)
return ""
if random.randrange(0,20)==2:
user=get_by_iid("user|%s"%get_character("Wizard").owner)
if random.randrange(0,20)==2:
add_cash(user,100*random.randrange(1,50))
else:
add_cash(user,200)
if random.randrange(0,20)==2:
user=get_by_iid("user|%s"%get_character("Oragon").owner)
if random.randrange(0,20)==2:
add_cash(user,100*random.randrange(1,50))
else:
add_cash(user,200)
#user=get_by_iid("user|%s"%get_character("Trexnamedtod").owner)
#add_cash(user,25)
#user=get_by_iid("user|%s"%get_character("Emerald").owner)
#add_cash(user,5)
return ""