Basic login sequence

This commit is contained in:
memetrollsXD 2022-07-31 13:30:15 +02:00
parent f7bce82c44
commit 9b5ed65d47
No known key found for this signature in database
GPG Key ID: 105C2F3417AC32CD
32 changed files with 444 additions and 2 deletions

2
.gitignore vendored
View File

@ -106,4 +106,4 @@ dist
# CrepeSR
config.json
src/data/proto
src/data/*

View File

@ -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]})`);
}
}

View File

@ -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 {

View File

@ -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);
}
}
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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)
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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
}

View File

@ -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);
}