- KAIST 이준영 leejy12
- GIST 현재오 hjo3736
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 |
Create a .env
file with the following contents.
DB_PASSWORD=<password>
Install dependencies
npm install
Run the server
npm run dev
Routing was done using Express.js. See API.md for details.
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.
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.
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.
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.
There is absolutely NO PROTECTION against SQL injection attacks. There is absolutely NO ENCRYPTION of data being transmitted.