Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

leejy12/madcamp-week2-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

몰입 오목 (BackEnd)

2022 여름 몰입캠프 공통과제 2주차


Authors

  • KAIST 이준영 leejy12
  • GIST 현재오 hjo3736

Technology

Category Tech Version
Server Node v16.15.1
npm 8.11.0
TypeScript Version 4.7.4
DB MySQL Ver 14.14 Distrib 5.7.38
OS Ubuntu 18.04.6 LTS

Build & Run

Create a .env file with the following contents.

DB_PASSWORD=<password>

Install dependencies

npm install

Run the server

npm run dev

API

Routing was done using Express.js. See API.md for details.


DB

Table users.

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | NULL    | auto_increment |
| email      | varchar(100) | NO   |     | NULL    |                |
| nickname   | varchar(30)  | NO   |     | NULL    |                |
| school     | varchar(30)  | NO   |     | NULL    |                |
| elo_rating | int(11)      | NO   |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

Each row's email and nickname are unique.


How the game works

Communication

Communication between the server and clients are done via websockets. When a player presses '매칭' button, a new websocket connection is established. The conncection is closed when the game is over. Each player is represented by class OmokPlayer. Each OmokPlayer class has a websocket member variable. This individual websocket is used to send specific messages to each player.

Game Matching

The game server keeps track of waiting players in a list waitingPlayers defined in src/gameServer.ts. When ever a new player establishes a websocket connection, the player is pushed to waitingPlayers. If the length of waitingPlayers is odd, the player is sent a "waiting" message. If the length of the list is even, we pop the first two players and create a new Game with those two. Of the two players, the one who was added to the list first plays Black i.e. goes first.

A game instance is represented by the class OmokGame. Each game is given a unique UUID and stored in a map data structure. When a game ends, it is removed from this map.

Game Play

Each player take turns making moves. A move is represented by the class OmokMove. The move gets serialized into JSON and is sent from the client to the server. An OmokMove contains the gameId which is used by the server to correctly update the corresponding game. After each move, the game server determines the state of the game (0: not over, 1: player 1 won, 2: player 2 won, 3: draw). The result of each move is represented by the class OmokMoveResult. This gets serialized to JSON and sent to both players after each move. When a game is ended, ELO ratings of each player gets updated in the DB and notified to each player. A new player is initially given a ELO rating of 1500. The maximum possible change of the rating after one round is 20.


Security

There is absolutely NO PROTECTION against SQL injection attacks. There is absolutely NO ENCRYPTION of data being transmitted.

About

몰입캠프 2주차 백엔드

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published