generic send :D

This commit is contained in:
TheLostTree 2022-08-02 23:52:03 -07:00
parent 4de62431db
commit e24ff7d25d
56 changed files with 92 additions and 86 deletions

View File

@ -32,7 +32,7 @@ export default async function handle(command: Command) {
return; return;
} }
const autoTarget = findBestMatch(target, possibleTargets.map(x => x.id)).bestMatch.target; const autoTarget = findBestMatch(target, possibleTargets.map(x => x.id))?.bestMatch.target;
Interface.target = possibleTargets.find(x => x.id === autoTarget)!.session; Interface.target = possibleTargets.find(x => x.id === autoTarget)!.session;

View File

@ -13,7 +13,7 @@ export class Scene {
public spawnEntity(entity: Entity, silent: boolean = false) { public spawnEntity(entity: Entity, silent: boolean = false) {
this.entities.set(entity.entityId, entity); this.entities.set(entity.entityId, entity);
if (!silent) { if (!silent) {
this.player.session.send("SceneEntityUpdateScNotify", { this.player.session.send(SceneEntityUpdateScNotify, {
entityList: [entity.getSceneEntityInfo()] entityList: [entity.getSceneEntityInfo()]
} as SceneEntityUpdateScNotify); } as SceneEntityUpdateScNotify);
} }
@ -22,7 +22,7 @@ export class Scene {
public despawnEntity(entityId: number, silent: boolean = false) { public despawnEntity(entityId: number, silent: boolean = false) {
this.entities.delete(entityId); this.entities.delete(entityId);
if (!silent) { if (!silent) {
this.player.session.send("SceneEntityDisappearScNotify", { this.player.session.send(SceneEntityDisappearScNotify, {
entityIdList: [entityId] entityIdList: [entityId]
} as SceneEntityDisappearScNotify); } as SceneEntityDisappearScNotify);
} }

View File

@ -12,8 +12,9 @@ import ProtoFactory from "./util/ProtoFactory"
const c = new Logger("CrepeSR"); const c = new Logger("CrepeSR");
c.log(`Starting CrepeSR...`); c.log(`Starting CrepeSR...`);
Banners.init(); Banners.init();
ProtoFactory.init(); ProtoFactory.init();
Interface.start(); Interface.start();
HttpServer.getInstance().start(); HttpServer.getInstance().start();
SRServer.getInstance().start(); SRServer.getInstance().start();

View File

@ -68,6 +68,20 @@ export default class Packet {
process.exit(1); process.exit(1);
} }
} }
public static fromEncodedBuffer(data: Buffer, name: PacketName): Buffer {
const cmdid = CmdID[name];
const packet = Buffer.allocUnsafe(16 + data.length);
packet.writeUInt32BE(0x1234567);
packet.writeUint16BE(cmdid, 4);
packet.writeUint16BE(0, 6);
packet.writeUint32BE(data.length, 8);
data.copy(packet, 12);
packet.writeUint32BE(0x89abcdef, 12 + data.length);
return packet;
}
} }
export type PacketName = keyof typeof CmdID; export type PacketName = keyof typeof CmdID;

View File

@ -80,32 +80,33 @@ export default class Session {
public async sync() { public async sync() {
const avatars = await Avatar.fromUID(this.player.db._id); const avatars = await Avatar.fromUID(this.player.db._id);
this.sendT(PlayerSyncScNotify, PlayerSyncScNotify.fromPartial({ this.send(PlayerSyncScNotify, PlayerSyncScNotify.fromPartial({
avatarSync: { avatarSync: {
avatarList: avatars.map(x => x.data), avatarList: avatars.map(x => x.data),
}, },
basicInfo: this.player.db.basicInfo basicInfo: this.player.db.basicInfo
})); }));
this.player.save(); //this.player.save();
} }
public async sendT<Class extends MessageType<any>, >(type: Class, data: UnWrapMessageType<Class>) { public async send<Class extends MessageType<any>, >(type: Class, data: UnWrapMessageType<Class>) {
const encodedBuffer = type.encode(data).finish();
const typeName = ProtoFactory.getName(type); const typeName = ProtoFactory.getName(type);
const encodedBuffer = type.encode(type.fromPartial(data)).finish();
const packet = Packet.fromEncodedBuffer(Buffer.from(encodedBuffer), typeName);
this.c.verbL(data); this.c.verbL(data);
this.c.verbH(encodedBuffer); this.c.verbH(encodedBuffer);
if(!encodedBuffer) console.log("sad!")
if (Logger.VERBOSE_LEVEL >= VerboseLevel.WARNS) this.c.log(typeName); if (Logger.VERBOSE_LEVEL >= VerboseLevel.WARNS) this.c.log(typeName);
//todo: might want to regen the ts-proto types with env = node //todo: might want to regen the ts-proto types with env = node
this.kcpobj.send(Buffer.from(encodedBuffer)); this.kcpobj.send(packet);
} }
public kick(hard: boolean = true) { public kick(hard: boolean = true) {
SRServer.getInstance().sessions.delete(this.id); SRServer.getInstance().sessions.delete(this.id);
this.kicked = true; this.kicked = true;
if (hard) this.sendT(PlayerKickOutScNotify, { if (hard) this.send(PlayerKickOutScNotify, {
kickType: PlayerKickOutScNotify_KickType.KICK_BLACK, kickType: PlayerKickOutScNotify_KickType.KICK_BLACK,
blackInfo: { blackInfo: {
limitLevel: BlackLimitLevel.BLACK_LIMIT_LEVEL_ALL, limitLevel: BlackLimitLevel.BLACK_LIMIT_LEVEL_ALL,
@ -119,21 +120,6 @@ export default class Session {
} }
/**
* @deprecated The method should not be used
* use sendT instead
*/
public send(name: PacketName, body: {}) {
this.c.verbL(body);
const packet = Packet.encode(name, body);
if (!packet) return;
this.c.verbH(packet.rawData);
if (Logger.VERBOSE_LEVEL >= VerboseLevel.WARNS) this.c.log(packet.protoName);
this.kcpobj.send(packet.rawData);
//i'll rename sendT to send once all instances are updated
this.c.warn("Session.send deprecated! migrate to Session.sendT");
}
public sendRaw(data: Buffer) { public sendRaw(data: Buffer) {
if (this.kicked) return; if (this.kicked) return;
this.kcpobj.send(data); this.kcpobj.send(data);

View File

@ -5,7 +5,7 @@ import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
const body = packet.body as ChangeLineupLeaderCsReq; const body = packet.body as ChangeLineupLeaderCsReq;
session.send("ChangeLineupLeaderScRsp", { session.send(ChangeLineupLeaderScRsp, {
retcode: 0, retcode: 0,
slot: body.slot slot: body.slot
} as ChangeLineupLeaderScRsp); } as ChangeLineupLeaderScRsp);

View File

@ -22,7 +22,7 @@ export default async function handle(session: Session, packet: Packet) {
isNew: true //TODO: avatar checking isNew: true //TODO: avatar checking
} as GachaItem); } as GachaItem);
} }
session.send("DoGachaScRsp", { session.send(DoGachaScRsp, {
retcode: 0, retcode: 0,
gachaId: body.gachaId!, gachaId: body.gachaId!,
gachaNum: body.gachaNum!, gachaNum: body.gachaNum!,

View File

@ -15,7 +15,7 @@ export default async function handle(session: Session, packet: Packet) {
session.player.db.posData.planeID = mazeEntry.PlaneID; session.player.db.posData.planeID = mazeEntry.PlaneID;
session.player.save(); session.player.save();
session.send("EnterMazeScRsp", { session.send(EnterMazeScRsp, {
retcode: 0, retcode: 0,
maze: { maze: {
floor: { floor: {

View File

@ -1,6 +1,7 @@
import { EnterSectionScRsp } from "../../data/proto/StarRail";
import Packet from "../kcp/Packet"; import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("EnterSectionScRsp", { retcode: 0 }); session.send(EnterSectionScRsp, { retcode: 0 });
} }

View File

@ -1,6 +1,7 @@
import { EntityBindPropScRsp } from "../../data/proto/StarRail";
import Packet from "../kcp/Packet"; import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("EntityBindPropScRsp", { retcode: 0 }); session.send(EntityBindPropScRsp, { retcode: 0 });
} }

View File

@ -5,7 +5,7 @@ import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
const body = packet.body as FinishTalkMissionCsReq; const body = packet.body as FinishTalkMissionCsReq;
session.send("FinishTalkMissionScRsp", { session.send(FinishTalkMissionScRsp, {
retcode: 0, retcode: 0,
talkStr: body.talkStr talkStr: body.talkStr
} as FinishTalkMissionScRsp); } as FinishTalkMissionScRsp);

View File

@ -14,5 +14,5 @@ export default async function handle(session: Session, packet: Packet) {
reward: { itemList: [] } reward: { itemList: [] }
} }
session.send("FinishTutorialGuideScRsp", dataObj); session.send(FinishTutorialGuideScRsp, dataObj);
} }

View File

@ -18,5 +18,5 @@ export default async function handle(session: Session, packet: Packet) {
lineupList lineupList
} as GetAllLineupDataScRsp; } as GetAllLineupDataScRsp;
session.send("GetAllLineupDataScRsp", dataObj); session.send(GetAllLineupDataScRsp, dataObj);
} }

View File

@ -2,22 +2,25 @@ import { GetAvatarDataCsReq, GetAvatarDataScRsp } from "../../data/proto/StarRai
import AvatarExcelTable from "../../data/excel/AvatarExcelTable.json"; import AvatarExcelTable from "../../data/excel/AvatarExcelTable.json";
import Packet from "../kcp/Packet"; import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
import Avatar from "../../db/Avatar"; import AvatarDb from "../../db/Avatar";
import { Avatar } from "../../data/proto/StarRail";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
const body = packet.body as GetAvatarDataCsReq; const body = packet.body as GetAvatarDataCsReq;
const avatar = await Avatar.fromUID(session.player.db._id); const avatar = await AvatarDb.fromUID(session.player.db._id);
console.log(avatar.length)
const dataObj = { const dataObj = {
retcode: 0, retcode: 0,
avatarList: avatar.map(av => av.data), avatarList: avatar.map(av => Avatar.fromPartial(av.data)),
isAll: body.isGetAll isAll: body.isGetAll
} as GetAvatarDataScRsp; };
Object.values(AvatarExcelTable).forEach(avatar => { Object.values(AvatarExcelTable).forEach(avatar => {
// dataObj.avatarList.push() // dataObj.avatarList.push()
}); });
session.send("GetAvatarDataScRsp", dataObj); session.send(GetAvatarDataScRsp, dataObj);
} }

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetBagScRsp", { session.send(GetBagScRsp, {
equipmentList: [], equipmentList: [],
materialList: [], materialList: [],
relicList: [], relicList: [],

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetBasicInfoScRsp", { session.send(GetBasicInfoScRsp, {
curDay: 1, curDay: 1,
exchangeTimes: 0, exchangeTimes: 0,
retcode: 0, retcode: 0,

View File

@ -19,5 +19,5 @@ export default async function handle(session: Session, packet: Packet) {
}); });
}); });
session.send("GetChallengeScRsp", dataObj); session.send(GetChallengeScRsp, dataObj);
} }

View File

@ -19,5 +19,5 @@ export default async function handle(session: Session, packet: Packet) {
}); });
}) })
session.send("GetChallengeRaidInfoScRsp", dataObj); session.send(GetChallengeRaidInfoScRsp, dataObj);
} }

View File

@ -5,7 +5,7 @@ import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
const lineup = await session.player.getLineup(); const lineup = await session.player.getLineup();
session.send("GetCurBattleInfoScRsp", { session.send(GetCurBattleInfoScRsp, {
retcode: 0, retcode: 0,
avatarList: lineup.avatarList.map(list => { avatarList: lineup.avatarList.map(list => {
return { return {

View File

@ -30,7 +30,7 @@ export default async function handle(session: Session, packet: Packet) {
session.player.save(); session.player.save();
} }
session.send("GetCurLineupDataScRsp", { session.send(GetCurLineupDataScRsp, {
retcode: 0, retcode: 0,
lineup: { lineup: {
...lineup, ...lineup,

View File

@ -8,7 +8,7 @@ export default async function handle(session: Session, packet: Packet) {
const _lineup = session.player.db.lineup; const _lineup = session.player.db.lineup;
const lineup = _lineup.lineups[_lineup.curIndex]; const lineup = _lineup.lineups[_lineup.curIndex];
const curAvatarEntity = new ActorEntity(session.player.scene, lineup.avatarList[0], posData.pos); const curAvatarEntity = new ActorEntity(session.player.scene, lineup.avatarList[0], posData.pos);
session.send("GetCurSceneInfoScRsp", { session.send(GetCurSceneInfoScRsp, {
retcode: 0, retcode: 0,
scene: { scene: {
planeId: posData.planeID, planeId: posData.planeID,

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetDialogueEventDataScRsp", { session.send(GetDialogueEventDataScRsp, {
dialogueEventList: [], dialogueEventList: [],
retcode: 0 retcode: 0
} as GetDialogueEventDataScRsp); } as GetDialogueEventDataScRsp);

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetExpeditionDataScRsp", { session.send(GetExpeditionDataScRsp, {
retcode: 0, retcode: 0,
expedtionList: [], expedtionList: [],
unlockedExpeditionIdList: [], unlockedExpeditionIdList: [],

View File

@ -19,5 +19,5 @@ export default async function handle(session: Session, packet: Packet) {
dataObj.npcMeetStatusList.push(meetStatusObj); dataObj.npcMeetStatusList.push(meetStatusObj);
}); });
session.send("GetFirstTalkNpcScRsp", dataObj); session.send(GetFirstTalkNpcScRsp, dataObj);
} }

View File

@ -4,7 +4,7 @@ import Session from "../kcp/Session";
import Banner from './../../util/Banner'; import Banner from './../../util/Banner';
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetGachaInfoScRsp", { session.send(GetGachaInfoScRsp, {
gachaRandom: 0, gachaRandom: 0,
retcode: 0, retcode: 0,
gachaInfoList: Banner.config.map(banner => { gachaInfoList: Banner.config.map(banner => {

View File

@ -5,7 +5,7 @@ import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
let gender: Gender = (session.player.db.heroBasicType % 2 === 0) ? Gender.GenderWoman : Gender.GenderMan; let gender: Gender = (session.player.db.heroBasicType % 2 === 0) ? Gender.GenderWoman : Gender.GenderMan;
session.send("GetHeroBasicTypeInfoScRsp", { session.send(GetHeroBasicTypeInfoScRsp, {
retcode: 0, retcode: 0,
gender: gender, gender: gender,
basicTypeInfoList: [{ basicTypeInfoList: [{

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetHeroPathScRsp", { session.send(GetHeroPathScRsp, {
retcode: 0, retcode: 0,
heroPathList: [] heroPathList: []
} as GetHeroPathScRsp); } as GetHeroPathScRsp);

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetLevelRewardTakenListScRsp", { session.send(GetLevelRewardTakenListScRsp, {
retcode: 0, retcode: 0,
takenLevelList: [] takenLevelList: []
} as GetLevelRewardTakenListScRsp); } as GetLevelRewardTakenListScRsp);

View File

@ -42,5 +42,5 @@ export default async function handle(session: Session, packet: Packet) {
}); });
} }
session.send("GetLineupAvatarDataScRsp", dataObj); session.send(GetLineupAvatarDataScRsp, dataObj);
} }

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetLoginActivityScRsp", { session.send(GetLoginActivityScRsp, {
retcode: 0, retcode: 0,
loginActivityList: [{ loginActivityList: [{
id: 1001, id: 1001,

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetMailScRsp", { session.send(GetMailScRsp, {
retcode: 0, retcode: 0,
mailList: [], mailList: [],
noticeMailList: [], noticeMailList: [],

View File

@ -26,5 +26,5 @@ export default async function handle(session: Session, packet: Packet) {
dataObj.unlockTeleportList = MazePlaneExcel.getAllEntries().map(x => x.ID); dataObj.unlockTeleportList = MazePlaneExcel.getAllEntries().map(x => x.ID);
session.send("GetMazeMapInfoScRsp", dataObj); session.send(GetMazeMapInfoScRsp, dataObj);
} }

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetMazeTimeOfDayScRsp", { session.send(GetMazeTimeOfDayScRsp, {
retcode: 0, retcode: 0,
mazeTimeOfDayMap: {} mazeTimeOfDayMap: {}
} as GetMazeTimeOfDayScRsp); } as GetMazeTimeOfDayScRsp);

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetMissionDataScRsp", { session.send(GetMissionDataScRsp, {
retcode: 0, retcode: 0,
missionList: [] missionList: []
} as GetMissionDataScRsp); } as GetMissionDataScRsp);

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetMissionEventDataScRsp", { session.send(GetMissionEventDataScRsp, {
retcode: 0, retcode: 0,
missionEventList: [] missionEventList: []
} as unknown as GetMissionEventDataScRsp); } as unknown as GetMissionEventDataScRsp);

View File

@ -54,5 +54,5 @@ export default async function handle(session: Session, packet: Packet) {
}); });
}); });
session.send("GetMissionStatusScRsp", dataObj); session.send(GetMissionStatusScRsp, dataObj);
} }

View File

@ -10,5 +10,5 @@ export default async function handle(session: Session, packet: Packet) {
messageGroupList: [], messageGroupList: [],
}; };
session.send("GetNpcMessageGroupScRsp", dataObj); session.send(GetNpcMessageGroupScRsp, dataObj);
} }

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetNpcStatusScRsp", { session.send(GetNpcStatusScRsp, {
retcode: 0, retcode: 0,
messageStatusList: [] messageStatusList: []
} as GetNpcStatusScRsp); } as GetNpcStatusScRsp);

View File

@ -5,7 +5,7 @@ import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
const body = packet.body as GetNpcTakenRewardCsReq; const body = packet.body as GetNpcTakenRewardCsReq;
session.send("GetNpcTakenRewardScRsp", { session.send(GetNpcTakenRewardScRsp, {
retcode: 0, retcode: 0,
npcId: body.npcId, npcId: body.npcId,
talkEventList: [] talkEventList: []

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetPrestigeInfoScRsp", { session.send(GetPrestigeInfoScRsp, {
retcode: 0, retcode: 0,
prestigeInfo: { prestigeInfo: {
exp: 0, exp: 0,

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetQuestDataScRsp", { session.send(GetQuestDataScRsp, {
questList: [], questList: [],
retcode: 0, retcode: 0,
takenAchievementLevelList: [], takenAchievementLevelList: [],

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetRogueInfoScRsp", { session.send(GetRogueInfoScRsp, {
retcode: 0, retcode: 0,
rogueInfo: { rogueInfo: {
status: RogueStatus.ROGUE_STATUS_NONE, status: RogueStatus.ROGUE_STATUS_NONE,

View File

@ -37,5 +37,5 @@ export default async function handle(session: Session, packet: Packet) {
dataObj.shopList.push(shopObj); dataObj.shopList.push(shopObj);
}); });
session.send("GetShopListScRsp", dataObj); session.send(GetShopListScRsp, dataObj);
} }

View File

@ -3,7 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
session.send("GetSpringRecoverDataScRsp", { session.send(GetSpringRecoverDataScRsp, {
retcode: 0, retcode: 0,
healPoolInfo: { healPoolInfo: {
healPool: 0, healPool: 0,

View File

@ -18,5 +18,5 @@ export default async function handle(session: Session, packet: Packet) {
}); });
}); });
session.send("GetTutorialScRsp", dataObj); session.send(GetTutorialScRsp, dataObj);
} }

View File

@ -18,5 +18,5 @@ export default async function handle(session: Session, packet: Packet) {
}); });
}); });
session.send("GetTutorialGuideScRsp", dataObj); session.send(GetTutorialGuideScRsp, dataObj);
} }

View File

@ -1,4 +1,4 @@
import { AvatarType, JoinLineupCsReq, SyncLineupNotify, SyncLineupReason } from "../../data/proto/StarRail"; import { AvatarType, JoinLineupCsReq, JoinLineupScRsp, SyncLineupNotify, SyncLineupReason } from "../../data/proto/StarRail";
import Avatar from "../../db/Avatar"; import Avatar from "../../db/Avatar";
import Packet from "../kcp/Packet"; import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
@ -6,7 +6,7 @@ import Session from "../kcp/Session";
// JoinLineupCsReq { baseAvatarId: 1002, slot: 1 } // JoinLineupCsReq { baseAvatarId: 1002, slot: 1 }
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
const body = packet.body as JoinLineupCsReq; const body = packet.body as JoinLineupCsReq;
session.send("JoinLineupScRsp", { retcode: 0 }); session.send(JoinLineupScRsp, { retcode: 0 });
let lineup = await session.player.getLineup(); let lineup = await session.player.getLineup();
const slot = body.slot || 0; const slot = body.slot || 0;
@ -29,7 +29,7 @@ export default async function handle(session: Session, packet: Packet) {
session.player.setLineup(lineup); session.player.setLineup(lineup);
session.player.save(); session.player.save();
session.send("SyncLineupNotify", { session.send(SyncLineupNotify, {
lineup: lineup, lineup: lineup,
reasonList: [SyncLineupReason.SYNC_REASON_NONE] reasonList: [SyncLineupReason.SYNC_REASON_NONE]
} as SyncLineupNotify); } as SyncLineupNotify);

View File

@ -21,7 +21,7 @@ export default async function handle(session: Session, packet: Packet) {
const dataObj = { const dataObj = {
retcode: 0, retcode: 0,
secretKeySeed: 0 secretKeySeed: 0,
} as PlayerGetTokenScRsp; } as PlayerGetTokenScRsp;
const account = await Account.fromToken(body.token || ""); const account = await Account.fromToken(body.token || "");
@ -46,5 +46,5 @@ export default async function handle(session: Session, packet: Packet) {
} }
dataObj.uid = player.db._id; dataObj.uid = player.db._id;
session.send("PlayerGetTokenScRsp", dataObj); session.send(PlayerGetTokenScRsp, dataObj);
} }

View File

@ -82,7 +82,7 @@ export default async function handle(session: Session, packet: Packet) {
plr.save(); plr.save();
} }
session.send("PlayerLoginScRsp", { session.send(PlayerLoginScRsp, {
basicInfo: plr!.db.basicInfo as PlayerBasicInfo, basicInfo: plr!.db.basicInfo as PlayerBasicInfo,
isNewPlayer: false, isNewPlayer: false,
stamina: 100, stamina: 100,

View File

@ -34,7 +34,7 @@ export default async function handle(session: Session, packet: Packet) {
} }
} }
session.send("SceneEntityMoveScRsp", { session.send(SceneEntityMoveScRsp, {
retcode: 0, retcode: 0,
downloadData: undefined, downloadData: undefined,
} as SceneEntityMoveScRsp); } as SceneEntityMoveScRsp);

View File

@ -1,8 +1,8 @@
import { SetClientPausedCsReq } from "../../data/proto/StarRail"; import { SetClientPausedCsReq, SetClientPausedScRsp } from "../../data/proto/StarRail";
import Packet from "../kcp/Packet"; import Packet from "../kcp/Packet";
import Session from "../kcp/Session"; import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
const body = packet.body as SetClientPausedCsReq; const body = packet.body as SetClientPausedCsReq;
session.send("SetClientPausedScRsp", { retcode: 0, paused: body.paused }); session.send(SetClientPausedScRsp, { retcode: 0, paused: body.paused });
} }

View File

@ -14,7 +14,7 @@ export default async function handle(session: Session, packet: Packet) {
session.c.error("Failed to set lineup name", false); session.c.error("Failed to set lineup name", false);
} }
session.send("SetLineupNameScRsp", { session.send(SetLineupNameScRsp, {
retcode: 0, retcode: 0,
index: session.player.db.lineup.curIndex, index: session.player.db.lineup.curIndex,
name: body.name name: body.name

View File

@ -8,7 +8,7 @@ export default async function handle(session: Session, packet: Packet) {
// TODO: This packet is just a base // TODO: This packet is just a base
session.send("StartChallengeScRsp", { session.send(StartChallengeScRsp, {
retcode: 0, retcode: 0,
curChallenge: { curChallenge: {
challengeId: body.challengeId, challengeId: body.challengeId,

View File

@ -4,7 +4,7 @@ import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
const body = packet.body as SwapLineupCsReq; const body = packet.body as SwapLineupCsReq;
session.send("SwapLineupScRsp", { retcode: 0 } as SwapLineupScRsp); session.send(SwapLineupScRsp, { retcode: 0 } as SwapLineupScRsp);
let lineup = await session.player.getLineup(); let lineup = await session.player.getLineup();
const _copy = lineup.avatarList[body.dstSlot]; const _copy = lineup.avatarList[body.dstSlot];
@ -14,7 +14,7 @@ export default async function handle(session: Session, packet: Packet) {
session.player.setLineup(lineup); session.player.setLineup(lineup);
session.player.save(); session.player.save();
session.send("SyncLineupNotify", { session.send(SyncLineupNotify, {
lineup: lineup, lineup: lineup,
reasonList: [SyncLineupReason.SYNC_REASON_NONE] reasonList: [SyncLineupReason.SYNC_REASON_NONE]
} as SyncLineupNotify); } as SyncLineupNotify);

View File

@ -5,7 +5,7 @@ import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
const body = packet.body as SyncTimeCsReq; const body = packet.body as SyncTimeCsReq;
session.send("SyncTimeScRsp", { session.send(SyncTimeScRsp, {
retcode: 0, retcode: 0,
clientTimeMs: body.clientTimeMs, clientTimeMs: body.clientTimeMs,
serverTimeMs: Math.round(new Date().getTime() / 1000) serverTimeMs: Math.round(new Date().getTime() / 1000)

View File

@ -5,7 +5,7 @@ import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) { export default async function handle(session: Session, packet: Packet) {
const body = packet.body as UnlockTutorialGuideCsReq; const body = packet.body as UnlockTutorialGuideCsReq;
session.send("UnlockTutorialGuideScRsp", { session.send(UnlockTutorialGuideScRsp, {
retcode: 0, retcode: 0,
tutorialGuide: { tutorialGuide: {
id: body.groupId, id: body.groupId,