From 9b5ed65d4760c7d8c363aee6ff81d923affc852c Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Sun, 31 Jul 2022 13:30:15 +0200 Subject: [PATCH 1/4] Basic login sequence --- .gitignore | 2 +- src/commands/debug.ts | 1 + src/db/Account.ts | 5 +++ src/db/Database.ts | 14 +++++++++ src/db/Player.ts | 2 +- src/server/packets/GetAllLineupDataCsReq.ts | 12 +++++++ src/server/packets/GetAvatarDataCsReq.ts | 31 +++++++++++++++++++ src/server/packets/GetBagCsReq.ts | 16 ++++++++++ src/server/packets/GetBasicInfoCsReq.ts | 15 +++++++++ src/server/packets/GetChallengeCsReq.ts | 12 +++++++ .../packets/GetChallengeRaidInfoCsReq.ts | 13 ++++++++ src/server/packets/GetCurBattleInfoCsReq.ts | 26 ++++++++++++++++ src/server/packets/GetCurLineupDataCsReq.ts | 20 ++++++++++++ src/server/packets/GetCurSceneInfoCsReq.ts | 21 +++++++++++++ .../packets/GetDialogueEventDataCsReq.ts | 12 +++++++ src/server/packets/GetExpeditionDataCsReq.ts | 14 +++++++++ src/server/packets/GetFirstTalkNpcCsReq.ts | 11 +++++++ .../packets/GetHeroBasicTypeInfoCsReq.ts | 28 +++++++++++++++++ src/server/packets/GetHeroPathCsReq.ts | 16 ++++++++++ .../packets/GetLevelRewardTakenListCsReq.ts | 12 +++++++ src/server/packets/GetLoginActivityCsReq.ts | 16 ++++++++++ src/server/packets/GetMailCsReq.ts | 16 ++++++++++ src/server/packets/GetMazeTimeOfDayCsReq.ts | 12 +++++++ src/server/packets/GetMissionDataCsReq.ts | 12 +++++++ .../packets/GetMissionEventDataCsReq.ts | 12 +++++++ src/server/packets/GetMissionStatusCsReq.ts | 15 +++++++++ src/server/packets/GetNpcStatusCsReq.ts | 12 +++++++ src/server/packets/GetQuestDataCsReq.ts | 14 +++++++++ src/server/packets/GetRogueInfoCsReq.ts | 12 +++++++ .../packets/GetSpringRecoverDataCsReq.ts | 20 ++++++++++++ src/server/packets/PlayerKeepAliveNotify.ts | 9 ++++++ src/server/packets/SyncTimeCsReq.ts | 13 ++++++++ 32 files changed, 444 insertions(+), 2 deletions(-) create mode 100644 src/server/packets/GetAllLineupDataCsReq.ts create mode 100644 src/server/packets/GetAvatarDataCsReq.ts create mode 100644 src/server/packets/GetBagCsReq.ts create mode 100644 src/server/packets/GetBasicInfoCsReq.ts create mode 100644 src/server/packets/GetChallengeCsReq.ts create mode 100644 src/server/packets/GetChallengeRaidInfoCsReq.ts create mode 100644 src/server/packets/GetCurBattleInfoCsReq.ts create mode 100644 src/server/packets/GetCurLineupDataCsReq.ts create mode 100644 src/server/packets/GetCurSceneInfoCsReq.ts create mode 100644 src/server/packets/GetDialogueEventDataCsReq.ts create mode 100644 src/server/packets/GetExpeditionDataCsReq.ts create mode 100644 src/server/packets/GetFirstTalkNpcCsReq.ts create mode 100644 src/server/packets/GetHeroBasicTypeInfoCsReq.ts create mode 100644 src/server/packets/GetHeroPathCsReq.ts create mode 100644 src/server/packets/GetLevelRewardTakenListCsReq.ts create mode 100644 src/server/packets/GetLoginActivityCsReq.ts create mode 100644 src/server/packets/GetMailCsReq.ts create mode 100644 src/server/packets/GetMazeTimeOfDayCsReq.ts create mode 100644 src/server/packets/GetMissionDataCsReq.ts create mode 100644 src/server/packets/GetMissionEventDataCsReq.ts create mode 100644 src/server/packets/GetMissionStatusCsReq.ts create mode 100644 src/server/packets/GetNpcStatusCsReq.ts create mode 100644 src/server/packets/GetQuestDataCsReq.ts create mode 100644 src/server/packets/GetRogueInfoCsReq.ts create mode 100644 src/server/packets/GetSpringRecoverDataCsReq.ts create mode 100644 src/server/packets/PlayerKeepAliveNotify.ts create mode 100644 src/server/packets/SyncTimeCsReq.ts diff --git a/.gitignore b/.gitignore index 45b3993..d8c7cab 100644 --- a/.gitignore +++ b/.gitignore @@ -106,4 +106,4 @@ dist # CrepeSR config.json -src/data/proto \ No newline at end of file +src/data/* \ No newline at end of file diff --git a/src/commands/debug.ts b/src/commands/debug.ts index fec4b68..55c1919 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -14,6 +14,7 @@ export default async function handle(command: Command) { } Config.VERBOSE_LEVEL = level as unknown as VerboseLevel; + Logger.VERBOSE_LEVEL = level as unknown as VerboseLevel; c.log(`VerboseLevel set to ${Config.VERBOSE_LEVEL} (${VerboseLevel[level]})`); } } \ No newline at end of file diff --git a/src/db/Account.ts b/src/db/Account.ts index 41451da..9d909cc 100644 --- a/src/db/Account.ts +++ b/src/db/Account.ts @@ -64,6 +64,11 @@ export default class Account { } await db.delete("accounts", { _id: Number(uid) }); } + + public async save() { + const db = Database.getInstance(); + await db.update("accounts", { _id: Number(this.uid) }, this); + } } function generateToken(): string { diff --git a/src/db/Database.ts b/src/db/Database.ts index 09e388b..00cd847 100644 --- a/src/db/Database.ts +++ b/src/db/Database.ts @@ -65,4 +65,18 @@ export default class Database { c.error(e as Error); } } + + public async update(collection: string, query: {}, payload: {}) { + try { + const db = await Database.client.db(); + const _collection = db.collection(collection); + if (!(await db.listCollections({ name: collection }).toArray()).length) { + c.warn(`Collection ${collection} does not exist. Creating...`); + await _collection.createIndexes([{ key: { id: 1 }, unique: true }]); + } + return await _collection.updateOne(query, { $set: payload }, { upsert: true }); + } catch (e) { + c.error(e as Error); + } + } } \ No newline at end of file diff --git a/src/db/Player.ts b/src/db/Player.ts index b9b6871..da31543 100644 --- a/src/db/Player.ts +++ b/src/db/Player.ts @@ -63,6 +63,6 @@ export default class Player { public async save() { const db = Database.getInstance(); - await db.set("players", this.db); + await db.update("players", { _id: this.db._id } , this.db); } } \ No newline at end of file diff --git a/src/server/packets/GetAllLineupDataCsReq.ts b/src/server/packets/GetAllLineupDataCsReq.ts new file mode 100644 index 0000000..22fc5f5 --- /dev/null +++ b/src/server/packets/GetAllLineupDataCsReq.ts @@ -0,0 +1,12 @@ +import { GetAllLineupDataCsReq, GetAllLineupDataScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetAllLineupDataCsReq; + + session.send("GetAllLineupDataScRsp", { + retcode: 0, + lineupList: [] + } as unknown as GetAllLineupDataScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetAvatarDataCsReq.ts b/src/server/packets/GetAvatarDataCsReq.ts new file mode 100644 index 0000000..d856e4f --- /dev/null +++ b/src/server/packets/GetAvatarDataCsReq.ts @@ -0,0 +1,31 @@ +import { ActivateFarmElementCsReq, GetAvatarDataCsReq, GetAvatarDataScRsp } from "../../data/proto/StarRail"; +import AvatarExcelTable from "../../data/excel/AvatarExcelTable.json"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetAvatarDataCsReq; + + const dataObj = { + retcode: 0, + avatarList: [{ + + }], + isAll: false + } as GetAvatarDataScRsp; + + Object.values(AvatarExcelTable).forEach(avatar => { + dataObj.avatarList.push({ + baseAvatarId: avatar.AvatarID, + equipmentUniqueId: 13501, + equipRelicList: [], + exp: 0, + level: 1, + promotion: 1, + rank: 100101, + skilltreeList: avatar.SkillList.map(skill => ({level: 1, pointId: skill})), + }) + }); + + session.send("GetAvatarDataScRsp", dataObj); +} \ No newline at end of file diff --git a/src/server/packets/GetBagCsReq.ts b/src/server/packets/GetBagCsReq.ts new file mode 100644 index 0000000..9c1ad85 --- /dev/null +++ b/src/server/packets/GetBagCsReq.ts @@ -0,0 +1,16 @@ +import { GetBagCsReq, GetBagScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetBagCsReq; + + session.send("GetBagScRsp", { + equipmentList: [], + materialList: [], + relicList: [], + retcode: 0, + rogueItemList: [], + waitDelResourceList: [] + } as GetBagScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetBasicInfoCsReq.ts b/src/server/packets/GetBasicInfoCsReq.ts new file mode 100644 index 0000000..a83f0bb --- /dev/null +++ b/src/server/packets/GetBasicInfoCsReq.ts @@ -0,0 +1,15 @@ +import { GetBasicInfoCsReq, GetBasicInfoScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetBasicInfoCsReq; + + session.send("GetBasicInfoScRsp", { + curDay: 1, + exchangeTimes: 0, + retcode: 0, + nextRecoverTime: Math.round(new Date().getTime() / 1000) + 100000, + weekCocoonFinishedCount: 0 + } as GetBasicInfoScRsp) +} \ No newline at end of file diff --git a/src/server/packets/GetChallengeCsReq.ts b/src/server/packets/GetChallengeCsReq.ts new file mode 100644 index 0000000..325d044 --- /dev/null +++ b/src/server/packets/GetChallengeCsReq.ts @@ -0,0 +1,12 @@ +import { GetChallengeCsReq, GetChallengeScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetChallengeCsReq; + + session.send("GetChallengeScRsp", { + retcode: 0, + challengeList: [] + } as GetChallengeScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetChallengeRaidInfoCsReq.ts b/src/server/packets/GetChallengeRaidInfoCsReq.ts new file mode 100644 index 0000000..d3bad49 --- /dev/null +++ b/src/server/packets/GetChallengeRaidInfoCsReq.ts @@ -0,0 +1,13 @@ +import { GetChallengeRaidInfoCsReq, GetChallengeRaidInfoScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetChallengeRaidInfoCsReq; + + session.send("GetChallengeRaidInfoScRsp", { + retcode: 0, + challengeRaidList: [], + takenRewardIdList: [] + } as GetChallengeRaidInfoScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetCurBattleInfoCsReq.ts b/src/server/packets/GetCurBattleInfoCsReq.ts new file mode 100644 index 0000000..b550b40 --- /dev/null +++ b/src/server/packets/GetCurBattleInfoCsReq.ts @@ -0,0 +1,26 @@ +import { AvatarType, GetCurBattleInfoCsReq, GetCurBattleInfoScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetCurBattleInfoCsReq; + + session.send("GetCurBattleInfoScRsp", { + retcode: 0, + avatarList: [{ + avatarType: AvatarType.AVATAR_TRIAL_TYPE, + hp: 1000, + id: 1001, + index: 1, + sp: 100, + level: 1, + promotion: 1, + rank: 100101, + equipmentList: [], + relicList: [], + skilltreeList: [100101] + }], + stageId: 10000, + logicRandomSeed: 2503 + } as unknown as GetCurBattleInfoScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetCurLineupDataCsReq.ts b/src/server/packets/GetCurLineupDataCsReq.ts new file mode 100644 index 0000000..e71e08a --- /dev/null +++ b/src/server/packets/GetCurLineupDataCsReq.ts @@ -0,0 +1,20 @@ +import { GetCurLineupDataCsReq, GetCurLineupDataScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetCurLineupDataCsReq; + + session.send("GetCurLineupDataScRsp", { + retcode: 0, + lineup: { + avatarList: [1001, 1002], + index: 1, + isVirtual: false, + mp: 100, + name: "lineuprspname", + planeId: 10000, + leaderSlot: 1, + } + } as unknown as GetCurLineupDataScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetCurSceneInfoCsReq.ts b/src/server/packets/GetCurSceneInfoCsReq.ts new file mode 100644 index 0000000..4891d8a --- /dev/null +++ b/src/server/packets/GetCurSceneInfoCsReq.ts @@ -0,0 +1,21 @@ +import { GetCurSceneInfoCsReq, GetCurSceneInfoScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetCurSceneInfoCsReq; + + session.send("GetCurSceneInfoScRsp", { + retcode: 0, + scene: { + planeId: 10000, + floorId: 10000000, + entityList: [], + entityBuffList: [], + entryId: 10001, + envBuffList: [], + gameModeType: 1, + lightenSectionList: [] + }, + } as unknown as GetCurSceneInfoScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetDialogueEventDataCsReq.ts b/src/server/packets/GetDialogueEventDataCsReq.ts new file mode 100644 index 0000000..15eb14f --- /dev/null +++ b/src/server/packets/GetDialogueEventDataCsReq.ts @@ -0,0 +1,12 @@ +import { GetDialogueEventDataCsReq, GetDialogueEventDataScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetDialogueEventDataCsReq; + + session.send("GetDialogueEventDataScRsp", { + dialogueEventList: [], + retcode: 0 + } as GetDialogueEventDataScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetExpeditionDataCsReq.ts b/src/server/packets/GetExpeditionDataCsReq.ts new file mode 100644 index 0000000..2a2e532 --- /dev/null +++ b/src/server/packets/GetExpeditionDataCsReq.ts @@ -0,0 +1,14 @@ +import { GetExpeditionDataCsReq, GetExpeditionDataScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetExpeditionDataCsReq; + + session.send("GetExpeditionDataScRsp", { + retcode: 0, + expedtionList: [], + unlockedExpeditionIdList: [], + teamCount: 4 + } as GetExpeditionDataScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetFirstTalkNpcCsReq.ts b/src/server/packets/GetFirstTalkNpcCsReq.ts new file mode 100644 index 0000000..73dd33f --- /dev/null +++ b/src/server/packets/GetFirstTalkNpcCsReq.ts @@ -0,0 +1,11 @@ +import { GetFirstTalkNpcCsReq, GetFirstTalkNpcScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetFirstTalkNpcCsReq; + + session.send("GetFirstTalkNpcScRsp", { + retcode: 0, + } as GetFirstTalkNpcScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetHeroBasicTypeInfoCsReq.ts b/src/server/packets/GetHeroBasicTypeInfoCsReq.ts new file mode 100644 index 0000000..5a0f84a --- /dev/null +++ b/src/server/packets/GetHeroBasicTypeInfoCsReq.ts @@ -0,0 +1,28 @@ +import { Gender, GetHeroBasicTypeInfoCsReq, GetHeroBasicTypeInfoScRsp, HeroBasicType } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetHeroBasicTypeInfoCsReq; + + session.send("GetHeroBasicTypeInfoScRsp", { + retcode: 0, + gender: Gender.GenderMan, + basicTypeInfoList: [{ + basicType: HeroBasicType.BoyMage, + rank: 1, + skillTreeList: [{ + level: 1, + pointId: 1 + }] + }], + curBasicType: HeroBasicType.BoyMage, + heroPathList: [{ + exp: 0, + level: 1, + heroPathType: 1 + }], + isPlayerInfoModified: false, + isGenderModified: false + } as GetHeroBasicTypeInfoScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetHeroPathCsReq.ts b/src/server/packets/GetHeroPathCsReq.ts new file mode 100644 index 0000000..e112adc --- /dev/null +++ b/src/server/packets/GetHeroPathCsReq.ts @@ -0,0 +1,16 @@ +import { GetHeroPathCsReq, GetHeroPathScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetHeroPathCsReq; + + session.send("GetHeroPathScRsp", { + retcode: 0, + heroPathList: [{ + exp: 0, + level: 1, + heroPathType: 1 + }] + } as GetHeroPathScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetLevelRewardTakenListCsReq.ts b/src/server/packets/GetLevelRewardTakenListCsReq.ts new file mode 100644 index 0000000..aefb117 --- /dev/null +++ b/src/server/packets/GetLevelRewardTakenListCsReq.ts @@ -0,0 +1,12 @@ +import { GetLevelRewardTakenListCsReq, GetLevelRewardTakenListScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetLevelRewardTakenListCsReq; + + session.send("GetLevelRewardTakenListScRsp", { + retcode: 0, + takenLevelList: [] + } as GetLevelRewardTakenListScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetLoginActivityCsReq.ts b/src/server/packets/GetLoginActivityCsReq.ts new file mode 100644 index 0000000..8443825 --- /dev/null +++ b/src/server/packets/GetLoginActivityCsReq.ts @@ -0,0 +1,16 @@ +import { GetLoginActivityCsReq, GetLoginActivityScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetLoginActivityCsReq; + + session.send("GetLoginActivityScRsp", { + retcode: 0, + loginActivityList: [{ + hasTakenLoginActivityRewardDaysList: [], + id: 1000, + loginDays: 1, + }] + } as GetLoginActivityScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetMailCsReq.ts b/src/server/packets/GetMailCsReq.ts new file mode 100644 index 0000000..40b9cb3 --- /dev/null +++ b/src/server/packets/GetMailCsReq.ts @@ -0,0 +1,16 @@ +import { GetMailCsReq, GetMailScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetMailCsReq; + + session.send("GetMailScRsp", { + retcode: 0, + mailList: [], + noticeMailList: [], + start: 0, + totalNum: 0, + isEnd: false + } as GetMailScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetMazeTimeOfDayCsReq.ts b/src/server/packets/GetMazeTimeOfDayCsReq.ts new file mode 100644 index 0000000..30bf2db --- /dev/null +++ b/src/server/packets/GetMazeTimeOfDayCsReq.ts @@ -0,0 +1,12 @@ +import { GetMazeTimeOfDayCsReq, GetMazeTimeOfDayScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetMazeTimeOfDayCsReq; + + session.send("GetMazeTimeOfDayScRsp", { + retcode: 0, + mazeTimeOfDayMap: {} + } as GetMazeTimeOfDayScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetMissionDataCsReq.ts b/src/server/packets/GetMissionDataCsReq.ts new file mode 100644 index 0000000..01507f8 --- /dev/null +++ b/src/server/packets/GetMissionDataCsReq.ts @@ -0,0 +1,12 @@ +import { GetMissionDataCsReq, GetMissionDataScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetMissionDataCsReq; + + session.send("GetMissionDataScRsp", { + retcode: 0, + missionList: [] + } as unknown as GetMissionDataScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetMissionEventDataCsReq.ts b/src/server/packets/GetMissionEventDataCsReq.ts new file mode 100644 index 0000000..261e344 --- /dev/null +++ b/src/server/packets/GetMissionEventDataCsReq.ts @@ -0,0 +1,12 @@ +import { GetMissionEventDataCsReq, GetMissionEventDataScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetMissionEventDataCsReq; + + session.send("GetMissionEventDataScRsp", { + retcode: 0, + missionEventList: [] + } as unknown as GetMissionEventDataScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetMissionStatusCsReq.ts b/src/server/packets/GetMissionStatusCsReq.ts new file mode 100644 index 0000000..ce8bc56 --- /dev/null +++ b/src/server/packets/GetMissionStatusCsReq.ts @@ -0,0 +1,15 @@ +import { GetMissionStatusCsReq, GetMissionStatusScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetMissionStatusCsReq; + + session.send("GetMissionStatusScRsp", { + retcode: 0, + finishedMainMissionIdList: [], + missionEventStatusList: [], + subMissionStatusList: [], + unfinishedMainMissionIdList: [] + } as GetMissionStatusScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetNpcStatusCsReq.ts b/src/server/packets/GetNpcStatusCsReq.ts new file mode 100644 index 0000000..d941df2 --- /dev/null +++ b/src/server/packets/GetNpcStatusCsReq.ts @@ -0,0 +1,12 @@ +import { GetNpcStatusCsReq, GetNpcStatusScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetNpcStatusCsReq; + + session.send("GetNpcStatusScRsp", { + retcode: 0, + messageStatusList: [] + } as GetNpcStatusScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetQuestDataCsReq.ts b/src/server/packets/GetQuestDataCsReq.ts new file mode 100644 index 0000000..102deab --- /dev/null +++ b/src/server/packets/GetQuestDataCsReq.ts @@ -0,0 +1,14 @@ +import { GetQuestDataCsReq, GetQuestDataScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetQuestDataCsReq; + + session.send("GetQuestDataScRsp", { + questList: [], + retcode: 0, + takenAchievementLevelList: [], + totalAchievementExp: 1, + } as GetQuestDataScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetRogueInfoCsReq.ts b/src/server/packets/GetRogueInfoCsReq.ts new file mode 100644 index 0000000..1224f0a --- /dev/null +++ b/src/server/packets/GetRogueInfoCsReq.ts @@ -0,0 +1,12 @@ +import { GetRogueInfoCsReq, GetRogueInfoScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetRogueInfoCsReq; + + session.send("GetRogueInfoScRsp", { + retcode: 0, + + } as GetRogueInfoScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetSpringRecoverDataCsReq.ts b/src/server/packets/GetSpringRecoverDataCsReq.ts new file mode 100644 index 0000000..ede3959 --- /dev/null +++ b/src/server/packets/GetSpringRecoverDataCsReq.ts @@ -0,0 +1,20 @@ +import { GetSpringRecoverDataCsReq, GetSpringRecoverDataScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetSpringRecoverDataCsReq; + + session.send("GetSpringRecoverDataScRsp", { + retcode: 0, + healPoolInfo: { + healPool: 0, + refreshTime: 600, + }, + springRecoverConfig: { + autoRecoverHp: true, + defaultHp: 100, + avatarPresetHpList: [] + } + } as GetSpringRecoverDataScRsp); +} \ No newline at end of file diff --git a/src/server/packets/PlayerKeepAliveNotify.ts b/src/server/packets/PlayerKeepAliveNotify.ts new file mode 100644 index 0000000..046ac41 --- /dev/null +++ b/src/server/packets/PlayerKeepAliveNotify.ts @@ -0,0 +1,9 @@ +import { PlayerKeepAliveNotify } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as PlayerKeepAliveNotify; + + // We actually don't need to handle this +} \ No newline at end of file diff --git a/src/server/packets/SyncTimeCsReq.ts b/src/server/packets/SyncTimeCsReq.ts new file mode 100644 index 0000000..87055ab --- /dev/null +++ b/src/server/packets/SyncTimeCsReq.ts @@ -0,0 +1,13 @@ +import { SyncTimeCsReq, SyncTimeScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as SyncTimeCsReq; + + session.send("SyncTimeScRsp", { + retcode: 0, + clientTimeMs: body.clientTimeMs, + serverTimeMs: Math.round(new Date().getTime() / 1000).toString() + } as unknown as SyncTimeScRsp); +} \ No newline at end of file From 69b014a71835cf539fc9dc1d923de096fb21a42a Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Sun, 31 Jul 2022 18:17:54 +0200 Subject: [PATCH 2/4] hardcoded login + kick command --- src/commands/Interface.ts | 3 ++ src/commands/kick.ts | 26 ++++++++++ src/commands/target.ts | 36 +++++++++++++ src/server/packets/FinishTalkMissionCsReq.ts | 12 +++++ src/server/packets/GetAvatarDataCsReq.ts | 20 ++++---- src/server/packets/GetCurBattleInfoCsReq.ts | 22 ++++---- src/server/packets/GetCurLineupDataCsReq.ts | 15 ++++-- .../packets/GetHeroBasicTypeInfoCsReq.ts | 11 +--- src/server/packets/GetHeroPathCsReq.ts | 6 +-- src/server/packets/GetLoginActivityCsReq.ts | 6 +-- src/server/packets/GetMissionStatusCsReq.ts | 26 ++++++++-- src/server/packets/GetRogueInfoCsReq.ts | 15 +++++- src/server/packets/PlayerLoginCsReq.ts | 14 ++--- src/server/packets/PlayerLogoutCsReq.ts | 8 +++ src/server/packets/SyncTimeCsReq.ts | 4 +- src/util/stringSimilarity.ts | 51 +++++++++++++++++++ 16 files changed, 217 insertions(+), 58 deletions(-) create mode 100644 src/commands/kick.ts create mode 100644 src/commands/target.ts create mode 100644 src/server/packets/FinishTalkMissionCsReq.ts create mode 100644 src/server/packets/PlayerLogoutCsReq.ts create mode 100644 src/util/stringSimilarity.ts diff --git a/src/commands/Interface.ts b/src/commands/Interface.ts index 3837f6e..fab8d2c 100644 --- a/src/commands/Interface.ts +++ b/src/commands/Interface.ts @@ -1,6 +1,7 @@ import { createInterface } from 'readline'; import _alias from './alias.json'; import Logger from '../util/Logger'; +import Session from '../server/kcp/Session'; const c = new Logger("Command", "blue"); const alias: { [key: string]: string } = _alias; @@ -22,6 +23,8 @@ export default class Interface { output: process.stdout }); + public static target: Session; + private constructor() { } public static readonly start = () => { diff --git a/src/commands/kick.ts b/src/commands/kick.ts new file mode 100644 index 0000000..bc41889 --- /dev/null +++ b/src/commands/kick.ts @@ -0,0 +1,26 @@ +import { BlackLimitLevel, PlayerKickOutScNotify, PlayerKickOutScNotify_KickType } from "../data/proto/StarRail"; +import SRServer from "../server/kcp/SRServer"; +import Logger from "../util/Logger"; +import Interface, { Command } from "./Interface"; +const c = new Logger("/kick", "blue"); + +export default async function handle(command: Command) { + if (!Interface.target) { + c.log("No target specified"); + return; + } + + Interface.target.send("PlayerKickOutScNotify", { + kickType: PlayerKickOutScNotify_KickType.KICK_BLACK, + blackInfo: { + limitLevel: BlackLimitLevel.BLACK_LIMIT_LEVEL_ALL, + beginTime: Math.round(Date.now() / 1000), + endTime: Math.round(Date.now() / 1000), + banType: 2 + } + } as PlayerKickOutScNotify); + + // SRServer.getInstance().sessions.delete(`${Interface.target.ctx.address}:${Interface.target.ctx.port}`); + + c.log(`Kicked ${Interface.target.account.name}`); +} \ No newline at end of file diff --git a/src/commands/target.ts b/src/commands/target.ts new file mode 100644 index 0000000..65fe303 --- /dev/null +++ b/src/commands/target.ts @@ -0,0 +1,36 @@ +import Logger from "../util/Logger"; +import Interface, { Command } from "./Interface"; +import findBestMatch from "../util/stringSimilarity"; +import SRServer from "../server/kcp/SRServer"; +import Session from "../server/kcp/Session"; +const c = new Logger("/target", "blue"); + +export default async function handle(command: Command) { + const target = command.args[0]; + const possibleTargets: { + id: string; + session: Session; + uid: number; + }[] = []; + + SRServer.getInstance().sessions.forEach(client => { + possibleTargets.push({ + id: `${client.ctx.address}:${client.ctx.port}`, + uid: Number(client.account.uid), + session: client + }); + }); + + if (!target) { + c.log("No target specified"); + c.log("Possible targets: "); + possibleTargets.forEach(x => c.trail(`${x.id} (UID: ${x.uid})`)); + return; + } + + const autoTarget = findBestMatch(target, possibleTargets.map(x => x.id)).bestMatch.target; + + Interface.target = possibleTargets.find(x => x.id === autoTarget)!.session; + + c.log(`Target set to ${autoTarget}`); +} \ No newline at end of file diff --git a/src/server/packets/FinishTalkMissionCsReq.ts b/src/server/packets/FinishTalkMissionCsReq.ts new file mode 100644 index 0000000..157924b --- /dev/null +++ b/src/server/packets/FinishTalkMissionCsReq.ts @@ -0,0 +1,12 @@ +import { FinishTalkMissionCsReq, FinishTalkMissionScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as FinishTalkMissionCsReq; + + session.send("FinishTalkMissionScRsp", { + retcode: 0, + talkStr: body.talkStr + } as FinishTalkMissionScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetAvatarDataCsReq.ts b/src/server/packets/GetAvatarDataCsReq.ts index d856e4f..22cbc98 100644 --- a/src/server/packets/GetAvatarDataCsReq.ts +++ b/src/server/packets/GetAvatarDataCsReq.ts @@ -9,22 +9,20 @@ export default async function handle(session: Session, packet: Packet) { const dataObj = { retcode: 0, avatarList: [{ - - }], - isAll: false - } as GetAvatarDataScRsp; - - Object.values(AvatarExcelTable).forEach(avatar => { - dataObj.avatarList.push({ - baseAvatarId: avatar.AvatarID, + baseAvatarId: 1001, equipmentUniqueId: 13501, equipRelicList: [], exp: 0, level: 1, promotion: 1, - rank: 100101, - skilltreeList: avatar.SkillList.map(skill => ({level: 1, pointId: skill})), - }) + rank: 1, + skilltreeList: [], + }], + isAll: body.isGetAll + } as GetAvatarDataScRsp; + + Object.values(AvatarExcelTable).forEach(avatar => { + // dataObj.avatarList.push() }); session.send("GetAvatarDataScRsp", dataObj); diff --git a/src/server/packets/GetCurBattleInfoCsReq.ts b/src/server/packets/GetCurBattleInfoCsReq.ts index b550b40..525ab5b 100644 --- a/src/server/packets/GetCurBattleInfoCsReq.ts +++ b/src/server/packets/GetCurBattleInfoCsReq.ts @@ -1,4 +1,4 @@ -import { AvatarType, GetCurBattleInfoCsReq, GetCurBattleInfoScRsp } from "../../data/proto/StarRail"; +import { AvatarType, BattleEndStatus, GetCurBattleInfoCsReq, GetCurBattleInfoScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; @@ -8,19 +8,19 @@ export default async function handle(session: Session, packet: Packet) { session.send("GetCurBattleInfoScRsp", { retcode: 0, avatarList: [{ - avatarType: AvatarType.AVATAR_TRIAL_TYPE, - hp: 1000, + avatarType: AvatarType.AVATAR_FORMAL_TYPE, id: 1001, - index: 1, - sp: 100, level: 1, + rank: 1, + index: 1, + hp: 100, + sp: 100, promotion: 1, - rank: 100101, - equipmentList: [], - relicList: [], - skilltreeList: [100101] }], stageId: 10000, - logicRandomSeed: 2503 - } as unknown as GetCurBattleInfoScRsp); + logicRandomSeed: 2503, + battleInfo: {}, + lastEndStatus: BattleEndStatus.BATTLE_END_WIN, + lastEventId: 0 + } as GetCurBattleInfoScRsp); } \ No newline at end of file diff --git a/src/server/packets/GetCurLineupDataCsReq.ts b/src/server/packets/GetCurLineupDataCsReq.ts index e71e08a..16cc498 100644 --- a/src/server/packets/GetCurLineupDataCsReq.ts +++ b/src/server/packets/GetCurLineupDataCsReq.ts @@ -1,4 +1,4 @@ -import { GetCurLineupDataCsReq, GetCurLineupDataScRsp } from "../../data/proto/StarRail"; +import { AvatarSlotType, AvatarType, GetCurLineupDataCsReq, GetCurLineupDataScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; @@ -8,13 +8,20 @@ export default async function handle(session: Session, packet: Packet) { session.send("GetCurLineupDataScRsp", { retcode: 0, lineup: { - avatarList: [1001, 1002], + avatarList: [{ + slot: 1, + avatarType: AvatarType.AVATAR_FORMAL_TYPE, + id: 1001, + hp: 100, + sp: 100, + satiety: 100 + }], index: 1, isVirtual: false, mp: 100, name: "lineuprspname", planeId: 10000, - leaderSlot: 1, + leaderSlot: 1 } - } as unknown as GetCurLineupDataScRsp); + } as GetCurLineupDataScRsp); } \ No newline at end of file diff --git a/src/server/packets/GetHeroBasicTypeInfoCsReq.ts b/src/server/packets/GetHeroBasicTypeInfoCsReq.ts index 5a0f84a..d704930 100644 --- a/src/server/packets/GetHeroBasicTypeInfoCsReq.ts +++ b/src/server/packets/GetHeroBasicTypeInfoCsReq.ts @@ -11,17 +11,10 @@ export default async function handle(session: Session, packet: Packet) { basicTypeInfoList: [{ basicType: HeroBasicType.BoyMage, rank: 1, - skillTreeList: [{ - level: 1, - pointId: 1 - }] + skillTreeList: [] }], curBasicType: HeroBasicType.BoyMage, - heroPathList: [{ - exp: 0, - level: 1, - heroPathType: 1 - }], + heroPathList: [], isPlayerInfoModified: false, isGenderModified: false } as GetHeroBasicTypeInfoScRsp); diff --git a/src/server/packets/GetHeroPathCsReq.ts b/src/server/packets/GetHeroPathCsReq.ts index e112adc..d27b668 100644 --- a/src/server/packets/GetHeroPathCsReq.ts +++ b/src/server/packets/GetHeroPathCsReq.ts @@ -7,10 +7,6 @@ export default async function handle(session: Session, packet: Packet) { session.send("GetHeroPathScRsp", { retcode: 0, - heroPathList: [{ - exp: 0, - level: 1, - heroPathType: 1 - }] + heroPathList: [] } as GetHeroPathScRsp); } \ No newline at end of file diff --git a/src/server/packets/GetLoginActivityCsReq.ts b/src/server/packets/GetLoginActivityCsReq.ts index 8443825..d9b16f7 100644 --- a/src/server/packets/GetLoginActivityCsReq.ts +++ b/src/server/packets/GetLoginActivityCsReq.ts @@ -7,10 +7,6 @@ export default async function handle(session: Session, packet: Packet) { session.send("GetLoginActivityScRsp", { retcode: 0, - loginActivityList: [{ - hasTakenLoginActivityRewardDaysList: [], - id: 1000, - loginDays: 1, - }] + loginActivityList: [] } as GetLoginActivityScRsp); } \ No newline at end of file diff --git a/src/server/packets/GetMissionStatusCsReq.ts b/src/server/packets/GetMissionStatusCsReq.ts index ce8bc56..6a99fc3 100644 --- a/src/server/packets/GetMissionStatusCsReq.ts +++ b/src/server/packets/GetMissionStatusCsReq.ts @@ -1,15 +1,35 @@ -import { GetMissionStatusCsReq, GetMissionStatusScRsp } from "../../data/proto/StarRail"; +import { GetMissionStatusCsReq, GetMissionStatusScRsp, MissionStatus } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { const body = packet.body as GetMissionStatusCsReq; - session.send("GetMissionStatusScRsp", { + const dataObj = { retcode: 0, finishedMainMissionIdList: [], missionEventStatusList: [], subMissionStatusList: [], unfinishedMainMissionIdList: [] - } as GetMissionStatusScRsp); + } as GetMissionStatusScRsp; + + body.mainMissionIdList.forEach(id => { dataObj.unfinishedMainMissionIdList.push(id); }); + + body.missionEventIdList.forEach(id => { + dataObj.missionEventStatusList.push({ + id: id, + progress: 0, + status: MissionStatus.MISSION_DOING + }); + }); + + body.subMissionIdList.forEach(id => { + dataObj.subMissionStatusList.push({ + id: id, + progress: 0, + status: MissionStatus.MISSION_DOING + }); + }); + + session.send("GetMissionStatusScRsp", dataObj); } \ No newline at end of file diff --git a/src/server/packets/GetRogueInfoCsReq.ts b/src/server/packets/GetRogueInfoCsReq.ts index 1224f0a..a360eec 100644 --- a/src/server/packets/GetRogueInfoCsReq.ts +++ b/src/server/packets/GetRogueInfoCsReq.ts @@ -1,4 +1,4 @@ -import { GetRogueInfoCsReq, GetRogueInfoScRsp } from "../../data/proto/StarRail"; +import { GetRogueInfoCsReq, GetRogueInfoScRsp, RogueStatus } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; @@ -7,6 +7,17 @@ export default async function handle(session: Session, packet: Packet) { session.send("GetRogueInfoScRsp", { retcode: 0, - + rogueInfo: { + status: RogueStatus.ROGUE_STATUS_DOING, + rogueCoin: 1, + baseAvatarIdList: [1001], + rogueStamina: 100, + reviveCount: 1, + recoverStaminaCount: 1, + isRecordSaved: true, + beginTime: Math.round(Date.now() / 1000), + endTime: Math.round(Date.now() / 1000) + 3600, + isWin: true, + } } as GetRogueInfoScRsp); } \ No newline at end of file diff --git a/src/server/packets/PlayerLoginCsReq.ts b/src/server/packets/PlayerLoginCsReq.ts index 121035d..7c421ad 100644 --- a/src/server/packets/PlayerLoginCsReq.ts +++ b/src/server/packets/PlayerLoginCsReq.ts @@ -1,4 +1,4 @@ -import { PlayerLoginCsReq, PlayerLoginScRsp } from "../../data/proto/StarRail"; +import { PlayerBasicInfo, PlayerLoginCsReq, PlayerLoginScRsp } from "../../data/proto/StarRail"; import Player from "../../db/Player"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; @@ -37,10 +37,12 @@ export default async function handle(session: Session, packet: Packet) { } session.send("PlayerLoginScRsp", { - basicInfo: plr!.db.basicInfo, - isNewPlayer: true, + basicInfo: plr!.db.basicInfo as PlayerBasicInfo, + isNewPlayer: false, stamina: 100, - curTimezone: body.clientTimeZone, - serverTimestampMs: Math.round(new Date().getTime() / 1000).toString(), - } as unknown as PlayerLoginScRsp); + retcode: 0, + isRelay: false, + loginRandom: Number(body.loginRandom), + serverTimestampMs: Math.round(new Date().getTime() / 1000), + } as PlayerLoginScRsp); } \ No newline at end of file diff --git a/src/server/packets/PlayerLogoutCsReq.ts b/src/server/packets/PlayerLogoutCsReq.ts new file mode 100644 index 0000000..8200668 --- /dev/null +++ b/src/server/packets/PlayerLogoutCsReq.ts @@ -0,0 +1,8 @@ +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; +import SRServer from "../kcp/SRServer"; + +export default async function handle(session: Session, packet: Packet) { + // Remove from session list + SRServer.getInstance().sessions.delete(`${session.ctx.address}:${session.ctx.port}`); +} \ No newline at end of file diff --git a/src/server/packets/SyncTimeCsReq.ts b/src/server/packets/SyncTimeCsReq.ts index 87055ab..7f90072 100644 --- a/src/server/packets/SyncTimeCsReq.ts +++ b/src/server/packets/SyncTimeCsReq.ts @@ -8,6 +8,6 @@ export default async function handle(session: Session, packet: Packet) { session.send("SyncTimeScRsp", { retcode: 0, clientTimeMs: body.clientTimeMs, - serverTimeMs: Math.round(new Date().getTime() / 1000).toString() - } as unknown as SyncTimeScRsp); + serverTimeMs: Math.round(new Date().getTime() / 1000) + } as SyncTimeScRsp); } \ No newline at end of file diff --git a/src/util/stringSimilarity.ts b/src/util/stringSimilarity.ts new file mode 100644 index 0000000..28aa525 --- /dev/null +++ b/src/util/stringSimilarity.ts @@ -0,0 +1,51 @@ +export function compareTwoStrings(first: string, second: string) { + first = first.replace(/\s+/g, '') + second = second.replace(/\s+/g, '') + + if (first === second) return 1; // identical or empty + if (first.length < 2 || second.length < 2) return 0; // if either is a 0-letter or 1-letter string + + let firstBigrams = new Map(); + for (let i = 0; i < first.length - 1; i++) { + const bigram = first.substring(i, i + 2); + const count = firstBigrams.has(bigram) + ? firstBigrams.get(bigram) + 1 + : 1; + + firstBigrams.set(bigram, count); + }; + + let intersectionSize = 0; + for (let i = 0; i < second.length - 1; i++) { + const bigram = second.substring(i, i + 2); + const count = firstBigrams.has(bigram) + ? firstBigrams.get(bigram) + : 0; + + if (count > 0) { + firstBigrams.set(bigram, count - 1); + intersectionSize++; + } + } + + return (2.0 * intersectionSize) / (first.length + second.length - 2); +} + +export default function findBestMatch(mainString: string, targetStrings: string[]) { + const ratings = []; + let bestMatchIndex = 0; + + for (let i = 0; i < targetStrings.length; i++) { + const currentTargetString = targetStrings[i]; + const currentRating = compareTwoStrings(mainString, currentTargetString) + ratings.push({ target: currentTargetString, rating: currentRating }) + if (currentRating > ratings[bestMatchIndex].rating) { + bestMatchIndex = i + } + } + + + const bestMatch = ratings[bestMatchIndex] + + return { ratings: ratings, bestMatch: bestMatch, bestMatchIndex: bestMatchIndex }; +} \ No newline at end of file From a8df503907badebe94c602f3aad73b8e7bd46347 Mon Sep 17 00:00:00 2001 From: codefactor-io Date: Sun, 31 Jul 2022 16:20:46 +0000 Subject: [PATCH 3/4] [CodeFactor] Apply fixes [ci skip] [skip ci] --- src/util/stringSimilarity.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/stringSimilarity.ts b/src/util/stringSimilarity.ts index 28aa525..83b5b9f 100644 --- a/src/util/stringSimilarity.ts +++ b/src/util/stringSimilarity.ts @@ -5,7 +5,7 @@ export function compareTwoStrings(first: string, second: string) { if (first === second) return 1; // identical or empty if (first.length < 2 || second.length < 2) return 0; // if either is a 0-letter or 1-letter string - let firstBigrams = new Map(); + const firstBigrams = new Map(); for (let i = 0; i < first.length - 1; i++) { const bigram = first.substring(i, i + 2); const count = firstBigrams.has(bigram) @@ -13,7 +13,7 @@ export function compareTwoStrings(first: string, second: string) { : 1; firstBigrams.set(bigram, count); - }; + } let intersectionSize = 0; for (let i = 0; i < second.length - 1; i++) { From f5d5808ca9f57d17d946f52a881af480069b801a Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Sun, 31 Jul 2022 18:29:57 +0200 Subject: [PATCH 4/4] fix more factoring issues --- src/db/Database.ts | 6 +++--- src/server/packets/GetAllLineupDataCsReq.ts | 4 +--- src/server/packets/GetAvatarDataCsReq.ts | 2 +- src/server/packets/GetBagCsReq.ts | 4 +--- src/server/packets/GetBasicInfoCsReq.ts | 4 +--- src/server/packets/GetChallengeCsReq.ts | 4 +--- src/server/packets/GetChallengeRaidInfoCsReq.ts | 4 +--- src/server/packets/GetCurBattleInfoCsReq.ts | 4 +--- src/server/packets/GetCurLineupDataCsReq.ts | 4 +--- src/server/packets/GetCurSceneInfoCsReq.ts | 4 +--- src/server/packets/GetDialogueEventDataCsReq.ts | 4 +--- src/server/packets/GetExpeditionDataCsReq.ts | 4 +--- src/server/packets/GetFirstTalkNpcCsReq.ts | 4 +--- src/server/packets/GetHeroBasicTypeInfoCsReq.ts | 4 +--- src/server/packets/GetHeroPathCsReq.ts | 4 +--- src/server/packets/GetLevelRewardTakenListCsReq.ts | 4 +--- src/server/packets/GetLoginActivityCsReq.ts | 4 +--- src/server/packets/GetMailCsReq.ts | 4 +--- src/server/packets/GetMazeTimeOfDayCsReq.ts | 4 +--- src/server/packets/GetMissionDataCsReq.ts | 4 +--- src/server/packets/GetMissionEventDataCsReq.ts | 4 +--- src/server/packets/GetNpcStatusCsReq.ts | 4 +--- src/server/packets/GetQuestDataCsReq.ts | 4 +--- src/server/packets/GetRogueInfoCsReq.ts | 4 +--- src/server/packets/GetSpringRecoverDataCsReq.ts | 4 +--- src/server/packets/PlayerKeepAliveNotify.ts | 3 --- 26 files changed, 27 insertions(+), 76 deletions(-) diff --git a/src/db/Database.ts b/src/db/Database.ts index 00cd847..34aeb04 100644 --- a/src/db/Database.ts +++ b/src/db/Database.ts @@ -22,7 +22,7 @@ export default class Database { return Database.instance; } - public async get(collection: string, query?: {}) { + public async get(collection: string, query?: object) { try { const db = await Database.client.db(); const _collection = db.collection(collection); @@ -52,7 +52,7 @@ export default class Database { } } - public async delete(collection: string, query: {}) { + public async delete(collection: string, query: object) { try { const db = await Database.client.db(); const _collection = db.collection(collection); @@ -66,7 +66,7 @@ export default class Database { } } - public async update(collection: string, query: {}, payload: {}) { + public async update(collection: string, query: object, payload: object) { try { const db = await Database.client.db(); const _collection = db.collection(collection); diff --git a/src/server/packets/GetAllLineupDataCsReq.ts b/src/server/packets/GetAllLineupDataCsReq.ts index 22fc5f5..734d2f1 100644 --- a/src/server/packets/GetAllLineupDataCsReq.ts +++ b/src/server/packets/GetAllLineupDataCsReq.ts @@ -1,10 +1,8 @@ -import { GetAllLineupDataCsReq, GetAllLineupDataScRsp } from "../../data/proto/StarRail"; +import { GetAllLineupDataScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetAllLineupDataCsReq; - session.send("GetAllLineupDataScRsp", { retcode: 0, lineupList: [] diff --git a/src/server/packets/GetAvatarDataCsReq.ts b/src/server/packets/GetAvatarDataCsReq.ts index 22cbc98..adfdceb 100644 --- a/src/server/packets/GetAvatarDataCsReq.ts +++ b/src/server/packets/GetAvatarDataCsReq.ts @@ -1,4 +1,4 @@ -import { ActivateFarmElementCsReq, GetAvatarDataCsReq, GetAvatarDataScRsp } from "../../data/proto/StarRail"; +import { GetAvatarDataCsReq, GetAvatarDataScRsp } from "../../data/proto/StarRail"; import AvatarExcelTable from "../../data/excel/AvatarExcelTable.json"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; diff --git a/src/server/packets/GetBagCsReq.ts b/src/server/packets/GetBagCsReq.ts index 9c1ad85..08c1914 100644 --- a/src/server/packets/GetBagCsReq.ts +++ b/src/server/packets/GetBagCsReq.ts @@ -1,10 +1,8 @@ -import { GetBagCsReq, GetBagScRsp } from "../../data/proto/StarRail"; +import { GetBagScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetBagCsReq; - session.send("GetBagScRsp", { equipmentList: [], materialList: [], diff --git a/src/server/packets/GetBasicInfoCsReq.ts b/src/server/packets/GetBasicInfoCsReq.ts index a83f0bb..471f0f6 100644 --- a/src/server/packets/GetBasicInfoCsReq.ts +++ b/src/server/packets/GetBasicInfoCsReq.ts @@ -1,10 +1,8 @@ -import { GetBasicInfoCsReq, GetBasicInfoScRsp } from "../../data/proto/StarRail"; +import { GetBasicInfoScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetBasicInfoCsReq; - session.send("GetBasicInfoScRsp", { curDay: 1, exchangeTimes: 0, diff --git a/src/server/packets/GetChallengeCsReq.ts b/src/server/packets/GetChallengeCsReq.ts index 325d044..901b438 100644 --- a/src/server/packets/GetChallengeCsReq.ts +++ b/src/server/packets/GetChallengeCsReq.ts @@ -1,10 +1,8 @@ -import { GetChallengeCsReq, GetChallengeScRsp } from "../../data/proto/StarRail"; +import { GetChallengeScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetChallengeCsReq; - session.send("GetChallengeScRsp", { retcode: 0, challengeList: [] diff --git a/src/server/packets/GetChallengeRaidInfoCsReq.ts b/src/server/packets/GetChallengeRaidInfoCsReq.ts index d3bad49..7f8c02b 100644 --- a/src/server/packets/GetChallengeRaidInfoCsReq.ts +++ b/src/server/packets/GetChallengeRaidInfoCsReq.ts @@ -1,10 +1,8 @@ -import { GetChallengeRaidInfoCsReq, GetChallengeRaidInfoScRsp } from "../../data/proto/StarRail"; +import { GetChallengeRaidInfoScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetChallengeRaidInfoCsReq; - session.send("GetChallengeRaidInfoScRsp", { retcode: 0, challengeRaidList: [], diff --git a/src/server/packets/GetCurBattleInfoCsReq.ts b/src/server/packets/GetCurBattleInfoCsReq.ts index 525ab5b..15dc9d4 100644 --- a/src/server/packets/GetCurBattleInfoCsReq.ts +++ b/src/server/packets/GetCurBattleInfoCsReq.ts @@ -1,10 +1,8 @@ -import { AvatarType, BattleEndStatus, GetCurBattleInfoCsReq, GetCurBattleInfoScRsp } from "../../data/proto/StarRail"; +import { AvatarType, BattleEndStatus, GetCurBattleInfoScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetCurBattleInfoCsReq; - session.send("GetCurBattleInfoScRsp", { retcode: 0, avatarList: [{ diff --git a/src/server/packets/GetCurLineupDataCsReq.ts b/src/server/packets/GetCurLineupDataCsReq.ts index 16cc498..7f1a6e4 100644 --- a/src/server/packets/GetCurLineupDataCsReq.ts +++ b/src/server/packets/GetCurLineupDataCsReq.ts @@ -1,10 +1,8 @@ -import { AvatarSlotType, AvatarType, GetCurLineupDataCsReq, GetCurLineupDataScRsp } from "../../data/proto/StarRail"; +import { AvatarType, GetCurLineupDataCsReq, GetCurLineupDataScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetCurLineupDataCsReq; - session.send("GetCurLineupDataScRsp", { retcode: 0, lineup: { diff --git a/src/server/packets/GetCurSceneInfoCsReq.ts b/src/server/packets/GetCurSceneInfoCsReq.ts index 4891d8a..ae5b40f 100644 --- a/src/server/packets/GetCurSceneInfoCsReq.ts +++ b/src/server/packets/GetCurSceneInfoCsReq.ts @@ -1,10 +1,8 @@ -import { GetCurSceneInfoCsReq, GetCurSceneInfoScRsp } from "../../data/proto/StarRail"; +import { GetCurSceneInfoScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetCurSceneInfoCsReq; - session.send("GetCurSceneInfoScRsp", { retcode: 0, scene: { diff --git a/src/server/packets/GetDialogueEventDataCsReq.ts b/src/server/packets/GetDialogueEventDataCsReq.ts index 15eb14f..0af2e98 100644 --- a/src/server/packets/GetDialogueEventDataCsReq.ts +++ b/src/server/packets/GetDialogueEventDataCsReq.ts @@ -1,10 +1,8 @@ -import { GetDialogueEventDataCsReq, GetDialogueEventDataScRsp } from "../../data/proto/StarRail"; +import { GetDialogueEventDataScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetDialogueEventDataCsReq; - session.send("GetDialogueEventDataScRsp", { dialogueEventList: [], retcode: 0 diff --git a/src/server/packets/GetExpeditionDataCsReq.ts b/src/server/packets/GetExpeditionDataCsReq.ts index 2a2e532..a2b23ca 100644 --- a/src/server/packets/GetExpeditionDataCsReq.ts +++ b/src/server/packets/GetExpeditionDataCsReq.ts @@ -1,10 +1,8 @@ -import { GetExpeditionDataCsReq, GetExpeditionDataScRsp } from "../../data/proto/StarRail"; +import { GetExpeditionDataScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetExpeditionDataCsReq; - session.send("GetExpeditionDataScRsp", { retcode: 0, expedtionList: [], diff --git a/src/server/packets/GetFirstTalkNpcCsReq.ts b/src/server/packets/GetFirstTalkNpcCsReq.ts index 73dd33f..efa2624 100644 --- a/src/server/packets/GetFirstTalkNpcCsReq.ts +++ b/src/server/packets/GetFirstTalkNpcCsReq.ts @@ -1,10 +1,8 @@ -import { GetFirstTalkNpcCsReq, GetFirstTalkNpcScRsp } from "../../data/proto/StarRail"; +import { GetFirstTalkNpcScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetFirstTalkNpcCsReq; - session.send("GetFirstTalkNpcScRsp", { retcode: 0, } as GetFirstTalkNpcScRsp); diff --git a/src/server/packets/GetHeroBasicTypeInfoCsReq.ts b/src/server/packets/GetHeroBasicTypeInfoCsReq.ts index d704930..91fb2da 100644 --- a/src/server/packets/GetHeroBasicTypeInfoCsReq.ts +++ b/src/server/packets/GetHeroBasicTypeInfoCsReq.ts @@ -1,10 +1,8 @@ -import { Gender, GetHeroBasicTypeInfoCsReq, GetHeroBasicTypeInfoScRsp, HeroBasicType } from "../../data/proto/StarRail"; +import { Gender, GetHeroBasicTypeInfoScRsp, HeroBasicType } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetHeroBasicTypeInfoCsReq; - session.send("GetHeroBasicTypeInfoScRsp", { retcode: 0, gender: Gender.GenderMan, diff --git a/src/server/packets/GetHeroPathCsReq.ts b/src/server/packets/GetHeroPathCsReq.ts index d27b668..950fa71 100644 --- a/src/server/packets/GetHeroPathCsReq.ts +++ b/src/server/packets/GetHeroPathCsReq.ts @@ -1,10 +1,8 @@ -import { GetHeroPathCsReq, GetHeroPathScRsp } from "../../data/proto/StarRail"; +import { GetHeroPathScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetHeroPathCsReq; - session.send("GetHeroPathScRsp", { retcode: 0, heroPathList: [] diff --git a/src/server/packets/GetLevelRewardTakenListCsReq.ts b/src/server/packets/GetLevelRewardTakenListCsReq.ts index aefb117..766e8b5 100644 --- a/src/server/packets/GetLevelRewardTakenListCsReq.ts +++ b/src/server/packets/GetLevelRewardTakenListCsReq.ts @@ -1,10 +1,8 @@ -import { GetLevelRewardTakenListCsReq, GetLevelRewardTakenListScRsp } from "../../data/proto/StarRail"; +import { GetLevelRewardTakenListScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetLevelRewardTakenListCsReq; - session.send("GetLevelRewardTakenListScRsp", { retcode: 0, takenLevelList: [] diff --git a/src/server/packets/GetLoginActivityCsReq.ts b/src/server/packets/GetLoginActivityCsReq.ts index d9b16f7..fa920ca 100644 --- a/src/server/packets/GetLoginActivityCsReq.ts +++ b/src/server/packets/GetLoginActivityCsReq.ts @@ -1,10 +1,8 @@ -import { GetLoginActivityCsReq, GetLoginActivityScRsp } from "../../data/proto/StarRail"; +import { GetLoginActivityScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetLoginActivityCsReq; - session.send("GetLoginActivityScRsp", { retcode: 0, loginActivityList: [] diff --git a/src/server/packets/GetMailCsReq.ts b/src/server/packets/GetMailCsReq.ts index 40b9cb3..13f4a7d 100644 --- a/src/server/packets/GetMailCsReq.ts +++ b/src/server/packets/GetMailCsReq.ts @@ -1,10 +1,8 @@ -import { GetMailCsReq, GetMailScRsp } from "../../data/proto/StarRail"; +import { GetMailScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetMailCsReq; - session.send("GetMailScRsp", { retcode: 0, mailList: [], diff --git a/src/server/packets/GetMazeTimeOfDayCsReq.ts b/src/server/packets/GetMazeTimeOfDayCsReq.ts index 30bf2db..c76c2da 100644 --- a/src/server/packets/GetMazeTimeOfDayCsReq.ts +++ b/src/server/packets/GetMazeTimeOfDayCsReq.ts @@ -1,10 +1,8 @@ -import { GetMazeTimeOfDayCsReq, GetMazeTimeOfDayScRsp } from "../../data/proto/StarRail"; +import { GetMazeTimeOfDayScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetMazeTimeOfDayCsReq; - session.send("GetMazeTimeOfDayScRsp", { retcode: 0, mazeTimeOfDayMap: {} diff --git a/src/server/packets/GetMissionDataCsReq.ts b/src/server/packets/GetMissionDataCsReq.ts index 01507f8..93cae07 100644 --- a/src/server/packets/GetMissionDataCsReq.ts +++ b/src/server/packets/GetMissionDataCsReq.ts @@ -1,10 +1,8 @@ -import { GetMissionDataCsReq, GetMissionDataScRsp } from "../../data/proto/StarRail"; +import { GetMissionDataScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetMissionDataCsReq; - session.send("GetMissionDataScRsp", { retcode: 0, missionList: [] diff --git a/src/server/packets/GetMissionEventDataCsReq.ts b/src/server/packets/GetMissionEventDataCsReq.ts index 261e344..cf37c30 100644 --- a/src/server/packets/GetMissionEventDataCsReq.ts +++ b/src/server/packets/GetMissionEventDataCsReq.ts @@ -1,10 +1,8 @@ -import { GetMissionEventDataCsReq, GetMissionEventDataScRsp } from "../../data/proto/StarRail"; +import { GetMissionEventDataScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetMissionEventDataCsReq; - session.send("GetMissionEventDataScRsp", { retcode: 0, missionEventList: [] diff --git a/src/server/packets/GetNpcStatusCsReq.ts b/src/server/packets/GetNpcStatusCsReq.ts index d941df2..040538a 100644 --- a/src/server/packets/GetNpcStatusCsReq.ts +++ b/src/server/packets/GetNpcStatusCsReq.ts @@ -1,10 +1,8 @@ -import { GetNpcStatusCsReq, GetNpcStatusScRsp } from "../../data/proto/StarRail"; +import { GetNpcStatusScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetNpcStatusCsReq; - session.send("GetNpcStatusScRsp", { retcode: 0, messageStatusList: [] diff --git a/src/server/packets/GetQuestDataCsReq.ts b/src/server/packets/GetQuestDataCsReq.ts index 102deab..599a783 100644 --- a/src/server/packets/GetQuestDataCsReq.ts +++ b/src/server/packets/GetQuestDataCsReq.ts @@ -1,10 +1,8 @@ -import { GetQuestDataCsReq, GetQuestDataScRsp } from "../../data/proto/StarRail"; +import { GetQuestDataScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetQuestDataCsReq; - session.send("GetQuestDataScRsp", { questList: [], retcode: 0, diff --git a/src/server/packets/GetRogueInfoCsReq.ts b/src/server/packets/GetRogueInfoCsReq.ts index a360eec..7d17545 100644 --- a/src/server/packets/GetRogueInfoCsReq.ts +++ b/src/server/packets/GetRogueInfoCsReq.ts @@ -1,10 +1,8 @@ -import { GetRogueInfoCsReq, GetRogueInfoScRsp, RogueStatus } from "../../data/proto/StarRail"; +import { GetRogueInfoScRsp, RogueStatus } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetRogueInfoCsReq; - session.send("GetRogueInfoScRsp", { retcode: 0, rogueInfo: { diff --git a/src/server/packets/GetSpringRecoverDataCsReq.ts b/src/server/packets/GetSpringRecoverDataCsReq.ts index ede3959..75dd1c6 100644 --- a/src/server/packets/GetSpringRecoverDataCsReq.ts +++ b/src/server/packets/GetSpringRecoverDataCsReq.ts @@ -1,10 +1,8 @@ -import { GetSpringRecoverDataCsReq, GetSpringRecoverDataScRsp } from "../../data/proto/StarRail"; +import { GetSpringRecoverDataScRsp } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as GetSpringRecoverDataCsReq; - session.send("GetSpringRecoverDataScRsp", { retcode: 0, healPoolInfo: { diff --git a/src/server/packets/PlayerKeepAliveNotify.ts b/src/server/packets/PlayerKeepAliveNotify.ts index 046ac41..0916100 100644 --- a/src/server/packets/PlayerKeepAliveNotify.ts +++ b/src/server/packets/PlayerKeepAliveNotify.ts @@ -1,9 +1,6 @@ -import { PlayerKeepAliveNotify } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - const body = packet.body as PlayerKeepAliveNotify; - // We actually don't need to handle this } \ No newline at end of file