Skip to content

Commit 5551452

Browse files
authored
Merge pull request #24 from USTakAssociation/dev
Dev to Main
2 parents f3b127b + 99b1d65 commit 5551452

29 files changed

+1613
-1728
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
playtakdb/
22

33
run
4-
run/**
4+
run/**
5+
6+
.idea

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
# PlayTak
1+
# PlayTak
22

3-
This is the new monorepo for the PlayTak services
3+
This is the new monorepo for the PlayTak services
44

55
## Description
66

7-
![Unit Tests](https://github.com/USTakAssociation/playtak-api/actions/workflows/ci.yml/badge.svg)
8-
9-
107
This repo contains the api and Tak server for servicing data to the PlayTak UI client and games ui
118

129
## Requirements
10+
1311
- docker
1412
- nvm
1513
- node v20
1614
- sqlite3
1715

18-
## Setup
16+
## Setup
1917

2018
Run the following commands to setup the api for local development
2119

@@ -28,16 +26,16 @@ cd ..
2826

2927
setup the local databases
3028

31-
3229
```bash
33-
sh ./script/development/create_databases.sh
30+
./scripts/development/create_databases.sh
3431
```
35-
This creates the players and games sqlite dbs in the playersdb folder
32+
33+
This creates the players and games sqlite dbs in the playtakdb folder
3634

3735
Optionally, you can then use the script `./scripts/development/add_user.sh` to add users to the local players database with a password of "password".
3836

3937
```bash
40-
./scripts/development/add_user.sh mylocalacct ./players.db
38+
./scripts/development/add_user.sh mynewusername ./playtakdb/players.db
4139
# See scripts/development/add_user.sh comments for more options.
4240
```
4341

@@ -51,7 +49,7 @@ docker compose up -d --build
5149

5250
## Test
5351

54-
You can run tests for each of the apps
52+
You can run tests for each of the apps:
5553

5654
```bash
5755
cd ./api
@@ -81,36 +79,38 @@ bru run test-suite --env local
8179
```
8280

8381
## TODO
82+
8483
- migrate to mariadb
8584
- create user auth endpoints and test
8685
- setup API key registration to track usage
8786
- add automated versioning and setup release artifacts with github
8887
- build out more robust deploy and rollback
8988
- java tests
9089

91-
9290
## Contributing
91+
9392
PlayTak is an Open Source Project. This means that:
9493

9594
> Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit.
9695
9796
Please read [CONTRIBUTING.md](docs/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
9897

9998
## Versioning
99+
100100
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the tags on this repository.
101101

102102
## Contributors
103+
103104
PlayTak is only possible due to the excellent work of the following contributors:
104105

105-
||
106-
:----:|
107-
|[chaitu](https://github.com/chaitu236)|
108-
|[Nohat](https://github.com/NoHatCoder)|
109-
|[Nitzel](https://github.com/nitzel)|
110-
|[InvaderB](https://github.com/invaderb)|
106+
| |
107+
| :-------------------------------------: |
108+
| [chaitu](https://github.com/chaitu236) |
109+
| [Nohat](https://github.com/NoHatCoder) |
110+
| [Nitzel](https://github.com/nitzel) |
111+
| [InvaderB](https://github.com/invaderb) |
111112

112113
See also the list of contributors who participated in this project.
113114

114115
License
115116
MIT License © USTA see LICENSE.md file
116-

api/README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# PlayTak-API
1+
# PlayTak-API
22

33
## Description
44

5-
![Unit Tests](https://github.com/USTakAssociation/playtak-api/actions/workflows/ci.yml/badge.svg)
6-
75
The Play Tak API is a nodejs built using the nestjs project which contains multiple endpoints for servicing data to the Play Tak UI.
86

97
## Requirements
@@ -14,7 +12,7 @@ The Play Tak API is a nodejs built using the nestjs project which contains multi
1412
## Installation
1513

1614
```bash
17-
$ npm install
15+
npm install
1816
```
1917

2018
## Running the app
@@ -24,20 +22,22 @@ There are two options to run the project: manually, or with docker (recommended)
2422
Either way, you will need to create two databases, which can be done with the following bash script:
2523

2624
```bash
27-
sh ../script/development/create_databases.sh
25+
../scripts/development/create_databases.sh
2826
```
27+
2928
This creates the players and games sqlite databases.
3029

31-
Optionally, you can then use the script `scripts/development/add_user.sh` to add users to the local players database with a password of "password".
30+
Optionally, you can then use the script `../scripts/development/add_user.sh` to add users to the local players database with a password of "password".
3231

3332
```bash
34-
./scripts/development/add_user.sh mylocalacct ./players.db
35-
# See scripts/development/add_user.sh comments for more options.
33+
../scripts/development/add_user.sh mynewusername ../playtakdb/players.db
34+
# See ../scripts/development/add_user.sh comments for more options.
3635
```
3736

3837
### docker
3938

4039
In the root of the repo, run the following command:
40+
4141
```bash
4242
docker compose up -d --build
4343
```
@@ -77,14 +77,17 @@ https://api.playtak.com/api
7777
https://api.beta.playtak.com/api
7878

7979
Events
80+
8081
- /events
8182

8283
Games History
84+
8385
- /v1/games-history/
8486
- /v1/games-history/{id}
8587
- /v1/games-history/ptn/{id}
8688
- /v1/hames-history/db
8789

8890
Ratings
91+
8992
- /v1/ratings
9093
- /v1/ratings/{player_name}

scripts/development/create_databases.sh

100644100755
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
#!/bin/bash
2+
23
# set the playtakdb folder to the parent directory variable
3-
$dbPath = "../../playtakdb"
4+
scriptpath=$(dirname "$(readlink -f "$0")")
5+
dbpath="$scriptpath/../../playtakdb"
6+
7+
# set the database paths
8+
playersdb="$dbpath/players.db"
9+
gamesdb="$dbpath/games.db"
410

5-
# check if playtakdb folder exists
11+
# check if playtakdb folder exists
612
if [ ! -d $dbpath ]; then
7-
mkdir $dbpath
8-
fi
9-
#remove existing
10-
if [ -f $dbPath/players.db ]; then
11-
rm $dbPath/players.db
13+
mkdir "$dbpath"
1214
fi
1315

14-
if [ -f $dbPath/games.db ]; then
15-
rm $dbPath/games.db
16+
# remove existing
17+
if [ -f $playersdb ]; then
18+
rm "$playersdb"
19+
fi
20+
if [ -f $gamesdb ]; then
21+
rm "$gamesdb"
1622
fi
1723

18-
$playersdb = "$dbPath/players.db"
19-
$gamesdb = "$dbPath/games.db"
20-
21-
#create db, tables
24+
# create db, tables
2225
echo "CREATE TABLE players (id INT PRIMARY_KEY, name VARCHAR(20), password VARCHAR(50), email VARCHAR(50), rating real default 1000, boost real default 750, ratedgames int default 0, maxrating real default 1000, ratingage real default 0, ratingbase int default 0, unrated int default 0, isbot int default 0, fatigue text default '{}', is_admin int default 0, is_mod int default 0, is_gagged int default 0, is_banned int default 0, participation_rating int default 1000);" | sqlite3 $playersdb
2326
echo "CREATE TABLE games (id INTEGER PRIMARY KEY, date INT, size INT, player_white VARCHAR(20), player_black VARCHAR(20), notation TEXT, result VARCAR(10), timertime INT DEFAULT 0, timerinc INT DEFAULT 0, rating_white int default 1000, rating_black int default 1000, unrated int default 0, tournament int default 0, komi int default 0, pieces int default -1, capstones int default -1, rating_change_white int default 0, rating_change_black int default 0, extra_time_amount int default 0, extra_time_trigger int default 0);" | sqlite3 $gamesdb

server/.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
7+
[*.java]
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
indent_style = tab
11+
indent_size = 4
12+
tab_width = 4
13+
max_line_length = 120
14+
ij_java_align_multiline_chained_methods = false
15+
ij_java_method_call_chain_wrap = on_every_item
16+
ij_java_prefer_parameters_wrap = false
17+
ij_java_array_initializer_wrap = split_into_lines
18+
ij_java_array_initializer_new_line_after_left_brace = true
19+
ij_java_array_initializer_right_brace_on_new_line = true
20+
ij_java_space_before_array_initializer_left_brace = true

server/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ WORKDIR /app
99
# Logged in users (not guests) will reconnected by the UI within ~12s.
1010

1111
# consider removing clean for slightly faster compilation
12-
ENTRYPOINT amvn clean package exec:java --watch
12+
ENTRYPOINT exec amvn clean package exec:java --watch
1313

1414
FROM base as production
1515
VOLUME /tmp

server/src/main/java/tak/ChatRoom.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,67 @@
55
*/
66
package tak;
77

8-
import java.util.concurrent.ConcurrentHashMap;
98
import tak.utils.BadWordFilter;
109
import tak.utils.ConcurrentHashSet;
11-
import java.util.concurrent.locks.*;
10+
11+
import java.util.concurrent.ConcurrentHashMap;
12+
import java.util.concurrent.locks.Lock;
13+
import java.util.concurrent.locks.ReentrantLock;
1214

1315
/**
1416
*
1517
* @author chaitu
1618
*/
1719
public class ChatRoom {
1820
static final ConcurrentHashMap<String, ChatRoom> chatRooms = new ConcurrentHashMap<>();
19-
static Lock roommaplock=new ReentrantLock();
20-
21+
static Lock roommaplock = new ReentrantLock();
22+
2123
ConcurrentHashSet<Client> members;
22-
24+
2325
ChatRoom() {
24-
members = new ConcurrentHashSet<Client>();
26+
members = new ConcurrentHashSet<>();
2527
}
26-
27-
public static ChatRoom joinRoom(String name, Client client){
28+
29+
public static ChatRoom joinRoom(String name, Client client) {
2830
roommaplock.lock();
29-
try{
30-
ChatRoom room=chatRooms.get(name);
31-
if(room==null){
31+
try {
32+
ChatRoom room = chatRooms.get(name);
33+
if (room == null) {
3234
room = new ChatRoom();
3335
chatRooms.put(name, room);
3436
}
3537
room.members.add(client);
3638
return room;
37-
}
38-
finally{
39+
} finally {
3940
roommaplock.unlock();
4041
}
4142
}
42-
43-
public static void shout(String name, Client client, String msg) {
44-
ChatRoom room=chatRooms.get(name);
45-
if(room!=null){
46-
String compiledmessage="ShoutRoom "+name+" <"+client.player.getName()+"> "+ BadWordFilter.filterText(msg);
47-
if(!client.player.isGagged()) {
43+
44+
public static void shout(String name, Client client, String msg) {
45+
ChatRoom room = chatRooms.get(name);
46+
if (room != null) {
47+
String compiledmessage = "ShoutRoom " + name + " <" + client.player.getName() + "> " + BadWordFilter.filterText(msg);
48+
if (!client.player.isGagged()) {
4849
for (Client cc : room.members) {
4950
cc.sendWithoutLogging(compiledmessage);
5051
}
5152
} else {
52-
client.sendWithoutLogging("ShoutRoom "+name+" <"+client.player.getName()+"> <Server: You have been muted for inappropriate chat behavior.>");
53+
client.sendWithoutLogging("ShoutRoom " + name + " <" + client.player.getName() + "> <Server: You have been muted for inappropriate chat behavior.>");
5354
}
5455
}
5556
}
56-
57-
public static void leaveRoom(String name, Client client){
57+
58+
public static void leaveRoom(String name, Client client) {
5859
roommaplock.lock();
59-
try{
60-
ChatRoom room=chatRooms.get(name);
61-
if(room!=null){
60+
try {
61+
ChatRoom room = chatRooms.get(name);
62+
if (room != null) {
6263
room.members.remove(client);
63-
if(room.members.isEmpty()){
64+
if (room.members.isEmpty()) {
6465
chatRooms.remove(name);
6566
}
6667
}
67-
}
68-
finally{
68+
} finally {
6969
roommaplock.unlock();
7070
}
7171
}

0 commit comments

Comments
 (0)