└── MultiPlay/
├── README.md
├── package-lock.json
├── package.json
├── src
│ ├── classes
│ ├── config
│ ├── constants
│ ├── events
│ ├── handlers
│ ├── init
│ ├── managers
│ ├── models
│ ├── mysql
│ ├── protobuf
│ ├── server.js
│ └── session
└── utils
├── dateFormatter.js
├── notification
├── parser
└── responseCH5_MULTIPLAY/
__root__
package-lock.json ❯package.json ❯
src
server.js ❯session
user.sessions.js ❯game.session.js ❯sessions.js ❯handlers
locationUpdate.handler.js ❯init.handler.js ❯game.handler.js ❯index.js ❯init
loadProto.js ❯initServer.js ❯config
config.js ❯events
onError.js ❯onData.js ❯onConnection.js ❯onEnd.js ❯mysql
testDataBase.js ❯createPool.js ❯constants
env.js ❯sessions.js ❯handlerIds.js ❯header.js ❯frame.js ❯protobuf
packetNames.js ❯init
initial.proto ❯response
response.proto ❯notification
locationResponse.proto ❯request
common.proto ❯game.proto ❯locationRequest.proto ❯classes
game.class.js ❯user.class.js ❯models
user.model.js ❯managers
base.manager.js ❯interval.manager.js ❯
utils
dateFormatter.js ❯response
createResponse.js ❯parser
packetParser.js ❯notification
game.notification.js ❯
헤더 및 패킷구조 설계
헤더
타입 번호 설명 PONG string 핑 패킷용 NORMAL string 일반 패킷용 LOCATION number 위치 보고 패킷용 공통패킷
타입 패킷명 설명 uint32 handlerId 핑 패킷용 string userId 일반 패킷용 string version 위치 보고 패킷용 bytes payload 위치 보고 패킷용
protoBuf 적용
initial
message InitialPayload{ string deviceId = 1; uint32 playerId = 2; float latency =3; }locationResponse
message LocationUpdate { repeated UserLocation users = 1;
message UserLocation { string id = 1; uint32 playerId = 2; float x = 3; float y = 4; } }common
message CommonPacket{ uint32 handlerId = 1; string userId = 2; string version = 3; bytes payload = 4; }ping
message Ping { int64 timestamp = 1; }LocationRequest
message LocationUpdatePayload {float x = 1; float y = 2;
}response
message Response { uint32 handlerId = 1; uint32 responseCode = 2; int64 timestamp = 3; bytes data = 4; }
DB 연동
이 프로젝트는 데이터 저장소로 MySQL을 사용합니다. 사용자 마지막 위치정보를 MySQL에 저장하며, 서버와의 데이터 동기화를 통해 게임 상태를 유지합니다.
Column Data Type Attributes id CHAR PRIMARY KEY device_id CHAR UNIQUE last_login TIMESTAMP DEFAULT NOW() x FLOAT y FLOAT
Latency 측정 및 추측항법
이 프로젝트는 인터벌 매니저를 통한 1000ms당 PING 측정으로 각 유저의 RTT를 체크하고 각 인스턴스에 기록합니다.
게임 세션은 참가되어 있는 유저들의 Latency 중 최대치를 기준으로 설정됩니다.
레이턴시 및 명령어 처리 기반 시간을 측정하여 예상 거리를 예측하여 위치패킷을 반환합니다.
managers
base.manager.js ❯interval.manager.js ❯
게임세션 자동 증감
이 프로젝트는 게임 세션이 유저 수에 따라 자동 증가, 감소합니다. 세션 당 인원이 많을수록 위치 패킷이 증가하여 사용자 경험이 저하될 수 있습니다.
src/constans/session.js 에서 세션 당 허용 인원을 설정할 수 있고, 현재는 세션당 최대 인원은 3명입니다.
유저는 처음 들어왔을 때 생성된 세션 중 가장 인원이 적은 곳으로 배치됩니다. 생성된 세션이 없거나, 모든 세션이 최대 인원일 경우 자동으로 세션을 생성 후 배치합니다.
유저가 해당 세션을 떠날 때 세션에 남아있는 유저가 없다면, 해당 세션을 삭제합니다.
게임세션 인터벌 레이턴시 유지
게임 세션이 정해진 시간(현재 1000ms)마다 세션 내 유저의 레이턴시를 종합하여 최고 레이턴시 기준으로 세션 레이턴시를 할당합니다.



