From 2a52e391d6abf19d7f6c18786969dd71214ae20e Mon Sep 17 00:00:00 2001 From: Wanich Keatkajonjumroen Date: Mon, 28 Aug 2023 03:18:56 +0900 Subject: [PATCH 1/9] Ongeki template start --- core/json.json | 1 + titles/ongeki/__init__.py | 2 ++ titles/ongeki/frontend.py | 40 +++++++++++++++++++++++ titles/ongeki/frontend/ongeki_index.jinja | 4 +++ 4 files changed, 47 insertions(+) create mode 100644 core/json.json create mode 100644 titles/ongeki/frontend.py create mode 100644 titles/ongeki/frontend/ongeki_index.jinja diff --git a/core/json.json b/core/json.json new file mode 100644 index 0000000..2b267ce --- /dev/null +++ b/core/json.json @@ -0,0 +1 @@ +{'chuni': , 'cm': , 'cxb': , 'diva': , 'idz': , 'mai2': , 'ongeki': , 'pokken': , 'sao': , 'wacca': } \ No newline at end of file diff --git a/titles/ongeki/__init__.py b/titles/ongeki/__init__.py index b887ba6..e4e0ce2 100644 --- a/titles/ongeki/__init__.py +++ b/titles/ongeki/__init__.py @@ -2,9 +2,11 @@ from titles.ongeki.index import OngekiServlet from titles.ongeki.const import OngekiConstants from titles.ongeki.database import OngekiData from titles.ongeki.read import OngekiReader +from titles.ongeki.frontend import OngekiFrontend index = OngekiServlet database = OngekiData reader = OngekiReader +frontend = OngekiFrontend game_codes = [OngekiConstants.GAME_CODE] current_schema_version = 5 diff --git a/titles/ongeki/frontend.py b/titles/ongeki/frontend.py new file mode 100644 index 0000000..474d4d8 --- /dev/null +++ b/titles/ongeki/frontend.py @@ -0,0 +1,40 @@ +import yaml +import jinja2 +from twisted.web.http import Request +from os import path +from twisted.web.server import Session + +from core.frontend import FE_Base, IUserSession +from core.config import CoreConfig + +from titles.ongeki.config import OngekiConfig +from titles.ongeki.const import OngekiConstants +from titles.ongeki.database import OngekiData +# from titles.ongeki.read import OngekiReader + + +class OngekiFrontend(FE_Base): + def __init__( + self, cfg: CoreConfig, environment: jinja2.Environment, cfg_dir: str + ) -> None: + super().__init__(cfg, environment) + self.data = OngekiData(cfg) + self.game_cfg = OngekiConfig() + if path.exists(f"{cfg_dir}/{OngekiConstants.CONFIG_NAME}"): + self.game_cfg.update( + yaml.safe_load(open(f"{cfg_dir}/{OngekiConstants.CONFIG_NAME}")) + ) + self.nav_name = "O.N.G.E.K.I." + + def render_GET(self, request: Request) -> bytes: + template = self.environment.get_template( + "titles/ongeki/frontend/ongeki_index.jinja" + ) + sesh: Session = request.getSession() + usr_sesh = IUserSession(sesh) + + return template.render( + title=f"{self.core_config.server.name} | {self.nav_name}", + game_list=self.environment.globals["game_list"], + sesh=vars(usr_sesh) + ).encode("utf-16") diff --git a/titles/ongeki/frontend/ongeki_index.jinja b/titles/ongeki/frontend/ongeki_index.jinja new file mode 100644 index 0000000..981340c --- /dev/null +++ b/titles/ongeki/frontend/ongeki_index.jinja @@ -0,0 +1,4 @@ +{% extends "core/frontend/index.jinja" %} +{% block content %} +

O.N.G.E.K.I.

+{% endblock content %} \ No newline at end of file From 5cccc9224abe6ecbd22dceeeb1a1c7713e4a303a Mon Sep 17 00:00:00 2001 From: Wanich Keatkajonjumroen Date: Mon, 28 Aug 2023 03:40:09 +0900 Subject: [PATCH 2/9] geki version display --- titles/ongeki/frontend.py | 6 ++++-- titles/ongeki/frontend/ongeki_index.jinja | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/titles/ongeki/frontend.py b/titles/ongeki/frontend.py index 474d4d8..0ec05c1 100644 --- a/titles/ongeki/frontend.py +++ b/titles/ongeki/frontend.py @@ -10,7 +10,6 @@ from core.config import CoreConfig from titles.ongeki.config import OngekiConfig from titles.ongeki.const import OngekiConstants from titles.ongeki.database import OngekiData -# from titles.ongeki.read import OngekiReader class OngekiFrontend(FE_Base): @@ -25,7 +24,8 @@ class OngekiFrontend(FE_Base): yaml.safe_load(open(f"{cfg_dir}/{OngekiConstants.CONFIG_NAME}")) ) self.nav_name = "O.N.G.E.K.I." - + self.geki_version = OngekiConstants.VERSION_NAMES[-1]+"?" + print(OngekiConstants.VERSION_NAMES[-1]) def render_GET(self, request: Request) -> bytes: template = self.environment.get_template( "titles/ongeki/frontend/ongeki_index.jinja" @@ -36,5 +36,7 @@ class OngekiFrontend(FE_Base): return template.render( title=f"{self.core_config.server.name} | {self.nav_name}", game_list=self.environment.globals["game_list"], + gachas=self.game_cfg.gachas.enabled_gachas, + version= self.geki_version, sesh=vars(usr_sesh) ).encode("utf-16") diff --git a/titles/ongeki/frontend/ongeki_index.jinja b/titles/ongeki/frontend/ongeki_index.jinja index 981340c..ddcdd05 100644 --- a/titles/ongeki/frontend/ongeki_index.jinja +++ b/titles/ongeki/frontend/ongeki_index.jinja @@ -1,4 +1,8 @@ {% extends "core/frontend/index.jinja" %} {% block content %} -

O.N.G.E.K.I.

+
+
+
+

{{ title }}

+Version: {{version}} {% endblock content %} \ No newline at end of file From 0d7409906a9c78016a0af678b463f131e0398cc1 Mon Sep 17 00:00:00 2001 From: Wanich Keatkajonjumroen Date: Wed, 30 Aug 2023 03:38:32 +0900 Subject: [PATCH 3/9] fixed backend ongeki rival functionality --- titles/ongeki/base.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/titles/ongeki/base.py b/titles/ongeki/base.py index ace1d12..9977157 100644 --- a/titles/ongeki/base.py +++ b/titles/ongeki/base.py @@ -978,35 +978,41 @@ class OngekiBase: """ Added in Bright """ - rival_list = self.data.profile.get_rivals(data["userId"]) - if rival_list is None or len(rival_list) < 1: + + rival_list = [] + user_rivals = self.data.profile.get_rivals(data["userId"]) + for rival in user_rivals: + tmp = {} + tmp["rivalUserId"] = rival[0] + rival_list.append(tmp) + + if user_rivals is None or len(rival_list) < 1: return { "userId": data["userId"], "length": 0, "userRivalList": [], } - return { "userId": data["userId"], "length": len(rival_list), - "userRivalList": rival_list._asdict(), + "userRivalList": rival_list, } - def handle_get_user_rival_data_api_reqiest(self, data: Dict) -> Dict: + def handle_get_user_rival_data_api_request(self, data: Dict) -> Dict: """ Added in Bright """ rivals = [] - + print(data) for rival in data["userRivalList"]: name = self.data.profile.get_profile_name( rival["rivalUserId"], self.version ) if name is None: continue - - rivals.append({"rivalUserId": rival["rival"], "rivalUserName": name}) - + print(name) + rivals.append({"rivalUserId": rival["rivalUserId"], "rivalUserName": name}) + print(rivals) return { "userId": data["userId"], "length": len(rivals), @@ -1027,7 +1033,7 @@ class OngekiBase: for song in music["userMusicList"]: song["userRivalMusicDetailList"] = song["userMusicDetailList"] song.pop("userMusicDetailList") - + print(music["userMusicList"]) return { "userId": data["userId"], "rivalUserId": rival_id, From eaf9e0cf09cd8698a37024377e40bf28309a36e0 Mon Sep 17 00:00:00 2001 From: Wanich Keatkajonjumroen Date: Wed, 30 Aug 2023 04:10:26 +0900 Subject: [PATCH 4/9] removed temp file --- core/json.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 core/json.json diff --git a/core/json.json b/core/json.json deleted file mode 100644 index 2b267ce..0000000 --- a/core/json.json +++ /dev/null @@ -1 +0,0 @@ -{'chuni': , 'cm': , 'cxb': , 'diva': , 'idz': , 'mai2': , 'ongeki': , 'pokken': , 'sao': , 'wacca': } \ No newline at end of file From 1f545aed41e8159f636e957b94a6a51e190ffe02 Mon Sep 17 00:00:00 2001 From: Wanich Keatkajonjumroen Date: Sat, 2 Sep 2023 05:04:59 +0900 Subject: [PATCH 5/9] removed print statements --- titles/ongeki/base.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/titles/ongeki/base.py b/titles/ongeki/base.py index 9977157..f69b351 100644 --- a/titles/ongeki/base.py +++ b/titles/ongeki/base.py @@ -1003,16 +1003,13 @@ class OngekiBase: Added in Bright """ rivals = [] - print(data) for rival in data["userRivalList"]: name = self.data.profile.get_profile_name( rival["rivalUserId"], self.version ) if name is None: continue - print(name) rivals.append({"rivalUserId": rival["rivalUserId"], "rivalUserName": name}) - print(rivals) return { "userId": data["userId"], "length": len(rivals), From 147d7adaafc77f43c045794637c6a0be65f9e06d Mon Sep 17 00:00:00 2001 From: Wanich Keatkajonjumroen Date: Sat, 2 Sep 2023 06:21:02 +0900 Subject: [PATCH 6/9] Frontend for adding rivals, versionless backend function to support --- core/frontend/index.jinja | 3 + titles/ongeki/frontend.py | 54 ++++++++++++++---- titles/ongeki/frontend/ongeki_index.jinja | 69 ++++++++++++++++++++++- titles/ongeki/schema/profile.py | 15 ++++- 4 files changed, 127 insertions(+), 14 deletions(-) diff --git a/core/frontend/index.jinja b/core/frontend/index.jinja index 7e4a1ca..fa89fc3 100644 --- a/core/frontend/index.jinja +++ b/core/frontend/index.jinja @@ -77,6 +77,9 @@ margin-bottom: 10px; width: 15%; } + .modal-content { + background-color: #181a1b; + } diff --git a/titles/ongeki/frontend.py b/titles/ongeki/frontend.py index 0ec05c1..02fe5bf 100644 --- a/titles/ongeki/frontend.py +++ b/titles/ongeki/frontend.py @@ -2,6 +2,7 @@ import yaml import jinja2 from twisted.web.http import Request from os import path +from twisted.web.util import redirectTo from twisted.web.server import Session from core.frontend import FE_Base, IUserSession @@ -10,6 +11,7 @@ from core.config import CoreConfig from titles.ongeki.config import OngekiConfig from titles.ongeki.const import OngekiConstants from titles.ongeki.database import OngekiData +from titles.ongeki.base import OngekiBase class OngekiFrontend(FE_Base): @@ -24,19 +26,51 @@ class OngekiFrontend(FE_Base): yaml.safe_load(open(f"{cfg_dir}/{OngekiConstants.CONFIG_NAME}")) ) self.nav_name = "O.N.G.E.K.I." - self.geki_version = OngekiConstants.VERSION_NAMES[-1]+"?" - print(OngekiConstants.VERSION_NAMES[-1]) + self.version = 7 + def render_GET(self, request: Request) -> bytes: template = self.environment.get_template( "titles/ongeki/frontend/ongeki_index.jinja" ) sesh: Session = request.getSession() usr_sesh = IUserSession(sesh) - - return template.render( - title=f"{self.core_config.server.name} | {self.nav_name}", - game_list=self.environment.globals["game_list"], - gachas=self.game_cfg.gachas.enabled_gachas, - version= self.geki_version, - sesh=vars(usr_sesh) - ).encode("utf-16") + if getattr(usr_sesh, "userId", 0) != 0: + profile_data =self.data.profile.get_profile_data_ignore_version(usr_sesh.userId) + rival_list = self.data.profile.get_rivals(usr_sesh.userId) + rival_data = { + "userRivalList": rival_list, + "userId": usr_sesh.userId + } + self.version = getattr(profile_data, "version" , 7) + if len(rival_list) > 0: + rival_info = OngekiBase.handle_get_user_rival_data_api_request(self, rival_data) + + return template.render( + data=self.data.profile, + title=f"{self.core_config.server.name} | {self.nav_name}", + game_list=self.environment.globals["game_list"], + gachas=self.game_cfg.gachas.enabled_gachas, + profile_data=profile_data, + rival_info=rival_info["userRivalDataList"], + sesh=vars(usr_sesh) + ).encode("utf-16") + else: + return redirectTo(b"/gate/", request) + + def render_POST(self, request: Request): + uri = request.uri.decode() + sesh: Session = request.getSession() + usr_sesh = IUserSession(sesh) + if hasattr(usr_sesh, "userId"): + if uri == "/game/ongeki/rival.add": + rival_id = request.args[b"rivalUserId"][0].decode() + self.data.profile.put_rival(usr_sesh.userId, rival_id) + self.logger.info(f"{usr_sesh.userId} added a rival") + return redirectTo(b"/game/ongeki/", request) + elif uri == "/game/ongeki/rival.delete": + return b"" + + else: + return b"" + else: + return b"User is not logged in" diff --git a/titles/ongeki/frontend/ongeki_index.jinja b/titles/ongeki/frontend/ongeki_index.jinja index ddcdd05..0eb271b 100644 --- a/titles/ongeki/frontend/ongeki_index.jinja +++ b/titles/ongeki/frontend/ongeki_index.jinja @@ -1,8 +1,73 @@ {% extends "core/frontend/index.jinja" %} {% block content %} + +{% if sesh is defined and sesh["userId"] > 0 %}


-

{{ title }}

-Version: {{version}} + +
+
+

Profile

+
+
+
+

{{ profile_data.userName }}

+
+
+

ID: {{ profile_data.user}}

+
+
+
+

Rivals

+
+
+ + + + + + + + + + {% for rival in rival_info%} + + + + + + {% endfor %} + +
IDNameDelete
{{rival.rivalUserId}}{{rival.rivalUserName}}
+
+ +
+ +{# #} +{% else %} +

Not Currently Logged In

+{% endif %} {% endblock content %} \ No newline at end of file diff --git a/titles/ongeki/schema/profile.py b/titles/ongeki/schema/profile.py index f6eeef2..a5bce97 100644 --- a/titles/ongeki/schema/profile.py +++ b/titles/ongeki/schema/profile.py @@ -269,7 +269,7 @@ class OngekiProfileData(BaseData): return None return row["userName"] - + def get_profile_preview(self, aime_id: int, version: int) -> Optional[Row]: sql = ( select([profile, option]) @@ -295,6 +295,17 @@ class OngekiProfileData(BaseData): return None return result.fetchone() + def get_profile_data_ignore_version(self, aime_id: int) -> Optional[Row]: + sql = select(profile).where( + and_( + profile.c.user == aime_id, + ) + ) + + result = self.execute(sql) + if result is None: + return None + return result.fetchone() def get_profile_options(self, aime_id: int) -> Optional[Row]: sql = select(option).where( and_( @@ -499,7 +510,7 @@ class OngekiProfileData(BaseData): def put_rival(self, aime_id: int, rival_id: int) -> Optional[int]: sql = insert(rival).values(user=aime_id, rivalUserId=rival_id) - conflict = sql.on_duplicate_key_update(rival=rival_id) + conflict = sql.on_duplicate_key_update(rivalUserId=rival_id) result = self.execute(conflict) if result is None: From 16d801aff5b52235435b4e9f229ee733b670f932 Mon Sep 17 00:00:00 2001 From: Wanich Keatkajonjumroen Date: Sat, 2 Sep 2023 07:40:57 +0900 Subject: [PATCH 7/9] Rival Delete functionality --- core/frontend/index.jinja | 1 + titles/ongeki/frontend.py | 9 ++++++--- titles/ongeki/frontend/js/rival_scripts.js | 12 ++++++++++++ titles/ongeki/frontend/ongeki_index.jinja | 9 +++++---- titles/ongeki/schema/profile.py | 9 ++++++++- 5 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 titles/ongeki/frontend/js/rival_scripts.js diff --git a/core/frontend/index.jinja b/core/frontend/index.jinja index fa89fc3..3dacbe5 100644 --- a/core/frontend/index.jinja +++ b/core/frontend/index.jinja @@ -4,6 +4,7 @@ {{ title }} +