728x90
반응형
효과는 굉장했다!
어느덧 프로젝트 4주 차가 되었고 현재는 유저 간 3:3 pvp까지 구현 후 배포를 위해 서버 모듈화를 진행하여 테스트 단계이다.
현재 내가 생각하는 가장 중요한 것은, 우리가 최종적으로 무엇이 목표인가에 대해 명확하게 인지하고 나아가는 것이라고 생각하는데, 단순히 서버를 나누고 실행시키는 것이 아닌, 각 모듈화 서버를 부하량에 따라 늘리고 줄이고 할 수 있는 로드밸런싱과 오토스케일링에 대해서 좀 더 심도 있게 공부해야 한다고 생각된다.
한 주 동안..
유저 간 3:3 pvp 기능을 구현하면서 Set과 Map에 대해서 많이 다뤄보게 되었는데 확실히 적용 가능하다면 손쉽게 사용하기 좋은데 Map안에 Map을 넣는 구조이다 보니 가공할 때 자칫 잘못하면 코드가 순식간에 복잡해 보이기 쉬운 것 같다.
// pvp.service.ts 중 일부
//...
async targetValidation(req: Request, res: Response, next: NextFunction): Promise<string|undefined> {
console.log('targetValidation')
const { socketId, CMD, userInfo, userStatus }: PostBody = req.body;
const roomName = userStatus!.pvpRoom;
const userNames: string[] = [];
const pvpRoom = rooms.get(roomName!);
const isDead = pvpRoom!.get(userInfo!.username)!.target;
// 사망한 유저인지 확인
if (isDead === 'none' || isDead === 'dead') {
const request = { body: { socketId, CMD: '관전 중에는 입력하지 못합니다.', userInfo, userStatus, option: 'enemyChoice' }};
pvpController.wrongCommand(request as Request, res, next);
return undefined;
}
// 본인 선택시 예외처리로직 시작
const iterator = pvpRoom!.values();
for (let i = 0; i < maxUsers; i++) {
userNames.push(iterator.next().value.userStatus.name);
}
// 본인의 index를 확인
const myIndex = userNames.findIndex((e)=>e===userStatus!.name);
// 유저가 속한 팀이아닌 상대팀만을 선택
if (myIndex < 2 && Number(CMD)-1 < 2) {
const request = { body: { socketId, CMD, userInfo, userStatus, option: 'enemyChoice' }};
pvpController.targetWrong(request as Request, res, next);
return undefined;
} else if (myIndex >= 2 && Number(CMD)-1 >= 2) {
const request = { body: { socketId, CMD, userInfo, userStatus, option: 'enemyChoice' }};
pvpController.targetWrong(request as Request, res, next);
return undefined;
} else if (Number(CMD) > maxUsers) {
const request = { body: { socketId, CMD, userInfo, userStatus, option: 'enemyChoice' }};
pvpController.targetWrong(request as Request, res, next);
return undefined;
}
// 이미 사망한 유저를 선택하지 못한다.
const dontSelect = await Characters.findOne({ where: { name: userNames[Number(CMD)-1] }})
if (dontSelect!.hp === 0) {
const request = { body: { socketId, CMD, userInfo, userStatus, option: 'enemyChoice' }};
pvpController.targetWrong(request as Request, res, next);
return undefined;
}
return pvpRoom!.get(userInfo!.username)!.target = userNames[Number(CMD)-1];
}
//...
앞으로 중요한 과제
- proxy
- worker thread
- docker, dockerhub
- kubernetes
- MSA
- 면접준비
- 멘탈관리
728x90
반응형