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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
This is a repository, containing a console application exercise, made by me, and solution in different languages.
The task should serve as a "final exam" for developers who are learning the basics of a programming language (where possible).
# ctfc
`ctfc` is the "**c**onsole **t**ext **f**ile **c**hat", and the project you're going to work on. As the name suggests, it will be a chatting application, entirely in the console. For data storage, simple text files will be used.
## General structure
### Feature overview
- User registration, login and updating
- Chat rooms with title and details, message history, real time chat updating
- Direct user messaging with message, real time updating
### User accounts
Each user must have the following properties:
- `string UserName`: between 2 and 40 characters (A-z, 0-9, ., \*, \_, -, at least one letter)
- `string Password`: between 5 and 40 characters (any character, but at least one number)
- `string Name`: between 2 and 60 characters (A-z, spaces, ', -)
Two users can't have the same UserName. Once set, a UserName cannot be changed.
Passwords must be hashed. You decide on which algorithm to use.
### Chat rooms
Each chat room must have the following properties:
- `string Name`: between 2 and 20 characters (A-z, 0-9, spaces, \_, -)
- `string Description`: between 0 and 30 characters (any character)
- `string Owner`: between 2 and 40 characters (must be an existing UserName)
- `string collection Messages`: a collection containing all messages
Two chat rooms can't have the same Name. Once set, a name cannot be changed.
Once set, an owner cannot be changed (owner is set via code, it's not chosen by user).
### Direct messages chat
Each direct message chat has the following properties:
- `string Name`: between 5 and 81 characters
- `string collection Messages`: a collection containing all messages
The name is not chosen by a user. It is in the format `USERNAME USERNAME`, where the two usernames must be in alphabetic order.
### Files
As discussed, files are used for long term storage. The location of all files are up to you, but they should follow this structure:
```
├─ Users
│ ├─ john.txt
│ ├─ robertson94.txt
│ └─ steve.txt
├─ Chat Rooms
│ ├─ Cool Kids Club.txt
│ └─ Computer geeks.txt
└─ Direct Messages
├─ john robertson94.txt
└─ robertson94 steve.txt
```
- Users folder: contains text files for each user, in format `USERNAME.txt`
- Each file is in the format:
```
USERNAME
PASSWORD_HASH
NAME
```
- Chat Rooms folder: contains text files for each chat room, in format `CHAT ROOM NAME.txt`
- Each file is in the format:
```
NAME
DESCRIPTION
OWNER_USERNAME
USERNAME
MESSAGE
USERNAME
MESSAGE
```
- Direct Messages folder: contains text files for each direct message combination, in format `USERNAME USERNAME.txt`
- Each file is in the format:
```
NAME
USERNAME
MESSAGE
USERNAME
MESSAGE
```
## User interface
In this part, you're gonna see the general rules for the UI. You must create a system which implements these rules, and then all pages/windows, defined in the following section, must utilize that system (so for each page, there is just a definition of what's inside it).
Note: the `█` character, represents the location of the cursor
- Errors are always surrounded by a double border:
```
╔════════════════════╗
║ An error occurred! ║
╚════════════════════╝
```
and must be shown at the top of the page.
- Menu items (navigation bar items) are always surrounded by a single border:
```
┌────────┬────────┬────────┐
│ Page 1 │ Page 2 │ Page 3 │
└────────┴────────┴────────┘
```
- At the left side, there is always a "rail" that connects all *fields* to the menu items. Errors are never connected.
```
╔══════════════════╗
║ Invalid message! ║
╚══════════════════╝
┌────────┬────────┬────────┐
│ Page 1 │ Page 2 │ Page 3 │
├────────┴────────┴────────┘
├% steve: This is a test message
├% john: It's true
├% steve: And this is another test
└@ Message : █
```
- Text fields just contain some text, and start with a `%`:
```
├% steve: This is a test message
```
- A notable exception is the page indicator, which is just text, but connects to the "rail", rather than start with a `%`:
```
├─Page 1/5─┘
```
- Input fields take user input and start with a `@`, then have specifications on valid input and finally semicolon and user's cursor:
```
└@ Username : █
```
They're always at the very bottom, unless filled. A filled input field is treated as a text field, but still has the `@` symbol.
```
├@ Username : John
└@ Password : █
```
- The specification can be a normal word (like just `Username`, `Password`, etc.) or a command specification. Command specifications are surrounded in square brackets. Capital letters or symbols mean that you can enter that character for the command, while lowercase word(s) specify what type of value is the command.
```
└@ [A/B/C/name/number/H]: █
```
*Here, you can either enter the letter A, B, C or H (case insensitive), and that will execute some command. If you enter some sort of a name or number, those will be seen as commands (case sensitive).*
`H` is the Help command, it shows in a bit more detail the command specifications, it should exist almost everywhere
- Usually there is a "blank" line above the input field, unless it's directly below the menu items:
```
┌───────┐
│ Login │
├───────┘
├% Logging into ctfc
│
└@ Username : █
```
```
┌───────┐
│ Login │
├───────┘
└@ Username : █
```
- Numbered fields are used for navigation purposes. In them, each item starts with with a number and by selecting a number, some action should happen to the selected item:
```
├1 First Option
├2 Second Option
├3 Third Option
```
### Initial window
When launching the application, the user will be prompted to choose between logging in or registering an account:
```
┌───────┬──────────┐
│ Login │ Register │
├───────┴──────────┘
└@ [L/R]: █
```
If an invalid value is given, the error is shown on top and the prompt is below:
```
╔════════════════════════════════╗
║ "asd" is not a valid argument! ║
╚════════════════════════════════╝
┌───────┬──────────┐
│ Login │ Register │
├───────┴──────────┘
└@ [L/R]: █
```
### Login
In the login screen, you should be greeted with a username prompt:
```
┌───────┐
│ Login │
├───────┘
└@ Username : █
```
After input, if the user does not exist, it will show an error and the prompt below it:
```
╔════════════════════════════╗
║ User "asd" does not exist! ║
╚════════════════════════════╝
┌───────┐
│ Login │
├───────┘
└@ Username : █
```
but if the user exists, it should show the password prompt below:
```
┌───────┐
│ Login │
├───────┘
├@ Username : John
└@ Password : █
```
On incorrect password, there should be an error shown and the prompt below:
```
╔═════════════════════╗
║ Incorrect password! ║
╚═════════════════════╝
┌───────┐
│ Login │
├───────┘
├@ Username : John
└@ Password : █
```
On correct password, user should be greeted by the [chats page](#Chats%20page).
Note: You probably got how it looks when there is an error, so I won't show it anymore.
### Register
The user should be prompted with input prompts in this order (if values is correct):
```
┌──────────┐
│ Register │
├──────────┘
└@ Username [A-z, 0-9, *, ., _, -]: █
```
```
┌──────────┐
│ Register │
├──────────┘
├@ Username : John
└@ Password [5-40 characters; at least 1 number]: █
```
```
┌──────────┐
│ Register │
├──────────┘
├@ Username : John
├@ Password : password1
└@ Name [2-60 characters]: █
```
After pressing enter in the name section, the user should be redirected to the [chats page](#Chats%20page) (so, instantly logged in).
### Chats page
The chats page is one of the main pages inside the application. Here you can see all available chats with pagination, and you can also Create your own chat or Edit ones you own.
```
┌─────────────────┬─────────┬────────┐
│ Direct Messages │ Account │ Logout │
├─────────────────┴─────────┴────────┘
├1 Cool Kids Club: A chat room only for those worthy of it B-)
├2 Computer geeks: You like computers? So do we. Join us for the nerdy experience
├─Page 1/1─┘
│
└@ [D/A/L/</>/C/E/name/number/H]: █
```
With Help message:
```
┌─────────────────┬─────────┬────────┐
│ Direct Messages │ Account │ Logout │
├─────────────────┴─────────┴────────┘
├1 Cool Kids Club: A chat room only for those worthy of it B)
├2 Computer geeks: You like computers? So do we. Join us for the nerdy experience
├─Page 1/1─┘
│
├% Chats page options: [(D)irect messages/(A)ccount/(L)ogout/(<) for previous page/(>) for next page/(C) for create chat/(name) for go to chat room by name/(number) for go to chat room by number/(H)elp]
└@ [D/A/L/</>/C/E/name/number/H]: █
```
### Specific chat page
```
┌───────┬─────────────────┬─────────┬────────┐
│ Chats │ Direct Messages │ Account │ Logout │
├───────┴─────────────────┴─────────┴────────┘
├% Computer geeks: You like computers? So do we. Join us for the nerdy experience
├% Brought to you by "David Robertson (robertson94)"
│
├% robertson94: I think the new Windows 11 design looks horrible
├% steve: Yeah, right??
├─Page 50/50─┘
│
└@ Message or [C/D/A/L/</>/H]: █
```
With Help message:
```
┌───────┬─────────────────┬─────────┬────────┐
│ Chats │ Direct Messages │ Account │ Logout │
├───────┴─────────────────┴─────────┴────────┘
├% Computer geeks: You like computers? So do we. Join us for the nerdy experience
├% Brought to you by "David Robertson (robertson94)"
│
├% robertson94: I think the new Windows 11 design looks horrible
├% steve: Yeah, right??
├─Page 50/50─┘
│
├% Chat options: [(C)hats/(D)irect messages/(A)ccount/(L)ogout/(<) for previous page/(>) for next page/Help]
└@ Message or [C/D/A/L/</>/H]: █
```
### Direct messages page
```
┌───────┬─────────┬────────┐
│ Chats │ Account │ Logout │
├───────┴─────────┴────────┘
├1 David Robertson (robertson94): Just a guy
├2 Bob J Stevenson (bjs)
├3 Steve (steve): I am Steve
├─Page 2/2─┘
│
└@ [C/A/L/</>/username/number/H]: █
```
With Help message:
```
┌───────┬─────────┬────────┐
│ Chats │ Account │ Logout │
├───────┴─────────┴────────┘
├1 David Robertson (robertson94): Just a guy
├2 Bob J Stevenson (bjs)
├3 Steve (steve): I am Steve
├─Page 2/2─┘
│
├% Direct messages options: [(C)hats/(A)ccount/(L)ogout/(<) for previous page/(>) for next page/(username) for directly message person with username/(number) for enter direct messages by number/(H)elp]
└@ [C/A/L/</>/username/number/H]: █
```
### Account
```
┌───────┬─────────────────┬────────┐
│ Chats │ Direct Messages │ Logout │
├───────┴─────────────────┴────────┘
├% Username : John
├1 Password : [HIDDEN]
├2 Name : John Smith
│
└@ [C/D/L/number/H]: █
```
With Help message:
```
┌───────┬─────────────────┬────────┐
│ Chats │ Direct Messages │ Logout │
├───────┴─────────────────┴────────┘
├% Username : John
├1 Password : [HIDDEN]
├2 Name : John Smith
│
├% Account options: [(C)hats/(D)irect Messages/(L)ogout/(number) for edit option by number/(H)elp]
└@ [C/D/L/number/H]: █
```
Editing an option requires you first input your password, then entering a new value for the chose property. I'll only show an example for updating password:
```
┌──────────────────────────┐
│ Editing Account Password │
├──────────────────────────┘
└@ Password or [B/H]: █
```
```
┌──────────────────────────┐
│ Editing Account Password │
├──────────────────────────┘
├% Editing Account Password options: [Back to account page/Help]
└@ Password or [B/H]: █
```
```
┌──────────────────────────┐
│ Editing Account Password │
├──────────────────────────┘
├@ Password or [B/H]: password1
└@ New Password: █
```
### Logout page
```
┌───────┬─────────────────┬─────────┐
│ Chats │ Direct Messages │ Account │
├───────┴─────────────────┴─────────┘
├% Are you sure you want to Log out?
│
└@ [Y/N]: █
```
The No option should return you to the chats page.
## Shortcomings
As I mentioned, this is meant to be an exercise task, not a real project. But, if you want to turn it into something useable, here are some suggestions on what you could do:
- Implement deletion of accounts and messages
- Replace text files with an actual database (because the file system doesn't scale at all)
- Add networking and maybe server application (or make it peer-to-peer)
- Implement friends and notifications and viewing accounts inside chats
- Add a biography/description field inside profiles
- Add profile email and implement a mail service (send password confirmation emails and such)
- Implement UI customization, or just rework the UI as a whole
|