mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2026-02-10 18:07:28 +08:00
Code refactoring
- Code refactoring - Fix a bug that the other player will not become the host of the room at once, when the player disconnect in link play. > Maybe add many unknown bugs. XD > The song database `arcsong.db` will not used in the future. You can use a tool in `tool` folder to import old data.
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
from flask import (
|
||||
Blueprint, flash, redirect, render_template, request, url_for
|
||||
)
|
||||
from web.login import login_required
|
||||
from werkzeug.utils import secure_filename
|
||||
from server.sql import Connect
|
||||
import web.webscore
|
||||
import web.system
|
||||
import time
|
||||
import server.arcscore
|
||||
import os
|
||||
import json
|
||||
from server.arcdownload import initialize_songfile
|
||||
import time
|
||||
|
||||
import server.arcscore
|
||||
from core.download import initialize_songfile
|
||||
from core.sql import Connect
|
||||
from flask import Blueprint, flash, redirect, render_template, request, url_for
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
import web.system
|
||||
import web.webscore
|
||||
from web.login import login_required
|
||||
|
||||
UPLOAD_FOLDER = 'database'
|
||||
ALLOWED_EXTENSIONS = {'db'}
|
||||
@@ -184,21 +183,21 @@ def all_song():
|
||||
return None
|
||||
|
||||
error = None
|
||||
with Connect('./database/arcsong.db') as c:
|
||||
c.execute('''select * from songs''')
|
||||
with Connect() as c:
|
||||
c.execute('''select * from chart''')
|
||||
x = c.fetchall()
|
||||
if x:
|
||||
posts = []
|
||||
for i in x:
|
||||
posts.append({'song_id': i[0],
|
||||
'name_en': i[1],
|
||||
'rating_pst': defnum(i[13]),
|
||||
'rating_prs': defnum(i[14]),
|
||||
'rating_ftr': defnum(i[15]),
|
||||
'rating_byn': defnum(i[16])
|
||||
'rating_pst': defnum(i[2]),
|
||||
'rating_prs': defnum(i[3]),
|
||||
'rating_ftr': defnum(i[4]),
|
||||
'rating_byn': defnum(i[5])
|
||||
})
|
||||
else:
|
||||
error = '没有铺面数据 No song data.'
|
||||
error = '没有谱面数据 No song data.'
|
||||
|
||||
if error:
|
||||
flash(error)
|
||||
@@ -218,9 +217,9 @@ def single_chart_top():
|
||||
difficulty = int(difficulty)
|
||||
error = None
|
||||
x = None
|
||||
with Connect('./database/arcsong.db') as c:
|
||||
with Connect('') as c:
|
||||
song_name = '%'+song_name+'%'
|
||||
c.execute('''select sid, name_en from songs where sid like :a limit 1''',
|
||||
c.execute('''select song_id, name from chart where song_id like :a limit 1''',
|
||||
{'a': song_name})
|
||||
x = c.fetchone()
|
||||
|
||||
@@ -260,7 +259,7 @@ def update_database():
|
||||
flash('未选择文件 No selected file.')
|
||||
return redirect(request.url)
|
||||
|
||||
if file and allowed_file(file.filename) and file.filename in ['arcsong.db', 'arcaea_database.db']:
|
||||
if file and allowed_file(file.filename) and file.filename in ['arcaea_database.db']:
|
||||
filename = 'old_' + secure_filename(file.filename)
|
||||
file.save(os.path.join(UPLOAD_FOLDER, filename))
|
||||
flash('上传成功 Success upload.')
|
||||
@@ -282,11 +281,11 @@ def update_database():
|
||||
@login_required
|
||||
def update_song_hash():
|
||||
# 更新数据库内谱面文件hash值
|
||||
error = initialize_songfile()
|
||||
if error:
|
||||
flash(error)
|
||||
else:
|
||||
try:
|
||||
initialize_songfile()
|
||||
flash('数据刷新成功 Success refresh data.')
|
||||
except:
|
||||
flash('Something error!')
|
||||
return render_template('web/updatedatabase.html')
|
||||
|
||||
|
||||
@@ -336,11 +335,11 @@ def add_song():
|
||||
if len(name_en) >= 256:
|
||||
name_en = name_en[:200]
|
||||
|
||||
with Connect('./database/arcsong.db') as c:
|
||||
with Connect() as c:
|
||||
c.execute(
|
||||
'''select exists(select * from songs where sid=:a)''', {'a': song_id})
|
||||
'''select exists(select * from chart where song_id=:a)''', {'a': song_id})
|
||||
if c.fetchone() == (0,):
|
||||
c.execute('''insert into songs(sid,name_en,rating_pst,rating_prs,rating_ftr,rating_byn) values(:a,:b,:c,:d,:e,:f)''', {
|
||||
c.execute('''insert into chart values(:a,:b,:c,:d,:e,:f)''', {
|
||||
'a': song_id, 'b': name_en, 'c': rating_pst, 'd': rating_prs, 'e': rating_ftr, 'f': rating_byd})
|
||||
flash('歌曲添加成功 Successfully add the song.')
|
||||
else:
|
||||
@@ -359,11 +358,11 @@ def delete_song():
|
||||
|
||||
error = None
|
||||
song_id = request.form['sid']
|
||||
with Connect('./database/arcsong.db') as c:
|
||||
with Connect() as c:
|
||||
c.execute(
|
||||
'''select exists(select * from songs where sid=:a)''', {'a': song_id})
|
||||
'''select exists(select * from chart where song_id=:a)''', {'a': song_id})
|
||||
if c.fetchone() == (1,):
|
||||
c.execute('''delete from songs where sid=:a''', {'a': song_id})
|
||||
c.execute('''delete from chart where song_id=:a''', {'a': song_id})
|
||||
flash('歌曲删除成功 Successfully delete the song.')
|
||||
else:
|
||||
error = "歌曲不存在 The song doesn't exist."
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import os
|
||||
from server.sql import Connect
|
||||
from core.sql import Connect
|
||||
import time
|
||||
import json
|
||||
import server.arcscore
|
||||
import hashlib
|
||||
from random import Random
|
||||
from setting import Config
|
||||
@@ -22,7 +20,7 @@ def random_str(randomlength=10):
|
||||
chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
|
||||
length = len(chars) - 1
|
||||
random = Random()
|
||||
for i in range(randomlength):
|
||||
for _ in range(randomlength):
|
||||
s += chars[random.randint(0, length)]
|
||||
return s
|
||||
|
||||
@@ -179,7 +177,6 @@ def update_user_char(c):
|
||||
def update_database():
|
||||
# 将old数据库不存在数据加入到新数据库上,并删除old数据库
|
||||
# 对于arcaea_datebase.db,更新一些表,并用character数据更新user_char_full
|
||||
# 对于arcsong.db,更新songs
|
||||
if os.path.isfile("database/old_arcaea_database.db") and os.path.isfile("database/arcaea_database.db"):
|
||||
with Connect('./database/old_arcaea_database.db') as c1:
|
||||
with Connect() as c2:
|
||||
@@ -206,6 +203,7 @@ def update_database():
|
||||
update_one_table(c1, c2, 'power')
|
||||
update_one_table(c1, c2, 'role_power')
|
||||
update_one_table(c1, c2, 'api_login')
|
||||
update_one_table(c1, c2, 'chart')
|
||||
|
||||
update_one_table(c1, c2, 'user_char')
|
||||
|
||||
@@ -216,15 +214,6 @@ def update_database():
|
||||
|
||||
os.remove('database/old_arcaea_database.db')
|
||||
|
||||
# songs
|
||||
if os.path.isfile("database/old_arcsong.db") and os.path.isfile("database/arcsong.db"):
|
||||
with Connect('./database/old_arcsong.db') as c1:
|
||||
with Connect('./database/arcsong.db') as c2:
|
||||
|
||||
update_one_table(c1, c2, 'songs')
|
||||
|
||||
os.remove('database/old_arcsong.db')
|
||||
|
||||
|
||||
def unlock_all_user_item(c):
|
||||
# 解锁所有用户购买
|
||||
@@ -321,44 +310,45 @@ def get_all_purchase():
|
||||
def update_one_save(c, user_id):
|
||||
# 同步指定用户存档
|
||||
# 注意,best_score表不比较,直接覆盖
|
||||
|
||||
c.execute('''select scores_data, clearlamps_data from user_save where user_id=:a''', {
|
||||
'a': user_id})
|
||||
x = c.fetchone()
|
||||
if x:
|
||||
scores = json.loads(x[0])[""]
|
||||
clearlamps = json.loads(x[1])[""]
|
||||
clear_song_id_difficulty = []
|
||||
clear_state = []
|
||||
for i in clearlamps:
|
||||
clear_song_id_difficulty.append(i['song_id']+str(i['difficulty']))
|
||||
clear_state.append(i['clear_type'])
|
||||
|
||||
for i in scores:
|
||||
rating = server.arcscore.get_one_ptt(
|
||||
i['song_id'], i['difficulty'], i['score'])
|
||||
if rating < 0:
|
||||
rating = 0
|
||||
try:
|
||||
index = clear_song_id_difficulty.index(
|
||||
i['song_id'] + str(i['difficulty']))
|
||||
except:
|
||||
index = -1
|
||||
if index != -1:
|
||||
clear_type = clear_state[index]
|
||||
else:
|
||||
clear_type = 0
|
||||
c.execute('''delete from best_score where user_id=:a and song_id=:b and difficulty=:c''', {
|
||||
'a': user_id, 'b': i['song_id'], 'c': i['difficulty']})
|
||||
c.execute('''insert into best_score values(:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, :l, :m, :n)''', {
|
||||
'a': user_id, 'b': i['song_id'], 'c': i['difficulty'], 'd': i['score'], 'e': i['shiny_perfect_count'], 'f': i['perfect_count'], 'g': i['near_count'], 'h': i['miss_count'], 'i': i['health'], 'j': i['modifier'], 'k': i['time_played'], 'l': clear_type, 'm': clear_type, 'n': rating})
|
||||
|
||||
ptt = server.arcscore.get_user_ptt(c, user_id) # 更新PTT
|
||||
c.execute('''update user set rating_ptt=:a where user_id=:b''', {
|
||||
'a': ptt, 'b': user_id})
|
||||
|
||||
return
|
||||
|
||||
# c.execute('''select scores_data, clearlamps_data from user_save where user_id=:a''', {
|
||||
# 'a': user_id})
|
||||
# x = c.fetchone()
|
||||
# if x:
|
||||
# scores = json.loads(x[0])[""]
|
||||
# clearlamps = json.loads(x[1])[""]
|
||||
# clear_song_id_difficulty = []
|
||||
# clear_state = []
|
||||
# for i in clearlamps:
|
||||
# clear_song_id_difficulty.append(i['song_id']+str(i['difficulty']))
|
||||
# clear_state.append(i['clear_type'])
|
||||
|
||||
# for i in scores:
|
||||
# rating = server.arcscore.get_one_ptt(
|
||||
# i['song_id'], i['difficulty'], i['score'])
|
||||
# if rating < 0:
|
||||
# rating = 0
|
||||
# try:
|
||||
# index = clear_song_id_difficulty.index(
|
||||
# i['song_id'] + str(i['difficulty']))
|
||||
# except:
|
||||
# index = -1
|
||||
# if index != -1:
|
||||
# clear_type = clear_state[index]
|
||||
# else:
|
||||
# clear_type = 0
|
||||
# c.execute('''delete from best_score where user_id=:a and song_id=:b and difficulty=:c''', {
|
||||
# 'a': user_id, 'b': i['song_id'], 'c': i['difficulty']})
|
||||
# c.execute('''insert into best_score values(:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, :l, :m, :n)''', {
|
||||
# 'a': user_id, 'b': i['song_id'], 'c': i['difficulty'], 'd': i['score'], 'e': i['shiny_perfect_count'], 'f': i['perfect_count'], 'g': i['near_count'], 'h': i['miss_count'], 'i': i['health'], 'j': i['modifier'], 'k': i['time_played'], 'l': clear_type, 'm': clear_type, 'n': rating})
|
||||
|
||||
# ptt = server.arcscore.get_user_ptt(c, user_id) # 更新PTT
|
||||
# c.execute('''update user set rating_ptt=:a where user_id=:b''', {
|
||||
# 'a': ptt, 'b': user_id})
|
||||
|
||||
# return
|
||||
|
||||
|
||||
def update_all_save(c):
|
||||
# 同步所有用户存档
|
||||
|
||||
Reference in New Issue
Block a user