mirror of
https://github.com/MikuLeaks/KianaBH3.git
synced 2025-12-14 13:54:43 +01:00
refactor: move game_server utils into global utils
This commit is contained in:
@@ -3,24 +3,26 @@ from game_server.net.session import Session
|
|||||||
from game_server.resource import ResourceManager
|
from game_server.resource import ResourceManager
|
||||||
from game_server.resource.configdb.avatar_tutorial import AvatarTutorialData
|
from game_server.resource.configdb.avatar_tutorial import AvatarTutorialData
|
||||||
from game_server.resource.configdb.activity_tower import ActivityTowerData
|
from game_server.resource.configdb.activity_tower import ActivityTowerData
|
||||||
from game_server.utils import get_unix_in_seconds
|
from utils.time import get_unix_in_seconds
|
||||||
from lib.proto import (
|
from lib.proto import (
|
||||||
GeneralActivityGetScheduleReq,
|
GeneralActivityGetScheduleReq,
|
||||||
GeneralActivityGetScheduleRsp,
|
GeneralActivityGetScheduleRsp,
|
||||||
GeneralActivityScheduleInfo
|
GeneralActivityScheduleInfo,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def handle(session: Session, msg: GeneralActivityGetScheduleReq) -> betterproto.Message:
|
|
||||||
|
|
||||||
|
async def handle(
|
||||||
|
session: Session, msg: GeneralActivityGetScheduleReq
|
||||||
|
) -> betterproto.Message:
|
||||||
schedule_list = []
|
schedule_list = []
|
||||||
|
|
||||||
for tutorial in ResourceManager.instance().values(AvatarTutorialData):
|
for tutorial in ResourceManager.instance().values(AvatarTutorialData):
|
||||||
schedule_list.append(
|
schedule_list.append(
|
||||||
GeneralActivityScheduleInfo(
|
GeneralActivityScheduleInfo(
|
||||||
activity_id=tutorial.ActivityID,
|
activity_id=tutorial.ActivityID,
|
||||||
settle_time=int(get_unix_in_seconds()+3600*24*7),
|
settle_time=int(get_unix_in_seconds() + 3600 * 24 * 7),
|
||||||
end_time=int(get_unix_in_seconds()+3600*24*7),
|
end_time=int(get_unix_in_seconds() + 3600 * 24 * 7),
|
||||||
end_day_time=int(get_unix_in_seconds()+3600*24*7)
|
end_day_time=int(get_unix_in_seconds() + 3600 * 24 * 7),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,13 +30,10 @@ async def handle(session: Session, msg: GeneralActivityGetScheduleReq) -> better
|
|||||||
schedule_list.append(
|
schedule_list.append(
|
||||||
GeneralActivityScheduleInfo(
|
GeneralActivityScheduleInfo(
|
||||||
activity_id=tower.ActivityID,
|
activity_id=tower.ActivityID,
|
||||||
settle_time=int(get_unix_in_seconds()+3600*24*7),
|
settle_time=int(get_unix_in_seconds() + 3600 * 24 * 7),
|
||||||
end_time=int(get_unix_in_seconds()+3600*24*7),
|
end_time=int(get_unix_in_seconds() + 3600 * 24 * 7),
|
||||||
end_day_time=int(get_unix_in_seconds()+3600*24*7)
|
end_day_time=int(get_unix_in_seconds() + 3600 * 24 * 7),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return GeneralActivityGetScheduleRsp(
|
return GeneralActivityGetScheduleRsp(retcode=0, schedule_list=schedule_list)
|
||||||
retcode=0,
|
|
||||||
schedule_list=schedule_list
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,22 +1,15 @@
|
|||||||
|
|
||||||
import betterproto
|
import betterproto
|
||||||
from game_server.net.session import Session
|
from game_server.net.session import Session
|
||||||
from game_server.utils import get_unix_in_seconds
|
from utils.time import get_unix_in_seconds
|
||||||
from lib.proto import (
|
from lib.proto import GetBuffEffectReq, GetBuffEffectRsp, BuffEffect
|
||||||
GetBuffEffectReq,
|
|
||||||
GetBuffEffectRsp,
|
|
||||||
BuffEffect
|
|
||||||
)
|
|
||||||
|
|
||||||
async def handle(session: Session, msg: GetBuffEffectReq) -> betterproto.Message:
|
async def handle(session: Session, msg: GetBuffEffectReq) -> betterproto.Message:
|
||||||
return GetBuffEffectRsp(
|
return GetBuffEffectRsp(
|
||||||
retcode=0,
|
retcode=0,
|
||||||
effect_list=[
|
effect_list=[
|
||||||
BuffEffect(
|
BuffEffect(effect_id=i, end_time=int(get_unix_in_seconds() + 3600 * 24 * 7))
|
||||||
effect_id=i,
|
|
||||||
end_time=int(get_unix_in_seconds()+3600*24*7)
|
|
||||||
)
|
|
||||||
for i in msg.effect_id_list
|
for i in msg.effect_id_list
|
||||||
],
|
],
|
||||||
aura_effect_list=msg.effect_id_list[:]
|
aura_effect_list=msg.effect_id_list[:],
|
||||||
)
|
)
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -2,23 +2,16 @@ import betterproto
|
|||||||
from game_server.net.session import Session
|
from game_server.net.session import Session
|
||||||
from game_server.resource import ResourceManager
|
from game_server.resource import ResourceManager
|
||||||
from game_server.resource.configdb.frame_data import Frame_Data
|
from game_server.resource.configdb.frame_data import Frame_Data
|
||||||
from game_server.utils import get_unix_in_seconds
|
from utils.time import get_unix_in_seconds
|
||||||
from lib.proto import (
|
from lib.proto import GetFrameDataReq, GetFrameDataRsp, FrameData
|
||||||
GetFrameDataReq,
|
|
||||||
GetFrameDataRsp,
|
|
||||||
FrameData
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def handle(session: Session, msg: GetFrameDataReq) -> betterproto.Message:
|
async def handle(session: Session, msg: GetFrameDataReq) -> betterproto.Message:
|
||||||
return GetFrameDataRsp(
|
return GetFrameDataRsp(
|
||||||
retcode=0,
|
retcode=0,
|
||||||
is_all=True,
|
is_all=True,
|
||||||
frame_list=[
|
frame_list=[
|
||||||
FrameData(
|
FrameData(id=frame.id, expire_time=get_unix_in_seconds() + 3600 * 24 * 7)
|
||||||
id=frame.id,
|
|
||||||
expire_time=get_unix_in_seconds() + 3600 * 24 * 7
|
|
||||||
)
|
|
||||||
for frame in ResourceManager.instance().values(Frame_Data)
|
for frame in ResourceManager.instance().values(Frame_Data)
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import betterproto
|
import betterproto
|
||||||
from game_server.net.session import Session
|
from game_server.net.session import Session
|
||||||
from game_server.utils import get_unix_in_seconds
|
from utils.time import get_unix_in_seconds
|
||||||
from lib.proto import (
|
from lib.proto import GetLoginActivityReq, GetLoginActivityRsp, LoginActivityData
|
||||||
GetLoginActivityReq,
|
|
||||||
GetLoginActivityRsp,
|
|
||||||
LoginActivityData
|
|
||||||
)
|
|
||||||
|
|
||||||
async def handle(session: Session, msg: GetLoginActivityReq) -> betterproto.Message:
|
async def handle(session: Session, msg: GetLoginActivityReq) -> betterproto.Message:
|
||||||
return GetLoginActivityRsp(
|
return GetLoginActivityRsp(
|
||||||
@@ -15,7 +12,7 @@ async def handle(session: Session, msg: GetLoginActivityReq) -> betterproto.Mess
|
|||||||
id=581,
|
id=581,
|
||||||
login_days=get_unix_in_seconds(),
|
login_days=get_unix_in_seconds(),
|
||||||
accept_time=get_unix_in_seconds(),
|
accept_time=get_unix_in_seconds(),
|
||||||
duration_end_time=get_unix_in_seconds() + 604800 * 2
|
duration_end_time=get_unix_in_seconds() + 604800 * 2,
|
||||||
)
|
)
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
import betterproto
|
import betterproto
|
||||||
from game_server.net.session import Session
|
from game_server.net.session import Session
|
||||||
from lib.proto import GetMainDataReq,GetMainDataRsp,WarshipAvatarData,ChatworldActivityInfo,WarshipThemeData
|
from lib.proto import (
|
||||||
from game_server.utils import get_unix_in_seconds
|
GetMainDataReq,
|
||||||
|
GetMainDataRsp,
|
||||||
|
WarshipAvatarData,
|
||||||
|
ChatworldActivityInfo,
|
||||||
|
WarshipThemeData,
|
||||||
|
)
|
||||||
|
from utils.time import get_unix_in_seconds
|
||||||
|
|
||||||
|
|
||||||
async def handle(session: Session, msg: GetMainDataReq) -> betterproto.Message:
|
async def handle(session: Session, msg: GetMainDataReq) -> betterproto.Message:
|
||||||
return GetMainDataRsp(
|
return GetMainDataRsp(
|
||||||
@@ -20,7 +27,7 @@ async def handle(session: Session, msg: GetMainDataReq) -> betterproto.Message:
|
|||||||
pay_hcoin=0,
|
pay_hcoin=0,
|
||||||
warship_avatar=WarshipAvatarData(
|
warship_avatar=WarshipAvatarData(
|
||||||
warship_first_avatar_id=session.player.warship_avatar.warship_first_avatar_id,
|
warship_first_avatar_id=session.player.warship_avatar.warship_first_avatar_id,
|
||||||
warship_second_avatar_id=session.player.warship_avatar.warship_second_avatar_id
|
warship_second_avatar_id=session.player.warship_avatar.warship_second_avatar_id,
|
||||||
),
|
),
|
||||||
self_desc=session.player.signature,
|
self_desc=session.player.signature,
|
||||||
use_frame_id=session.player.head_frame,
|
use_frame_id=session.player.head_frame,
|
||||||
@@ -31,19 +38,48 @@ async def handle(session: Session, msg: GetMainDataReq) -> betterproto.Message:
|
|||||||
equipment_size_limit=1000,
|
equipment_size_limit=1000,
|
||||||
open_panel_activity_list=[2],
|
open_panel_activity_list=[2],
|
||||||
chatworld_activity_info=ChatworldActivityInfo(
|
chatworld_activity_info=ChatworldActivityInfo(
|
||||||
is_has_npc_red_envelope=False,
|
is_has_npc_red_envelope=False, treasure_schedule_id=0
|
||||||
treasure_schedule_id=0
|
|
||||||
),
|
),
|
||||||
is_allow_cost_senior_equip_on_cur_device=True,
|
is_allow_cost_senior_equip_on_cur_device=True,
|
||||||
type_list=[2, 3, 4, 5, 6, 7, 8, 9, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39],
|
type_list=[
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
7,
|
||||||
|
8,
|
||||||
|
9,
|
||||||
|
14,
|
||||||
|
16,
|
||||||
|
17,
|
||||||
|
18,
|
||||||
|
19,
|
||||||
|
20,
|
||||||
|
21,
|
||||||
|
22,
|
||||||
|
23,
|
||||||
|
24,
|
||||||
|
26,
|
||||||
|
27,
|
||||||
|
28,
|
||||||
|
29,
|
||||||
|
30,
|
||||||
|
31,
|
||||||
|
32,
|
||||||
|
33,
|
||||||
|
35,
|
||||||
|
36,
|
||||||
|
37,
|
||||||
|
38,
|
||||||
|
39,
|
||||||
|
],
|
||||||
level_lock_id=1,
|
level_lock_id=1,
|
||||||
mcoin=100000,
|
mcoin=100000,
|
||||||
month_recharge_price=0,
|
month_recharge_price=0,
|
||||||
warship_theme=WarshipThemeData(
|
warship_theme=WarshipThemeData(warship_id=session.player.warship_id),
|
||||||
warship_id=session.player.warship_id
|
|
||||||
),
|
|
||||||
total_login_days=1,
|
total_login_days=1,
|
||||||
next_evaluate_time=0,
|
next_evaluate_time=0,
|
||||||
on_medal_id=0,
|
on_medal_id=0,
|
||||||
today_recharge_price=0
|
today_recharge_price=0,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,28 +2,27 @@ import betterproto
|
|||||||
from game_server.net.session import Session
|
from game_server.net.session import Session
|
||||||
from game_server.resource import ResourceManager
|
from game_server.resource import ResourceManager
|
||||||
from game_server.resource.configdb.mission_data import MissionData
|
from game_server.resource.configdb.mission_data import MissionData
|
||||||
from game_server.utils import get_unix_in_seconds
|
from utils.time import get_unix_in_seconds
|
||||||
from lib.proto import (
|
from lib.proto import (
|
||||||
GetMissionDataReq,
|
GetMissionDataReq,
|
||||||
GetMissionDataRsp,
|
GetMissionDataRsp,
|
||||||
Mission,
|
Mission,
|
||||||
MissionStatus,
|
MissionStatus,
|
||||||
ChallengeMissionData,
|
ChallengeMissionData,
|
||||||
MainlineStepMission
|
MainlineStepMission,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def handle(session: Session, msg: GetMissionDataReq) -> betterproto.Message:
|
async def handle(session: Session, msg: GetMissionDataReq) -> betterproto.Message:
|
||||||
return GetMissionDataRsp(
|
return GetMissionDataRsp(
|
||||||
retcode=0,
|
retcode=0,
|
||||||
challenge_mission=ChallengeMissionData(
|
challenge_mission=ChallengeMissionData(is_unlock=True),
|
||||||
is_unlock=True
|
close_mission_list=[
|
||||||
),
|
mission.id for mission in ResourceManager.instance().values(MissionData)
|
||||||
close_mission_list=[mission.id for mission in ResourceManager.instance().values(MissionData)],
|
],
|
||||||
is_all=True,
|
is_all=True,
|
||||||
is_in_activity=True,
|
is_in_activity=True,
|
||||||
mainline_step=MainlineStepMission(
|
mainline_step=MainlineStepMission(is_update=True),
|
||||||
is_update=True
|
|
||||||
),
|
|
||||||
mission_list=[
|
mission_list=[
|
||||||
Mission(
|
Mission(
|
||||||
mission_id=mission.id,
|
mission_id=mission.id,
|
||||||
@@ -32,8 +31,8 @@ async def handle(session: Session, msg: GetMissionDataReq) -> betterproto.Messag
|
|||||||
progress=mission.totalProgress,
|
progress=mission.totalProgress,
|
||||||
begin_time=0,
|
begin_time=0,
|
||||||
end_time=2073239999,
|
end_time=2073239999,
|
||||||
cycle_id=1
|
cycle_id=1,
|
||||||
)
|
)
|
||||||
for mission in ResourceManager.instance().values(MissionData)
|
for mission in ResourceManager.instance().values(MissionData)
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import betterproto
|
import betterproto
|
||||||
import random
|
import random
|
||||||
from game_server.net.session import Session
|
from game_server.net.session import Session
|
||||||
from game_server.utils import get_unix_in_seconds
|
from utils.time import get_unix_in_seconds
|
||||||
from lib.proto import (
|
from lib.proto import GetOpenworldEndlessDataReq, GetOpenworldEndlessDataRsp
|
||||||
GetOpenworldEndlessDataReq,
|
|
||||||
GetOpenworldEndlessDataRsp
|
|
||||||
)
|
|
||||||
|
|
||||||
async def handle(session: Session, msg: GetOpenworldEndlessDataReq) -> betterproto.Message:
|
|
||||||
|
async def handle(
|
||||||
|
session: Session, msg: GetOpenworldEndlessDataReq
|
||||||
|
) -> betterproto.Message:
|
||||||
return GetOpenworldEndlessDataRsp(
|
return GetOpenworldEndlessDataRsp(
|
||||||
retcode=0,
|
retcode=0,
|
||||||
begin_time=0,
|
begin_time=0,
|
||||||
@@ -15,5 +15,5 @@ async def handle(session: Session, msg: GetOpenworldEndlessDataReq) -> betterpro
|
|||||||
close_time=int(get_unix_in_seconds() + 3600 * 24 * 7 + 1200),
|
close_time=int(get_unix_in_seconds() + 3600 * 24 * 7 + 1200),
|
||||||
random_seed=random.randint(1, 1000000),
|
random_seed=random.randint(1, 1000000),
|
||||||
hard_level=msg.level,
|
hard_level=msg.level,
|
||||||
type=msg.type
|
type=msg.type,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import betterproto
|
import betterproto
|
||||||
from game_server.net.session import Session
|
from game_server.net.session import Session
|
||||||
from game_server.utils import get_unix_in_seconds
|
from utils.time import get_unix_in_seconds
|
||||||
from lib.proto import GetProductListReq,GetProductListRsp
|
from lib.proto import GetProductListReq, GetProductListRsp
|
||||||
|
|
||||||
|
|
||||||
async def handle(session: Session, msg: GetProductListReq) -> betterproto.Message:
|
async def handle(session: Session, msg: GetProductListReq) -> betterproto.Message:
|
||||||
return GetProductListRsp(
|
return GetProductListRsp(
|
||||||
retcode=0,
|
retcode=0,
|
||||||
next_random_box_product_refresh_time=int(get_unix_in_seconds() + 3600 * 24),
|
next_random_box_product_refresh_time=int(get_unix_in_seconds() + 3600 * 24),
|
||||||
next_limit_product_refresh_time=int(get_unix_in_seconds() + 3600 * 24)
|
next_limit_product_refresh_time=int(get_unix_in_seconds() + 3600 * 24),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
import betterproto
|
import betterproto
|
||||||
from game_server.net.session import Session
|
from game_server.net.session import Session
|
||||||
from game_server.utils import get_unix_in_seconds
|
from utils.time import get_unix_in_seconds
|
||||||
from lib.proto import (
|
from lib.proto import (
|
||||||
GetWeekDayActivityDataReq,
|
GetWeekDayActivityDataReq,
|
||||||
GetWeekDayActivityDataRsp,
|
GetWeekDayActivityDataRsp,
|
||||||
WeekDayActivity
|
WeekDayActivity,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def handle(session: Session, msg: GetWeekDayActivityDataReq) -> betterproto.Message:
|
|
||||||
|
async def handle(
|
||||||
|
session: Session, msg: GetWeekDayActivityDataReq
|
||||||
|
) -> betterproto.Message:
|
||||||
return GetWeekDayActivityDataRsp(
|
return GetWeekDayActivityDataRsp(
|
||||||
retcode=0,
|
retcode=0,
|
||||||
activity_list=[
|
activity_list=[
|
||||||
WeekDayActivity(
|
WeekDayActivity(
|
||||||
activity_id=1003,
|
activity_id=1003,
|
||||||
@@ -18,7 +21,7 @@ async def handle(session: Session, msg: GetWeekDayActivityDataReq) -> betterprot
|
|||||||
begin_time=0,
|
begin_time=0,
|
||||||
end_time=get_unix_in_seconds() + 3600 * 24 * 7,
|
end_time=get_unix_in_seconds() + 3600 * 24 * 7,
|
||||||
activity_begin_time=int(get_unix_in_seconds() * (10 / 8)),
|
activity_begin_time=int(get_unix_in_seconds() * (10 / 8)),
|
||||||
force_open_time=0
|
force_open_time=0,
|
||||||
)
|
)
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import betterproto
|
import betterproto
|
||||||
from game_server.net.session import Session
|
from game_server.net.session import Session
|
||||||
from lib.proto import SyncTimeReq,SyncTimeRsp
|
from lib.proto import SyncTimeReq, SyncTimeRsp
|
||||||
from game_server.utils import get_unix_in_seconds
|
from utils.time import get_unix_in_seconds
|
||||||
|
|
||||||
|
|
||||||
async def handle(session: Session, msg: SyncTimeReq) -> betterproto.Message:
|
async def handle(session: Session, msg: SyncTimeReq) -> betterproto.Message:
|
||||||
return SyncTimeRsp(
|
return SyncTimeRsp(retcode=0, cur_time=get_unix_in_seconds(), seq=msg.seq)
|
||||||
retcode=0,
|
|
||||||
cur_time=get_unix_in_seconds(),
|
|
||||||
seq=msg.seq
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
import time as t
|
|
||||||
from time import time
|
|
||||||
|
|
||||||
def cur_timestamp_ms():
|
|
||||||
return int((time() * 1000))
|
|
||||||
|
|
||||||
def cur_timestamp_seconds():
|
|
||||||
return int(time())
|
|
||||||
|
|
||||||
def get_unix_in_seconds():
|
|
||||||
return int(t.time())
|
|
||||||
4
utils/time.py
Normal file
4
utils/time.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
def get_unix_in_seconds():
|
||||||
|
return int(time.time())
|
||||||
Reference in New Issue
Block a user