mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2026-02-09 09:17:26 +08:00
Update a midway version (waiting for offical update)
Add some things and fix some bugs. It will not have a description.
This commit is contained in:
@@ -38,12 +38,27 @@ def get_one_song(c, user_id, song_id, file_dir='./database/songs'):
|
||||
token = token[:8]
|
||||
|
||||
if i == 'base.ogg':
|
||||
re['audio'] = {"checksum": get_file_md5(os.path.join(file_dir, song_id, 'base.ogg')),
|
||||
c.execute(
|
||||
'''select md5 from songfile where song_id=:a and file_type=-1''', {'a': song_id})
|
||||
x = c.fetchone()
|
||||
if x:
|
||||
checksum = x[0]
|
||||
else:
|
||||
checksum = get_file_md5(os.path.join(
|
||||
file_dir, song_id, 'base.ogg'))
|
||||
re['audio'] = {"checksum": checksum,
|
||||
"url": url_for('download', file_path=song_id+'/base.ogg', t=token, _external=True)}
|
||||
else:
|
||||
if 'chart' not in re:
|
||||
re['chart'] = {}
|
||||
re['chart'][i[0]] = {"checksum": get_file_md5(os.path.join(file_dir, song_id, i)),
|
||||
c.execute(
|
||||
'''select md5 from songfile where song_id=:a and file_type=:b''', {'a': song_id, 'b': int(i[0])})
|
||||
x = c.fetchone()
|
||||
if x:
|
||||
checksum = x[0]
|
||||
else:
|
||||
checksum = get_file_md5(os.path.join(file_dir, song_id, i))
|
||||
re['chart'][i[0]] = {"checksum": checksum,
|
||||
"url": url_for('download', file_path=song_id+'/'+i, t=token, _external=True)}
|
||||
|
||||
c.execute('''insert into download_token values(:a,:b,:c,:d,:e)''', {
|
||||
@@ -60,7 +75,7 @@ def get_all_songs(user_id, file_dir='./database/songs'):
|
||||
c = conn.cursor()
|
||||
for i in dir_list:
|
||||
if os.path.isdir(os.path.join(file_dir, i)):
|
||||
re.update(get_one_song(c, user_id, i))
|
||||
re.update(get_one_song(c, user_id, i, file_dir))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
@@ -125,3 +140,45 @@ def is_able_download(user_id):
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return f
|
||||
|
||||
|
||||
def initialize_one_songfile(c, song_id, file_dir='./database/songs'):
|
||||
# 计算并添加歌曲md5到表中,无返回
|
||||
dir_list = os.listdir(os.path.join(file_dir, song_id))
|
||||
for i in dir_list:
|
||||
if os.path.isfile(os.path.join(file_dir, song_id, i)) and i in ['0.aff', '1.aff', '2.aff', '3.aff', 'base.ogg']:
|
||||
if i == 'base.ogg':
|
||||
c.execute('''insert into songfile values(:a,-1,:c)''', {
|
||||
'a': song_id, 'c': get_file_md5(os.path.join(file_dir, song_id, 'base.ogg'))})
|
||||
else:
|
||||
c.execute('''insert into songfile values(:a,:b,:c)''', {
|
||||
'a': song_id, 'b': int(i[0]), 'c': get_file_md5(os.path.join(file_dir, song_id, i))})
|
||||
|
||||
return
|
||||
|
||||
|
||||
def initialize_songfile(file_dir='./database/songs'):
|
||||
# 初始化歌曲数据的md5表,返回错误信息
|
||||
error = None
|
||||
try:
|
||||
dir_list = os.listdir(file_dir)
|
||||
except:
|
||||
error = 'OS error!'
|
||||
return error
|
||||
try:
|
||||
conn = sqlite3.connect('./database/arcaea_database.db')
|
||||
c = conn.cursor()
|
||||
except:
|
||||
error = 'Database error!'
|
||||
return error
|
||||
try:
|
||||
c.execute('''delete from songfile''')
|
||||
for i in dir_list:
|
||||
if os.path.isdir(os.path.join(file_dir, i)):
|
||||
initialize_one_songfile(c, i, file_dir)
|
||||
except:
|
||||
error = 'Initialization error!'
|
||||
finally:
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return error
|
||||
|
||||
@@ -178,3 +178,50 @@ def claim_user_present(user_id, present_id):
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return flag
|
||||
|
||||
|
||||
def claim_user_redeem(user_id, code):
|
||||
# 处理兑换码,返回碎片数量和错误码
|
||||
fragment = 0
|
||||
conn = sqlite3.connect('./database/arcaea_database.db')
|
||||
c = conn.cursor()
|
||||
c.execute('''select * from redeem where code=:a''', {'a': code})
|
||||
x = c.fetchone()
|
||||
if not x:
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return 0, 504
|
||||
|
||||
if x[2] == 0: # 一次性
|
||||
c.execute(
|
||||
'''select exists(select * from user_redeem where code=:a)''', {'a': code})
|
||||
if c.fetchone() == (1,):
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return 0, 505
|
||||
elif x[2] == 1: # 每个玩家一次
|
||||
c.execute('''select exists(select * from user_redeem where code=:a and user_id=:b)''',
|
||||
{'a': code, 'b': user_id})
|
||||
if c.fetchone() == (1,):
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return 0, 506
|
||||
|
||||
c.execute('''insert into user_redeem values(:b,:a)''',
|
||||
{'a': code, 'b': user_id})
|
||||
|
||||
items = json.loads(x[1])
|
||||
for i in items:
|
||||
if i['type'] == 'fragment':
|
||||
fragment = i['amount']
|
||||
if i['type'] == 'memory':
|
||||
c.execute('''select ticket from user where user_id=:a''', {
|
||||
'a': user_id})
|
||||
ticket = int(c.fetchone()[0])
|
||||
ticket += int(i['amount'])
|
||||
c.execute('''update user set ticket=:b where user_id=:a''', {
|
||||
'a': user_id, 'b': ticket})
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return fragment, None
|
||||
|
||||
@@ -255,8 +255,56 @@ def get_song_state(x):
|
||||
return 0
|
||||
|
||||
|
||||
def get_user_ptt(c, user_id) -> int:
|
||||
# 总ptt计算
|
||||
sumr = 0
|
||||
c.execute('''select rating from best_score where user_id = :a order by rating DESC limit 30''', {
|
||||
'a': user_id})
|
||||
x = c.fetchall()
|
||||
if x != []:
|
||||
n = len(x)
|
||||
for i in x:
|
||||
sumr += float(i[0])
|
||||
c.execute('''select * from recent30 where user_id = :a''', {'a': user_id})
|
||||
x = c.fetchone()
|
||||
if x is not None:
|
||||
r30 = []
|
||||
s30 = []
|
||||
for i in range(1, 61, 2):
|
||||
if x[i] is not None:
|
||||
r30.append(float(x[i]))
|
||||
s30.append(x[i+1])
|
||||
else:
|
||||
r30.append(0)
|
||||
s30.append('')
|
||||
r30, s30 = (list(t) for t in zip(*sorted(zip(r30, s30), reverse=True)))
|
||||
songs = []
|
||||
i = 0
|
||||
while len(songs) < 10 and i <= 29 and s30[i] != '' and s30[i] is not None:
|
||||
if s30[i] not in songs:
|
||||
sumr += r30[i]
|
||||
songs.append(s30[i])
|
||||
i += 1
|
||||
|
||||
return int(sumr/40*100)
|
||||
|
||||
|
||||
def update_recent30(c, user_id, song_id, rating, is_protected):
|
||||
# 刷新r30,这里的判断方法存疑
|
||||
def insert_r30table(c, user_id, a, b):
|
||||
# 更新r30表
|
||||
c.execute('''delete from recent30 where user_id = :a''',
|
||||
{'a': user_id})
|
||||
sql = 'insert into recent30 values(' + str(user_id)
|
||||
for i in range(0, 30):
|
||||
if a[i] is not None and b[i] is not None:
|
||||
sql = sql + ',' + str(a[i]) + ',"' + b[i] + '"'
|
||||
else:
|
||||
sql = sql + ',0,""'
|
||||
|
||||
sql = sql + ')'
|
||||
c.execute(sql)
|
||||
|
||||
c.execute('''select * from recent30 where user_id = :a''', {'a': user_id})
|
||||
x = c.fetchone()
|
||||
songs = []
|
||||
@@ -293,12 +341,9 @@ def update_recent30(c, user_id, song_id, rating, is_protected):
|
||||
b.append(x[i+1])
|
||||
|
||||
if is_protected:
|
||||
ptt_pre = get_user_ptt(c, user_id)
|
||||
a_pre = [x for x in a]
|
||||
b_pre = [x for x in b]
|
||||
s_pre = 0
|
||||
for x in a_pre:
|
||||
if x is not None:
|
||||
s_pre += x
|
||||
|
||||
for i in range(r30_id, 0, -1):
|
||||
a[i] = a[i-1]
|
||||
@@ -306,62 +351,23 @@ def update_recent30(c, user_id, song_id, rating, is_protected):
|
||||
a[0] = rating
|
||||
b[0] = song_id
|
||||
|
||||
insert_r30table(c, user_id, a, b)
|
||||
|
||||
if is_protected:
|
||||
s = 0
|
||||
for x in a:
|
||||
if x is not None:
|
||||
s += x
|
||||
if s < s_pre:
|
||||
a = [x for x in a_pre]
|
||||
b = [x for x in b_pre]
|
||||
ptt = get_user_ptt(c, user_id)
|
||||
if ptt < ptt_pre:
|
||||
# 触发保护
|
||||
if song_id in b_pre:
|
||||
for i in range(29, -1, -1):
|
||||
if song_id == b_pre[i] and rating > a_pre[i]:
|
||||
# 发现重复歌曲,更新到最高rating
|
||||
a_pre[i] = rating
|
||||
break
|
||||
|
||||
c.execute('''delete from recent30 where user_id = :a''', {'a': user_id})
|
||||
sql = 'insert into recent30 values(' + str(user_id)
|
||||
for i in range(0, 30):
|
||||
if a[i] is not None and b[i] is not None:
|
||||
sql = sql + ',' + str(a[i]) + ',"' + b[i] + '"'
|
||||
else:
|
||||
sql = sql + ',0,""'
|
||||
|
||||
sql = sql + ')'
|
||||
c.execute(sql)
|
||||
insert_r30table(c, user_id, a_pre, b_pre)
|
||||
return None
|
||||
|
||||
|
||||
def get_user_ptt(c, user_id) -> int:
|
||||
# 总ptt计算
|
||||
sumr = 0
|
||||
c.execute('''select rating from best_score where user_id = :a order by rating DESC limit 30''', {
|
||||
'a': user_id})
|
||||
x = c.fetchall()
|
||||
if x != []:
|
||||
n = len(x)
|
||||
for i in x:
|
||||
sumr += float(i[0])
|
||||
c.execute('''select * from recent30 where user_id = :a''', {'a': user_id})
|
||||
x = c.fetchone()
|
||||
if x is not None:
|
||||
r30 = []
|
||||
s30 = []
|
||||
for i in range(1, 61, 2):
|
||||
if x[i] is not None:
|
||||
r30.append(float(x[i]))
|
||||
s30.append(x[i+1])
|
||||
else:
|
||||
r30.append(0)
|
||||
s30.append('')
|
||||
r30, s30 = (list(t) for t in zip(*sorted(zip(r30, s30), reverse=True)))
|
||||
songs = []
|
||||
i = 0
|
||||
while len(songs) < 10 and i <= 29 and s30[i] != '' and s30[i] is not None:
|
||||
if s30[i] not in songs:
|
||||
sumr += r30[i]
|
||||
songs.append(s30[i])
|
||||
i += 1
|
||||
|
||||
return int(sumr/40*100)
|
||||
|
||||
|
||||
def arc_score_post(user_id, song_id, difficulty, score, shiny_perfect_count, perfect_count, near_count, miss_count, health, modifier, beyond_gauge, clear_type):
|
||||
# 分数上传,返回变化后的ptt,和世界模式变化
|
||||
|
||||
@@ -372,11 +378,6 @@ def arc_score_post(user_id, song_id, difficulty, score, shiny_perfect_count, per
|
||||
# recent 更新
|
||||
c.execute('''update user set song_id = :b, difficulty = :c, score = :d, shiny_perfect_count = :e, perfect_count = :f, near_count = :g, miss_count = :h, health = :i, modifier = :j, clear_type = :k, rating = :l, time_played = :m where user_id = :a''', {
|
||||
'a': user_id, 'b': song_id, 'c': difficulty, 'd': score, 'e': shiny_perfect_count, 'f': perfect_count, 'g': near_count, 'h': miss_count, 'i': health, 'j': modifier, 'k': clear_type, 'l': rating, 'm': now})
|
||||
# recent30 更新
|
||||
if health == -1 or int(score) >= 9800000:
|
||||
update_recent30(c, user_id, song_id+str(difficulty), rating, True)
|
||||
else:
|
||||
update_recent30(c, user_id, song_id+str(difficulty), rating, False)
|
||||
# 成绩录入
|
||||
c.execute('''select score, best_clear_type from best_score where user_id = :a and song_id = :b and difficulty = :c''', {
|
||||
'a': user_id, 'b': song_id, 'c': difficulty})
|
||||
@@ -392,6 +393,11 @@ def arc_score_post(user_id, song_id, difficulty, score, shiny_perfect_count, per
|
||||
if score >= int(x[0]): # 成绩更新
|
||||
c.execute('''update best_score set score = :d, shiny_perfect_count = :e, perfect_count = :f, near_count = :g, miss_count = :h, health = :i, modifier = :j, clear_type = :k, rating = :l, time_played = :m where user_id = :a and song_id = :b and difficulty = :c ''', {
|
||||
'a': user_id, 'b': song_id, 'c': difficulty, 'd': score, 'e': shiny_perfect_count, 'f': perfect_count, 'g': near_count, 'h': miss_count, 'i': health, 'j': modifier, 'k': clear_type, 'l': rating, 'm': now})
|
||||
# recent30 更新
|
||||
if health == -1 or int(score) >= 9800000:
|
||||
update_recent30(c, user_id, song_id+str(difficulty), rating, True)
|
||||
else:
|
||||
update_recent30(c, user_id, song_id+str(difficulty), rating, False)
|
||||
# 总PTT更新
|
||||
ptt = get_user_ptt(c, user_id)
|
||||
c.execute('''update user set rating_ptt = :a where user_id = :b''', {
|
||||
|
||||
Reference in New Issue
Block a user