-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterm-project-notes-teamx.txt
188 lines (161 loc) · 8.02 KB
/
term-project-notes-teamx.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
Title: Term Project Notes TeamX
Class: CSC 667/867
Project: UNO
Team: X
Team-Members: Andy Almeida - pie240, Arjun - Kepler, Tyler - Tydershot, *KARMA
Set-Up:
1. Install Node.js
2. Install PostgreSQL
2a. sudo -u postgres -i
2b. psql
2c. CREATE USER <username>;
2d. ALTER USER <username> WITH PASSWORD '<password>';
2e. ALTER USER <username> CREATEDB;
2f. exit
3. Git Fetch the Repo: https://github.com/csc-667-spring-2023-roberts/term-project-teamx.git
4. Create a .env file in the folder
5. Add to the .env file:
DATABASE_URL=postgres://USERNAME:PASSWORD@localhost:5432/<database-name>
SECRET=mySecretKey
6. createdb <database-name>
7. npm init
8. npm install
9. npm run start:dev
10.The server should be runnable, and you can add to the code. When you save the project, it will immediately
11.You can connect to the website via http://localhost:3000
Database Breakdown:
Tables:
test_table:
id: id
created_at: timestamp, nn, default("current_timestamp")
users:
id: id
username: varchar(256), nn, unique
email: varchar(256), nn, unique
password: char(60), nn
created_at: timestamp, nn, default("current_timestamp")
game:
id: id
is_started: boolean, nn, default(false)
created_at: timestamp, nn, default("current_timestamp")
current_game:
game_id: int, nn
player_count: int, nn
lastupdated: timestamp, nn, default("current_timestamp")
current _number: int, nn
current_color: varchar(256), nn
current_direction: boolean, nn
gamebag:
value: varchar(256)
color: varchar(256)
gameid: int, nn
userid: int, nn
specialcond: boolean, nn
game_users:
user_id: int, nn
game_id: int, nn
current: boolean, default:false, nn
table_order: int, nn
session:
sid: varchar(255), nn, primarykey, deferrable:false
sess: string
expire: TIMESTAMP, default("current_timestamp")
Folder/File Descriptions:
/backend:
/db: IMPORTANT contains the javascript that deals with the sql queries and functions that the routes use
/chat.js: create - query to insert into chat db
/connection.js: nothingyet
/games.js: list - gets the list of games...
create - creates a game in the db with default values - returns the game id
creatingUser - get the creating user from a game
join - gets the highest table order from the game, and inserts a user into game_user with +1 table order
getUsers - gets the id and username from the game_users that match the game
/users.js: create - inserts a user into the user table
findByEmail - self explanitory
/middleware: holds middleware
/add-session-locals.js: addSessionLocals - makes the app.locals.user = session.user
/is-authenticated.js: isAuthenticated - gets the user from the session,
if the user is undefined or user id is undefined, then continue,
if not, redirect to login
/request-time.js: Sends the Request recieved at Datetime to console
/routes/static:
/authentication.js: has routes for registration and login pages, deals heavily with account authentication
/chat.js: has a function to emit a chat message event that works with the socket
/games.js: functions that deal with the game webpage creation (create, join) and functionality (draw, )
/home.js: single function to route the html with a simple html injection
/lobby.js: single function to route the html with a simple html injection and awaits the games list
/test.js: test page to test html injections
/static: contains the bundle that the website uses. this is constructed after?? no real need to mess with...
/scripts: contains the bundle, big and scary, dont mess with...
/stylesheets: contains css for the page
/favicon.ico: the pages icon
/views: the base html that is called by the routes
/games.ejs: html - hold the games, includes templates for js calls= (templates: user, card, chatmessage)
/home.ejs: base page with all links
/lobby.ejs: has a space for chat and the list of games that are available to join (templates: chat)
/login.ejs: login form to log in
/register.ejs: registration form to register
/server.js: The main routing for the server. Would not really mess with unless you make more pages...
/constants: holds a file that contains constants for the whole project
/events.js: so far, contains two constants for events: playerjoined and gamestateupdated
/frontend: frontend
/css: css for the website
/index.css: css for the website
/games: js that is actually called by the html
/index.js: js that is called by the html
/util: small utilities for the html
/game-ids.js: returns the gameId
/index.js: js that is called by the html
/migrations: the code the handles the Postgres database. It creates the tables. Refer to the database build above
/node_modules: the modules that the project uses. Use npm to deal with this
/.env: contains the connection to the database. this must be created whenever a fresh pull from github is made
the rest of the files will either not be messed with for this project, or do not require explination
Project Interaction/Construction Flow:
The purpose for this is to better visualise the flow of how the whole project is dealing with these cases;
This can hopefully help make more sense of how the project interacts with itself, and in turn make developing to it easier/make more sense
Case: Index Page Requested
1. Server.js routes the user to start at routes/static/home.js
2. routes/static/home.js gets the requested page and renders the home.ejs with dynamically inserted data via js
Case: User uses Register page to register to site
1. Server.js routes the user to start at route/static/authentication.js
2. route/static/authentication.js gets the requested page and renders the registration.ejs with dynamically inserted data via js
3. after the user enters thier data into the form, and clicks submit, post is sent to route/static/authentication.js
4. the post function creates an entry into the database using backend/db/users.js
5. the post function then redirects to the route/static/lobby.js
6. route/static/lobby.js gets the requested page and renders the lobby.ejs with dynamically inserted data via js
Case: User enters something into chat and clicks enter
1. The user is currently in the lobby.ejs and games.ejs
2. The user enters text into the chatMessage input
3. The event is caught at frontend/index.js
4. Data is collected and routed to route/static/chat.js
5. an event is emitted by chat.js
6. the event is picked up by the socket, and caught in frontend/index.js
7. frontend/index.js clones the chatMessageTemplate, fills it with the data, and appends it to the html
Case: User creates a game
1. Server.js routes the user to start at route/static/lobby.js
2. route/static/lobby.js gets the requested page and renders the lobby.ejs with dynamically inserted data via js
3. the games object that is dynamically inserted is pulled by the database via backend/db/games.js
4. the user clicks the Create Game submit button on the lobby.ejs page
5. the button is a post method that has the action /games/create
6. route/static/games.js deals with this
7. route/static/games.js uses the post /create method
8. post /create method creates a Game using backend/db/games.js
9. the user then will be redirected to that /games/:id
10.the creating user would be pulled from backend/db/games.js
11.then games.ejs will be rendered with dynamically inserted datab via js (creatinguser, gameid)
Case: User joins a game
1.
Quick Notes:
Get vs Post: Get is done when the route is requested. Post is done after the page is already loaded, and you are leaving it.
Project Notes:
Refer to TeamMeow's Repository. They are doing things well.
Refer to 5/4 Class -> He worked on TeamQ -> Sockets...
The Game is run in the Games Page
Three Sections:
1. Nav Bar -> Home, Loby, logout, profile
2. All the players in the game each players cards, deck, colorcard.
a.One player
b.The persons cards
i. number: 0-9
ii.color: "red", "blue", "green", "yellow"
c.What is the top the card on the pile