mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2025-12-14 08:06:23 +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:
Binary file not shown.
@@ -217,6 +217,19 @@ c.execute('''create table if not exists user_present(user_id int,
|
||||
present_id text,
|
||||
primary key(user_id, present_id)
|
||||
);''')
|
||||
c.execute('''create table if not exists songfile(song_id text,
|
||||
file_type int,
|
||||
md5 text,
|
||||
primary key(song_id, file_type)
|
||||
);''')
|
||||
c.execute('''create table if not exists redeem(code text primary key,
|
||||
items text,
|
||||
type int
|
||||
);''')
|
||||
c.execute('''create table if not exists user_redeem(user_id int,
|
||||
code text,
|
||||
primary key(user_id, code)
|
||||
);''')
|
||||
|
||||
|
||||
char = ['Hikari', 'Tairitsu', 'Kou', 'Sapphire', 'Lethe', '', 'Tairitsu(Axium)', 'Tairitsu(Grievous Lady)', 'Stella', 'Hikari & Fisica', 'Ilith', 'Eto', 'Luna', 'Shirabe', 'Hikari(Zero)', 'Hikari(Fracture)', 'Hikari(Summer)', 'Tairitsu(Summer)', 'Tairitsu & Trin',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from flask import Flask, request, jsonify, make_response, send_from_directory
|
||||
from logging.config import dictConfig
|
||||
import configparser
|
||||
import base64
|
||||
import server.auth
|
||||
@@ -462,9 +463,34 @@ def cloud_post():
|
||||
return error_return(108)
|
||||
|
||||
|
||||
@app.route('/coffee/12/purchase/me/redeem', methods=['POST']) # 兑换码,依然没有用
|
||||
@app.route('/coffee/12/purchase/me/redeem', methods=['POST']) # 兑换码
|
||||
def redeem():
|
||||
return error_return(504)
|
||||
headers = request.headers
|
||||
token = headers['Authorization']
|
||||
token = token[7:]
|
||||
code = request.form['code']
|
||||
try:
|
||||
user_id = server.auth.token_get_id(token)
|
||||
if user_id is not None:
|
||||
fragment, error_code = server.arcpurchase.claim_user_redeem(
|
||||
user_id, code)
|
||||
if not error_code:
|
||||
if fragment > 0:
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"value": {"coupon": "fragment"+str(fragment)}
|
||||
})
|
||||
else:
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"value": {"coupon": ""}
|
||||
})
|
||||
else:
|
||||
return error_return(error_code)
|
||||
else:
|
||||
return error_return(108)
|
||||
except:
|
||||
return error_return(108)
|
||||
|
||||
|
||||
# 礼物确认
|
||||
@@ -667,6 +693,26 @@ def main():
|
||||
app.register_blueprint(web.login.bp)
|
||||
app.register_blueprint(web.index.bp)
|
||||
|
||||
dictConfig({
|
||||
'version': 1,
|
||||
'formatters': {'default': {
|
||||
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
|
||||
}},
|
||||
'root': {
|
||||
'level': 'INFO'
|
||||
}
|
||||
})
|
||||
|
||||
app.logger.info("Start to initialize data in 'songfile' table...")
|
||||
try:
|
||||
error = server.arcdownload.initialize_songfile()
|
||||
except:
|
||||
error = 'Something wrong.'
|
||||
if error:
|
||||
app.logger.warning(error)
|
||||
else:
|
||||
app.logger.info('Complete!')
|
||||
|
||||
app.run(HOST, PORT)
|
||||
|
||||
|
||||
|
||||
@@ -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''', {
|
||||
|
||||
39
latest version/templates/web/allredeem.html
Normal file
39
latest version/templates/web/allredeem.html
Normal file
@@ -0,0 +1,39 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block header %}
|
||||
<h1>{% block title %}All redeem codes{% endblock %}</h1>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if posts %}<br />
|
||||
{% for redeem in posts %}
|
||||
|
||||
<div class="char-redeem">
|
||||
<span>Code: </span>
|
||||
<span class="name">{{redeem['code']}}</span>
|
||||
<br />
|
||||
|
||||
<span>Type: </span>
|
||||
<span class="char-num">
|
||||
{% if redeem['type'] == 0 %}
|
||||
仅可使用一次 It can only be used once.
|
||||
{% elif redeem['type'] == 1 %}
|
||||
每个用户仅可以使用一次 Each user can only use it once.
|
||||
{% endif %}
|
||||
</span>
|
||||
<br />
|
||||
|
||||
<span>Items: </span>
|
||||
<span class="char-num" style='white-space:pre'>{{redeem['items']}}</span>
|
||||
<br />
|
||||
<div><a href="/web/redeem/{{redeem['code']}}">使用者 Players who have used it.</a></div>
|
||||
|
||||
</div>
|
||||
{% if not loop.last %}
|
||||
<br />
|
||||
<hr />
|
||||
<br />
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
50
latest version/templates/web/changeredeem.html
Normal file
50
latest version/templates/web/changeredeem.html
Normal file
@@ -0,0 +1,50 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block header %}
|
||||
<h1>{% block title %}Change the redeem codes{% endblock %}</h1>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form action="/web/changeredeem/addredeem" method="post">
|
||||
<div class="title">Add the redeem</div>
|
||||
<div>指定生成 Specify generation</div>
|
||||
<label for="code">The redeem code</label>
|
||||
<input name="code" id="code">
|
||||
<div>Or</div>
|
||||
<div>随机批量生成 Batch generation at random</div>
|
||||
<label for="amount">Amount</label>
|
||||
<input name="amount" id="amount">
|
||||
<br />
|
||||
<div>Type:
|
||||
<br />
|
||||
<br />
|
||||
<label><input type="radio" name="type" value="0" checked>仅可使用一次 It can only be used once.</label>
|
||||
<br />
|
||||
<label><input type="radio" name="type" value="1">每个用户仅可以使用一次 Each user can only use it once.</label>
|
||||
</div>
|
||||
|
||||
|
||||
<br />
|
||||
<div>Items:</div>
|
||||
<label for="fragment">Fragments</label>
|
||||
<input name="fragment" id="fragment">
|
||||
<label for="ticket">Memories</label>
|
||||
<input name="ticket" id="ticket">
|
||||
|
||||
<div class="content">两种奖励可以都有,不需要请留空。</div>
|
||||
<div class="content">You can have both kinds of items. Please leave it blank if you don't need it.</div>
|
||||
<div class="content">兑换码长度为10~20。</div>
|
||||
<div class="content">The length of redeem code is 10 ~ 20.</div>
|
||||
<div class="content">随机生成数量不得超过1000。</div>
|
||||
<div class="content">The amount of batch generation should not be more than 1000.</div>
|
||||
<input type="submit" value="Add">
|
||||
</form>
|
||||
<br />
|
||||
<hr />
|
||||
<form action="/web/changeredeem/deleteredeem" method="post">
|
||||
<div class="title">Delete the redeem</div>
|
||||
<label for="code">The redeem code</label>
|
||||
<input name="code" id="code" required>
|
||||
|
||||
<input type="submit" value="Delete">
|
||||
</form>
|
||||
{% endblock %}
|
||||
24
latest version/templates/web/changeuserpwd.html
Normal file
24
latest version/templates/web/changeuserpwd.html
Normal file
@@ -0,0 +1,24 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block header %}
|
||||
<h1>{% block title %}Change user password{% endblock %}</h1>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form action="/web/changeuserpwd" method="post">
|
||||
<div class="title">Edit the user's password</div>
|
||||
<label for="name">Arcaea Username</label>
|
||||
<input name="name" id="name">
|
||||
or<br />
|
||||
<label for="user_code">Arcaea User Code</label>
|
||||
<input name="user_code" id="user_code">
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<label for="pwd">Password</label>
|
||||
<input type="password" name="pwd" id="pwd" required>
|
||||
<label for="pwd2">Enter again</label>
|
||||
<input type="password" name="pwd2" id="pwd2" required>
|
||||
|
||||
<input type="submit" value="Edit">
|
||||
</form>
|
||||
{% endblock %}
|
||||
@@ -17,10 +17,12 @@
|
||||
<a href="{{ url_for('index.all_character') }}">角色信息查询 All characters</a></br></br>
|
||||
<a href="{{ url_for('index.all_item') }}">购买信息查询 All items</a></br></br>
|
||||
<a href="{{ url_for('index.all_present') }}">奖励信息查询 All presents</a></br></br>
|
||||
<a href="{{ url_for('index.all_redeem') }}">兑换码信息查询 All redeem codes</a></br></br>
|
||||
<a href="{{ url_for('index.single_chart_top') }}">单个铺面排行榜查询 Single song chart tops</a>
|
||||
<hr>
|
||||
<h1>系统方面 System</h1>
|
||||
<a href="{{ url_for('index.update_database') }}">数据库更新 Update databases</a></br></br>
|
||||
<a href="{{ url_for('index.edit_userpwd') }}">用户密码修改 Change user password</a></br></br>
|
||||
<a href="{{ url_for('index.update_user_save') }}">用户存档更新 Update user saves</a></br></br>
|
||||
<a href="{{ url_for('index.change_song') }}">歌曲修改 Change the songs</a></br></br>
|
||||
<a href="{{ url_for('index.change_character') }}">角色修改 Change the characters</a></br></br>
|
||||
@@ -28,7 +30,9 @@
|
||||
<a href="{{ url_for('index.change_user') }}">用户信息修改 Change user information</a></br></br>
|
||||
<a href="{{ url_for('index.change_user_purchase') }}">用户购买信息修改 Change user purchase information</a></br></br>
|
||||
<a href="{{ url_for('index.change_present') }}">奖励修改 Change the presents</a></br></br>
|
||||
<a href="{{ url_for('index.deliver_present') }}">奖励分发 Deliver the presents</a>
|
||||
<a href="{{ url_for('index.deliver_present') }}">奖励分发 Deliver the presents</a></br></br>
|
||||
<a href="{{ url_for('index.change_redeem') }}">兑换码修改 Change the redeem codes</a>
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
24
latest version/templates/web/redeem.html
Normal file
24
latest version/templates/web/redeem.html
Normal file
@@ -0,0 +1,24 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block header %}
|
||||
<h1>{% block title %}Redeem - {{code}}{% endblock %}</h1>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if posts %}
|
||||
{% for user in posts %}
|
||||
|
||||
<div id="user-info">
|
||||
<div class="name">{{user['name']}}
|
||||
<span class="rank">UID: {{user['user_id']}}</span>
|
||||
<span class="rank">User code: {{user['user_code']}}</span>
|
||||
</div>
|
||||
</div>
|
||||
{% if not loop.last %}
|
||||
<br />
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
<br />
|
||||
<a href="{{ url_for('index.all_redeem') }}">Back</a>
|
||||
{% endblock %}
|
||||
@@ -12,10 +12,10 @@
|
||||
<div class="content">
|
||||
这里可以将旧版本的数据库同步到新版本的数据库,并刷新用户拥有的角色列表。<br />
|
||||
可上传文件: arcaea_database.db和arcsong.db<br />
|
||||
新数据库不存在的数据会被添加,存在的数据将不会被改变。<br /><br />
|
||||
新数据库不存在的数据会被添加,存在的重复数据也会被改变。<br /><br />
|
||||
Here you can synchronize the old version of the database to the new version of the database and refresh the list of
|
||||
characters owned by players.<br />
|
||||
Uploadable files: arcaea_database.db & arcsong.db<br />
|
||||
Data that does not exist in the new database will be added and the existing data will not be changed.
|
||||
Data that does not exist in the new database will be added and the existing duplicate data will also be changed.
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -986,3 +986,199 @@ def deliver_present():
|
||||
flash(error)
|
||||
|
||||
return render_template('web/deliverpresent.html')
|
||||
|
||||
|
||||
@bp.route('/allredeem', methods=['GET'])
|
||||
@login_required
|
||||
def all_redeem():
|
||||
# 所有兑换码数据
|
||||
|
||||
conn = sqlite3.connect('./database/arcaea_database.db')
|
||||
c = conn.cursor()
|
||||
c.execute('''select * from redeem''')
|
||||
x = c.fetchall()
|
||||
error = None
|
||||
if x:
|
||||
posts = []
|
||||
for i in x:
|
||||
items = json.loads(i[1])
|
||||
items_string = ''
|
||||
for j in items:
|
||||
items_string = items_string + '\n' + \
|
||||
str(j['id']) + ': ' + str(j['amount'])
|
||||
|
||||
posts.append({'code': i[0],
|
||||
'items': items_string,
|
||||
'type': i[2]
|
||||
})
|
||||
else:
|
||||
error = '没有兑换码数据 No redeem code data.'
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
if error:
|
||||
flash(error)
|
||||
return render_template('web/allredeem.html')
|
||||
else:
|
||||
return render_template('web/allredeem.html', posts=posts)
|
||||
|
||||
|
||||
@bp.route('/changeredeem', methods=['GET'])
|
||||
@login_required
|
||||
def change_redeem():
|
||||
# 修改兑换码数据
|
||||
return render_template('web/changeredeem.html')
|
||||
|
||||
|
||||
@bp.route('/changeredeem/addredeem', methods=['POST'])
|
||||
@login_required
|
||||
def add_redeem():
|
||||
# 添加兑换码数据
|
||||
print(request.form)
|
||||
code = request.form['code']
|
||||
amount = request.form['amount']
|
||||
redeem_type = request.form['type']
|
||||
fragment = request.form['fragment']
|
||||
ticket = request.form['ticket']
|
||||
try:
|
||||
if amount:
|
||||
amount = int(amount)
|
||||
if ticket:
|
||||
ticket = int(ticket)
|
||||
if fragment:
|
||||
fragment = int(fragment)
|
||||
except:
|
||||
flash('数据错误 Wrong data.')
|
||||
return redirect(url_for('index.change_redeem'))
|
||||
|
||||
items = []
|
||||
if ticket:
|
||||
items.append({'type': 'memory', 'id': 'memory', 'amount': ticket})
|
||||
if fragment:
|
||||
items.append(
|
||||
{'type': 'fragment', 'id': 'fragment', 'amount': fragment})
|
||||
if items == []:
|
||||
flash('奖励为空 No items.')
|
||||
return redirect(url_for('index.change_redeem'))
|
||||
|
||||
if code and not amount:
|
||||
if len(code) > 20 or len(code) < 10:
|
||||
flash('兑换码长度不合适 Inappropriate length of redeem code.')
|
||||
return redirect(url_for('index.change_redeem'))
|
||||
|
||||
message = web.system.add_one_redeem(
|
||||
code, redeem_type, json.dumps(items))
|
||||
elif amount and not code:
|
||||
if amount <= 0 or amount > 1000:
|
||||
flash('数量错误 Wrong amount.')
|
||||
return redirect(url_for('index.change_redeem'))
|
||||
|
||||
message = web.system.add_some_random_redeem(
|
||||
amount, redeem_type, json.dumps(items))
|
||||
elif amount and code:
|
||||
flash('只能使用一种添加方式 Only one add method can be used.')
|
||||
return redirect(url_for('index.change_redeem'))
|
||||
else:
|
||||
flash('空输入 Null input.')
|
||||
return redirect(url_for('index.change_redeem'))
|
||||
|
||||
if message:
|
||||
flash(message)
|
||||
|
||||
return redirect(url_for('index.change_redeem'))
|
||||
|
||||
|
||||
@bp.route('/changeredeem/deleteredeem', methods=['POST'])
|
||||
@login_required
|
||||
def delete_redeem():
|
||||
# 删除兑换码数据
|
||||
code = request.form['code']
|
||||
message = web.system.delete_one_redeem(code)
|
||||
|
||||
if message:
|
||||
flash(message)
|
||||
|
||||
return redirect(url_for('index.change_redeem'))
|
||||
|
||||
|
||||
@bp.route('/redeem/<code>', methods=['GET'])
|
||||
@login_required
|
||||
def one_redeem(code):
|
||||
# 某个兑换码的用户使用情况数据
|
||||
|
||||
conn = sqlite3.connect('./database/arcaea_database.db')
|
||||
c = conn.cursor()
|
||||
c.execute(
|
||||
'''select user_id, name, user_code from user where user_id in (select user_id from user_redeem where code=:a)''', {'a': code})
|
||||
x = c.fetchall()
|
||||
error = None
|
||||
if x:
|
||||
posts = []
|
||||
for i in x:
|
||||
posts.append({'user_id': i[0],
|
||||
'name': i[1],
|
||||
'user_code': i[2]
|
||||
})
|
||||
else:
|
||||
error = '没有数据 No data.'
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
if error:
|
||||
flash(error)
|
||||
return render_template('web/redeem.html', code=code)
|
||||
else:
|
||||
return render_template('web/redeem.html', posts=posts, code=code)
|
||||
|
||||
|
||||
@bp.route('/changeuserpwd', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def edit_userpwd():
|
||||
# 修改用户密码
|
||||
if request.method == 'GET':
|
||||
return render_template('web/changeuserpwd.html')
|
||||
|
||||
error = None
|
||||
|
||||
name = request.form['name']
|
||||
user_code = request.form['user_code']
|
||||
pwd = request.form['pwd']
|
||||
pwd2 = request.form['pwd2']
|
||||
if pwd != pwd2:
|
||||
flash('两次输入的密码不一致 Entered passwords differ!')
|
||||
return render_template('web/changeuserpwd.html')
|
||||
else:
|
||||
if len(pwd) < 8 or len(pwd) > 20:
|
||||
flash('密码太长或太短 Password is too long or too short!')
|
||||
return render_template('web/changeuserpwd.html')
|
||||
|
||||
conn = sqlite3.connect('./database/arcaea_database.db')
|
||||
c = conn.cursor()
|
||||
|
||||
if name or user_code:
|
||||
|
||||
if user_code:
|
||||
c.execute('''select user_id from user where user_code=:a''', {
|
||||
'a': user_code})
|
||||
else:
|
||||
c.execute(
|
||||
'''select user_id from user where name=:a''', {'a': name})
|
||||
|
||||
user_id = c.fetchone()
|
||||
if user_id:
|
||||
user_id = user_id[0]
|
||||
web.system.change_userpwd(c, user_id, pwd)
|
||||
flash('用户密码修改成功 Successfully edit the user information.')
|
||||
|
||||
else:
|
||||
error = '玩家不存在 The player does not exist.'
|
||||
|
||||
else:
|
||||
error = '输入为空 Null Input.'
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
if error:
|
||||
flash(error)
|
||||
|
||||
return redirect(url_for('index.edit_userpwd'))
|
||||
|
||||
@@ -3,6 +3,8 @@ import sqlite3
|
||||
import time
|
||||
import json
|
||||
import server.arcscore
|
||||
import hashlib
|
||||
from random import Random
|
||||
|
||||
|
||||
def int2b(x):
|
||||
@@ -13,6 +15,17 @@ def int2b(x):
|
||||
return True
|
||||
|
||||
|
||||
def random_str(randomlength=10):
|
||||
# 随机生成字符串
|
||||
s = ''
|
||||
chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
|
||||
length = len(chars) - 1
|
||||
random = Random()
|
||||
for i in range(randomlength):
|
||||
s += chars[random.randint(0, length)]
|
||||
return s
|
||||
|
||||
|
||||
def get_table_info(c, table_name):
|
||||
# 得到表结构,返回主键列表和字段名列表
|
||||
pk = []
|
||||
@@ -85,8 +98,25 @@ def get_sql_insert_table(table_name, field, value):
|
||||
return sql, sql_dict
|
||||
|
||||
|
||||
def get_sql_delete_table(table_name, where_field=[], where_value=[]):
|
||||
# sql语句拼接,delete from ... where ...
|
||||
sql = 'delete from ' + table_name
|
||||
sql_dict = {}
|
||||
|
||||
if where_field and where_value:
|
||||
sql += ' where '
|
||||
sql += where_field[0] + '=:' + where_field[0]
|
||||
sql_dict[where_field[0]] = where_value[0]
|
||||
if len(where_field) >= 1:
|
||||
for i in range(1, len(where_field)):
|
||||
sql_dict[where_field[i]] = where_value[i]
|
||||
sql += ' and ' + where_field[i] + '=:' + where_field[i]
|
||||
|
||||
return sql, sql_dict
|
||||
|
||||
|
||||
def update_one_table(c1, c2, table_name):
|
||||
# 从c1向c2更新数据表,c2中存在的信息不变
|
||||
# 从c1向c2更新数据表,c1中存在的信息不变
|
||||
c1.execute(
|
||||
'''select * from sqlite_master where type = 'table' and name = :a''', {'a': table_name})
|
||||
c2.execute(
|
||||
@@ -117,11 +147,15 @@ def update_one_table(c1, c2, table_name):
|
||||
sql = 'select exists(' + sql + ')'
|
||||
c2.execute(sql, sql_dict)
|
||||
|
||||
if c2.fetchone() == (0,):
|
||||
sql, sql_dict = get_sql_insert_table(
|
||||
table_name, field, list(y[i]))
|
||||
if c2.fetchone() == (1,): # 如果c2里存在,先删除
|
||||
sql, sql_dict = get_sql_delete_table(
|
||||
table_name, db1_pk, list(x[i]))
|
||||
c2.execute(sql, sql_dict)
|
||||
|
||||
sql, sql_dict = get_sql_insert_table(
|
||||
table_name, field, list(y[i]))
|
||||
c2.execute(sql, sql_dict)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@@ -142,7 +176,7 @@ def update_user_char(c):
|
||||
|
||||
def update_database():
|
||||
# 将old数据库不存在数据加入到新数据库上,并删除old数据库
|
||||
# 对于arcaea_datebase.db,更新best_score,friend,recent30,user,user_world, user_item, user_save, login, present, user_present并用character数据更新user_char
|
||||
# 对于arcaea_datebase.db,更新一些表,并用character数据更新user_char
|
||||
# 对于arcsong.db,更新songs
|
||||
if os.path.isfile("database/old_arcaea_database.db") and os.path.isfile("database/arcaea_database.db"):
|
||||
conn1 = sqlite3.connect('./database/old_arcaea_database.db')
|
||||
@@ -155,11 +189,14 @@ def update_database():
|
||||
update_one_table(c1, c2, 'best_score')
|
||||
update_one_table(c1, c2, 'recent30')
|
||||
update_one_table(c1, c2, 'user_world')
|
||||
update_one_table(c1, c2, 'item')
|
||||
update_one_table(c1, c2, 'user_item')
|
||||
update_one_table(c1, c2, 'user_save')
|
||||
update_one_table(c1, c2, 'login')
|
||||
update_one_table(c1, c2, 'present')
|
||||
update_one_table(c1, c2, 'user_present')
|
||||
update_one_table(c1, c2, 'redeem')
|
||||
update_one_table(c1, c2, 'user_redeem')
|
||||
|
||||
update_user_char(c2)
|
||||
|
||||
@@ -378,3 +415,73 @@ def deliver_all_user_present(c, present_id):
|
||||
{'a': i[0], 'b': present_id})
|
||||
|
||||
return
|
||||
|
||||
|
||||
def add_one_redeem(code, redeem_type, items):
|
||||
# 添加一个兑换码
|
||||
|
||||
message = None
|
||||
conn = sqlite3.connect('./database/arcaea_database.db')
|
||||
c = conn.cursor()
|
||||
c.execute(
|
||||
'''select exists(select * from redeem where code=:a)''', {'a': code})
|
||||
if c.fetchone() == (0,):
|
||||
c.execute('''insert into redeem values(:a,:b,:c)''', {
|
||||
'a': code, 'b': items, 'c': redeem_type})
|
||||
message = '添加成功 Successfully add it.'
|
||||
else:
|
||||
message = '兑换码已存在 The redeem code exists.'
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return message
|
||||
|
||||
|
||||
def add_some_random_redeem(amount, redeem_type, items):
|
||||
# 随机生成一堆10位的兑换码
|
||||
|
||||
message = None
|
||||
conn = sqlite3.connect('./database/arcaea_database.db')
|
||||
c = conn.cursor()
|
||||
i = 0
|
||||
while i <= amount:
|
||||
code = random_str()
|
||||
c.execute(
|
||||
'''select exists(select * from redeem where code=:a)''', {'a': code})
|
||||
if c.fetchone() == (0,):
|
||||
c.execute('''insert into redeem values(:a,:b,:c)''',
|
||||
{'a': code, 'b': items, 'c': redeem_type})
|
||||
i += 1
|
||||
|
||||
message = '添加成功 Successfully add it.'
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return message
|
||||
|
||||
|
||||
def delete_one_redeem(code):
|
||||
# 删除一个兑换码
|
||||
|
||||
message = None
|
||||
conn = sqlite3.connect('./database/arcaea_database.db')
|
||||
c = conn.cursor()
|
||||
c.execute(
|
||||
'''select exists(select * from redeem where code=:a)''', {'a': code})
|
||||
if c.fetchone() == (1,):
|
||||
c.execute('''delete from redeem where code = :a''', {'a': code})
|
||||
c.execute('''delete from user_redeem where code =:a''', {'a': code})
|
||||
message = '删除成功 Successfully delete it.'
|
||||
else:
|
||||
message = '兑换码不存在 The redeem code does not exist.'
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return message
|
||||
|
||||
|
||||
def change_userpwd(c, user_id, password):
|
||||
# 修改用户密码
|
||||
hash_pwd = hashlib.sha256(password.encode("utf8")).hexdigest()
|
||||
c.execute('''update user set password =:a where user_id=:b''',
|
||||
{'a': hash_pwd, 'b': user_id})
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user